Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigSurfaceView.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.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
      // TODO
73
      }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// PUBLIC API
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
    public ConfigSurfaceView(Context context, AttributeSet attrs)
80
      {
81
      super(context,attrs);
82

    
83
      mCreated = false;
84

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

    
94
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
95

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

    
107
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
108
          String version = GLES30.glGetString(GLES30.GL_VERSION);
109
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
110
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
111

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

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

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

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

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

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

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

    
(6-6/6)