Project

General

Profile

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

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

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 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 9c39179e Leszek Koltunski
    public static final float BUBBLE_SIZE         = 0.15f;
91 e3c74c0f Leszek Koltunski
92 af7b68e6 Leszek Koltunski
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
93 ffd68f35 Leszek Koltunski
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
94
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
95
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
96
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
97
98 e365b6c2 Leszek Koltunski
    public static final int FLAGS2=  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
99
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
100
101 1237d25d Leszek Koltunski
    private static final int ACTIVITY_NUMBER = 0;
102 598de3ee Leszek Koltunski
    private static final float RATIO_BAR  = 0.10f;
103 1071fb69 Leszek Koltunski
    private static final float RATIO_INSET= 0.09f;
104 598de3ee Leszek Koltunski
105 c3ffcf58 Leszek Koltunski
    private boolean mJustStarted;
106 1b3cbd5b Leszek Koltunski
    private FirebaseAnalytics mFirebaseAnalytics;
107 f6a9c538 Leszek Koltunski
    private static int mScreenWidth, mScreenHeight;
108 b1e9596b Leszek Koltunski
    private boolean mPolicyAccepted, mIsChinese;
109 0254cfd7 Leszek Koltunski
    private int mCurrentApiVersion;
110 598de3ee Leszek Koltunski
    private int mHeightUpperBar, mHeightLowerBar;
111 c3ffcf58 Leszek Koltunski
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
114 0c52af30 Leszek Koltunski
    @Override
115 34747dd1 Leszek Koltunski
    protected void onCreate(Bundle savedState)
116 0c52af30 Leszek Koltunski
      {
117 34747dd1 Leszek Koltunski
      super.onCreate(savedState);
118 1237d25d Leszek Koltunski
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
119 d7de3072 Leszek Koltunski
120 dd874ae8 Leszek Koltunski
      setTheme(R.style.MaterialThemeNoActionBar);
121 1cbcc6bf Leszek Koltunski
      setContentView(R.layout.main);
122 c3ffcf58 Leszek Koltunski
123
      mJustStarted = true;
124 1b3cbd5b Leszek Koltunski
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
125 51853bf2 Leszek Koltunski
      mIsChinese = localeIsChinese();
126 e3c74c0f Leszek Koltunski
127
      DisplayMetrics displaymetrics = new DisplayMetrics();
128
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
129 88fb92ba Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
130
      mScreenHeight=displaymetrics.heightPixels;
131 51853bf2 Leszek Koltunski
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
132
                                                  // which is not yet hidden.
133
                                                  // TODO: figure this out exactly.
134 0254cfd7 Leszek Koltunski
      hideNavigationBar();
135 e8f6670f Leszek Koltunski
      cutoutHack();
136 598de3ee Leszek Koltunski
      computeBarHeights();
137 0254cfd7 Leszek Koltunski
      }
138
139 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
140
// this does not include possible insets
141
142
    private void computeBarHeights()
143
      {
144
      float height = getScreenHeightInPixels();
145
      int barHeight = (int)(height*RATIO_BAR);
146
      mHeightLowerBar = barHeight;
147
      mHeightUpperBar = barHeight;
148 214e301a Leszek Koltunski
149
      LinearLayout layoutTop = findViewById(R.id.upperBar);
150
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
151
152
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
153
      paramsTop.height = mHeightUpperBar;
154
      layoutTop.setLayoutParams(paramsTop);
155
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
156
      paramsBot.height = mHeightLowerBar;
157
      layoutBot.setLayoutParams(paramsBot);
158 598de3ee Leszek Koltunski
      }
159
160 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162
    private void hideNavigationBar()
163
      {
164 c9556e1e Leszek Koltunski
      mCurrentApiVersion = Build.VERSION.SDK_INT;
165 0254cfd7 Leszek Koltunski
166
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
167
        {
168
        final View decorView = getWindow().getDecorView();
169
170 c9556e1e Leszek Koltunski
        decorView.setSystemUiVisibility(FLAGS);
171
172 0254cfd7 Leszek Koltunski
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
173
          {
174
          @Override
175
          public void onSystemUiVisibilityChange(int visibility)
176
            {
177
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
178
              {
179 ffd68f35 Leszek Koltunski
              decorView.setSystemUiVisibility(FLAGS);
180 0254cfd7 Leszek Koltunski
              }
181
            }
182
          });
183
        }
