Project

General

Profile

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

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

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