Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 617b7b66

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.RubikDialogWhatsNew;
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               = false;
68

    
69
    public static final float PADDING             = 0.01f;
70
    public static final float SMALL_MARGIN        = 0.004f;
71
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
72
    public static final float TITLE_TEXT_SIZE     = 0.06f;
73
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
74
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
75
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
76
    public static final float SCORES_ITEM_TEXT    = 0.030f;
77
    public static final float TAB_WIDTH           = 0.066f;
78
    public static final float TAB_HEIGHT          = 0.066f;
79
    public static final float POPUP_PADDING       = 0.028f;
80
    public static final float POPUP_MARGIN        = 0.016f;
81
    public static final float RATIO_BAR           = 0.10f;
82

    
83
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
84
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
85
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
86
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
87
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
88

    
89
    private static final int ACTIVITY_NUMBER = 0;
90
    private static final float RATIO_INSET= 0.09f;
91

    
92
    private static final String KEY_PLAY = "movesController_play";
93
    private static final String KEY_SOLV = "movesController_solv";
94

    
95
    private boolean mJustStarted;
96
    private FirebaseAnalytics mFirebaseAnalytics;
97
    private static int mScreenWidth, mScreenHeight;
98
    private boolean mPolicyAccepted, mIsChinese;
99
    private int mCurrentApiVersion;
100
    private int mHeightUpperBar, mHeightLowerBar;
101
    private int mOldVersion1, mOldVersion2, mOldVersion3;
102
    private String mOldVersion, mCurrVersion;
103
    private int mSolverIndex;
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

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

    
113
      setTheme(R.style.MaterialThemeNoActionBar);
114
      setContentView(R.layout.main);
115

    
116
      mJustStarted = true;
117
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
118
      mIsChinese = localeIsChinese();
119

    
120
      DisplayMetrics displaymetrics = new DisplayMetrics();
121
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
122
      mScreenWidth =displaymetrics.widthPixels;
123
      mScreenHeight=displaymetrics.heightPixels;
124

    
125
      hideNavigationBar();
126
      cutoutHack();
127
      computeBarHeights();
128

    
129
      mCurrVersion = getAppVers();
130
      mSolverIndex = 0;
131

    
132
      Thread thread = new Thread()
133
        {
134
        public void run()
135
          {
136
          RubikInAppMessanging listener = new RubikInAppMessanging();
137
          FirebaseInAppMessaging.getInstance().addClickListener(listener);
138
          }
139
        };
140

    
141
      thread.start();
142
      }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
// this does not include possible insets
146

    
147
    private void computeBarHeights()
148
      {
149
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
150
      mHeightLowerBar = barHeight;
151
      mHeightUpperBar = barHeight;
152

    
153
      LinearLayout layoutTop = findViewById(R.id.upperBar);
154
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
155

    
156
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
157
      paramsTop.height = mHeightUpperBar;
158
      layoutTop.setLayoutParams(paramsTop);
159
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
160
      paramsBot.height = mHeightLowerBar;
161
      layoutBot.setLayoutParams(paramsBot);
162
      }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
    private void hideNavigationBar()
167
      {
168
      mCurrentApiVersion = Build.VERSION.SDK_INT;
169

    
170
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
171
        {
172
        final View decorView = getWindow().getDecorView();
173

    
174
        decorView.setSystemUiVisibility(FLAGS);
175

    
176
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
177
          {
178
          @Override
179
          public void onSystemUiVisibilityChange(int visibility)
180
            {
181
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
182
              {
183
              decorView.setSystemUiVisibility(FLAGS);
184
              }
185
            }
186
          });
187
        }
188
      }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
    @Override
193
    public void onAttachedToWindow()
194
      {
195
      super.onAttachedToWindow();
196

    
197
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
198
        {
199
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
200
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
201

    
202
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
203
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
204
        paramsHid.height = (int)(insetHeight*RATIO_INSET);
205
        layoutHid.setLayoutParams(paramsHid);
206
        mHeightUpperBar += paramsHid.height;
207
        }
208
      }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211
// do not avoid cutouts
212

    
213
    private void cutoutHack()
214
      {
215
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
216
        {
217
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
218
        }
219
      }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
    @Override
224
    public void onWindowFocusChanged(boolean hasFocus)
