Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialSurfaceView.java @ ce31f774

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
5
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
6
///////////////////////////////////////////////////////////////////////////////////////////////////
7

    
8
package org.distorted.tutorials;
9

    
10
import android.annotation.SuppressLint;
11
import android.app.ActivityManager;
12
import android.content.Context;
13
import android.content.pm.ConfigurationInfo;
14
import android.opengl.GLES30;
15
import android.opengl.GLSurfaceView;
16
import android.util.AttributeSet;
17
import android.view.MotionEvent;
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
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
25
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
public class TutorialSurfaceView extends GLSurfaceView
30
{
31
    private ObjectControl mObjectController;
32
    private TutorialRenderer mRenderer;
33
    private int mScreenWidth, mScreenHeight;
34
    private boolean mCreated;
35
    private int mTouchMode;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
    void setScreenSize(int width, int height)
40
      {
41
      mScreenWidth = width;
42
      mScreenHeight= height;
43
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height));
44
      mObjectController.setObjectMove( (int)(-0.5f*width*TutorialActivity.BAR_RATIO), 0);
45
      mObjectController.setObjectScale(0.80f);
46

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

    
54
        TutorialActivity act = (TutorialActivity) getContext();
55
        mTouchMode = act.getIsFree() ? MODE_ROTATE : MODE_DRAG;
56
        }
57
      }
58

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

    
61
    boolean isVertical()
62
      {
63
      return mScreenHeight>mScreenWidth;
64
      }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
    ObjectControl getObjectControl()
69
      {
70
      return mObjectController;
71
      }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
// PUBLIC API
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
    public TutorialSurfaceView(Context context, AttributeSet attrs)
78
      {
79
      super(context,attrs);
80

    
81
      mCreated = false;
82
      mTouchMode = MODE_ROTATE;
83

    
84
      if(!isInEditMode())
85
        {
86
        TutorialActivity act = (TutorialActivity)context;
87
        TutorialObjectLibInterface ref = new TutorialObjectLibInterface(act);
88
        mObjectController = new ObjectControl(ref);
89
        mRenderer = new TutorialRenderer(this);
90

    
91
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
92

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

    
104
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
105
          String version = GLES30.glGetString(GLES30.GL_VERSION);
106
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
107
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
108

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

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
    @Override
122
    public void onPause()
123
      {
124
      super.onPause();
125
      mObjectController.onPause();
126
      }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
    @Override
131
    public void onResume()
132
      {
133
      super.onResume();
134
      mObjectController.onResume();
135
      }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
    @SuppressLint("ClickableViewAccessibility")
140
    @Override
141
    public boolean onTouchEvent(MotionEvent event)
142
      {
143
      return mObjectController.onTouchEvent(event,mTouchMode);
144
      }
145
}
146

    
(5-5/6)