Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigSurfaceView.java @ 427ba5bf

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
    void resetObject()
71
      {
72
      ConfigActivity act = (ConfigActivity)getContext();
73
      act.recreateColors();
74
      act.recreateStickers(ConfigScreenPane.DEFAULT_BORDERS,ConfigScreenPane.DEFAULT_CORNERS);
75
      act.resetUI();
76
      }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
// PUBLIC API
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
    public ConfigSurfaceView(Context context, AttributeSet attrs)
83
      {
84
      super(context,attrs);
85

    
86
      mCreated = false;
87

    
88
      if(!isInEditMode())
89
        {
90
        ConfigActivity act = (ConfigActivity)context;
91
        ConfigObjectLibInterface ref = new ConfigObjectLibInterface(act);
92
        mInterface = new OSInterface(act,ref);
93
        mObjectController = new ObjectControl(mInterface);
94
        mObjectController.setRotateOnCreation(true);
95
        mRenderer = new ConfigRenderer(this);
96

    
97
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
98

    
99
        try
100
          {
101
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
102
          int esVersion = configurationInfo.reqGlEsVersion>>16;
103
          setEGLContextClientVersion(esVersion);
104
          setRenderer(mRenderer);
105
          }
106
        catch(Exception ex)
107
          {
108
          act.OpenGLError();
109

    
110
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
111
          String version = GLES30.glGetString(GLES30.GL_VERSION);
112
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
113
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
114

    
115
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
116
          crashlytics.setCustomKey("GLSL Version"  , shading );
117
          crashlytics.setCustomKey("GL version"    , version );
118
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
119
          crashlytics.setCustomKey("GLSL renderer" , renderer);
120
          crashlytics.recordException(ex);
121
          }
122
        }
123
      }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
    @Override
128
    public void onPause()
129
      {
130
      super.onPause();
131
      mObjectController.onPause();
132
      }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
    @Override
137
    public void onResume()
138
      {
139
      super.onResume();
140
      mObjectController.onResume();
141
      }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
    @SuppressLint("ClickableViewAccessibility")
146
    @Override
147
    public boolean onTouchEvent(MotionEvent event)
148
      {
149
      mInterface.setMotionEvent(event);
150
      return mObjectController.onTouchEvent(MODE_REPLACE);
151
      }
152
}
153

    
(6-6/6)