225
      {
226
      super.onWindowFocusChanged(hasFocus);
227

    
228
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
229
        {
230
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
231
        }
232
      }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235
    
236
    @Override
237
    protected void onPause() 
238
      {
239
      super.onPause();
240
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
241
      view.onPause();
242
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
243
      RubikNetwork.onPause();
244
      savePreferences();
245
      }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248
    
249
    @Override
250
    protected void onResume() 
251
      {
252
      super.onResume();
253
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
254
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
255
      view.onResume();
256

    
257
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
258
      restorePreferences(preferences,mJustStarted);
259
      ScreenList.setScreen(this);
260
      restoreMoves(preferences);
261

    
262
      if( mJustStarted )
263
        {
264
        mJustStarted = false;
265
        RubikScores scores = RubikScores.getInstance();
266
        scores.incrementNumRuns();
267
        scores.setCountry(this);
268
        RubikObjectList.restoreMeshState(preferences);
269
        }
270

    
271
      int object = RubikObjectList.getCurrObject();
272
      changeIfDifferent(object,view.getObjectControl());
273

    
274
      if( mIsChinese && !mPolicyAccepted ) privacyPolicy();
275
      else
276
        {
277
        if( !mOldVersion.equals(mCurrVersion) )
278
          {
279
          displayNovelties();
280
          }
281
        else
282
          {
283
          if( USE_IAP ) view.setShowStars();
284
          }
285
        }
286
      }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

    
290
    private void privacyPolicy()
291
      {
292
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
293
      priDiag.show(getSupportFragmentManager(), null);
294
      }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

    
298
    private void displayNovelties()
299
      {
300
      Bundle bundle = new Bundle();
301
      bundle.putString("argument",mOldVersion);
302
      RubikDialogWhatsNew newDialog = new RubikDialogWhatsNew();
303
      newDialog.setArguments(bundle);
304
      newDialog.show(getSupportFragmentManager(), RubikDialogWhatsNew.getDialogTag() );
305
      }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308
    
309
    @Override
310
    protected void onDestroy() 
311
      {
312
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
313
      super.onDestroy();
314
      }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
    private String getAppVers()
319
      {
320
      try
321
        {
322
        PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
323
        return pInfo.versionName;
324
        }
325
      catch (PackageManager.NameNotFoundException e)
326
        {
327
        return "unknown";
328
        }
329
      }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
    private void savePreferences()
334
      {
335
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
336
      SharedPreferences.Editor editor = preferences.edit();
337

    
338
      editor.putBoolean("policyAccepted", mPolicyAccepted);
339
      editor.putString("appVersion", mCurrVersion );
340

    
341
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
342
        {
343
        BaseEffect.Type.getType(i).savePreferences(editor);
344
        }
345

    
346
      for (int i = 0; i< ScreenList.LENGTH; i++)
347
        {
348
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
349
        }
350

    
351
      RubikObjectList.savePreferences(editor);
352
      RubikObjectList.saveMeshState(editor);
353
      ScreenList.savePreferences(editor);
354
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
355
      view.getObjectControl().savePreferences(editor);
356

    
357
      ScreenList curr = ScreenList.getCurrentScreen();
358

    
359
      if( curr==ScreenList.PLAY )
360
        {
361
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
362
        play.saveMovePreferences(KEY_PLAY,editor);
363
        }
364
      if( curr==ScreenList.SOLV )
365
        {
366
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
367
        solv.saveMovePreferences(KEY_SOLV,editor);
368
        }
369

    
370
      boolean success = editor.commit();
371
      if( !success ) android.util.Log.e("D", "Failed to save preferences");
372
      }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
    private void restorePreferences(SharedPreferences preferences, boolean justStarted)
