1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 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.screens;
|
11
|
|
12
|
import java.lang.ref.WeakReference;
|
13
|
|
14
|
import android.app.Activity;
|
15
|
import android.content.Context;
|
16
|
import android.content.SharedPreferences;
|
17
|
import android.content.res.ColorStateList;
|
18
|
import android.content.res.Resources;
|
19
|
import android.os.Build;
|
20
|
import android.os.Bundle;
|
21
|
import android.util.TypedValue;
|
22
|
import android.view.Gravity;
|
23
|
import android.view.LayoutInflater;
|
24
|
import android.view.View;
|
25
|
import android.widget.Button;
|
26
|
import android.widget.GridLayout;
|
27
|
import android.widget.ImageButton;
|
28
|
import android.widget.LinearLayout;
|
29
|
import android.widget.PopupWindow;
|
30
|
import android.widget.RelativeLayout;
|
31
|
import android.widget.TextView;
|
32
|
|
33
|
import org.distorted.dialogs.RubikDialogUpdates;
|
34
|
import org.distorted.external.RubikNetwork;
|
35
|
import org.distorted.external.RubikScores;
|
36
|
import org.distorted.external.RubikUpdates;
|
37
|
|
38
|
import org.distorted.helpers.PopupCreator;
|
39
|
import org.distorted.main.R;
|
40
|
import org.distorted.main.RubikActivity;
|
41
|
import org.distorted.dialogs.RubikDialogAbout;
|
42
|
import org.distorted.dialogs.RubikDialogPattern;
|
43
|
import org.distorted.dialogs.RubikDialogScores;
|
44
|
import org.distorted.dialogs.RubikDialogTutorial;
|
45
|
import org.distorted.helpers.TransparentImageButton;
|
46
|
import org.distorted.objectlib.main.ObjectControl;
|
47
|
import org.distorted.objects.RubikObject;
|
48
|
import org.distorted.objects.RubikObjectList;
|
49
|
|
50
|
import static android.view.View.inflate;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
public class RubikScreenPlay extends RubikScreenBase implements RubikNetwork.Updatee
|
55
|
{
|
56
|
public static final int NUM_COLUMNS = 5;
|
57
|
public static final int LEVELS_SHOWN = 8;
|
58
|
private static final int NUM_BUTTONS = 6;
|
59
|
private static final int[] mLocation = new int[2];
|
60
|
|
61
|
private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton;
|
62
|
private PopupWindow mObjectPopup, mMenuPopup;
|
63
|
private WeakReference<RubikActivity> mWeakAct;
|
64
|
private TextView mBubbleUpdates;
|
65
|
private Button[] mLevel;
|
66
|
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mMenuButtonHeight, mMenuTextSize;
|
67
|
private int mLevelValue;
|
68
|
private int mColCount, mRowCount, mMaxRowCount;
|
69
|
private int mUpperBarHeight;
|
70
|
private boolean mShouldReactToEndOfScrambling;
|
71
|
private float mScreenWidth;
|
72
|
private int mOldNumScramble;
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
void leaveScreen(RubikActivity act)
|
77
|
{
|
78
|
|
79
|
}
|
80
|
|
81
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82
|
|
83
|
void enterScreen(final RubikActivity act)
|
84
|
{
|
85
|
mWeakAct = new WeakReference<>(act);
|
86
|
mScreenWidth = act.getScreenWidthInPixels();
|
87
|
mUpperBarHeight = act.getHeightUpperBar();
|
88
|
|
89
|
mMenuButtonHeight = (int)(mScreenWidth*RubikActivity.MENU_BUTTON_HEIGHT);
|
90
|
mMenuTextSize = (int)(mScreenWidth*RubikActivity.MENU_MAIN_TEXT_SIZE);
|
91
|
|
92
|
mObjectPopup = null;
|
93
|
mOldNumScramble = 1000; // used to remember which 'level' buttons are visible; initially all visible
|
94
|
|
95
|
// TOP ////////////////////////////
|
96
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
97
|
layoutTop.removeAllViews();
|
98
|
|
99
|
setupSolveButton(act);
|
100
|
layoutTop.addView(mSolveButton);
|
101
|
setupMenuButton(act,mScreenWidth);
|
102
|
layoutTop.addView(mMenuButton);
|
103
|
setupScrambleButton(act);
|
104
|
layoutTop.addView(mScrambleButton);
|
105
|
|
106
|
// BOTTOM /////////////////////////
|
107
|
setupObjectButton(act,mScreenWidth);
|
108
|
createBottomPane(act,mObjButton,null);
|
109
|
}
|
110
|
|
111
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
private void setupObjectButton(final RubikActivity act, final float width)
|
114
|
{
|
115
|
final int margin = (int)(width*RubikActivity.SMALL_MARGIN);
|
116
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu);
|
117
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
118
|
mObjButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
119
|
|
120
|
mObjButton.setOnClickListener( new View.OnClickListener()
|
121
|
{
|
122
|
@Override
|
123
|
public void onClick(View view)
|
124
|
{
|
125
|
if( mObjectPopup==null )
|
126
|
{
|
127
|
float width = act.getScreenWidthInPixels();
|
128
|
float height= act.getScreenHeightInPixels();
|
129
|
setupObjectWindow(act,width,height);
|
130
|
}
|
131
|
|
132
|
if( act.getControl().isUINotBlocked())
|
133
|
{
|
134
|
int rowCount = Math.min(mMaxRowCount,mRowCount);
|
135
|
View popupView = mObjectPopup.getContentView();
|
136
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
137
|
displayPopup(act,view,mObjectPopup,mObjectSize*mColCount,mObjectSize*rowCount+5*margin,margin,margin);
|
138
|
}
|
139
|
}
|
140
|
});
|
141
|
}
|
142
|
|
143
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144
|
|
145
|
private void setupMenuButton(final RubikActivity act, final float width)
|
146
|
{
|
147
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_menu,R.drawable.ui_medium_menu, R.drawable.ui_big_menu, R.drawable.ui_huge_menu);
|
148
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
149
|
mMenuButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
150
|
|
151
|
mMenuButton.setOnClickListener( new View.OnClickListener()
|
152
|
{
|
153
|
@Override
|
154
|
public void onClick(View view)
|
155
|
{
|
156
|
if( mMenuPopup==null )
|
157
|
{
|
158
|
float width = act.getScreenWidthInPixels();
|
159
|
setupMenuWindow(act,width);
|
160
|
}
|
161
|
|
162
|
if( act.getControl().isUINotBlocked())
|
163
|
{
|
164
|
View popupView = mMenuPopup.getContentView();
|
165
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
166
|
setupLevelButtonVisibilityAndColor(act);
|
167
|
displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-mMenuLayoutWidth/2 + width/6),0);
|
168
|
}
|
169
|
}
|
170
|
});
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
private void setupObjectWindow(final RubikActivity act, final float width, final float height)
|
176
|
{
|
177
|
int numObjects = RubikObjectList.getNumObjects();
|
178
|
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
|
179
|
mColCount = NUM_COLUMNS;
|
180
|
|
181
|
int cubeSize = (int)(width/9);
|
182
|
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
183
|
int padding = (int)(width*RubikActivity.POPUP_PADDING);
|
184
|
mObjectSize = (int)(cubeSize + 2*margin + 0.5f);
|
185
|
mMaxRowCount = (int)((height-1.8f*mUpperBarHeight)/mObjectSize);
|
186
|
|
187
|
LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null);
|
188
|
GridLayout objectGrid = view.findViewById(R.id.objectGrid);
|
189
|
RelativeLayout bottomLayout = view.findViewById(R.id.bottomLayout);
|
190
|
setupBottomLayout(act,bottomLayout);
|
191
|
|
192
|
PopupCreator.createObjectGrid(objectGrid,act,mRowCount,mColCount,numObjects,margin,cubeSize,padding);
|
193
|
|
194
|
for(int child=0; child<numObjects; child++)
|
195
|
{
|
196
|
final RubikObject obj = RubikObjectList.getObject(child);
|
197
|
View v = objectGrid.getChildAt(child);
|
198
|
ImageButton button = PopupCreator.getButton(obj,v);
|
199
|
final int ordinal = child;
|
200
|
|
201
|
button.setOnClickListener( new View.OnClickListener()
|
202
|
{
|
203
|
@Override
|
204
|
public void onClick(View v)
|
205
|
{
|
206
|
if( obj!=null && act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()==ScreenList.PLAY )
|
207
|
{
|
208
|
if( obj.isFree() )
|
209
|
{
|
210
|
RubikObjectList.setCurrObject(ordinal);
|
211
|
act.changeObject(ordinal,true);
|
212
|
if( mMenuPopup!=null ) setupLevelButtonVisibilityAndColor(act);
|
213
|
mMovesController.clearMoves(act);
|
214
|
}
|
215
|
else
|
216
|
{
|
217
|
act.switchToPurchase(ordinal);
|
218
|
}
|
219
|
}
|
220
|
|
221
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
222
|
}
|
223
|
});
|
224
|
}
|
225
|
|
226
|
mObjectPopup = new PopupWindow(act);
|
227
|
mObjectPopup.setFocusable(true);
|
228
|
mObjectPopup.setContentView(view);
|
229
|
}
|
230
|
|
231
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232
|
|
233
|
private void setupBottomLayout(final RubikActivity act, final RelativeLayout layout)
|
234
|
{
|
235
|
int iconT = RubikActivity.getDrawable(R.drawable.ui_small_tutorial,R.drawable.ui_medium_tutorial, R.drawable.ui_big_tutorial, R.drawable.ui_huge_tutorial);
|
236
|
int iconD = RubikActivity.getDrawable(R.drawable.ui_small_download,R.drawable.ui_medium_download, R.drawable.ui_big_download, R.drawable.ui_huge_download);
|
237
|
int iconI = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info);
|
238
|
|
239
|
ImageButton buttonTut = layout.findViewById(R.id.buttonTut);
|
240
|
ImageButton buttonDow = layout.findViewById(R.id.buttonDow);
|
241
|
ImageButton buttonInf = layout.findViewById(R.id.buttonInf);
|
242
|
|
243
|
buttonTut.setImageResource(iconT);
|
244
|
buttonDow.setImageResource(iconD);
|
245
|
buttonInf.setImageResource(iconI);
|
246
|
|
247
|
TypedValue outValue = new TypedValue();
|
248
|
act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
|
249
|
buttonTut.setBackgroundResource(outValue.resourceId);
|
250
|
buttonDow.setBackgroundResource(outValue.resourceId);
|
251
|
buttonInf.setBackgroundResource(outValue.resourceId);
|
252
|
|
253
|
buttonTut.setOnClickListener( new View.OnClickListener()
|
254
|
{
|
255
|
@Override
|
256
|
public void onClick(View v)
|
257
|
{
|
258
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
259
|
RubikDialogTutorial tDiag = new RubikDialogTutorial();
|
260
|
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
|
261
|
}
|
262
|
});
|
263
|
|
264
|
buttonDow.setOnClickListener( new View.OnClickListener()
|
265
|
{
|
266
|
@Override
|
267
|
public void onClick(View v)
|
268
|
{
|
269
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
270
|
RubikDialogUpdates uDiag = new RubikDialogUpdates();
|
271
|
uDiag.show( act.getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() );
|
272
|
}
|
273
|
});
|
274
|
|
275
|
buttonInf.setOnClickListener( new View.OnClickListener()
|
276
|
{
|
277
|
@Override
|
278
|
public void onClick(View v)
|
279
|
{
|
280
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
281
|
int currObject = RubikObjectList.getCurrObject();
|
282
|
act.switchConfig(currObject);
|
283
|
}
|
284
|
});
|
285
|
|
286
|
mBubbleUpdates = layout.findViewById(R.id.bubbleUpdates);
|
287
|
mBubbleUpdates.setVisibility(View.INVISIBLE);
|
288
|
|
289
|
RubikNetwork network = RubikNetwork.getInstance();
|
290
|
network.signUpForUpdates(this);
|
291
|
}
|
292
|
|
293
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
294
|
|
295
|
void setupSolveButton(final RubikActivity act)
|
296
|
{
|
297
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);
|
298
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
299
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
|
300
|
|
301
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
302
|
{
|
303
|
@Override
|
304
|
public void onClick(View v)
|
305
|
{
|
306
|
act.getControl().solveObject();
|
307
|
mMovesController.clearMoves(act);
|
308
|
}
|
309
|
});
|
310
|
}
|
311
|
|
312
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
313
|
|
314
|
private void setupScrambleButton(final RubikActivity act)
|
315
|
{
|
316
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble,R.drawable.ui_medium_cube_scramble, R.drawable.ui_big_cube_scramble, R.drawable.ui_huge_cube_scramble);
|
317
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
318
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
319
|
|
320
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
321
|
{
|
322
|
@Override
|
323
|
public void onClick(View v)
|
324
|
{
|
325
|
mShouldReactToEndOfScrambling = false;
|
326
|
act.getControl().fastScrambleObject(RubikObject.FAST_SCRAMBLES);
|
327
|
}
|
328
|
});
|
329
|
}
|
330
|
|
331
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
332
|
|
333
|
private void setupMenuWindow(final RubikActivity act, final float width)
|
334
|
{
|
335
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
336
|
final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
|
337
|
|
338
|
mMenuPopup = new PopupWindow(act);
|
339
|
mMenuPopup.setContentView(layout);
|
340
|
mMenuPopup.setFocusable(true);
|
341
|
int padding = (int)(width*RubikActivity.MEDIUM_MARGIN);
|
342
|
|
343
|
mMenuLayoutWidth = (int)(width*0.65f);
|
344
|
mMenuLayoutHeight= padding + NUM_BUTTONS*(mMenuButtonHeight+padding) + 4*mMenuButtonHeight+6*padding;
|
345
|
|
346
|
layout.setPadding(padding,0,padding,0);
|
347
|
|
348
|
Button highScores = layout.findViewById(R.id.menuHighScores);
|
349
|
highScores.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
350
|
highScores.setOnClickListener( new View.OnClickListener()
|
351
|
{
|
352
|
@Override
|
353
|
public void onClick(View v)
|
354
|
{
|
355
|
mMenuPopup.dismiss();
|
356
|
Bundle sBundle = new Bundle();
|
357
|
int currObject = RubikObjectList.getCurrObject();
|
358
|
sBundle.putInt("tab", currObject );
|
359
|
sBundle.putBoolean("submitting", false);
|
360
|
RubikDialogScores scores = new RubikDialogScores();
|
361
|
scores.setArguments(sBundle);
|
362
|
scores.show(act.getSupportFragmentManager(), null);
|
363
|
}
|
364
|
});
|
365
|
|
366
|
Button prettyPatterns = layout.findViewById(R.id.menuPrettyPatterns);
|
367
|
prettyPatterns.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
368
|
prettyPatterns.setOnClickListener( new View.OnClickListener()
|
369
|
{
|
370
|
@Override
|
371
|
public void onClick(View v)
|
372
|
{
|
373
|
mMenuPopup.dismiss();
|
374
|
RubikDialogPattern pDiag = new RubikDialogPattern();
|
375
|
pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
|
376
|
}
|
377
|
});
|
378
|
|
379
|
Button solver = layout.findViewById(R.id.menuSolver);
|
380
|
solver.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
381
|
solver.setOnClickListener( new View.OnClickListener()
|
382
|
{
|
383
|
@Override
|
384
|
public void onClick(View v)
|
385
|
{
|
386
|
mMenuPopup.dismiss();
|
387
|
ScreenList.switchScreen(act, ScreenList.SVER);
|
388
|
}
|
389
|
});
|
390
|
|
391
|
Button tutorials = layout.findViewById(R.id.menuTutorials);
|
392
|
tutorials.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
393
|
tutorials.setOnClickListener( new View.OnClickListener()
|
394
|
{
|
395
|
@Override
|
396
|
public void onClick(View v)
|
397
|
{
|
398
|
mMenuPopup.dismiss();
|
399
|
RubikDialogTutorial tDiag = new RubikDialogTutorial();
|
400
|
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
|
401
|
}
|
402
|
});
|
403
|
|
404
|
Button bandaged = layout.findViewById(R.id.menuBandaged);
|
405
|
bandaged.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
406
|
bandaged.setOnClickListener( new View.OnClickListener()
|
407
|
{
|
408
|
@Override
|
409
|
public void onClick(View v)
|
410
|
{
|
411
|
mMenuPopup.dismiss();
|
412
|
act.switchToBandagedCreator();
|
413
|
}
|
414
|
});
|
415
|
|
416
|
Button about = layout.findViewById(R.id.menuAbout);
|
417
|
about.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
418
|
about.setOnClickListener( new View.OnClickListener()
|
419
|
{
|
420
|
@Override
|
421
|
public void onClick(View v)
|
422
|
{
|
423
|
mMenuPopup.dismiss();
|
424
|
RubikDialogAbout aDiag = new RubikDialogAbout();
|
425
|
aDiag.show(act.getSupportFragmentManager(), null);
|
426
|
}
|
427
|
});
|
428
|
|
429
|
TextView levels = layout.findViewById(R.id.menuLevels);
|
430
|
levels.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
431
|
|
432
|
setupLevelButtons(act,layout,padding);
|
433
|
}
|
434
|
|
435
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
436
|
|
437
|
private void setupLevelButtons(RubikActivity act, View layout, int padding)
|
438
|
{
|
439
|
int sizeW = (mMenuLayoutWidth-4*padding)/3;
|
440
|
int sizeH = (int)(sizeW*0.8f);
|
441
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(sizeW,sizeH);
|
442
|
params.setMargins(padding/2,0,padding/2,0);
|
443
|
|
444
|
mLevel = new Button[LEVELS_SHOWN+1];
|
445
|
|
446
|
mLevel[0] = layout.findViewById(R.id.level1);
|
447
|
mLevel[1] = layout.findViewById(R.id.level2);
|
448
|
mLevel[2] = layout.findViewById(R.id.level3);
|
449
|
mLevel[3] = layout.findViewById(R.id.level4);
|
450
|
mLevel[4] = layout.findViewById(R.id.level5);
|
451
|
mLevel[5] = layout.findViewById(R.id.level6);
|
452
|
mLevel[6] = layout.findViewById(R.id.level7);
|
453
|
mLevel[7] = layout.findViewById(R.id.level8);
|
454
|
mLevel[8] = layout.findViewById(R.id.levelM);
|
455
|
|
456
|
for(int i=0; i<=LEVELS_SHOWN; i++)
|
457
|
{
|
458
|
final int ii = i;
|
459
|
mLevel[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
460
|
mLevel[i].setLayoutParams(params);
|
461
|
mLevel[i].setOnClickListener( new View.OnClickListener()
|
462
|
{
|
463
|
@Override
|
464
|
public void onClick(View v)
|
465
|
{
|
466
|
ObjectControl control = act.getControl();
|
467
|
|
468
|
if(control.isUINotBlocked())
|
469
|
{
|
470
|
if( mMenuPopup!=null ) mMenuPopup.dismiss();
|
471
|
|
472
|
int currObject = RubikObjectList.getCurrObject();
|
473
|
RubikObject object = RubikObjectList.getObject(currObject);
|
474
|
final int scrambles = ii<LEVELS_SHOWN ? ii+1 : (object==null ? 0 : object.getNumScramble());
|
475
|
mLevelValue = ii+1;
|
476
|
mShouldReactToEndOfScrambling = true;
|
477
|
control.scrambleObject(scrambles);
|
478
|
}
|
479
|
}
|
480
|
});
|
481
|
}
|
482
|
}
|
483
|
|
484
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
485
|
|
486
|
private void setupLevelButtonVisibilityAndColor(RubikActivity act)
|
487
|
{
|
488
|
int currObject = RubikObjectList.getCurrObject();
|
489
|
RubikObject object = RubikObjectList.getObject(currObject);
|
490
|
int numScramble = object==null ? 1 : object.getNumScramble();
|
491
|
RubikScores scores = RubikScores.getInstance();
|
492
|
Resources res = act.getResources();
|
493
|
ColorStateList colorG = ColorStateList.valueOf(res.getColor(R.color.green));
|
494
|
ColorStateList colorD = ColorStateList.valueOf(res.getColor(R.color.dark_grey));
|
495
|
|
496
|
for(int level=0; level<=LEVELS_SHOWN; level++)
|
497
|
{
|
498
|
boolean isSolved = scores.isSolved(currObject,level);
|
499
|
mLevel[level].setBackgroundTintList( isSolved ? colorG : colorD);
|
500
|
}
|
501
|
|
502
|
if( numScramble<=LEVELS_SHOWN || mOldNumScramble<=LEVELS_SHOWN )
|
503
|
{
|
504
|
if( numScramble<mOldNumScramble )
|
505
|
{
|
506
|
int max = Math.min(LEVELS_SHOWN,mOldNumScramble-1);
|
507
|
for(int level=numScramble; level<=max; level++) mLevel[level].setVisibility(View.INVISIBLE);
|
508
|
mLevel[numScramble-1].setText(R.string.levelM);
|
509
|
}
|
510
|
if( numScramble>mOldNumScramble )
|
511
|
{
|
512
|
int max = Math.min(LEVELS_SHOWN,numScramble-1);
|
513
|
mLevel[mOldNumScramble-1].setText( String.valueOf(mOldNumScramble) );
|
514
|
|
515
|
for(int level=mOldNumScramble; level<=max; level++)
|
516
|
{
|
517
|
mLevel[level].setVisibility(View.VISIBLE);
|
518
|
if( level<max ) mLevel[level].setText( String.valueOf(level+1) );
|
519
|
else mLevel[level].setText( R.string.levelM );
|
520
|
}
|
521
|
}
|
522
|
}
|
523
|
|
524
|
mOldNumScramble = numScramble;
|
525
|
}
|
526
|
|
527
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
528
|
// This is necessary! Otherwise the ObjectPopup will not be re-created next time and we will still
|
529
|
// hold a reference to the old instance of the RubikActivity class (because setupObjectWindow is not
|
530
|
// going to be called)
|
531
|
// An reference to the old instance of RubikActivity will cause all sorts of strange issues.
|
532
|
|
533
|
public void savePreferences(SharedPreferences.Editor editor)
|
534
|
{
|
535
|
editor.putInt("play_LevelValue", mLevelValue );
|
536
|
|
537
|
if( mObjectPopup!=null )
|
538
|
{
|
539
|
mObjectPopup.dismiss();
|
540
|
mObjectPopup = null;
|
541
|
}
|
542
|
|
543
|
if( mMenuPopup!=null )
|
544
|
{
|
545
|
mMenuPopup.dismiss();
|
546
|
mMenuPopup = null;
|
547
|
}
|
548
|
}
|
549
|
|
550
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
551
|
|
552
|
public void restorePreferences(SharedPreferences preferences)
|
553
|
{
|
554
|
mLevelValue = preferences.getInt("play_LevelValue", 0);
|
555
|
}
|
556
|
|
557
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
558
|
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes
|
559
|
|
560
|
private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff)
|
561
|
{
|
562
|
View topLayout = act.findViewById(R.id.relativeLayout);
|
563
|
boolean isFullScreen;
|
564
|
|
565
|
if( topLayout!=null )
|
566
|
{
|
567
|
topLayout.getLocationOnScreen(mLocation);
|
568
|
isFullScreen = (mLocation[1]==0);
|
569
|
}
|
570
|
else
|
571
|
{
|
572
|
isFullScreen = true;
|
573
|
}
|
574
|
|
575
|
try
|
576
|
{
|
577
|
// if on Android 11 or we are fullscreen
|
578
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || isFullScreen )
|
579
|
{
|
580
|
window.showAsDropDown(view, xoff, yoff, Gravity.CENTER);
|
581
|
window.update(view, w, h);
|
582
|
}
|
583
|
else // Android 10 or below in pop-up mode or split-screen mode
|
584
|
{
|
585
|
view.getLocationOnScreen(mLocation);
|
586
|
int width = view.getWidth();
|
587
|
int height = view.getHeight();
|
588
|
int x = mLocation[0]+(width-w)/2;
|
589
|
int y = mLocation[1]+height+yoff;
|
590
|
|
591
|
window.showAsDropDown(view);
|
592
|
window.update(x,y,w,h);
|
593
|
}
|
594
|
}
|
595
|
catch( IllegalArgumentException iae )
|
596
|
{
|
597
|
// ignore, this means window is 'not attached to window manager' -
|
598
|
// which most probably is because we are already exiting the app.
|
599
|
}
|
600
|
}
|
601
|
|
602
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
603
|
|
604
|
public int getLevel()
|
605
|
{
|
606
|
return mLevelValue;
|
607
|
}
|
608
|
|
609
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
610
|
|
611
|
public void recreatePopup()
|
612
|
{
|
613
|
mObjectPopup = null;
|
614
|
}
|
615
|
|
616
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
617
|
|
618
|
public boolean shouldReactToEndOfScrambling()
|
619
|
{
|
620
|
return mShouldReactToEndOfScrambling;
|
621
|
}
|
622
|
|
623
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
624
|
|
625
|
public void receiveUpdate(RubikUpdates updates)
|
626
|
{
|
627
|
Activity act = mWeakAct.get();
|
628
|
|
629
|
if( act!=null )
|
630
|
{
|
631
|
act.runOnUiThread(new Runnable()
|
632
|
{
|
633
|
@Override
|
634
|
public void run()
|
635
|
{
|
636
|
int num = updates.getCompletedNumber();
|
637
|
|
638
|
if( num>0 )
|
639
|
{
|
640
|
String shownNum = String.valueOf(num);
|
641
|
mBubbleUpdates.setText(shownNum);
|
642
|
mBubbleUpdates.setVisibility(View.VISIBLE);
|
643
|
int height = (int)(0.05f*mScreenWidth);
|
644
|
mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height);
|
645
|
}
|
646
|
else
|
647
|
{
|
648
|
mBubbleUpdates.setVisibility(View.INVISIBLE);
|
649
|
}
|
650
|
}
|
651
|
});
|
652
|
}
|
653
|
}
|
654
|
|
655
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
656
|
|
657
|
public void errorUpdate()
|
658
|
{
|
659
|
android.util.Log.e("D", "Screen: Error receiving update");
|
660
|
}
|
661
|
}
|