Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 2afc6754

1 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4 fdec60a3 Leszek Koltunski
// This file is part of Magic Cube.                                                              //
5 0c52af30 Leszek Koltunski
//                                                                                               //
6 fdec60a3 Leszek Koltunski
// Magic Cube is free software: you can redistribute it and/or modify                            //
7 0c52af30 Leszek Koltunski
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11 fdec60a3 Leszek Koltunski
// Magic Cube is distributed in the hope that it will be useful,                                 //
12 0c52af30 Leszek Koltunski
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17 fdec60a3 Leszek Koltunski
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 1f9772f3 Leszek Koltunski
package org.distorted.main;
21 0c52af30 Leszek Koltunski
22 2afc6754 Leszek Koltunski
import java.util.Locale;
23
24 b6468abb Leszek Koltunski
import android.content.Intent;
25 33499c56 Leszek Koltunski
import android.content.SharedPreferences;
26 b1e9596b Leszek Koltunski
import android.os.Build;
27 0c52af30 Leszek Koltunski
import android.os.Bundle;
28 b1e9596b Leszek Koltunski
import android.os.LocaleList;
29 33499c56 Leszek Koltunski
import android.preference.PreferenceManager;
30 e3c74c0f Leszek Koltunski
31
import android.util.DisplayMetrics;
32 fd0b901a Leszek Koltunski
import android.view.DisplayCutout;
33 0254cfd7 Leszek Koltunski
import android.view.View;
34 1cb36646 Leszek Koltunski
import android.view.ViewGroup;
35 c9556e1e Leszek Koltunski
import android.view.WindowManager;
36 1cb36646 Leszek Koltunski
import android.widget.LinearLayout;
37 0c52af30 Leszek Koltunski
38 1b3cbd5b Leszek Koltunski
import com.google.firebase.analytics.FirebaseAnalytics;
39
40 3f7a4363 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
41
import org.distorted.library.main.DistortedScreen;
42
43 2afc6754 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
44 3f7a4363 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
45 318c0a7d Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
46 88a3e972 Leszek Koltunski
import org.distorted.objectlib.helpers.BlockController;
47 2afc6754 Leszek Koltunski
import org.distorted.objectlib.effects.BaseEffect;
48
import org.distorted.objectlib.helpers.TwistyActivity;
49 3f7a4363 Leszek Koltunski
50 2d9fc972 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
51 b1e9596b Leszek Koltunski
import org.distorted.dialogs.RubikDialogPrivacy;
52 6a083c6a Leszek Koltunski
import org.distorted.network.RubikScores;
53
import org.distorted.network.RubikNetwork;
54 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
55
import org.distorted.screens.RubikScreenPlay;
56 eaf87d1d Leszek Koltunski
import org.distorted.tutorials.TutorialActivity;
57 211b48f2 Leszek Koltunski
58 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
59
60 55e6be1d Leszek Koltunski
public class RubikActivity extends TwistyActivity
61 0c52af30 Leszek Koltunski
{
62 054fbee1 Leszek Koltunski
    public static final float PADDING             = 0.01f;
63
    public static final float MARGIN              = 0.004f;
64
    public static final float LARGE_MARGIN        = 0.025f;
65
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
66
    public static final float TITLE_TEXT_SIZE     = 0.06f;
67 7ea57482 Leszek Koltunski
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
68
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
69 045857e5 Leszek Koltunski
    public static final float MENU_ITEM_SIZE      = 0.11f;
70 5de2c572 Leszek Koltunski
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
71
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
72 362807f0 Leszek Koltunski
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
73
    public static final float SCORES_ITEM_TEXT    = 0.030f;
74 ef1f3e34 Leszek Koltunski
    public static final float TUTORIAL_ITEM_TEXT  = 0.100f;
75 eb376d3a Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
76
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
77
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
78
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
79 e3c74c0f Leszek Koltunski
80 af7b68e6 Leszek Koltunski
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
81 ffd68f35 Leszek Koltunski
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
82
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
83
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
84
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
85
86 e365b6c2 Leszek Koltunski
    public static final int FLAGS2=  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
87
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
88
89 598de3ee Leszek Koltunski
    private static final float RATIO_BAR  = 0.10f;
90
    private static final float RATIO_INSET= 0.08f;
91
92 c3ffcf58 Leszek Koltunski
    private boolean mJustStarted;
93 1b3cbd5b Leszek Koltunski
    private FirebaseAnalytics mFirebaseAnalytics;
94 f6a9c538 Leszek Koltunski
    private static int mScreenWidth, mScreenHeight;
95 b1e9596b Leszek Koltunski
    private boolean mPolicyAccepted, mIsChinese;
96 0254cfd7 Leszek Koltunski
    private int mCurrentApiVersion;
97 598de3ee Leszek Koltunski
    private int mHeightUpperBar, mHeightLowerBar;
98 c3ffcf58 Leszek Koltunski
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
101 0c52af30 Leszek Koltunski
    @Override
102 34747dd1 Leszek Koltunski
    protected void onCreate(Bundle savedState)
103 0c52af30 Leszek Koltunski
      {
104 34747dd1 Leszek Koltunski
      super.onCreate(savedState);
105 d7de3072 Leszek Koltunski
      DistortedLibrary.onCreate(0);
106
107 f6fcf06a Leszek Koltunski
      setTheme(R.style.CustomActivityThemeNoActionBar);
108 1cbcc6bf Leszek Koltunski
      setContentView(R.layout.main);
109 c3ffcf58 Leszek Koltunski
110
      mJustStarted = true;
111 1b3cbd5b Leszek Koltunski
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
112 e3c74c0f Leszek Koltunski
113
      DisplayMetrics displaymetrics = new DisplayMetrics();
114
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
115 88fb92ba Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
116
      mScreenHeight=displaymetrics.heightPixels;
117 b1e9596b Leszek Koltunski
118
      mIsChinese = localeIsChinese();
119 55e6be1d Leszek Koltunski
      unlock();
120 0254cfd7 Leszek Koltunski
121
      hideNavigationBar();
122 e8f6670f Leszek Koltunski
      cutoutHack();
123 598de3ee Leszek Koltunski
      computeBarHeights();
124 0254cfd7 Leszek Koltunski
      }
125
126 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
127
// this does not include possible insets
128
129
    private void computeBarHeights()
130
      {
131
      float height = getScreenHeightInPixels();
132
      int barHeight = (int)(height*RATIO_BAR);
133
      mHeightLowerBar = barHeight;
134
      mHeightUpperBar = barHeight;
135 214e301a Leszek Koltunski
136
      LinearLayout layoutTop = findViewById(R.id.upperBar);
137
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
138
139
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
140
      paramsTop.height = mHeightUpperBar;
141
      layoutTop.setLayoutParams(paramsTop);
142
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
143
      paramsBot.height = mHeightLowerBar;
144
      layoutBot.setLayoutParams(paramsBot);
145 598de3ee Leszek Koltunski
      }
146
147 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
148
149
    private void hideNavigationBar()
150
      {
151 c9556e1e Leszek Koltunski
      mCurrentApiVersion = Build.VERSION.SDK_INT;
152 0254cfd7 Leszek Koltunski
153
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
154
        {
155
        final View decorView = getWindow().getDecorView();
156
157 c9556e1e Leszek Koltunski
        decorView.setSystemUiVisibility(FLAGS);
158
159 0254cfd7 Leszek Koltunski
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
160
          {
161
          @Override
162
          public void onSystemUiVisibilityChange(int visibility)
163
            {
164
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
165
              {
166 ffd68f35 Leszek Koltunski
              decorView.setSystemUiVisibility(FLAGS);
167 0254cfd7 Leszek Koltunski
              }
168
            }
169
          });
170
        }
171
      }
