Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 00fcfefa

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.library.main.DistortedLibrary;
39

    
40
import org.distorted.library.main.DistortedScreen;
41
import org.distorted.messaging.RubikInAppMessanging;
42
import org.distorted.objectlib.main.ObjectControl;
43
import org.distorted.objectlib.main.TwistyObject;
44
import org.distorted.objectlib.effects.BaseEffect;
45

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

    
58
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
public class RubikActivity extends AppCompatActivity
63
{
64
    public static final boolean SHOW_DOWNLOADED_DEBUG = false;
65
    public static final boolean SHOW_SOLVED_DEBUG     = true;
66

    
67
    public static final float PADDING             = 0.01f;
68
    public static final float SMALL_MARGIN        = 0.004f;
69
    public static final float MEDIUM_MARGIN       = 0.015f;
70
    public static final float LARGE_MARGIN        = 0.025f;
71
    public static final float POPUP_PADDING       = 0.045f;
72
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
73
    public static final float TITLE_TEXT_SIZE     = 0.06f;
74
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
75
    public static final float SOLVER_BMP_V_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 TUTORIAL_ITEM_TEXT  = 0.100f;
81
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
82
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
83
    public static final float MENU_MAIN_TEXT_SIZE = 0.047f;
84
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
85
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
86
    public static final float TAB_WIDTH           = 0.100f;
87
    public static final float TAB_HEIGHT          = 0.100f;
88
    public static final float MENU_BUTTON_HEIGHT  = 0.115f;
89

    
90
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
91
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
92
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
93
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
94
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
95

    
96
    private static final int ACTIVITY_NUMBER = 0;
97
    private static final float RATIO_BAR  = 0.10f;
98
    private static final float RATIO_INSET= 0.09f;
99

    
100
    private static final String KEY_PLAY = "movesController_play";
101
    private static final String KEY_SOLV = "movesController_solv";
102

    
103
    private boolean mJustStarted;
104
    private FirebaseAnalytics mFirebaseAnalytics;
105
    private static int mScreenWidth, mScreenHeight;
106
    private boolean mPolicyAccepted, mIsChinese;
107
    private int mCurrentApiVersion;
108
    private int mHeightUpperBar, mHeightLowerBar;
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

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

    
118
      setTheme(R.style.MaterialThemeNoActionBar);
119
      setContentView(R.layout.main);
120

    
121
      mJustStarted = true;
122
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
123
      mIsChinese = localeIsChinese();
124

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

    
130
      hideNavigationBar();
131
      cutoutHack();
132
      computeBarHeights();
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
      unblockEverything();
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
      }
279
    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281
    
282
    @Override
283
    protected void onDestroy() 
284
      {
285
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
286
      super.onDestroy();
287
      }
288

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

    
291
    private String getAppVers()
292
      {
293
      try
294
        {
295
        PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
296
        return pInfo.versionName;
297
        }
298
      catch (PackageManager.NameNotFoundException e)
299
        {
300
        return "unknown";
301
        }
302
      }
303

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

    
306
    private void savePreferences()
307
      {
308
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
309
      SharedPreferences.Editor editor = preferences.edit();
310

    
311
      editor.putBoolean("policyAccepted", mPolicyAccepted);
312
      editor.putString("appVersion", getAppVers() );
313

    
314
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
315
        {
316
        BaseEffect.Type.getType(i).savePreferences(editor);
317
        }
318

    
319
      for (int i = 0; i< ScreenList.LENGTH; i++)
320
        {
321
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
322
        }
323

    
324
      RubikObjectList.savePreferences(editor);
325
      RubikObjectList.saveMeshState(editor);
326
      ScreenList.savePreferences(editor);
327
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
328
      view.getObjectControl().savePreferences(editor);
329

    
330
      ScreenList curr = ScreenList.getCurrentScreen();
331

    
332
      if( curr==ScreenList.PLAY )
333
        {
334
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
335
        play.saveMovePreferences(KEY_PLAY,editor);
336
        }
337
      if( curr==ScreenList.SOLV )
338
        {
339
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
340
        solv.saveMovePreferences(KEY_SOLV,editor);
341
        }
342

    
343
      boolean success = editor.commit();
344
      if( !success ) android.util.Log.e("D", "Failed to save preferences");
345
      }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
    private void restorePreferences(SharedPreferences preferences, boolean justStarted)