377
      {
378
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
379
      mOldVersion = preferences.getString("appVersion","");
380
      parseOldVersion(mOldVersion);
381

    
382
      RubikObjectList.restorePreferences(this,preferences,justStarted);
383

    
384
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
385
        {
386
        BaseEffect.Type.getType(i).restorePreferences(preferences);
387
        }
388

    
389
      for (int i=0; i<ScreenList.LENGTH; i++)
390
        {
391
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
392
        }
393

    
394
      RubikScores scores = RubikScores.getInstance();
395

    
396
      if( scores.isVerified() )
397
        {
398
        FirebaseAnalytics analytics = getAnalytics();
399
        analytics.setUserId(scores.getName());
400
        }
401

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

    
406
      if( justStarted && numStars==0 && oldVersionLessThan(1,11,4) )
407
        {
408
        scores.correctNumStars();
409
        }
410

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

    
421
      ScreenList.restorePreferences(preferences);
422

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

    
432
      if( !mOldVersion.equals("") )
433
        {
434
        RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
435
        view.getObjectControl().restorePreferences(preferences);
436
        }
437
      }
438

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

    
441
    private void parseOldVersion(String version)
442
      {
443
      if( version==null ) return;
444

    
445
      try
446
        {
447
        String[] parts = version.split("\\.");
448

    
449
        if( parts.length==3 )
450
          {
451
          mOldVersion1 = Integer.parseInt(parts[0]);
452
          mOldVersion2 = Integer.parseInt(parts[1]);
453
          mOldVersion3 = Integer.parseInt(parts[2]);
454
          }
455
        }
456
      catch(Exception ignored)
457
        {
458
        mOldVersion1 = 0;
459
        mOldVersion2 = 0;
460
        mOldVersion3 = 0;
461
        }
462
      }
463

    
464
///////////////////////////////////////////////////////////////////////////////////////////////////
465

    
466
    private boolean oldVersionLessThan(int v1, int v2, int v3)
467
      {
468
      if( mOldVersion1<v1 ) return true;
469
      if( mOldVersion1>v1 ) return false;
470
      if( mOldVersion2<v2 ) return true;
471
      if( mOldVersion2>v2 ) return false;
472
      return mOldVersion3<v3;
473
      }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

    
477
    private void restoreMoves(SharedPreferences preferences)
478
      {
479
      ScreenList curr = ScreenList.getCurrentScreen();
480

    
481
      if( curr==ScreenList.PLAY )
482
        {
483
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
484
        play.restoreMovePreferences(this,KEY_PLAY,preferences);
485
        }
486
      if( curr==ScreenList.SOLV )
487
        {
488
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
489
        solv.restoreMovePreferences(this,KEY_SOLV,preferences);
490
        }
491
      }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
    void OpenGLError()
496
      {
497
      RubikDialogError errDiag = new RubikDialogError();
498
      errDiag.show(getSupportFragmentManager(), null);
499
      }
500

    
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502
// PUBLIC API
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
    public FirebaseAnalytics getAnalytics()
506
      {
507
      return mFirebaseAnalytics;
508
      }
509

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

    
512
    public int getHeightUpperBar()
513
      {
514
      return mHeightUpperBar;
515
      }
516

    
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518

    
519
    public int getHeightLowerBar()
520
      {
521
      return mHeightLowerBar;
522
      }
523

    
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525

    
526
    public TwistyObject getObject()
527
      {
528
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
529
      return view.getObjectControl().getObject();
530
      }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533

    
534
    public DistortedScreen getScreen()
535
      {
536
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
537
      return view.getRenderer().getScreen();
538
      }
539

    
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541

    
542
    public ObjectControl getControl()
543
      {
544
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
545
      return view.getObjectControl();
546
      }
547

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

    
550
    public int getScreenWidthInPixels()
551
      {
552
      return mScreenWidth;
553
      }
554

    
555
///////////////////////////////////////////////////////////////////////////////////////////////////
556

    
557
    public int getScreenHeightInPixels()
558
      {
559
      return mScreenHeight;
560
      }
561

    
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563

    
564
    public void changeObject(int newObject, boolean reportChange)
565
      {
566
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
567
      ObjectControl control = view.getObjectControl();
568
      TwistyObject oldObject = control.getObject();
569
      changeIfDifferent(newObject,control);
570

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

    
584
        if( BuildConfig.DEBUG )
585
          {
586
          android.util.Log.e("rubik", name.toString());
587
          }
588
        else
589
          {
590
          FirebaseAnalytics analytics = getAnalytics();
591

    
592
          if( analytics!=null )
593
            {
594
            Bundle bundle = new Bundle();
595
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
596
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
597
            }
598
          }
599
        }
600
      }
601

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

    
604
    public void changeIfDifferent(int ordinal, ObjectControl control)
