Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayView.java @ f404152d

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.helpers.OperatingSystemInterface;
24
import org.distorted.objectlib.main.ObjectControl;
25
import org.distorted.objectlib.main.TwistyObjectNode;
26
import org.distorted.os.OSInterface;
27

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

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
public class BandagedPlayView extends GLSurfaceView
33
{
34
    private ObjectControl mObjectController;
35
    private OSInterface mInterface;
36
    private BandagedPlayRenderer mRenderer;
37
    private int mScreenWidth, mScreenHeight;
38
    private boolean mCreated;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
    void setScreenSize(int width, int height)
43
      {
44
      mScreenWidth = width;
45
      mScreenHeight= height;
46
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)) );
47
      mObjectController.setObjectScale(1.00f);
48

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

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
    boolean isVertical()
61
      {
62
      return mScreenHeight>mScreenWidth;
63
      }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
    ObjectControl getObjectControl()
68
      {
69
      return mObjectController;
70
      }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
// PUBLIC API
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
    public BandagedPlayView(Context context, AttributeSet attrs)
77
      {
78
      super(context,attrs);
79

    
80
      mCreated = false;
81

    
82
      if(!isInEditMode())
83
        {
84
        BandagedPlayActivity act = (BandagedPlayActivity)context;
85
        BandagedPlayLibInterface ref = new BandagedPlayLibInterface(act);
86
        mInterface = new OSInterface(act,ref);
87
        mObjectController = new ObjectControl(mInterface);
88
        mObjectController.setRotateOnCreation(true);
89
        mRenderer = new BandagedPlayRenderer(this);
90

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

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

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

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

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

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

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

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

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

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

    
(14-14/14)