Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 09784afd

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 b6468abb Leszek Koltunski
import android.content.Intent;
23 33499c56 Leszek Koltunski
import android.content.SharedPreferences;
24 b1e9596b Leszek Koltunski
import android.os.Build;
25 0c52af30 Leszek Koltunski
import android.os.Bundle;
26 b1e9596b Leszek Koltunski
import android.os.LocaleList;
27 33499c56 Leszek Koltunski
import android.preference.PreferenceManager;
28 66e777b0 Leszek Koltunski
import androidx.appcompat.app.AppCompatActivity;
29 e3c74c0f Leszek Koltunski
30
import android.util.DisplayMetrics;
31 fd0b901a Leszek Koltunski
import android.view.DisplayCutout;
32 0254cfd7 Leszek Koltunski
import android.view.View;
33 1cb36646 Leszek Koltunski
import android.view.ViewGroup;
34 c9556e1e Leszek Koltunski
import android.view.WindowManager;
35 1cb36646 Leszek Koltunski
import android.widget.LinearLayout;
36 0c52af30 Leszek Koltunski
37 1b3cbd5b Leszek Koltunski
import com.google.firebase.analytics.FirebaseAnalytics;
38
39 2d9fc972 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
40 b1e9596b Leszek Koltunski
import org.distorted.dialogs.RubikDialogPrivacy;
41 1f9772f3 Leszek Koltunski
import org.distorted.effects.BaseEffect;
42 e1111500 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
43 0c52af30 Leszek Koltunski
44 36b9ee93 Leszek Koltunski
import org.distorted.library.message.EffectListener;
45 9c2f0c91 Leszek Koltunski
import org.distorted.objects.TwistyObject;
46 c3ffcf58 Leszek Koltunski
import org.distorted.scores.RubikScores;
47 f0e87514 Leszek Koltunski
import org.distorted.scores.RubikScoresDownloader;
48 9c2f0c91 Leszek Koltunski
import org.distorted.objects.ObjectList;
49 be576d14 Leszek Koltunski
import org.distorted.states.StateList;
50 1f9772f3 Leszek Koltunski
import org.distorted.states.RubikStatePlay;
51 b6468abb Leszek Koltunski
import org.distorted.tutorial.TutorialActivity;
52 36b9ee93 Leszek Koltunski
import org.distorted.tutorial.TutorialList;
53 211b48f2 Leszek Koltunski
54 b1e9596b Leszek Koltunski
import java.util.Locale;
55
56 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58 09784afd Leszek Koltunski
public class RubikActivity extends AppCompatActivity implements RubikDebug.ActivityChanger, RubikPreRender.ActionFinishedListener
59 0c52af30 Leszek Koltunski
{
60 054fbee1 Leszek Koltunski
    public static final float PADDING             = 0.01f;
61
    public static final float MARGIN              = 0.004f;
62
    public static final float LARGE_MARGIN        = 0.025f;
63
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
64
    public static final float TITLE_TEXT_SIZE     = 0.06f;
65 7ea57482 Leszek Koltunski
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
66
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
67 045857e5 Leszek Koltunski
    public static final float MENU_ITEM_SIZE      = 0.11f;
68 5de2c572 Leszek Koltunski
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
69
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
70 362807f0 Leszek Koltunski
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
71
    public static final float SCORES_ITEM_TEXT    = 0.030f;
72 ef1f3e34 Leszek Koltunski
    public static final float TUTORIAL_ITEM_TEXT  = 0.100f;
73 eb376d3a Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
74
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
75
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
76
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
77 e3c74c0f Leszek Koltunski
78 af7b68e6 Leszek Koltunski
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
79 ffd68f35 Leszek Koltunski
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
80
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
81
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
82
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
83
84 e365b6c2 Leszek Koltunski
    public static final int FLAGS2=  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
85
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
86
87 c3ffcf58 Leszek Koltunski
    private boolean mJustStarted;
88 1b3cbd5b Leszek Koltunski
    private FirebaseAnalytics mFirebaseAnalytics;
89 f6a9c538 Leszek Koltunski
    private static int mScreenWidth, mScreenHeight;
90 b1e9596b Leszek Koltunski
    private boolean mPolicyAccepted, mIsChinese;
91 0254cfd7 Leszek Koltunski
    private int mCurrentApiVersion;
92 46405bb4 Leszek Koltunski
    private boolean mIsLocked;
93 c3ffcf58 Leszek Koltunski
94 36b9ee93 Leszek Koltunski
    private static int mNumTests=0;
95
96 c3ffcf58 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
97
98 0c52af30 Leszek Koltunski
    @Override
99 34747dd1 Leszek Koltunski
    protected void onCreate(Bundle savedState)
100 0c52af30 Leszek Koltunski
      {
101 34747dd1 Leszek Koltunski
      super.onCreate(savedState);
102 d7de3072 Leszek Koltunski
      DistortedLibrary.onCreate(0);
103
104 f6fcf06a Leszek Koltunski
      setTheme(R.style.CustomActivityThemeNoActionBar);
105 1cbcc6bf Leszek Koltunski
      setContentView(R.layout.main);
106 c3ffcf58 Leszek Koltunski
107
      mJustStarted = true;
108 1b3cbd5b Leszek Koltunski
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
109 e3c74c0f Leszek Koltunski
110
      DisplayMetrics displaymetrics = new DisplayMetrics();
111
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
112 88fb92ba Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
113
      mScreenHeight=displaymetrics.heightPixels;
114 b1e9596b Leszek Koltunski
115
      mIsChinese = localeIsChinese();
116 46405bb4 Leszek Koltunski
      mIsLocked = false;
117 0254cfd7 Leszek Koltunski
118
      hideNavigationBar();
119 e8f6670f Leszek Koltunski
      cutoutHack();
120 0254cfd7 Leszek Koltunski
      // askForPermissions();
121 99dd8d12 Leszek Koltunski
122
      RubikScoresDownloader downloader = RubikScoresDownloader.getInstance();
123
      downloader.error("TEST_BEGIN");
124 0254cfd7 Leszek Koltunski
      }
125
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
128
    private void hideNavigationBar()
129
      {
130 c9556e1e Leszek Koltunski
      mCurrentApiVersion = Build.VERSION.SDK_INT;
131 0254cfd7 Leszek Koltunski
132
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
133
        {
134
        final View decorView = getWindow().getDecorView();
135
136 c9556e1e Leszek Koltunski
        decorView.setSystemUiVisibility(FLAGS);
137
138 0254cfd7 Leszek Koltunski
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
139
          {
140
          @Override
141
          public void onSystemUiVisibilityChange(int visibility)
142
            {
143
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
144
              {
145 ffd68f35 Leszek Koltunski
              decorView.setSystemUiVisibility(FLAGS);
146 0254cfd7 Leszek Koltunski
              }
147
            }
148
          });
149
        }
150
      }
