Project

General

Profile

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

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

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
import org.distorted.objectlib.effects.BaseEffect;
48

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

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

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

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

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

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

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

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

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

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

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

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

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

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

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

    
144
      thread.start();
145
      }
146

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

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

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

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

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

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

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

    
177
        decorView.setSystemUiVisibility(FLAGS);
178

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

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

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

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

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

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
// do not avoid cutouts
215

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

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

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

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

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

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

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

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

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

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

    
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

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

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

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

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

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

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

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

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

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

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

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

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

    
361
      ScreenList curr = ScreenList.getCurrentScreen();
362

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

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

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

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

    
386
      parseOldVersion(mOldVersion);
387

    
388
      RubikObjectList.restorePreferences(this,preferences,justStarted);
389

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

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

    
400
      RubikScores scores = RubikScores.getInstance();
401

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

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

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

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

    
427
      ScreenList.restorePreferences(preferences);
428

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

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

    
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446

    
447
    private void parseOldVersion(String version)
448
      {
449
      if( version==null ) return;
450

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

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

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

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

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

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

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

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

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

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508
// PUBLIC API
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
    public FirebaseAnalytics getAnalytics()
512
      {
513
      return mFirebaseAnalytics;
514
      }
515

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

    
518
    public int getHeightUpperBar()
519
      {
520
      return mHeightUpperBar;
521
      }
522

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

    
525
    public int getHeightLowerBar()
526
      {
527
      return mHeightLowerBar;
528
      }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531

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

    
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539

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

    
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547

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

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

    
556
    public int getScreenWidthInPixels()
557
      {
558
      return mScreenWidth;
559
      }
560

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

    
563
    public int getScreenHeightInPixels()
564
      {
565
      return mScreenHeight;
566
      }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

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

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

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

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

    
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609

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

    
622
      control.changeIfDifferent(ordinal,name,meshState,iconMode,asset);
623
      }
624

    
625
///////////////////////////////////////////////////////////////////////////////////////////////////
626

    
627
    public static int getDrawableSize()
628
      {
629
      if( mScreenHeight<1000 ) return 0;
630
      if( mScreenHeight<1600 ) return 1;
631
      if( mScreenHeight<1900 ) return 2;
632
      return 3;
633
      }
634

    
635
///////////////////////////////////////////////////////////////////////////////////////////////////
636

    
637
    public static int getDrawable(int small, int medium, int big, int huge)
638
      {
639
      int size = getDrawableSize();
640

    
641
      switch(size)
642
        {
643
        case 0 : return small;
644
        case 1 : return medium;
645
        case 2 : return big;
646
        default: return huge;
647
        }
648
      }
649

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

    
652
    public void acceptPrivacy()
653
      {
654
      mPolicyAccepted = true;
655
      }
656

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

    
659
    public void declinePrivacy()
660
      {
661
      finish();
662
      }
663

    
664
///////////////////////////////////////////////////////////////////////////////////////////////////
665

    
666
    public static boolean localeIsChinese()
667
      {
668
      String language;
669

    
670
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
671
        {
672
        language= LocaleList.getDefault().get(0).getLanguage();
673
        }
674
      else
675
        {
676
        language= Locale.getDefault().getLanguage();
677
        }
678

    
679
      return language.equals("zh");
680
      }
681

    
682
///////////////////////////////////////////////////////////////////////////////////////////////////
683

    
684
    public boolean isVertical()
685
      {
686
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
687
      return view.isVertical();
688
      }
689

    
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691

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

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

    
702
    public void switchConfig(int objectOrdinal)
703
      {
704
      Intent intent = new Intent(this, ConfigActivity.class);
705
      intent.putExtra("obj", objectOrdinal);
706
      startActivity(intent);
707
      }
708

    
709
///////////////////////////////////////////////////////////////////////////////////////////////////
710

    
711
    public void switchToBandagedCreator()
712
      {
713
      Intent intent = new Intent(this, BandagedCreatorActivity.class);
714
      startActivity(intent);
715
      }
716

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

    
719
    public void switchToPurchase(int objectOrdinal)
720
      {
721
      Intent intent = new Intent(this, PurchaseActivity.class);
722
      intent.putExtra("obj", objectOrdinal);
723
      startActivity(intent);
724
      }
725

    
726
///////////////////////////////////////////////////////////////////////////////////////////////////
727

    
728
    public void reloadObject(String shortName)
729
      {
730
      TwistyObject currObject = getObject();
731
      String name = currObject==null ? "" : currObject.getShortName();
732

    
733
      if( name.toLowerCase(Locale.ENGLISH).equals(shortName) )
734
        {
735
        RubikObject object = RubikObjectList.getObject(name);
736

    
737
        if( object!=null )
738
          {
739
          int meshState = object.getMeshState();
740
          int iconMode  = TwistyObject.MODE_NORM;
741
          InputStream jsonStream = object.getObjectStream(this);
742
          InputStream meshStream = object.getMeshStream(this);
743
          RubikSurfaceView view  = findViewById(R.id.rubikSurfaceView);
744
          OSInterface os         = view.getInterface();
745
          InitAssets asset       = new InitAssets(jsonStream,meshStream,os);
746
          ObjectControl control  = getControl();
747
          control.changeObject(-1,meshState,iconMode,asset);
748
          }
749
        }
750
      }
751

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

    
754
    public void setSolverIndex(int index)
755
      {
756
      mSolverIndex = index;
757
      }
758

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

    
761
    public int getSolverIndex()
762
      {
763
      return mSolverIndex;
764
      }
765

    
766
///////////////////////////////////////////////////////////////////////////////////////////////////
767

    
768
   public OperatingSystemInterface getInterface()
769
     {
770
     RubikSurfaceView view  = findViewById(R.id.rubikSurfaceView);
771
     return view.getInterface();
772
     }
773
}
(1-1/4)