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