151
152 1cb36646 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
153
154
    @Override
155
    public void onAttachedToWindow()
156
      {
157 fd0b901a Leszek Koltunski
      super.onAttachedToWindow();
158
159 e8f6670f Leszek Koltunski
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
160
        {
161
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
162
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
163
164
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
165
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
166
        paramsHid.height = (int)(0.8f*insetHeight);
167
        layoutHid.setLayoutParams(paramsHid);
168
        }
169
170 1cb36646 Leszek Koltunski
      final float RATIO = 0.10f;
171
      float height = getScreenHeightInPixels();
172
173
      LinearLayout layoutTop = findViewById(R.id.upperBar);
174
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
175
176
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
177
      paramsTop.height = (int)(height*RATIO);
178
      layoutTop.setLayoutParams(paramsTop);
179
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
180
      paramsBot.height = (int)(height*RATIO);
181
      layoutBot.setLayoutParams(paramsBot);
182
      }
183
184 0254cfd7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
185 e8f6670f Leszek Koltunski
// do not avoid cutouts
186 c9556e1e Leszek Koltunski
187 e8f6670f Leszek Koltunski
    private void cutoutHack()
188 c9556e1e Leszek Koltunski
      {
189
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
190
        {
191
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
192
        }
193
      }
194
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196 0254cfd7 Leszek Koltunski
197
    @Override
198
    public void onWindowFocusChanged(boolean hasFocus)
199
      {
200
      super.onWindowFocusChanged(hasFocus);
201
202
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
203
        {
204 ffd68f35 Leszek Koltunski
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
205 0254cfd7 Leszek Koltunski
        }
206
      }
207
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
210
    private void askForPermissions()
211
      {
212 2f5783d4 Leszek Koltunski
      final int REQUEST_EXTERNAL_STORAGE = 1;
213
214
      String[] PERMISSIONS_STORAGE =
215
        {
216 fcc0e034 Leszek Koltunski
        android.Manifest.permission.READ_EXTERNAL_STORAGE,
217
        android.Manifest.permission.WRITE_EXTERNAL_STORAGE
218 2f5783d4 Leszek Koltunski
        };
219
220 fcc0e034 Leszek Koltunski
      int permission = androidx.core.app.ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
221 2f5783d4 Leszek Koltunski
222 fcc0e034 Leszek Koltunski
      if (permission != android.content.pm.PackageManager.PERMISSION_GRANTED)
223 2f5783d4 Leszek Koltunski
        {
224 fcc0e034 Leszek Koltunski
        androidx.core.app.ActivityCompat.requestPermissions( this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE );
225 2f5783d4 Leszek Koltunski
        }
226 0c52af30 Leszek Koltunski
      }
