Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 8badfe2a

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