172
173 1cb36646 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175
    @Override
176
    public void onAttachedToWindow()
177
      {
178 fd0b901a Leszek Koltunski
      super.onAttachedToWindow();
179
180 e8f6670f Leszek Koltunski
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
181
        {
182
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
183
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
184
185
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
186
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
187 598de3ee Leszek Koltunski
        paramsHid.height = (int)(insetHeight*RATIO_INSET);
188 e8f6670f Leszek Koltunski
        layoutHid.setLayoutParams(paramsHid);
189 598de3ee Leszek Koltunski
        mHeightUpperBar += paramsHid.height;
190 e8f6670f Leszek Koltunski
        }
191 1cb36646 Leszek Koltunski
      }
192
193 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
194 e8f6670f Leszek Koltunski
// do not avoid cutouts
195 c9556e1e Leszek Koltunski
196 e8f6670f Leszek Koltunski
    private void cutoutHack()
197 c9556e1e Leszek Koltunski
      {
198
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
199
        {
200
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
201
        }
202
      }
203
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205 0254cfd7 Leszek Koltunski
206
    @Override
207
    public void onWindowFocusChanged(boolean hasFocus)
208
      {
209
      super.onWindowFocusChanged(hasFocus);
210
211
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
212
        {
213 ffd68f35 Leszek Koltunski
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
214 0254cfd7 Leszek Koltunski
        }
215
      }
