Project

General

Profile

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

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

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 e019c70b Leszek Koltunski
import androidx.appcompat.app.AppCompatActivity;
39
40 1b3cbd5b Leszek Koltunski
import com.google.firebase.analytics.FirebaseAnalytics;
41
42 3f7a4363 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
43
import org.distorted.library.main.DistortedScreen;
44
45 2afc6754 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
46 3f7a4363 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
47 318c0a7d Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
48 2afc6754 Leszek Koltunski
import org.distorted.objectlib.effects.BaseEffect;
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 e019c70b Leszek Koltunski
public class RubikActivity extends AppCompatActivity
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 0254cfd7 Leszek Koltunski
120
      hideNavigationBar();
121 e8f6670f Leszek Koltunski
      cutoutHack();
122 598de3ee Leszek Koltunski
      computeBarHeights();
123 0254cfd7 Leszek Koltunski
      }
124
125 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
126
// this does not include possible insets
127
128
    private void computeBarHeights()
129
      {
130
      float height = getScreenHeightInPixels();
131
      int barHeight = (int)(height*RATIO_BAR);
132
      mHeightLowerBar = barHeight;
133
      mHeightUpperBar = barHeight;
134 214e301a Leszek Koltunski
135
      LinearLayout layoutTop = findViewById(R.id.upperBar);
136
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
137
138
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
139
      paramsTop.height = mHeightUpperBar;
140
      layoutTop.setLayoutParams(paramsTop);
141
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
142
      paramsBot.height = mHeightLowerBar;
143
      layoutBot.setLayoutParams(paramsBot);
144 598de3ee Leszek Koltunski
      }
145
146 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
147
148
    private void hideNavigationBar()
149
      {
150 c9556e1e Leszek Koltunski
      mCurrentApiVersion = Build.VERSION.SDK_INT;
151 0254cfd7 Leszek Koltunski
152
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
153
        {
154
        final View decorView = getWindow().getDecorView();
155
156 c9556e1e Leszek Koltunski
        decorView.setSystemUiVisibility(FLAGS);
157
158 0254cfd7 Leszek Koltunski
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
159
          {
160
          @Override
161
          public void onSystemUiVisibilityChange(int visibility)
162
            {
163
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
164
              {
165 ffd68f35 Leszek Koltunski
              decorView.setSystemUiVisibility(FLAGS);
166 0254cfd7 Leszek Koltunski
              }
167
            }
168
          });
169
        }
170
      }
171
172 1cb36646 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174
    @Override
175
    public void onAttachedToWindow()
176
      {
177 fd0b901a Leszek Koltunski
      super.onAttachedToWindow();
178
179 e8f6670f Leszek Koltunski
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
180
        {
181
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
182
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
183
184
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
185
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
186 598de3ee Leszek Koltunski
        paramsHid.height = (int)(insetHeight*RATIO_INSET);
187 e8f6670f Leszek Koltunski
        layoutHid.setLayoutParams(paramsHid);
188 598de3ee Leszek Koltunski
        mHeightUpperBar += paramsHid.height;
189 e8f6670f Leszek Koltunski
        }
190 1cb36646 Leszek Koltunski
      }
191
192 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
193 e8f6670f Leszek Koltunski
// do not avoid cutouts
194 c9556e1e Leszek Koltunski
195 e8f6670f Leszek Koltunski
    private void cutoutHack()
196 c9556e1e Leszek Koltunski
      {
197
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
198
        {
199
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
200
        }
201
      }
202
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204 0254cfd7 Leszek Koltunski
205
    @Override
206
    public void onWindowFocusChanged(boolean hasFocus)
207
      {
208
      super.onWindowFocusChanged(hasFocus);
209
210
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
211
        {
212 ffd68f35 Leszek Koltunski
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
213 0254cfd7 Leszek Koltunski
        }
214
      }
215
216 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
217
    
218
    @Override
219
    protected void onPause() 
220
      {
221 82f42eeb Leszek Koltunski
      super.onPause();
222 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
223 0c52af30 Leszek Koltunski
      view.onPause();
224 d7de3072 Leszek Koltunski
      DistortedLibrary.onPause(0);
225 6a083c6a Leszek Koltunski
      RubikNetwork.onPause();
226 33499c56 Leszek Koltunski
      savePreferences();
227 0c52af30 Leszek Koltunski
      }
228
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
    
231
    @Override
232
    protected void onResume() 
