Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 598de3ee

1 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4 fdec60a3 Leszek Koltunski
// This file is part of Magic Cube.                                                              //
5 0c52af30 Leszek Koltunski
//                                                                                               //
6 fdec60a3 Leszek Koltunski
// Magic Cube is free software: you can redistribute it and/or modify                            //
7 0c52af30 Leszek Koltunski
// 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 fdec60a3 Leszek Koltunski
// Magic Cube is distributed in the hope that it will be useful,                                 //
12 0c52af30 Leszek Koltunski
// 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 fdec60a3 Leszek Koltunski
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 1f9772f3 Leszek Koltunski
package org.distorted.main;
21 0c52af30 Leszek Koltunski
22 b6468abb Leszek Koltunski
import android.content.Intent;
23 33499c56 Leszek Koltunski
import android.content.SharedPreferences;
24 b1e9596b Leszek Koltunski
import android.os.Build;
25 0c52af30 Leszek Koltunski
import android.os.Bundle;
26 b1e9596b Leszek Koltunski
import android.os.LocaleList;
27 33499c56 Leszek Koltunski
import android.preference.PreferenceManager;
28 e3c74c0f Leszek Koltunski
29
import android.util.DisplayMetrics;
30 fd0b901a Leszek Koltunski
import android.view.DisplayCutout;
31 0254cfd7 Leszek Koltunski
import android.view.View;
32 1cb36646 Leszek Koltunski
import android.view.ViewGroup;
33 c9556e1e Leszek Koltunski
import android.view.WindowManager;
34 1cb36646 Leszek Koltunski
import android.widget.LinearLayout;
35 0c52af30 Leszek Koltunski
36 1b3cbd5b Leszek Koltunski
import com.google.firebase.analytics.FirebaseAnalytics;
37
38 2d9fc972 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
39 b1e9596b Leszek Koltunski
import org.distorted.dialogs.RubikDialogPrivacy;
40 1f9772f3 Leszek Koltunski
import org.distorted.effects.BaseEffect;
41 809c3432 Leszek Koltunski
import org.distorted.helpers.BlockController;
42 55e6be1d Leszek Koltunski
import org.distorted.helpers.TwistyActivity;
43
import org.distorted.helpers.TwistyPreRender;
44 e1111500 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
45 0c52af30 Leszek Koltunski
46 f8eece7d Leszek Koltunski
import org.distorted.library.main.DistortedScreen;
47 7aa4c349 Leszek Koltunski
import org.distorted.library.type.Static4D;
48 9c2f0c91 Leszek Koltunski
import org.distorted.objects.TwistyObject;
49 6a083c6a Leszek Koltunski
import org.distorted.network.RubikScores;
50
import org.distorted.network.RubikNetwork;
51 9c2f0c91 Leszek Koltunski
import org.distorted.objects.ObjectList;
52 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
53
import org.distorted.screens.RubikScreenPlay;
54 eaf87d1d Leszek Koltunski
import org.distorted.tutorials.TutorialActivity;
55 211b48f2 Leszek Koltunski
56 b1e9596b Leszek Koltunski
import java.util.Locale;
57
58 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
59
60 55e6be1d Leszek Koltunski
public class RubikActivity extends TwistyActivity
61 0c52af30 Leszek Koltunski
{
62 054fbee1 Leszek Koltunski
    public static final float PADDING             = 0.01f;
63
    public static final float MARGIN              = 0.004f;
64
    public static final float LARGE_MARGIN        = 0.025f;
65
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
66
    public static final float TITLE_TEXT_SIZE     = 0.06f;
67 7ea57482 Leszek Koltunski
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
68
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
69 045857e5 Leszek Koltunski
    public static final float MENU_ITEM_SIZE      = 0.11f;
70 5de2c572 Leszek Koltunski
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
71
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
72 362807f0 Leszek Koltunski
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
73
    public static final float SCORES_ITEM_TEXT    = 0.030f;
74 ef1f3e34 Leszek Koltunski
    public static final float TUTORIAL_ITEM_TEXT  = 0.100f;
75 eb376d3a Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
76
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
77
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
78
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
79 e3c74c0f Leszek Koltunski
80 af7b68e6 Leszek Koltunski
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
81 ffd68f35 Leszek Koltunski
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
82
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
83
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
84
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
85
86 e365b6c2 Leszek Koltunski
    public static final int FLAGS2=  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
87
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
88
89 598de3ee Leszek Koltunski
    private static final float RATIO_BAR  = 0.10f;
90
    private static final float RATIO_INSET= 0.08f;
91
92 c3ffcf58 Leszek Koltunski
    private boolean mJustStarted;
93 1b3cbd5b Leszek Koltunski
    private FirebaseAnalytics mFirebaseAnalytics;
94 f6a9c538 Leszek Koltunski
    private static int mScreenWidth, mScreenHeight;
95 b1e9596b Leszek Koltunski
    private boolean mPolicyAccepted, mIsChinese;
96 0254cfd7 Leszek Koltunski
    private int mCurrentApiVersion;
97 598de3ee Leszek Koltunski
    private int mHeightUpperBar, mHeightLowerBar;
98 c3ffcf58 Leszek Koltunski
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
101 0c52af30 Leszek Koltunski
    @Override
102 34747dd1 Leszek Koltunski
    protected void onCreate(Bundle savedState)
103 0c52af30 Leszek Koltunski
      {
104 34747dd1 Leszek Koltunski
      super.onCreate(savedState);
105 d7de3072 Leszek Koltunski
      DistortedLibrary.onCreate(0);
106
107 f6fcf06a Leszek Koltunski
      setTheme(R.style.CustomActivityThemeNoActionBar);
108 1cbcc6bf Leszek Koltunski
      setContentView(R.layout.main);
109 c3ffcf58 Leszek Koltunski
110
      mJustStarted = true;
111 1b3cbd5b Leszek Koltunski
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
112 e3c74c0f Leszek Koltunski
113
      DisplayMetrics displaymetrics = new DisplayMetrics();
114
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
115 88fb92ba Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
116
      mScreenHeight=displaymetrics.heightPixels;
117 b1e9596b Leszek Koltunski
118
      mIsChinese = localeIsChinese();
119 55e6be1d Leszek Koltunski
      unlock();
120 0254cfd7 Leszek Koltunski
121
      hideNavigationBar();
122 e8f6670f Leszek Koltunski
      cutoutHack();
123 598de3ee Leszek Koltunski
      computeBarHeights();
124 0254cfd7 Leszek Koltunski
      // askForPermissions();
125
      }
126
127 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
128
// this does not include possible insets
129
130
    private void computeBarHeights()
131
      {
132
      float height = getScreenHeightInPixels();
133
      int barHeight = (int)(height*RATIO_BAR);
134
      mHeightLowerBar = barHeight;
135
      mHeightUpperBar = barHeight;
136
      }
137
138 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
139
140
    private void hideNavigationBar()
141
      {
142 c9556e1e Leszek Koltunski
      mCurrentApiVersion = Build.VERSION.SDK_INT;
143 0254cfd7 Leszek Koltunski
144
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
145
        {
146
        final View decorView = getWindow().getDecorView();
147
148 c9556e1e Leszek Koltunski
        decorView.setSystemUiVisibility(FLAGS);
149
150 0254cfd7 Leszek Koltunski
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
151
          {
152
          @Override
153
          public void onSystemUiVisibilityChange(int visibility)
154
            {
155
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
156
              {
157 ffd68f35 Leszek Koltunski
              decorView.setSystemUiVisibility(FLAGS);
158 0254cfd7 Leszek Koltunski
              }
159
            }
160
          });
161
        }
162
      }
