Project

General

Profile

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

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

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.library.main.DistortedLibrary;
39

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

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

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

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

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

    
68
    public static final float PADDING             = 0.01f;
69
    public static final float SMALL_MARGIN        = 0.004f;
70
    public static final float MEDIUM_MARGIN       = 0.015f;
71
    public static final float LARGE_MARGIN        = 0.025f;
72
    public static final float POPUP_PADDING       = 0.045f;
73
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
74
    public static final float TITLE_TEXT_SIZE     = 0.06f;
75
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
76
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
77
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
78
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
79
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
80
    public static final float SCORES_ITEM_TEXT    = 0.030f;
81
    public static final float TUTORIAL_ITEM_TEXT  = 0.100f;
82
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
83
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
84
    public static final float MENU_MAIN_TEXT_SIZE = 0.047f;
85
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
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 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
    
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286
    
287
    @Override
288
    protected void onDestroy() 
289
      {
290
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
291
      super.onDestroy();
292
      }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
    private String getAppVers()
297
      {
298
      try
299
        {
300
        PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
301
        return pInfo.versionName;
302
        }
303
      catch (PackageManager.NameNotFoundException e)
304
        {
305
        return "unknown";
306
        }
307
      }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
    private void savePreferences()
312
      {
313
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
314
      SharedPreferences.Editor editor = preferences.edit();
315

    
316
      editor.putBoolean("policyAccepted", mPolicyAccepted);
317
      editor.putString("appVersion", mCurrVersion );
318

    
319
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
320
        {
321
        BaseEffect.Type.getType(i).savePreferences(editor);
322
        }
323

    
324
      for (int i = 0; i< ScreenList.LENGTH; i++)
325
        {
326
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
327
        }
328

    
329
      RubikObjectList.savePreferences(editor);
330
      RubikObjectList.saveMeshState(editor);
331
      ScreenList.savePreferences(editor);
332
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
333
      view.getObjectControl().savePreferences(editor);
334

    
335
      ScreenList curr = ScreenList.getCurrentScreen();
336

    
337
      if( curr==ScreenList.PLAY )
338
        {
339
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
340
        play.saveMovePreferences(KEY_PLAY,editor);
341
        }
342
      if( curr==ScreenList.SOLV )
343
        {
344
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
345
        solv.saveMovePreferences(KEY_SOLV,editor);
346
        }
347

    
348
      boolean success = editor.commit();
349
      if( !success ) android.util.Log.e("D", "Failed to save preferences");
350
      }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
    private void restorePreferences(SharedPreferences preferences, boolean justStarted)
355
      {
356
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
357
      String oldVersion = preferences.getString("appVersion","");
358
      parseVersion(oldVersion);
359

    
360
      RubikObjectList.restorePreferences(this,preferences,justStarted);
361

    
362
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
363
        {
364
        BaseEffect.Type.getType(i).restorePreferences(preferences);
365
        }
366

    
367
      for (int i=0; i<ScreenList.LENGTH; i++)
368
        {
369
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
370
        }
371

    
372
      RubikScores scores = RubikScores.getInstance();
373

    
374
      if( scores.isVerified() )
375
        {
376
        FirebaseAnalytics analytics = getAnalytics();
377
        analytics.setUserId(scores.getName());
378
        }
379

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

    
384
      if( justStarted && numStars==0 && oldVersionLessThan(1,11,4) )
385
        {
386
        scores.correctNumStars();
387
        }
388

    
389
      // in 1.11.5 we have introduced IAP. When upgrading from something less than 1.11.5 to
390
      // something at least 1.11.5, mark all solved objects as free.
391
      // this needs to be after the above ScreenList.getScreen(i).getScreenClass().restorePreferences()
392
      // as that restores the Records which we need here
393
      // also needs to be after RubikObjectList.restorePreferences()
394
      if( USE_IAP && justStarted && oldVersionLessThan(1,11,5) && !mCurrVersion.equals("1.11.4") )
395
        {
396
        RubikObjectList.firstUpgradeMarkAllSolvedAsFree();
397
        }
398

    
399
      ScreenList.restorePreferences(preferences);
400

    
401
      // Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their
402
      // case the 'mOldVersion' - version of the app which saved the preferences on the last
403
      // go - is empty.
404
      // Between versions 1.8.6 and 1.9.0, the order of the cubits in TwistyCube has changed.
405
      // If someone has scrambled the cube with v. 1.8.6, then upgraded to 1.9.0 and re-started
406
      // the app, because of the different order of the cubits - his cube would be messed up.
407
      // So in such case, i.e. on fresh upgrade from version<=1.8.6 to version>=1.9.0, do not
408
      // restore the object scrambling.
409

    
410
      if( !oldVersion.equals("") )
411
        {
412
        RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
413
        view.getObjectControl().restorePreferences(preferences);
414
        }
415
      }
