Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayView.java @ 401d9c0f

1 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 da56b12f Leszek Koltunski
// Copyright 2022 Leszek Koltunski                                                               //
3 9530f6b0 Leszek Koltunski
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 44fec653 Leszek Koltunski
// 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 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.bandaged;
11
12 565d139b Leszek Koltunski
import android.annotation.SuppressLint;
13 9530f6b0 Leszek Koltunski
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 565d139b Leszek Koltunski
import android.view.MotionEvent;
20 9530f6b0 Leszek Koltunski
21
import com.google.firebase.crashlytics.FirebaseCrashlytics;
22
23
import org.distorted.objectlib.main.ObjectControl;
24
import org.distorted.objectlib.main.TwistyObjectNode;
25 ed0ea1c5 Leszek Koltunski
import org.distorted.os.OSInterface;
26 9530f6b0 Leszek Koltunski
27 565d139b Leszek Koltunski
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
28
29 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
30
31
public class BandagedPlayView extends GLSurfaceView
32
{
33
    private ObjectControl mObjectController;
34 ed0ea1c5 Leszek Koltunski
    private OSInterface mInterface;
35 9530f6b0 Leszek Koltunski
    private BandagedPlayRenderer mRenderer;
36
    private int mScreenWidth, mScreenHeight;
37
    private boolean mCreated;
38
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41
    void setScreenSize(int width, int height)
42
      {
43
      mScreenWidth = width;
44
      mScreenHeight= height;
45 b1178f5f Leszek Koltunski
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)) );
46 9530f6b0 Leszek Koltunski
      mObjectController.setObjectScale(1.00f);
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
      }
56
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59
    boolean isVertical()
60
      {
61
      return mScreenHeight>mScreenWidth;
62
      }
63
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66
    ObjectControl getObjectControl()
67
      {
68
      return mObjectController;
69
      }
70
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
// PUBLIC API
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
75
    public BandagedPlayView(Context context, AttributeSet attrs)
76
      {
77
      super(context,attrs);
78
79
      mCreated = false;
80
81
      if(!isInEditMode())
82
        {
83
        BandagedPlayActivity act = (BandagedPlayActivity)context;
84 88b94310 Leszek Koltunski
        BandagedPlayLibInterface ref = new BandagedPlayLibInterface(act);
85 ed0ea1c5 Leszek Koltunski
        mInterface = new OSInterface(act);
86 ac4c7a1d Leszek Koltunski
        mObjectController = new ObjectControl(ref,mInterface);
87 9530f6b0 Leszek Koltunski
        mObjectController.setRotateOnCreation(true);
88
        mRenderer = new BandagedPlayRenderer(this);
89
90
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
91
92
        try
93
          {
94
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
95
          int esVersion = configurationInfo.reqGlEsVersion>>16;
96
          setEGLContextClientVersion(esVersion);
97
          setRenderer(mRenderer);
98
          }
99
        catch(Exception ex)
100
          {
101
          act.OpenGLError();
102
103
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
104
          String version = GLES30.glGetString(GLES30.GL_VERSION);
105
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
106
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
107
108
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
109
          crashlytics.setCustomKey("GLSL Version"  , shading );
110
          crashlytics.setCustomKey("GL version"    , version );
111
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
112
          crashlytics.setCustomKey("GLSL renderer" , renderer);
113
          crashlytics.recordException(ex);
114
          }
115
        }
116
      }
117
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120
    @Override
121
    public void onPause()
122
      {
123
      super.onPause();
124
      mObjectController.onPause();
125
      }
126
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
129
    @Override
130
    public void onResume()
131
      {
132
      super.onResume();
133
      mObjectController.onResume();
134
      }
135 565d139b Leszek Koltunski
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137
138
    @SuppressLint("ClickableViewAccessibility")
139
    @Override
140
    public boolean onTouchEvent(MotionEvent event)
141
      {
142 401d9c0f Leszek Koltunski
      mInterface.setMotionEvent(event);
143
      return mObjectController.onTouchEvent(MODE_ROTATE);
144 565d139b Leszek Koltunski
      }
145 9530f6b0 Leszek Koltunski
}