163
164 1cb36646 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
165
166
    @Override
167
    public void onAttachedToWindow()
168
      {
169 fd0b901a Leszek Koltunski
      super.onAttachedToWindow();
170
171 e8f6670f Leszek Koltunski
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
172
        {
173
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
174
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
175
176
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
177
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
178 598de3ee Leszek Koltunski
        paramsHid.height = (int)(insetHeight*RATIO_INSET);
179 e8f6670f Leszek Koltunski
        layoutHid.setLayoutParams(paramsHid);
180 598de3ee Leszek Koltunski
        mHeightUpperBar += paramsHid.height;
181 e8f6670f Leszek Koltunski
        }
182
183 1cb36646 Leszek Koltunski
      float height = getScreenHeightInPixels();
184
185
      LinearLayout layoutTop = findViewById(R.id.upperBar);
186
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
187
188
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
189 598de3ee Leszek Koltunski
      paramsTop.height = (int)(height*RATIO_BAR);
190 1cb36646 Leszek Koltunski
      layoutTop.setLayoutParams(paramsTop);
191
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
192 598de3ee Leszek Koltunski
      paramsBot.height = (int)(height*RATIO_BAR);
193 1cb36646 Leszek Koltunski
      layoutBot.setLayoutParams(paramsBot);
194
      }
