Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 9c39179e

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 b20e89d2 Leszek Koltunski
import org.distorted.dmesh.ObjectMesh;
47
import org.distorted.jsons.ObjectJson;
48 3f7a4363 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
49
50 2afc6754 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
51 3f7a4363 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
52 2afc6754 Leszek Koltunski
import org.distorted.objectlib.effects.BaseEffect;
53 3f7a4363 Leszek Koltunski
54 2d9fc972 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
55 b1e9596b Leszek Koltunski
import org.distorted.dialogs.RubikDialogPrivacy;
56 6a083c6a Leszek Koltunski
import org.distorted.network.RubikScores;
57
import org.distorted.network.RubikNetwork;
58 d433b50e Leszek Koltunski
import org.distorted.objects.RubikObject;
59
import org.distorted.objects.RubikObjectList;
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 054fbee1 Leszek Koltunski
    public static final float PADDING             = 0.01f;
71
    public static final float MARGIN              = 0.004f;
72
    public static final float LARGE_MARGIN        = 0.025f;
73
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
74
    public static final float TITLE_TEXT_SIZE     = 0.06f;
75 7ea57482 Leszek Koltunski
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
76
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
77 045857e5 Leszek Koltunski
    public static final float MENU_ITEM_SIZE      = 0.11f;
78 5de2c572 Leszek Koltunski
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
79
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
80 362807f0 Leszek Koltunski
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
81
    public static final float SCORES_ITEM_TEXT    = 0.030f;
82 ef1f3e34 Leszek Koltunski
    public static final float TUTORIAL_ITEM_TEXT  = 0.100f;
83 eb376d3a Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
84
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
85
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
86
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
87 6e3fcb91 Leszek Koltunski
    public static final float TAB_WIDTH           = 0.100f;
88
    public static final float TAB_HEIGHT          = 0.100f;
89 9c39179e Leszek Koltunski
    public static final float BUBBLE_SIZE         = 0.15f;
90 e3c74c0f Leszek Koltunski
91 af7b68e6 Leszek Koltunski
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
92 ffd68f35 Leszek Koltunski
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
93
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
94
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
95
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
96
97 e365b6c2 Leszek Koltunski
    public static final int FLAGS2=  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
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 c3ffcf58 Leszek Koltunski
    private boolean mJustStarted;
105 1b3cbd5b Leszek Koltunski
    private FirebaseAnalytics mFirebaseAnalytics;
106 f6a9c538 Leszek Koltunski
    private static int mScreenWidth, mScreenHeight;
107 b1e9596b Leszek Koltunski
    private boolean mPolicyAccepted, mIsChinese;
108 0254cfd7 Leszek Koltunski
    private int mCurrentApiVersion;
109 598de3ee Leszek Koltunski
    private int mHeightUpperBar, mHeightLowerBar;
110 c3ffcf58 Leszek Koltunski
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112
113 0c52af30 Leszek Koltunski
    @Override
114 34747dd1 Leszek Koltunski
    protected void onCreate(Bundle savedState)
115 0c52af30 Leszek Koltunski
      {
116 34747dd1 Leszek Koltunski
      super.onCreate(savedState);
117 1237d25d Leszek Koltunski
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
118 d7de3072 Leszek Koltunski
119 dd874ae8 Leszek Koltunski
      setTheme(R.style.MaterialThemeNoActionBar);
120 1cbcc6bf Leszek Koltunski
      setContentView(R.layout.main);
121 c3ffcf58 Leszek Koltunski
122
      mJustStarted = true;
123 1b3cbd5b Leszek Koltunski
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
124 51853bf2 Leszek Koltunski
      mIsChinese = localeIsChinese();
125 e3c74c0f Leszek Koltunski
126
      DisplayMetrics displaymetrics = new DisplayMetrics();
127
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
128 88fb92ba Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
129
      mScreenHeight=displaymetrics.heightPixels;
130 51853bf2 Leszek Koltunski
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
131
                                                  // which is not yet hidden.
132
                                                  // TODO: figure this out exactly.
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
      float height = getScreenHeightInPixels();
144
      int barHeight = (int)(height*RATIO_BAR);
145
      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 c3ffcf58 Leszek Koltunski
      if( mJustStarted )
257
        {
258
        mJustStarted = false;
259 82ce8e64 Leszek Koltunski
        RubikScores scores = RubikScores.getInstance();
260
        scores.incrementNumRuns();
261
        scores.setCountry(this);
262 f12e4de9 Leszek Koltunski
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
263
        RubikObjectList.restoreMeshState(preferences);
264 c3ffcf58 Leszek Koltunski
        }
265
266 400ff34d Leszek Koltunski
      int object = RubikObjectList.getCurrObject();
267 b20e89d2 Leszek Koltunski
      changeIfDifferent(object,view.getObjectControl());
268 51853bf2 Leszek Koltunski
269 b1e9596b Leszek Koltunski
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
270 0c52af30 Leszek Koltunski
      }
