Project

General

Profile

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

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

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 b20e89d2 Leszek Koltunski
import java.io.InputStream;
23 2afc6754 Leszek Koltunski
import java.util.Locale;
24
25 b6468abb Leszek Koltunski
import android.content.Intent;
26 33499c56 Leszek Koltunski
import android.content.SharedPreferences;
27 4c9947bd Leszek Koltunski
import android.content.pm.PackageInfo;
28
import android.content.pm.PackageManager;
29 b1e9596b Leszek Koltunski
import android.os.Build;
30 0c52af30 Leszek Koltunski
import android.os.Bundle;
31 b1e9596b Leszek Koltunski
import android.os.LocaleList;
32 33499c56 Leszek Koltunski
import android.preference.PreferenceManager;
33 e3c74c0f Leszek Koltunski
34
import android.util.DisplayMetrics;
35 fd0b901a Leszek Koltunski
import android.view.DisplayCutout;
36 0254cfd7 Leszek Koltunski
import android.view.View;
37 1cb36646 Leszek Koltunski
import android.view.ViewGroup;
38 c9556e1e Leszek Koltunski
import android.view.WindowManager;
39 1cb36646 Leszek Koltunski
import android.widget.LinearLayout;
40 0c52af30 Leszek Koltunski
41 e019c70b Leszek Koltunski
import androidx.appcompat.app.AppCompatActivity;
42
43 1b3cbd5b Leszek Koltunski
import com.google.firebase.analytics.FirebaseAnalytics;
44
45 1237d25d Leszek Koltunski
import org.distorted.config.ConfigActivity;
46 9530f6b0 Leszek Koltunski
import org.distorted.bandaged.BandagedCreatorActivity;
47 3f7a4363 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
48
49 2afc6754 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
50 3f7a4363 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
51 2afc6754 Leszek Koltunski
import org.distorted.objectlib.effects.BaseEffect;
52 3f7a4363 Leszek Koltunski
53 2d9fc972 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
54 b1e9596b Leszek Koltunski
import org.distorted.dialogs.RubikDialogPrivacy;
55 acabdd83 Leszek Koltunski
import org.distorted.external.RubikScores;
56
import org.distorted.external.RubikNetwork;
57 d433b50e Leszek Koltunski
import org.distorted.objects.RubikObject;
58
import org.distorted.objects.RubikObjectList;
59 d175b83d Leszek Koltunski
import org.distorted.screens.RubikScreenFreePlay;
60 2e3488f6 Leszek Koltunski
import org.distorted.screens.RubikScreenSolving;
61 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
62
import org.distorted.screens.RubikScreenPlay;
63 eaf87d1d Leszek Koltunski
import org.distorted.tutorials.TutorialActivity;
64 211b48f2 Leszek Koltunski
65 09cf2a36 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
66
67 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69 e019c70b Leszek Koltunski
public class RubikActivity extends AppCompatActivity
70 0c52af30 Leszek Koltunski
{
71 a474ccde Leszek Koltunski
    public static final boolean SHOW_DOWNLOADED_DEBUG = false;
72 e847c553 Leszek Koltunski
73 054fbee1 Leszek Koltunski
    public static final float PADDING             = 0.01f;
74 c651024f Leszek Koltunski
    public static final float SMALL_MARGIN        = 0.004f;
75
    public static final float MEDIUM_MARGIN       = 0.015f;
76 054fbee1 Leszek Koltunski
    public static final float LARGE_MARGIN        = 0.025f;
77
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
78
    public static final float TITLE_TEXT_SIZE     = 0.06f;
79 7ea57482 Leszek Koltunski
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
80
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
81 045857e5 Leszek Koltunski
    public static final float MENU_ITEM_SIZE      = 0.11f;
82 5de2c572 Leszek Koltunski
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
83
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
84 362807f0 Leszek Koltunski
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
85
    public static final float SCORES_ITEM_TEXT    = 0.030f;
86 ef1f3e34 Leszek Koltunski
    public static final float TUTORIAL_ITEM_TEXT  = 0.100f;
87 eb376d3a Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
88
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
89
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
90
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
91 6e3fcb91 Leszek Koltunski
    public static final float TAB_WIDTH           = 0.100f;
92
    public static final float TAB_HEIGHT          = 0.100f;
93 e3c74c0f Leszek Koltunski
94 af7b68e6 Leszek Koltunski
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
95 ffd68f35 Leszek Koltunski
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
96
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
97
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
98
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
99
100 1237d25d Leszek Koltunski
    private static final int ACTIVITY_NUMBER = 0;
101 598de3ee Leszek Koltunski
    private static final float RATIO_BAR  = 0.10f;
102 1071fb69 Leszek Koltunski
    private static final float RATIO_INSET= 0.09f;
103 598de3ee Leszek Koltunski
104 972f9eae Leszek Koltunski
    private static final String KEY_PLAY = "movesController_play";
105
    private static final String KEY_SOLV = "movesController_solv";
106 d175b83d Leszek Koltunski
    public  static final String KEY_FREE = "movesController_free";
107 972f9eae Leszek Koltunski
108 c3ffcf58 Leszek Koltunski
    private boolean mJustStarted;
109 1b3cbd5b Leszek Koltunski
    private FirebaseAnalytics mFirebaseAnalytics;
110 f6a9c538 Leszek Koltunski
    private static int mScreenWidth, mScreenHeight;
111 b1e9596b Leszek Koltunski
    private boolean mPolicyAccepted, mIsChinese;
112 0254cfd7 Leszek Koltunski
    private int mCurrentApiVersion;
113 598de3ee Leszek Koltunski
    private int mHeightUpperBar, mHeightLowerBar;
114 c3ffcf58 Leszek Koltunski
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
117 0c52af30 Leszek Koltunski
    @Override
118 34747dd1 Leszek Koltunski
    protected void onCreate(Bundle savedState)
119 0c52af30 Leszek Koltunski
      {
120 34747dd1 Leszek Koltunski
      super.onCreate(savedState);
121 1237d25d Leszek Koltunski
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
122 d7de3072 Leszek Koltunski
123 dd874ae8 Leszek Koltunski
      setTheme(R.style.MaterialThemeNoActionBar);
124 1cbcc6bf Leszek Koltunski
      setContentView(R.layout.main);
125 c3ffcf58 Leszek Koltunski
126
      mJustStarted = true;
127 1b3cbd5b Leszek Koltunski
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
128 51853bf2 Leszek Koltunski
      mIsChinese = localeIsChinese();
129 e3c74c0f Leszek Koltunski
130
      DisplayMetrics displaymetrics = new DisplayMetrics();
131 7fe59aa5 Leszek Koltunski
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
132 88fb92ba Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
133
      mScreenHeight=displaymetrics.heightPixels;
134 7fe59aa5 Leszek Koltunski
135 0254cfd7 Leszek Koltunski
      hideNavigationBar();
136 e8f6670f Leszek Koltunski
      cutoutHack();
137 598de3ee Leszek Koltunski
      computeBarHeights();
138 0254cfd7 Leszek Koltunski
      }
139
140 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
141
// this does not include possible insets
142
143
    private void computeBarHeights()
144
      {
145 7fe59aa5 Leszek Koltunski
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
146 598de3ee Leszek Koltunski
      mHeightLowerBar = barHeight;
147
      mHeightUpperBar = barHeight;
148 214e301a Leszek Koltunski
149
      LinearLayout layoutTop = findViewById(R.id.upperBar);
150
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
151
152
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
153
      paramsTop.height = mHeightUpperBar;
154
      layoutTop.setLayoutParams(paramsTop);
155
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
156
      paramsBot.height = mHeightLowerBar;
157
      layoutBot.setLayoutParams(paramsBot);
158 598de3ee Leszek Koltunski
      }
159
160 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162
    private void hideNavigationBar()
163
      {
164 c9556e1e Leszek Koltunski
      mCurrentApiVersion = Build.VERSION.SDK_INT;
165 0254cfd7 Leszek Koltunski
166
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
167
        {
168
        final View decorView = getWindow().getDecorView();
169
170 c9556e1e Leszek Koltunski
        decorView.setSystemUiVisibility(FLAGS);
171
172 0254cfd7 Leszek Koltunski
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
173
          {
174
          @Override
175
          public void onSystemUiVisibilityChange(int visibility)
176
            {
177
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
178
              {
179 ffd68f35 Leszek Koltunski
              decorView.setSystemUiVisibility(FLAGS);
180 0254cfd7 Leszek Koltunski
              }
181
            }
182
          });
183
        }
184
      }