195
196 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
197 e8f6670f Leszek Koltunski
// do not avoid cutouts
198 c9556e1e Leszek Koltunski
199 e8f6670f Leszek Koltunski
    private void cutoutHack()
200 c9556e1e Leszek Koltunski
      {
201
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
202
        {
203
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
204
        }
205
      }
206
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208 0254cfd7 Leszek Koltunski
209
    @Override
210
    public void onWindowFocusChanged(boolean hasFocus)
211
      {
212
      super.onWindowFocusChanged(hasFocus);
213
214
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
215
        {
216 ffd68f35 Leszek Koltunski
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
217 0254cfd7 Leszek Koltunski
        }
218
      }
219
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221
222
    private void askForPermissions()
223
      {
224 2f5783d4 Leszek Koltunski
      final int REQUEST_EXTERNAL_STORAGE = 1;
225
226
      String[] PERMISSIONS_STORAGE =
227
        {
228 fcc0e034 Leszek Koltunski
        android.Manifest.permission.READ_EXTERNAL_STORAGE,
229
        android.Manifest.permission.WRITE_EXTERNAL_STORAGE
230 2f5783d4 Leszek Koltunski
        };
231
232 fcc0e034 Leszek Koltunski
      int permission = androidx.core.app.ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
233 2f5783d4 Leszek Koltunski
234 fcc0e034 Leszek Koltunski
      if (permission != android.content.pm.PackageManager.PERMISSION_GRANTED)
235 2f5783d4 Leszek Koltunski
        {
236 fcc0e034 Leszek Koltunski
        androidx.core.app.ActivityCompat.requestPermissions( this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE );
237 2f5783d4 Leszek Koltunski
        }
238 0c52af30 Leszek Koltunski
      }
239
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
    
242
    @Override
243
    protected void onPause() 
244
      {
245 82f42eeb Leszek Koltunski
      super.onPause();
246 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
247 0c52af30 Leszek Koltunski
      view.onPause();
248 d7de3072 Leszek Koltunski
      DistortedLibrary.onPause(0);
249 809c3432 Leszek Koltunski
      BlockController.onPause();
250 6a083c6a Leszek Koltunski
      RubikNetwork.onPause();
251 33499c56 Leszek Koltunski
      savePreferences();
252 0c52af30 Leszek Koltunski
      }
253
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255
    
256
    @Override
257
    protected void onResume() 
