Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigSurfaceView.java @ 8cf17ca7

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 static org.distorted.objectlib.main.ObjectControl.MODE_REPLACE;
13

    
14
import android.annotation.SuppressLint;
15
import android.app.ActivityManager;
16
import android.content.Context;
17
import android.content.pm.ConfigurationInfo;
18
import android.opengl.GLES30;
19
import android.opengl.GLSurfaceView;
20
import android.util.AttributeSet;
21
import android.view.MotionEvent;
22

    
23
import com.google.firebase.crashlytics.FirebaseCrashlytics;
24

    
25
import org.distorted.objectlib.main.ObjectControl;
26
import org.distorted.objectlib.main.TwistyObjectNode;
27
import org.distorted.os.OSInterface;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class ConfigSurfaceView extends GLSurfaceView
32
{
33
    private ObjectControl mObjectController;
34
    private ConfigRenderer mRenderer;
35
    private OSInterface mInterface;
36
    private boolean mCreated;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
    void setScreenSize(int width, int height)
41
      {
42
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height));
43
      mObjectController.setObjectScale(1.00f);
44

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

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
    ObjectControl getObjectControl()
57
      {
58
      return mObjectController;
59
      }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
    ConfigRenderer getRenderer()
64
      {
65
      return mRenderer;
66
      }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
    OSInterface getInterface()
71
      {
72
      return mInterface;
73
      }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
    void resetObject()
78
      {
79
      ConfigActivity act = (ConfigActivity)getContext();
80
      act.recreateColors();
81
      act.recreateStickers(ConfigScreenPane.DEFAULT_BORDERS,ConfigScreenPane.DEFAULT_CORNERS);
82
      act.resetUI();
83
      }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
// PUBLIC API
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
    public ConfigSurfaceView(Context context, AttributeSet attrs)
90
      {
91
      super(context,attrs);
92

    
93
      mCreated = false;
94

    
95
      if(!isInEditMode())
96
        {
97
        ConfigActivity act = (ConfigActivity)context;
98
        ConfigObjectLibInterface ref = new ConfigObjectLibInterface(act);
99
        mInterface = new OSInterface(act,ref);
100
        mObjectController = new ObjectControl(mInterface);
101
        mObjectController.setRotateOnCreation(true);
102
        mRenderer = new ConfigRenderer(this);
103

    
104
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
105

    
106
        try
107
          {
108
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
109
          int esVersion = configurationInfo.reqGlEsVersion>>16;
110
          setEGLContextClientVersion(esVersion);
111
          setRenderer(mRenderer);
112
          }
113
        catch(Exception ex)
114
          {
115
          act.OpenGLError();
116

    
117
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
118
          String version = GLES30.glGetString(GLES30.GL_VERSION);
119
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
120
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
121

    
122
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
123
          crashlytics.setCustomKey("GLSL Version"  , shading );
124
          crashlytics.setCustomKey("GL version"    , version );
125
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
126
          crashlytics.setCustomKey("GLSL renderer" , renderer);
127
          crashlytics.recordException(ex);
128
          }
129
        }
130
      }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
    @Override
135
    public void onPause()
136
      {
137
      super.onPause();
138
      mObjectController.onPause();
139
      }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
    @Override
144
    public void onResume()
145
      {
146
      super.onResume();
147
      mObjectController.onResume();
148
      }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
    @SuppressLint("ClickableViewAccessibility")
153
    @Override
154
    public boolean onTouchEvent(MotionEvent event)
155
      {
156
      mInterface.setMotionEvent(event);
157
      return mObjectController.onTouchEvent(MODE_REPLACE);
158
      }
159
}
160

    
(6-6/6)