Project

General

Profile

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

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

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 TutorialOSInterface mInterface;
33
    private TutorialRenderer mRenderer;
34
    private int mScreenWidth, mScreenHeight;
35
    private boolean mCreated;
36
    private int mTouchMode;
37

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

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

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

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

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

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
// PUBLIC API
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

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

    
82
      mCreated = false;
83
      mTouchMode = MODE_ROTATE;
84

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

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

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

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

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

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

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

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

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

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

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

    
(6-6/7)