Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayView.java @ 306aa049

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.bandaged;
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 static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
27

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

    
30
public class BandagedPlayView extends GLSurfaceView
31
{
32
    private ObjectControl mObjectController;
33
    private BandagedPlayRenderer 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
      mObjectController.setObjectScale(1.00f);
45

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
    boolean isVertical()
58
      {
59
      return mScreenHeight>mScreenWidth;
60
      }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
    ObjectControl getObjectControl()
65
      {
66
      return mObjectController;
67
      }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
// PUBLIC API
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
    public BandagedPlayView(Context context, AttributeSet attrs)
74
      {
75
      super(context,attrs);
76

    
77
      mCreated = false;
78

    
79
      if(!isInEditMode())
80
        {
81
        BandagedPlayActivity act = (BandagedPlayActivity)context;
82
        BandagedPlayLibInterface ref = new BandagedPlayLibInterface(act);
83
        mObjectController = new ObjectControl(act,ref);
84
        mObjectController.setRotateOnCreation(true);
85
        mRenderer = new BandagedPlayRenderer(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
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
140
      }
141
}
142

    
(13-13/13)