1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.main;
|
11
|
|
12
|
import java.io.InputStream;
|
13
|
import java.util.Locale;
|
14
|
|
15
|
import android.content.Intent;
|
16
|
import android.content.SharedPreferences;
|
17
|
import android.content.pm.PackageInfo;
|
18
|
import android.content.pm.PackageManager;
|
19
|
import android.os.Build;
|
20
|
import android.os.Bundle;
|
21
|
import android.os.LocaleList;
|
22
|
import android.preference.PreferenceManager;
|
23
|
|
24
|
import android.util.DisplayMetrics;
|
25
|
import android.view.DisplayCutout;
|
26
|
import android.view.View;
|
27
|
import android.view.ViewGroup;
|
28
|
import android.view.WindowManager;
|
29
|
import android.widget.LinearLayout;
|
30
|
|
31
|
import androidx.appcompat.app.AppCompatActivity;
|
32
|
|
33
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
34
|
import com.google.firebase.inappmessaging.FirebaseInAppMessaging;
|
35
|
|
36
|
import org.distorted.config.ConfigActivity;
|
37
|
import org.distorted.bandaged.BandagedCreatorActivity;
|
38
|
import org.distorted.dialogs.RubikDialogStarsExplain;
|
39
|
import org.distorted.library.main.DistortedLibrary;
|
40
|
|
41
|
import org.distorted.library.main.DistortedScreen;
|
42
|
import org.distorted.messaging.RubikInAppMessanging;
|
43
|
import org.distorted.objectlib.main.ObjectControl;
|
44
|
import org.distorted.objectlib.main.TwistyObject;
|
45
|
import org.distorted.objectlib.effects.BaseEffect;
|
46
|
|
47
|
import org.distorted.dialogs.RubikDialogError;
|
48
|
import org.distorted.dialogs.RubikDialogPrivacy;
|
49
|
import org.distorted.external.RubikScores;
|
50
|
import org.distorted.external.RubikNetwork;
|
51
|
import org.distorted.objects.RubikObject;
|
52
|
import org.distorted.objects.RubikObjectList;
|
53
|
import org.distorted.purchase.PurchaseActivity;
|
54
|
import org.distorted.screens.RubikScreenSolving;
|
55
|
import org.distorted.screens.ScreenList;
|
56
|
import org.distorted.screens.RubikScreenPlay;
|
57
|
import org.distorted.tutorials.TutorialActivity;
|
58
|
|
59
|
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
public class RubikActivity extends AppCompatActivity
|
64
|
{
|
65
|
public static final boolean SHOW_DOWNLOADED_DEBUG = false;
|
66
|
public static final boolean SHOW_IAP_DEBUG = true;
|
67
|
public static final boolean USE_IAP = true;
|
68
|
|
69
|
public static final float PADDING = 0.01f;
|
70
|
public static final float SMALL_MARGIN = 0.004f;
|
71
|
public static final float MEDIUM_MARGIN = 0.015f;
|
72
|
public static final float LARGE_MARGIN = 0.025f;
|
73
|
public static final float POPUP_PADDING = 0.045f;
|
74
|
public static final float BUTTON_TEXT_SIZE = 0.05f;
|
75
|
public static final float TITLE_TEXT_SIZE = 0.06f;
|
76
|
public static final float SOLVER_BMP_H_SIZE = 0.11f;
|
77
|
public static final float SOLVER_BMP_V_SIZE = 0.06f;
|
78
|
public static final float PATTERN_GROUP_TEXT = 0.03f;
|
79
|
public static final float PATTERN_CHILD_TEXT = 0.02f;
|
80
|
public static final float SCORES_LEVEL_TEXT = 0.035f;
|
81
|
public static final float SCORES_ITEM_TEXT = 0.030f;
|
82
|
public static final float TUTORIAL_ITEM_TEXT = 0.100f;
|
83
|
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_MAIN_TEXT_SIZE = 0.047f;
|
86
|
public static final float MENU_MED_TEXT_SIZE = 0.04f;
|
87
|
public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
|
88
|
public static final float TAB_WIDTH = 0.100f;
|
89
|
public static final float TAB_HEIGHT = 0.100f;
|
90
|
public static final float MENU_BUTTON_HEIGHT = 0.115f;
|
91
|
|
92
|
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
93
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
94
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
95
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
96
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
97
|
|
98
|
private static final int ACTIVITY_NUMBER = 0;
|
99
|
private static final float RATIO_BAR = 0.10f;
|
100
|
private static final float RATIO_INSET= 0.09f;
|
101
|
|
102
|
private static final String KEY_PLAY = "movesController_play";
|
103
|
private static final String KEY_SOLV = "movesController_solv";
|
104
|
|
105
|
private boolean mJustStarted;
|
106
|
private FirebaseAnalytics mFirebaseAnalytics;
|
107
|
private static int mScreenWidth, mScreenHeight;
|
108
|
private boolean mPolicyAccepted, mIsChinese;
|
109
|
private int mCurrentApiVersion;
|
110
|
private int mHeightUpperBar, mHeightLowerBar;
|
111
|
private int mOldVersion1, mOldVersion2, mOldVersion3;
|
112
|
private String mOldVersion, mCurrVersion;
|
113
|
|
114
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115
|
|
116
|
@Override
|
117
|
protected void onCreate(Bundle savedState)
|
118
|
{
|
119
|
super.onCreate(savedState);
|
120
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
121
|
|
122
|
setTheme(R.style.MaterialThemeNoActionBar);
|
123
|
setContentView(R.layout.main);
|
124
|
|
125
|
mJustStarted = true;
|
126
|
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
|
127
|
mIsChinese = localeIsChinese();
|
128
|
|
129
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
130
|
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
|
131
|
mScreenWidth =displaymetrics.widthPixels;
|
132
|
mScreenHeight=displaymetrics.heightPixels;
|
133
|
|
134
|
hideNavigationBar();
|
135
|
cutoutHack();
|
136
|
computeBarHeights();
|
137
|
|
138
|
mCurrVersion = getAppVers();
|
139
|
|
140
|
Thread thread = new Thread()
|
141
|
{
|
142
|
public void run()
|
143
|
{
|
144
|
RubikInAppMessanging listener = new RubikInAppMessanging();
|
145
|
FirebaseInAppMessaging.getInstance().addClickListener(listener);
|
146
|
}
|
147
|
};
|
148
|
|
149
|
thread.start();
|
150
|
}
|
151
|
|
152
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
153
|
// this does not include possible insets
|
154
|
|
155
|
private void computeBarHeights()
|
156
|
{
|
157
|
int barHeight = (int)(mScreenHeight*RATIO_BAR);
|
158
|
mHeightLowerBar = barHeight;
|
159
|
mHeightUpperBar = barHeight;
|
160
|
|
161
|
LinearLayout layoutTop = findViewById(R.id.upperBar);
|
162
|
LinearLayout layoutBot = findViewById(R.id.lowerBar);
|
163
|
|
164
|
ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
|
165
|
paramsTop.height = mHeightUpperBar;
|
166
|
layoutTop.setLayoutParams(paramsTop);
|
167
|
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
|
168
|
paramsBot.height = mHeightLowerBar;
|
169
|
layoutBot.setLayoutParams(paramsBot);
|
170
|
}
|
171
|
|
172
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173
|
|
174
|
private void hideNavigationBar()
|
175
|
{
|
176
|
mCurrentApiVersion = Build.VERSION.SDK_INT;
|
177
|
|
178
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
|
179
|
{
|
180
|
final View decorView = getWindow().getDecorView();
|
181
|
|
182
|
decorView.setSystemUiVisibility(FLAGS);
|
183
|
|
184
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
|
185
|
{
|
186
|
@Override
|
187
|
public void onSystemUiVisibilityChange(int visibility)
|
188
|
{
|
189
|
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
190
|
{
|
191
|
decorView.setSystemUiVisibility(FLAGS);
|
192
|
}
|
193
|
}
|
194
|
});
|
195
|
}
|
196
|
}
|
197
|
|
198
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199
|
|
200
|
@Override
|
201
|
public void onAttachedToWindow()
|
202
|
{
|
203
|
super.onAttachedToWindow();
|
204
|
|
205
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
206
|
{
|
207
|
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
|
208
|
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
|
209
|
|
210
|
LinearLayout layoutHid = findViewById(R.id.hiddenBar);
|
211
|
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
|
212
|
paramsHid.height = (int)(insetHeight*RATIO_INSET);
|
213
|
layoutHid.setLayoutParams(paramsHid);
|
214
|
mHeightUpperBar += paramsHid.height;
|
215
|
}
|
216
|
}
|
217
|
|
218
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
219
|
// do not avoid cutouts
|
220
|
|
221
|
private void cutoutHack()
|
222
|
{
|
223
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
224
|
{
|
225
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
226
|
}
|
227
|
}
|
228
|
|
229
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
230
|
|
231
|
@Override
|
232
|
public void onWindowFocusChanged(boolean hasFocus)
|
233
|
{
|
234
|
super.onWindowFocusChanged(hasFocus);
|
235
|
|
236
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
|
237
|
{
|
238
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
239
|
}
|
240
|
}
|
241
|
|
242
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243
|
|
244
|
@Override
|
245
|
protected void onPause()
|
246
|
{
|
247
|
super.onPause();
|
248
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
249
|
view.onPause();
|
250
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
251
|
RubikNetwork.onPause();
|
252
|
savePreferences();
|
253
|
}
|
254
|
|
255
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256
|
|
257
|
@Override
|
258
|
protected void onResume()
|
259
|
{
|
260
|
super.onResume();
|
261
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
262
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
263
|
view.onResume();
|
264
|
|
265
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
266
|
restorePreferences(preferences,mJustStarted);
|
267
|
ScreenList.setScreen(this);
|
268
|
unblockEverything();
|
269
|
restoreMoves(preferences);
|
270
|
|
271
|
if( mJustStarted )
|
272
|
{
|
273
|
mJustStarted = false;
|
274
|
RubikScores scores = RubikScores.getInstance();
|
275
|
scores.incrementNumRuns();
|
276
|
scores.setCountry(this);
|
277
|
RubikObjectList.restoreMeshState(preferences);
|
278
|
}
|
279
|
|
280
|
int object = RubikObjectList.getCurrObject();
|
281
|
changeIfDifferent(object,view.getObjectControl());
|
282
|
|
283
|
if( mIsChinese && !mPolicyAccepted ) privacyPolicy();
|
284
|
|
285
|
if( USE_IAP && mOldVersion!=null && !mOldVersion.equals("") && oldVersionLessThan(1,11,5) && !mCurrVersion.equals("1.11.4") )
|
286
|
{
|
287
|
explainStars();
|
288
|
}
|
289
|
else
|
290
|
{
|
291
|
view.setShowStars();
|
292
|
}
|
293
|
}
|
294
|
|
295
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
296
|
|
297
|
private void privacyPolicy()
|
298
|
{
|
299
|
RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
|
300
|
priDiag.show(getSupportFragmentManager(), null);
|
301
|
}
|
302
|
|
303
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
304
|
|
305
|
private void explainStars()
|
306
|
{
|
307
|
RubikDialogStarsExplain staDiag = new RubikDialogStarsExplain();
|
308
|
staDiag.show(getSupportFragmentManager(), null);
|
309
|
}
|
310
|
|
311
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
312
|
|
313
|
@Override
|
314
|
protected void onDestroy()
|
315
|
{
|
316
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
317
|
super.onDestroy();
|
318
|
}
|
319
|
|
320
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
321
|
|
322
|
private String getAppVers()
|
323
|
{
|
324
|
try
|
325
|
{
|
326
|
PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
|
327
|
return pInfo.versionName;
|
328
|
}
|
329
|
catch (PackageManager.NameNotFoundException e)
|
330
|
{
|
331
|
return "unknown";
|
332
|
}
|
333
|
}
|
334
|
|
335
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
336
|
|
337
|
private void savePreferences()
|
338
|
{
|
339
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
340
|
SharedPreferences.Editor editor = preferences.edit();
|
341
|
|
342
|
editor.putBoolean("policyAccepted", mPolicyAccepted);
|
343
|
editor.putString("appVersion", mCurrVersion );
|
344
|
|
345
|
for (int i=0; i<BaseEffect.Type.LENGTH; i++)
|
346
|
{
|
347
|
BaseEffect.Type.getType(i).savePreferences(editor);
|
348
|
}
|
349
|
|
350
|
for (int i = 0; i< ScreenList.LENGTH; i++)
|
351
|
{
|
352
|
ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
|
353
|
}
|
354
|
|
355
|
RubikObjectList.savePreferences(editor);
|
356
|
RubikObjectList.saveMeshState(editor);
|
357
|
ScreenList.savePreferences(editor);
|
358
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
359
|
view.getObjectControl().savePreferences(editor);
|
360
|
|
361
|
ScreenList curr = ScreenList.getCurrentScreen();
|
362
|
|
363
|
if( curr==ScreenList.PLAY )
|
364
|
{
|
365
|
RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
|
366
|
play.saveMovePreferences(KEY_PLAY,editor);
|
367
|
}
|
368
|
if( curr==ScreenList.SOLV )
|
369
|
{
|
370
|
RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
|
371
|
solv.saveMovePreferences(KEY_SOLV,editor);
|
372
|
}
|
373
|
|
374
|
boolean success = editor.commit();
|
375
|
if( !success ) android.util.Log.e("D", "Failed to save preferences");
|
376
|
}
|
377
|
|
378
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
379
|
|
380
|
private void restorePreferences(SharedPreferences preferences, boolean justStarted)
|
381
|
{
|
382
|
mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
|
383
|
mOldVersion = preferences.getString("appVersion","");
|
384
|
parseOldVersion(mOldVersion);
|
385
|
|
386
|
RubikObjectList.restorePreferences(this,preferences,justStarted);
|
387
|
|
388
|
for (int i=0; i<BaseEffect.Type.LENGTH; i++)
|
389
|
{
|
390
|
BaseEffect.Type.getType(i).restorePreferences(preferences);
|
391
|
}
|
392
|
|
393
|
for (int i=0; i<ScreenList.LENGTH; i++)
|
394
|
{
|
395
|
ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
|
396
|
}
|
397
|
|
398
|
RubikScores scores = RubikScores.getInstance();
|
399
|
|
400
|
if( scores.isVerified() )
|
401
|
{
|
402
|
FirebaseAnalytics analytics = getAnalytics();
|
403
|
analytics.setUserId(scores.getName());
|
404
|
}
|
405
|
|
406
|
// all old users upgrading from version <1.11.4, where there was no concept of 'stars',
|
407
|
// get all the stars they have earned
|
408
|
int numStars = scores.getNumStars();
|
409
|
|
410
|
if( justStarted && numStars==0 && oldVersionLessThan(1,11,4) )
|
411
|
{
|
412
|
scores.correctNumStars();
|
413
|
}
|
414
|
|
415
|
// in 1.11.5 we have introduced IAP. When upgrading from something less than 1.11.5 to
|
416
|
// something at least 1.11.5, mark all solved objects as free.
|
417
|
// this needs to be after the above ScreenList.getScreen(i).getScreenClass().restorePreferences()
|
418
|
// as that restores the Records which we need here
|
419
|
// also needs to be after RubikObjectList.restorePreferences()
|
420
|
if( USE_IAP && justStarted && oldVersionLessThan(1,11,5) && !mCurrVersion.equals("1.11.4") )
|
421
|
{
|
422
|
RubikObjectList.firstUpgradeMarkAllSolvedAsFree();
|
423
|
}
|
424
|
|
425
|
ScreenList.restorePreferences(preferences);
|
426
|
|
427
|
// Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their
|
428
|
// case the 'mOldVersion' - version of the app which saved the preferences on the last
|
429
|
// go - is empty.
|
430
|
// Between versions 1.8.6 and 1.9.0, the order of the cubits in TwistyCube has changed.
|
431
|
// If someone has scrambled the cube with v. 1.8.6, then upgraded to 1.9.0 and re-started
|
432
|
// the app, because of the different order of the cubits - his cube would be messed up.
|
433
|
// So in such case, i.e. on fresh upgrade from version<=1.8.6 to version>=1.9.0, do not
|
434
|
// restore the object scrambling.
|
435
|
|
436
|
if( !mOldVersion.equals("") )
|
437
|
{
|
438
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
439
|
view.getObjectControl().restorePreferences(preferences);
|
440
|
}
|
441
|
}
|
442
|
|
443
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
444
|
|
445
|
private void parseOldVersion(String version)
|
446
|
{
|
447
|
if( version==null ) return;
|
448
|
|
449
|
try
|
450
|
{
|
451
|
String[] parts = version.split("\\.");
|
452
|
|
453
|
if( parts.length==3 )
|
454
|
{
|
455
|
mOldVersion1 = Integer.parseInt(parts[0]);
|
456
|
mOldVersion2 = Integer.parseInt(parts[1]);
|
457
|
mOldVersion3 = Integer.parseInt(parts[2]);
|
458
|
}
|
459
|
}
|
460
|
catch(Exception ignored)
|
461
|
{
|
462
|
mOldVersion1 = 0;
|
463
|
mOldVersion2 = 0;
|
464
|
mOldVersion3 = 0;
|
465
|
}
|
466
|
}
|
467
|
|
468
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
469
|
|
470
|
private boolean oldVersionLessThan(int v1, int v2, int v3)
|
471
|
{
|
472
|
if( mOldVersion1<v1 ) return true;
|
473
|
if( mOldVersion1>v1 ) return false;
|
474
|
if( mOldVersion2<v2 ) return true;
|
475
|
if( mOldVersion2>v2 ) return false;
|
476
|
return mOldVersion3<v3;
|
477
|
}
|
478
|
|
479
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
480
|
|
481
|
private void restoreMoves(SharedPreferences preferences)
|
482
|
{
|
483
|
ScreenList curr = ScreenList.getCurrentScreen();
|
484
|
|
485
|
if( curr==ScreenList.PLAY )
|
486
|
{
|
487
|
RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
|
488
|
play.restoreMovePreferences(this,KEY_PLAY,preferences);
|
489
|
}
|
490
|
if( curr==ScreenList.SOLV )
|
491
|
{
|
492
|
RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
|
493
|
solv.restoreMovePreferences(this,KEY_SOLV,preferences);
|
494
|
}
|
495
|
}
|
496
|
|
497
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
498
|
|
499
|
void OpenGLError()
|
500
|
{
|
501
|
RubikDialogError errDiag = new RubikDialogError();
|
502
|
errDiag.show(getSupportFragmentManager(), null);
|
503
|
}
|
504
|
|
505
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
506
|
// PUBLIC API
|
507
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
508
|
|
509
|
public FirebaseAnalytics getAnalytics()
|
510
|
{
|
511
|
return mFirebaseAnalytics;
|
512
|
}
|
513
|
|
514
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
515
|
|
516
|
public int getHeightUpperBar()
|
517
|
{
|
518
|
return mHeightUpperBar;
|
519
|
}
|
520
|
|
521
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
522
|
|
523
|
public int getHeightLowerBar()
|
524
|
{
|
525
|
return mHeightLowerBar;
|
526
|
}
|
527
|
|
528
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
529
|
|
530
|
public TwistyObject getObject()
|
531
|
{
|
532
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
533
|
return view.getObjectControl().getObject();
|
534
|
}
|
535
|
|
536
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
537
|
|
538
|
public DistortedScreen getScreen()
|
539
|
{
|
540
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
541
|
return view.getRenderer().getScreen();
|
542
|
}
|
543
|
|
544
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
545
|
|
546
|
public ObjectControl getControl()
|
547
|
{
|
548
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
549
|
return view.getObjectControl();
|
550
|
}
|
551
|
|
552
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
553
|
|
554
|
public int getScreenWidthInPixels()
|
555
|
{
|
556
|
return mScreenWidth;
|
557
|
}
|
558
|
|
559
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
560
|
|
561
|
public int getScreenHeightInPixels()
|
562
|
{
|
563
|
return mScreenHeight;
|
564
|
}
|
565
|
|
566
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
567
|
|
568
|
public void changeObject(int newObject, boolean reportChange)
|
569
|
{
|
570
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
571
|
ObjectControl control = view.getObjectControl();
|
572
|
TwistyObject oldObject = control.getObject();
|
573
|
changeIfDifferent(newObject,control);
|
574
|
|
575
|
if( reportChange && oldObject!=null )
|
576
|
{
|
577
|
RubikObject robject = RubikObjectList.getObject(newObject);
|
578
|
String newName = robject==null ? "NULL" : robject.getUpperName();
|
579
|
float fps = view.getRenderer().getFPS();
|
580
|
fps = (int)(fps+0.5f);
|
581
|
StringBuilder name = new StringBuilder();
|
582
|
name.append(oldObject.getShortName());
|
583
|
name.append(' ');
|
584
|
name.append(fps);
|
585
|
name.append(" --> ");
|
586
|
name.append(newName);
|
587
|
|
588
|
if( BuildConfig.DEBUG )
|
589
|
{
|
590
|
android.util.Log.e("rubik", name.toString());
|
591
|
}
|
592
|
else
|
593
|
{
|
594
|
FirebaseAnalytics analytics = getAnalytics();
|
595
|
|
596
|
if( analytics!=null )
|
597
|
{
|
598
|
Bundle bundle = new Bundle();
|
599
|
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
|
600
|
analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
|
601
|
}
|
602
|
}
|
603
|
}
|
604
|
}
|
605
|
|
606
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
607
|
|
608
|
public void changeIfDifferent(int ordinal, ObjectControl control)
|
609
|
{
|
610
|
RubikObject object = RubikObjectList.getObject(ordinal);
|
611
|
int meshState = object!=null ? object.getMeshState() : MESH_NICE;
|
612
|
int iconMode = TwistyObject.MODE_NORM;
|
613
|
InputStream jsonStream = object==null ? null : object.getObjectStream(this);
|
614
|
InputStream meshStream = object==null ? null : object.getMeshStream(this);
|
615
|
String name = object==null ? "NULL" : object.getUpperName();
|
616
|
|
617
|
control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
|
618
|
}
|
619
|
|
620
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
621
|
|
622
|
public static int getDrawableSize()
|
623
|
{
|
624
|
if( mScreenHeight<1000 )
|
625
|
{
|
626
|
return 0;
|
627
|
}
|
628
|
if( mScreenHeight<1600 )
|
629
|
{
|
630
|
return 1;
|
631
|
}
|
632
|
if( mScreenHeight<1900 )
|
633
|
{
|
634
|
return 2;
|
635
|
}
|
636
|
|
637
|
return 3;
|
638
|
}
|
639
|
|
640
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
641
|
|
642
|
public static int getDrawable(int small, int medium, int big, int huge)
|
643
|
{
|
644
|
int size = getDrawableSize();
|
645
|
|
646
|
switch(size)
|
647
|
{
|
648
|
case 0 : return small;
|
649
|
case 1 : return medium;
|
650
|
case 2 : return big;
|
651
|
default: return huge;
|
652
|
}
|
653
|
}
|
654
|
|
655
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
656
|
|
657
|
public void acceptPrivacy()
|
658
|
{
|
659
|
mPolicyAccepted = true;
|
660
|
}
|
661
|
|
662
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
663
|
|
664
|
public void declinePrivacy()
|
665
|
{
|
666
|
finish();
|
667
|
}
|
668
|
|
669
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
670
|
|
671
|
public static boolean localeIsChinese()
|
672
|
{
|
673
|
String language;
|
674
|
|
675
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
676
|
{
|
677
|
language= LocaleList.getDefault().get(0).getLanguage();
|
678
|
}
|
679
|
else
|
680
|
{
|
681
|
language= Locale.getDefault().getLanguage();
|
682
|
}
|
683
|
|
684
|
return language.equals("zh");
|
685
|
}
|
686
|
|
687
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
688
|
|
689
|
public boolean isVertical()
|
690
|
{
|
691
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
692
|
return view.isVertical();
|
693
|
}
|
694
|
|
695
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
696
|
|
697
|
public void blockEverything(int place)
|
698
|
{
|
699
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
700
|
ObjectControl control = view.getObjectControl();
|
701
|
control.blockEverything(place);
|
702
|
|
703
|
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
704
|
play.setLockState(this);
|
705
|
}
|
706
|
|
707
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
708
|
|
709
|
public void unblockEverything()
|
710
|
{
|
711
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
712
|
ObjectControl control = view.getObjectControl();
|
713
|
control.unblockEverything();
|
714
|
|
715
|
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
716
|
play.setLockState(this);
|
717
|
}
|
718
|
|
719
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
720
|
|
721
|
public void switchTutorial(String url, int objectOrdinal)
|
722
|
{
|
723
|
Intent intent = new Intent(this, TutorialActivity.class);
|
724
|
intent.putExtra("url", url);
|
725
|
intent.putExtra("obj", objectOrdinal);
|
726
|
startActivity(intent);
|
727
|
}
|
728
|
|
729
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
730
|
|
731
|
public void switchConfig(int objectOrdinal)
|
732
|
{
|
733
|
Intent intent = new Intent(this, ConfigActivity.class);
|
734
|
intent.putExtra("obj", objectOrdinal);
|
735
|
startActivity(intent);
|
736
|
}
|
737
|
|
738
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
739
|
|
740
|
public void switchToBandagedCreator()
|
741
|
{
|
742
|
Intent intent = new Intent(this, BandagedCreatorActivity.class);
|
743
|
startActivity(intent);
|
744
|
}
|
745
|
|
746
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
747
|
|
748
|
public void switchToPurchase(int objectOrdinal)
|
749
|
{
|
750
|
Intent intent = new Intent(this, PurchaseActivity.class);
|
751
|
intent.putExtra("obj", objectOrdinal);
|
752
|
startActivity(intent);
|
753
|
}
|
754
|
|
755
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
756
|
|
757
|
public void reloadObject(String shortName)
|
758
|
{
|
759
|
TwistyObject currObject = getObject();
|
760
|
String name = currObject==null ? "" : currObject.getShortName();
|
761
|
|
762
|
if( name.toLowerCase(Locale.ENGLISH).equals(shortName) )
|
763
|
{
|
764
|
RubikObject object = RubikObjectList.getObject(name);
|
765
|
|
766
|
if( object!=null )
|
767
|
{
|
768
|
int meshState = object.getMeshState();
|
769
|
int iconMode = TwistyObject.MODE_NORM;
|
770
|
InputStream jsonStream = object.getObjectStream(this);
|
771
|
InputStream meshStream = object.getMeshStream(this);
|
772
|
ObjectControl control = getControl();
|
773
|
control.changeObject(-1,meshState,iconMode,jsonStream,meshStream);
|
774
|
}
|
775
|
}
|
776
|
}
|
777
|
}
|