184
      }
185
186 1cb36646 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
187
188
    @Override
189
    public void onAttachedToWindow()
190
      {
191 fd0b901a Leszek Koltunski
      super.onAttachedToWindow();
192
193 e8f6670f Leszek Koltunski
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
194
        {
195
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
196
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
197
198
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
199
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
200 598de3ee Leszek Koltunski
        paramsHid.height = (int)(insetHeight*RATIO_INSET);
201 e8f6670f Leszek Koltunski
        layoutHid.setLayoutParams(paramsHid);
202 598de3ee Leszek Koltunski
        mHeightUpperBar += paramsHid.height;
203 e8f6670f Leszek Koltunski
        }
204 1cb36646 Leszek Koltunski
      }
205
206 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
207 e8f6670f Leszek Koltunski
// do not avoid cutouts
208 c9556e1e Leszek Koltunski
209 e8f6670f Leszek Koltunski
    private void cutoutHack()
210 c9556e1e Leszek Koltunski
      {
211
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
212
        {
213
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
214
        }
215
      }
216
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218 0254cfd7 Leszek Koltunski
219
    @Override
220
    public void onWindowFocusChanged(boolean hasFocus)
221
      {
222
      super.onWindowFocusChanged(hasFocus);
223
224
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
225
        {
226 ffd68f35 Leszek Koltunski
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
227 0254cfd7 Leszek Koltunski
        }
228
      }
229
230 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
231
    
232
    @Override
233
    protected void onPause() 
234
      {
235 82f42eeb Leszek Koltunski
      super.onPause();
236 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
237 0c52af30 Leszek Koltunski
      view.onPause();
238 1237d25d Leszek Koltunski
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
239 6a083c6a Leszek Koltunski
      RubikNetwork.onPause();
240 33499c56 Leszek Koltunski
      savePreferences();
241 0c52af30 Leszek Koltunski
      }
242
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
    
245
    @Override
246
    protected void onResume() 
247
      {
248
      super.onResume();
249 1237d25d Leszek Koltunski
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
250 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
251 0c52af30 Leszek Koltunski
      view.onResume();
252 33499c56 Leszek Koltunski
      restorePreferences();
253 51853bf2 Leszek Koltunski
254 f5da732a Leszek Koltunski
      ScreenList.setScreen(this);
255 8badfe2a Leszek Koltunski
      unblockEverything();
256 4888e97c Leszek Koltunski
257 c3ffcf58 Leszek Koltunski
      if( mJustStarted )
258
        {
259
        mJustStarted = false;
260 82ce8e64 Leszek Koltunski
        RubikScores scores = RubikScores.getInstance();
261
        scores.incrementNumRuns();
262
        scores.setCountry(this);
263 f12e4de9 Leszek Koltunski
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
264
        RubikObjectList.restoreMeshState(preferences);
265 c3ffcf58 Leszek Koltunski
        }
266
267 400ff34d Leszek Koltunski
      int object = RubikObjectList.getCurrObject();
268 b20e89d2 Leszek Koltunski
      changeIfDifferent(object,view.getObjectControl());
269 51853bf2 Leszek Koltunski
270 b1e9596b Leszek Koltunski
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
271 0c52af30 Leszek Koltunski
      }
272
    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274
    
275
    @Override
276
    protected void onDestroy() 
277
      {
278 1237d25d Leszek Koltunski
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
279 0c52af30 Leszek Koltunski
      super.onDestroy();
280
      }
281
282 4c9947bd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
283
284 b20e89d2 Leszek Koltunski
    private String getAppVers()
285 4c9947bd Leszek Koltunski
      {
286 b20e89d2 Leszek Koltunski
      try
287
        {
288
        PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
289
        return pInfo.versionName;
290
        }
291
      catch (PackageManager.NameNotFoundException e)
292
        {
293
        return "unknown";
294
        }
295 4c9947bd Leszek Koltunski
      }
