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 |
211b48f2
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
28 |
|
|
import android.view.View;
|
29 |
|
|
import android.widget.Button;
|
30 |
e07c48a2
|
Leszek Koltunski
|
import android.widget.GridLayout;
|
31 |
211b48f2
|
Leszek Koltunski
|
import android.widget.ImageButton;
|
32 |
|
|
import android.widget.LinearLayout;
|
33 |
4c0cd600
|
Leszek Koltunski
|
import android.widget.PopupWindow;
|
34 |
211b48f2
|
Leszek Koltunski
|
|
35 |
e03e0352
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogAbout;
|
36 |
a8576d91
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogPattern;
|
37 |
e03e0352
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogScores;
|
38 |
234a7582
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogTutorial;
|
39 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
40 |
|
|
import org.distorted.main.RubikActivity;
|
41 |
9c2f0c91
|
Leszek Koltunski
|
import org.distorted.objects.ObjectList;
|
42 |
d7e539d0
|
Leszek Koltunski
|
import org.distorted.scores.RubikScores;
|
43 |
211b48f2
|
Leszek Koltunski
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
a8576d91
|
Leszek Koltunski
|
public class RubikStatePlay extends RubikStateBase
|
47 |
211b48f2
|
Leszek Koltunski
|
{
|
48 |
0254cfd7
|
Leszek Koltunski
|
private static final int LEVELS_SHOWN = 10;
|
49 |
9c2f0c91
|
Leszek Koltunski
|
public static final int DEF_OBJECT= ObjectList.CUBE.ordinal();
|
50 |
85b09df4
|
Leszek Koltunski
|
public static final int DEF_SIZE = 3;
|
51 |
211b48f2
|
Leszek Koltunski
|
|
52 |
2971588c
|
Leszek Koltunski
|
private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.tutorials, R.string.about };
|
53 |
e03e0352
|
Leszek Koltunski
|
private static final int NUM_BUTTONS = BUTTON_LABELS.length;
|
54 |
|
|
|
55 |
a8576d91
|
Leszek Koltunski
|
private ImageButton mObjButton, mMenuButton, mSolveButton;
|
56 |
15846fe4
|
Leszek Koltunski
|
private Button mPlayButton;
|
57 |
0254cfd7
|
Leszek Koltunski
|
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
|
58 |
4888e97c
|
Leszek Koltunski
|
private int mObject = DEF_OBJECT;
|
59 |
|
|
private int mSize = DEF_SIZE;
|
60 |
0254cfd7
|
Leszek Koltunski
|
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
|
61 |
85b09df4
|
Leszek Koltunski
|
private int mLevelValue;
|
62 |
e07c48a2
|
Leszek Koltunski
|
private float mButtonSize, mMenuItemSize, mMenuTextSize;
|
63 |
|
|
private int mColCount, mRowCount;
|
64 |
0254cfd7
|
Leszek Koltunski
|
private LinearLayout mPlayLayout;
|
65 |
211b48f2
|
Leszek Koltunski
|
|
66 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
|
68 |
329c0aeb
|
Leszek Koltunski
|
void leaveState(RubikActivity act)
|
69 |
211b48f2
|
Leszek Koltunski
|
{
|
70 |
85b09df4
|
Leszek Koltunski
|
|
71 |
211b48f2
|
Leszek Koltunski
|
}
|
72 |
|
|
|
73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
|
|
|
75 |
a6d3b158
|
Leszek Koltunski
|
void enterState(final RubikActivity act)
|
76 |
211b48f2
|
Leszek Koltunski
|
{
|
77 |
e3c74c0f
|
Leszek Koltunski
|
float width = act.getScreenWidthInPixels();
|
78 |
a8576d91
|
Leszek Koltunski
|
|
79 |
eb376d3a
|
Leszek Koltunski
|
mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE;
|
80 |
88fb92ba
|
Leszek Koltunski
|
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
|
81 |
|
|
mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;
|
82 |
e3c74c0f
|
Leszek Koltunski
|
|
83 |
9c2f0c91
|
Leszek Koltunski
|
mRowCount = ObjectList.getRowCount();
|
84 |
|
|
mColCount = ObjectList.getColumnCount();
|
85 |
e07c48a2
|
Leszek Koltunski
|
|
86 |
211b48f2
|
Leszek Koltunski
|
// TOP ////////////////////////////
|
87 |
7289fd6c
|
Leszek Koltunski
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
88 |
211b48f2
|
Leszek Koltunski
|
layoutTop.removeAllViews();
|
89 |
85b09df4
|
Leszek Koltunski
|
|
90 |
b376bfd7
|
Leszek Koltunski
|
setupObjectWindow(act,width);
|
91 |
ad0c8e0e
|
Leszek Koltunski
|
setupObjectButton(act,width);
|
92 |
85b09df4
|
Leszek Koltunski
|
layoutTop.addView(mObjButton);
|
93 |
0254cfd7
|
Leszek Koltunski
|
|
94 |
|
|
setupMenuWindow(act,width);
|
95 |
|
|
setupMenuButton(act,width);
|
96 |
|
|
layoutTop.addView(mMenuButton);
|
97 |
|
|
|
98 |
|
|
setupPlayWindow(act,width);
|
99 |
ad0c8e0e
|
Leszek Koltunski
|
setupPlayButton(act,width);
|
100 |
85b09df4
|
Leszek Koltunski
|
layoutTop.addView(mPlayButton);
|
101 |
211b48f2
|
Leszek Koltunski
|
|
102 |
ad0c8e0e
|
Leszek Koltunski
|
setupSolveButton(act,width);
|
103 |
a8576d91
|
Leszek Koltunski
|
createBottomPane(act,width,mSolveButton);
|
104 |
769d7b9f
|
Leszek Koltunski
|
}
|
105 |
211b48f2
|
Leszek Koltunski
|
|
106 |
769d7b9f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107 |
4c0cd600
|
Leszek Koltunski
|
|
108 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupObjectButton(final RubikActivity act, final float width)
|
109 |
769d7b9f
|
Leszek Koltunski
|
{
|
110 |
e07c48a2
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
111 |
|
|
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);
|
112 |
da768c35
|
Leszek Koltunski
|
mObjButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
|
113 |
769d7b9f
|
Leszek Koltunski
|
|
114 |
|
|
mObjButton.setOnClickListener( new View.OnClickListener()
|
115 |
|
|
{
|
116 |
|
|
@Override
|
117 |
|
|
public void onClick(View view)
|
118 |
4c0cd600
|
Leszek Koltunski
|
{
|
119 |
5a4d4fba
|
Leszek Koltunski
|
if( act.getPreRender().canPlay() )
|
120 |
a42e25a6
|
Leszek Koltunski
|
{
|
121 |
456780f1
|
Leszek Koltunski
|
if( mObjectPopup==null )
|
122 |
|
|
{
|
123 |
|
|
// I completely don't understand it, but Firebase says occasionally mObjectPopup is null here. Recreate.
|
124 |
|
|
float width = act.getScreenWidthInPixels();
|
125 |
|
|
setupObjectWindow(act,width);
|
126 |
|
|
}
|
127 |
|
|
|
128 |
466b2ffc
|
Leszek Koltunski
|
mObjectPopup.setFocusable(false);
|
129 |
|
|
mObjectPopup.update();
|
130 |
|
|
|
131 |
|
|
View popupView = mObjectPopup.getContentView();
|
132 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
133 |
|
|
|
134 |
e8f6670f
|
Leszek Koltunski
|
mObjectPopup.showAsDropDown(view, margin, margin);
|
135 |
466b2ffc
|
Leszek Koltunski
|
mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount);
|
136 |
|
|
|
137 |
|
|
mObjectPopup.setFocusable(true);
|
138 |
|
|
mObjectPopup.update();
|
139 |
a42e25a6
|
Leszek Koltunski
|
}
|
140 |
769d7b9f
|
Leszek Koltunski
|
}
|
141 |
|
|
});
|
142 |
|
|
}
|
143 |
4c0cd600
|
Leszek Koltunski
|
|
144 |
85b09df4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
145 |
|
|
|
146 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupPlayButton(final RubikActivity act, final float width)
|
147 |
85b09df4
|
Leszek Koltunski
|
{
|
148 |
0254cfd7
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
149 |
da768c35
|
Leszek Koltunski
|
mPlayButton = new TransparentButton(act, R.string.play, mButtonSize, width);
|
150 |
85b09df4
|
Leszek Koltunski
|
|
151 |
|
|
mPlayButton.setOnClickListener( new View.OnClickListener()
|
152 |
|
|
{
|
153 |
|
|
@Override
|
154 |
0254cfd7
|
Leszek Koltunski
|
public void onClick(View view)
|
155 |
85b09df4
|
Leszek Koltunski
|
{
|
156 |
6a76f80a
|
Leszek Koltunski
|
if( act.getPreRender().canPlay() )
|
157 |
6e194411
|
Leszek Koltunski
|
{
|
158 |
6a76f80a
|
Leszek Koltunski
|
if( mPlayPopup==null )
|
159 |
|
|
{
|
160 |
|
|
// I completely don't understand it, but Firebase says occasionally mPlayPopup is null here. Recreate.
|
161 |
|
|
float width = act.getScreenWidthInPixels();
|
162 |
|
|
setupPlayWindow(act,width);
|
163 |
|
|
}
|
164 |
6e194411
|
Leszek Koltunski
|
|
165 |
6a76f80a
|
Leszek Koltunski
|
mPlayPopup.setFocusable(false);
|
166 |
|
|
mPlayPopup.update();
|
167 |
466b2ffc
|
Leszek Koltunski
|
|
168 |
6a76f80a
|
Leszek Koltunski
|
View popupView = mPlayPopup.getContentView();
|
169 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
170 |
466b2ffc
|
Leszek Koltunski
|
|
171 |
6a76f80a
|
Leszek Koltunski
|
final int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
|
172 |
|
|
final int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex);
|
173 |
|
|
final int levelsShown = Math.min(maxLevel,LEVELS_SHOWN);
|
174 |
eaee1ddc
|
Leszek Koltunski
|
|
175 |
6a76f80a
|
Leszek Koltunski
|
mPlayPopup.showAsDropDown(view, margin, margin);
|
176 |
|
|
mPlayPopup.update(view, mPlayLayoutWidth, (int)(levelsShown*(mMenuItemSize+margin)+2*margin));
|
177 |
466b2ffc
|
Leszek Koltunski
|
|
178 |
6a76f80a
|
Leszek Koltunski
|
mPlayPopup.setFocusable(true);
|
179 |
|
|
mPlayPopup.update();
|
180 |
|
|
}
|
181 |
85b09df4
|
Leszek Koltunski
|
}
|
182 |
|
|
});
|
183 |
|
|
}
|
184 |
|
|
|
185 |
e31abc1e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186 |
|
|
|
187 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupMenuButton(final RubikActivity act, final float width)
|
188 |
e31abc1e
|
Leszek Koltunski
|
{
|
189 |
0254cfd7
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
190 |
|
|
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);
|
191 |
da768c35
|
Leszek Koltunski
|
mMenuButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
|
192 |
e31abc1e
|
Leszek Koltunski
|
|
193 |
e03e0352
|
Leszek Koltunski
|
mMenuButton.setOnClickListener( new View.OnClickListener()
|
194 |
e31abc1e
|
Leszek Koltunski
|
{
|
195 |
|
|
@Override
|
196 |
|
|
public void onClick(View view)
|
197 |
|
|
{
|
198 |
e03e0352
|
Leszek Koltunski
|
if( act.getPreRender().canPlay() )
|
199 |
|
|
{
|
200 |
456780f1
|
Leszek Koltunski
|
if( mMenuPopup==null )
|
201 |
|
|
{
|
202 |
|
|
// I completely don't understand it, but Firebase says occasionally mMenuPopup is null here. Recreate.
|
203 |
|
|
float width = act.getScreenWidthInPixels();
|
204 |
|
|
setupMenuWindow(act,width);
|
205 |
|
|
}
|
206 |
|
|
|
207 |
466b2ffc
|
Leszek Koltunski
|
mMenuPopup.setFocusable(false);
|
208 |
|
|
mMenuPopup.update();
|
209 |
|
|
|
210 |
|
|
View popupView = mMenuPopup.getContentView();
|
211 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
212 |
|
|
|
213 |
e8f6670f
|
Leszek Koltunski
|
mMenuPopup.showAsDropDown(view, (int)(-width/12), margin);
|
214 |
74b08185
|
Leszek Koltunski
|
mMenuPopup.update(view, mMenuLayoutWidth, mMenuLayoutHeight);
|
215 |
466b2ffc
|
Leszek Koltunski
|
|
216 |
|
|
mMenuPopup.setFocusable(true);
|
217 |
|
|
mMenuPopup.update();
|
218 |
e03e0352
|
Leszek Koltunski
|
}
|
219 |
e31abc1e
|
Leszek Koltunski
|
}
|
220 |
|
|
});
|
221 |
|
|
}
|
222 |
|
|
|
223 |
4c0cd600
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
224 |
|
|
|
225 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupObjectWindow(final RubikActivity act, final float width)
|
226 |
4c0cd600
|
Leszek Koltunski
|
{
|
227 |
769d7b9f
|
Leszek Koltunski
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
228 |
|
|
final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
|
229 |
92843d3b
|
Leszek Koltunski
|
GridLayout objectGrid = layout.findViewById(R.id.objectGrid);
|
230 |
e07c48a2
|
Leszek Koltunski
|
|
231 |
9c2f0c91
|
Leszek Koltunski
|
int[] indices = ObjectList.getIndices();
|
232 |
e07c48a2
|
Leszek Koltunski
|
|
233 |
|
|
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
|
234 |
|
|
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
|
235 |
|
|
|
236 |
92843d3b
|
Leszek Koltunski
|
objectGrid.setColumnCount(mColCount);
|
237 |
|
|
objectGrid.setRowCount(mRowCount);
|
238 |
e07c48a2
|
Leszek Koltunski
|
|
239 |
fa679111
|
Leszek Koltunski
|
int[] nextInColumn = new int[mColCount];
|
240 |
|
|
|
241 |
e07c48a2
|
Leszek Koltunski
|
for(int row=0; row<mRowCount; row++)
|
242 |
|
|
{
|
243 |
|
|
rowSpecs[row] = GridLayout.spec(row);
|
244 |
|
|
}
|
245 |
|
|
for(int col=0; col<mColCount; col++)
|
246 |
|
|
{
|
247 |
|
|
colSpecs[col] = GridLayout.spec(col);
|
248 |
fa679111
|
Leszek Koltunski
|
nextInColumn[col] =0;
|
249 |
e07c48a2
|
Leszek Koltunski
|
}
|
250 |
769d7b9f
|
Leszek Koltunski
|
|
251 |
e03e0352
|
Leszek Koltunski
|
mObjectPopup = new PopupWindow(act);
|
252 |
|
|
mObjectPopup.setContentView(layout);
|
253 |
|
|
mObjectPopup.setFocusable(true);
|
254 |
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);
|
255 |
769d7b9f
|
Leszek Koltunski
|
|
256 |
f6a9c538
|
Leszek Koltunski
|
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon);
|
257 |
e07c48a2
|
Leszek Koltunski
|
int cubeWidth = bd.getIntrinsicWidth();
|
258 |
|
|
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
259 |
|
|
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
|
260 |
f6a9c538
|
Leszek Koltunski
|
|
261 |
9c2f0c91
|
Leszek Koltunski
|
for(int object = 0; object< ObjectList.NUM_OBJECTS; object++)
|
262 |
769d7b9f
|
Leszek Koltunski
|
{
|
263 |
9c2f0c91
|
Leszek Koltunski
|
final ObjectList list = ObjectList.getObject(object);
|
264 |
53f23b64
|
Leszek Koltunski
|
final int[] sizes = list.getSizes();
|
265 |
769d7b9f
|
Leszek Koltunski
|
int[] icons = list.getIconIDs();
|
266 |
|
|
int len = sizes.length;
|
267 |
|
|
final int obj = object;
|
268 |
fa679111
|
Leszek Koltunski
|
int col = indices[object];
|
269 |
769d7b9f
|
Leszek Koltunski
|
|
270 |
|
|
for(int i=0; i<len; i++)
|
271 |
|
|
{
|
272 |
e07c48a2
|
Leszek Koltunski
|
final int index = i;
|
273 |
769d7b9f
|
Leszek Koltunski
|
|
274 |
|
|
ImageButton button = new ImageButton(act);
|
275 |
|
|
button.setBackgroundResource(icons[i]);
|
276 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
277 |
|
|
{
|
278 |
|
|
@Override
|
279 |
|
|
public void onClick(View v)
|
280 |
|
|
{
|
281 |
be576d14
|
Leszek Koltunski
|
if( act.getPreRender().canPlay() && StateList.getCurrentState()== StateList.PLAY )
|
282 |
a42e25a6
|
Leszek Koltunski
|
{
|
283 |
|
|
mObject = obj;
|
284 |
e07c48a2
|
Leszek Koltunski
|
mSize = sizes[index];
|
285 |
|
|
act.changeObject(list,sizes[index], true);
|
286 |
0254cfd7
|
Leszek Koltunski
|
adjustLevels(act);
|
287 |
40c8c5fa
|
Leszek Koltunski
|
mMoves.clear();
|
288 |
a42e25a6
|
Leszek Koltunski
|
}
|
289 |
8e3898c8
|
Leszek Koltunski
|
|
290 |
e03e0352
|
Leszek Koltunski
|
mObjectPopup.dismiss();
|
291 |
769d7b9f
|
Leszek Koltunski
|
}
|
292 |
|
|
});
|
293 |
|
|
|
294 |
fa679111
|
Leszek Koltunski
|
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[nextInColumn[col]],colSpecs[col]);
|
295 |
e07c48a2
|
Leszek Koltunski
|
params.bottomMargin = margin;
|
296 |
|
|
params.topMargin = margin;
|
297 |
|
|
params.leftMargin = margin;
|
298 |
|
|
params.rightMargin = margin;
|
299 |
|
|
|
300 |
fa679111
|
Leszek Koltunski
|
nextInColumn[col]++;
|
301 |
|
|
|
302 |
92843d3b
|
Leszek Koltunski
|
objectGrid.addView(button, params);
|
303 |
769d7b9f
|
Leszek Koltunski
|
}
|
304 |
|
|
}
|
305 |
4c0cd600
|
Leszek Koltunski
|
}
|
306 |
|
|
|
307 |
e03e0352
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
308 |
|
|
|
309 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupMenuWindow(final RubikActivity act, final float width)
|
310 |
e03e0352
|
Leszek Koltunski
|
{
|
311 |
|
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
312 |
e07c48a2
|
Leszek Koltunski
|
final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
|
313 |
|
|
LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
|
314 |
e03e0352
|
Leszek Koltunski
|
|
315 |
|
|
mMenuPopup = new PopupWindow(act);
|
316 |
|
|
mMenuPopup.setContentView(layout);
|
317 |
|
|
mMenuPopup.setFocusable(true);
|
318 |
ad0c8e0e
|
Leszek Koltunski
|
int margin = (int)(width*RubikActivity.MARGIN);
|
319 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
320 |
e03e0352
|
Leszek Koltunski
|
|
321 |
0254cfd7
|
Leszek Koltunski
|
mMenuLayoutWidth = (int)(width/2);
|
322 |
|
|
mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
|
323 |
|
|
|
324 |
|
|
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
325 |
|
|
pT.setMargins(margin, 0, margin, margin);
|
326 |
|
|
LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
327 |
|
|
pM.setMargins(margin, margin, margin, margin);
|
328 |
|
|
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
329 |
|
|
pB.setMargins(margin, margin, margin, 2*margin);
|
330 |
e03e0352
|
Leszek Koltunski
|
|
331 |
|
|
for(int i=0; i<NUM_BUTTONS; i++)
|
332 |
|
|
{
|
333 |
|
|
final int but = i;
|
334 |
|
|
Button button = new Button(act);
|
335 |
d85e1397
|
Leszek Koltunski
|
button.setLayoutParams(pT);
|
336 |
e03e0352
|
Leszek Koltunski
|
button.setText(BUTTON_LABELS[i]);
|
337 |
88fb92ba
|
Leszek Koltunski
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
338 |
e03e0352
|
Leszek Koltunski
|
|
339 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
340 |
|
|
{
|
341 |
|
|
@Override
|
342 |
|
|
public void onClick(View v)
|
343 |
|
|
{
|
344 |
|
|
mMenuPopup.dismiss();
|
345 |
0254cfd7
|
Leszek Koltunski
|
MenuAction(act,but);
|
346 |
e03e0352
|
Leszek Koltunski
|
}
|
347 |
|
|
});
|
348 |
|
|
|
349 |
e07c48a2
|
Leszek Koltunski
|
menuLayout.addView(button);
|
350 |
e03e0352
|
Leszek Koltunski
|
}
|
351 |
0254cfd7
|
Leszek Koltunski
|
}
|
352 |
e03e0352
|
Leszek Koltunski
|
|
353 |
0254cfd7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
354 |
|
|
|
355 |
|
|
private void setupPlayWindow(final RubikActivity act, final float width)
|
356 |
|
|
{
|
357 |
|
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
358 |
|
|
final View layout = layoutInflater.inflate(R.layout.popup_play, null);
|
359 |
|
|
mPlayLayout = layout.findViewById(R.id.playGrid);
|
360 |
|
|
|
361 |
|
|
mPlayLayoutWidth = (int)(width*0.4f);
|
362 |
|
|
|
363 |
|
|
mPlayPopup = new PopupWindow(act);
|
364 |
|
|
mPlayPopup.setContentView(layout);
|
365 |
|
|
mPlayPopup.setFocusable(true);
|
366 |
|
|
|
367 |
|
|
adjustLevels(act);
|
368 |
e03e0352
|
Leszek Koltunski
|
}
|
369 |
|
|
|
370 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
371 |
|
|
|
372 |
0254cfd7
|
Leszek Koltunski
|
private void MenuAction(RubikActivity act, int button)
|
373 |
e03e0352
|
Leszek Koltunski
|
{
|
374 |
|
|
switch(button)
|
375 |
|
|
{
|
376 |
be576d14
|
Leszek Koltunski
|
case 0: RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
377 |
e03e0352
|
Leszek Koltunski
|
int object = play.getObject();
|
378 |
|
|
int size = play.getSize();
|
379 |
9c2f0c91
|
Leszek Koltunski
|
int sizeIndex = ObjectList.getSizeIndex(object,size);
|
380 |
a8576d91
|
Leszek Koltunski
|
Bundle sBundle = new Bundle();
|
381 |
|
|
sBundle.putInt("tab", ObjectList.pack(object,sizeIndex) );
|
382 |
|
|
sBundle.putBoolean("submitting", false);
|
383 |
e03e0352
|
Leszek Koltunski
|
RubikDialogScores scores = new RubikDialogScores();
|
384 |
a8576d91
|
Leszek Koltunski
|
scores.setArguments(sBundle);
|
385 |
e03e0352
|
Leszek Koltunski
|
scores.show(act.getSupportFragmentManager(), null);
|
386 |
|
|
break;
|
387 |
234a7582
|
Leszek Koltunski
|
case 1: RubikDialogPattern pDiag = new RubikDialogPattern();
|
388 |
a8576d91
|
Leszek Koltunski
|
Bundle pBundle = new Bundle();
|
389 |
234a7582
|
Leszek Koltunski
|
int pOrd = getPatternOrdinal();
|
390 |
|
|
pBundle.putInt("tab", pOrd );
|
391 |
a8576d91
|
Leszek Koltunski
|
pDiag.setArguments(pBundle);
|
392 |
234a7582
|
Leszek Koltunski
|
pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
|
393 |
e03e0352
|
Leszek Koltunski
|
break;
|
394 |
be576d14
|
Leszek Koltunski
|
case 2: StateList.switchState(act, StateList.SVER);
|
395 |
e03e0352
|
Leszek Koltunski
|
break;
|
396 |
234a7582
|
Leszek Koltunski
|
case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial();
|
397 |
|
|
Bundle tBundle = new Bundle();
|
398 |
|
|
int tOrd = getTutorialOrdinal();
|
399 |
|
|
tBundle.putInt("tab", tOrd );
|
400 |
|
|
tDiag.setArguments(tBundle);
|
401 |
|
|
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
|
402 |
2971588c
|
Leszek Koltunski
|
break;
|
403 |
|
|
case 4: RubikDialogAbout aDiag = new RubikDialogAbout();
|
404 |
a8576d91
|
Leszek Koltunski
|
aDiag.show(act.getSupportFragmentManager(), null);
|
405 |
e03e0352
|
Leszek Koltunski
|
break;
|
406 |
|
|
}
|
407 |
|
|
}
|
408 |
|
|
|
409 |
46405bb4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
410 |
|
|
|
411 |
a8576d91
|
Leszek Koltunski
|
void setupSolveButton(final RubikActivity act, final float width)
|
412 |
46405bb4
|
Leszek Koltunski
|
{
|
413 |
a8576d91
|
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);
|
414 |
|
|
mSolveButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
|
415 |
46405bb4
|
Leszek Koltunski
|
|
416 |
a8576d91
|
Leszek Koltunski
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
417 |
46405bb4
|
Leszek Koltunski
|
{
|
418 |
a8576d91
|
Leszek Koltunski
|
@Override
|
419 |
|
|
public void onClick(View v)
|
420 |
|
|
{
|
421 |
|
|
act.getPreRender().solveObject();
|
422 |
|
|
mMoves.clear();
|
423 |
|
|
}
|
424 |
|
|
});
|
425 |
46405bb4
|
Leszek Koltunski
|
}
|
426 |
|
|
|
427 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
428 |
|
|
|
429 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
430 |
|
|
{
|
431 |
4888e97c
|
Leszek Koltunski
|
editor.putInt("statePlay_object", mObject);
|
432 |
|
|
editor.putInt("statePlay_size" , mSize);
|
433 |
4c0cd600
|
Leszek Koltunski
|
|
434 |
e03e0352
|
Leszek Koltunski
|
if( mObjectPopup!=null )
|
435 |
|
|
{
|
436 |
|
|
mObjectPopup.dismiss();
|
437 |
|
|
mObjectPopup = null;
|
438 |
|
|
}
|
439 |
|
|
|
440 |
|
|
if( mMenuPopup!=null )
|
441 |
4c0cd600
|
Leszek Koltunski
|
{
|
442 |
e03e0352
|
Leszek Koltunski
|
mMenuPopup.dismiss();
|
443 |
|
|
mMenuPopup = null;
|
444 |
4c0cd600
|
Leszek Koltunski
|
}
|
445 |
0254cfd7
|
Leszek Koltunski
|
|
446 |
|
|
if( mPlayPopup!=null )
|
447 |
|
|
{
|
448 |
|
|
mPlayPopup.dismiss();
|
449 |
|
|
mPlayPopup = null;
|
450 |
|
|
}
|
451 |
211b48f2
|
Leszek Koltunski
|
}
|
452 |
|
|
|
453 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
454 |
|
|
|
455 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
456 |
|
|
{
|
457 |
eb389a97
|
Leszek Koltunski
|
mObject= preferences.getInt("statePlay_object", DEF_OBJECT);
|
458 |
|
|
mSize = preferences.getInt("statePlay_size" , DEF_SIZE );
|
459 |
211b48f2
|
Leszek Koltunski
|
}
|
460 |
|
|
|
461 |
53f23b64
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
462 |
|
|
|
463 |
9c2f0c91
|
Leszek Koltunski
|
public boolean setObjectAndSize(RubikActivity act, ObjectList obj, int size)
|
464 |
53f23b64
|
Leszek Koltunski
|
{
|
465 |
7b7d65ce
|
Leszek Koltunski
|
if( mObject!=obj.ordinal() || mSize != size )
|
466 |
|
|
{
|
467 |
|
|
boolean success = false;
|
468 |
53f23b64
|
Leszek Koltunski
|
|
469 |
7b7d65ce
|
Leszek Koltunski
|
for( int s: obj.getSizes() )
|
470 |
|
|
if( s==size )
|
471 |
|
|
{
|
472 |
|
|
success = true;
|
473 |
|
|
break;
|
474 |
|
|
}
|
475 |
|
|
|
476 |
|
|
if( success )
|
477 |
53f23b64
|
Leszek Koltunski
|
{
|
478 |
7b7d65ce
|
Leszek Koltunski
|
mObject = obj.ordinal();
|
479 |
|
|
mSize = size;
|
480 |
5f8c532e
|
Leszek Koltunski
|
|
481 |
0254cfd7
|
Leszek Koltunski
|
if( mPlayLayout!=null ) adjustLevels(act);
|
482 |
53f23b64
|
Leszek Koltunski
|
}
|
483 |
|
|
|
484 |
7b7d65ce
|
Leszek Koltunski
|
return success;
|
485 |
|
|
}
|
486 |
|
|
|
487 |
|
|
return true;
|
488 |
|
|
}
|
489 |
|
|
|
490 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
491 |
|
|
|
492 |
0254cfd7
|
Leszek Koltunski
|
private void adjustLevels(final RubikActivity act)
|
493 |
7b7d65ce
|
Leszek Koltunski
|
{
|
494 |
9c2f0c91
|
Leszek Koltunski
|
int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
|
495 |
|
|
int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex);
|
496 |
7b7d65ce
|
Leszek Koltunski
|
String[] levels = new String[maxLevel];
|
497 |
|
|
|
498 |
|
|
for(int i=0; i<maxLevel; i++)
|
499 |
53f23b64
|
Leszek Koltunski
|
{
|
500 |
7b7d65ce
|
Leszek Koltunski
|
levels[i] = act.getString(R.string.lv_placeholder,i+1);
|
501 |
53f23b64
|
Leszek Koltunski
|
}
|
502 |
|
|
|
503 |
0254cfd7
|
Leszek Koltunski
|
if( mLevelValue>maxLevel ) mLevelValue=1;
|
504 |
|
|
|
505 |
|
|
float width = act.getScreenWidthInPixels();
|
506 |
|
|
int margin = (int)(width*RubikActivity.MARGIN);
|
507 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
508 |
|
|
|
509 |
|
|
LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
|
510 |
|
|
pM.setMargins(margin, 0, margin, margin);
|
511 |
|
|
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
|
512 |
|
|
pT.setMargins(margin, margin, margin, margin);
|
513 |
|
|
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
|
514 |
|
|
pB.setMargins(margin, margin, margin, 2*margin);
|
515 |
|
|
|
516 |
|
|
mPlayLayout.removeAllViews();
|
517 |
|
|
|
518 |
d7e539d0
|
Leszek Koltunski
|
RubikScores scores = RubikScores.getInstance();
|
519 |
|
|
|
520 |
0254cfd7
|
Leszek Koltunski
|
for(int i=0; i<maxLevel; i++)
|
521 |
011fcfe0
|
Leszek Koltunski
|
{
|
522 |
0254cfd7
|
Leszek Koltunski
|
final int but = i;
|
523 |
|
|
Button button = new Button(act);
|
524 |
|
|
button.setLayoutParams(i==0 ? pT : (i==maxLevel-1 ? pB : pM));
|
525 |
|
|
button.setText(levels[i]);
|
526 |
|
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
527 |
|
|
|
528 |
68f6046c
|
Leszek Koltunski
|
int icon = scores.isSolved(mObject, sizeIndex, i) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
529 |
d7e539d0
|
Leszek Koltunski
|
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
|
530 |
|
|
|
531 |
0254cfd7
|
Leszek Koltunski
|
button.setOnClickListener( new View.OnClickListener()
|
532 |
011fcfe0
|
Leszek Koltunski
|
{
|
533 |
0254cfd7
|
Leszek Koltunski
|
@Override
|
534 |
|
|
public void onClick(View v)
|
535 |
|
|
{
|
536 |
|
|
mPlayPopup.dismiss();
|
537 |
|
|
mLevelValue = but+1;
|
538 |
|
|
act.getPreRender().scrambleObject(mLevelValue);
|
539 |
|
|
}
|
540 |
|
|
});
|
541 |
011fcfe0
|
Leszek Koltunski
|
|
542 |
0254cfd7
|
Leszek Koltunski
|
mPlayLayout.addView(button);
|
543 |
|
|
}
|
544 |
53f23b64
|
Leszek Koltunski
|
}
|
545 |
|
|
|
546 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
547 |
|
|
|
548 |
dca3888a
|
Leszek Koltunski
|
public int getLevel()
|
549 |
211b48f2
|
Leszek Koltunski
|
{
|
550 |
85b09df4
|
Leszek Koltunski
|
return mLevelValue;
|
551 |
211b48f2
|
Leszek Koltunski
|
}
|
552 |
|
|
|
553 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
554 |
|
|
|
555 |
4888e97c
|
Leszek Koltunski
|
public int getObject()
|
556 |
211b48f2
|
Leszek Koltunski
|
{
|
557 |
4888e97c
|
Leszek Koltunski
|
return mObject;
|
558 |
211b48f2
|
Leszek Koltunski
|
}
|
559 |
|
|
|
560 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
561 |
|
|
|
562 |
4888e97c
|
Leszek Koltunski
|
public int getSize()
|
563 |
211b48f2
|
Leszek Koltunski
|
{
|
564 |
4888e97c
|
Leszek Koltunski
|
return mSize;
|
565 |
|
|
}
|
566 |
211b48f2
|
Leszek Koltunski
|
}
|