416

    
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418

    
419
    private void parseVersion(String version)
420
      {
421
      if( version==null ) return;
422

    
423
      try
424
        {
425
        String[] parts = version.split("\\.");
426

    
427
        if( parts.length==3 )
428
          {
429
          mOldVersion1 = Integer.parseInt(parts[0]);
430
          mOldVersion2 = Integer.parseInt(parts[1]);
431
          mOldVersion3 = Integer.parseInt(parts[2]);
432
          }
433
        }
434
      catch(Exception ignored)
435
        {
436
        mOldVersion1 = 0;
437
        mOldVersion2 = 0;
438
        mOldVersion3 = 0;
439
        }
440
      }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
    private boolean oldVersionLessThan(int v1, int v2, int v3)
445
      {
446
      if( mOldVersion1<v1 ) return true;
447
      if( mOldVersion1>v1 ) return false;
448
      if( mOldVersion2<v2 ) return true;
449
      if( mOldVersion2>v2 ) return false;
450
      return mOldVersion3<v3;
451
      }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
    private void restoreMoves(SharedPreferences preferences)
456
      {
457
      ScreenList curr = ScreenList.getCurrentScreen();
458

    
459
      if( curr==ScreenList.PLAY )
460
        {
461
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
462
        play.restoreMovePreferences(this,KEY_PLAY,preferences);
463
        }
464
      if( curr==ScreenList.SOLV )
465
        {
466
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
467
        solv.restoreMovePreferences(this,KEY_SOLV,preferences);
468
        }
469
      }
470

    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

    
473
    private void PrivacyPolicy()
474
      {
475
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
476
      priDiag.show(getSupportFragmentManager(), null);
477
      }
478

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480

    
481
    void OpenGLError()
482
      {
483
      RubikDialogError errDiag = new RubikDialogError();
484
      errDiag.show(getSupportFragmentManager(), null);
485
      }
486

    
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488
// PUBLIC API
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490

    
491
    public FirebaseAnalytics getAnalytics()
492
      {
493
      return mFirebaseAnalytics;
494
      }
495

    
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

    
498
    public int getHeightUpperBar()
499
      {
500
      return mHeightUpperBar;
501
      }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
    public int getHeightLowerBar()
506
      {
507
      return mHeightLowerBar;
508
      }
509

    
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511

    
512
    public TwistyObject getObject()
513
      {
514
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
515
      return view.getObjectControl().getObject();
516
      }
517

    
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519

    
520
    public DistortedScreen getScreen()
521
      {
522
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
523
      return view.getRenderer().getScreen();
524
      }
525

    
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527

    
528
    public ObjectControl getControl()
529
      {
530
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
531
      return view.getObjectControl();
532
      }
533

    
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535

    
536
    public int getScreenWidthInPixels()
537
      {
538
      return mScreenWidth;
539
      }
540

    
541
///////////////////////////////////////////////////////////////////////////////////////////////////
542

    
543
    public int getScreenHeightInPixels()
544
      {
545
      return mScreenHeight;
546
      }
547

    
548
///////////////////////////////////////////////////////////////////////////////////////////////////
549

    
550
    public void changeObject(int newObject, boolean reportChange)
551
      {
552
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
553
      ObjectControl control = view.getObjectControl();
554
      TwistyObject oldObject = control.getObject();
555
      changeIfDifferent(newObject,control);
556

    
557
      if( reportChange && oldObject!=null )
558
        {
559
        RubikObject robject = RubikObjectList.getObject(newObject);
560
        String newName = robject==null ? "NULL" : robject.getUpperName();
561
        float fps = view.getRenderer().getFPS();
562
        fps = (int)(fps+0.5f);
563
        StringBuilder name = new StringBuilder();
564
        name.append(oldObject.getShortName());
565
        name.append(' ');
566
        name.append(fps);
567
        name.append(" --> ");
568
        name.append(newName);
569

    
570
        if( BuildConfig.DEBUG )
571
          {
572
          android.util.Log.e("rubik", name.toString());
573
          }
574
        else
575
          {
576
          FirebaseAnalytics analytics = getAnalytics();
577

    
578
          if( analytics!=null )
579
            {
580
            Bundle bundle = new Bundle();
581
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
582
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
583
            }
584
          }
585
        }
586
      }
