Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 4c9947bd

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