216
217 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
218
    
219
    @Override
220
    protected void onPause() 
221
      {
222 82f42eeb Leszek Koltunski
      super.onPause();
223 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
224 0c52af30 Leszek Koltunski
      view.onPause();
225 d7de3072 Leszek Koltunski
      DistortedLibrary.onPause(0);
226 809c3432 Leszek Koltunski
      BlockController.onPause();
227 6a083c6a Leszek Koltunski
      RubikNetwork.onPause();
228 33499c56 Leszek Koltunski
      savePreferences();
229 0c52af30 Leszek Koltunski
      }
230
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232
    
233
    @Override
234
    protected void onResume() 
235
      {
236
      super.onResume();
237 d7de3072 Leszek Koltunski
      DistortedLibrary.onResume(0);
238 809c3432 Leszek Koltunski
      BlockController.onResume();
239 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
240 0c52af30 Leszek Koltunski
      view.onResume();
241 33499c56 Leszek Koltunski
      restorePreferences();
242 f5da732a Leszek Koltunski
      ScreenList.setScreen(this);
243 8badfe2a Leszek Koltunski
      unblockEverything();
244 4888e97c Leszek Koltunski
245 c3ffcf58 Leszek Koltunski
      if( mJustStarted )
246
        {
247
        mJustStarted = false;
248 82ce8e64 Leszek Koltunski
        RubikScores scores = RubikScores.getInstance();
249
        scores.incrementNumRuns();
250
        scores.setCountry(this);
251 c3ffcf58 Leszek Koltunski
        }
252
253 f5da732a Leszek Koltunski
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
254 8ab435b9 Leszek Koltunski
      ObjectType object = play.getObject();
255 2afc6754 Leszek Koltunski
      view.getObjectControl().changeObject(object);
256 8ab435b9 Leszek Koltunski
      
257 b1e9596b Leszek Koltunski
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
258 0c52af30 Leszek Koltunski
      }
259
    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261
    
262
    @Override
263
    protected void onDestroy() 
264
      {
265 d7de3072 Leszek Koltunski
      DistortedLibrary.onDestroy(0);
266 0c52af30 Leszek Koltunski
      super.onDestroy();
267
      }
268
269 33499c56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
270
271
    private void savePreferences()
272
      {
273
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
274
      SharedPreferences.Editor editor = preferences.edit();
275
276 b1e9596b Leszek Koltunski
      editor.putBoolean("policyAccepted", mPolicyAccepted);
277
278 211b48f2 Leszek Koltunski
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
279 33499c56 Leszek Koltunski
        {
280
        BaseEffect.Type.getType(i).savePreferences(editor);
281
        }
282
283 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
284 211b48f2 Leszek Koltunski
        {
285 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
286 211b48f2 Leszek Koltunski
        }
287 33499c56 Leszek Koltunski
288 fcd5b990 Leszek Koltunski
      ScreenList.savePreferences(editor);
289 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
290 2afc6754 Leszek Koltunski
      view.getObjectControl().savePreferences(editor);
291 0333d81e Leszek Koltunski
292 33499c56 Leszek Koltunski
      editor.apply();
293
      }
294
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296
297
    private void restorePreferences()
