Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 7aa4c349

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