Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 526a5906

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 3f7a4363 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
47
48 2afc6754 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
49 3f7a4363 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
50 2afc6754 Leszek Koltunski
import org.distorted.objectlib.effects.BaseEffect;
51 3f7a4363 Leszek Koltunski
52 2d9fc972 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
53 b1e9596b Leszek Koltunski
import org.distorted.dialogs.RubikDialogPrivacy;
54 acabdd83 Leszek Koltunski
import org.distorted.external.RubikScores;
55
import org.distorted.external.RubikNetwork;
56 d433b50e Leszek Koltunski
import org.distorted.objects.RubikObject;
57
import org.distorted.objects.RubikObjectList;
58 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
59
import org.distorted.screens.RubikScreenPlay;
60 eaf87d1d Leszek Koltunski
import org.distorted.tutorials.TutorialActivity;
61 211b48f2 Leszek Koltunski
62 09cf2a36 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
63
64 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66 e019c70b Leszek Koltunski
public class RubikActivity extends AppCompatActivity
67 0c52af30 Leszek Koltunski
{
68 e847c553 Leszek Koltunski
    public static final boolean SHOW_DOWNLOADED_DEBUG = false;
69
70 054fbee1 Leszek Koltunski
    public static final float PADDING             = 0.01f;
71 c651024f Leszek Koltunski
    public static final float SMALL_MARGIN        = 0.004f;
72
    public static final float MEDIUM_MARGIN       = 0.015f;
73 054fbee1 Leszek Koltunski
    public static final float LARGE_MARGIN        = 0.025f;
74
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
75
    public static final float TITLE_TEXT_SIZE     = 0.06f;
76 7ea57482 Leszek Koltunski
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
77
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
78 045857e5 Leszek Koltunski
    public static final float MENU_ITEM_SIZE      = 0.11f;
79 5de2c572 Leszek Koltunski
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
80
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
81 362807f0 Leszek Koltunski
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
82
    public static final float SCORES_ITEM_TEXT    = 0.030f;
83 ef1f3e34 Leszek Koltunski
    public static final float TUTORIAL_ITEM_TEXT  = 0.100f;
84 eb376d3a Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
85
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
86
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
87
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
88 6e3fcb91 Leszek Koltunski
    public static final float TAB_WIDTH           = 0.100f;
89
    public static final float TAB_HEIGHT          = 0.100f;
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 526a5906 Leszek Koltunski
      RubikObjectList.restorePreferences(preferences);
335
336 33499c56 Leszek Koltunski
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
337 4235de9b Leszek Koltunski
        {
338 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
339 4235de9b Leszek Koltunski
        }
340 33499c56 Leszek Koltunski
341 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
342 211b48f2 Leszek Koltunski
        {
343 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
344 211b48f2 Leszek Koltunski
        }
345 33499c56 Leszek Koltunski
346 fcd5b990 Leszek Koltunski
      ScreenList.restorePreferences(preferences);
347 0333d81e Leszek Koltunski
      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 84d746d7 Leszek Koltunski
        String newName = robject==null ? "NULL" : robject.getUpperName();
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 314e9ff0 Leszek Koltunski
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
496
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
497 aec421fd Leszek Koltunski
      String name = object==null ? "NULL" : object.getUpperName();
498 09cf2a36 Leszek Koltunski
499 aec421fd Leszek Koltunski
      control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream);
500 2e8ec627 Leszek Koltunski
      }
501
502 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
503
504
    public static int getDrawableSize()
505
      {
506
      if( mScreenHeight<1000 )
507
        {
508
        return 0;
509
        }
510
      if( mScreenHeight<1600 )
511
        {
512
        return 1;
513
        }
514 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
515
        {
516
        return 2;
517
        }
518 f6a9c538 Leszek Koltunski
519 31a9f38d Leszek Koltunski
      return 3;
520 f6a9c538 Leszek Koltunski
      }
521
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523
524 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
525 f6a9c538 Leszek Koltunski
      {
526
      int size = getDrawableSize();
527
528
      switch(size)
529
        {
530
        case 0 : return small;
531
        case 1 : return medium;
532 31a9f38d Leszek Koltunski
        case 2 : return big;
533
        default: return huge;
534 f6a9c538 Leszek Koltunski
        }
535
      }
536
537 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
538
539
    public void acceptPrivacy()
540
      {
541
      mPolicyAccepted = true;
542
      }
543
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545
546
    public void declinePrivacy()
547
      {
548
      finish();
549
      }
550
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552
553
    public static boolean localeIsChinese()
554
      {
555
      String language;
556
557
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
558
        {
559
        language= LocaleList.getDefault().get(0).getLanguage();
560
        }
561
      else
562
        {
563
        language= Locale.getDefault().getLanguage();
564
        }
565
566
      return language.equals("zh");
567
      }
568
569 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
570
571
    public boolean isVertical()
572
      {
573
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
574
      return view.isVertical();
575
      }
576 46405bb4 Leszek Koltunski
577 f5da732a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
578
579 809c3432 Leszek Koltunski
    public void blockEverything(int place)
580 f5da732a Leszek Koltunski
      {
581 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
582
      ObjectControl control = view.getObjectControl();
583
      control.blockEverything(place);
584 8badfe2a Leszek Koltunski
585
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
586
      play.setLockState(this);
587 f5da732a Leszek Koltunski
      }
588
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590
591
    public void unblockEverything()
592
      {
593 2afc6754 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
594
      ObjectControl control = view.getObjectControl();
595
      control.unblockEverything();
596 8badfe2a Leszek Koltunski
597
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
598
      play.setLockState(this);
599 f5da732a Leszek Koltunski
      }
600
601 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
602
603 d433b50e Leszek Koltunski
    public void switchTutorial(String url, int objectOrdinal)
604 b6468abb Leszek Koltunski
      {
605
      Intent myIntent = new Intent(this, TutorialActivity.class);
606 2971588c Leszek Koltunski
      myIntent.putExtra("url", url);
607 d433b50e Leszek Koltunski
      myIntent.putExtra("obj", objectOrdinal);
608 b6468abb Leszek Koltunski
      startActivity(myIntent);
609
      }
610 1237d25d Leszek Koltunski
611
///////////////////////////////////////////////////////////////////////////////////////////////////
612
613 d433b50e Leszek Koltunski
    public void switchConfig(int objectOrdinal)
614 1237d25d Leszek Koltunski
      {
615
      Intent myIntent = new Intent(this, ConfigActivity.class);
616 d433b50e Leszek Koltunski
      myIntent.putExtra("obj", objectOrdinal);
617 1237d25d Leszek Koltunski
      startActivity(myIntent);
618
      }
619 0c52af30 Leszek Koltunski
}