Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ b1629e16

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.main;
11

    
12
import java.io.InputStream;
13
import java.util.Locale;
14

    
15
import android.content.Intent;
16
import android.content.SharedPreferences;
17
import android.content.pm.PackageInfo;
18
import android.content.pm.PackageManager;
19
import android.os.Build;
20
import android.os.Bundle;
21
import android.os.LocaleList;
22
import android.preference.PreferenceManager;
23

    
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
import com.google.firebase.inappmessaging.FirebaseInAppMessaging;
35

    
36
import org.distorted.config.ConfigActivity;
37
import org.distorted.bandaged.BandagedCreatorActivity;
38
import org.distorted.dialogs.RubikDialogStarsExplain;
39
import org.distorted.library.main.DistortedLibrary;
40

    
41
import org.distorted.library.main.DistortedScreen;
42
import org.distorted.messaging.RubikInAppMessanging;
43
import org.distorted.objectlib.main.ObjectControl;
44
import org.distorted.objectlib.main.TwistyObject;
45
import org.distorted.objectlib.effects.BaseEffect;
46

    
47
import org.distorted.dialogs.RubikDialogError;
48
import org.distorted.dialogs.RubikDialogPrivacy;
49
import org.distorted.external.RubikScores;
50
import org.distorted.external.RubikNetwork;
51
import org.distorted.objects.RubikObject;
52
import org.distorted.objects.RubikObjectList;
53
import org.distorted.purchase.PurchaseActivity;
54
import org.distorted.screens.RubikScreenSolving;
55
import org.distorted.screens.ScreenList;
56
import org.distorted.screens.RubikScreenPlay;
57
import org.distorted.tutorials.TutorialActivity;
58

    
59
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
60

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

    
63
public class RubikActivity extends AppCompatActivity
64
{
65
    public static final boolean SHOW_DOWNLOADED_DEBUG = false;
66
    public static final boolean SHOW_IAP_DEBUG        = true;
67
    public static final boolean USE_IAP               = true;
68

    
69
    public static final float PADDING             = 0.01f;
70
    public static final float SMALL_MARGIN        = 0.004f;
71
    public static final float MEDIUM_MARGIN       = 0.015f;
72
    public static final float LARGE_MARGIN        = 0.025f;
73
    public static final float POPUP_PADDING       = 0.045f;
74
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
75
    public static final float TITLE_TEXT_SIZE     = 0.06f;
76
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
77
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
78
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
79
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
80
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
81
    public static final float SCORES_ITEM_TEXT    = 0.030f;
82
    public static final float TUTORIAL_ITEM_TEXT  = 0.100f;
83
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
84
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
85
    public static final float MENU_MAIN_TEXT_SIZE = 0.047f;
86
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
87
    public static final float TAB_WIDTH           = 0.100f;
88
    public static final float TAB_HEIGHT          = 0.100f;
89
    public static final float MENU_BUTTON_HEIGHT  = 0.115f;
90

    
91
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
92
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
93
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
94
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
95
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
96

    
97
    private static final int ACTIVITY_NUMBER = 0;
98
    private static final float RATIO_BAR  = 0.10f;
99
    private static final float RATIO_INSET= 0.09f;
100

    
101
    private static final String KEY_PLAY = "movesController_play";
102
    private static final String KEY_SOLV = "movesController_solv";
103

    
104
    private boolean mJustStarted;
105
    private FirebaseAnalytics mFirebaseAnalytics;
106
    private static int mScreenWidth, mScreenHeight;
107
    private boolean mPolicyAccepted, mIsChinese;
108
    private int mCurrentApiVersion;
109
    private int mHeightUpperBar, mHeightLowerBar;
110
    private int mOldVersion1, mOldVersion2, mOldVersion3;
111
    private String mOldVersion, mCurrVersion;
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
    @Override
116
    protected void onCreate(Bundle savedState)
117
      {
118
      super.onCreate(savedState);
119
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
120

    
121
      setTheme(R.style.MaterialThemeNoActionBar);
122
      setContentView(R.layout.main);
123

    
124
      mJustStarted = true;
125
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
126
      mIsChinese = localeIsChinese();
127

    
128
      DisplayMetrics displaymetrics = new DisplayMetrics();
129
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
130
      mScreenWidth =displaymetrics.widthPixels;
131
      mScreenHeight=displaymetrics.heightPixels;
132

    
133
      hideNavigationBar();
134
      cutoutHack();
135
      computeBarHeights();
136

    
137
      mCurrVersion = getAppVers();
138

    
139
      Thread thread = new Thread()
140
        {
141
        public void run()
142
          {
143
          RubikInAppMessanging listener = new RubikInAppMessanging();
144
          FirebaseInAppMessaging.getInstance().addClickListener(listener);
145
          }
146
        };
147

    
148
      thread.start();
149
      }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152
// this does not include possible insets
153

    
154
    private void computeBarHeights()
155
      {
156
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
157
      mHeightLowerBar = barHeight;
158
      mHeightUpperBar = barHeight;
159

    
160
      LinearLayout layoutTop = findViewById(R.id.upperBar);
161
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
162

    
163
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
164
      paramsTop.height = mHeightUpperBar;
165
      layoutTop.setLayoutParams(paramsTop);
166
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
167
      paramsBot.height = mHeightLowerBar;
168
      layoutBot.setLayoutParams(paramsBot);
169
      }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
    private void hideNavigationBar()
174
      {
175
      mCurrentApiVersion = Build.VERSION.SDK_INT;
176

    
177
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
178
        {
179
        final View decorView = getWindow().getDecorView();
180

    
181
        decorView.setSystemUiVisibility(FLAGS);
182

    
183
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
184
          {
185
          @Override
186
          public void onSystemUiVisibilityChange(int visibility)
187
            {
188
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
189
              {
190
              decorView.setSystemUiVisibility(FLAGS);
191
              }
192
            }
193
          });
194
        }
195
      }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
    @Override
