1 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// 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 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// 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 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
fcd5b990
|
Leszek Koltunski
|
package org.distorted.screens;
|
21 |
211b48f2
|
Leszek Koltunski
|
|
22 |
4c0cd600
|
Leszek Koltunski
|
import android.content.Context;
|
23 |
211b48f2
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
24 |
b600ccd9
|
Leszek Koltunski
|
import android.content.res.Resources;
|
25 |
4c0cd600
|
Leszek Koltunski
|
import android.graphics.drawable.BitmapDrawable;
|
26 |
255492a0
|
Leszek Koltunski
|
import android.os.Build;
|
27 |
e03e0352
|
Leszek Koltunski
|
import android.os.Bundle;
|
28 |
e3c74c0f
|
Leszek Koltunski
|
import android.util.TypedValue;
|
29 |
255492a0
|
Leszek Koltunski
|
import android.view.Gravity;
|
30 |
211b48f2
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
31 |
|
|
import android.view.View;
|
32 |
|
|
import android.widget.Button;
|
33 |
e07c48a2
|
Leszek Koltunski
|
import android.widget.GridLayout;
|
34 |
211b48f2
|
Leszek Koltunski
|
import android.widget.ImageButton;
|
35 |
|
|
import android.widget.LinearLayout;
|
36 |
4c0cd600
|
Leszek Koltunski
|
import android.widget.PopupWindow;
|
37 |
211b48f2
|
Leszek Koltunski
|
|
38 |
2afc6754
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectControl;
|
39 |
3f7a4363
|
Leszek Koltunski
|
|
40 |
|
|
import org.distorted.main.R;
|
41 |
|
|
import org.distorted.main.RubikActivity;
|
42 |
e03e0352
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogAbout;
|
43 |
a8576d91
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogPattern;
|
44 |
e03e0352
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogScores;
|
45 |
234a7582
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogTutorial;
|
46 |
55e6be1d
|
Leszek Koltunski
|
import org.distorted.helpers.TransparentButton;
|
47 |
|
|
import org.distorted.helpers.TransparentImageButton;
|
48 |
6a083c6a
|
Leszek Koltunski
|
import org.distorted.network.RubikScores;
|
49 |
d433b50e
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
50 |
|
|
import org.distorted.objects.RubikObjectList;
|
51 |
211b48f2
|
Leszek Koltunski
|
|
52 |
b600ccd9
|
Leszek Koltunski
|
import static android.view.View.inflate;
|
53 |
88d28110
|
Leszek Koltunski
|
|
54 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
fcd5b990
|
Leszek Koltunski
|
public class RubikScreenPlay extends RubikScreenBase
|
57 |
211b48f2
|
Leszek Koltunski
|
{
|
58 |
6e3fcb91
|
Leszek Koltunski
|
public static final int NUM_COLUMNS = 5;
|
59 |
00af5060
|
Leszek Koltunski
|
public static final int LEVELS_SHOWN = 10;
|
60 |
211b48f2
|
Leszek Koltunski
|
|
61 |
7cf2637d
|
Leszek Koltunski
|
private static final int[] BUTTON_LABELS = { R.string.scores,
|
62 |
|
|
R.string.patterns,
|
63 |
|
|
R.string.solver,
|
64 |
|
|
R.string.tutorials,
|
65 |
|
|
R.string.about };
|
66 |
|
|
|
67 |
e03e0352
|
Leszek Koltunski
|
private static final int NUM_BUTTONS = BUTTON_LABELS.length;
|
68 |
de62316a
|
Leszek Koltunski
|
private static final float LAST_BUTTON = 1.5f;
|
69 |
dc78f395
|
Leszek Koltunski
|
private static final int[] mLocation = new int[2];
|
70 |
e03e0352
|
Leszek Koltunski
|
|
71 |
0873a75a
|
Leszek Koltunski
|
private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton;
|
72 |
033100af
|
Leszek Koltunski
|
private TransparentButton mPlayButton;
|
73 |
0254cfd7
|
Leszek Koltunski
|
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
|
74 |
400ff34d
|
Leszek Koltunski
|
private LinearLayout mPlayLayout;
|
75 |
0254cfd7
|
Leszek Koltunski
|
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
|
76 |
85b09df4
|
Leszek Koltunski
|
private int mLevelValue;
|
77 |
e07c48a2
|
Leszek Koltunski
|
private float mButtonSize, mMenuItemSize, mMenuTextSize;
|
78 |
598de3ee
|
Leszek Koltunski
|
private int mColCount, mRowCount, mMaxRowCount;
|
79 |
255492a0
|
Leszek Koltunski
|
private int mUpperBarHeight;
|
80 |
dd874ae8
|
Leszek Koltunski
|
private boolean mShouldReactToEndOfScrambling;
|
81 |
6e3fcb91
|
Leszek Koltunski
|
private int mBottomHeight;
|
82 |
255492a0
|
Leszek Koltunski
|
|
83 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
f5da732a
|
Leszek Koltunski
|
void leaveScreen(RubikActivity act)
|
86 |
211b48f2
|
Leszek Koltunski
|
{
|
87 |
85b09df4
|
Leszek Koltunski
|
|
88 |
211b48f2
|
Leszek Koltunski
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
f5da732a
|
Leszek Koltunski
|
void enterScreen(final RubikActivity act)
|
93 |
211b48f2
|
Leszek Koltunski
|
{
|
94 |
d433b50e
|
Leszek Koltunski
|
int numObjects = RubikObjectList.getNumObjects();
|
95 |
e3c74c0f
|
Leszek Koltunski
|
float width = act.getScreenWidthInPixels();
|
96 |
255492a0
|
Leszek Koltunski
|
mUpperBarHeight = act.getHeightUpperBar();
|
97 |
a8576d91
|
Leszek Koltunski
|
|
98 |
eb376d3a
|
Leszek Koltunski
|
mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE;
|
99 |
88fb92ba
|
Leszek Koltunski
|
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
|
100 |
|
|
mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;
|
101 |
e3c74c0f
|
Leszek Koltunski
|
|
102 |
d433b50e
|
Leszek Koltunski
|
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
|
103 |
287e91a6
|
Leszek Koltunski
|
mColCount = NUM_COLUMNS;
|
104 |
e07c48a2
|
Leszek Koltunski
|
|
105 |
211b48f2
|
Leszek Koltunski
|
// TOP ////////////////////////////
|
106 |
7289fd6c
|
Leszek Koltunski
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
107 |
211b48f2
|
Leszek Koltunski
|
layoutTop.removeAllViews();
|
108 |
85b09df4
|
Leszek Koltunski
|
|
109 |
ad0c8e0e
|
Leszek Koltunski
|
setupObjectButton(act,width);
|
110 |
85b09df4
|
Leszek Koltunski
|
layoutTop.addView(mObjButton);
|
111 |
0254cfd7
|
Leszek Koltunski
|
|
112 |
|
|
setupMenuButton(act,width);
|
113 |
|
|
layoutTop.addView(mMenuButton);
|
114 |
|
|
|
115 |
2da68298
|
Leszek Koltunski
|
setupPlayButton(act,width);
|
116 |
85b09df4
|
Leszek Koltunski
|
layoutTop.addView(mPlayButton);
|
117 |
211b48f2
|
Leszek Koltunski
|
|
118 |
dd874ae8
|
Leszek Koltunski
|
setupSolveButton(act);
|
119 |
|
|
setupScrambleButton(act);
|
120 |
|
|
createBottomPane(act,mSolveButton,mScrambleButton);
|
121 |
769d7b9f
|
Leszek Koltunski
|
}
|
122 |
211b48f2
|
Leszek Koltunski
|
|
123 |
8ab435b9
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
124 |
4c0cd600
|
Leszek Koltunski
|
|
125 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupObjectButton(final RubikActivity act, final float width)
|
126 |
769d7b9f
|
Leszek Koltunski
|
{
|
127 |
e07c48a2
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
128 |
6e3fcb91
|
Leszek Koltunski
|
final int lMargin = (int)(width*RubikActivity.LARGE_MARGIN);
|
129 |
e07c48a2
|
Leszek Koltunski
|
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);
|
130 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
131 |
|
|
mObjButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
132 |
769d7b9f
|
Leszek Koltunski
|
|
133 |
|
|
mObjButton.setOnClickListener( new View.OnClickListener()
|
134 |
|
|
{
|
135 |
|
|
@Override
|
136 |
|
|
public void onClick(View view)
|
137 |
4c0cd600
|
Leszek Koltunski
|
{
|
138 |
2da68298
|
Leszek Koltunski
|
if( mObjectPopup==null )
|
139 |
|
|
{
|
140 |
|
|
float width = act.getScreenWidthInPixels();
|
141 |
|
|
float height= act.getScreenHeightInPixels();
|
142 |
|
|
setupObjectWindow(act,width,height);
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
if( act.getControl().isUINotBlocked())
|
146 |
a42e25a6
|
Leszek Koltunski
|
{
|
147 |
598de3ee
|
Leszek Koltunski
|
int rowCount = Math.min(mMaxRowCount,mRowCount);
|
148 |
c5b4af4a
|
Leszek Koltunski
|
View popupView = mObjectPopup.getContentView();
|
149 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
150 |
6e3fcb91
|
Leszek Koltunski
|
displayPopup(act,view,mObjectPopup,mObjectSize*mColCount,mObjectSize*rowCount+mBottomHeight+2*lMargin,margin,margin);
|
151 |
c5b4af4a
|
Leszek Koltunski
|
}
|
152 |
769d7b9f
|
Leszek Koltunski
|
}
|
153 |
|
|
});
|
154 |
|
|
}
|
155 |
4c0cd600
|
Leszek Koltunski
|
|
156 |
85b09df4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157 |
|
|
|
158 |
2da68298
|
Leszek Koltunski
|
private void setupPlayButton(final RubikActivity act, final float width)
|
159 |
85b09df4
|
Leszek Koltunski
|
{
|
160 |
2da68298
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
161 |
d90c55cc
|
Leszek Koltunski
|
|
162 |
033100af
|
Leszek Koltunski
|
mPlayButton = new TransparentButton(act, R.string.play, mButtonSize);
|
163 |
85b09df4
|
Leszek Koltunski
|
|
164 |
|
|
mPlayButton.setOnClickListener( new View.OnClickListener()
|
165 |
|
|
{
|
166 |
|
|
@Override
|
167 |
0254cfd7
|
Leszek Koltunski
|
public void onClick(View view)
|
168 |
85b09df4
|
Leszek Koltunski
|
{
|
169 |
2da68298
|
Leszek Koltunski
|
if( mPlayPopup==null )
|
170 |
|
|
{
|
171 |
|
|
float width = act.getScreenWidthInPixels();
|
172 |
|
|
setupPlayWindow(act,width);
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
if( act.getControl().isUINotBlocked())
|
176 |
6e194411
|
Leszek Koltunski
|
{
|
177 |
d38a302b
|
Leszek Koltunski
|
adjustSolvedIcons();
|
178 |
2da68298
|
Leszek Koltunski
|
float height= act.getScreenHeightInPixels();
|
179 |
|
|
final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) );
|
180 |
c5b4af4a
|
Leszek Koltunski
|
View popupView = mPlayPopup.getContentView();
|
181 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
182 |
400ff34d
|
Leszek Koltunski
|
final int object = RubikObjectList.getCurrObject();
|
183 |
|
|
final int dbLevel = RubikObjectList.getDBLevel(object);
|
184 |
0a7aa15b
|
Leszek Koltunski
|
final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN);
|
185 |
d90c55cc
|
Leszek Koltunski
|
final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f));
|
186 |
255492a0
|
Leszek Koltunski
|
final int realHeight = Math.min(popupHeight,maxHeight);
|
187 |
|
|
displayPopup(act,view,mPlayPopup,mPlayLayoutWidth,realHeight,margin,margin);
|
188 |
6fad862b
|
Leszek Koltunski
|
}
|
189 |
85b09df4
|
Leszek Koltunski
|
}
|
190 |
|
|
});
|
191 |
|
|
}
|
192 |
|
|
|
193 |
e31abc1e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194 |
|
|
|
195 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupMenuButton(final RubikActivity act, final float width)
|
196 |
e31abc1e
|
Leszek Koltunski
|
{
|
197 |
2da68298
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
198 |
0254cfd7
|
Leszek Koltunski
|
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);
|
199 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
200 |
|
|
mMenuButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
201 |
e31abc1e
|
Leszek Koltunski
|
|
202 |
e03e0352
|
Leszek Koltunski
|
mMenuButton.setOnClickListener( new View.OnClickListener()
|
203 |
e31abc1e
|
Leszek Koltunski
|
{
|
204 |
|
|
@Override
|
205 |
|
|
public void onClick(View view)
|
206 |
|
|
{
|
207 |
2da68298
|
Leszek Koltunski
|
if( mMenuPopup==null )
|
208 |
|
|
{
|
209 |
|
|
float width = act.getScreenWidthInPixels();
|
210 |
|
|
setupMenuWindow(act,width);
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
if( act.getControl().isUINotBlocked())
|
214 |
e03e0352
|
Leszek Koltunski
|
{
|
215 |
c5b4af4a
|
Leszek Koltunski
|
View popupView = mMenuPopup.getContentView();
|
216 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
217 |
255492a0
|
Leszek Koltunski
|
displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-width/12),margin);
|
218 |
6fad862b
|
Leszek Koltunski
|
}
|
219 |
e31abc1e
|
Leszek Koltunski
|
}
|
220 |
|
|
});
|
221 |
|
|
}
|
222 |
|
|
|
223 |
4c0cd600
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
224 |
|
|
|
225 |
598de3ee
|
Leszek Koltunski
|
private void setupObjectWindow(final RubikActivity act, final float width, final float height)
|
226 |
4c0cd600
|
Leszek Koltunski
|
{
|
227 |
6e3fcb91
|
Leszek Koltunski
|
int cubeWidth = (int)(width/9);
|
228 |
598de3ee
|
Leszek Koltunski
|
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
229 |
|
|
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
|
230 |
0b162619
|
Leszek Koltunski
|
mMaxRowCount = (int)((height-1.8f*mUpperBarHeight)/mObjectSize);
|
231 |
598de3ee
|
Leszek Koltunski
|
|
232 |
8d1da3f1
|
Leszek Koltunski
|
LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null);
|
233 |
b600ccd9
|
Leszek Koltunski
|
GridLayout objectGrid = view.findViewById(R.id.objectGrid);
|
234 |
e07c48a2
|
Leszek Koltunski
|
|
235 |
|
|
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
|
236 |
|
|
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
|
237 |
|
|
|
238 |
92843d3b
|
Leszek Koltunski
|
objectGrid.setColumnCount(mColCount);
|
239 |
|
|
objectGrid.setRowCount(mRowCount);
|
240 |
e07c48a2
|
Leszek Koltunski
|
|
241 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout bottomLayout = view.findViewById(R.id.bottomLayout);
|
242 |
6e3fcb91
|
Leszek Koltunski
|
setupBottomLayout(act,bottomLayout,(NUM_COLUMNS-2)*mObjectSize);
|
243 |
0b162619
|
Leszek Koltunski
|
|
244 |
b600ccd9
|
Leszek Koltunski
|
mObjectPopup = new PopupWindow(act);
|
245 |
|
|
mObjectPopup.setFocusable(true);
|
246 |
|
|
mObjectPopup.setContentView(view);
|
247 |
|
|
|
248 |
0501a4b8
|
Leszek Koltunski
|
int[] nextInRow = new int[mRowCount];
|
249 |
fa679111
|
Leszek Koltunski
|
|
250 |
e07c48a2
|
Leszek Koltunski
|
for(int row=0; row<mRowCount; row++)
|
251 |
|
|
{
|
252 |
|
|
rowSpecs[row] = GridLayout.spec(row);
|
253 |
0501a4b8
|
Leszek Koltunski
|
nextInRow[row]= 0;
|
254 |
e07c48a2
|
Leszek Koltunski
|
}
|
255 |
|
|
for(int col=0; col<mColCount; col++)
|
256 |
|
|
{
|
257 |
|
|
colSpecs[col] = GridLayout.spec(col);
|
258 |
|
|
}
|
259 |
769d7b9f
|
Leszek Koltunski
|
|
260 |
d433b50e
|
Leszek Koltunski
|
int numObjects = RubikObjectList.getNumObjects();
|
261 |
|
|
|
262 |
|
|
for(int object=0; object<numObjects; object++)
|
263 |
769d7b9f
|
Leszek Koltunski
|
{
|
264 |
d433b50e
|
Leszek Koltunski
|
final RubikObject robject = RubikObjectList.getObject(object);
|
265 |
6e3fcb91
|
Leszek Koltunski
|
int icons = robject==null ? 0 : robject.getIconID();
|
266 |
287e91a6
|
Leszek Koltunski
|
int row = object/NUM_COLUMNS;
|
267 |
400ff34d
|
Leszek Koltunski
|
final int ordinal = robject==null ? 0 : robject.getOrdinal();
|
268 |
769d7b9f
|
Leszek Koltunski
|
|
269 |
7ac0ee88
|
Leszek Koltunski
|
ImageButton button = new ImageButton(act);
|
270 |
|
|
button.setBackgroundResource(icons);
|
271 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
272 |
769d7b9f
|
Leszek Koltunski
|
{
|
273 |
7ac0ee88
|
Leszek Koltunski
|
@Override
|
274 |
|
|
public void onClick(View v)
|
275 |
769d7b9f
|
Leszek Koltunski
|
{
|
276 |
2afc6754
|
Leszek Koltunski
|
if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
|
277 |
769d7b9f
|
Leszek Koltunski
|
{
|
278 |
400ff34d
|
Leszek Koltunski
|
RubikObjectList.setCurrObject(act,ordinal);
|
279 |
|
|
act.changeObject(ordinal,true);
|
280 |
4c9947bd
|
Leszek Koltunski
|
if( mPlayLayout!=null ) adjustLevels(act);
|
281 |
dd1a65c1
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
282 |
769d7b9f
|
Leszek Koltunski
|
}
|
283 |
|
|
|
284 |
7ac0ee88
|
Leszek Koltunski
|
mObjectPopup.dismiss();
|
285 |
|
|
}
|
286 |
|
|
});
|
287 |
e07c48a2
|
Leszek Koltunski
|
|
288 |
7ac0ee88
|
Leszek Koltunski
|
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
|
289 |
|
|
params.bottomMargin = margin;
|
290 |
|
|
params.topMargin = margin;
|
291 |
|
|
params.leftMargin = margin;
|
292 |
|
|
params.rightMargin = margin;
|
293 |
fa679111
|
Leszek Koltunski
|
|
294 |
6e3fcb91
|
Leszek Koltunski
|
params.width = cubeWidth;
|
295 |
|
|
params.height= cubeWidth;
|
296 |
|
|
|
297 |
7ac0ee88
|
Leszek Koltunski
|
nextInRow[row]++;
|
298 |
|
|
|
299 |
|
|
objectGrid.addView(button, params);
|
300 |
769d7b9f
|
Leszek Koltunski
|
}
|
301 |
4c0cd600
|
Leszek Koltunski
|
}
|
302 |
|
|
|
303 |
8d1da3f1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
304 |
|
|
|
305 |
d433b50e
|
Leszek Koltunski
|
private void setupBottomLayout(final RubikActivity act, final LinearLayout layout, int width)
|
306 |
8d1da3f1
|
Leszek Koltunski
|
{
|
307 |
|
|
int iconD = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info);
|
308 |
|
|
int iconT = RubikActivity.getDrawable(R.drawable.ui_small_tutorial,R.drawable.ui_medium_tutorial, R.drawable.ui_big_tutorial, R.drawable.ui_huge_tutorial);
|
309 |
|
|
|
310 |
|
|
ImageButton buttonTut = layout.findViewById(R.id.buttonTut);
|
311 |
|
|
Button buttonNul = layout.findViewById(R.id.buttonNul);
|
312 |
|
|
ImageButton buttonDet = layout.findViewById(R.id.buttonDet);
|
313 |
|
|
|
314 |
|
|
buttonTut.setImageResource(iconT);
|
315 |
|
|
buttonDet.setImageResource(iconD);
|
316 |
|
|
buttonNul.setVisibility(View.INVISIBLE);
|
317 |
|
|
|
318 |
|
|
buttonNul.setWidth(width);
|
319 |
|
|
|
320 |
6e3fcb91
|
Leszek Koltunski
|
Resources res = act.getResources();
|
321 |
|
|
BitmapDrawable bd = (BitmapDrawable)res.getDrawable(iconD);
|
322 |
|
|
mBottomHeight = bd.getIntrinsicHeight();
|
323 |
|
|
|
324 |
8d1da3f1
|
Leszek Koltunski
|
TypedValue outValue = new TypedValue();
|
325 |
|
|
act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
|
326 |
|
|
buttonTut.setBackgroundResource(outValue.resourceId);
|
327 |
|
|
buttonDet.setBackgroundResource(outValue.resourceId);
|
328 |
|
|
|
329 |
|
|
buttonTut.setOnClickListener( new View.OnClickListener()
|
330 |
|
|
{
|
331 |
|
|
@Override
|
332 |
|
|
public void onClick(View v)
|
333 |
|
|
{
|
334 |
|
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
335 |
|
|
RubikDialogTutorial tDiag = new RubikDialogTutorial();
|
336 |
|
|
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
|
337 |
|
|
}
|
338 |
|
|
});
|
339 |
|
|
|
340 |
|
|
buttonDet.setOnClickListener( new View.OnClickListener()
|
341 |
|
|
{
|
342 |
|
|
@Override
|
343 |
|
|
public void onClick(View v)
|
344 |
|
|
{
|
345 |
f12e4de9
|
Leszek Koltunski
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
346 |
400ff34d
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
347 |
|
|
act.switchConfig(currObject);
|
348 |
8d1da3f1
|
Leszek Koltunski
|
}
|
349 |
|
|
});
|
350 |
|
|
}
|
351 |
|
|
|
352 |
e03e0352
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
353 |
|
|
|
354 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupMenuWindow(final RubikActivity act, final float width)
|
355 |
e03e0352
|
Leszek Koltunski
|
{
|
356 |
|
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
357 |
e07c48a2
|
Leszek Koltunski
|
final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
|
358 |
|
|
LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
|
359 |
e03e0352
|
Leszek Koltunski
|
|
360 |
|
|
mMenuPopup = new PopupWindow(act);
|
361 |
|
|
mMenuPopup.setContentView(layout);
|
362 |
|
|
mMenuPopup.setFocusable(true);
|
363 |
ad0c8e0e
|
Leszek Koltunski
|
int margin = (int)(width*RubikActivity.MARGIN);
|
364 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
365 |
e03e0352
|
Leszek Koltunski
|
|
366 |
0254cfd7
|
Leszek Koltunski
|
mMenuLayoutWidth = (int)(width/2);
|
367 |
|
|
mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
|
368 |
|
|
|
369 |
43162dfb
|
Leszek Koltunski
|
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
370 |
e03e0352
|
Leszek Koltunski
|
|
371 |
|
|
for(int i=0; i<NUM_BUTTONS; i++)
|
372 |
|
|
{
|
373 |
|
|
final int but = i;
|
374 |
|
|
Button button = new Button(act);
|
375 |
43162dfb
|
Leszek Koltunski
|
button.setLayoutParams(p);
|
376 |
e03e0352
|
Leszek Koltunski
|
button.setText(BUTTON_LABELS[i]);
|
377 |
88fb92ba
|
Leszek Koltunski
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
378 |
e03e0352
|
Leszek Koltunski
|
|
379 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
380 |
|
|
{
|
381 |
|
|
@Override
|
382 |
|
|
public void onClick(View v)
|
383 |
|
|
{
|
384 |
|
|
mMenuPopup.dismiss();
|
385 |
0254cfd7
|
Leszek Koltunski
|
MenuAction(act,but);
|
386 |
e03e0352
|
Leszek Koltunski
|
}
|
387 |
|
|
});
|
388 |
|
|
|
389 |
e07c48a2
|
Leszek Koltunski
|
menuLayout.addView(button);
|
390 |
e03e0352
|
Leszek Koltunski
|
}
|
391 |
0254cfd7
|
Leszek Koltunski
|
}
|
392 |
e03e0352
|
Leszek Koltunski
|
|
393 |
0254cfd7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
394 |
|
|
|
395 |
|
|
private void setupPlayWindow(final RubikActivity act, final float width)
|
396 |
|
|
{
|
397 |
|
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
398 |
|
|
final View layout = layoutInflater.inflate(R.layout.popup_play, null);
|
399 |
|
|
mPlayLayout = layout.findViewById(R.id.playGrid);
|
400 |
|
|
|
401 |
|
|
mPlayLayoutWidth = (int)(width*0.4f);
|
402 |
|
|
|
403 |
|
|
mPlayPopup = new PopupWindow(act);
|
404 |
|
|
mPlayPopup.setContentView(layout);
|
405 |
|
|
mPlayPopup.setFocusable(true);
|
406 |
|
|
|
407 |
|
|
adjustLevels(act);
|
408 |
e03e0352
|
Leszek Koltunski
|
}
|
409 |
|
|
|
410 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
411 |
|
|
|
412 |
0254cfd7
|
Leszek Koltunski
|
private void MenuAction(RubikActivity act, int button)
|
413 |
e03e0352
|
Leszek Koltunski
|
{
|
414 |
|
|
switch(button)
|
415 |
|
|
{
|
416 |
8ab435b9
|
Leszek Koltunski
|
case 0: Bundle sBundle = new Bundle();
|
417 |
400ff34d
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
418 |
|
|
sBundle.putInt("tab", currObject );
|
419 |
a8576d91
|
Leszek Koltunski
|
sBundle.putBoolean("submitting", false);
|
420 |
e03e0352
|
Leszek Koltunski
|
RubikDialogScores scores = new RubikDialogScores();
|
421 |
a8576d91
|
Leszek Koltunski
|
scores.setArguments(sBundle);
|
422 |
e03e0352
|
Leszek Koltunski
|
scores.show(act.getSupportFragmentManager(), null);
|
423 |
|
|
break;
|
424 |
234a7582
|
Leszek Koltunski
|
case 1: RubikDialogPattern pDiag = new RubikDialogPattern();
|
425 |
|
|
pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
|
426 |
e03e0352
|
Leszek Koltunski
|
break;
|
427 |
b2a92941
|
Leszek Koltunski
|
case 2: ScreenList.switchScreen(act, ScreenList.SVER);
|
428 |
e03e0352
|
Leszek Koltunski
|
break;
|
429 |
b2a92941
|
Leszek Koltunski
|
case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial();
|
430 |
234a7582
|
Leszek Koltunski
|
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
|
431 |
2971588c
|
Leszek Koltunski
|
break;
|
432 |
b2a92941
|
Leszek Koltunski
|
case 4: RubikDialogAbout aDiag = new RubikDialogAbout();
|
433 |
a8576d91
|
Leszek Koltunski
|
aDiag.show(act.getSupportFragmentManager(), null);
|
434 |
e03e0352
|
Leszek Koltunski
|
break;
|
435 |
|
|
}
|
436 |
|
|
}
|
437 |
|
|
|
438 |
46405bb4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
439 |
|
|
|
440 |
dd874ae8
|
Leszek Koltunski
|
void setupSolveButton(final RubikActivity act)
|
441 |
46405bb4
|
Leszek Koltunski
|
{
|
442 |
dd874ae8
|
Leszek Koltunski
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve_new,R.drawable.ui_medium_cube_solve_new, R.drawable.ui_big_cube_solve_new, R.drawable.ui_huge_cube_solve_new);
|
443 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
444 |
|
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_END,params);
|
445 |
46405bb4
|
Leszek Koltunski
|
|
446 |
a8576d91
|
Leszek Koltunski
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
447 |
46405bb4
|
Leszek Koltunski
|
{
|
448 |
a8576d91
|
Leszek Koltunski
|
@Override
|
449 |
|
|
public void onClick(View v)
|
450 |
|
|
{
|
451 |
2afc6754
|
Leszek Koltunski
|
act.getControl().solveObject();
|
452 |
dd1a65c1
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
453 |
a8576d91
|
Leszek Koltunski
|
}
|
454 |
|
|
});
|
455 |
46405bb4
|
Leszek Koltunski
|
}
|
456 |
|
|
|
457 |
dd874ae8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
458 |
|
|
|
459 |
|
|
private void setupScrambleButton(final RubikActivity act)
|
460 |
|
|
{
|
461 |
|
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble_new,R.drawable.ui_medium_cube_scramble_new, R.drawable.ui_big_cube_scramble_new, R.drawable.ui_huge_cube_scramble_new);
|
462 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
463 |
|
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_START, params);
|
464 |
dd874ae8
|
Leszek Koltunski
|
|
465 |
|
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
466 |
|
|
{
|
467 |
|
|
@Override
|
468 |
|
|
public void onClick(View v)
|
469 |
|
|
{
|
470 |
400ff34d
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
471 |
|
|
RubikObject object = RubikObjectList.getObject(currObject);
|
472 |
d433b50e
|
Leszek Koltunski
|
int numScrambles = object==null ? 0 : object.getNumScramble();
|
473 |
dd874ae8
|
Leszek Koltunski
|
mShouldReactToEndOfScrambling = false;
|
474 |
|
|
act.getControl().scrambleObject(numScrambles);
|
475 |
|
|
}
|
476 |
|
|
});
|
477 |
|
|
}
|
478 |
|
|
|
479 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
480 |
3398a606
|
Leszek Koltunski
|
// This is necessary! Otherwise the ObjectPopup will not be re-created next time and we will still
|
481 |
|
|
// hold a reference to the old instance of the RubikActivity class (because setupObjectWindow is not
|
482 |
|
|
// going to be called)
|
483 |
|
|
// An reference to the old instance of RubikActivity will cause all sorts of strange issues.
|
484 |
211b48f2
|
Leszek Koltunski
|
|
485 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
486 |
|
|
{
|
487 |
d38a302b
|
Leszek Koltunski
|
editor.putInt("play_LevelValue", mLevelValue );
|
488 |
|
|
|
489 |
3398a606
|
Leszek Koltunski
|
if( mObjectPopup!=null )
|
490 |
|
|
{
|
491 |
|
|
mObjectPopup.dismiss();
|
492 |
|
|
mObjectPopup = null;
|
493 |
|
|
}
|
494 |
87d86e5f
|
Leszek Koltunski
|
|
495 |
3398a606
|
Leszek Koltunski
|
if( mMenuPopup!=null )
|
496 |
|
|
{
|
497 |
|
|
mMenuPopup.dismiss();
|
498 |
|
|
mMenuPopup = null;
|
499 |
|
|
}
|
500 |
|
|
|
501 |
|
|
if( mPlayPopup!=null )
|
502 |
|
|
{
|
503 |
|
|
mPlayPopup.dismiss();
|
504 |
|
|
mPlayPopup = null;
|
505 |
|
|
}
|
506 |
211b48f2
|
Leszek Koltunski
|
}
|
507 |
|
|
|
508 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
509 |
|
|
|
510 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
511 |
|
|
{
|
512 |
d38a302b
|
Leszek Koltunski
|
mLevelValue = preferences.getInt("play_LevelValue", 0);
|
513 |
211b48f2
|
Leszek Koltunski
|
}
|
514 |
|
|
|
515 |
53f23b64
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
516 |
|
|
|
517 |
400ff34d
|
Leszek Koltunski
|
public void setCurrObject(RubikActivity act)
|
518 |
53f23b64
|
Leszek Koltunski
|
{
|
519 |
400ff34d
|
Leszek Koltunski
|
if( mPlayLayout!=null ) adjustLevels(act);
|
520 |
7b7d65ce
|
Leszek Koltunski
|
}
|
521 |
|
|
|
522 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
523 |
255492a0
|
Leszek Koltunski
|
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes
|
524 |
|
|
|
525 |
|
|
private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff)
|
526 |
|
|
{
|
527 |
|
|
View topLayout = act.findViewById(R.id.relativeLayout);
|
528 |
7ac0ee88
|
Leszek Koltunski
|
boolean isFullScreen;
|
529 |
00aa398a
|
Leszek Koltunski
|
|
530 |
|
|
if( topLayout!=null )
|
531 |
|
|
{
|
532 |
|
|
topLayout.getLocationOnScreen(mLocation);
|
533 |
7ac0ee88
|
Leszek Koltunski
|
isFullScreen = (mLocation[1]==0);
|
534 |
00aa398a
|
Leszek Koltunski
|
}
|
535 |
|
|
else
|
536 |
|
|
{
|
537 |
7ac0ee88
|
Leszek Koltunski
|
isFullScreen = true;
|
538 |
00aa398a
|
Leszek Koltunski
|
}
|
539 |
255492a0
|
Leszek Koltunski
|
|
540 |
69a271f3
|
Leszek Koltunski
|
try
|
541 |
255492a0
|
Leszek Koltunski
|
{
|
542 |
69a271f3
|
Leszek Koltunski
|
// if on Android 11 or we are fullscreen
|
543 |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || isFullScreen )
|
544 |
|
|
{
|
545 |
|
|
window.showAsDropDown(view, xoff, yoff, Gravity.CENTER);
|
546 |
|
|
window.update(view, w, h);
|
547 |
|
|
}
|
548 |
|
|
else // Android 10 or below in pop-up mode or split-screen mode
|
549 |
|
|
{
|
550 |
|
|
view.getLocationOnScreen(mLocation);
|
551 |
|
|
int width = view.getWidth();
|
552 |
|
|
int height = view.getHeight();
|
553 |
|
|
int x = mLocation[0]+(width-w)/2;
|
554 |
|
|
int y = mLocation[1]+height+yoff;
|
555 |
|
|
|
556 |
|
|
window.showAsDropDown(view);
|
557 |
|
|
window.update(x,y,w,h);
|
558 |
|
|
}
|
559 |
255492a0
|
Leszek Koltunski
|
}
|
560 |
69a271f3
|
Leszek Koltunski
|
catch( IllegalArgumentException iae )
|
561 |
255492a0
|
Leszek Koltunski
|
{
|
562 |
69a271f3
|
Leszek Koltunski
|
// ignore, this means window is 'not attached to window manager' -
|
563 |
|
|
// which most probably is because we are already exiting the app.
|
564 |
255492a0
|
Leszek Koltunski
|
}
|
565 |
|
|
}
|
566 |
|
|
|
567 |
ae77f661
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
568 |
|
|
|
569 |
d38a302b
|
Leszek Koltunski
|
private void adjustSolvedIcons()
|
570 |
ae77f661
|
Leszek Koltunski
|
{
|
571 |
59cc16ae
|
Leszek Koltunski
|
if( mPlayLayout!=null )
|
572 |
ae77f661
|
Leszek Koltunski
|
{
|
573 |
59cc16ae
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
574 |
|
|
int dbLevel = RubikObjectList.getDBLevel(currObject);
|
575 |
|
|
int numLevel= Math.min(dbLevel, LEVELS_SHOWN);
|
576 |
|
|
RubikScores scores = RubikScores.getInstance();
|
577 |
|
|
|
578 |
|
|
for(int i=0; i<numLevel; i++)
|
579 |
|
|
{
|
580 |
|
|
int level = i<numLevel-1 ? i+1 : dbLevel;
|
581 |
|
|
Button button = (Button)mPlayLayout.getChildAt(i);
|
582 |
|
|
int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
583 |
|
|
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
|
584 |
|
|
}
|
585 |
ae77f661
|
Leszek Koltunski
|
}
|
586 |
|
|
}
|
587 |
|
|
|
588 |
255492a0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
589 |
7b7d65ce
|
Leszek Koltunski
|
|
590 |
0254cfd7
|
Leszek Koltunski
|
private void adjustLevels(final RubikActivity act)
|
591 |
7b7d65ce
|
Leszek Koltunski
|
{
|
592 |
400ff34d
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
593 |
|
|
int dbLevel = RubikObjectList.getDBLevel(currObject);
|
594 |
|
|
RubikObject object = RubikObjectList.getObject(currObject);
|
595 |
d433b50e
|
Leszek Koltunski
|
int numScrambles = object==null ? 0 : object.getNumScramble();
|
596 |
0a7aa15b
|
Leszek Koltunski
|
int numLevel = Math.min(dbLevel, LEVELS_SHOWN);
|
597 |
00af5060
|
Leszek Koltunski
|
String[] levels = new String[numLevel];
|
598 |
7b7d65ce
|
Leszek Koltunski
|
|
599 |
00af5060
|
Leszek Koltunski
|
for(int i=0; i<numLevel-1; i++)
|
600 |
53f23b64
|
Leszek Koltunski
|
{
|
601 |
7b7d65ce
|
Leszek Koltunski
|
levels[i] = act.getString(R.string.lv_placeholder,i+1);
|
602 |
53f23b64
|
Leszek Koltunski
|
}
|
603 |
|
|
|
604 |
4fc7b1e6
|
Leszek Koltunski
|
if( numLevel>0 )
|
605 |
|
|
{
|
606 |
|
|
levels[numLevel-1] = act.getString(R.string.level_full);
|
607 |
|
|
}
|
608 |
00af5060
|
Leszek Koltunski
|
|
609 |
0a7aa15b
|
Leszek Koltunski
|
if( mLevelValue>dbLevel || mLevelValue<1 ||
|
610 |
|
|
(mLevelValue<dbLevel || mLevelValue>LEVELS_SHOWN ) )
|
611 |
00af5060
|
Leszek Koltunski
|
{
|
612 |
|
|
mLevelValue=1;
|
613 |
|
|
}
|
614 |
0254cfd7
|
Leszek Koltunski
|
|
615 |
de62316a
|
Leszek Koltunski
|
float width = act.getScreenWidthInPixels();
|
616 |
|
|
int margin = (int)(width*RubikActivity.MARGIN);
|
617 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
618 |
|
|
int butWidth = mPlayLayoutWidth - 2*padding;
|
619 |
|
|
int butHeight= (int)mMenuItemSize;
|
620 |
|
|
int lastButH = (int)(mMenuItemSize*LAST_BUTTON) ;
|
621 |
0254cfd7
|
Leszek Koltunski
|
|
622 |
de62316a
|
Leszek Koltunski
|
LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( butWidth, butHeight );
|
623 |
0254cfd7
|
Leszek Koltunski
|
pM.setMargins(margin, 0, margin, margin);
|
624 |
de62316a
|
Leszek Koltunski
|
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( butWidth, butHeight );
|
625 |
0254cfd7
|
Leszek Koltunski
|
pT.setMargins(margin, margin, margin, margin);
|
626 |
de62316a
|
Leszek Koltunski
|
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( butWidth, lastButH );
|
627 |
0254cfd7
|
Leszek Koltunski
|
pB.setMargins(margin, margin, margin, 2*margin);
|
628 |
|
|
|
629 |
|
|
mPlayLayout.removeAllViews();
|
630 |
|
|
|
631 |
d7e539d0
|
Leszek Koltunski
|
RubikScores scores = RubikScores.getInstance();
|
632 |
|
|
|
633 |
00af5060
|
Leszek Koltunski
|
for(int i=0; i<numLevel; i++)
|
634 |
011fcfe0
|
Leszek Koltunski
|
{
|
635 |
0a7aa15b
|
Leszek Koltunski
|
final int level = i<numLevel-1 ? i+1 : dbLevel;
|
636 |
|
|
final int scrambles = i<numLevel-1 ? i+1 : numScrambles;
|
637 |
0254cfd7
|
Leszek Koltunski
|
Button button = new Button(act);
|
638 |
00af5060
|
Leszek Koltunski
|
button.setLayoutParams(i==0 ? pT : (i==numLevel-1 ? pB : pM));
|
639 |
0254cfd7
|
Leszek Koltunski
|
button.setText(levels[i]);
|
640 |
|
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
641 |
|
|
|
642 |
400ff34d
|
Leszek Koltunski
|
int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
643 |
d7e539d0
|
Leszek Koltunski
|
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
|
644 |
|
|
|
645 |
0254cfd7
|
Leszek Koltunski
|
button.setOnClickListener( new View.OnClickListener()
|
646 |
011fcfe0
|
Leszek Koltunski
|
{
|
647 |
0254cfd7
|
Leszek Koltunski
|
@Override
|
648 |
|
|
public void onClick(View v)
|
649 |
|
|
{
|
650 |
2afc6754
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
651 |
6fad862b
|
Leszek Koltunski
|
|
652 |
2afc6754
|
Leszek Koltunski
|
if(control.isUINotBlocked())
|
653 |
6fad862b
|
Leszek Koltunski
|
{
|
654 |
598de3ee
|
Leszek Koltunski
|
if( mPlayPopup!=null ) mPlayPopup.dismiss();
|
655 |
0a7aa15b
|
Leszek Koltunski
|
mLevelValue = level;
|
656 |
dd874ae8
|
Leszek Koltunski
|
mShouldReactToEndOfScrambling = true;
|
657 |
2afc6754
|
Leszek Koltunski
|
control.scrambleObject(scrambles);
|
658 |
6fad862b
|
Leszek Koltunski
|
}
|
659 |
0254cfd7
|
Leszek Koltunski
|
}
|
660 |
|
|
});
|
661 |
011fcfe0
|
Leszek Koltunski
|
|
662 |
0254cfd7
|
Leszek Koltunski
|
mPlayLayout.addView(button);
|
663 |
|
|
}
|
664 |
53f23b64
|
Leszek Koltunski
|
}
|
665 |
|
|
|
666 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
667 |
|
|
|
668 |
dca3888a
|
Leszek Koltunski
|
public int getLevel()
|
669 |
211b48f2
|
Leszek Koltunski
|
{
|
670 |
85b09df4
|
Leszek Koltunski
|
return mLevelValue;
|
671 |
211b48f2
|
Leszek Koltunski
|
}
|
672 |
|
|
|
673 |
dd874ae8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
674 |
|
|
|
675 |
|
|
public boolean shouldReactToEndOfScrambling()
|
676 |
|
|
{
|
677 |
|
|
return mShouldReactToEndOfScrambling;
|
678 |
|
|
}
|
679 |
211b48f2
|
Leszek Koltunski
|
}
|