Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialSurfaceView.java @ 2cf21fdc

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.app.ActivityManager;
11
import android.content.Context;
12
import android.content.pm.ConfigurationInfo;
13
import android.opengl.GLES30;
14
import android.opengl.GLSurfaceView;
15
import android.util.AttributeSet;
16
import android.view.MotionEvent;
17

    
18
import com.google.firebase.crashlytics.FirebaseCrashlytics;
19

    
20
import org.distorted.objectlib.main.ObjectControl;
21
import org.distorted.objectlib.main.TwistyObjectNode;
22

    
23
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
24

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

    
27
public class TutorialSurfaceView extends GLSurfaceView
28
{
29
    private ObjectControl mObjectController;
30
    private TutorialRenderer mRenderer;
31
    private int mScreenWidth, mScreenHeight;
32
    private boolean mCreated;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
    void setScreenSize(int width, int height)
37
      {
38
      mScreenWidth = width;
39
      mScreenHeight= height;
40
      mObjectController.setScreenSize(width,height);
41
      mObjectController.setObjectMove( (int)(-0.5f*width*TutorialActivity.BAR_RATIO), 0);
42
      mObjectController.setObjectScale(0.80f);
43

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

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
    boolean isVertical()
56
      {
57
      return mScreenHeight>mScreenWidth;
58
      }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
    ObjectControl getObjectControl()
63
      {
64
      return mObjectController;
65
      }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
// PUBLIC API
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
    public TutorialSurfaceView(Context context, AttributeSet attrs)
72
      {
73
      super(context,attrs);
74

    
75
      mCreated = false;
76

    
77
      if(!isInEditMode())
78
        {
79
        TutorialActivity act = (TutorialActivity)context;
80
        TutorialObjectLibInterface ref = new TutorialObjectLibInterface(act);
81
        mObjectController = new ObjectControl(act,ref);
82
        mRenderer = new TutorialRenderer(this);
83

    
84
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
85

    
86
        try
87
          {
88
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
89
          int esVersion = configurationInfo.reqGlEsVersion>>16;
90
          setEGLContextClientVersion(esVersion);
91
          setRenderer(mRenderer);
92
          }
93
        catch(Exception ex)
94
          {
95
          act.OpenGLError();
96

    
97
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
98
          String version = GLES30.glGetString(GLES30.GL_VERSION);
99
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
100
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
101

    
102
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
103
          crashlytics.setCustomKey("GLSL Version"  , shading );
104
          crashlytics.setCustomKey("GL version"    , version );
105
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
106
          crashlytics.setCustomKey("GLSL renderer" , renderer);
107
          crashlytics.recordException(ex);
108
          }
109
        }
110
      }
111

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

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

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

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

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
    @Override
133
    public boolean onTouchEvent(MotionEvent event)
134
      {
135
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
136
      }
137
}
138

    
(5-5/6)