Project

General

Profile

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

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

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