Project

General

Profile

Download (4.62 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / purchase / PurchaseSurfaceView.java @ de131f0a

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.purchase;
11

    
12
import android.app.ActivityManager;
13
import android.content.Context;
14
import android.content.pm.ConfigurationInfo;
15
import android.opengl.GLES30;
16
import android.opengl.GLSurfaceView;
17
import android.util.AttributeSet;
18

    
19
import com.google.firebase.crashlytics.FirebaseCrashlytics;
20

    
21
import org.distorted.objectlib.main.ObjectControl;
22
import org.distorted.objectlib.main.TwistyObjectNode;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

    
26
public class PurchaseSurfaceView extends GLSurfaceView
27
{
28
    private ObjectControl mObjectController;
29
    private PurchaseRenderer mRenderer;
30
    private int mScreenWidth, mScreenHeight;
31
    private boolean mCreated;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
    void setScreenSize(int width, int height)
36
      {
37
      mScreenWidth = width;
38
      mScreenHeight= height;
39
      mObjectController.setScreenSize(width,height);
40
      mObjectController.setObjectScale(1.00f);
41

    
42
      if( !mCreated )
43
        {
44
        mCreated = true;
45
        mObjectController.createNode(width,height);
46
        TwistyObjectNode objectNode = mObjectController.getNode();
47
        mRenderer.getScreen().attach(objectNode);
48
        }
49
      }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
    boolean isVertical()
54
      {
55
      return mScreenHeight>mScreenWidth;
56
      }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
    ObjectControl getObjectControl()
61
      {
62
      return mObjectController;
63
      }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
// PUBLIC API
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
    public PurchaseSurfaceView(Context context, AttributeSet attrs)
70
      {
71
      super(context,attrs);
72

    
73
      mCreated = false;
74

    
75
      if(!isInEditMode())
76
        {
77
        PurchaseActivity act = (PurchaseActivity)context;
78
        PurchaseObjectLibInterface ref = new PurchaseObjectLibInterface();
79
        mObjectController = new ObjectControl(act,ref);
80
        mObjectController.setRotateOnCreation(true);
81
        mRenderer = new PurchaseRenderer(this);
82

    
83
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
84

    
85
        try
86
          {
87
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
88
          int esVersion = configurationInfo.reqGlEsVersion>>16;
89
          setEGLContextClientVersion(esVersion);
90
          setRenderer(mRenderer);
91
          }
92
        catch(Exception ex)
93
          {
94
          act.OpenGLError();
95

    
96
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
97
          String version = GLES30.glGetString(GLES30.GL_VERSION);
98
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
99
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
100

    
101
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
102
          crashlytics.setCustomKey("GLSL Version"  , shading );
103
          crashlytics.setCustomKey("GL version"    , version );
104
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
105
          crashlytics.setCustomKey("GLSL renderer" , renderer);
106
          crashlytics.recordException(ex);
107
          }
108
        }
109
      }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
    @Override
114
    public void onPause()
115
      {
116
      super.onPause();
117
      mObjectController.onPause();
118
      }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
    @Override
123
    public void onResume()
124
      {
125
      super.onResume();
126
      mObjectController.onResume();
127
      }
128
}
129

    
(6-6/6)