271
    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273
    
274
    @Override
275
    protected void onDestroy() 
276
      {
277 1237d25d Leszek Koltunski
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
278 0c52af30 Leszek Koltunski
      super.onDestroy();
279
      }
280
281 4c9947bd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
282
283 b20e89d2 Leszek Koltunski
    private String getAppVers()
284 4c9947bd Leszek Koltunski
      {
285 b20e89d2 Leszek Koltunski
      try
286
        {
287
        PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
288
        return pInfo.versionName;
289
        }
290
      catch (PackageManager.NameNotFoundException e)
291
        {
292
        return "unknown";
293
        }
294 4c9947bd Leszek Koltunski
      }
295
296 33499c56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
297
298
    private void savePreferences()
299
      {
300
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
301
      SharedPreferences.Editor editor = preferences.edit();
302
303 b1e9596b Leszek Koltunski
      editor.putBoolean("policyAccepted", mPolicyAccepted);
304 4c9947bd Leszek Koltunski
      editor.putString("appVersion", getAppVers() );
305 b1e9596b Leszek Koltunski
306 211b48f2 Leszek Koltunski
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
307 33499c56 Leszek Koltunski
        {
308
        BaseEffect.Type.getType(i).savePreferences(editor);
309
        }
310
311 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
312 211b48f2 Leszek Koltunski
        {
313 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
314 211b48f2 Leszek Koltunski
        }
315 33499c56 Leszek Koltunski
316 400ff34d Leszek Koltunski
      RubikObjectList.savePreferences(editor);
317 f12e4de9 Leszek Koltunski
      RubikObjectList.saveMeshState(editor);
318 fcd5b990 Leszek Koltunski
      ScreenList.savePreferences(editor);
319 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
320 2afc6754 Leszek Koltunski
      view.getObjectControl().savePreferences(editor);
321 0333d81e Leszek Koltunski
322 33499c56 Leszek Koltunski
      editor.apply();
323
      }
324
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326
327
    private void restorePreferences()
328
      {
329
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
330
331 b1e9596b Leszek Koltunski
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
332 4c9947bd Leszek Koltunski
      String oldVersion = preferences.getString("appVersion","");
333 b1e9596b Leszek Koltunski
334 33499c56 Leszek Koltunski
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
335 4235de9b Leszek Koltunski
        {
336 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
337 4235de9b Leszek Koltunski
        }
338 33499c56 Leszek Koltunski
339 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
340 211b48f2 Leszek Koltunski
        {
341 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
342 211b48f2 Leszek Koltunski
        }
343 33499c56 Leszek Koltunski
344 400ff34d Leszek Koltunski
      RubikObjectList.restorePreferences(preferences);
345 fcd5b990 Leszek Koltunski
      ScreenList.restorePreferences(preferences);
346 0333d81e Leszek Koltunski
347
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
348 4c9947bd Leszek Koltunski
349
      // Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their
350
      // case the 'mOldVersion' - version of the app which saved the preferences on the last
351
      // go - is empty.
352
      // Between versions 1.8.6 and 1.9.0, the order of the cubits in TwistyCube has changed.
353
      // If someone has scrambled the cube with v. 1.8.6, then upgraded to 1.9.0 and re-started
354
      // the app, because of the different order of the cubits - his cube would be messed up.
355
      // So in such case, i.e. on fresh upgrade from version<=1.8.6 to version>=1.9.0, do not
356
      // restore the object scrambling.
357
358
      if( !oldVersion.equals("") )
359
        {
360
        view.getObjectControl().restorePreferences(preferences);
361
        }
362 ee4e7896 Leszek Koltunski
363
      RubikScores scores = RubikScores.getInstance();
364
365
      if( scores.isVerified() )
366
        {
367
        FirebaseAnalytics analytics = getAnalytics();
368
        analytics.setUserId(scores.getName());
369
        }
370 f3e12931 Leszek Koltunski
      }
