Project

General

Profile

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

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

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 b6468abb Leszek Koltunski
import org.distorted.tutorial.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 f3e12931 Leszek Koltunski
      }
343
344 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
345
346
    private void PrivacyPolicy()
347
      {
348
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
349
      priDiag.show(getSupportFragmentManager(), null);
350
      }
351
352 2d9fc972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
353
354 e7e0a94d Leszek Koltunski
    void OpenGLError()
355 2d9fc972 Leszek Koltunski
      {
356
      RubikDialogError errDiag = new RubikDialogError();
357
      errDiag.show(getSupportFragmentManager(), null);
358
      }
359
360 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
361 47ba5ddc Leszek Koltunski
// PUBLIC API
362 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
363
364
    public FirebaseAnalytics getAnalytics()
365
      {
366
      return mFirebaseAnalytics;
367
      }
368
369 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
370
371 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
372 aa171dee Leszek Koltunski
      {
373
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
374 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
375
      return pre.getObject();
376 8becce57 Leszek Koltunski
      }
377
378 e3c74c0f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
379
380 88fb92ba Leszek Koltunski
    public int getScreenWidthInPixels()
381 e3c74c0f Leszek Koltunski
      {
382
      return mScreenWidth;
383
      }
384
385 88fb92ba Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
386
387
    public int getScreenHeightInPixels()
388
      {
389
      return mScreenHeight;
390
      }
391
392 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
393
394 5a4d4fba Leszek Koltunski
    public RubikPreRender getPreRender()
395 8becce57 Leszek Koltunski
      {
396
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
397 5a4d4fba Leszek Koltunski
      return view.getPreRender();
398 aa171dee Leszek Koltunski
      }
399
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401
402 9c2f0c91 Leszek Koltunski
    public void changeObject(ObjectList newObject, int newSize, boolean reportChange)
403 769d7b9f Leszek Koltunski
      {
404
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
405 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
406 7eae2d49 Leszek Koltunski
407
      if( reportChange )
408
        {
409 9c2f0c91 Leszek Koltunski
        TwistyObject oldObject = pre.getObject();
410
        ObjectList oldList = oldObject.getObjectList();
411 d99f3a48 Leszek Koltunski
        int oldNum = oldObject.getNumLayers();
412 7eae2d49 Leszek Koltunski
        float fps = view.getRenderer().getFPS();
413 e35247b8 Leszek Koltunski
        fps = (int)(fps+0.5f);
414 7eae2d49 Leszek Koltunski
        StringBuilder name = new StringBuilder();
415
        name.append(oldList.name());
416
        name.append('_');
417 d99f3a48 Leszek Koltunski
        name.append(oldNum);
418 7eae2d49 Leszek Koltunski
        name.append(' ');
419
        name.append(fps);
420
        name.append(" --> ");
421
        name.append(newObject.name());
422
        name.append('_');
423
        name.append(newSize);
424
425
        if( BuildConfig.DEBUG )
426
          {
427
          android.util.Log.e("rubik", name.toString());
428
          }
429
        else
430
          {
431
          FirebaseAnalytics analytics = getAnalytics();
432
433
          if( analytics!=null )
434
            {
435
            Bundle bundle = new Bundle();
436
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
437
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
438
            }
439
          }
440
        }
441
442
      pre.changeObject(newObject,newSize);
443 2e8ec627 Leszek Koltunski
      }
444
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446
447 9c2f0c91 Leszek Koltunski
    public void setupObject(ObjectList object, int size, int[][] moves)
448 2e8ec627 Leszek Koltunski
      {
449
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
450 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
451
      pre.setupObject(object,size,moves);
452 769d7b9f Leszek Koltunski
      }
453
454 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
455
456
    public static int getDrawableSize()
457
      {
458
      if( mScreenHeight<1000 )
459
        {
460
        return 0;
461
        }
462
      if( mScreenHeight<1600 )
463
        {
464
        return 1;
465
        }
466 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
467
        {
468
        return 2;
469
        }
470 f6a9c538 Leszek Koltunski
471 31a9f38d Leszek Koltunski
      return 3;
472 f6a9c538 Leszek Koltunski
      }
473
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475
476 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
477 f6a9c538 Leszek Koltunski
      {
478
      int size = getDrawableSize();
479
480
      switch(size)
481
        {
482
        case 0 : return small;
483
        case 1 : return medium;
484 31a9f38d Leszek Koltunski
        case 2 : return big;
485
        default: return huge;
486 f6a9c538 Leszek Koltunski
        }
487
      }
488
489 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
490
491
    public void acceptPrivacy()
492
      {
493
      mPolicyAccepted = true;
494
      }
495
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497
498
    public void declinePrivacy()
499
      {
500
      finish();
501
      }
502
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504
505
    public static boolean localeIsChinese()
506
      {
507
      String language;
508
509
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
510
        {
511
        language= LocaleList.getDefault().get(0).getLanguage();
512
        }
513
      else
514
        {
515
        language= Locale.getDefault().getLanguage();
516
        }
517
518
      return language.equals("zh");
519
      }
520
521 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
522
523
    public boolean isVertical()
524
      {
525
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
526
      return view.isVertical();
527
      }
528 46405bb4 Leszek Koltunski
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530
531
    public void toggleLock()
532
      {
533
      mIsLocked = !mIsLocked;
534
      }
535
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537
538
    public boolean isLocked()
539
      {
540 be576d14 Leszek Koltunski
      StateList state = StateList.getCurrentState();
541 46405bb4 Leszek Koltunski
542 be576d14 Leszek Koltunski
      if( state== StateList.PLAY || state== StateList.READ || state== StateList.SOLV )
543 46405bb4 Leszek Koltunski
        {
544
        return mIsLocked;
545
        }
546
547
      return false;
548
      }
549
550
///////////////////////////////////////////////////////////////////////////////////////////////////
551
552
    public boolean retLocked()
553
      {
554
      return mIsLocked;
555
      }
556 b6468abb Leszek Koltunski
557
///////////////////////////////////////////////////////////////////////////////////////////////////
558
559 79bf5d8b Leszek Koltunski
    public void switchTutorial(String url, ObjectList object, int size)
560 b6468abb Leszek Koltunski
      {
561
      Intent myIntent = new Intent(this, TutorialActivity.class);
562 2971588c Leszek Koltunski
      myIntent.putExtra("url", url);
563 79bf5d8b Leszek Koltunski
      myIntent.putExtra("obj", object.ordinal());
564
      myIntent.putExtra("siz", size);
565 b6468abb Leszek Koltunski
      startActivity(myIntent);
566
      }
567 0c52af30 Leszek Koltunski
}