Project

General

Profile

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

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

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
import org.distorted.os.OSInterface;
26

    
27
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class BandagedPlayView extends GLSurfaceView
32
{
33
    private ObjectControl mObjectController;
34
    private OSInterface mInterface;
35
    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
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)) );
46
      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
        BandagedPlayLibInterface ref = new BandagedPlayLibInterface(act);
85
        mInterface = new OSInterface(act);
86
        mObjectController = new ObjectControl(ref,mInterface);
87
        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

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

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

    
(13-13/13)