200
    public void onAttachedToWindow()
201
      {
202
      super.onAttachedToWindow();
203

    
204
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
205
        {
206
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
207
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
208

    
209
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
210
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
211
        paramsHid.height = (int)(insetHeight*RATIO_INSET);
212
        layoutHid.setLayoutParams(paramsHid);
213
        mHeightUpperBar += paramsHid.height;
214
        }
215
      }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218
// do not avoid cutouts
219

    
220
    private void cutoutHack()
221
      {
222
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
223
        {
224
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
225
        }
226
      }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
    @Override
231
    public void onWindowFocusChanged(boolean hasFocus)
232
      {
233
      super.onWindowFocusChanged(hasFocus);
234

    
235
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
236
        {
237
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
238
        }
239
      }
240

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242
    
243
    @Override
244
    protected void onPause() 
245
      {
246
      super.onPause();
247
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
248
      view.onPause();
249
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
250
      RubikNetwork.onPause();
251
      savePreferences();
252
      }
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255
    
256
    @Override
257
    protected void onResume() 
258
      {
259
      super.onResume();
260
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
261
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
262
      view.onResume();
263

    
264
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
265
      restorePreferences(preferences,mJustStarted);
266
      ScreenList.setScreen(this);
267
      unblockEverything();
268
      restoreMoves(preferences);
269

    
270
      if( mJustStarted )
271
        {
272
        mJustStarted = false;
273
        RubikScores scores = RubikScores.getInstance();
274
        scores.incrementNumRuns();
275
        scores.setCountry(this);
276
        RubikObjectList.restoreMeshState(preferences);
277
        }
278

    
279
      int object = RubikObjectList.getCurrObject();
280
      changeIfDifferent(object,view.getObjectControl());
281

    
282
      if( mIsChinese && !mPolicyAccepted ) privacyPolicy();
283

    
284
      if( USE_IAP )
285
        {
286
        if( mOldVersion!=null && !mOldVersion.equals("") && oldVersionLessThan(1,11,5) && !mCurrVersion.equals("1.11.4") )
287
          {
288
          explainStars();
289
          }
290
        else
291
          {
292
          view.setShowStars();
293
          }
294
        }
295
      }
296

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

    
299
    private void privacyPolicy()
300
      {
301
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
302
      priDiag.show(getSupportFragmentManager(), null);
303
      }
304

    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

    
307
    private void explainStars()
308
      {
309
      RubikDialogStarsExplain staDiag = new RubikDialogStarsExplain();
310
      staDiag.show(getSupportFragmentManager(), null);
311
      }
312

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314
    
315
    @Override
316
    protected void onDestroy() 
