Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikActivity.java @ 99dd8d12

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 36b9ee93 Leszek Koltunski
public class RubikActivity extends AppCompatActivity implements RubikDebug.ActivityChanger, EffectListener
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 36b9ee93 Leszek Koltunski
RubikPreRender pre = view.getPreRender();
271
pre.destroyNewObject();
272
RubikDebug.addDebug("RubikActivity: onResume");
273
274 53f23b64 Leszek Koltunski
      boolean success = false;
275 be576d14 Leszek Koltunski
      RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
276 4888e97c Leszek Koltunski
      int object = play.getObject();
277
      int size   = play.getSize();
278
279 9c2f0c91 Leszek Koltunski
      if( object>=0 && object< ObjectList.NUM_OBJECTS )
280 4c0cd600 Leszek Koltunski
        {
281 9c2f0c91 Leszek Koltunski
        ObjectList obj = ObjectList.getObject(object);
282 4c0cd600 Leszek Koltunski
        int[] sizes = obj.getSizes();
283 9c2f0c91 Leszek Koltunski
        int sizeIndex = ObjectList.getSizeIndex(object,size);
284 4c0cd600 Leszek Koltunski
285 53f23b64 Leszek Koltunski
        if( sizeIndex>=0 && sizeIndex<sizes.length )
286 4c0cd600 Leszek Koltunski
          {
287 53f23b64 Leszek Koltunski
          success = true;
288 5a4d4fba Leszek Koltunski
          view.getPreRender().changeObject(obj,size);
289 4c0cd600 Leszek Koltunski
          }
290 53f23b64 Leszek Koltunski
        }
291
292
      if( !success )
293
        {
294 9c2f0c91 Leszek Koltunski
        ObjectList obj = ObjectList.getObject(RubikStatePlay.DEF_OBJECT);
295 53f23b64 Leszek Koltunski
        int s = RubikStatePlay.DEF_SIZE;
296
297 7b7d65ce Leszek Koltunski
        play.setObjectAndSize(this,obj,s);
298 5a4d4fba Leszek Koltunski
        view.getPreRender().changeObject(obj,s);
299 4c0cd600 Leszek Koltunski
        }
300 b1e9596b Leszek Koltunski
301
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
302 0c52af30 Leszek Koltunski
      }
303
    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305
    
306
    @Override
307
    protected void onDestroy() 
308
      {
309 d7de3072 Leszek Koltunski
      DistortedLibrary.onDestroy(0);
310 0c52af30 Leszek Koltunski
      super.onDestroy();
311
      }
312
313 33499c56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
314
315
    private void savePreferences()
316
      {
317
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
318
      SharedPreferences.Editor editor = preferences.edit();
319
320 b1e9596b Leszek Koltunski
      editor.putBoolean("policyAccepted", mPolicyAccepted);
321
322 211b48f2 Leszek Koltunski
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
323 33499c56 Leszek Koltunski
        {
324
        BaseEffect.Type.getType(i).savePreferences(editor);
325
        }
326
327 be576d14 Leszek Koltunski
      for (int i = 0; i< StateList.LENGTH; i++)
328 211b48f2 Leszek Koltunski
        {
329 be576d14 Leszek Koltunski
        StateList.getState(i).getStateClass().savePreferences(editor);
330 211b48f2 Leszek Koltunski
        }
331 33499c56 Leszek Koltunski
332 be576d14 Leszek Koltunski
      StateList.savePreferences(editor);
333 0333d81e Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
334 5a4d4fba Leszek Koltunski
      view.getPreRender().savePreferences(editor);
335 0333d81e Leszek Koltunski
336 33499c56 Leszek Koltunski
      editor.apply();
337
      }
338
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340
341
    private void restorePreferences()
