Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 240bf467

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