317
      {
318
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
319
      super.onDestroy();
320
      }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
    private String getAppVers()
325
      {
326
      try
327
        {
328
        PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
329
        return pInfo.versionName;
330
        }
331
      catch (PackageManager.NameNotFoundException e)
332
        {
333
        return "unknown";
334
        }
335
      }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
    private void savePreferences()
340
      {
341
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
342
      SharedPreferences.Editor editor = preferences.edit();
343

    
344
      editor.putBoolean("policyAccepted", mPolicyAccepted);
345
      editor.putString("appVersion", mCurrVersion );
346

    
347
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
348
        {
349
        BaseEffect.Type.getType(i).savePreferences(editor);
350
        }
351

    
352
      for (int i = 0; i< ScreenList.LENGTH; i++)
353
        {
354
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
355
        }
356

    
357
      RubikObjectList.savePreferences(editor);
358
      RubikObjectList.saveMeshState(editor);
359
      ScreenList.savePreferences(editor);
360
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
361
      view.getObjectControl().savePreferences(editor);
362

    
363
      ScreenList curr = ScreenList.getCurrentScreen();
364

    
365
      if( curr==ScreenList.PLAY )
366
        {
367
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
368
        play.saveMovePreferences(KEY_PLAY,editor);
369
        }
370
      if( curr==ScreenList.SOLV )
371
        {
372
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
373
        solv.saveMovePreferences(KEY_SOLV,editor);
374
        }
375

    
376
      boolean success = editor.commit();
377
      if( !success ) android.util.Log.e("D", "Failed to save preferences");
378
      }
379

    
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381

    
382
    private void restorePreferences(SharedPreferences preferences, boolean justStarted)
383
      {
384
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
385
      mOldVersion = preferences.getString("appVersion","");
386
      parseOldVersion(mOldVersion);
387

    
388
      RubikObjectList.restorePreferences(this,preferences,justStarted);
389

    
390
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
391
        {
392
        BaseEffect.Type.getType(i).restorePreferences(preferences);
393
        }
394

    
395
      for (int i=0; i<ScreenList.LENGTH; i++)
396
        {
397
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
398
        }
399

    
400
      RubikScores scores = RubikScores.getInstance();
401

    
402
      if( scores.isVerified() )
403
        {
404
        FirebaseAnalytics analytics = getAnalytics();
405
        analytics.setUserId(scores.getName());
406
        }
407

    
408
      // all old users upgrading from version <1.11.4, where there was no concept of 'stars',
409
      // get all the stars they have earned
410
      int numStars = scores.getNumStars();
411

    
412
      if( justStarted && numStars==0 && oldVersionLessThan(1,11,4) )
413
        {
414
        scores.correctNumStars();
415
        }
416

    
417
      // in 1.11.5 we have introduced IAP. When upgrading from something less than 1.11.5 to
418
      // something at least 1.11.5, mark all solved objects as free.
419
      // this needs to be after the above ScreenList.getScreen(i).getScreenClass().restorePreferences()
420
      // as that restores the Records which we need here
421
      // also needs to be after RubikObjectList.restorePreferences()
422
      if( USE_IAP && justStarted && oldVersionLessThan(1,11,5) && !mCurrVersion.equals("1.11.4") )
423
        {
424
        RubikObjectList.firstUpgradeMarkAllSolvedAsFree();
425
        }
426

    
427
      ScreenList.restorePreferences(preferences);
428

    
429
      // Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their
430
      // case the 'mOldVersion' - version of the app which saved the preferences on the last
431
      // go - is empty.
432
      // Between versions 1.8.6 and 1.9.0, the order of the cubits in TwistyCube has changed.
433
      // If someone has scrambled the cube with v. 1.8.6, then upgraded to 1.9.0 and re-started
434
      // the app, because of the different order of the cubits - his cube would be messed up.
435
      // So in such case, i.e. on fresh upgrade from version<=1.8.6 to version>=1.9.0, do not
436
      // restore the object scrambling.
437

    
438
      if( !mOldVersion.equals("") )
439
        {
440
        RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
441
        view.getObjectControl().restorePreferences(preferences);
442
        }
443
      }
444

    
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446

    
447
    private void parseOldVersion(String version)