342
      {
343
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
344
345 b1e9596b Leszek Koltunski
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
346
347 33499c56 Leszek Koltunski
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
348 4235de9b Leszek Koltunski
        {
349 33499c56 Leszek Koltunski
        BaseEffect.Type.getType(i).restorePreferences(preferences);
350 4235de9b Leszek Koltunski
        }
351 33499c56 Leszek Koltunski
352 be576d14 Leszek Koltunski
      for (int i = 0; i< StateList.LENGTH; i++)
353 211b48f2 Leszek Koltunski
        {
354 be576d14 Leszek Koltunski
        StateList.getState(i).getStateClass().restorePreferences(preferences);
355 211b48f2 Leszek Koltunski
        }
356 33499c56 Leszek Koltunski
357 be576d14 Leszek Koltunski
      StateList.restorePreferences(preferences);
358 0333d81e Leszek Koltunski
359
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
360 5a4d4fba Leszek Koltunski
      view.getPreRender().restorePreferences(preferences);
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 34747dd1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
388 47ba5ddc Leszek Koltunski
// PUBLIC API
389 1b3cbd5b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
390
391
    public FirebaseAnalytics getAnalytics()
392
      {
393
      return mFirebaseAnalytics;
394
      }
395
396 a6d3b158 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
397
398 9c2f0c91 Leszek Koltunski
    public TwistyObject getObject()
399 aa171dee Leszek Koltunski
      {
400
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
401 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
402
      return pre.getObject();
403 8becce57 Leszek Koltunski
      }
404
405 e3c74c0f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
406
407 88fb92ba Leszek Koltunski
    public int getScreenWidthInPixels()
408 e3c74c0f Leszek Koltunski
      {
409
      return mScreenWidth;
410
      }
411
412 88fb92ba Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
413
414
    public int getScreenHeightInPixels()
415
      {
416
      return mScreenHeight;
417
      }
418
419 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
420
421 5a4d4fba Leszek Koltunski
    public RubikPreRender getPreRender()
422 8becce57 Leszek Koltunski
      {
423
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
424 5a4d4fba Leszek Koltunski
      return view.getPreRender();
425 aa171dee Leszek Koltunski
      }
426
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
429 9c2f0c91 Leszek Koltunski
    public void changeObject(ObjectList newObject, int newSize, boolean reportChange)
430 769d7b9f Leszek Koltunski
      {
431
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
432 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
433 7eae2d49 Leszek Koltunski
434
      if( reportChange )
435
        {
436 9c2f0c91 Leszek Koltunski
        TwistyObject oldObject = pre.getObject();
437
        ObjectList oldList = oldObject.getObjectList();
438 d99f3a48 Leszek Koltunski
        int oldNum = oldObject.getNumLayers();
439 7eae2d49 Leszek Koltunski
        float fps = view.getRenderer().getFPS();
440 e35247b8 Leszek Koltunski
        fps = (int)(fps+0.5f);
441 7eae2d49 Leszek Koltunski
        StringBuilder name = new StringBuilder();
442
        name.append(oldList.name());
443
        name.append('_');
444 d99f3a48 Leszek Koltunski
        name.append(oldNum);
445 7eae2d49 Leszek Koltunski
        name.append(' ');
446
        name.append(fps);
447
        name.append(" --> ");
448
        name.append(newObject.name());
449
        name.append('_');
450
        name.append(newSize);
451
452
        if( BuildConfig.DEBUG )
453
          {
454
          android.util.Log.e("rubik", name.toString());
455
          }
456
        else
457
          {
458
          FirebaseAnalytics analytics = getAnalytics();
459
460
          if( analytics!=null )
461
            {
462
            Bundle bundle = new Bundle();
463
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
464
            analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
465
            }
466
          }
467
        }
468
469
      pre.changeObject(newObject,newSize);
470 2e8ec627 Leszek Koltunski
      }
471
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473
474 9c2f0c91 Leszek Koltunski
    public void setupObject(ObjectList object, int size, int[][] moves)
475 2e8ec627 Leszek Koltunski
      {
476
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
477 5a4d4fba Leszek Koltunski
      RubikPreRender pre = view.getPreRender();
478
      pre.setupObject(object,size,moves);
479 769d7b9f Leszek Koltunski
      }
480
481 f6a9c538 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
482
483
    public static int getDrawableSize()
484
      {
485
      if( mScreenHeight<1000 )
486
        {
487
        return 0;
488
        }
489
      if( mScreenHeight<1600 )
490
        {
491
        return 1;
492
        }
493 31a9f38d Leszek Koltunski
      if( mScreenHeight<1900 )
494
        {
495
        return 2;
496
        }
497 f6a9c538 Leszek Koltunski
498 31a9f38d Leszek Koltunski
      return 3;
499 f6a9c538 Leszek Koltunski
      }
500
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502
503 31a9f38d Leszek Koltunski
    public static int getDrawable(int small, int medium, int big, int huge)
504 f6a9c538 Leszek Koltunski
      {
505
      int size = getDrawableSize();
506
507
      switch(size)
508
        {
509
        case 0 : return small;
510
        case 1 : return medium;
511 31a9f38d Leszek Koltunski
        case 2 : return big;
512
        default: return huge;
513 f6a9c538 Leszek Koltunski
        }
514
      }
515
516 b1e9596b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
517
518
    public void acceptPrivacy()
519
      {
520
      mPolicyAccepted = true;
521
      }
522
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524
525
    public void declinePrivacy()
526
      {
527
      finish();
528
      }
529
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531
532
    public static boolean localeIsChinese()
533
      {
534
      String language;
535
536
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
537
        {
538
        language= LocaleList.getDefault().get(0).getLanguage();
539
        }
540
      else
541
        {
542
        language= Locale.getDefault().getLanguage();
543
        }
544
545
      return language.equals("zh");
546
      }
547
548 769d7b9f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
549
550
    public boolean isVertical()
551
      {
552
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
553
      return view.isVertical();
554
      }
555 46405bb4 Leszek Koltunski
556
///////////////////////////////////////////////////////////////////////////////////////////////////
557
558
    public void toggleLock()
559
      {
560
      mIsLocked = !mIsLocked;
561
      }
562
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564
565
    public boolean isLocked()
566
      {
567 be576d14 Leszek Koltunski
      StateList state = StateList.getCurrentState();
568 46405bb4 Leszek Koltunski
569 be576d14 Leszek Koltunski
      if( state== StateList.PLAY || state== StateList.READ || state== StateList.SOLV )
570 46405bb4 Leszek Koltunski
        {
571
        return mIsLocked;
572
        }
573
574
      return false;
575
      }
576
577
///////////////////////////////////////////////////////////////////////////////////////////////////
578
579
    public boolean retLocked()
580
      {
581
      return mIsLocked;
582
      }
583 b6468abb Leszek Koltunski
584
///////////////////////////////////////////////////////////////////////////////////////////////////
585
586 79bf5d8b Leszek Koltunski
    public void switchTutorial(String url, ObjectList object, int size)
587 b6468abb Leszek Koltunski
      {
588
      Intent myIntent = new Intent(this, TutorialActivity.class);
589 2971588c Leszek Koltunski
      myIntent.putExtra("url", url);
590 79bf5d8b Leszek Koltunski
      myIntent.putExtra("obj", object.ordinal());
591
      myIntent.putExtra("siz", size);
592 b6468abb Leszek Koltunski
      startActivity(myIntent);
593
      }
594 36b9ee93 Leszek Koltunski
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596
597
  public void change()
598
    {
599
    mNumTests++;
600
601
    if( mNumTests<100 )
602
      {
603
      TutorialList list  = TutorialList.getObject(2);
604
      ObjectList objList = list.getObjectList();
605
      int size           = list.getSize();
606
      String url         = list.getTutorialURL(0);
607
608
      switchTutorial(url, objList, size);
609
      }
610
    else
611
      {
612
      finish();
613
      }
614
    }
615
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617
618
  public void assign()
619
    {
620
    RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
621
    RubikPreRender pre = view.getPreRender();
622
    TwistyObject object = pre.getObject();
623
624
    int angle = 360 / object.getBasicAngle();
625
626
    object.addNewRotation(1,1,angle,1000,this);
627
    }
628
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630
631
  public void effectFinished(final long effectID)
632
    {
633
    RubikDebug debug = RubikDebug.getInstance();
634
    debug.onReturned();
635
    }
636 0c52af30 Leszek Koltunski
}