185
186 1cb36646 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
187
188
    @Override
189
    public void onAttachedToWindow()
190
      {
191 fd0b901a Leszek Koltunski
      super.onAttachedToWindow();
192
193 e8f6670f Leszek Koltunski
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
194
        {
195
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
196
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
197
198
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
199
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
200 598de3ee Leszek Koltunski
        paramsHid.height = (int)(insetHeight*RATIO_INSET);
201 e8f6670f Leszek Koltunski
        layoutHid.setLayoutParams(paramsHid);
202 598de3ee Leszek Koltunski
        mHeightUpperBar += paramsHid.height;
203 e8f6670f Leszek Koltunski
        }
204 1cb36646 Leszek Koltunski
      }
205
206 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
207 e8f6670f Leszek Koltunski
// do not avoid cutouts
208 c9556e1e Leszek Koltunski
209 e8f6670f Leszek Koltunski
    private void cutoutHack()
210 c9556e1e Leszek Koltunski
      {
211
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
212
        {
213
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
214
        }
215
      }
216
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218 0254cfd7 Leszek Koltunski
219
    @Override
220
    public void onWindowFocusChanged(boolean hasFocus)
221
      {
222
      super.onWindowFocusChanged(hasFocus);
223
224
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
225
        {
226 ffd68f35 Leszek Koltunski
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
227 0254cfd7 Leszek Koltunski
        }
228
      }