448
      {
449
      if( version==null ) return;
450

    
451
      try
452
        {
453
        String[] parts = version.split("\\.");
454

    
455
        if( parts.length==3 )
456
          {
457
          mOldVersion1 = Integer.parseInt(parts[0]);
458
          mOldVersion2 = Integer.parseInt(parts[1]);
459
          mOldVersion3 = Integer.parseInt(parts[2]);
460
          }
461
        }
462
      catch(Exception ignored)
463
        {
464
        mOldVersion1 = 0;
465
        mOldVersion2 = 0;
466
        mOldVersion3 = 0;
467
        }
468
      }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

    
472
    private boolean oldVersionLessThan(int v1, int v2, int v3)
473
      {
474
      if( mOldVersion1<v1 ) return true;
475
      if( mOldVersion1>v1 ) return false;
476
      if( mOldVersion2<v2 ) return true;
477
      if( mOldVersion2>v2 ) return false;
478
      return mOldVersion3<v3;
479
      }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

    
483
    private void restoreMoves(SharedPreferences preferences)
484
      {
485
      ScreenList curr = ScreenList.getCurrentScreen();
486

    
487
      if( curr==ScreenList.PLAY )
488
        {
489
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
490
        play.restoreMovePreferences(this,KEY_PLAY,preferences);
491
        }
492
      if( curr==ScreenList.SOLV )
493
        {
494
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
495
        solv.restoreMovePreferences(this,KEY_SOLV,preferences);
496
        }
497
      }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
    void OpenGLError()
502
      {
503
      RubikDialogError errDiag = new RubikDialogError();
504
      errDiag.show(getSupportFragmentManager(), null);
505
      }
506

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508
// PUBLIC API
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
    public FirebaseAnalytics getAnalytics()
512
      {
513
      return mFirebaseAnalytics;
514
      }
515

    
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517

    
518
    public int getHeightUpperBar()
519
      {
520
      return mHeightUpperBar;
521
      }
522

    
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524

    
525
    public int getHeightLowerBar()
526
      {
527
      return mHeightLowerBar;
528
      }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531

    
532
    public TwistyObject getObject()
533
      {
534
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
535
      return view.getObjectControl().getObject();
536
      }
537

    
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539

    
540
    public DistortedScreen getScreen()
541
      {
542
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
543
      return view.getRenderer().getScreen();
544
      }
545

    
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547

    
548
    public ObjectControl getControl()
549
      {
550
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
551
      return view.getObjectControl();
552
      }
553

    
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555

    
556
    public int getScreenWidthInPixels()
557
      {
558
      return mScreenWidth;
559
      }
560

    
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562

    
563
    public int getScreenHeightInPixels()
564
      {
565
      return mScreenHeight;
566
      }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

    
570
    public void changeObject(int newObject, boolean reportChange)
571
      {
572
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
573
      ObjectControl control = view.getObjectControl();
574
      TwistyObject oldObject = control.getObject();
575
      changeIfDifferent(newObject,control);
576

    
577
      if( reportChange && oldObject!=null )
578
        {
579
        RubikObject robject = RubikObjectList.getObject(newObject);
580
        String newName = robject==null ? "NULL" : robject.getUpperName();
581
        float fps = view.getRenderer().getFPS();
582
        fps = (int)(fps+0.5f);
583
        StringBuilder name = new StringBuilder();
584
        name.append(oldObject.getShortName());
585
        name.append(' ');
586
        name.append(fps);
587
        name.append(" --> ");
588
        name.append(newName);
589

    
590
        if( BuildConfig.DEBUG )
591
          {
592
          android.util.Log.e("rubik", name.toString());
593
          }
594
        else
595
          {
596
          FirebaseAnalytics analytics = getAnalytics();
597

    
598
          if( analytics!=null )
599
            {
600
            Bundle bundle = new Bundle();
601
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
602
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
603
            }
604
          }
605
        }
606
      }
607

    
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609

    
610
    public void changeIfDifferent(int ordinal, ObjectControl control)
611
      {
612
      RubikObject object = RubikObjectList.getObject(ordinal);
613
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
614
      int iconMode  = TwistyObject.MODE_NORM;
615
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
616
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
617
      String name = object==null ? "NULL" : object.getUpperName();
618

    
619
      control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
620
      }
621

    
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623

    
624
    public static int getDrawableSize()