296
297 33499c56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
298
299
    private void savePreferences()
300
      {
301
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
302
      SharedPreferences.Editor editor = preferences.edit();
303
304 b1e9596b Leszek Koltunski
      editor.putBoolean("policyAccepted", mPolicyAccepted);
305 4c9947bd Leszek Koltunski
      editor.putString("appVersion", getAppVers() );
306 b1e9596b Leszek Koltunski
307 211b48f2 Leszek Koltunski
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
308 33499c56 Leszek Koltunski
        {
309
        BaseEffect.Type.getType(i).savePreferences(editor);
310
        }
311
312 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
313 211b48f2 Leszek Koltunski
        {
314 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
315 211b48f2 Leszek Koltunski
        }
316 33499c56 Leszek Koltunski
317 400ff34d Leszek Koltunski
      RubikObjectList.savePreferences(editor);
318 f12e4de9 Leszek Koltunski
      RubikObjectList.saveMeshState(editor);
319 fcd5b990 Leszek Koltunski
      ScreenList.savePreferences(editor);
320 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
321 2afc6754 Leszek Koltunski
      view.getObjectControl().savePreferences(editor);
322 0333d81e Leszek Koltunski
323 33499c56 Leszek Koltunski
      editor.apply();
324
      }
325
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
328
    private void restorePreferences()
329
      {
330
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
331
332 b1e9596b Leszek Koltunski
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
333 4c9947bd Leszek Koltunski
      String oldVersion = preferences.getString("appVersion","");
334 b1e9596b Leszek Koltunski
335 33499c56 Leszek Koltunski
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
336 4235de9b Leszek Koltunski
        {
337 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
338 4235de9b Leszek Koltunski
        }
339 33499c56 Leszek Koltunski
340 fcd5b990 Leszek Koltunski
      for (int i = 0; i< ScreenList.LENGTH; i++)
341 211b48f2 Leszek Koltunski
        {
342 f5da732a Leszek Koltunski
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
343 211b48f2 Leszek Koltunski
        }
344 33499c56 Leszek Koltunski
345 400ff34d Leszek Koltunski
      RubikObjectList.restorePreferences(preferences);
346 fcd5b990 Leszek Koltunski
      ScreenList.restorePreferences(preferences);
347 0333d81e Leszek Koltunski
348
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
349 4c9947bd Leszek Koltunski
350
      // Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their
351
      // case the 'mOldVersion' - version of the app which saved the preferences on the last
352
      // go - is empty.
353
      // Between versions 1.8.6 and 1.9.0, the order of the cubits in TwistyCube has changed.
354
      // If someone has scrambled the cube with v. 1.8.6, then upgraded to 1.9.0 and re-started
355
      // the app, because of the different order of the cubits - his cube would be messed up.
356
      // So in such case, i.e. on fresh upgrade from version<=1.8.6 to version>=1.9.0, do not
357
      // restore the object scrambling.
358
359
      if( !oldVersion.equals("") )
360
        {
361
        view.getObjectControl().restorePreferences(preferences);
362
        }
363 ee4e7896 Leszek Koltunski
364
      RubikScores scores = RubikScores.getInstance();
365
366
      if( scores.isVerified() )
367
        {
368
        FirebaseAnalytics analytics = getAnalytics();
369
        analytics.setUserId(scores.getName());
370
        }
371 f3e12931 Leszek Koltunski
      }
372
373 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
374
375
    private void PrivacyPolicy()
376
      {
377
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
378
      priDiag.show(getSupportFragmentManager(), null);
379
      }
380
381 2d9fc972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
382
383 e7e0a94d Leszek Koltunski
    void OpenGLError()
384 2d9fc972 Leszek Koltunski
      {
385
      RubikDialogError errDiag = new RubikDialogError();
386
      errDiag.show(getSupportFragmentManager(), null);
387
      }
388
389 2da68298 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
390
391
    void setScreenSize(int width, int height)
