Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayView.java @ 7fe59aa5

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.bandaged;
21

    
22
import android.annotation.SuppressLint;
23
import android.app.ActivityManager;
24
import android.content.Context;
25
import android.content.pm.ConfigurationInfo;
26
import android.opengl.GLES30;
27
import android.opengl.GLSurfaceView;
28
import android.util.AttributeSet;
29
import android.view.MotionEvent;
30

    
31
import com.google.firebase.crashlytics.FirebaseCrashlytics;
32

    
33
import org.distorted.objectlib.main.ObjectControl;
34
import org.distorted.objectlib.main.TwistyObjectNode;
35

    
36
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
37

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

    
40
public class BandagedPlayView extends GLSurfaceView
41
{
42
    private ObjectControl mObjectController;
43
    private BandagedPlayRenderer mRenderer;
44
    private int mScreenWidth, mScreenHeight;
45
    private boolean mCreated;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
    void setScreenSize(int width, int height)
50
      {
51
      mScreenWidth = width;
52
      mScreenHeight= height;
53
      mObjectController.setScreenSize(width,height);
54
      mObjectController.setObjectScale(1.00f);
55

    
56
      if( !mCreated )
57
        {
58
        mCreated = true;
59
        mObjectController.createNode(width,height);
60
        TwistyObjectNode objectNode = mObjectController.getNode();
61
        mRenderer.getScreen().attach(objectNode);
62
        }
63
      }
64

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

    
67
    boolean isVertical()
68
      {
69
      return mScreenHeight>mScreenWidth;
70
      }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
    ObjectControl getObjectControl()
75
      {
76
      return mObjectController;
77
      }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
// PUBLIC API
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
    public BandagedPlayView(Context context, AttributeSet attrs)
84
      {
85
      super(context,attrs);
86

    
87
      mCreated = false;
88

    
89
      if(!isInEditMode())
90
        {
91
        BandagedPlayActivity act = (BandagedPlayActivity)context;
92
        BandagedPlayLibInterface ref = new BandagedPlayLibInterface(act);
93
        mObjectController = new ObjectControl(act,ref);
94
        mObjectController.setRotateOnCreation(true);
95
        mRenderer = new BandagedPlayRenderer(this);
96

    
97
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
98

    
99
        try
100
          {
101
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
102
          int esVersion = configurationInfo.reqGlEsVersion>>16;
103
          setEGLContextClientVersion(esVersion);
104
          setRenderer(mRenderer);
105
          }
106
        catch(Exception ex)
107
          {
108
          act.OpenGLError();
109

    
110
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
111
          String version = GLES30.glGetString(GLES30.GL_VERSION);
112
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
113
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
114

    
115
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
116
          crashlytics.setCustomKey("GLSL Version"  , shading );
117
          crashlytics.setCustomKey("GL version"    , version );
118
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
119
          crashlytics.setCustomKey("GLSL renderer" , renderer);
120
          crashlytics.recordException(ex);
121
          }
122
        }
123
      }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

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

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
    @Override
137
    public void onResume()
138
      {
139
      super.onResume();
140
      mObjectController.onResume();
141
      }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
    @SuppressLint("ClickableViewAccessibility")
146
    @Override
147
    public boolean onTouchEvent(MotionEvent event)
148
      {
149
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
150
      }
151
}
152

    
(13-13/13)