625
      {
626
      if( mScreenHeight<1000 )
627
        {
628
        return 0;
629
        }
630
      if( mScreenHeight<1600 )
631
        {
632
        return 1;
633
        }
634
      if( mScreenHeight<1900 )
635
        {
636
        return 2;
637
        }
638

    
639
      return 3;
640
      }
641

    
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643

    
644
    public static int getDrawable(int small, int medium, int big, int huge)
645
      {
646
      int size = getDrawableSize();
647

    
648
      switch(size)
649
        {
650
        case 0 : return small;
651
        case 1 : return medium;
652
        case 2 : return big;
653
        default: return huge;
654
        }
655
      }
656

    
657
///////////////////////////////////////////////////////////////////////////////////////////////////
658

    
659
    public void acceptPrivacy()
660
      {
661
      mPolicyAccepted = true;
662
      }
663

    
664
///////////////////////////////////////////////////////////////////////////////////////////////////
665

    
666
    public void declinePrivacy()
667
      {
668
      finish();
669
      }
670

    
671
///////////////////////////////////////////////////////////////////////////////////////////////////
672

    
673
    public static boolean localeIsChinese()
674
      {
675
      String language;
676

    
677
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
678
        {
679
        language= LocaleList.getDefault().get(0).getLanguage();
680
        }
681
      else
682
        {
683
        language= Locale.getDefault().getLanguage();
684
        }
685

    
686
      return language.equals("zh");
687
      }
688

    
689
///////////////////////////////////////////////////////////////////////////////////////////////////
690

    
691
    public boolean isVertical()
692
      {
693
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
694
      return view.isVertical();
695
      }
696

    
697
///////////////////////////////////////////////////////////////////////////////////////////////////
698

    
699
    public void blockEverything(int place)
700
      {
701
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
702
      ObjectControl control = view.getObjectControl();
703
      control.blockEverything(place);
704

    
705
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
706
      play.setLockState(this);
707
      }
708

    
709
///////////////////////////////////////////////////////////////////////////////////////////////////
710

    
711
    public void unblockEverything()
712
      {
713
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
714
      ObjectControl control = view.getObjectControl();
715
      control.unblockEverything();
716

    
717
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
718
      play.setLockState(this);
719
      }
720

    
721
///////////////////////////////////////////////////////////////////////////////////////////////////
722

    
723
    public void switchTutorial(String url, int objectOrdinal)
724
      {
725
      Intent intent = new Intent(this, TutorialActivity.class);
726
      intent.putExtra("url", url);
727
      intent.putExtra("obj", objectOrdinal);
728
      startActivity(intent);
729
      }
730

    
731
///////////////////////////////////////////////////////////////////////////////////////////////////
732

    
733
    public void switchConfig(int objectOrdinal)
734
      {
735
      Intent intent = new Intent(this, ConfigActivity.class);
736
      intent.putExtra("obj", objectOrdinal);
737
      startActivity(intent);
738
      }
739

    
740
///////////////////////////////////////////////////////////////////////////////////////////////////
741

    
742
    public void switchToBandagedCreator()
743
      {
744
      Intent intent = new Intent(this, BandagedCreatorActivity.class);
745
      startActivity(intent);
746
      }
747

    
748
///////////////////////////////////////////////////////////////////////////////////////////////////
749

    
750
    public void switchToPurchase(int objectOrdinal)
751
      {
752
      Intent intent = new Intent(this, PurchaseActivity.class);
753
      intent.putExtra("obj", objectOrdinal);
754
      startActivity(intent);
755
      }
756

    
757
///////////////////////////////////////////////////////////////////////////////////////////////////
758

    
759
    public void reloadObject(String shortName)
760
      {
761
      TwistyObject currObject = getObject();
762
      String name = currObject==null ? "" : currObject.getShortName();
763

    
764
      if( name.toLowerCase(Locale.ENGLISH).equals(shortName) )
765
        {
766
        RubikObject object = RubikObjectList.getObject(name);
767

    
768
        if( object!=null )
769
          {
770
          int meshState = object.getMeshState();
771
          int iconMode  = TwistyObject.MODE_NORM;
772
          InputStream jsonStream = object.getObjectStream(this);
773
          InputStream meshStream = object.getMeshStream(this);
774
          ObjectControl control = getControl();
775
          control.changeObject(-1,meshState,iconMode,jsonStream,meshStream);
776
          }
777
        }
778
      }
779
}
(1-1/4)