Project

General

Profile

« Previous | Next » 

Revision 1237d25d

Added by Leszek Koltunski over 2 years ago

Beginnings of the ConfigActivity.

View differences:

src/main/AndroidManifest.xml
29 29
        </activity>
30 30

  
31 31
        <activity android:name="org.distorted.tutorials.TutorialActivity" android:exported="true" android:screenOrientation="portrait"/>
32
        <activity android:name="org.distorted.config.ConfigActivity" android:exported="true" android:screenOrientation="portrait"/>
32 33
    </application>
33 34
</manifest>
src/main/java/org/distorted/config/ConfigActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.config;
21

  
22
import android.os.Build;
23
import android.os.Bundle;
24
import android.util.DisplayMetrics;
25
import android.view.DisplayCutout;
26
import android.view.View;
27
import android.view.ViewGroup;
28
import android.view.WindowManager;
29
import android.widget.LinearLayout;
30

  
31
import androidx.appcompat.app.AppCompatActivity;
32

  
33
import com.google.firebase.analytics.FirebaseAnalytics;
34

  
35
import org.distorted.dialogs.RubikDialogError;
36
import org.distorted.dmesh.ObjectMesh;
37
import org.distorted.jsons.ObjectJson;
38
import org.distorted.library.main.DistortedLibrary;
39
import org.distorted.main.R;
40
import org.distorted.objectlib.main.ObjectControl;
41
import org.distorted.objectlib.main.ObjectType;
42
import org.distorted.tutorials.TutorialScreen;
43

  
44
import java.io.InputStream;
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
public class ConfigActivity extends AppCompatActivity
49
{
50
    private static final int ACTIVITY_NUMBER = 2;
51
    private static final float RATIO_INSET= 0.08f;
52
    public static final float BAR_RATIO = 0.17f;
53

  
54
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
55
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
56

  
57
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
58
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
59
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
60
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
61
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
62

  
63
    private FirebaseAnalytics mFirebaseAnalytics;
64
    private static int mScreenWidth, mScreenHeight;
65
    private int mCurrentApiVersion;
66
    private ConfigScreen mScreen;
67
    private int mObjectOrdinal;
68
    private int mHeightUpperBar;
69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
    @Override
73
    protected void onCreate(Bundle savedState)
74
      {
75
      super.onCreate(savedState);
76
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
77
      setTheme(R.style.MaterialThemeNoActionBar);
78
      setContentView(R.layout.config);
79

  
80
      Bundle b = getIntent().getExtras();
81

  
82
      if(b != null) mObjectOrdinal = b.getInt("obj");
83

  
84
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
85

  
86
      DisplayMetrics displaymetrics = new DisplayMetrics();
87
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
88
      mScreenWidth =displaymetrics.widthPixels;
89
      mScreenHeight=displaymetrics.heightPixels;
90

  
91
      hideNavigationBar();
92
      cutoutHack();
93
      }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

  
97
    private void hideNavigationBar()
98
      {
99
      mCurrentApiVersion = Build.VERSION.SDK_INT;
100

  
101
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
102
        {
103
        final View decorView = getWindow().getDecorView();
104

  
105
        decorView.setSystemUiVisibility(FLAGS);
106

  
107
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
108
          {
109
          @Override
110
          public void onSystemUiVisibilityChange(int visibility)
111
            {
112
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
113
              {
114
              decorView.setSystemUiVisibility(FLAGS);
115
              }
116
            }
117
          });
118
        }
119
      }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

  
123
    @Override
124
    public void onAttachedToWindow()
125
      {
126
      super.onAttachedToWindow();
127

  
128
      int insetHeight = 0;
129

  
130
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
131
        {
132
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
133
        insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
134
        }
135

  
136
      LinearLayout layoutHid = findViewById(R.id.hiddenBar);
137
      ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
138
      paramsHid.height = (int)(insetHeight*RATIO_INSET);
139
      layoutHid.setLayoutParams(paramsHid);
140
      mHeightUpperBar += paramsHid.height;
141

  
142
      if( mScreen==null ) mScreen = new ConfigScreen();
143
      mScreen.createScreen(this);
144
      }
145

  
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
// do not avoid cutouts
148

  
149
    private void cutoutHack()
150
      {
151
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
152
        {
153
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
154
        }
155
      }
156

  
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

  
159
    @Override
160
    public void onWindowFocusChanged(boolean hasFocus)