258
      {
259
      super.onResume();
260 d7de3072 Leszek Koltunski
      DistortedLibrary.onResume(0);
261 809c3432 Leszek Koltunski
      BlockController.onResume();
262 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
263 0c52af30 Leszek Koltunski
      view.onResume();
264 e03e0352 Leszek Koltunski
      view.initialize();
265 33499c56 Leszek Koltunski
      restorePreferences();
266 f5da732a Leszek Koltunski
      ScreenList.setScreen(this);
267 8badfe2a Leszek Koltunski
      unblockEverything();
268 4888e97c Leszek Koltunski
269 c3ffcf58 Leszek Koltunski
      if( mJustStarted )
270
        {
271
        mJustStarted = false;
272 82ce8e64 Leszek Koltunski
        RubikScores scores = RubikScores.getInstance();
273
        scores.incrementNumRuns();
274
        scores.setCountry(this);
275 c3ffcf58 Leszek Koltunski
        }
276
277 53f23b64 Leszek Koltunski
      boolean success = false;
278 f5da732a Leszek Koltunski
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
279 4888e97c Leszek Koltunski
      int object = play.getObject();
280
      int size   = play.getSize();
281
282 9c2f0c91 Leszek Koltunski
      if( object>=0 && object< ObjectList.NUM_OBJECTS )
283 4c0cd600 Leszek Koltunski
        {
284 9c2f0c91 Leszek Koltunski
        ObjectList obj = ObjectList.getObject(object);
285 4c0cd600 Leszek Koltunski
        int[] sizes = obj.getSizes();
286 9c2f0c91 Leszek Koltunski
        int sizeIndex = ObjectList.getSizeIndex(object,size);
287 4c0cd600 Leszek Koltunski
288 53f23b64 Leszek Koltunski
        if( sizeIndex>=0 && sizeIndex<sizes.length )
289 4c0cd600 Leszek Koltunski
          {
290 53f23b64 Leszek Koltunski
          success = true;
291 5a4d4fba Leszek Koltunski
          view.getPreRender().changeObject(obj,size);
292 4c0cd600 Leszek Koltunski
          }
293 53f23b64 Leszek Koltunski
        }
294
295
      if( !success )
296
        {
297 fcd5b990 Leszek Koltunski
        ObjectList obj = ObjectList.getObject(RubikScreenPlay.DEF_OBJECT);
298
        int s = RubikScreenPlay.DEF_SIZE;
299 53f23b64 Leszek Koltunski
300 7b7d65ce Leszek Koltunski
        play.setObjectAndSize(this,obj,s);
301 5a4d4fba Leszek Koltunski
        view.getPreRender().changeObject(obj,s);
302 4c0cd600 Leszek Koltunski
        }
303 b1e9596b Leszek Koltunski
304
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
305 0c52af30 Leszek Koltunski
      }
306
    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308
    
309
    @Override
310
    protected void onDestroy() 
311
      {
312 d7de3072 Leszek Koltunski
      DistortedLibrary.onDestroy(0);
313 0c52af30 Leszek Koltunski
      super.onDestroy();
314
      }
315
316 33499c56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
317
318
    private void savePreferences()
319
      {
320
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
321
      SharedPreferences.Editor editor = preferences.edit();
322
323 b1e9596b Leszek Koltunski
      editor.putBoolean("policyAccepted", mPolicyAccepted);
324
325 211b48f2 Leszek Koltunski
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
326 33499c56 Leszek Koltunski
        {
327
        BaseEffect.Type.getType(i).savePreferences(editor);
328
        }
329
330 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
331 211b48f2 Leszek Koltunski
        {
332 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
333 211b48f2 Leszek Koltunski
        }
334 33499c56 Leszek Koltunski
335 fcd5b990 Leszek Koltunski
      ScreenList.savePreferences(editor);
336 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
337 5a4d4fba Leszek Koltunski
      view.getPreRender().savePreferences(editor);
338 0333d81e Leszek Koltunski
339 33499c56 Leszek Koltunski
      editor.apply();
340
      }
341
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
344
    private void restorePreferences()
345
      {
346
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
347
348 b1e9596b Leszek Koltunski
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
349
350 33499c56 Leszek Koltunski
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
351 4235de9b Leszek Koltunski
        {
352 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
353 4235de9b Leszek Koltunski
        }
354 33499c56 Leszek Koltunski
355 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
356 211b48f2 Leszek Koltunski
        {
357 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
358 211b48f2 Leszek Koltunski
        }
359 33499c56 Leszek Koltunski
360 fcd5b990 Leszek Koltunski
      ScreenList.restorePreferences(preferences);
361 0333d81e Leszek Koltunski
362
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
363 5a4d4fba Leszek Koltunski
      view.getPreRender().restorePreferences(preferences);
364 ee4e7896 Leszek Koltunski
365
      RubikScores scores = RubikScores.getInstance();
366
367
      if( scores.isVerified() )
368
        {
369
        FirebaseAnalytics analytics = getAnalytics();
370
        analytics.setUserId(scores.getName());
371
        }
372 f3e12931 Leszek Koltunski
      }
373
374 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
375
376
    private void PrivacyPolicy()