350
      {
351
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
352
      String oldVersion = preferences.getString("appVersion","");
353

    
354
      RubikObjectList.restorePreferences(this,preferences,justStarted);
355

    
356
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
357
        {
358
        BaseEffect.Type.getType(i).restorePreferences(preferences);
359
        }
360

    
361
      for (int i=0; i<ScreenList.LENGTH; i++)
362
        {
363
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
364
        }
365

    
366
      // this needs to be after the above ScreenList.restore as that restores the Records which we need here
367
      if( justStarted ) RubikObjectList.setObjectFreeState();
368

    
369
      ScreenList.restorePreferences(preferences);
370
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
371

    
372
      // Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their
373
      // case the 'mOldVersion' - version of the app which saved the preferences on the last
374
      // go - is empty.
375
      // Between versions 1.8.6 and 1.9.0, the order of the cubits in TwistyCube has changed.
376
      // If someone has scrambled the cube with v. 1.8.6, then upgraded to 1.9.0 and re-started
377
      // the app, because of the different order of the cubits - his cube would be messed up.
378
      // So in such case, i.e. on fresh upgrade from version<=1.8.6 to version>=1.9.0, do not
379
      // restore the object scrambling.
380

    
381
      if( !oldVersion.equals("") )
382
        {
383
        view.getObjectControl().restorePreferences(preferences);
384
        }
385

    
386
      RubikScores scores = RubikScores.getInstance();
387

    
388
      if( scores.isVerified() )
389
        {
390
        FirebaseAnalytics analytics = getAnalytics();
391
        analytics.setUserId(scores.getName());
392
        }
393

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

    
398
      if( numStars==0 && upgradingFromVersionWithNoStars(oldVersion) )
399
        {
400
        scores.correctNumStars();
401
        }
402
      }
403

    
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

    
406
    private boolean upgradingFromVersionWithNoStars(String version)
407
      {
408
      if( version!=null )
409
        {
410
        try
411
          {
412
          int dot = version.indexOf('.',2);
413

    
414
          if( dot>2 )
415
            {
416
            String middle = version.substring(2,dot);
417
            int middleInt = Integer.parseInt(middle);
418

    
419
            if( middleInt<11 ) return true;
420
            if( middleInt==11 )
421
              {
422
              String end = version.substring(dot+1);
423
              int endInt = Integer.parseInt(end);
424
              return endInt<4;
425
              }
426
            }
427
          }
428
        catch(Exception ignored) {}
429
        }
430

    
431
      return false;
432
      }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
    private void restoreMoves(SharedPreferences preferences)
437
      {
438
      ScreenList curr = ScreenList.getCurrentScreen();
439

    
440
      if( curr==ScreenList.PLAY )
441
        {
442
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
443
        play.restoreMovePreferences(this,KEY_PLAY,preferences);
444
        }
445
      if( curr==ScreenList.SOLV )
446
        {
447
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
448
        solv.restoreMovePreferences(this,KEY_SOLV,preferences);
449
        }
450
      }
451

    
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453

    
454
    private void PrivacyPolicy()
455
      {
456
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
457
      priDiag.show(getSupportFragmentManager(), null);
458
      }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
    void OpenGLError()
463
      {
464
      RubikDialogError errDiag = new RubikDialogError();
465
      errDiag.show(getSupportFragmentManager(), null);
466
      }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469
// PUBLIC API
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

    
472
    public FirebaseAnalytics getAnalytics()
473
      {
474
      return mFirebaseAnalytics;
475
      }
476

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

    
479
    public int getHeightUpperBar()
480
      {
481
      return mHeightUpperBar;
482
      }
483

    
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485

    
486
    public int getHeightLowerBar()
487
      {
488
      return mHeightLowerBar;
489
      }
490

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492

    
493
    public TwistyObject getObject()
494
      {
495
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
496
      return view.getObjectControl().getObject();
497
      }
498

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

    
501
    public DistortedScreen getScreen()
502
      {
503
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
504
      return view.getRenderer().getScreen();
505
      }