161
      {
162
      super.onWindowFocusChanged(hasFocus);
163

  
164
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
165
        {
166
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
167
        }
168
      }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
    
172
    @Override
173
    protected void onPause() 
174
      {
175
      super.onPause();
176
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
177
      view.onPause();
178
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
179
      }
180

  
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
    
183
    @Override
184
    protected void onResume() 
185
      {
186
      super.onResume();
187
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
188
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
189
      view.onResume();
190

  
191
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectType.NUM_OBJECTS )
192
        {
193
        ObjectType obj = ObjectType.getObject(mObjectOrdinal);
194
        changeIfDifferent(obj,view.getObjectControl());
195
        }
196
      }
197

  
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
    
200
    @Override
201
    protected void onDestroy() 
202
      {
203
      super.onDestroy();
204
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
205
      }
206

  
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

  
209
    void OpenGLError()
210
      {
211
      RubikDialogError errDiag = new RubikDialogError();
212
      errDiag.show(getSupportFragmentManager(), null);
213
      }
214

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

  
217
    private void changeIfDifferent(ObjectType type,ObjectControl control)
218
      {
219
      InputStream jsonStream = ObjectJson.getStream(type,this);
220
      InputStream meshStream = ObjectMesh.getStream(type,this);
221
      control.changeIfDifferent(type.ordinal(),jsonStream,meshStream);
222
      }
223

  
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

  
226
    ConfigScreen getState()
227
      {
228
      return mScreen;
229
      }
230

  
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232
// PUBLIC API
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

  
235
    public FirebaseAnalytics getAnalytics()
236
      {
237
      return mFirebaseAnalytics;
238
      }
239

  
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

  
242
    public int getHeightUpperBar()
243
      {
244
      return mHeightUpperBar;
245
      }
246

  
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

  
249
    public int getScreenWidthInPixels()
250
      {
251
      return mScreenWidth;
252
      }
253

  
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

  
256
    public ObjectControl getControl()
257
      {
258
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
259
      return view.getObjectControl();
260
      }
261

  
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

  
264
    public static int getDrawableSize()
265
      {
266
      if( mScreenHeight<1000 )
267
        {
268
        return 0;
269
        }
270
      if( mScreenHeight<1600 )
271
        {
272
        return 1;
273
        }
274
      if( mScreenHeight<1900 )
275
        {
276
        return 2;
277
        }
278

  
279
      return 3;
280
      }
281

  
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

  
284
    public static int getDrawable(int small, int medium, int big, int huge)
285
      {
286
      int size = getDrawableSize();
287

  
288
      switch(size)
289
        {
290
        case 0 : return small;
291
        case 1 : return medium;
292
        case 2 : return big;
293
        default: return huge;
294
        }
295
      }
296

  
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

  
299
    public boolean isVertical()
300
      {
301
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
302
      return view.isVertical();
303
      }
