Project

General

Profile

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

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

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