371
372 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
373
374
    private void PrivacyPolicy()
375
      {
376
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
377
      priDiag.show(getSupportFragmentManager(), null);
378
      }
379
380 2d9fc972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
381
382 e7e0a94d Leszek Koltunski
    void OpenGLError()
383 2d9fc972 Leszek Koltunski
      {
384
      RubikDialogError errDiag = new RubikDialogError();
385
      errDiag.show(getSupportFragmentManager(), null);
386
      }
387
388 2da68298 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
389
390
    void setScreenSize(int width, int height)
391
      {
392
      mScreenWidth = width;
393
      mScreenHeight= height;
394
      }
395
396 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
397 47ba5ddc Leszek Koltunski
// PUBLIC API
398 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
399
400
    public FirebaseAnalytics getAnalytics()
401
      {
402
      return mFirebaseAnalytics;
403
      }
404
405 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
406
407
    public int getHeightUpperBar()
408
      {
409
      return mHeightUpperBar;
410
      }
411
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413
414
    public int getHeightLowerBar()
415
      {
416
      return mHeightLowerBar;
417
      }
418
419 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
420
421 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
422 aa171dee Leszek Koltunski
      {
423
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
424 2afc6754 Leszek Koltunski
      return view.getObjectControl().getObject();
425 8becce57 Leszek Koltunski
      }
426
427 f8eece7d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
428
429 2afc6754 Leszek Koltunski
    public ObjectControl getControl()
430 f8eece7d Leszek Koltunski
      {
431
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
432 2afc6754 Leszek Koltunski
      return view.getObjectControl();
433 f8eece7d Leszek Koltunski
      }
434
435 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
436
437 8ba7aeb1 Leszek Koltunski
    public int getScreenWidthInPixels()
438 8becce57 Leszek Koltunski
      {
439 8ba7aeb1 Leszek Koltunski
      return mScreenWidth;
440
      }
441
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443
444
    public int getScreenHeightInPixels()
445
      {
446
      return mScreenHeight;
447 aa171dee Leszek Koltunski
      }
448
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
451 d433b50e Leszek Koltunski
    public void changeObject(int newObject, boolean reportChange)
452 769d7b9f Leszek Koltunski
      {
453
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
454 2afc6754 Leszek Koltunski
      ObjectControl control = view.getObjectControl();
455 b20e89d2 Leszek Koltunski
      TwistyObject oldObject = control.getObject();
456
      changeIfDifferent(newObject,control);
457 7eae2d49 Leszek Koltunski
458 b20e89d2 Leszek Koltunski
      if( reportChange && oldObject!=null )
459 7eae2d49 Leszek Koltunski
        {
460 d433b50e Leszek Koltunski
        RubikObject robject = RubikObjectList.getObject(newObject);
461
        String newName = robject==null ? "NULL" : robject.getName();
462 b20e89d2 Leszek Koltunski
        float fps = view.getRenderer().getFPS();
463
        fps = (int)(fps+0.5f);
464
        StringBuilder name = new StringBuilder();
465
        name.append(oldObject.getShortName());
466
        name.append(' ');
467
        name.append(fps);
468
        name.append(" --> ");
469 d433b50e Leszek Koltunski
        name.append(newName);
470 b20e89d2 Leszek Koltunski
471
        if( BuildConfig.DEBUG )
472 03822c33 Leszek Koltunski
          {
473 b20e89d2 Leszek Koltunski
          android.util.Log.e("rubik", name.toString());
474
          }
475
        else
476
          {
477
          FirebaseAnalytics analytics = getAnalytics();
478 03822c33 Leszek Koltunski
479 b20e89d2 Leszek Koltunski
          if( analytics!=null )
480
            {
481
            Bundle bundle = new Bundle();
482
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
483
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
484 7eae2d49 Leszek Koltunski
            }
485
          }
486
        }
487 b20e89d2 Leszek Koltunski
      }
