Project

General

Profile

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

magiccube / src / main / java / org / distorted / playui / PlayView.java @ c9f72ca3

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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.playui;
11

    
12
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
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 PlayView extends GLSurfaceView
32
{
33
    private ObjectControl mObjectController;
34
    private OSInterface mInterface;
35
    private PlayRenderer mRenderer;
36
    private boolean mCreated;
37

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

    
40
    void setScreenSize(int width, int height)
41
      {
42
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*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
    OSInterface getInterface()
64
      {
65
      return mInterface;
66
      }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
// PUBLIC API
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
    public PlayView(Context context, AttributeSet attrs)
73
      {
74
      super(context,attrs);
75

    
76
      mCreated = false;
77

    
78
      if(!isInEditMode())
79
        {
80
        PlayActivity act = (PlayActivity)context;
81
        PlayLibInterface ref = new PlayLibInterface(act);
82
        mInterface = new OSInterface(act,ref);
83
        mObjectController = new ObjectControl(mInterface);
84
        mObjectController.setRotateOnCreation(true);
85
        mRenderer = new PlayRenderer(this);
86

    
87
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
88

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

    
100
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
101
          String version = GLES30.glGetString(GLES30.GL_VERSION);
102
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
103
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
104

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

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
    @Override
118
    public void onPause()
119
      {
120
      super.onPause();
121
      mObjectController.onPause();
122
      }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
    @Override
127
    public void onResume()
128
      {
129
      super.onResume();
130
      mObjectController.onResume();
131
      }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
    @SuppressLint("ClickableViewAccessibility")
136
    @Override
137
    public boolean onTouchEvent(MotionEvent event)
138
      {
139
      mInterface.setMotionEvent(event);
140
      return mObjectController.onTouchEvent(MODE_ROTATE);
141
      }
142
}
143

    
(5-5/5)