Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 9a39aabf

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
      editor.putInt("solverIndex", mSolverIndex );
341

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

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

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

    
358
      ScreenList curr = ScreenList.getCurrentScreen();
359

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

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

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

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

    
383
      parseOldVersion(mOldVersion);
384

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

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

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

    
397
      RubikScores scores = RubikScores.getInstance();
398

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

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

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

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

    
424
      ScreenList.restorePreferences(preferences);
425

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

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

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

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

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

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

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

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

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479

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

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

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

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

    
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505
// PUBLIC API
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507

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

    
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514

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

    
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521

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

    
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528

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

    
535
///////////////////////////////////////////////////////////////////////////////////////////////////
536

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

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544

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

    
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552

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

    
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559

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

    
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566

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

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

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

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

    
605
///////////////////////////////////////////////////////////////////////////////////////////////////
606

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

    
616
      control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
617
      }
618

    
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620

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

    
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630

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

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

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

    
646
    public void acceptPrivacy()
647
      {
648
      mPolicyAccepted = true;
649
      }
650

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

    
653
    public void declinePrivacy()
654
      {
655
      finish();
656
      }
657

    
658
///////////////////////////////////////////////////////////////////////////////////////////////////
659

    
660
    public static boolean localeIsChinese()
661
      {
662
      String language;
663

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

    
673
      return language.equals("zh");
674
      }
675

    
676
///////////////////////////////////////////////////////////////////////////////////////////////////
677

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

    
684
///////////////////////////////////////////////////////////////////////////////////////////////////
685

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

    
694
///////////////////////////////////////////////////////////////////////////////////////////////////
695

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

    
703
///////////////////////////////////////////////////////////////////////////////////////////////////
704

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

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

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

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

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

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

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

    
743
///////////////////////////////////////////////////////////////////////////////////////////////////
744

    
745
    public void setSolverIndex(int index)
746
      {
747
      mSolverIndex = index;
748
      }
749

    
750
///////////////////////////////////////////////////////////////////////////////////////////////////
751

    
752
    public int getSolverIndex()
753
      {
754
      return mSolverIndex;
755
      }
756

    
757
}
(1-1/4)