227
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
    
230
    @Override
231
    protected void onPause() 
232
      {
233 82f42eeb Leszek Koltunski
      super.onPause();
234 36b9ee93 Leszek Koltunski
235
      RubikDebug debug = RubikDebug.getInstance();
236
      debug.onPause();
237
238 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
239 0c52af30 Leszek Koltunski
      view.onPause();
240 d7de3072 Leszek Koltunski
      DistortedLibrary.onPause(0);
241 f3e12931 Leszek Koltunski
      RubikScoresDownloader.onPause();
242 33499c56 Leszek Koltunski
      savePreferences();
243 0c52af30 Leszek Koltunski
      }
244
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246
    
247
    @Override
248
    protected void onResume() 
249
      {
250
      super.onResume();
251 d7de3072 Leszek Koltunski
      DistortedLibrary.onResume(0);
252 4235de9b Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
253 0c52af30 Leszek Koltunski
      view.onResume();
254 36b9ee93 Leszek Koltunski
255
      RubikDebug debug = RubikDebug.getInstance();
256
      debug.onResume(this);
257
258 e03e0352 Leszek Koltunski
      view.initialize();
259 33499c56 Leszek Koltunski
      restorePreferences();
260 be576d14 Leszek Koltunski
      StateList.setState(this);
261 4888e97c Leszek Koltunski
262 c3ffcf58 Leszek Koltunski
      if( mJustStarted )
263
        {
264
        mJustStarted = false;
265 82ce8e64 Leszek Koltunski
        RubikScores scores = RubikScores.getInstance();
266
        scores.incrementNumRuns();
267
        scores.setCountry(this);
268 c3ffcf58 Leszek Koltunski
        }
269
270 09784afd Leszek Koltunski
      RubikDebug.addDebug("RubikActivity: onResume");
271 36b9ee93 Leszek Koltunski
272 53f23b64 Leszek Koltunski
      boolean success = false;
273 be576d14 Leszek Koltunski
      RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
274 4888e97c Leszek Koltunski
      int object = play.getObject();
275
      int size   = play.getSize();
276
277 9c2f0c91 Leszek Koltunski
      if( object>=0 && object< ObjectList.NUM_OBJECTS )
278 4c0cd600 Leszek Koltunski
        {
279 9c2f0c91 Leszek Koltunski
        ObjectList obj = ObjectList.getObject(object);
280 4c0cd600 Leszek Koltunski
        int[] sizes = obj.getSizes();
281 9c2f0c91 Leszek Koltunski
        int sizeIndex = ObjectList.getSizeIndex(object,size);
282 4c0cd600 Leszek Koltunski
283 53f23b64 Leszek Koltunski
        if( sizeIndex>=0 && sizeIndex<sizes.length )
284 4c0cd600 Leszek Koltunski
          {
285 53f23b64 Leszek Koltunski
          success = true;
286 5a4d4fba Leszek Koltunski
          view.getPreRender().changeObject(obj,size);
287 4c0cd600 Leszek Koltunski
          }
288 53f23b64 Leszek Koltunski
        }
289
290
      if( !success )
291
        {
292 9c2f0c91 Leszek Koltunski
        ObjectList obj = ObjectList.getObject(RubikStatePlay.DEF_OBJECT);
293 53f23b64 Leszek Koltunski
        int s = RubikStatePlay.DEF_SIZE;
294
295 7b7d65ce Leszek Koltunski
        play.setObjectAndSize(this,obj,s);
296 5a4d4fba Leszek Koltunski
        view.getPreRender().changeObject(obj,s);
297 4c0cd600 Leszek Koltunski
        }
298 b1e9596b Leszek Koltunski
299
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
300 0c52af30 Leszek Koltunski
      }
301
    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303
    
304
    @Override
305
    protected void onDestroy() 
306
      {
307 d7de3072 Leszek Koltunski
      DistortedLibrary.onDestroy(0);
308 0c52af30 Leszek Koltunski
      super.onDestroy();
309
      }
310
311 33499c56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
312
313
    private void savePreferences()