304
}
src/main/java/org/distorted/config/ConfigObjectLibInterface.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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.config;
21

  
22
import com.google.firebase.crashlytics.FirebaseCrashlytics;
23

  
24
import org.distorted.library.message.EffectMessageSender;
25
import org.distorted.objectlib.BuildConfig;
26
import org.distorted.objectlib.helpers.BlockController;
27
import org.distorted.objectlib.helpers.ObjectLibInterface;
28

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

  
31
public class ConfigObjectLibInterface implements ObjectLibInterface
32
{
33
  public void onWinEffectFinished(String debug, int scrambleNum) { }
34
  public void onScrambleEffectFinished() { }
35
  public void onBeginRotation() { }
36
  public void onSolved() { }
37
  public void onObjectCreated(long time) { }
38
  public void onReplaceModeDown(int cubit, int face) { }
39
  public void onReplaceModeUp() { }
40
  public void onFinishRotation(int axis, int row, int angle) { }
41
  public void failedToDrag() { }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
  public void reportProblem(String problem, boolean reportException)
46
    {
47
    if( BuildConfig.DEBUG )
48
      {
49
      android.util.Log.e("interface", problem);
50
      }
51
    else
52
      {
53
      if( reportException )
54
        {
55
        Exception ex = new Exception(problem);
56
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
57
        crashlytics.setCustomKey("problem" , problem);
58
        crashlytics.recordException(ex);
59
        }
60
      else
61
        {
62
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
63
        crashlytics.log(problem);
64
        }
65
      }
66
    }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
  private void reportUIProblem(int place, long pause, long resume, long time)
71
    {
72
    String error = "UI BLOCK "+place+" blocked for "+time;
73

  
74
    if( BuildConfig.DEBUG )
75
       {
76
       android.util.Log.e("D", error);
77
       }
78
    else
79
      {
80
      Exception ex = new Exception(error);
81
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
82
      crashlytics.setCustomKey("pause" , pause );
83
      crashlytics.setCustomKey("resume", resume );
84
      crashlytics.recordException(ex);
85
      }
86
    }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
  private void reportTouchProblem(int place, long pause, long resume, long time)
91
    {
92
    String error = "TOUCH BLOCK "+place+" blocked for "+time;
93

  
94
    if( BuildConfig.DEBUG )
95
       {
96
       android.util.Log.e("D", error);
97
       }
98
    else
99
      {
100
      Exception ex = new Exception(error);
101
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
102
      crashlytics.setCustomKey("pause" , pause );
103
      crashlytics.setCustomKey("resume", resume);
104
      crashlytics.recordException(ex);
105
      }
106
    }
107

  
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

  
110
  private void reportThreadProblem(int place, long pause, long resume, long time)
111
    {
112
    String error = EffectMessageSender.reportState();
113

  
114
    if( BuildConfig.DEBUG )
115
       {
116
       android.util.Log.e("D", error);
117
       }
118
    else
119
      {
120
      Exception ex = new Exception(error);
121
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
122
      crashlytics.setCustomKey("pause" , pause  );
123
      crashlytics.setCustomKey("resume", resume );
124
      crashlytics.recordException(ex);
125
      }
126
    }
127

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

  
130
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
131
    {
132
    switch(type)
133
      {
134
      case BlockController.TYPE_UI    : reportUIProblem(place,pause,resume,time); break;
135
      case BlockController.TYPE_TOUCH : reportTouchProblem(place,pause,resume,time); break;
136
      case BlockController.TYPE_THREAD: reportThreadProblem(place,pause,resume,time); break;
137
      }
138
    }
139
}
src/main/java/org/distorted/config/ConfigRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.config;
21

  
22
import android.opengl.GLSurfaceView;
23

  
24
import org.distorted.library.effect.EffectType;
25
import org.distorted.library.effect.VertexEffectQuaternion;
26
import org.distorted.library.effect.VertexEffectRotate;
27
import org.distorted.library.main.DistortedLibrary;
28
import org.distorted.library.main.DistortedScreen;
29
import org.distorted.objectlib.effects.BaseEffect;
30

  
31
import javax.microedition.khronos.egl.EGLConfig;
32
import javax.microedition.khronos.opengles.GL10;
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
public class ConfigRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
37
{
38
   private final ConfigSurfaceView mView;
39
   private final DistortedScreen mScreen;
40

  
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

  
43
   ConfigRenderer(ConfigSurfaceView v)
44
     {
45
     final float BRIGHTNESS = 0.30f;
46

  
47
     mView = v;
48
     mScreen = new DistortedScreen();
49
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
50
     }
51

  
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

  
54
   @Override
55
   public void onDrawFrame(GL10 glUnused)
56
     {
57
     long time = System.currentTimeMillis();
58
     mView.getObjectControl().preRender();
59
     mScreen.render(time);
60
     }
61

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

  
64
   @Override
65
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
66
      {
67
      mScreen.resize(width,height);
68
      mView.setScreenSize(width,height);
69
      }
70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
   @Override
74
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
75
      {
76
      DistortedLibrary.setMax(EffectType.VERTEX,61);    // 60 Minx quaternions + rotate
77
      VertexEffectRotate.enable();
78
      VertexEffectQuaternion.enable();
79
      BaseEffect.Type.enableEffects();
80

  
81
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
82
      }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
   public void distortedException(Exception ex)
87
     {
88
     android.util.Log.e("CONFIG", "unexpected exception: "+ex.getMessage() );
89
     }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
   DistortedScreen getScreen()
94
     {
95
     return mScreen;
96
     }
97
}
src/main/java/org/distorted/config/ConfigScreen.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.config;
21

  
22
import android.view.View;
23
import android.widget.LinearLayout;
24

  
25
import org.distorted.helpers.TransparentImageButton;
26
import org.distorted.main.R;
27
import org.distorted.main.RubikActivity;
28
import org.distorted.objectlib.main.ObjectControl;
29

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

  
32
public class ConfigScreen
33
{
34
  private TransparentImageButton mBackButton;
35

  
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

  
38
  private void setupBackButton(final ConfigActivity act)
39
    {
40
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
41
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
42
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
43

  
44
    mBackButton.setOnClickListener( new View.OnClickListener()
45
      {
46
      @Override
47
      public void onClick(View v)
48
        {
49
        ObjectControl control = act.getControl();
50
        if( control!=null ) control.unblockEverything();
51
        act.finish();
52
        }
53
      });
54
    }
55

  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

  
58
  void createScreen(final ConfigActivity act)
59
    {
60
    LinearLayout layout = act.findViewById(R.id.lowerBar);
61
    layout.removeAllViews();
62
    setupBackButton(act);
63
    layout.addView(mBackButton);
64
    }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
// PUBLIC API
68

  
69
  public ConfigScreen()
70
    {
71

  
72
    }
73
}
src/main/java/org/distorted/config/ConfigSurfaceView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.config;
21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLES30;
26
import android.opengl.GLSurfaceView;
27
import android.util.AttributeSet;
28

  
29
import com.google.firebase.crashlytics.FirebaseCrashlytics;
30

  
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objectlib.main.TwistyObjectNode;
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
public class ConfigSurfaceView extends GLSurfaceView
37
{
38
    private ObjectControl mObjectController;
39
    private ConfigRenderer mRenderer;
40
    private int mScreenWidth, mScreenHeight;
41
    private boolean mCreated;
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
    void setScreenSize(int width, int height)
46
      {
47
      mScreenWidth = width;
48
      mScreenHeight= height;
49
      mObjectController.setScreenSize(width,height);
50
      mObjectController.setObjectScale(0.80f);
51

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

  
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

  
63
    boolean isVertical()
64
      {
65
      return mScreenHeight>mScreenWidth;
66
      }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
    ObjectControl getObjectControl()
71
      {
72
      return mObjectController;
73
      }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// PUBLIC API
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

  
79
    public ConfigSurfaceView(Context context, AttributeSet attrs)
80
      {
81
      super(context,attrs);
82

  
83
      mCreated = false;
84

  
85
      if(!isInEditMode())
86
        {
87
        ConfigActivity act = (ConfigActivity)context;
88
        ConfigObjectLibInterface ref = new ConfigObjectLibInterface();
89
        mObjectController = new ObjectControl(act,ref);
90
        mRenderer = new ConfigRenderer(this);
91

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

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

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

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

  
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

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

  
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

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

  
src/main/java/org/distorted/main/RubikActivity.java
42 42

  
43 43
import com.google.firebase.analytics.FirebaseAnalytics;
44 44

  
45
import org.distorted.config.ConfigActivity;
45 46
import org.distorted.dmesh.ObjectMesh;
46 47
import org.distorted.jsons.ObjectJson;
47 48
import org.distorted.library.main.DistortedLibrary;
......
90 91
    public static final int FLAGS2=  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
91 92
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
92 93

  
94
    private static final int ACTIVITY_NUMBER = 0;
93 95
    private static final float RATIO_BAR  = 0.10f;
94 96
    private static final float RATIO_INSET= 0.08f;
95 97

  
......
106 108
    protected void onCreate(Bundle savedState)
107 109
      {
108 110
      super.onCreate(savedState);
109
      DistortedLibrary.onCreate(0);
111
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
110 112

  
111 113
      setTheme(R.style.MaterialThemeNoActionBar);
112 114
      setContentView(R.layout.main);
......
225 227
      super.onPause();
226 228
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
227 229
      view.onPause();
228
      DistortedLibrary.onPause(0);
230
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
229 231
      RubikNetwork.onPause();
230 232
      savePreferences();
231 233
      }
......
236 238
    protected void onResume() 
237 239
      {
238 240
      super.onResume();
239
      DistortedLibrary.onResume(0);
241
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
240 242
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
241 243
      view.onResume();
242 244
      restorePreferences();
......
263 265
    @Override
264 266
    protected void onDestroy() 
265 267
      {
266
      DistortedLibrary.onDestroy(0);
268
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
267 269
      super.onDestroy();
268 270
      }
269 271

  
......
587 589
      myIntent.putExtra("obj", object.ordinal());
588 590
      startActivity(myIntent);
589 591
      }
592

  
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594

  
595
    public void switchConfig(ObjectType object)
596
      {
597
      Intent myIntent = new Intent(this, ConfigActivity.class);
598
      myIntent.putExtra("obj", object.ordinal());
599
      startActivity(myIntent);
600
      }
590 601
}
src/main/java/org/distorted/screens/RubikScreenPlay.java
350 350
      @Override
351 351
      public void onClick(View v)
352 352
        {
353
        android.util.Log.e("D", "BUTTON DET CLICKED!!");
353
        act.switchConfig(mObject);
354 354
        }
355 355
      });
356 356
    }