392
      {
393
      mScreenWidth = width;
394
      mScreenHeight= height;
395
      }
396
397 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
398 47ba5ddc Leszek Koltunski
// PUBLIC API
399 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
400
401
    public FirebaseAnalytics getAnalytics()
402
      {
403
      return mFirebaseAnalytics;
404
      }
405
406 598de3ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
407
408
    public int getHeightUpperBar()
409
      {
410
      return mHeightUpperBar;
411
      }
412
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414
415
    public int getHeightLowerBar()
416
      {
417
      return mHeightLowerBar;
418
      }
419
420 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
421
422 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
423 aa171dee Leszek Koltunski
      {
424
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
425 2afc6754 Leszek Koltunski
      return view.getObjectControl().getObject();
426 8becce57 Leszek Koltunski
      }
427
428 f8eece7d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
429
430 2afc6754 Leszek Koltunski
    public ObjectControl getControl()
431 f8eece7d Leszek Koltunski
      {
432
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
433 2afc6754 Leszek Koltunski
      return view.getObjectControl();
434 f8eece7d Leszek Koltunski
      }
435
436 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
437
438 8ba7aeb1 Leszek Koltunski
    public int getScreenWidthInPixels()
439 8becce57 Leszek Koltunski
      {
440 8ba7aeb1 Leszek Koltunski
      return mScreenWidth;
441
      }
442
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444
445
    public int getScreenHeightInPixels()
446
      {
447
      return mScreenHeight;
448 aa171dee Leszek Koltunski
      }
449
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451
452 d433b50e Leszek Koltunski
    public void changeObject(int newObject, boolean reportChange)
453 769d7b9f Leszek Koltunski
      {
454
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
455 2afc6754 Leszek Koltunski
      ObjectControl control = view.getObjectControl();
456 b20e89d2 Leszek Koltunski
      TwistyObject oldObject = control.getObject();
457
      changeIfDifferent(newObject,control);
458 7eae2d49 Leszek Koltunski
459 b20e89d2 Leszek Koltunski
      if( reportChange && oldObject!=null )
460 7eae2d49 Leszek Koltunski
        {
461 d433b50e Leszek Koltunski
        RubikObject robject = RubikObjectList.getObject(newObject);
462
        String newName = robject==null ? "NULL" : robject.getName();
463 b20e89d2 Leszek Koltunski
        float fps = view.getRenderer().getFPS();
464
        fps = (int)(fps+0.5f);
465
        StringBuilder name = new StringBuilder();
466
        name.append(oldObject.getShortName());
467
        name.append(' ');
468
        name.append(fps);
469
        name.append(" --> ");
470 d433b50e Leszek Koltunski
        name.append(newName);
471 b20e89d2 Leszek Koltunski
472
        if( BuildConfig.DEBUG )
473 03822c33 Leszek Koltunski
          {
474 b20e89d2 Leszek Koltunski
          android.util.Log.e("rubik", name.toString());
475
          }
476
        else
477
          {
478
          FirebaseAnalytics analytics = getAnalytics();
479 03822c33 Leszek Koltunski
480 b20e89d2 Leszek Koltunski
          if( analytics!=null )
481
            {
482
            Bundle bundle = new Bundle();
483
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
484
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
485 7eae2d49 Leszek Koltunski
            }
486
          }
487
        }
488 b20e89d2 Leszek Koltunski
      }
489
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491 7eae2d49 Leszek Koltunski
492 d433b50e Leszek Koltunski
    public void changeIfDifferent(int ordinal, ObjectControl control)
493 b20e89d2 Leszek Koltunski
      {
494 09cf2a36 Leszek Koltunski
      RubikObject object = RubikObjectList.getObject(ordinal);
495
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
496
497 804293f0 Leszek Koltunski
      InputStream jsonStream = ObjectJson.getObjectStream(this,ordinal);
498
      InputStream meshStream = ObjectMesh.getMeshStream(this,ordinal);
499 09cf2a36 Leszek Koltunski
      control.changeIfDifferent(ordinal,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
}