298
      {
299
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
300
301 b1e9596b Leszek Koltunski
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
302
303 33499c56 Leszek Koltunski
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
304 4235de9b Leszek Koltunski
        {
305 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
306 4235de9b Leszek Koltunski
        }
307 33499c56 Leszek Koltunski
308 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
309 211b48f2 Leszek Koltunski
        {
310 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
311 211b48f2 Leszek Koltunski
        }
312 33499c56 Leszek Koltunski
313 fcd5b990 Leszek Koltunski
      ScreenList.restorePreferences(preferences);
314 0333d81e Leszek Koltunski
315
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
316 2afc6754 Leszek Koltunski
      view.getObjectControl().restorePreferences(preferences);
317 ee4e7896 Leszek Koltunski
318
      RubikScores scores = RubikScores.getInstance();
319
320
      if( scores.isVerified() )
321
        {
322
        FirebaseAnalytics analytics = getAnalytics();
323
        analytics.setUserId(scores.getName());
324
        }
325 f3e12931 Leszek Koltunski
      }
326
327 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
328
329
    private void PrivacyPolicy()
330
      {
331
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
332
      priDiag.show(getSupportFragmentManager(), null);
333
      }
334
335 2d9fc972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
336
337 e7e0a94d Leszek Koltunski
    void OpenGLError()
338 2d9fc972 Leszek Koltunski
      {
339
      RubikDialogError errDiag = new RubikDialogError();
340
      errDiag.show(getSupportFragmentManager(), null);
341
      }
342
343 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
344 47ba5ddc Leszek Koltunski
// PUBLIC API
345 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
346
347
    public FirebaseAnalytics getAnalytics()
348
      {
349
      return mFirebaseAnalytics;
350
      }
351
352 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
353
354
    public int getHeightUpperBar()
355
      {
356
      return mHeightUpperBar;
357
      }
358
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
361
    public int getHeightLowerBar()
362
      {
363
      return mHeightLowerBar;
364
      }
365
366 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
367
368 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
369 aa171dee Leszek Koltunski
      {
370
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
371 2afc6754 Leszek Koltunski
      return view.getObjectControl().getObject();
372 8becce57 Leszek Koltunski
      }
373
374 f8eece7d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
375
376 2afc6754 Leszek Koltunski
    public ObjectControl getControl()
377 f8eece7d Leszek Koltunski
      {
378
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
379 2afc6754 Leszek Koltunski
      return view.getObjectControl();
380 f8eece7d Leszek Koltunski
      }
381
382 e3c74c0f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
383
384 2afc6754 Leszek Koltunski
    public DistortedScreen getScreen()
385 55e6be1d Leszek Koltunski
      {
386
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
387 2afc6754 Leszek Koltunski
      RubikRenderer renderer = view.getRenderer();
388
      return renderer.getScreen();
389 88fb92ba Leszek Koltunski
      }
390
391 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
392
393 8ba7aeb1 Leszek Koltunski
    public int getScreenWidthInPixels()
394 8becce57 Leszek Koltunski
      {
395 8ba7aeb1 Leszek Koltunski
      return mScreenWidth;
396
      }
397
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399
400
    public int getScreenHeightInPixels()
401
      {
402
      return mScreenHeight;
403 aa171dee Leszek Koltunski
      }
404
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406
407 318c0a7d Leszek Koltunski
    public void changeObject(ObjectType newObject, boolean reportChange)
408 769d7b9f Leszek Koltunski
      {
409
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
410 2afc6754 Leszek Koltunski
      ObjectControl control = view.getObjectControl();
411 7eae2d49 Leszek Koltunski
412
      if( reportChange )
413
        {
414 2afc6754 Leszek Koltunski
        TwistyObject oldObject = control.getObject();
415 7eae2d49 Leszek Koltunski
416 03822c33 Leszek Koltunski
        if( oldObject!=null )
417
          {
418 c4175d85 Leszek Koltunski
          ObjectType oldList = oldObject.getObjectType();
419 03822c33 Leszek Koltunski
          float fps = view.getRenderer().getFPS();
420
          fps = (int)(fps+0.5f);
421
          StringBuilder name = new StringBuilder();
422
          name.append(oldList.name());
423
          name.append(' ');
424
          name.append(fps);
425
          name.append(" --> ");
426
          name.append(newObject.name());
427
428
          if( BuildConfig.DEBUG )
429 7eae2d49 Leszek Koltunski
            {
430 03822c33 Leszek Koltunski
            android.util.Log.e("rubik", name.toString());
431
            }
432
          else
433
            {
434
            FirebaseAnalytics analytics = getAnalytics();
435
436
            if( analytics!=null )
437
              {
438
              Bundle bundle = new Bundle();
439
              bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
440
              analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
441
              }
442 7eae2d49 Leszek Koltunski
            }
443
          }
444
        }
445
446 2afc6754 Leszek Koltunski
      control.changeObject(newObject);
447 2e8ec627 Leszek Koltunski
      }
