Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 65bc1da3

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.helpers.OperatingSystemInterface;
44
import org.distorted.objectlib.main.InitAssets;
45
import org.distorted.objectlib.main.ObjectControl;
46
import org.distorted.objectlib.main.TwistyObject;
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.os.OSInterface;
55
import org.distorted.purchase.PurchaseActivity;
56
import org.distorted.screens.RubikScreenSolving;
57
import org.distorted.screens.ScreenList;
58
import org.distorted.screens.RubikScreenPlay;
59
import org.distorted.tutorials.TutorialActivity;
60

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

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

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

    
71
    public static final float PADDING             = 0.01f;
72
    public static final float SMALL_MARGIN        = 0.004f;
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 PATTERN_GROUP_TEXT  = 0.03f;
76
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
77
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
78
    public static final float SCORES_ITEM_TEXT    = 0.025f;
79
    public static final float TAB_WIDTH           = 0.066f;
80
    public static final float TAB_HEIGHT          = 0.066f;
81
    public static final float POPUP_PADDING       = 0.028f;
82
    public static final float POPUP_MARGIN        = 0.016f;
83
    public static final float RATIO_BAR           = 0.10f;
84

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

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

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

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

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

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

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

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

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

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

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

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

    
143
      thread.start();
144
      }
145

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

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

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

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

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

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

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

    
176
        decorView.setSystemUiVisibility(FLAGS);
177

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

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

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

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

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

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
// do not avoid cutouts
214

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

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

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

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

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

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

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

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

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

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

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

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

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

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

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

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

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

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

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

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

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

    
349
      RubikObjectList.savePreferences(editor);
350
      RubikObjectList.saveMeshState(editor);
351
      ScreenList.savePreferences(editor);
352
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
353
      OSInterface os = view.getInterface();
354
      os.setEditor(editor);
355
      view.getObjectControl().savePreferences();
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
      mSolverIndex = preferences.getInt("solverIndex",0);
381

    
382
      parseOldVersion(mOldVersion);
383

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

    
386
      for (int i=0; i<ScreenList.LENGTH; i++)
387
        {
388
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
389
        }
390

    
391
      RubikScores scores = RubikScores.getInstance();
392

    
393
      if( scores.isVerified() )
394
        {
395
        FirebaseAnalytics analytics = getAnalytics();
396
        analytics.setUserId(scores.getName());
397
        }
398

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

    
403
      if( justStarted && numStars==0 && oldVersionLessThan(1,11,4) )
404
        {
405
        scores.correctNumStars();
406
        }
407

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

    
418
      ScreenList.restorePreferences(preferences);
419

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

    
429
      if( !mOldVersion.equals("") )
430
        {
431
        RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
432
        OSInterface os = view.getInterface();
433
        os.setPreferences(preferences);
434
        view.getObjectControl().restorePreferences();
435
        }
436
      }
437

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439

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

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

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

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

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

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

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

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

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

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

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501
// PUBLIC API
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

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

    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

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

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

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

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

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

    
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532

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

    
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540

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

    
547
///////////////////////////////////////////////////////////////////////////////////////////////////
548

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

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

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

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

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

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

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

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

    
601
///////////////////////////////////////////////////////////////////////////////////////////////////
602

    
603
    public void changeIfDifferent(int ordinal, ObjectControl control)
604
      {
605
      RubikObject object = RubikObjectList.getObject(ordinal);
606
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
607
      int iconMode  = TwistyObject.MODE_NORM;
608
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
609
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
610
      String name = object==null ? "NULL" : object.getUpperName();
611
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
612
      OSInterface os = view.getInterface();
613
      InitAssets asset = new InitAssets(jsonStream,meshStream,os);
614

    
615
      control.changeIfDifferent(ordinal,name,meshState,iconMode,asset);
616
      }
617

    
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

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

    
628
///////////////////////////////////////////////////////////////////////////////////////////////////
629

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

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

    
643
///////////////////////////////////////////////////////////////////////////////////////////////////
644

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

    
650
///////////////////////////////////////////////////////////////////////////////////////////////////
651

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

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

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

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

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

    
675
///////////////////////////////////////////////////////////////////////////////////////////////////
676

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

    
683
///////////////////////////////////////////////////////////////////////////////////////////////////
684

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

    
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694

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

    
702
///////////////////////////////////////////////////////////////////////////////////////////////////
703

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

    
710
///////////////////////////////////////////////////////////////////////////////////////////////////
711

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

    
719
///////////////////////////////////////////////////////////////////////////////////////////////////
720

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

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

    
730
        if( object!=null )
731
          {
732
          int meshState = object.getMeshState();
733
          int iconMode  = TwistyObject.MODE_NORM;
734
          InputStream jsonStream = object.getObjectStream(this);
735
          InputStream meshStream = object.getMeshStream(this);
736
          RubikSurfaceView view  = findViewById(R.id.rubikSurfaceView);
737
          OSInterface os         = view.getInterface();
738
          InitAssets asset       = new InitAssets(jsonStream,meshStream,os);
739
          ObjectControl control  = getControl();
740
          control.changeObject(-1,meshState,iconMode,asset);
741
          }
742
        }
743
      }
744

    
745
///////////////////////////////////////////////////////////////////////////////////////////////////
746

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

    
752
///////////////////////////////////////////////////////////////////////////////////////////////////
753

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

    
759
///////////////////////////////////////////////////////////////////////////////////////////////////
760

    
761
   public OperatingSystemInterface getInterface()
762
     {
763
     RubikSurfaceView view  = findViewById(R.id.rubikSurfaceView);
764
     return view.getInterface();
765
     }
766
}
(1-1/4)