229
230 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
231
    
232
    @Override
233
    protected void onPause() 
234
      {
235 82f42eeb Leszek Koltunski
      super.onPause();
236 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
237 0c52af30 Leszek Koltunski
      view.onPause();
238 1237d25d Leszek Koltunski
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
239 6a083c6a Leszek Koltunski
      RubikNetwork.onPause();
240 33499c56 Leszek Koltunski
      savePreferences();
241 0c52af30 Leszek Koltunski
      }
242
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
    
245
    @Override
246
    protected void onResume() 
247
      {
248
      super.onResume();
249 1237d25d Leszek Koltunski
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
250 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
251 0c52af30 Leszek Koltunski
      view.onResume();
252 33499c56 Leszek Koltunski
      restorePreferences();
253 51853bf2 Leszek Koltunski
254 f5da732a Leszek Koltunski
      ScreenList.setScreen(this);
255 8badfe2a Leszek Koltunski
      unblockEverything();
256 4888e97c Leszek Koltunski
257 2e3488f6 Leszek Koltunski
      restoreMoves();
258
259 c3ffcf58 Leszek Koltunski
      if( mJustStarted )
260
        {
261
        mJustStarted = false;
262 82ce8e64 Leszek Koltunski
        RubikScores scores = RubikScores.getInstance();
263
        scores.incrementNumRuns();
264
        scores.setCountry(this);
265 f12e4de9 Leszek Koltunski
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
266
        RubikObjectList.restoreMeshState(preferences);
267 c3ffcf58 Leszek Koltunski
        }
268
269 400ff34d Leszek Koltunski
      int object = RubikObjectList.getCurrObject();
270 b20e89d2 Leszek Koltunski
      changeIfDifferent(object,view.getObjectControl());
271 51853bf2 Leszek Koltunski
272 b1e9596b Leszek Koltunski
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
273 0c52af30 Leszek Koltunski
      }
274
    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276
    
277
    @Override
278
    protected void onDestroy() 
279
      {
280 1237d25d Leszek Koltunski
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
281 0c52af30 Leszek Koltunski
      super.onDestroy();
282
      }
283
284 4c9947bd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
285
286 b20e89d2 Leszek Koltunski
    private String getAppVers()
287 4c9947bd Leszek Koltunski
      {
288 b20e89d2 Leszek Koltunski
      try
289
        {
290
        PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
291
        return pInfo.versionName;
292
        }
293
      catch (PackageManager.NameNotFoundException e)
294
        {
295
        return "unknown";
296
        }
297 4c9947bd Leszek Koltunski
      }
298
299 33499c56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
300
301
    private void savePreferences()
