Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 743b41d5

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.RubikDialogAbout;
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.InitAssets;
44
import org.distorted.objectlib.main.ObjectControl;
45
import org.distorted.objectlib.main.TwistyObject;
46
import org.distorted.objectlib.effects.BaseEffect;
47

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

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

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

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

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

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

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

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

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

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

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

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

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

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

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

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

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

    
142
      thread.start();
143
      }
144

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

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

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

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

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

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

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

    
175
        decorView.setSystemUiVisibility(FLAGS);
176

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

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

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

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

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

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212
// do not avoid cutouts
213

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

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

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

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

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

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

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

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

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

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

    
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

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

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

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

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

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

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

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

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

    
339
      editor.putBoolean("policyAccepted", mPolicyAccepted);
340
      editor.putString("appVersion", mCurrVersion );
341
      editor.putInt("solverIndex", mSolverIndex );
342

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

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

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

    
359
      ScreenList curr = ScreenList.getCurrentScreen();
360

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

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

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
    private void restorePreferences(SharedPreferences preferences, boolean justStarted)
379
      {
380
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
381
      mOldVersion = preferences.getString("appVersion","");
382
      mSolverIndex = preferences.getInt("solverIndex",0);
383

    
384
      parseOldVersion(mOldVersion);
385

    
386
      RubikObjectList.restorePreferences(this,preferences,justStarted);
387

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

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

    
398
      RubikScores scores = RubikScores.getInstance();
399

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

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

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

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

    
425
      ScreenList.restorePreferences(preferences);
426

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

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

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

    
445
    private void parseOldVersion(String version)
446
      {
447
      if( version==null ) return;
448

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

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

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

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

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

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

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

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

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

    
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506
// PUBLIC API
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508

    
509
    public FirebaseAnalytics getAnalytics()
510
      {
511
      return mFirebaseAnalytics;
512
      }
513

    
514
///////////////////////////////////////////////////////////////////////////////////////////////////
515

    
516
    public int getHeightUpperBar()
517
      {
518
      return mHeightUpperBar;
519
      }
520

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

    
523
    public int getHeightLowerBar()
524
      {
525
      return mHeightLowerBar;
526
      }
527

    
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529

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

    
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537

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

    
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545

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

    
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553

    
554
    public int getScreenWidthInPixels()
555
      {
556
      return mScreenWidth;
557
      }
558

    
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560

    
561
    public int getScreenHeightInPixels()
562
      {
563
      return mScreenHeight;
564
      }
565

    
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567

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

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

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

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

    
606
///////////////////////////////////////////////////////////////////////////////////////////////////
607

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

    
618
      control.changeIfDifferent(ordinal,name,meshState,iconMode,asset);
619
      }
620

    
621
///////////////////////////////////////////////////////////////////////////////////////////////////
622

    
623
    public static int getDrawableSize()
624
      {
625
      if( mScreenHeight<1000 ) return 0;
626
      if( mScreenHeight<1600 ) return 1;
627
      if( mScreenHeight<1900 ) return 2;
628
      return 3;
629
      }
630

    
631
///////////////////////////////////////////////////////////////////////////////////////////////////
632

    
633
    public static int getDrawable(int small, int medium, int big, int huge)
634
      {
635
      int size = getDrawableSize();
636

    
637
      switch(size)
638
        {
639
        case 0 : return small;
640
        case 1 : return medium;
641
        case 2 : return big;
642
        default: return huge;
643
        }
644
      }
645

    
646
///////////////////////////////////////////////////////////////////////////////////////////////////
647

    
648
    public void acceptPrivacy()
649
      {
650
      mPolicyAccepted = true;
651
      }
652

    
653
///////////////////////////////////////////////////////////////////////////////////////////////////
654

    
655
    public void declinePrivacy()
656
      {
657
      finish();
658
      }
659

    
660
///////////////////////////////////////////////////////////////////////////////////////////////////
661

    
662
    public static boolean localeIsChinese()
663
      {
664
      String language;
665

    
666
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
667
        {
668
        language= LocaleList.getDefault().get(0).getLanguage();
669
        }
670
      else
671
        {
672
        language= Locale.getDefault().getLanguage();
673
        }
674

    
675
      return language.equals("zh");
676
      }
677

    
678
///////////////////////////////////////////////////////////////////////////////////////////////////
679

    
680
    public boolean isVertical()
681
      {
682
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
683
      return view.isVertical();
684
      }
685

    
686
///////////////////////////////////////////////////////////////////////////////////////////////////
687

    
688
    public void switchTutorial(String url, int objectOrdinal)
689
      {
690
      Intent intent = new Intent(this, TutorialActivity.class);
691
      intent.putExtra("url", url);
692
      intent.putExtra("obj", objectOrdinal);
693
      startActivity(intent);
694
      }
695

    
696
///////////////////////////////////////////////////////////////////////////////////////////////////
697

    
698
    public void switchConfig(int objectOrdinal)
699
      {
700
      Intent intent = new Intent(this, ConfigActivity.class);
701
      intent.putExtra("obj", objectOrdinal);
702
      startActivity(intent);
703
      }
704

    
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706

    
707
    public void switchToBandagedCreator()
708
      {
709
      Intent intent = new Intent(this, BandagedCreatorActivity.class);
710
      startActivity(intent);
711
      }
712

    
713
///////////////////////////////////////////////////////////////////////////////////////////////////
714

    
715
    public void switchToPurchase(int objectOrdinal)
716
      {
717
      Intent intent = new Intent(this, PurchaseActivity.class);
718
      intent.putExtra("obj", objectOrdinal);
719
      startActivity(intent);
720
      }
721

    
722
///////////////////////////////////////////////////////////////////////////////////////////////////
723

    
724
    public void reloadObject(String shortName)
725
      {
726
      TwistyObject currObject = getObject();
727
      String name = currObject==null ? "" : currObject.getShortName();
728

    
729
      if( name.toLowerCase(Locale.ENGLISH).equals(shortName) )
730
        {
731
        RubikObject object = RubikObjectList.getObject(name);
732

    
733
        if( object!=null )
734
          {
735
          int meshState = object.getMeshState();
736
          int iconMode  = TwistyObject.MODE_NORM;
737
          InputStream jsonStream = object.getObjectStream(this);
738
          InputStream meshStream = object.getMeshStream(this);
739
          InitAssets asset       = new InitAssets(jsonStream,meshStream,getResources());
740
          ObjectControl control = getControl();
741
          control.changeObject(-1,meshState,iconMode,asset);
742
          }
743
        }
744
      }
745

    
746
///////////////////////////////////////////////////////////////////////////////////////////////////
747

    
748
    public void setSolverIndex(int index)
749
      {
750
      mSolverIndex = index;
751
      }
752

    
753
///////////////////////////////////////////////////////////////////////////////////////////////////
754

    
755
    public int getSolverIndex()
756
      {
757
      return mSolverIndex;
758
      }
759

    
760
}
(1-1/4)