488
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490 7eae2d49 Leszek Koltunski
491 d433b50e Leszek Koltunski
    public void changeIfDifferent(int ordinal, ObjectControl control)
492 b20e89d2 Leszek Koltunski
      {
493 09cf2a36 Leszek Koltunski
      RubikObject object = RubikObjectList.getObject(ordinal);
494
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
495
496 804293f0 Leszek Koltunski
      InputStream jsonStream = ObjectJson.getObjectStream(this,ordinal);
497
      InputStream meshStream = ObjectMesh.getMeshStream(this,ordinal);
498 09cf2a36 Leszek Koltunski
      control.changeIfDifferent(ordinal,meshState,jsonStream,meshStream);
499 2e8ec627 Leszek Koltunski
      }
500
501 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
502
503
    public static int getDrawableSize()
504
      {
505
      if( mScreenHeight<1000 )
506
        {
507
        return 0;
508
        }
509
      if( mScreenHeight<1600 )
510
        {
511
        return 1;
512
        }
513 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
514
        {
515
        return 2;
516
        }
517 f6a9c538 Leszek Koltunski
518 31a9f38d Leszek Koltunski
      return 3;
519 f6a9c538 Leszek Koltunski
      }
520
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522
523 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
524 f6a9c538 Leszek Koltunski
      {
525
      int size = getDrawableSize();
526
527
      switch(size)
528
        {
529
        case 0 : return small;
530
        case 1 : return medium;
531 31a9f38d Leszek Koltunski
        case 2 : return big;
532
        default: return huge;
533 f6a9c538 Leszek Koltunski
        }
534
      }
535
536 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
537
538
    public void acceptPrivacy()
539
      {
540
      mPolicyAccepted = true;
541
      }
542
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544
545
    public void declinePrivacy()
546
      {
547
      finish();
548
      }
549
550
///////////////////////////////////////////////////////////////////////////////////////////////////
551
552
    public static boolean localeIsChinese()
553
      {
554
      String language;
555
556
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
557
        {
558
        language= LocaleList.getDefault().get(0).getLanguage();
559
        }
560
      else
561
        {
562
        language= Locale.getDefault().getLanguage();
563
        }
564
565
      return language.equals("zh");
566
      }
567
568 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
569
570
    public boolean isVertical()
571
      {
572
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
573
      return view.isVertical();
574
      }
575 46405bb4 Leszek Koltunski
576 f5da732a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
577
578 809c3432 Leszek Koltunski
    public void blockEverything(int place)
579 f5da732a Leszek Koltunski
      {
580 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
581
      ObjectControl control = view.getObjectControl();
582
      control.blockEverything(place);
583 8badfe2a Leszek Koltunski
584
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
585
      play.setLockState(this);
586 f5da732a Leszek Koltunski
      }
587
588
///////////////////////////////////////////////////////////////////////////////////////////////////
589
590
    public void unblockEverything()
591
      {
592 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
593
      ObjectControl control = view.getObjectControl();
594
      control.unblockEverything();
595 8badfe2a Leszek Koltunski
596
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
597
      play.setLockState(this);
598 f5da732a Leszek Koltunski
      }
599
600 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
601
602 d433b50e Leszek Koltunski
    public void switchTutorial(String url, int objectOrdinal)
603 b6468abb Leszek Koltunski
      {
604
      Intent myIntent = new Intent(this, TutorialActivity.class);
605 2971588c Leszek Koltunski
      myIntent.putExtra("url", url);
606 d433b50e Leszek Koltunski
      myIntent.putExtra("obj", objectOrdinal);
607 b6468abb Leszek Koltunski
      startActivity(myIntent);
608
      }
609 1237d25d Leszek Koltunski
610
///////////////////////////////////////////////////////////////////////////////////////////////////
611
612 d433b50e Leszek Koltunski
    public void switchConfig(int objectOrdinal)
613 1237d25d Leszek Koltunski
      {
614
      Intent myIntent = new Intent(this, ConfigActivity.class);
615 d433b50e Leszek Koltunski
      myIntent.putExtra("obj", objectOrdinal);
616 1237d25d Leszek Koltunski
      startActivity(myIntent);
617
      }
618 0c52af30 Leszek Koltunski
}