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 |
9439f455
|
Leszek Koltunski
|
import android.os.Build;
|
26 |
211b48f2
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
27 |
4c0cd600
|
Leszek Koltunski
|
import android.view.Gravity;
|
28 |
211b48f2
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
29 |
|
|
import android.view.View;
|
30 |
85b09df4
|
Leszek Koltunski
|
import android.widget.AdapterView;
|
31 |
|
|
import android.widget.ArrayAdapter;
|
32 |
211b48f2
|
Leszek Koltunski
|
import android.widget.Button;
|
33 |
|
|
import android.widget.ImageButton;
|
34 |
|
|
import android.widget.LinearLayout;
|
35 |
4c0cd600
|
Leszek Koltunski
|
import android.widget.PopupWindow;
|
36 |
66e777b0
|
Leszek Koltunski
|
import androidx.appcompat.widget.AppCompatSpinner;
|
37 |
211b48f2
|
Leszek Koltunski
|
|
38 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
39 |
|
|
import org.distorted.main.RubikActivity;
|
40 |
|
|
import org.distorted.objects.RubikObjectList;
|
41 |
211b48f2
|
Leszek Koltunski
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
85b09df4
|
Leszek Koltunski
|
public class RubikStatePlay extends RubikStateAbstract implements AdapterView.OnItemSelectedListener
|
45 |
211b48f2
|
Leszek Koltunski
|
{
|
46 |
85b09df4
|
Leszek Koltunski
|
private static final int DEF_LEVEL = 1;
|
47 |
|
|
public static final int DEF_OBJECT= RubikObjectList.CUBE.ordinal();
|
48 |
|
|
public static final int DEF_SIZE = 3;
|
49 |
211b48f2
|
Leszek Koltunski
|
|
50 |
4c0cd600
|
Leszek Koltunski
|
private ImageButton mObjButton;
|
51 |
85b09df4
|
Leszek Koltunski
|
private Button mBackButton, mSolveButton, mPlayButton;
|
52 |
4c0cd600
|
Leszek Koltunski
|
private PopupWindow mPopup;
|
53 |
4888e97c
|
Leszek Koltunski
|
private int mObject = DEF_OBJECT;
|
54 |
|
|
private int mSize = DEF_SIZE;
|
55 |
85b09df4
|
Leszek Koltunski
|
private int mLayoutWidth;
|
56 |
4c0cd600
|
Leszek Koltunski
|
private LinearLayout mLayout;
|
57 |
8e3898c8
|
Leszek Koltunski
|
private AppCompatSpinner mLevelSpinner;
|
58 |
|
|
private ArrayAdapter<String> mSpinnerAdapter;
|
59 |
85b09df4
|
Leszek Koltunski
|
private int mLevelValue;
|
60 |
211b48f2
|
Leszek Koltunski
|
|
61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
329c0aeb
|
Leszek Koltunski
|
void leaveState(RubikActivity act)
|
64 |
211b48f2
|
Leszek Koltunski
|
{
|
65 |
85b09df4
|
Leszek Koltunski
|
|
66 |
211b48f2
|
Leszek Koltunski
|
}
|
67 |
|
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
a6d3b158
|
Leszek Koltunski
|
void enterState(final RubikActivity act)
|
71 |
211b48f2
|
Leszek Koltunski
|
{
|
72 |
85b09df4
|
Leszek Koltunski
|
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
73 |
|
|
final float scale = metrics.density;
|
74 |
211b48f2
|
Leszek Koltunski
|
|
75 |
|
|
// TOP ////////////////////////////
|
76 |
7289fd6c
|
Leszek Koltunski
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
77 |
211b48f2
|
Leszek Koltunski
|
layoutTop.removeAllViews();
|
78 |
85b09df4
|
Leszek Koltunski
|
|
79 |
|
|
if( mObjButton ==null ) setupObjectButton(act,scale);
|
80 |
|
|
layoutTop.addView(mObjButton);
|
81 |
|
|
if( mLevelSpinner==null ) setupLevelSpinner(act,scale);
|
82 |
|
|
layoutTop.addView(mLevelSpinner);
|
83 |
|
|
if( mPlayButton ==null ) setupPlayButton(act,scale);
|
84 |
|
|
layoutTop.addView(mPlayButton);
|
85 |
211b48f2
|
Leszek Koltunski
|
|
86 |
|
|
// BOT ////////////////////////////
|
87 |
|
|
|
88 |
85b09df4
|
Leszek Koltunski
|
if( mSolveButton==null ) setupSolveButton(act,scale);
|
89 |
769d7b9f
|
Leszek Koltunski
|
|
90 |
4c0cd600
|
Leszek Koltunski
|
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
|
91 |
|
|
layoutLeft.removeAllViews();
|
92 |
85b09df4
|
Leszek Koltunski
|
layoutLeft.addView(mSolveButton);
|
93 |
4888e97c
|
Leszek Koltunski
|
|
94 |
769d7b9f
|
Leszek Koltunski
|
if( mBackButton==null ) setupBackButton(act,scale);
|
95 |
|
|
|
96 |
4c0cd600
|
Leszek Koltunski
|
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
|
97 |
|
|
layoutRight.removeAllViews();
|
98 |
|
|
layoutRight.addView(mBackButton);
|
99 |
211b48f2
|
Leszek Koltunski
|
|
100 |
769d7b9f
|
Leszek Koltunski
|
if( mPopup==null ) setupPopupWindow(act, scale);
|
101 |
|
|
}
|
102 |
211b48f2
|
Leszek Koltunski
|
|
103 |
769d7b9f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
4c0cd600
|
Leszek Koltunski
|
|
105 |
769d7b9f
|
Leszek Koltunski
|
private void setupObjectButton(final RubikActivity act, final float scale)
|
106 |
|
|
{
|
107 |
|
|
int padding = (int)(3*scale + 0.5f);
|
108 |
|
|
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
109 |
|
|
mObjButton = new ImageButton(act);
|
110 |
|
|
mObjButton.setLayoutParams(objectParams);
|
111 |
|
|
mObjButton.setPadding(padding,0,padding,0);
|
112 |
|
|
mObjButton.setImageResource(R.drawable.cube_menu);
|
113 |
|
|
|
114 |
|
|
mObjButton.setOnClickListener( new View.OnClickListener()
|
115 |
|
|
{
|
116 |
|
|
@Override
|
117 |
|
|
public void onClick(View view)
|
118 |
4c0cd600
|
Leszek Koltunski
|
{
|
119 |
a42e25a6
|
Leszek Koltunski
|
if( act.getPostRender().canPlay() )
|
120 |
|
|
{
|
121 |
|
|
int total = RubikObjectList.getTotal();
|
122 |
|
|
boolean vertical = act.isVertical();
|
123 |
|
|
mLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
|
124 |
4c0cd600
|
Leszek Koltunski
|
|
125 |
a42e25a6
|
Leszek Koltunski
|
int width = view.getWidth();
|
126 |
9439f455
|
Leszek Koltunski
|
int layhei = mLayoutWidth * (vertical? total:1);
|
127 |
a42e25a6
|
Leszek Koltunski
|
int laywid = mLayoutWidth * (vertical? 1:total);
|
128 |
4c0cd600
|
Leszek Koltunski
|
|
129 |
85b09df4
|
Leszek Koltunski
|
mPopup.showAsDropDown(view, (width-laywid)/2, 0, Gravity.LEFT);
|
130 |
9439f455
|
Leszek Koltunski
|
|
131 |
|
|
if( android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1 )
|
132 |
|
|
{
|
133 |
|
|
mPopup.update(view, laywid, layhei);
|
134 |
|
|
}
|
135 |
a42e25a6
|
Leszek Koltunski
|
}
|
136 |
769d7b9f
|
Leszek Koltunski
|
}
|
137 |
|
|
});
|
138 |
|
|
}
|
139 |
4c0cd600
|
Leszek Koltunski
|
|
140 |
85b09df4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141 |
|
|
|
142 |
|
|
private void setupLevelSpinner(final RubikActivity act, final float scale)
|
143 |
|
|
{
|
144 |
|
|
int spinnerPadding = (int)(scale* 10 + 0.5f);
|
145 |
|
|
int spinnerMargin = (int)(scale* 3 + 0.5f);
|
146 |
|
|
int spinnerLength = (int)(scale*150 + 0.5f);
|
147 |
|
|
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(spinnerLength,LinearLayout.LayoutParams.MATCH_PARENT);
|
148 |
|
|
spinnerLayoutParams.topMargin = spinnerMargin;
|
149 |
|
|
spinnerLayoutParams.bottomMargin = spinnerMargin;
|
150 |
|
|
spinnerLayoutParams.leftMargin = spinnerMargin;
|
151 |
|
|
spinnerLayoutParams.rightMargin = 2*spinnerMargin;
|
152 |
|
|
|
153 |
8e3898c8
|
Leszek Koltunski
|
mLevelSpinner = new AppCompatSpinner(act);
|
154 |
85b09df4
|
Leszek Koltunski
|
mLevelSpinner.setLayoutParams(spinnerLayoutParams);
|
155 |
|
|
mLevelSpinner.setPadding(spinnerPadding,0,spinnerPadding,0);
|
156 |
|
|
mLevelSpinner.setBackgroundResource(R.drawable.spinner);
|
157 |
|
|
mLevelSpinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
158 |
|
|
|
159 |
|
|
mLevelSpinner.setOnItemSelectedListener(this);
|
160 |
8e3898c8
|
Leszek Koltunski
|
int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize);
|
161 |
|
|
int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex);
|
162 |
|
|
String[] levels = new String[maxLevel];
|
163 |
85b09df4
|
Leszek Koltunski
|
|
164 |
8e3898c8
|
Leszek Koltunski
|
for(int i=0; i<maxLevel; i++)
|
165 |
85b09df4
|
Leszek Koltunski
|
{
|
166 |
|
|
levels[i] = act.getString(R.string.lv_placeholder,i+1);
|
167 |
|
|
}
|
168 |
|
|
|
169 |
c7f9e82d
|
Leszek Koltunski
|
if( mLevelValue>maxLevel ) mLevelValue=1;
|
170 |
|
|
|
171 |
8e3898c8
|
Leszek Koltunski
|
mSpinnerAdapter = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels);
|
172 |
|
|
mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
173 |
|
|
mLevelSpinner.setAdapter(mSpinnerAdapter);
|
174 |
85b09df4
|
Leszek Koltunski
|
mLevelSpinner.setSelection(mLevelValue-1);
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178 |
|
|
|
179 |
|
|
private void setupPlayButton(final RubikActivity act, final float scale)
|
180 |
|
|
{
|
181 |
|
|
int padding = (int)(3*scale + 0.5f);
|
182 |
|
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
183 |
|
|
mPlayButton = new Button(act);
|
184 |
|
|
mPlayButton.setLayoutParams(backParams);
|
185 |
|
|
mPlayButton.setPadding(padding,0,padding,0);
|
186 |
|
|
mPlayButton.setText(R.string.play);
|
187 |
|
|
|
188 |
|
|
mPlayButton.setOnClickListener( new View.OnClickListener()
|
189 |
|
|
{
|
190 |
|
|
@Override
|
191 |
|
|
public void onClick(View v)
|
192 |
|
|
{
|
193 |
|
|
act.getPostRender().scrambleObject(mLevelValue);
|
194 |
|
|
}
|
195 |
|
|
});
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199 |
|
|
|
200 |
|
|
private void setupSolveButton(final RubikActivity act, final float scale)
|
201 |
|
|
{
|
202 |
|
|
int padding = (int)(3*scale + 0.5f);
|
203 |
|
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
204 |
|
|
mSolveButton = new Button(act);
|
205 |
|
|
mSolveButton.setLayoutParams(backParams);
|
206 |
|
|
mSolveButton.setPadding(padding,0,padding,0);
|
207 |
|
|
mSolveButton.setText(R.string.solve);
|
208 |
|
|
|
209 |
|
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
210 |
|
|
{
|
211 |
|
|
@Override
|
212 |
|
|
public void onClick(View v)
|
213 |
|
|
{
|
214 |
|
|
act.getPostRender().solveObject();
|
215 |
|
|
}
|
216 |
|
|
});
|
217 |
|
|
}
|
218 |
|
|
|
219 |
769d7b9f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
220 |
4c0cd600
|
Leszek Koltunski
|
|
221 |
769d7b9f
|
Leszek Koltunski
|
private void setupBackButton(final RubikActivity act, final float scale)
|
222 |
|
|
{
|
223 |
|
|
int padding = (int)(3*scale + 0.5f);
|
224 |
|
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
225 |
|
|
mBackButton = new Button(act);
|
226 |
|
|
mBackButton.setLayoutParams(backParams);
|
227 |
|
|
mBackButton.setPadding(padding,0,padding,0);
|
228 |
|
|
mBackButton.setText(R.string.back);
|
229 |
a6d3b158
|
Leszek Koltunski
|
|
230 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
231 |
|
|
{
|
232 |
|
|
@Override
|
233 |
|
|
public void onClick(View v)
|
234 |
|
|
{
|
235 |
a42e25a6
|
Leszek Koltunski
|
if( act.getPostRender().canPlay() ) RubikState.goBack(act);
|
236 |
a6d3b158
|
Leszek Koltunski
|
}
|
237 |
|
|
});
|
238 |
211b48f2
|
Leszek Koltunski
|
}
|
239 |
|
|
|
240 |
4c0cd600
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
241 |
|
|
|
242 |
769d7b9f
|
Leszek Koltunski
|
private void setupPopupWindow(final RubikActivity act, final float scale)
|
243 |
4c0cd600
|
Leszek Koltunski
|
{
|
244 |
769d7b9f
|
Leszek Koltunski
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
245 |
|
|
final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
|
246 |
|
|
mLayout = layout.findViewById(R.id.popup);
|
247 |
|
|
|
248 |
|
|
mPopup = new PopupWindow(act);
|
249 |
|
|
mPopup.setContentView(layout);
|
250 |
|
|
mPopup.setFocusable(true);
|
251 |
|
|
int margin = (int)(5*scale + 0.5f);
|
252 |
|
|
|
253 |
|
|
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2);
|
254 |
|
|
int cubeWidth = bd.getIntrinsicWidth();
|
255 |
|
|
mLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f);
|
256 |
4c0cd600
|
Leszek Koltunski
|
|
257 |
769d7b9f
|
Leszek Koltunski
|
for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
|
258 |
|
|
{
|
259 |
53f23b64
|
Leszek Koltunski
|
final RubikObjectList list = RubikObjectList.getObject(object);
|
260 |
|
|
final int[] sizes = list.getSizes();
|
261 |
769d7b9f
|
Leszek Koltunski
|
int[] icons = list.getIconIDs();
|
262 |
|
|
int len = sizes.length;
|
263 |
|
|
final int obj = object;
|
264 |
|
|
|
265 |
|
|
for(int i=0; i<len; i++)
|
266 |
|
|
{
|
267 |
|
|
final int size = i;
|
268 |
|
|
|
269 |
|
|
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
|
270 |
|
|
p.setMargins(margin, margin, margin, margin);
|
271 |
|
|
|
272 |
|
|
ImageButton button = new ImageButton(act);
|
273 |
|
|
button.setLayoutParams(p);
|
274 |
4c0cd600
|
Leszek Koltunski
|
|
275 |
769d7b9f
|
Leszek Koltunski
|
button.setBackgroundResource(icons[i]);
|
276 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
277 |
|
|
{
|
278 |
|
|
@Override
|
279 |
|
|
public void onClick(View v)
|
280 |
|
|
{
|
281 |
a42e25a6
|
Leszek Koltunski
|
if( act.getPostRender().canPlay() && RubikState.getCurrentState()==RubikState.PLAY )
|
282 |
|
|
{
|
283 |
|
|
mObject = obj;
|
284 |
|
|
mSize = sizes[size];
|
285 |
2e8ec627
|
Leszek Koltunski
|
act.changeObject(list,sizes[size]);
|
286 |
7b7d65ce
|
Leszek Koltunski
|
adjustSpinner(act);
|
287 |
a42e25a6
|
Leszek Koltunski
|
}
|
288 |
8e3898c8
|
Leszek Koltunski
|
|
289 |
769d7b9f
|
Leszek Koltunski
|
mPopup.dismiss();
|
290 |
|
|
}
|
291 |
|
|
});
|
292 |
|
|
|
293 |
|
|
mLayout.addView(button);
|
294 |
|
|
}
|
295 |
|
|
}
|
296 |
4c0cd600
|
Leszek Koltunski
|
}
|
297 |
|
|
|
298 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
299 |
|
|
|
300 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
301 |
|
|
{
|
302 |
85b09df4
|
Leszek Koltunski
|
editor.putInt("statePlay_level" , mLevelValue);
|
303 |
4888e97c
|
Leszek Koltunski
|
editor.putInt("statePlay_object", mObject);
|
304 |
|
|
editor.putInt("statePlay_size" , mSize);
|
305 |
4c0cd600
|
Leszek Koltunski
|
|
306 |
85b09df4
|
Leszek Koltunski
|
mObjButton = null;
|
307 |
|
|
mBackButton = null;
|
308 |
|
|
mSolveButton = null;
|
309 |
|
|
mPlayButton = null;
|
310 |
|
|
mLevelSpinner= null;
|
311 |
4c0cd600
|
Leszek Koltunski
|
|
312 |
|
|
if( mPopup!=null )
|
313 |
|
|
{
|
314 |
|
|
mPopup.dismiss();
|
315 |
53f23b64
|
Leszek Koltunski
|
mPopup = null;
|
316 |
4c0cd600
|
Leszek Koltunski
|
}
|
317 |
211b48f2
|
Leszek Koltunski
|
}
|
318 |
|
|
|
319 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
320 |
|
|
|
321 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
322 |
|
|
{
|
323 |
85b09df4
|
Leszek Koltunski
|
mLevelValue = preferences.getInt("statePlay_level" , DEF_LEVEL );
|
324 |
|
|
mObject = preferences.getInt("statePlay_object", DEF_OBJECT);
|
325 |
|
|
mSize = preferences.getInt("statePlay_size" , DEF_SIZE );
|
326 |
211b48f2
|
Leszek Koltunski
|
}
|
327 |
|
|
|
328 |
53f23b64
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
329 |
|
|
|
330 |
7b7d65ce
|
Leszek Koltunski
|
public boolean setObjectAndSize(RubikActivity act, RubikObjectList obj, int size)
|
331 |
53f23b64
|
Leszek Koltunski
|
{
|
332 |
7b7d65ce
|
Leszek Koltunski
|
if( mObject!=obj.ordinal() || mSize != size )
|
333 |
|
|
{
|
334 |
|
|
boolean success = false;
|
335 |
53f23b64
|
Leszek Koltunski
|
|
336 |
7b7d65ce
|
Leszek Koltunski
|
for( int s: obj.getSizes() )
|
337 |
|
|
if( s==size )
|
338 |
|
|
{
|
339 |
|
|
success = true;
|
340 |
|
|
break;
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
if( success )
|
344 |
53f23b64
|
Leszek Koltunski
|
{
|
345 |
7b7d65ce
|
Leszek Koltunski
|
mObject = obj.ordinal();
|
346 |
|
|
mSize = size;
|
347 |
5f8c532e
|
Leszek Koltunski
|
|
348 |
|
|
if( mLevelSpinner!=null ) adjustSpinner(act);
|
349 |
53f23b64
|
Leszek Koltunski
|
}
|
350 |
|
|
|
351 |
7b7d65ce
|
Leszek Koltunski
|
return success;
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
return true;
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
358 |
|
|
|
359 |
|
|
private void adjustSpinner(RubikActivity act)
|
360 |
|
|
{
|
361 |
|
|
int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize);
|
362 |
|
|
int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex);
|
363 |
|
|
String[] levels = new String[maxLevel];
|
364 |
|
|
|
365 |
|
|
for(int i=0; i<maxLevel; i++)
|
366 |
53f23b64
|
Leszek Koltunski
|
{
|
367 |
7b7d65ce
|
Leszek Koltunski
|
levels[i] = act.getString(R.string.lv_placeholder,i+1);
|
368 |
53f23b64
|
Leszek Koltunski
|
}
|
369 |
|
|
|
370 |
7b7d65ce
|
Leszek Koltunski
|
mSpinnerAdapter = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels);
|
371 |
|
|
mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
372 |
|
|
mLevelSpinner.setAdapter(mSpinnerAdapter);
|
373 |
53f23b64
|
Leszek Koltunski
|
}
|
374 |
|
|
|
375 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
376 |
|
|
|
377 |
85b09df4
|
Leszek Koltunski
|
int getLevel()
|
378 |
211b48f2
|
Leszek Koltunski
|
{
|
379 |
85b09df4
|
Leszek Koltunski
|
return mLevelValue;
|
380 |
211b48f2
|
Leszek Koltunski
|
}
|
381 |
|
|
|
382 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
383 |
|
|
|
384 |
4888e97c
|
Leszek Koltunski
|
public int getObject()
|
385 |
211b48f2
|
Leszek Koltunski
|
{
|
386 |
4888e97c
|
Leszek Koltunski
|
return mObject;
|
387 |
211b48f2
|
Leszek Koltunski
|
}
|
388 |
|
|
|
389 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
390 |
|
|
|
391 |
4888e97c
|
Leszek Koltunski
|
public int getSize()
|
392 |
211b48f2
|
Leszek Koltunski
|
{
|
393 |
4888e97c
|
Leszek Koltunski
|
return mSize;
|
394 |
|
|
}
|
395 |
85b09df4
|
Leszek Koltunski
|
|
396 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
397 |
|
|
|
398 |
|
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
399 |
|
|
{
|
400 |
|
|
mLevelValue = pos+1;
|
401 |
|
|
}
|
402 |
|
|
|
403 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
404 |
|
|
|
405 |
|
|
public void onNothingSelected(AdapterView<?> parent) { }
|
406 |
211b48f2
|
Leszek Koltunski
|
}
|