233
      {
234
      super.onResume();
235 d7de3072 Leszek Koltunski
      DistortedLibrary.onResume(0);
236 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
237 0c52af30 Leszek Koltunski
      view.onResume();
238 33499c56 Leszek Koltunski
      restorePreferences();
239 f5da732a Leszek Koltunski
      ScreenList.setScreen(this);
240 8badfe2a Leszek Koltunski
      unblockEverything();
241 4888e97c Leszek Koltunski
242 c3ffcf58 Leszek Koltunski
      if( mJustStarted )
243
        {
244
        mJustStarted = false;
245 82ce8e64 Leszek Koltunski
        RubikScores scores = RubikScores.getInstance();
246
        scores.incrementNumRuns();
247
        scores.setCountry(this);
248 c3ffcf58 Leszek Koltunski
        }
249
250 f5da732a Leszek Koltunski
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
251 8ab435b9 Leszek Koltunski
      ObjectType object = play.getObject();
252 2afc6754 Leszek Koltunski
      view.getObjectControl().changeObject(object);
253 8ab435b9 Leszek Koltunski
      
254 b1e9596b Leszek Koltunski
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
255 0c52af30 Leszek Koltunski
      }
256
    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258
    
259
    @Override
260
    protected void onDestroy() 
261
      {
262 d7de3072 Leszek Koltunski
      DistortedLibrary.onDestroy(0);
263 0c52af30 Leszek Koltunski
      super.onDestroy();
264
      }
265
266 33499c56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
267
268
    private void savePreferences()
269
      {
270
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
271
      SharedPreferences.Editor editor = preferences.edit();
272
273 b1e9596b Leszek Koltunski
      editor.putBoolean("policyAccepted", mPolicyAccepted);
274
275 211b48f2 Leszek Koltunski
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
276 33499c56 Leszek Koltunski
        {
277
        BaseEffect.Type.getType(i).savePreferences(editor);
278
        }
279
280 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
281 211b48f2 Leszek Koltunski
        {
282 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
283 211b48f2 Leszek Koltunski
        }
284 33499c56 Leszek Koltunski
285 fcd5b990 Leszek Koltunski
      ScreenList.savePreferences(editor);
286 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
287 2afc6754 Leszek Koltunski
      view.getObjectControl().savePreferences(editor);
288 0333d81e Leszek Koltunski
289 33499c56 Leszek Koltunski
      editor.apply();
290
      }
291
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293
294
    private void restorePreferences()
295
      {
296
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
297
298 b1e9596b Leszek Koltunski
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
299
300 33499c56 Leszek Koltunski
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
301 4235de9b Leszek Koltunski
        {
302 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
303 4235de9b Leszek Koltunski
        }
304 33499c56 Leszek Koltunski
305 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
306 211b48f2 Leszek Koltunski
        {
307 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
308 211b48f2 Leszek Koltunski
        }
309 33499c56 Leszek Koltunski
310 fcd5b990 Leszek Koltunski
      ScreenList.restorePreferences(preferences);
311 0333d81e Leszek Koltunski
312
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
313 2afc6754 Leszek Koltunski
      view.getObjectControl().restorePreferences(preferences);
314 ee4e7896 Leszek Koltunski
315
      RubikScores scores = RubikScores.getInstance();
316
317
      if( scores.isVerified() )
318
        {
319
        FirebaseAnalytics analytics = getAnalytics();
320
        analytics.setUserId(scores.getName());
321
        }
322 f3e12931 Leszek Koltunski
      }
323
324 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
325
326
    private void PrivacyPolicy()
327
      {
328
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
329
      priDiag.show(getSupportFragmentManager(), null);
330
      }
331
332 2d9fc972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
333
334 e7e0a94d Leszek Koltunski
    void OpenGLError()
335 2d9fc972 Leszek Koltunski
      {
336
      RubikDialogError errDiag = new RubikDialogError();
337
      errDiag.show(getSupportFragmentManager(), null);
338
      }
339
340 2da68298 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
341
342
    void setScreenSize(int width, int height)
343
      {
344
      mScreenWidth = width;
345
      mScreenHeight= height;
346
      }
347
348 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
349 47ba5ddc Leszek Koltunski
// PUBLIC API
350 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
351
352
    public FirebaseAnalytics getAnalytics()
353
      {
354
      return mFirebaseAnalytics;
355
      }
356
357 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
358
359
    public int getHeightUpperBar()
360
      {
361
      return mHeightUpperBar;
362
      }
363
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365
366
    public int getHeightLowerBar()
367
      {
368
      return mHeightLowerBar;
369
      }
370
371 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
372
373 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
374 aa171dee Leszek Koltunski
      {
375
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
376 2afc6754 Leszek Koltunski
      return view.getObjectControl().getObject();
377 8becce57 Leszek Koltunski
      }
378
379 f8eece7d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
380
381 2afc6754 Leszek Koltunski
    public ObjectControl getControl()
382 f8eece7d Leszek Koltunski
      {
383
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
384 2afc6754 Leszek Koltunski
      return view.getObjectControl();
385 f8eece7d Leszek Koltunski
      }
386
387 e3c74c0f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
388
389 2afc6754 Leszek Koltunski
    public DistortedScreen getScreen()
390 55e6be1d Leszek Koltunski
      {
391
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
392 2afc6754 Leszek Koltunski
      RubikRenderer renderer = view.getRenderer();
393
      return renderer.getScreen();
394 88fb92ba Leszek Koltunski
      }
395
396 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
397
398 8ba7aeb1 Leszek Koltunski
    public int getScreenWidthInPixels()
