Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 6142069a

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