302
      {
303
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
304
      SharedPreferences.Editor editor = preferences.edit();
305
306 b1e9596b Leszek Koltunski
      editor.putBoolean("policyAccepted", mPolicyAccepted);
307 4c9947bd Leszek Koltunski
      editor.putString("appVersion", getAppVers() );
308 b1e9596b Leszek Koltunski
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 400ff34d Leszek Koltunski
      RubikObjectList.savePreferences(editor);
320 f12e4de9 Leszek Koltunski
      RubikObjectList.saveMeshState(editor);
321 fcd5b990 Leszek Koltunski
      ScreenList.savePreferences(editor);
322 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
323 2afc6754 Leszek Koltunski
      view.getObjectControl().savePreferences(editor);
324 0333d81e Leszek Koltunski
325 2e3488f6 Leszek Koltunski
      ScreenList curr = ScreenList.getCurrentScreen();
326
327
      if( curr==ScreenList.PLAY )
328
        {
329
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
330 972f9eae Leszek Koltunski
        play.saveMovePreferences(KEY_PLAY,editor);
331 2e3488f6 Leszek Koltunski
        }
332
      if( curr==ScreenList.SOLV )
333
        {
334
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
335 972f9eae Leszek Koltunski
        solv.saveMovePreferences(KEY_SOLV,editor);
336 2e3488f6 Leszek Koltunski
        }
337 d175b83d Leszek Koltunski
      if( curr==ScreenList.FREE )
338
        {
339
        RubikScreenFreePlay free = (RubikScreenFreePlay)ScreenList.FREE.getScreenClass();
340
        free.saveMovePreferences(KEY_FREE,editor);
341
        }
342 2e3488f6 Leszek Koltunski
343 33499c56 Leszek Koltunski
      editor.apply();
344
      }
345
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347
348
    private void restorePreferences()
349
      {
350
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
351
352 b1e9596b Leszek Koltunski
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
353 4c9947bd Leszek Koltunski
      String oldVersion = preferences.getString("appVersion","");
354 b1e9596b Leszek Koltunski
355 81493402 Leszek Koltunski
      RubikObjectList.restorePreferences(this,preferences);
356 526a5906 Leszek Koltunski
357 03423c67 Leszek Koltunski
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
358 4235de9b Leszek Koltunski
        {
359 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
360 4235de9b Leszek Koltunski
        }
361 33499c56 Leszek Koltunski
362 03423c67 Leszek Koltunski
      for (int i=0; i<ScreenList.LENGTH; i++)
363 211b48f2 Leszek Koltunski
        {
364 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
365 211b48f2 Leszek Koltunski
        }
366 33499c56 Leszek Koltunski
367 fcd5b990 Leszek Koltunski
      ScreenList.restorePreferences(preferences);
368 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
369 4c9947bd Leszek Koltunski
370
      // Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their
371
      // case the 'mOldVersion' - version of the app which saved the preferences on the last
372
      // go - is empty.
373
      // Between versions 1.8.6 and 1.9.0, the order of the cubits in TwistyCube has changed.
374
      // If someone has scrambled the cube with v. 1.8.6, then upgraded to 1.9.0 and re-started
375
      // the app, because of the different order of the cubits - his cube would be messed up.
376
      // So in such case, i.e. on fresh upgrade from version<=1.8.6 to version>=1.9.0, do not
377
      // restore the object scrambling.
378
379
      if( !oldVersion.equals("") )
380
        {
381
        view.getObjectControl().restorePreferences(preferences);
382
        }
383 ee4e7896 Leszek Koltunski
384
      RubikScores scores = RubikScores.getInstance();
385
386
      if( scores.isVerified() )
387
        {
388
        FirebaseAnalytics analytics = getAnalytics();
389
        analytics.setUserId(scores.getName());
390
        }
391 f3e12931 Leszek Koltunski
      }
392
393 2e3488f6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
394
395
    private void restoreMoves()
396
      {
397
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
398
      ScreenList curr = ScreenList.getCurrentScreen();
399
400
      if( curr==ScreenList.PLAY )
401
        {
402
        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
403 972f9eae Leszek Koltunski
        play.restoreMovePreferences(this,KEY_PLAY,preferences);
404 2e3488f6 Leszek Koltunski
        }
405
      if( curr==ScreenList.SOLV )
406
        {
407
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
408 972f9eae Leszek Koltunski
        solv.restoreMovePreferences(this,KEY_SOLV,preferences);
409 2e3488f6 Leszek Koltunski
        }
410 d175b83d Leszek Koltunski
      if( curr==ScreenList.FREE )
411
        {
412
        RubikScreenFreePlay free = (RubikScreenFreePlay)ScreenList.FREE.getScreenClass();
413
        free.restoreMovePreferences(this,KEY_FREE,preferences);
414
        }
415 2e3488f6 Leszek Koltunski
      }
416
417 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
418
419
    private void PrivacyPolicy()
420
      {
421
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
422
      priDiag.show(getSupportFragmentManager(), null);
423
      }
424
425 2d9fc972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
426
427 e7e0a94d Leszek Koltunski
    void OpenGLError()
