Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 0effd5a9

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
      // switch this off - we are not present in China anymore.
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< ScreenList.LENGTH; i++)
346
        {
347
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
348
        }
349

    
350
      RubikObjectList.savePreferences(editor);
351
      RubikObjectList.saveMeshState(editor);
352
      ScreenList.savePreferences(editor);
353
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
354
      OSInterface os = view.getInterface();
355
      os.setEditor(editor);
356
      view.getObjectControl().savePreferences();
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<ScreenList.LENGTH; i++)
388
        {
389
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
390
        }
391

    
392
      RubikScores scores = RubikScores.getInstance();
393

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

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

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

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

    
419
      ScreenList.restorePreferences(preferences);
420

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
616
      control.changeIfDifferent(ordinal,name,meshState,iconMode,asset);
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(int objectOrdinal)
706
      {
707
      Intent intent = new Intent(this, BandagedCreatorActivity.class);
708
      intent.putExtra("obj", objectOrdinal);
709
      startActivity(intent);
710
      }
711

    
712
///////////////////////////////////////////////////////////////////////////////////////////////////
713

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

    
721
///////////////////////////////////////////////////////////////////////////////////////////////////
722

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

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

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

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

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

    
754
///////////////////////////////////////////////////////////////////////////////////////////////////
755

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

    
761
///////////////////////////////////////////////////////////////////////////////////////////////////
762

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