Project

General

Profile

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

magiccube / src / main / java / org / distorted / info / InfoSurfaceView.java @ 58fd2ec0

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.info;
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
import org.distorted.os.OSInterface;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
public class InfoSurfaceView extends GLSurfaceView
28
{
29
    private ObjectControl mObjectController;
30
    private InfoRenderer 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
// PUBLIC API
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
    public InfoSurfaceView(Context context, AttributeSet attrs)
61
      {
62
      super(context,attrs);
63

    
64
      mCreated = false;
65

    
66
      if(!isInEditMode())
67
        {
68
        InfoActivity act = (InfoActivity)context;
69
        InfoObjectLibInterface ref = new InfoObjectLibInterface();
70
        OSInterface inter = new OSInterface(act,ref);
71
        mObjectController = new ObjectControl(inter);
72
        mObjectController.setRotateOnCreation(true);
73
        mRenderer = new InfoRenderer(this);
74

    
75
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
76

    
77
        try
78
          {
79
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
80
          int esVersion = configurationInfo.reqGlEsVersion>>16;
81
          setEGLContextClientVersion(esVersion);
82
          setRenderer(mRenderer);
83
          }
84
        catch(Exception ex)
85
          {
86
          act.OpenGLError();
87

    
88
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
89
          String version = GLES30.glGetString(GLES30.GL_VERSION);
90
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
91
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
92

    
93
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
94
          crashlytics.setCustomKey("GLSL Version"  , shading );
95
          crashlytics.setCustomKey("GL version"    , version );
96
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
97
          crashlytics.setCustomKey("GLSL renderer" , renderer);
98
          crashlytics.recordException(ex);
99
          }
100
        }
101
      }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
    @Override
106
    public void onPause()
107
      {
108
      super.onPause();
109
      mObjectController.onPause();
110
      }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

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

    
(6-6/6)