314
      {
315
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
316
      SharedPreferences.Editor editor = preferences.edit();
317
318 b1e9596b Leszek Koltunski
      editor.putBoolean("policyAccepted", mPolicyAccepted);
319
320 211b48f2 Leszek Koltunski
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
321 33499c56 Leszek Koltunski
        {
322
        BaseEffect.Type.getType(i).savePreferences(editor);
323
        }
324
325 be576d14 Leszek Koltunski
      for (int i = 0; i< StateList.LENGTH; i++)
326 211b48f2 Leszek Koltunski
        {
327 be576d14 Leszek Koltunski
        StateList.getState(i).getStateClass().savePreferences(editor);
328 211b48f2 Leszek Koltunski
        }
329 33499c56 Leszek Koltunski
330 be576d14 Leszek Koltunski
      StateList.savePreferences(editor);
331 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
332 5a4d4fba Leszek Koltunski
      view.getPreRender().savePreferences(editor);
333 0333d81e Leszek Koltunski
334 33499c56 Leszek Koltunski
      editor.apply();
335
      }
336
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338
339
    private void restorePreferences()
340
      {
341
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
342
343 b1e9596b Leszek Koltunski
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
344
345 33499c56 Leszek Koltunski
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
346 4235de9b Leszek Koltunski
        {
347 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
348 4235de9b Leszek Koltunski
        }
349 33499c56 Leszek Koltunski
350 be576d14 Leszek Koltunski
      for (int i = 0; i< StateList.LENGTH; i++)
351 211b48f2 Leszek Koltunski
        {
352 be576d14 Leszek Koltunski
        StateList.getState(i).getStateClass().restorePreferences(preferences);
353 211b48f2 Leszek Koltunski
        }
354 33499c56 Leszek Koltunski
355 be576d14 Leszek Koltunski
      StateList.restorePreferences(preferences);
356 0333d81e Leszek Koltunski
357
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
358 5a4d4fba Leszek Koltunski
      view.getPreRender().restorePreferences(preferences);
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 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
386 47ba5ddc Leszek Koltunski
// PUBLIC API
387 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
388
389
    public FirebaseAnalytics getAnalytics()
390
      {
391
      return mFirebaseAnalytics;
392
      }
393
394 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
395
396 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
397 aa171dee Leszek Koltunski
      {
398
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
399 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
400
      return pre.getObject();
401 8becce57 Leszek Koltunski
      }
402
403 e3c74c0f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
404
405 88fb92ba Leszek Koltunski
    public int getScreenWidthInPixels()
406 e3c74c0f Leszek Koltunski
      {
407
      return mScreenWidth;
408
      }
409
410 88fb92ba Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
411
412
    public int getScreenHeightInPixels()
413
      {
414
      return mScreenHeight;
415
      }
416
417 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
418
419 5a4d4fba Leszek Koltunski
    public RubikPreRender getPreRender()
420 8becce57 Leszek Koltunski
      {
421
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
422 5a4d4fba Leszek Koltunski
      return view.getPreRender();
423 aa171dee Leszek Koltunski
      }
424
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426
427 9c2f0c91 Leszek Koltunski
    public void changeObject(ObjectList newObject, int newSize, boolean reportChange)
428 769d7b9f Leszek Koltunski
      {
429
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
430 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
431 7eae2d49 Leszek Koltunski
432
      if( reportChange )
433
        {
434 9c2f0c91 Leszek Koltunski
        TwistyObject oldObject = pre.getObject();
435
        ObjectList oldList = oldObject.getObjectList();
436 d99f3a48 Leszek Koltunski
        int oldNum = oldObject.getNumLayers();
437 7eae2d49 Leszek Koltunski
        float fps = view.getRenderer().getFPS();
438 e35247b8 Leszek Koltunski
        fps = (int)(fps+0.5f);
439 7eae2d49 Leszek Koltunski
        StringBuilder name = new StringBuilder();
440
        name.append(oldList.name());
441
        name.append('_');
442 d99f3a48 Leszek Koltunski
        name.append(oldNum);
443 7eae2d49 Leszek Koltunski
        name.append(' ');
444
        name.append(fps);
445
        name.append(" --> ");
446
        name.append(newObject.name());
447
        name.append('_');
448
        name.append(newSize);
449
450
        if( BuildConfig.DEBUG )
451
          {
452
          android.util.Log.e("rubik", name.toString());
453
          }
454
        else
455
          {
456
          FirebaseAnalytics analytics = getAnalytics();
457
458
          if( analytics!=null )
459
            {
460
            Bundle bundle = new Bundle();
461
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
462
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
463
            }
464
          }
465
        }
466
467
      pre.changeObject(newObject,newSize);
468 2e8ec627 Leszek Koltunski
      }
469
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471
472 9c2f0c91 Leszek Koltunski
    public void setupObject(ObjectList object, int size, int[][] moves)
473 2e8ec627 Leszek Koltunski
      {
474
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
475 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
476
      pre.setupObject(object,size,moves);
477 769d7b9f Leszek Koltunski
      }
478
479 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
480
481
    public static int getDrawableSize()
482
      {
483
      if( mScreenHeight<1000 )
484
        {
485
        return 0;
486
        }
487
      if( mScreenHeight<1600 )
488
        {
489
        return 1;
490
        }
491 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
492
        {
493
        return 2;
494
        }
495 f6a9c538 Leszek Koltunski
496 31a9f38d Leszek Koltunski
      return 3;
497 f6a9c538 Leszek Koltunski
      }
498
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500
501 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
502 f6a9c538 Leszek Koltunski
      {
503
      int size = getDrawableSize();
504
505
      switch(size)
506
        {
507
        case 0 : return small;
508
        case 1 : return medium;
509 31a9f38d Leszek Koltunski
        case 2 : return big;
510
        default: return huge;
511 f6a9c538 Leszek Koltunski
        }
512
      }
513
514 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
515
516
    public void acceptPrivacy()
517
      {
518
      mPolicyAccepted = true;
519
      }
520
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522
523
    public void declinePrivacy()
524
      {
525
      finish();
526
      }
527
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529
530
    public static boolean localeIsChinese()
531
      {
532
      String language;
533
534
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
535
        {
536
        language= LocaleList.getDefault().get(0).getLanguage();
537
        }
538
      else
539
        {
540
        language= Locale.getDefault().getLanguage();
541
        }
542
543
      return language.equals("zh");
544
      }
545
546 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
547
548
    public boolean isVertical()
549
      {
550
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
551
      return view.isVertical();
552
      }
553 46405bb4 Leszek Koltunski
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555
556
    public void toggleLock()
557
      {
558
      mIsLocked = !mIsLocked;
559
      }
560
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562
563
    public boolean isLocked()
564
      {
565 be576d14 Leszek Koltunski
      StateList state = StateList.getCurrentState();
566 46405bb4 Leszek Koltunski
567 be576d14 Leszek Koltunski
      if( state== StateList.PLAY || state== StateList.READ || state== StateList.SOLV )
568 46405bb4 Leszek Koltunski
        {
569
        return mIsLocked;
570
        }
571
572
      return false;
573
      }
574
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
577
    public boolean retLocked()
578
      {
579
      return mIsLocked;
580
      }
581 b6468abb Leszek Koltunski
582
///////////////////////////////////////////////////////////////////////////////////////////////////
583
584 79bf5d8b Leszek Koltunski
    public void switchTutorial(String url, ObjectList object, int size)
585 b6468abb Leszek Koltunski
      {
586
      Intent myIntent = new Intent(this, TutorialActivity.class);
587 2971588c Leszek Koltunski
      myIntent.putExtra("url", url);
588 79bf5d8b Leszek Koltunski
      myIntent.putExtra("obj", object.ordinal());
589
      myIntent.putExtra("siz", size);
590 b6468abb Leszek Koltunski
      startActivity(myIntent);
591
      }
592 36b9ee93 Leszek Koltunski
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594
595
  public void change()
596
    {
597
    mNumTests++;
598
599
    if( mNumTests<100 )
600
      {
601
      TutorialList list  = TutorialList.getObject(2);
602
      ObjectList objList = list.getObjectList();
603
      int size           = list.getSize();
604
      String url         = list.getTutorialURL(0);
605
606
      switchTutorial(url, objList, size);
607
      }
608
    else
609
      {
610
      finish();
611
      }
612
    }
613
614
///////////////////////////////////////////////////////////////////////////////////////////////////
615
616
  public void assign()
617
    {
618
    RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
619
    RubikPreRender pre = view.getPreRender();
620
    TwistyObject object = pre.getObject();
621
622
    int angle = 360 / object.getBasicAngle();
623
624 09784afd Leszek Koltunski
    pre.addRotation(this,1,1,angle,1000);
625 36b9ee93 Leszek Koltunski
    }
626
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628
629 09784afd Leszek Koltunski
  public void onActionFinished(final long effectID)
630 36b9ee93 Leszek Koltunski
    {
631
    RubikDebug debug = RubikDebug.getInstance();
632
    debug.onReturned();
633
    }
634 0c52af30 Leszek Koltunski
}