Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 214e301a

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