Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ dd874ae8

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