Project

General

Profile

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

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

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 PurchaseOSInterface mInterface;
30
    private PurchaseRenderer mRenderer;
31
    private boolean mCreated;
32

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

    
35
    void setScreenSize(int width, int height)
36
      {
37
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height));
38
      mObjectController.setObjectScale(1.00f);
39

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

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
    ObjectControl getObjectControl()
52
      {
53
      return mObjectController;
54
      }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
    PurchaseRenderer getRenderer()
59
      {
60
      return mRenderer;
61
      }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
// PUBLIC API
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
    public PurchaseSurfaceView(Context context, AttributeSet attrs)
68
      {
69
      super(context,attrs);
70

    
71
      mCreated = false;
72

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

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

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

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

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

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

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

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

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

    
(7-7/7)