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 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.states;
|
21 |
211b48f2
|
Leszek Koltunski
|
|
22 |
4c0cd600
|
Leszek Koltunski
|
import android.content.Context;
|
23 |
211b48f2
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
24 |
4c0cd600
|
Leszek Koltunski
|
import android.graphics.drawable.BitmapDrawable;
|
25 |
e03e0352
|
Leszek Koltunski
|
import android.os.Bundle;
|
26 |
e3c74c0f
|
Leszek Koltunski
|
import android.util.TypedValue;
|
27 |
4c0cd600
|
Leszek Koltunski
|
import android.view.Gravity;
|
28 |
211b48f2
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
29 |
|
|
import android.view.View;
|
30 |
|
|
import android.widget.Button;
|
31 |
e07c48a2
|
Leszek Koltunski
|
import android.widget.GridLayout;
|
32 |
211b48f2
|
Leszek Koltunski
|
import android.widget.ImageButton;
|
33 |
|
|
import android.widget.LinearLayout;
|
34 |
4c0cd600
|
Leszek Koltunski
|
import android.widget.PopupWindow;
|
35 |
211b48f2
|
Leszek Koltunski
|
|
36 |
e03e0352
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogAbout;
|
37 |
|
|
import org.distorted.dialogs.RubikDialogScores;
|
38 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
39 |
|
|
import org.distorted.main.RubikActivity;
|
40 |
15846fe4
|
Leszek Koltunski
|
import org.distorted.main.RubikPreRender;
|
41 |
|
|
import org.distorted.objects.RubikObject;
|
42 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.objects.RubikObjectList;
|
43 |
d7e539d0
|
Leszek Koltunski
|
import org.distorted.scores.RubikScores;
|
44 |
211b48f2
|
Leszek Koltunski
|
|
45 |
15846fe4
|
Leszek Koltunski
|
import java.util.ArrayList;
|
46 |
|
|
|
47 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
|
|
|
49 |
0254cfd7
|
Leszek Koltunski
|
public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender.ActionFinishedListener
|
50 |
211b48f2
|
Leszek Koltunski
|
{
|
51 |
15846fe4
|
Leszek Koltunski
|
private static final int DURATION_MILLIS = 750;
|
52 |
0254cfd7
|
Leszek Koltunski
|
private static final int LEVELS_SHOWN = 10;
|
53 |
85b09df4
|
Leszek Koltunski
|
public static final int DEF_OBJECT= RubikObjectList.CUBE.ordinal();
|
54 |
|
|
public static final int DEF_SIZE = 3;
|
55 |
211b48f2
|
Leszek Koltunski
|
|
56 |
e03e0352
|
Leszek Koltunski
|
private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about };
|
57 |
|
|
private static final int NUM_BUTTONS = BUTTON_LABELS.length;
|
58 |
|
|
|
59 |
46405bb4
|
Leszek Koltunski
|
private ImageButton mObjButton, mMenuButton, mPrevButton, mSolveButton, mLockButton;
|
60 |
15846fe4
|
Leszek Koltunski
|
private Button mPlayButton;
|
61 |
0254cfd7
|
Leszek Koltunski
|
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
|
62 |
4888e97c
|
Leszek Koltunski
|
private int mObject = DEF_OBJECT;
|
63 |
|
|
private int mSize = DEF_SIZE;
|
64 |
0254cfd7
|
Leszek Koltunski
|
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
|
65 |
85b09df4
|
Leszek Koltunski
|
private int mLevelValue;
|
66 |
e07c48a2
|
Leszek Koltunski
|
private float mButtonSize, mMenuItemSize, mMenuTextSize;
|
67 |
|
|
private int mColCount, mRowCount;
|
68 |
0254cfd7
|
Leszek Koltunski
|
private LinearLayout mPlayLayout;
|
69 |
211b48f2
|
Leszek Koltunski
|
|
70 |
15846fe4
|
Leszek Koltunski
|
private ArrayList<Move> mMoves;
|
71 |
|
|
private boolean mCanPrevMove;
|
72 |
|
|
|
73 |
|
|
private static class Move
|
74 |
|
|
{
|
75 |
|
|
private int mAxis, mRow, mAngle;
|
76 |
|
|
|
77 |
|
|
Move(int axis, int row, int angle)
|
78 |
|
|
{
|
79 |
|
|
mAxis = axis;
|
80 |
|
|
mRow = row;
|
81 |
|
|
mAngle= angle;
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86 |
|
|
|
87 |
329c0aeb
|
Leszek Koltunski
|
void leaveState(RubikActivity act)
|
88 |
211b48f2
|
Leszek Koltunski
|
{
|
89 |
85b09df4
|
Leszek Koltunski
|
|
90 |
211b48f2
|
Leszek Koltunski
|
}
|
91 |
|
|
|
92 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93 |
|
|
|
94 |
a6d3b158
|
Leszek Koltunski
|
void enterState(final RubikActivity act)
|
95 |
211b48f2
|
Leszek Koltunski
|
{
|
96 |
e3c74c0f
|
Leszek Koltunski
|
float width = act.getScreenWidthInPixels();
|
97 |
88fb92ba
|
Leszek Koltunski
|
mMenuTextSize = width*RubikActivity.MENU_MEDIUM_TEXT_SIZE;
|
98 |
|
|
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
|
99 |
|
|
mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;
|
100 |
e3c74c0f
|
Leszek Koltunski
|
|
101 |
15846fe4
|
Leszek Koltunski
|
mCanPrevMove = true;
|
102 |
|
|
|
103 |
|
|
if( mMoves==null ) mMoves = new ArrayList<>();
|
104 |
|
|
else mMoves.clear();
|
105 |
|
|
|
106 |
e07c48a2
|
Leszek Koltunski
|
mRowCount = RubikObjectList.getRowCount();
|
107 |
|
|
mColCount = RubikObjectList.getColumnCount();
|
108 |
|
|
|
109 |
211b48f2
|
Leszek Koltunski
|
// TOP ////////////////////////////
|
110 |
7289fd6c
|
Leszek Koltunski
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
111 |
211b48f2
|
Leszek Koltunski
|
layoutTop.removeAllViews();
|
112 |
85b09df4
|
Leszek Koltunski
|
|
113 |
b376bfd7
|
Leszek Koltunski
|
setupObjectWindow(act,width);
|
114 |
ad0c8e0e
|
Leszek Koltunski
|
setupObjectButton(act,width);
|
115 |
85b09df4
|
Leszek Koltunski
|
layoutTop.addView(mObjButton);
|
116 |
0254cfd7
|
Leszek Koltunski
|
|
117 |
|
|
setupMenuWindow(act,width);
|
118 |
|
|
setupMenuButton(act,width);
|
119 |
|
|
layoutTop.addView(mMenuButton);
|
120 |
|
|
|
121 |
|
|
setupPlayWindow(act,width);
|
122 |
ad0c8e0e
|
Leszek Koltunski
|
setupPlayButton(act,width);
|
123 |
85b09df4
|
Leszek Koltunski
|
layoutTop.addView(mPlayButton);
|
124 |
211b48f2
|
Leszek Koltunski
|
|
125 |
|
|
// BOT ////////////////////////////
|
126 |
92843d3b
|
Leszek Koltunski
|
LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
|
127 |
|
|
layoutBot.removeAllViews();
|
128 |
4888e97c
|
Leszek Koltunski
|
|
129 |
4fb1fc0d
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
|
130 |
|
|
|
131 |
|
|
LinearLayout layoutLeft = new LinearLayout(act);
|
132 |
|
|
layoutLeft.setLayoutParams(params);
|
133 |
|
|
LinearLayout layoutMid = new LinearLayout(act);
|
134 |
|
|
layoutMid.setLayoutParams(params);
|
135 |
|
|
LinearLayout layoutRight = new LinearLayout(act);
|
136 |
|
|
layoutRight.setLayoutParams(params);
|
137 |
|
|
|
138 |
ad0c8e0e
|
Leszek Koltunski
|
setupPrevButton(act,width);
|
139 |
4fb1fc0d
|
Leszek Koltunski
|
layoutLeft.addView(mPrevButton);
|
140 |
46405bb4
|
Leszek Koltunski
|
setupLockButton(act,width);
|
141 |
|
|
layoutMid.addView(mLockButton);
|
142 |
ad0c8e0e
|
Leszek Koltunski
|
setupSolveButton(act,width);
|
143 |
4fb1fc0d
|
Leszek Koltunski
|
layoutRight.addView(mSolveButton);
|
144 |
|
|
|
145 |
|
|
layoutBot.addView(layoutLeft);
|
146 |
|
|
layoutBot.addView(layoutMid);
|
147 |
|
|
layoutBot.addView(layoutRight);
|
148 |
769d7b9f
|
Leszek Koltunski
|
}
|
149 |
211b48f2
|
Leszek Koltunski
|
|
150 |
769d7b9f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
4c0cd600
|
Leszek Koltunski
|
|
152 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupObjectButton(final RubikActivity act, final float width)
|
153 |
769d7b9f
|
Leszek Koltunski
|
{
|
154 |
e07c48a2
|
Leszek Koltunski
|
final int padding = (int)(width*RubikActivity.PADDING);
|
155 |
|
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
156 |
|
|
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);
|
157 |
ad0c8e0e
|
Leszek Koltunski
|
|
158 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.2f);
|
159 |
|
|
params.topMargin = margin;
|
160 |
|
|
params.bottomMargin = margin;
|
161 |
|
|
params.leftMargin = margin;
|
162 |
|
|
params.rightMargin = margin;
|
163 |
|
|
|
164 |
769d7b9f
|
Leszek Koltunski
|
mObjButton = new ImageButton(act);
|
165 |
ad0c8e0e
|
Leszek Koltunski
|
mObjButton.setLayoutParams(params);
|
166 |
769d7b9f
|
Leszek Koltunski
|
mObjButton.setPadding(padding,0,padding,0);
|
167 |
f6a9c538
|
Leszek Koltunski
|
mObjButton.setImageResource(icon);
|
168 |
769d7b9f
|
Leszek Koltunski
|
|
169 |
|
|
mObjButton.setOnClickListener( new View.OnClickListener()
|
170 |
|
|
{
|
171 |
|
|
@Override
|
172 |
|
|
public void onClick(View view)
|
173 |
4c0cd600
|
Leszek Koltunski
|
{
|
174 |
5a4d4fba
|
Leszek Koltunski
|
if( act.getPreRender().canPlay() )
|
175 |
a42e25a6
|
Leszek Koltunski
|
{
|
176 |
466b2ffc
|
Leszek Koltunski
|
mObjectPopup.setFocusable(false);
|
177 |
|
|
mObjectPopup.update();
|
178 |
|
|
|
179 |
|
|
View popupView = mObjectPopup.getContentView();
|
180 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
181 |
|
|
|
182 |
fa679111
|
Leszek Koltunski
|
mObjectPopup.showAsDropDown(view, margin, margin, Gravity.LEFT);
|
183 |
466b2ffc
|
Leszek Koltunski
|
mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount);
|
184 |
|
|
|
185 |
|
|
mObjectPopup.setFocusable(true);
|
186 |
|
|
mObjectPopup.update();
|
187 |
9439f455
|
Leszek Koltunski
|
|
188 |
a42e25a6
|
Leszek Koltunski
|
}
|
189 |
769d7b9f
|
Leszek Koltunski
|
}
|
190 |
|
|
});
|
191 |
|
|
}
|
192 |
4c0cd600
|
Leszek Koltunski
|
|
193 |
85b09df4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194 |
|
|
|
195 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupPlayButton(final RubikActivity act, final float width)
|
196 |
85b09df4
|
Leszek Koltunski
|
{
|
197 |
0254cfd7
|
Leszek Koltunski
|
final int padding = (int)(width*RubikActivity.PADDING);
|
198 |
|
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
199 |
ad0c8e0e
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.2f);
|
200 |
|
|
params.topMargin = margin;
|
201 |
|
|
params.bottomMargin = margin;
|
202 |
|
|
params.leftMargin = margin;
|
203 |
|
|
params.rightMargin = margin;
|
204 |
|
|
|
205 |
85b09df4
|
Leszek Koltunski
|
mPlayButton = new Button(act);
|
206 |
ad0c8e0e
|
Leszek Koltunski
|
mPlayButton.setLayoutParams(params);
|
207 |
85b09df4
|
Leszek Koltunski
|
mPlayButton.setPadding(padding,0,padding,0);
|
208 |
e3c74c0f
|
Leszek Koltunski
|
mPlayButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
|
209 |
85b09df4
|
Leszek Koltunski
|
mPlayButton.setText(R.string.play);
|
210 |
|
|
|
211 |
|
|
mPlayButton.setOnClickListener( new View.OnClickListener()
|
212 |
|
|
{
|
213 |
|
|
@Override
|
214 |
0254cfd7
|
Leszek Koltunski
|
public void onClick(View view)
|
215 |
85b09df4
|
Leszek Koltunski
|
{
|
216 |
466b2ffc
|
Leszek Koltunski
|
mPlayPopup.setFocusable(false);
|
217 |
|
|
mPlayPopup.update();
|
218 |
|
|
|
219 |
|
|
View popupView = mPlayPopup.getContentView();
|
220 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
221 |
|
|
|
222 |
eaee1ddc
|
Leszek Koltunski
|
final int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize);
|
223 |
|
|
final int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex);
|
224 |
|
|
final int levelsShown = Math.min(maxLevel,LEVELS_SHOWN);
|
225 |
|
|
|
226 |
0254cfd7
|
Leszek Koltunski
|
mPlayPopup.showAsDropDown(view, margin, margin, Gravity.RIGHT);
|
227 |
eaee1ddc
|
Leszek Koltunski
|
mPlayPopup.update(view, mPlayLayoutWidth, (int)(levelsShown*(mMenuItemSize+margin)+2*margin));
|
228 |
466b2ffc
|
Leszek Koltunski
|
|
229 |
|
|
mPlayPopup.setFocusable(true);
|
230 |
|
|
mPlayPopup.update();
|
231 |
85b09df4
|
Leszek Koltunski
|
}
|
232 |
|
|
});
|
233 |
|
|
}
|
234 |
|
|
|
235 |
e31abc1e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236 |
|
|
|
237 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupMenuButton(final RubikActivity act, final float width)
|
238 |
e31abc1e
|
Leszek Koltunski
|
{
|
239 |
0254cfd7
|
Leszek Koltunski
|
final int padding = (int)(width*RubikActivity.PADDING);
|
240 |
|
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
241 |
|
|
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);
|
242 |
f6a9c538
|
Leszek Koltunski
|
|
243 |
0254cfd7
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.2f);
|
244 |
ad0c8e0e
|
Leszek Koltunski
|
params.topMargin = margin;
|
245 |
|
|
params.bottomMargin = margin;
|
246 |
|
|
params.leftMargin = margin;
|
247 |
|
|
params.rightMargin = margin;
|
248 |
|
|
|
249 |
e03e0352
|
Leszek Koltunski
|
mMenuButton = new ImageButton(act);
|
250 |
ad0c8e0e
|
Leszek Koltunski
|
mMenuButton.setLayoutParams(params);
|
251 |
e03e0352
|
Leszek Koltunski
|
mMenuButton.setPadding(padding,0,padding,0);
|
252 |
f6a9c538
|
Leszek Koltunski
|
mMenuButton.setImageResource(icon);
|
253 |
e31abc1e
|
Leszek Koltunski
|
|
254 |
e03e0352
|
Leszek Koltunski
|
mMenuButton.setOnClickListener( new View.OnClickListener()
|
255 |
e31abc1e
|
Leszek Koltunski
|
{
|
256 |
|
|
@Override
|
257 |
|
|
public void onClick(View view)
|
258 |
|
|
{
|
259 |
e03e0352
|
Leszek Koltunski
|
if( act.getPreRender().canPlay() )
|
260 |
|
|
{
|
261 |
466b2ffc
|
Leszek Koltunski
|
mMenuPopup.setFocusable(false);
|
262 |
|
|
mMenuPopup.update();
|
263 |
|
|
|
264 |
|
|
View popupView = mMenuPopup.getContentView();
|
265 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
266 |
|
|
|
267 |
0254cfd7
|
Leszek Koltunski
|
mMenuPopup.showAsDropDown(view, (int)(-width/12), margin, Gravity.CENTER);
|
268 |
74b08185
|
Leszek Koltunski
|
mMenuPopup.update(view, mMenuLayoutWidth, mMenuLayoutHeight);
|
269 |
466b2ffc
|
Leszek Koltunski
|
|
270 |
|
|
mMenuPopup.setFocusable(true);
|
271 |
|
|
mMenuPopup.update();
|
272 |
e03e0352
|
Leszek Koltunski
|
}
|
273 |
e31abc1e
|
Leszek Koltunski
|
}
|
274 |
|
|
});
|
275 |
|
|
}
|
276 |
|
|
|
277 |
85b09df4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
278 |
|
|
|
279 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupSolveButton(final RubikActivity act, final float width)
|
280 |
85b09df4
|
Leszek Koltunski
|
{
|
281 |
ad0c8e0e
|
Leszek Koltunski
|
int padding = (int)(width*RubikActivity.PADDING);
|
282 |
|
|
int margin = (int)(width*RubikActivity.MARGIN);
|
283 |
31a9f38d
|
Leszek Koltunski
|
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);
|
284 |
f6a9c538
|
Leszek Koltunski
|
|
285 |
4fb1fc0d
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
286 |
ad0c8e0e
|
Leszek Koltunski
|
params.topMargin = margin;
|
287 |
|
|
params.bottomMargin = margin;
|
288 |
|
|
params.leftMargin = margin;
|
289 |
|
|
params.rightMargin = margin;
|
290 |
|
|
|
291 |
15846fe4
|
Leszek Koltunski
|
mSolveButton = new ImageButton(act);
|
292 |
ad0c8e0e
|
Leszek Koltunski
|
mSolveButton.setLayoutParams(params);
|
293 |
85b09df4
|
Leszek Koltunski
|
mSolveButton.setPadding(padding,0,padding,0);
|
294 |
f6a9c538
|
Leszek Koltunski
|
mSolveButton.setImageResource(icon);
|
295 |
85b09df4
|
Leszek Koltunski
|
|
296 |
|
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
297 |
|
|
{
|
298 |
|
|
@Override
|
299 |
|
|
public void onClick(View v)
|
300 |
|
|
{
|
301 |
5a4d4fba
|
Leszek Koltunski
|
act.getPreRender().solveObject();
|
302 |
5b893eee
|
Leszek Koltunski
|
mMoves.clear();
|
303 |
85b09df4
|
Leszek Koltunski
|
}
|
304 |
|
|
});
|
305 |
|
|
}
|
306 |
|
|
|
307 |
46405bb4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
308 |
|
|
|
309 |
|
|
private void setupLockButton(final RubikActivity act, final float width)
|
310 |
|
|
{
|
311 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
312 |
|
|
int margin = (int)(width*RubikActivity.MARGIN);
|
313 |
|
|
|
314 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
315 |
|
|
params.topMargin = margin;
|
316 |
|
|
params.bottomMargin = margin;
|
317 |
|
|
params.leftMargin = margin;
|
318 |
|
|
params.rightMargin = margin;
|
319 |
|
|
|
320 |
|
|
mLockButton = new ImageButton(act);
|
321 |
|
|
mLockButton.setLayoutParams(params);
|
322 |
|
|
mLockButton.setPadding(padding,0,padding,0);
|
323 |
|
|
mLockButton.setImageResource(getLockIcon(act));
|
324 |
|
|
|
325 |
|
|
mLockButton.setOnClickListener( new View.OnClickListener()
|
326 |
|
|
{
|
327 |
|
|
@Override
|
328 |
|
|
public void onClick(View v)
|
329 |
|
|
{
|
330 |
|
|
toggleLock(act);
|
331 |
|
|
}
|
332 |
|
|
});
|
333 |
|
|
}
|
334 |
|
|
|
335 |
769d7b9f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
336 |
4c0cd600
|
Leszek Koltunski
|
|
337 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupPrevButton(final RubikActivity act, final float width)
|
338 |
769d7b9f
|
Leszek Koltunski
|
{
|
339 |
ad0c8e0e
|
Leszek Koltunski
|
int padding = (int)(width*RubikActivity.PADDING);
|
340 |
|
|
int margin = (int)(width*RubikActivity.MARGIN);
|
341 |
31a9f38d
|
Leszek Koltunski
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back);
|
342 |
f6a9c538
|
Leszek Koltunski
|
|
343 |
4fb1fc0d
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
344 |
ad0c8e0e
|
Leszek Koltunski
|
params.topMargin = margin;
|
345 |
|
|
params.bottomMargin = margin;
|
346 |
|
|
params.leftMargin = margin;
|
347 |
|
|
params.rightMargin = margin;
|
348 |
|
|
|
349 |
15846fe4
|
Leszek Koltunski
|
mPrevButton = new ImageButton(act);
|
350 |
ad0c8e0e
|
Leszek Koltunski
|
mPrevButton.setLayoutParams(params);
|
351 |
15846fe4
|
Leszek Koltunski
|
mPrevButton.setPadding(padding,0,padding,0);
|
352 |
f6a9c538
|
Leszek Koltunski
|
mPrevButton.setImageResource(icon);
|
353 |
15846fe4
|
Leszek Koltunski
|
|
354 |
|
|
mPrevButton.setOnClickListener( new View.OnClickListener()
|
355 |
a6d3b158
|
Leszek Koltunski
|
{
|
356 |
|
|
@Override
|
357 |
|
|
public void onClick(View v)
|
358 |
|
|
{
|
359 |
15846fe4
|
Leszek Koltunski
|
RubikPreRender pre = act.getPreRender();
|
360 |
|
|
backMove(pre);
|
361 |
a6d3b158
|
Leszek Koltunski
|
}
|
362 |
|
|
});
|
363 |
211b48f2
|
Leszek Koltunski
|
}
|
364 |
|
|
|
365 |
4c0cd600
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366 |
|
|
|
367 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupObjectWindow(final RubikActivity act, final float width)
|
368 |
4c0cd600
|
Leszek Koltunski
|
{
|
369 |
769d7b9f
|
Leszek Koltunski
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
370 |
|
|
final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
|
371 |
92843d3b
|
Leszek Koltunski
|
GridLayout objectGrid = layout.findViewById(R.id.objectGrid);
|
372 |
e07c48a2
|
Leszek Koltunski
|
|
373 |
|
|
int[] indices = RubikObjectList.getIndices();
|
374 |
|
|
|
375 |
|
|
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
|
376 |
|
|
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
|
377 |
|
|
|
378 |
92843d3b
|
Leszek Koltunski
|
objectGrid.setColumnCount(mColCount);
|
379 |
|
|
objectGrid.setRowCount(mRowCount);
|
380 |
e07c48a2
|
Leszek Koltunski
|
|
381 |
fa679111
|
Leszek Koltunski
|
int[] nextInColumn = new int[mColCount];
|
382 |
|
|
|
383 |
e07c48a2
|
Leszek Koltunski
|
for(int row=0; row<mRowCount; row++)
|
384 |
|
|
{
|
385 |
|
|
rowSpecs[row] = GridLayout.spec(row);
|
386 |
|
|
}
|
387 |
|
|
for(int col=0; col<mColCount; col++)
|
388 |
|
|
{
|
389 |
|
|
colSpecs[col] = GridLayout.spec(col);
|
390 |
fa679111
|
Leszek Koltunski
|
nextInColumn[col] =0;
|
391 |
e07c48a2
|
Leszek Koltunski
|
}
|
392 |
769d7b9f
|
Leszek Koltunski
|
|
393 |
e03e0352
|
Leszek Koltunski
|
mObjectPopup = new PopupWindow(act);
|
394 |
|
|
mObjectPopup.setContentView(layout);
|
395 |
|
|
mObjectPopup.setFocusable(true);
|
396 |
31a9f38d
|
Leszek Koltunski
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2);
|
397 |
769d7b9f
|
Leszek Koltunski
|
|
398 |
f6a9c538
|
Leszek Koltunski
|
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon);
|
399 |
e07c48a2
|
Leszek Koltunski
|
int cubeWidth = bd.getIntrinsicWidth();
|
400 |
|
|
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
401 |
|
|
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
|
402 |
f6a9c538
|
Leszek Koltunski
|
|
403 |
769d7b9f
|
Leszek Koltunski
|
for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
|
404 |
|
|
{
|
405 |
53f23b64
|
Leszek Koltunski
|
final RubikObjectList list = RubikObjectList.getObject(object);
|
406 |
|
|
final int[] sizes = list.getSizes();
|
407 |
769d7b9f
|
Leszek Koltunski
|
int[] icons = list.getIconIDs();
|
408 |
|
|
int len = sizes.length;
|
409 |
|
|
final int obj = object;
|
410 |
fa679111
|
Leszek Koltunski
|
int col = indices[object];
|
411 |
769d7b9f
|
Leszek Koltunski
|
|
412 |
|
|
for(int i=0; i<len; i++)
|
413 |
|
|
{
|
414 |
e07c48a2
|
Leszek Koltunski
|
final int index = i;
|
415 |
769d7b9f
|
Leszek Koltunski
|
|
416 |
|
|
ImageButton button = new ImageButton(act);
|
417 |
|
|
button.setBackgroundResource(icons[i]);
|
418 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
419 |
|
|
{
|
420 |
|
|
@Override
|
421 |
|
|
public void onClick(View v)
|
422 |
|
|
{
|
423 |
5a4d4fba
|
Leszek Koltunski
|
if( act.getPreRender().canPlay() && RubikState.getCurrentState()==RubikState.PLAY )
|
424 |
a42e25a6
|
Leszek Koltunski
|
{
|
425 |
|
|
mObject = obj;
|
426 |
e07c48a2
|
Leszek Koltunski
|
mSize = sizes[index];
|
427 |
|
|
act.changeObject(list,sizes[index], true);
|
428 |
0254cfd7
|
Leszek Koltunski
|
adjustLevels(act);
|
429 |
40c8c5fa
|
Leszek Koltunski
|
mMoves.clear();
|
430 |
a42e25a6
|
Leszek Koltunski
|
}
|
431 |
8e3898c8
|
Leszek Koltunski
|
|
432 |
e03e0352
|
Leszek Koltunski
|
mObjectPopup.dismiss();
|
433 |
769d7b9f
|
Leszek Koltunski
|
}
|
434 |
|
|
});
|
435 |
|
|
|
436 |
fa679111
|
Leszek Koltunski
|
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[nextInColumn[col]],colSpecs[col]);
|
437 |
e07c48a2
|
Leszek Koltunski
|
params.bottomMargin = margin;
|
438 |
|
|
params.topMargin = margin;
|
439 |
|
|
params.leftMargin = margin;
|
440 |
|
|
params.rightMargin = margin;
|
441 |
|
|
|
442 |
fa679111
|
Leszek Koltunski
|
nextInColumn[col]++;
|
443 |
|
|
|
444 |
92843d3b
|
Leszek Koltunski
|
objectGrid.addView(button, params);
|
445 |
769d7b9f
|
Leszek Koltunski
|
}
|
446 |
|
|
}
|
447 |
4c0cd600
|
Leszek Koltunski
|
}
|
448 |
|
|
|
449 |
e03e0352
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
450 |
|
|
|
451 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupMenuWindow(final RubikActivity act, final float width)
|
452 |
e03e0352
|
Leszek Koltunski
|
{
|
453 |
|
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
454 |
e07c48a2
|
Leszek Koltunski
|
final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
|
455 |
|
|
LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
|
456 |
e03e0352
|
Leszek Koltunski
|
|
457 |
|
|
mMenuPopup = new PopupWindow(act);
|
458 |
|
|
mMenuPopup.setContentView(layout);
|
459 |
|
|
mMenuPopup.setFocusable(true);
|
460 |
ad0c8e0e
|
Leszek Koltunski
|
int margin = (int)(width*RubikActivity.MARGIN);
|
461 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
462 |
e03e0352
|
Leszek Koltunski
|
|
463 |
0254cfd7
|
Leszek Koltunski
|
mMenuLayoutWidth = (int)(width/2);
|
464 |
|
|
mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
|
465 |
|
|
|
466 |
|
|
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
467 |
|
|
pT.setMargins(margin, 0, margin, margin);
|
468 |
|
|
LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
469 |
|
|
pM.setMargins(margin, margin, margin, margin);
|
470 |
|
|
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
471 |
|
|
pB.setMargins(margin, margin, margin, 2*margin);
|
472 |
e03e0352
|
Leszek Koltunski
|
|
473 |
|
|
for(int i=0; i<NUM_BUTTONS; i++)
|
474 |
|
|
{
|
475 |
|
|
final int but = i;
|
476 |
|
|
Button button = new Button(act);
|
477 |
0254cfd7
|
Leszek Koltunski
|
button.setLayoutParams(pT);//i==0 ? pT : (i==NUM_BUTTONS-1 ? pB : pM));
|
478 |
e03e0352
|
Leszek Koltunski
|
button.setText(BUTTON_LABELS[i]);
|
479 |
88fb92ba
|
Leszek Koltunski
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
480 |
e03e0352
|
Leszek Koltunski
|
|
481 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
482 |
|
|
{
|
483 |
|
|
@Override
|
484 |
|
|
public void onClick(View v)
|
485 |
|
|
{
|
486 |
|
|
mMenuPopup.dismiss();
|
487 |
0254cfd7
|
Leszek Koltunski
|
MenuAction(act,but);
|
488 |
e03e0352
|
Leszek Koltunski
|
}
|
489 |
|
|
});
|
490 |
|
|
|
491 |
e07c48a2
|
Leszek Koltunski
|
menuLayout.addView(button);
|
492 |
e03e0352
|
Leszek Koltunski
|
}
|
493 |
0254cfd7
|
Leszek Koltunski
|
}
|
494 |
e03e0352
|
Leszek Koltunski
|
|
495 |
0254cfd7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
496 |
|
|
|
497 |
|
|
private void setupPlayWindow(final RubikActivity act, final float width)
|
498 |
|
|
{
|
499 |
|
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
500 |
|
|
final View layout = layoutInflater.inflate(R.layout.popup_play, null);
|
501 |
|
|
mPlayLayout = layout.findViewById(R.id.playGrid);
|
502 |
|
|
|
503 |
|
|
mPlayLayoutWidth = (int)(width*0.4f);
|
504 |
|
|
|
505 |
|
|
mPlayPopup = new PopupWindow(act);
|
506 |
|
|
mPlayPopup.setContentView(layout);
|
507 |
|
|
mPlayPopup.setFocusable(true);
|
508 |
|
|
|
509 |
|
|
adjustLevels(act);
|
510 |
e03e0352
|
Leszek Koltunski
|
}
|
511 |
|
|
|
512 |
15846fe4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
513 |
|
|
|
514 |
|
|
private void backMove(RubikPreRender pre)
|
515 |
|
|
{
|
516 |
|
|
if( mCanPrevMove )
|
517 |
|
|
{
|
518 |
|
|
int numMoves = mMoves.size();
|
519 |
|
|
|
520 |
|
|
if( numMoves>0 )
|
521 |
|
|
{
|
522 |
|
|
Move move = mMoves.remove(numMoves-1);
|
523 |
|
|
RubikObject object = pre.getObject();
|
524 |
|
|
|
525 |
|
|
int axis = move.mAxis;
|
526 |
|
|
int row = (1<<move.mRow);
|
527 |
|
|
int angle = move.mAngle;
|
528 |
|
|
int numRot= Math.abs(angle*object.getBasicAngle()/360);
|
529 |
|
|
|
530 |
|
|
if( angle!=0 )
|
531 |
|
|
{
|
532 |
|
|
mCanPrevMove = false;
|
533 |
|
|
pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS);
|
534 |
|
|
}
|
535 |
|
|
else
|
536 |
|
|
{
|
537 |
|
|
android.util.Log.e("solution", "error: trying to back move of angle 0");
|
538 |
|
|
}
|
539 |
|
|
}
|
540 |
|
|
}
|
541 |
|
|
}
|
542 |
0254cfd7
|
Leszek Koltunski
|
|
543 |
e03e0352
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
544 |
|
|
|
545 |
0254cfd7
|
Leszek Koltunski
|
private void MenuAction(RubikActivity act, int button)
|
546 |
e03e0352
|
Leszek Koltunski
|
{
|
547 |
|
|
switch(button)
|
548 |
|
|
{
|
549 |
|
|
case 0: RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
|
550 |
|
|
int object = play.getObject();
|
551 |
|
|
int size = play.getSize();
|
552 |
|
|
int sizeIndex = RubikObjectList.getSizeIndex(object,size);
|
553 |
|
|
|
554 |
|
|
Bundle bundle = new Bundle();
|
555 |
|
|
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) );
|
556 |
|
|
bundle.putBoolean("submitting", false);
|
557 |
|
|
|
558 |
|
|
RubikDialogScores scores = new RubikDialogScores();
|
559 |
|
|
scores.setArguments(bundle);
|
560 |
|
|
scores.show(act.getSupportFragmentManager(), null);
|
561 |
|
|
break;
|
562 |
|
|
case 1: RubikState.switchState(act,RubikState.PATT);
|
563 |
|
|
break;
|
564 |
|
|
case 2: RubikState.switchState(act,RubikState.SVER);
|
565 |
|
|
break;
|
566 |
|
|
case 3: RubikDialogAbout diag = new RubikDialogAbout();
|
567 |
|
|
diag.show(act.getSupportFragmentManager(), null);
|
568 |
|
|
break;
|
569 |
|
|
}
|
570 |
|
|
}
|
571 |
|
|
|
572 |
46405bb4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
573 |
|
|
|
574 |
|
|
private void toggleLock(RubikActivity act)
|
575 |
|
|
{
|
576 |
|
|
act.toggleLock();
|
577 |
|
|
mLockButton.setImageResource(getLockIcon(act));
|
578 |
|
|
}
|
579 |
|
|
|
580 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
581 |
|
|
|
582 |
|
|
private int getLockIcon(RubikActivity act)
|
583 |
|
|
{
|
584 |
|
|
if( act.retLocked() )
|
585 |
|
|
{
|
586 |
|
|
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);
|
587 |
|
|
}
|
588 |
|
|
else
|
589 |
|
|
{
|
590 |
|
|
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked);
|
591 |
|
|
}
|
592 |
|
|
}
|
593 |
|
|
|
594 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
595 |
|
|
|
596 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
597 |
|
|
{
|
598 |
4888e97c
|
Leszek Koltunski
|
editor.putInt("statePlay_object", mObject);
|
599 |
|
|
editor.putInt("statePlay_size" , mSize);
|
600 |
4c0cd600
|
Leszek Koltunski
|
|
601 |
e03e0352
|
Leszek Koltunski
|
if( mObjectPopup!=null )
|
602 |
|
|
{
|
603 |
|
|
mObjectPopup.dismiss();
|
604 |
|
|
mObjectPopup = null;
|
605 |
|
|
}
|
606 |
|
|
|
607 |
|
|
if( mMenuPopup!=null )
|
608 |
4c0cd600
|
Leszek Koltunski
|
{
|
609 |
e03e0352
|
Leszek Koltunski
|
mMenuPopup.dismiss();
|
610 |
|
|
mMenuPopup = null;
|
611 |
4c0cd600
|
Leszek Koltunski
|
}
|
612 |
0254cfd7
|
Leszek Koltunski
|
|
613 |
|
|
if( mPlayPopup!=null )
|
614 |
|
|
{
|
615 |
|
|
mPlayPopup.dismiss();
|
616 |
|
|
mPlayPopup = null;
|
617 |
|
|
}
|
618 |
211b48f2
|
Leszek Koltunski
|
}
|
619 |
|
|
|
620 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
621 |
|
|
|
622 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
623 |
|
|
{
|
624 |
85b09df4
|
Leszek Koltunski
|
mObject = preferences.getInt("statePlay_object", DEF_OBJECT);
|
625 |
|
|
mSize = preferences.getInt("statePlay_size" , DEF_SIZE );
|
626 |
211b48f2
|
Leszek Koltunski
|
}
|
627 |
|
|
|
628 |
53f23b64
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
629 |
|
|
|
630 |
7b7d65ce
|
Leszek Koltunski
|
public boolean setObjectAndSize(RubikActivity act, RubikObjectList obj, int size)
|
631 |
53f23b64
|
Leszek Koltunski
|
{
|
632 |
7b7d65ce
|
Leszek Koltunski
|
if( mObject!=obj.ordinal() || mSize != size )
|
633 |
|
|
{
|
634 |
|
|
boolean success = false;
|
635 |
53f23b64
|
Leszek Koltunski
|
|
636 |
7b7d65ce
|
Leszek Koltunski
|
for( int s: obj.getSizes() )
|
637 |
|
|
if( s==size )
|
638 |
|
|
{
|
639 |
|
|
success = true;
|
640 |
|
|
break;
|
641 |
|
|
}
|
642 |
|
|
|
643 |
|
|
if( success )
|
644 |
53f23b64
|
Leszek Koltunski
|
{
|
645 |
7b7d65ce
|
Leszek Koltunski
|
mObject = obj.ordinal();
|
646 |
|
|
mSize = size;
|
647 |
5f8c532e
|
Leszek Koltunski
|
|
648 |
0254cfd7
|
Leszek Koltunski
|
if( mPlayLayout!=null ) adjustLevels(act);
|
649 |
53f23b64
|
Leszek Koltunski
|
}
|
650 |
|
|
|
651 |
7b7d65ce
|
Leszek Koltunski
|
return success;
|
652 |
|
|
}
|
653 |
|
|
|
654 |
|
|
return true;
|
655 |
|
|
}
|
656 |
|
|
|
657 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
658 |
|
|
|
659 |
0254cfd7
|
Leszek Koltunski
|
private void adjustLevels(final RubikActivity act)
|
660 |
7b7d65ce
|
Leszek Koltunski
|
{
|
661 |
|
|
int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize);
|
662 |
0254cfd7
|
Leszek Koltunski
|
int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex);
|
663 |
7b7d65ce
|
Leszek Koltunski
|
String[] levels = new String[maxLevel];
|
664 |
|
|
|
665 |
|
|
for(int i=0; i<maxLevel; i++)
|
666 |
53f23b64
|
Leszek Koltunski
|
{
|
667 |
7b7d65ce
|
Leszek Koltunski
|
levels[i] = act.getString(R.string.lv_placeholder,i+1);
|
668 |
53f23b64
|
Leszek Koltunski
|
}
|
669 |
|
|
|
670 |
0254cfd7
|
Leszek Koltunski
|
if( mLevelValue>maxLevel ) mLevelValue=1;
|
671 |
|
|
|
672 |
|
|
float width = act.getScreenWidthInPixels();
|
673 |
|
|
int margin = (int)(width*RubikActivity.MARGIN);
|
674 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
675 |
|
|
|
676 |
|
|
LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
|
677 |
|
|
pM.setMargins(margin, 0, margin, margin);
|
678 |
|
|
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
|
679 |
|
|
pT.setMargins(margin, margin, margin, margin);
|
680 |
|
|
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
|
681 |
|
|
pB.setMargins(margin, margin, margin, 2*margin);
|
682 |
|
|
|
683 |
|
|
mPlayLayout.removeAllViews();
|
684 |
|
|
|
685 |
d7e539d0
|
Leszek Koltunski
|
int realSize= RubikObjectList.getSizeIndex(mObject,mSize);
|
686 |
|
|
RubikScores scores = RubikScores.getInstance();
|
687 |
|
|
|
688 |
0254cfd7
|
Leszek Koltunski
|
for(int i=0; i<maxLevel; i++)
|
689 |
011fcfe0
|
Leszek Koltunski
|
{
|
690 |
0254cfd7
|
Leszek Koltunski
|
final int but = i;
|
691 |
|
|
Button button = new Button(act);
|
692 |
|
|
button.setLayoutParams(i==0 ? pT : (i==maxLevel-1 ? pB : pM));
|
693 |
|
|
button.setText(levels[i]);
|
694 |
|
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
695 |
|
|
|
696 |
d7e539d0
|
Leszek Koltunski
|
int icon = scores.isSolved(mObject, realSize, i) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
697 |
|
|
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
|
698 |
|
|
|
699 |
0254cfd7
|
Leszek Koltunski
|
button.setOnClickListener( new View.OnClickListener()
|
700 |
011fcfe0
|
Leszek Koltunski
|
{
|
701 |
0254cfd7
|
Leszek Koltunski
|
@Override
|
702 |
|
|
public void onClick(View v)
|
703 |
|
|
{
|
704 |
|
|
mPlayPopup.dismiss();
|
705 |
|
|
mLevelValue = but+1;
|
706 |
|
|
act.getPreRender().scrambleObject(mLevelValue);
|
707 |
|
|
}
|
708 |
|
|
});
|
709 |
011fcfe0
|
Leszek Koltunski
|
|
710 |
0254cfd7
|
Leszek Koltunski
|
mPlayLayout.addView(button);
|
711 |
|
|
}
|
712 |
53f23b64
|
Leszek Koltunski
|
}
|
713 |
|
|
|
714 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
715 |
|
|
|
716 |
85b09df4
|
Leszek Koltunski
|
int getLevel()
|
717 |
211b48f2
|
Leszek Koltunski
|
{
|
718 |
85b09df4
|
Leszek Koltunski
|
return mLevelValue;
|
719 |
211b48f2
|
Leszek Koltunski
|
}
|
720 |
|
|
|
721 |
15846fe4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
722 |
|
|
|
723 |
|
|
public void addMove(int axis, int row, int angle)
|
724 |
|
|
{
|
725 |
|
|
mMoves.add(new Move(axis,row,angle));
|
726 |
|
|
}
|
727 |
|
|
|
728 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
729 |
|
|
|
730 |
4888e97c
|
Leszek Koltunski
|
public int getObject()
|
731 |
211b48f2
|
Leszek Koltunski
|
{
|
732 |
4888e97c
|
Leszek Koltunski
|
return mObject;
|
733 |
211b48f2
|
Leszek Koltunski
|
}
|
734 |
|
|
|
735 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
736 |
|
|
|
737 |
4888e97c
|
Leszek Koltunski
|
public int getSize()
|
738 |
211b48f2
|
Leszek Koltunski
|
{
|
739 |
4888e97c
|
Leszek Koltunski
|
return mSize;
|
740 |
|
|
}
|
741 |
85b09df4
|
Leszek Koltunski
|
|
742 |
15846fe4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
743 |
|
|
|
744 |
|
|
public void onActionFinished(final long effectID)
|
745 |
|
|
{
|
746 |
|
|
mCanPrevMove = true;
|
747 |
|
|
}
|
748 |
211b48f2
|
Leszek Koltunski
|
}
|