Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikSurfaceView.java @ 6142069a

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.main;
11

    
12
import android.annotation.SuppressLint;
13
import android.app.ActivityManager;
14
import android.content.Context;
15
import android.content.pm.ConfigurationInfo;
16
import android.opengl.GLES30;
17
import android.opengl.GLSurfaceView;
18
import android.util.AttributeSet;
19
import android.view.MotionEvent;
20

    
21
import com.google.firebase.crashlytics.FirebaseCrashlytics;
22

    
23
import org.distorted.objectlib.main.ObjectControl;
24
import org.distorted.objectlib.main.TwistyObjectNode;
25

    
26
import org.distorted.screens.ScreenList;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class RubikSurfaceView extends GLSurfaceView
31
{
32
    private ObjectControl mObjectController;
33
    private RubikRenderer mRenderer;
34
    private int mScreenWidth, mScreenHeight;
35
    private boolean mCreated;
36

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

    
39
    void setScreenSize(int width, int height)
40
      {
41
      mScreenWidth = width;
42
      mScreenHeight= height;
43
      mObjectController.setScreenSize(width,height);
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
    boolean isVertical()
57
      {
58
      return mScreenHeight>mScreenWidth;
59
      }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
    RubikRenderer getRenderer()
64
      {
65
      return mRenderer;
66
      }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

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

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

    
83
      mCreated = false;
84

    
85
      if(!isInEditMode())
86
        {
87
        RubikActivity act = (RubikActivity)context;
88
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
89
        mObjectController = new ObjectControl(act,ref);
90
        mRenderer = new RubikRenderer(this);
91

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

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

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

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

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

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

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

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

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
    @SuppressLint("ClickableViewAccessibility")
141
    @Override
142
    public boolean onTouchEvent(MotionEvent event)
143
      {
144
      int mode = ScreenList.getMode();
145
      return mObjectController.onTouchEvent(event,mode);
146
      }
147
}
148

    
(4-4/4)