605
      {
606
      RubikObject object = RubikObjectList.getObject(ordinal);
607
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
608
      int iconMode  = TwistyObject.MODE_NORM;
609
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
610
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
611
      String name = object==null ? "NULL" : object.getUpperName();
612

    
613
      control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
614
      }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617

    
618
    public static int getDrawableSize()
619
      {
620
      if( mScreenHeight<1000 ) return 0;
621
      if( mScreenHeight<1600 ) return 1;
622
      if( mScreenHeight<1900 ) return 2;
623
      return 3;
624
      }
625

    
626
///////////////////////////////////////////////////////////////////////////////////////////////////
627

    
628
    public static int getDrawable(int small, int medium, int big, int huge)
629
      {
630
      int size = getDrawableSize();
631

    
632
      switch(size)
633
        {
634
        case 0 : return small;
635
        case 1 : return medium;
636
        case 2 : return big;
637
        default: return huge;
638
        }
639
      }
640

    
641
///////////////////////////////////////////////////////////////////////////////////////////////////
642

    
643
    public void acceptPrivacy()
644
      {
645
      mPolicyAccepted = true;
646
      }
647

    
648
///////////////////////////////////////////////////////////////////////////////////////////////////
649

    
650
    public void declinePrivacy()
651
      {
652
      finish();
653
      }
654

    
655
///////////////////////////////////////////////////////////////////////////////////////////////////
656

    
657
    public static boolean localeIsChinese()
658
      {
659
      String language;
660

    
661
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
662
        {
663
        language= LocaleList.getDefault().get(0).getLanguage();
664
        }
665
      else
666
        {
667
        language= Locale.getDefault().getLanguage();
668
        }
669

    
670
      return language.equals("zh");
671
      }
672

    
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674

    
675
    public boolean isVertical()
676
      {
677
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
678
      return view.isVertical();
679
      }
680

    
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682

    
683
    public void switchTutorial(String url, int objectOrdinal)
684
      {
685
      Intent intent = new Intent(this, TutorialActivity.class);
686
      intent.putExtra("url", url);
687
      intent.putExtra("obj", objectOrdinal);
688
      startActivity(intent);
689
      }
690

    
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692

    
693
    public void switchConfig(int objectOrdinal)
694
      {
695
      Intent intent = new Intent(this, ConfigActivity.class);
696
      intent.putExtra("obj", objectOrdinal);
697
      startActivity(intent);
698
      }
699

    
700
///////////////////////////////////////////////////////////////////////////////////////////////////
701

    
702
    public void switchToBandagedCreator()
703
      {
704
      Intent intent = new Intent(this, BandagedCreatorActivity.class);
705
      startActivity(intent);
706
      }
707

    
708
///////////////////////////////////////////////////////////////////////////////////////////////////
709

    
710
    public void switchToPurchase(int objectOrdinal)
711
      {
712
      Intent intent = new Intent(this, PurchaseActivity.class);
713
      intent.putExtra("obj", objectOrdinal);
714
      startActivity(intent);
715
      }
716

    
717
///////////////////////////////////////////////////////////////////////////////////////////////////
718

    
719
    public void reloadObject(String shortName)
720
      {
721
      TwistyObject currObject = getObject();
722
      String name = currObject==null ? "" : currObject.getShortName();
723

    
724
      if( name.toLowerCase(Locale.ENGLISH).equals(shortName) )
725
        {
726
        RubikObject object = RubikObjectList.getObject(name);
727

    
728
        if( object!=null )
729
          {
730
          int meshState = object.getMeshState();
731
          int iconMode  = TwistyObject.MODE_NORM;
732
          InputStream jsonStream = object.getObjectStream(this);
733
          InputStream meshStream = object.getMeshStream(this);
734
          ObjectControl control = getControl();
735
          control.changeObject(-1,meshState,iconMode,jsonStream,meshStream);
736
          }
737
        }
738
      }
739

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

    
742
    public void setSolverIndex(int index)
743
      {
744
      mSolverIndex = index;
745
      }
746

    
747
///////////////////////////////////////////////////////////////////////////////////////////////////
748

    
749
    public int getSolverIndex()
750
      {
751
      return mSolverIndex;
752
      }
753

    
754
}
(1-1/4)