src/main/java/org/distorted/tutorials/TutorialActivity.java
50 50
{
51 51
    private static final String URL = "https://www.youtube.com/embed/";
52 52

  
53
    private static final int ACTIVITY_NUMBER = 1;
53 54
    public static final float BAR_RATIO = 0.17f;
54 55
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
55 56
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
......
63 64
    private FirebaseAnalytics mFirebaseAnalytics;
64 65
    private static int mScreenWidth, mScreenHeight;
65 66
    private int mCurrentApiVersion;
66
    private TutorialScreen mState;
67
    private TutorialScreen mScreen;
67 68
    private String mURL;
68 69
    private int mObjectOrdinal;
69 70
    private TutorialWebView mWebView;
......
74 75
    protected void onCreate(Bundle savedState)
75 76
      {
76 77
      super.onCreate(savedState);
77
      DistortedLibrary.onCreate(1);
78
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
78 79
      setTheme(R.style.MaterialThemeNoActionBar);
79 80
      setContentView(R.layout.tutorial);
80 81

  
......
137 138
      paramsR.width = (int)(width*BAR_RATIO);
138 139
      viewR.setLayoutParams(paramsR);
139 140

  
140
      if( mState==null ) mState = new TutorialScreen();
141
      if( mScreen==null ) mScreen = new TutorialScreen();
141 142

  
142
      mState.createRightPane(this);
143
      mScreen.createRightPane(this);
143 144

  
144 145
      WebView videoView = findViewById(R.id.tutorialVideoView);
145 146
      mWebView = new TutorialWebView(videoView);
......
181 182

  
182 183
      if( mWebView!=null ) mWebView.onPause();
183 184

  
184
      DistortedLibrary.onPause(1);
185
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
185 186
      }
186 187

  
187 188
///////////////////////////////////////////////////////////////////////////////////////////////////
......
190 191
    protected void onResume() 
191 192
      {
192 193
      super.onResume();
193
      DistortedLibrary.onResume(1);
194
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
194 195
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
195 196
      view.onResume();
196 197

  
......
209 210
    protected void onDestroy() 
210 211
      {
211 212
      super.onDestroy();
212
      DistortedLibrary.onDestroy(1);
213
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
213 214
      }
214 215

  
215 216
///////////////////////////////////////////////////////////////////////////////////////////////////
......
233 234

  
234 235
    TutorialScreen getState()
235 236
      {
236
      return mState;
237
      return mScreen;
237 238
      }
238 239

  
239 240
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/layout/config.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent"
5
    android:orientation="vertical">
6

  
7
    <LinearLayout
8
        android:id="@+id/hiddenBar"
9
        android:layout_width="match_parent"
10
        android:layout_height="100dp"
11
        android:gravity="center"
12
        android:orientation="horizontal"
13
        android:background="@android:color/transparent">
14
    </LinearLayout>
15

  
16
    <LinearLayout
17
        android:id="@+id/upperBar"
18
        android:layout_width="match_parent"
19
        android:layout_height="100dp"
20
        android:gravity="center"
21
        android:orientation="horizontal"
22
        android:background="@android:color/transparent">
23
    </LinearLayout>
24

  
25
    <LinearLayout
26
        android:layout_width="match_parent"
27
        android:layout_height="match_parent"
28
        android:gravity="center"
29
        android:orientation="vertical"
30
        android:background="@android:color/transparent">
31

  
32
        <org.distorted.config.ConfigSurfaceView
33
           android:id="@+id/configSurfaceView"
34
           android:layout_width="match_parent"
35
           android:layout_height="0dp"
36
           android:layout_weight="1"/>
37

  
38
        <ScrollView
39
           android:id="@+id/configScroll"
40
           android:layout_width="match_parent"
41
           android:layout_height="0dp"
42
           android:layout_weight="1"/>
43

  
44
    </LinearLayout>
45

  
46
    <LinearLayout
47
        android:id="@+id/lowerBar"
48
        android:layout_width="match_parent"
49
        android:layout_height="100dp"
50
        android:orientation="horizontal"
51
        android:background="@android:color/transparent">
52
    </LinearLayout>
53

  
54
</LinearLayout>

Also available in: Unified diff