448
449 88a3e972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
450
451
  public boolean isLocked()
452
    {
453
    ScreenList state = ScreenList.getCurrentScreen();
454
455
    if( state== ScreenList.PLAY || state== ScreenList.READ || state== ScreenList.SOLV )
456
      {
457
      return retLocked();
458
      }
459
460
    return false;
461
    }
462
463 2e8ec627 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
464
465 318c0a7d Leszek Koltunski
    public void setupObject(ObjectType object, int[][] moves)
466 2e8ec627 Leszek Koltunski
      {
467
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
468 2afc6754 Leszek Koltunski
      ObjectControl control = view.getObjectControl();
469
      control.setupObject(object,moves);
470 769d7b9f Leszek Koltunski
      }
471
472 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
473
474
    public static int getDrawableSize()
475
      {
476
      if( mScreenHeight<1000 )
477
        {
478
        return 0;
479
        }
480
      if( mScreenHeight<1600 )
481
        {
482
        return 1;
483
        }
484 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
485
        {
486
        return 2;
487
        }
488 f6a9c538 Leszek Koltunski
489 31a9f38d Leszek Koltunski
      return 3;
490 f6a9c538 Leszek Koltunski
      }
491
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493
494 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
495 f6a9c538 Leszek Koltunski
      {
496
      int size = getDrawableSize();
497
498
      switch(size)
499
        {
500
        case 0 : return small;
501
        case 1 : return medium;
502 31a9f38d Leszek Koltunski
        case 2 : return big;
503
        default: return huge;
504 f6a9c538 Leszek Koltunski
        }
505
      }
506
507 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
508
509
    public void acceptPrivacy()
510
      {
511
      mPolicyAccepted = true;
512
      }
513
514
///////////////////////////////////////////////////////////////////////////////////////////////////
515
516
    public void declinePrivacy()
517
      {
518
      finish();
519
      }
520
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522
523
    public static boolean localeIsChinese()
524
      {
525
      String language;
526
527
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
528
        {
529
        language= LocaleList.getDefault().get(0).getLanguage();
530
        }
531
      else
532
        {
533
        language= Locale.getDefault().getLanguage();
534
        }
535
536
      return language.equals("zh");
537
      }
538
539 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
540
541
    public boolean isVertical()
542
      {
543
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
544
      return view.isVertical();
545
      }
546 46405bb4 Leszek Koltunski
547 f5da732a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
548
549 809c3432 Leszek Koltunski
    public void blockEverything(int place)
550 f5da732a Leszek Koltunski
      {
551 55e6be1d Leszek Koltunski
      setLock();
552 f5da732a Leszek Koltunski
553 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
554
      ObjectControl control = view.getObjectControl();
555
      control.blockEverything(place);
556 8badfe2a Leszek Koltunski
557
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
558
      play.setLockState(this);
559 f5da732a Leszek Koltunski
      }
560
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562
563
    public void unblockEverything()
564
      {
565 55e6be1d Leszek Koltunski
      unsetLock();
566 f5da732a Leszek Koltunski
567 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
568
      ObjectControl control = view.getObjectControl();
569
      control.unblockEverything();
570 8badfe2a Leszek Koltunski
571
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
572
      play.setLockState(this);
573 f5da732a Leszek Koltunski
      }
574
575 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
576
577 318c0a7d Leszek Koltunski
    public void switchTutorial(String url, ObjectType object)
578 b6468abb Leszek Koltunski
      {
579
      Intent myIntent = new Intent(this, TutorialActivity.class);
580 2971588c Leszek Koltunski
      myIntent.putExtra("url", url);
581 79bf5d8b Leszek Koltunski
      myIntent.putExtra("obj", object.ordinal());
582 b6468abb Leszek Koltunski
      startActivity(myIntent);
583
      }
584 0c52af30 Leszek Koltunski
}