428 2d9fc972 Leszek Koltunski
      {
429
      RubikDialogError errDiag = new RubikDialogError();
430
      errDiag.show(getSupportFragmentManager(), null);
431
      }
432
433 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
434 47ba5ddc Leszek Koltunski
// PUBLIC API
435 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
436
437
    public FirebaseAnalytics getAnalytics()
438
      {
439
      return mFirebaseAnalytics;
440
      }
441
442 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
443
444
    public int getHeightUpperBar()
445
      {
446
      return mHeightUpperBar;
447
      }
448
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
451
    public int getHeightLowerBar()
452
      {
453
      return mHeightLowerBar;
454
      }
455
456 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
457
458 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
459 aa171dee Leszek Koltunski
      {
460
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
461 2afc6754 Leszek Koltunski
      return view.getObjectControl().getObject();
462 8becce57 Leszek Koltunski
      }
463
464 f8eece7d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
465
466 2afc6754 Leszek Koltunski
    public ObjectControl getControl()
467 f8eece7d Leszek Koltunski
      {
468
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
469 2afc6754 Leszek Koltunski
      return view.getObjectControl();
470 f8eece7d Leszek Koltunski
      }
471
472 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
473
474 8ba7aeb1 Leszek Koltunski
    public int getScreenWidthInPixels()
475 8becce57 Leszek Koltunski
      {
476 8ba7aeb1 Leszek Koltunski
      return mScreenWidth;
477
      }
478
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480
481
    public int getScreenHeightInPixels()
482
      {
483
      return mScreenHeight;
484 aa171dee Leszek Koltunski
      }
485
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487
488 d433b50e Leszek Koltunski
    public void changeObject(int newObject, boolean reportChange)
489 769d7b9f Leszek Koltunski
      {
490
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
491 2afc6754 Leszek Koltunski
      ObjectControl control = view.getObjectControl();
492 b20e89d2 Leszek Koltunski
      TwistyObject oldObject = control.getObject();
493
      changeIfDifferent(newObject,control);
494 7eae2d49 Leszek Koltunski
495 b20e89d2 Leszek Koltunski
      if( reportChange && oldObject!=null )
496 7eae2d49 Leszek Koltunski
        {
497 d433b50e Leszek Koltunski
        RubikObject robject = RubikObjectList.getObject(newObject);
498 84d746d7 Leszek Koltunski
        String newName = robject==null ? "NULL" : robject.getUpperName();
499 b20e89d2 Leszek Koltunski
        float fps = view.getRenderer().getFPS();
500
        fps = (int)(fps+0.5f);
501
        StringBuilder name = new StringBuilder();
502
        name.append(oldObject.getShortName());
503
        name.append(' ');
504
        name.append(fps);
505
        name.append(" --> ");
506 d433b50e Leszek Koltunski
        name.append(newName);
507 b20e89d2 Leszek Koltunski
508
        if( BuildConfig.DEBUG )
509 03822c33 Leszek Koltunski
          {
510 b20e89d2 Leszek Koltunski
          android.util.Log.e("rubik", name.toString());
511
          }
512
        else
513
          {
514
          FirebaseAnalytics analytics = getAnalytics();
515 03822c33 Leszek Koltunski
516 b20e89d2 Leszek Koltunski
          if( analytics!=null )
517
            {
518
            Bundle bundle = new Bundle();
519
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
520
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
521 7eae2d49 Leszek Koltunski
            }
522
          }
523
        }
524 b20e89d2 Leszek Koltunski
      }
525
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527 7eae2d49 Leszek Koltunski
528 d433b50e Leszek Koltunski
    public void changeIfDifferent(int ordinal, ObjectControl control)
529 b20e89d2 Leszek Koltunski
      {
530 09cf2a36 Leszek Koltunski
      RubikObject object = RubikObjectList.getObject(ordinal);
531
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
532 7cb8d4b0 Leszek Koltunski
      int iconMode  = TwistyObject.MODE_NORM;
533 314e9ff0 Leszek Koltunski
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
534
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
535 aec421fd Leszek Koltunski
      String name = object==null ? "NULL" : object.getUpperName();
536 09cf2a36 Leszek Koltunski
537 7cb8d4b0 Leszek Koltunski
      control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
538 2e8ec627 Leszek Koltunski
      }
539
540 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
541
542
    public static int getDrawableSize()
