Project

General

Profile

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

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

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