506

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508

    
509
    public ObjectControl getControl()
510
      {
511
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
512
      return view.getObjectControl();
513
      }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516

    
517
    public int getScreenWidthInPixels()
518
      {
519
      return mScreenWidth;
520
      }
521

    
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523

    
524
    public int getScreenHeightInPixels()
525
      {
526
      return mScreenHeight;
527
      }
528

    
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530

    
531
    public void changeObject(int newObject, boolean reportChange)
532
      {
533
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
534
      ObjectControl control = view.getObjectControl();
535
      TwistyObject oldObject = control.getObject();
536
      changeIfDifferent(newObject,control);
537

    
538
      if( reportChange && oldObject!=null )
539
        {
540
        RubikObject robject = RubikObjectList.getObject(newObject);
541
        String newName = robject==null ? "NULL" : robject.getUpperName();
542
        float fps = view.getRenderer().getFPS();
543
        fps = (int)(fps+0.5f);
544
        StringBuilder name = new StringBuilder();
545
        name.append(oldObject.getShortName());
546
        name.append(' ');
547
        name.append(fps);
548
        name.append(" --> ");
549
        name.append(newName);
550

    
551
        if( BuildConfig.DEBUG )
552
          {
553
          android.util.Log.e("rubik", name.toString());
554
          }
555
        else
556
          {
557
          FirebaseAnalytics analytics = getAnalytics();
558

    
559
          if( analytics!=null )
560
            {
561
            Bundle bundle = new Bundle();
562
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
563
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
564
            }
565
          }
566
        }
567
      }
568

    
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570

    
571
    public void changeIfDifferent(int ordinal, ObjectControl control)
572
      {
573
      RubikObject object = RubikObjectList.getObject(ordinal);
574
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
575
      int iconMode  = TwistyObject.MODE_NORM;
576
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
577
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
578
      String name = object==null ? "NULL" : object.getUpperName();
579

    
580
      control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
581
      }
582

    
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584

    
585
    public static int getDrawableSize()
586
      {
587
      if( mScreenHeight<1000 )
588
        {
589
        return 0;
590
        }
591
      if( mScreenHeight<1600 )
592
        {
593
        return 1;
594
        }
595
      if( mScreenHeight<1900 )
596
        {
597
        return 2;
598
        }
599

    
600
      return 3;
601
      }
602

    
603
///////////////////////////////////////////////////////////////////////////////////////////////////
604

    
605
    public static int getDrawable(int small, int medium, int big, int huge)
606
      {
607
      int size = getDrawableSize();
608

    
609
      switch(size)
610
        {
611
        case 0 : return small;
612
        case 1 : return medium;
613
        case 2 : return big;
614
        default: return huge;
615
        }
616
      }
617

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

    
620
    public void acceptPrivacy()
621
      {
622
      mPolicyAccepted = true;
623
      }
624

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

    
627
    public void declinePrivacy()
628
      {
629
      finish();
630
      }
631

    
632
///////////////////////////////////////////////////////////////////////////////////////////////////
633

    
634
    public static boolean localeIsChinese()
635
      {
636
      String language;
637

    
638
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
639
        {
640
        language= LocaleList.getDefault().get(0).getLanguage();
641
        }
642
      else
643
        {
644
        language= Locale.getDefault().getLanguage();
645
        }
646

    
647
      return language.equals("zh");
648
      }
649

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

    
652
    public boolean isVertical()
653
      {
654
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
655
      return view.isVertical();
656
      }
657

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

    
660
    public void blockEverything(int place)
661
      {
662
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
663
      ObjectControl control = view.getObjectControl();
664
      control.blockEverything(place);
665

    
666
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
667
      play.setLockState(this);
668
      }
669

    
670
///////////////////////////////////////////////////////////////////////////////////////////////////
671

    
672
    public void unblockEverything()
673
      {
674
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
675
      ObjectControl control = view.getObjectControl();
676
      control.unblockEverything();
677

    
678
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
679
      play.setLockState(this);
680
      }
681

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

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

    
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693

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

    
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702

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

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

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

    
718
///////////////////////////////////////////////////////////////////////////////////////////////////
719

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

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

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