543
      {
544
      if( mScreenHeight<1000 )
545
        {
546
        return 0;
547
        }
548
      if( mScreenHeight<1600 )
549
        {
550
        return 1;
551
        }
552 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
553
        {
554
        return 2;
555
        }
556 f6a9c538 Leszek Koltunski
557 31a9f38d Leszek Koltunski
      return 3;
558 f6a9c538 Leszek Koltunski
      }
559
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561
562 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
563 f6a9c538 Leszek Koltunski
      {
564
      int size = getDrawableSize();
565
566
      switch(size)
567
        {
568
        case 0 : return small;
569
        case 1 : return medium;
570 31a9f38d Leszek Koltunski
        case 2 : return big;
571
        default: return huge;
572 f6a9c538 Leszek Koltunski
        }
573
      }
574
575 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
576
577
    public void acceptPrivacy()
578
      {
579
      mPolicyAccepted = true;
580
      }
581
582
///////////////////////////////////////////////////////////////////////////////////////////////////
583
584
    public void declinePrivacy()
585
      {
586
      finish();
587
      }
588
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590
591
    public static boolean localeIsChinese()
592
      {
593
      String language;
594
595
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
596
        {
597
        language= LocaleList.getDefault().get(0).getLanguage();
598
        }
599
      else
600
        {
601
        language= Locale.getDefault().getLanguage();
602
        }
603
604
      return language.equals("zh");
605
      }
606
607 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
608
609
    public boolean isVertical()
610
      {
611
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
612
      return view.isVertical();
613
      }
614 46405bb4 Leszek Koltunski
615 f5da732a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
616
617 809c3432 Leszek Koltunski
    public void blockEverything(int place)
618 f5da732a Leszek Koltunski
      {
619 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
620
      ObjectControl control = view.getObjectControl();
621
      control.blockEverything(place);
622 8badfe2a Leszek Koltunski
623
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
624
      play.setLockState(this);
625 f5da732a Leszek Koltunski
      }
626
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628
629
    public void unblockEverything()
630
      {
631 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
632
      ObjectControl control = view.getObjectControl();
633
      control.unblockEverything();
634 8badfe2a Leszek Koltunski
635
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
636
      play.setLockState(this);
637 f5da732a Leszek Koltunski
      }
638
639 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
640
641 d433b50e Leszek Koltunski
    public void switchTutorial(String url, int objectOrdinal)
642 b6468abb Leszek Koltunski
      {
643 9530f6b0 Leszek Koltunski
      Intent intent = new Intent(this, TutorialActivity.class);
644
      intent.putExtra("url", url);
645
      intent.putExtra("obj", objectOrdinal);
646
      startActivity(intent);
647 b6468abb Leszek Koltunski
      }
648 1237d25d Leszek Koltunski
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650
651 d433b50e Leszek Koltunski
    public void switchConfig(int objectOrdinal)
652 1237d25d Leszek Koltunski
      {
653 9530f6b0 Leszek Koltunski
      Intent intent = new Intent(this, ConfigActivity.class);
654
      intent.putExtra("obj", objectOrdinal);
655
      startActivity(intent);
656
      }
657
658
///////////////////////////////////////////////////////////////////////////////////////////////////
659
660
    public void switchToBandagedCreator()
661
      {
662
      Intent intent = new Intent(this, BandagedCreatorActivity.class);
663
      startActivity(intent);
664 1237d25d Leszek Koltunski
      }
665 41a5dd89 Leszek Koltunski
666
///////////////////////////////////////////////////////////////////////////////////////////////////
667
668
    public void reloadObject(String shortName)
669
      {
670
      TwistyObject currObject = getObject();
671 03423c67 Leszek Koltunski
      String name = currObject==null ? "" : currObject.getShortName();
672 41a5dd89 Leszek Koltunski
673 5e048300 Leszek Koltunski
      if( name.toLowerCase(Locale.ENGLISH).equals(shortName) )
674 41a5dd89 Leszek Koltunski
        {
675
        RubikObject object = RubikObjectList.getObject(name);
676
677
        if( object!=null )
678
          {
679
          int meshState = object.getMeshState();
680
          int iconMode  = TwistyObject.MODE_NORM;
681
          InputStream jsonStream = object.getObjectStream(this);
682
          InputStream meshStream = object.getMeshStream(this);
683
          ObjectControl control = getControl();
684
          control.changeObject(-1,meshState,iconMode,jsonStream,meshStream);
685
          }
686
        }
687
      }
688 0c52af30 Leszek Koltunski
}