Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 5e048300

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