Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 7fe59aa5

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