377
      {
378
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
379
      priDiag.show(getSupportFragmentManager(), null);
380
      }
381
382 2d9fc972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
383
384 e7e0a94d Leszek Koltunski
    void OpenGLError()
385 2d9fc972 Leszek Koltunski
      {
386
      RubikDialogError errDiag = new RubikDialogError();
387
      errDiag.show(getSupportFragmentManager(), null);
388
      }
389
390 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
391 47ba5ddc Leszek Koltunski
// PUBLIC API
392 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
393
394
    public FirebaseAnalytics getAnalytics()
395
      {
396
      return mFirebaseAnalytics;
397
      }
398
399 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
400
401
    public int getHeightUpperBar()
402
      {
403
      return mHeightUpperBar;
404
      }
405
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407
408
    public int getHeightLowerBar()
409
      {
410
      return mHeightLowerBar;
411
      }
412
413 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
414
415 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
416 aa171dee Leszek Koltunski
      {
417
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
418 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
419
      return pre.getObject();
420 8becce57 Leszek Koltunski
      }
421
422 f8eece7d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
423
424
    public DistortedScreen getScreen()
425
      {
426
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
427
      RubikRenderer renderer = view.getRenderer();
428
      return renderer.getScreen();
429
      }
430
431 e3c74c0f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
432
433 8ba7aeb1 Leszek Koltunski
    public RubikPreRender getPreRender()
434 e3c74c0f Leszek Koltunski
      {
435 8ba7aeb1 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
436
      return view.getPreRender();
437 e3c74c0f Leszek Koltunski
      }
438
439 55e6be1d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
440
441
    public TwistyPreRender getTwistyPreRender()
442
      {
443
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
444
      return view.getPreRender();
445
      }
446
447 88fb92ba Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
448
449 8ba7aeb1 Leszek Koltunski
    public RubikSurfaceView getSurfaceView()
450 88fb92ba Leszek Koltunski
      {
451 8ba7aeb1 Leszek Koltunski
      return findViewById(R.id.rubikSurfaceView);
452 88fb92ba Leszek Koltunski
      }
453
454 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
455
456 8ba7aeb1 Leszek Koltunski
    public int getScreenWidthInPixels()
457 8becce57 Leszek Koltunski
      {
458 8ba7aeb1 Leszek Koltunski
      return mScreenWidth;
459
      }
460
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462
463
    public int getScreenHeightInPixels()
464
      {
465
      return mScreenHeight;
466 aa171dee Leszek Koltunski
      }
467
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469
470 9c2f0c91 Leszek Koltunski
    public void changeObject(ObjectList newObject, int newSize, boolean reportChange)
471 769d7b9f Leszek Koltunski
      {
472
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
473 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
474 7eae2d49 Leszek Koltunski
475
      if( reportChange )
476
        {
477 9c2f0c91 Leszek Koltunski
        TwistyObject oldObject = pre.getObject();
478 7eae2d49 Leszek Koltunski
479 03822c33 Leszek Koltunski
        if( oldObject!=null )
480
          {
481
          ObjectList oldList = oldObject.getObjectList();
482
          int oldNum = oldObject.getNumLayers();
483
          float fps = view.getRenderer().getFPS();
484
          fps = (int)(fps+0.5f);
485
          StringBuilder name = new StringBuilder();
486
          name.append(oldList.name());
487
          name.append('_');
488
          name.append(oldNum);
489
          name.append(' ');
490
          name.append(fps);
491
          name.append(" --> ");
492
          name.append(newObject.name());
493
          name.append('_');
494
          name.append(newSize);
495
496
          if( BuildConfig.DEBUG )
497 7eae2d49 Leszek Koltunski
            {
498 03822c33 Leszek Koltunski
            android.util.Log.e("rubik", name.toString());
499
            }
500
          else
501
            {
502
            FirebaseAnalytics analytics = getAnalytics();
503
504
            if( analytics!=null )
505
              {
506
              Bundle bundle = new Bundle();
507
              bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
508
              analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
509
              }
510 7eae2d49 Leszek Koltunski
            }
511
          }
512
        }
513
514
      pre.changeObject(newObject,newSize);
515 2e8ec627 Leszek Koltunski
      }
