Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigSurfaceView.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.config;
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 ConfigSurfaceView extends GLSurfaceView
27
{
28
    private ObjectControl mObjectController;
29
    private ConfigOSInterface mInterface;
30
    private ConfigRenderer mRenderer;
31
    private int mScreenWidth, mScreenHeight;
32
    private boolean mCreated;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

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

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

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

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

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

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

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
// PUBLIC API
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
    public ConfigSurfaceView(Context context, AttributeSet attrs)
71
      {
72
      super(context,attrs);
73

    
74
      mCreated = false;
75

    
76
      if(!isInEditMode())
77
        {
78
        ConfigActivity act = (ConfigActivity)context;
79
        ConfigObjectLibInterface ref = new ConfigObjectLibInterface();
80
        mInterface = new ConfigOSInterface(act);
81
        mObjectController = new ObjectControl(ref,mInterface);
82
        mObjectController.setRotateOnCreation(true);
83
        mRenderer = new ConfigRenderer(this);
84

    
85
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
86

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

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

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

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

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

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

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

    
(7-7/7)