399 8becce57 Leszek Koltunski
      {
400 8ba7aeb1 Leszek Koltunski
      return mScreenWidth;
401
      }
402
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404
405
    public int getScreenHeightInPixels()
406
      {
407
      return mScreenHeight;
408 aa171dee Leszek Koltunski
      }
409
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411
412 318c0a7d Leszek Koltunski
    public void changeObject(ObjectType newObject, boolean reportChange)
413 769d7b9f Leszek Koltunski
      {
414
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
415 2afc6754 Leszek Koltunski
      ObjectControl control = view.getObjectControl();
416 7eae2d49 Leszek Koltunski
417
      if( reportChange )
418
        {
419 2afc6754 Leszek Koltunski
        TwistyObject oldObject = control.getObject();
420 7eae2d49 Leszek Koltunski
421 03822c33 Leszek Koltunski
        if( oldObject!=null )
422
          {
423 e4f656d1 Leszek Koltunski
          ObjectType oldType = oldObject.getObjectType();
424 03822c33 Leszek Koltunski
          float fps = view.getRenderer().getFPS();
425
          fps = (int)(fps+0.5f);
426
          StringBuilder name = new StringBuilder();
427 e4f656d1 Leszek Koltunski
          name.append(oldType.name());
428 03822c33 Leszek Koltunski
          name.append(' ');
429
          name.append(fps);
430
          name.append(" --> ");
431
          name.append(newObject.name());
432
433
          if( BuildConfig.DEBUG )
434 7eae2d49 Leszek Koltunski
            {
435 03822c33 Leszek Koltunski
            android.util.Log.e("rubik", name.toString());
436
            }
437
          else
438
            {
439
            FirebaseAnalytics analytics = getAnalytics();
440
441
            if( analytics!=null )
442
              {
443
              Bundle bundle = new Bundle();
444
              bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
445
              analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
446
              }
447 7eae2d49 Leszek Koltunski
            }
448
          }
449
        }
450
451 2afc6754 Leszek Koltunski
      control.changeObject(newObject);
452 2e8ec627 Leszek Koltunski
      }
453
454 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
455
456
    public static int getDrawableSize()
457
      {
458
      if( mScreenHeight<1000 )
459
        {
460
        return 0;
461
        }
462
      if( mScreenHeight<1600 )
463
        {
464
        return 1;
465
        }
466 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
467
        {
468
        return 2;
469
        }
470 f6a9c538 Leszek Koltunski
471 31a9f38d Leszek Koltunski
      return 3;
472 f6a9c538 Leszek Koltunski
      }
473
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475
476 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
477 f6a9c538 Leszek Koltunski
      {
478
      int size = getDrawableSize();
479
480
      switch(size)
481
        {
482
        case 0 : return small;
483
        case 1 : return medium;
484 31a9f38d Leszek Koltunski
        case 2 : return big;
485
        default: return huge;
486 f6a9c538 Leszek Koltunski
        }
487
      }
488
489 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
490
491
    public void acceptPrivacy()
492
      {
493
      mPolicyAccepted = true;
494
      }
495
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497
498
    public void declinePrivacy()
499
      {
500
      finish();
501
      }
502
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504
505
    public static boolean localeIsChinese()
506
      {
507
      String language;
508
509
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
510
        {
511
        language= LocaleList.getDefault().get(0).getLanguage();
512
        }
513
      else
514
        {
515
        language= Locale.getDefault().getLanguage();
516
        }
517
518
      return language.equals("zh");
519
      }
520
521 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
522
523
    public boolean isVertical()
524
      {
525
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
526
      return view.isVertical();
527
      }
528 46405bb4 Leszek Koltunski
529 f5da732a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
530
531 809c3432 Leszek Koltunski
    public void blockEverything(int place)
532 f5da732a Leszek Koltunski
      {
533 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
534
      ObjectControl control = view.getObjectControl();
535
      control.blockEverything(place);
536 8badfe2a Leszek Koltunski
537
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
538
      play.setLockState(this);
539 f5da732a Leszek Koltunski
      }
540
541
///////////////////////////////////////////////////////////////////////////////////////////////////
542
543
    public void unblockEverything()
544
      {
545 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
546
      ObjectControl control = view.getObjectControl();
547
      control.unblockEverything();
548 8badfe2a Leszek Koltunski
549
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
550
      play.setLockState(this);
551 f5da732a Leszek Koltunski
      }
552
553 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
554
555 318c0a7d Leszek Koltunski
    public void switchTutorial(String url, ObjectType object)
556 b6468abb Leszek Koltunski
      {
557
      Intent myIntent = new Intent(this, TutorialActivity.class);
558 2971588c Leszek Koltunski
      myIntent.putExtra("url", url);
559 79bf5d8b Leszek Koltunski
      myIntent.putExtra("obj", object.ordinal());
560 b6468abb Leszek Koltunski
      startActivity(myIntent);
561
      }
562 0c52af30 Leszek Koltunski
}