516
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518
519 9c2f0c91 Leszek Koltunski
    public void setupObject(ObjectList object, int size, int[][] moves)
520 2e8ec627 Leszek Koltunski
      {
521
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
522 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
523
      pre.setupObject(object,size,moves);
524 769d7b9f Leszek Koltunski
      }
525
526 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
527
528
    public static int getDrawableSize()
529
      {
530
      if( mScreenHeight<1000 )
531
        {
532
        return 0;
533
        }
534
      if( mScreenHeight<1600 )
535
        {
536
        return 1;
537
        }
538 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
539
        {
540
        return 2;
541
        }
542 f6a9c538 Leszek Koltunski
543 31a9f38d Leszek Koltunski
      return 3;
544 f6a9c538 Leszek Koltunski
      }
545
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547
548 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
549 f6a9c538 Leszek Koltunski
      {
550
      int size = getDrawableSize();
551
552
      switch(size)
553
        {
554
        case 0 : return small;
555
        case 1 : return medium;
556 31a9f38d Leszek Koltunski
        case 2 : return big;
557
        default: return huge;
558 f6a9c538 Leszek Koltunski
        }
559
      }
560
561 314bffaf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
562
563
    public void setControlState(boolean on)
564
      {
565
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
566
      RubikRenderer renderer = view.getRenderer();
567
      renderer.setControlState(on);
568
      }
569
570 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
571
572
    public void acceptPrivacy()
573
      {
574
      mPolicyAccepted = true;
575
      }
576
577
///////////////////////////////////////////////////////////////////////////////////////////////////
578
579
    public void declinePrivacy()
580
      {
581
      finish();
582
      }
583
584
///////////////////////////////////////////////////////////////////////////////////////////////////
585
586
    public static boolean localeIsChinese()
587
      {
588
      String language;
589
590
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
591
        {
592
        language= LocaleList.getDefault().get(0).getLanguage();
593
        }
594
      else
595
        {
596
        language= Locale.getDefault().getLanguage();
597
        }
598
599
      return language.equals("zh");
600
      }
601
602 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
603
604
    public boolean isVertical()
605
      {
606
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
607
      return view.isVertical();
608
      }
609 46405bb4 Leszek Koltunski
610 f5da732a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
611
612 809c3432 Leszek Koltunski
    public void blockEverything(int place)
613 f5da732a Leszek Koltunski
      {
614 55e6be1d Leszek Koltunski
      setLock();
615 f5da732a Leszek Koltunski
616 55e6be1d Leszek Koltunski
      TwistyPreRender pre = getPreRender();
617 809c3432 Leszek Koltunski
      pre.blockEverything(place);
618 8badfe2a Leszek Koltunski
619
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
620
      play.setLockState(this);
621 f5da732a Leszek Koltunski
      }
622
623
///////////////////////////////////////////////////////////////////////////////////////////////////
624
625
    public void unblockEverything()
626
      {
627 55e6be1d Leszek Koltunski
      unsetLock();
628 f5da732a Leszek Koltunski
629 55e6be1d Leszek Koltunski
      TwistyPreRender pre = getPreRender();
630 f5da732a Leszek Koltunski
      pre.unblockEverything();
631 8badfe2a Leszek Koltunski
632
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
633
      play.setLockState(this);
634 f5da732a Leszek Koltunski
      }
635
636 7aa4c349 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
637
638
    public Static4D getCurrQuat()
639
      {
640
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
641
      return view.getQuat();
642
      }
643
644 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
645
646 79bf5d8b Leszek Koltunski
    public void switchTutorial(String url, ObjectList object, int size)
647 b6468abb Leszek Koltunski
      {
648
      Intent myIntent = new Intent(this, TutorialActivity.class);
649 2971588c Leszek Koltunski
      myIntent.putExtra("url", url);
650 79bf5d8b Leszek Koltunski
      myIntent.putExtra("obj", object.ordinal());
651
      myIntent.putExtra("siz", size);
652 b6468abb Leszek Koltunski
      startActivity(myIntent);
653
      }
654 0c52af30 Leszek Koltunski
}