Project

General

Profile

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

magiccube / src / main / java / org / distorted / main_old / RubikActivity.java @ b42c8399

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