Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 1071fb69

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