Project

General

Profile

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

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

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