587

    
588
///////////////////////////////////////////////////////////////////////////////////////////////////
589

    
590
    public void changeIfDifferent(int ordinal, ObjectControl control)
591
      {
592
      RubikObject object = RubikObjectList.getObject(ordinal);
593
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
594
      int iconMode  = TwistyObject.MODE_NORM;
595
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
596
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
597
      String name = object==null ? "NULL" : object.getUpperName();
598

    
599
      control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
600
      }
601

    
602
///////////////////////////////////////////////////////////////////////////////////////////////////
603

    
604
    public static int getDrawableSize()
605
      {
606
      if( mScreenHeight<1000 )
607
        {
608
        return 0;
609
        }
610
      if( mScreenHeight<1600 )
611
        {
612
        return 1;
613
        }
614
      if( mScreenHeight<1900 )
615
        {
616
        return 2;
617
        }
618

    
619
      return 3;
620
      }
621

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

    
624
    public static int getDrawable(int small, int medium, int big, int huge)
625
      {
626
      int size = getDrawableSize();
627

    
628
      switch(size)
629
        {
630
        case 0 : return small;
631
        case 1 : return medium;
632
        case 2 : return big;
633
        default: return huge;
634
        }
635
      }
636

    
637
///////////////////////////////////////////////////////////////////////////////////////////////////
638

    
639
    public void acceptPrivacy()
640
      {
641
      mPolicyAccepted = true;
642
      }
643

    
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645

    
646
    public void declinePrivacy()
647
      {
648
      finish();
649
      }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652

    
653
    public static boolean localeIsChinese()
654
      {
655
      String language;
656

    
657
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
658
        {
659
        language= LocaleList.getDefault().get(0).getLanguage();
660
        }
661
      else
662
        {
663
        language= Locale.getDefault().getLanguage();
664
        }
665

    
666
      return language.equals("zh");
667
      }
668

    
669
///////////////////////////////////////////////////////////////////////////////////////////////////
670

    
671
    public boolean isVertical()
672
      {
673
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
674
      return view.isVertical();
675
      }
676

    
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678

    
679
    public void blockEverything(int place)
680
      {
681
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
682
      ObjectControl control = view.getObjectControl();
683
      control.blockEverything(place);
684

    
685
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
686
      play.setLockState(this);
687
      }
688

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

    
691
    public void unblockEverything()
692
      {
693
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
694
      ObjectControl control = view.getObjectControl();
695
      control.unblockEverything();
696

    
697
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
698
      play.setLockState(this);
699
      }
700

    
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702

    
703
    public void switchTutorial(String url, int objectOrdinal)
704
      {
705
      Intent intent = new Intent(this, TutorialActivity.class);
706
      intent.putExtra("url", url);
707
      intent.putExtra("obj", objectOrdinal);
708
      startActivity(intent);
709
      }
710

    
711
///////////////////////////////////////////////////////////////////////////////////////////////////
712

    
713
    public void switchConfig(int objectOrdinal)
714
      {
715
      Intent intent = new Intent(this, ConfigActivity.class);
716
      intent.putExtra("obj", objectOrdinal);
717
      startActivity(intent);
718
      }
719

    
720
///////////////////////////////////////////////////////////////////////////////////////////////////
721

    
722
    public void switchToBandagedCreator()
723
      {
724
      Intent intent = new Intent(this, BandagedCreatorActivity.class);
725
      startActivity(intent);
726
      }
727

    
728
///////////////////////////////////////////////////////////////////////////////////////////////////
729

    
730
    public void switchToPurchase(int objectOrdinal)
731
      {
732
      Intent intent = new Intent(this, PurchaseActivity.class);
733
      intent.putExtra("obj", objectOrdinal);
734
      startActivity(intent);
735
      }
736

    
737
///////////////////////////////////////////////////////////////////////////////////////////////////
738

    
739
    public void reloadObject(String shortName)
740
      {
741
      TwistyObject currObject = getObject();
742
      String name = currObject==null ? "" : currObject.getShortName();
743

    
744
      if( name.toLowerCase(Locale.ENGLISH).equals(shortName) )
745
        {
746
        RubikObject object = RubikObjectList.getObject(name);
747

    
748
        if( object!=null )
749
          {
750
          int meshState = object.getMeshState();
751
          int iconMode  = TwistyObject.MODE_NORM;
752
          InputStream jsonStream = object.getObjectStream(this);
753
          InputStream meshStream = object.getMeshStream(this);
754
          ObjectControl control = getControl();
755
          control.changeObject(-1,meshState,iconMode,jsonStream,meshStream);
756
          }
757
        }
758
      }
759
}
(1-1/4)