Revision a7d8c3cd
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/config/ConfigScreen.java | ||
---|---|---|
33 | 33 |
import android.widget.TextView; |
34 | 34 |
|
35 | 35 |
import org.distorted.objectlib.main.ObjectControl; |
36 |
import org.distorted.objectlib.main.ObjectType; |
|
37 | 36 |
|
38 | 37 |
import org.distorted.helpers.TransparentImageButton; |
39 | 38 |
import org.distorted.main.R; |
40 | 39 |
import org.distorted.main.RubikActivity; |
40 |
import org.distorted.objects.RubikObject; |
|
41 |
import org.distorted.objects.RubikObjectList; |
|
41 | 42 |
|
42 | 43 |
import static android.view.View.inflate; |
43 |
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS; |
|
44 | 44 |
|
45 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 46 |
|
... | ... | |
97 | 97 |
colSpecs[col] = GridLayout.spec(col); |
98 | 98 |
} |
99 | 99 |
|
100 |
for(int object = 0; object< NUM_OBJECTS; object++) |
|
100 |
int numObjects = RubikObjectList.getNumObjects(); |
|
101 |
|
|
102 |
for(int object=0; object<numObjects; object++) |
|
101 | 103 |
{ |
102 | 104 |
final int ordinal = object; |
103 |
ObjectType type = ObjectType.getObject(ordinal);
|
|
105 |
RubikObject rubikObject = RubikObjectList.getObject(ordinal);
|
|
104 | 106 |
int iconSize = RubikActivity.getDrawableSize(); |
105 |
int icons = type.getIconID(iconSize);
|
|
107 |
int icons = rubikObject.getIconID(iconSize);
|
|
106 | 108 |
int row = object/NUM_COLUMNS; |
107 | 109 |
|
108 | 110 |
ImageButton button = new ImageButton(act); |
... | ... | |
115 | 117 |
if( act.getControl().isUINotBlocked() && mObjectOrdinal!=ordinal ) |
116 | 118 |
{ |
117 | 119 |
mObjectOrdinal = ordinal; |
118 |
act.changeObject(type);
|
|
119 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,NUM_OBJECTS));
|
|
120 |
act.changeObject(rubikObject);
|
|
121 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,numObjects));
|
|
120 | 122 |
mPane.updatePane(act,mObjectOrdinal); |
121 | 123 |
} |
122 | 124 |
|
... | ... | |
234 | 236 |
|
235 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
236 | 238 |
|
237 |
private void prevObject(ConfigActivity act) |
|
239 |
private void prevObject(ConfigActivity act, int numObjects)
|
|
238 | 240 |
{ |
239 | 241 |
mObjectOrdinal--; |
240 |
if( mObjectOrdinal<0 ) mObjectOrdinal=NUM_OBJECTS-1;
|
|
242 |
if( mObjectOrdinal<0 ) mObjectOrdinal=numObjects-1;
|
|
241 | 243 |
|
242 |
ObjectType type = ObjectType.getObject(mObjectOrdinal);
|
|
243 |
act.changeObject(type);
|
|
244 |
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
|
245 |
act.changeObject(object);
|
|
244 | 246 |
|
245 | 247 |
mPane.updatePane(act,mObjectOrdinal); |
246 | 248 |
} |
247 | 249 |
|
248 | 250 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
249 | 251 |
|
250 |
private void nextObject(ConfigActivity act) |
|
252 |
private void nextObject(ConfigActivity act, int numObjects)
|
|
251 | 253 |
{ |
252 | 254 |
mObjectOrdinal++; |
253 |
if( mObjectOrdinal>=NUM_OBJECTS ) mObjectOrdinal=0;
|
|
255 |
if( mObjectOrdinal>=numObjects ) mObjectOrdinal=0;
|
|
254 | 256 |
|
255 |
ObjectType type = ObjectType.getObject(mObjectOrdinal);
|
|
256 |
act.changeObject(type);
|
|
257 |
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
|
258 |
act.changeObject(object);
|
|
257 | 259 |
|
258 | 260 |
mPane.updatePane(act,mObjectOrdinal); |
259 | 261 |
} |
... | ... | |
271 | 273 |
@Override |
272 | 274 |
public void onClick(View v) |
273 | 275 |
{ |
274 |
prevObject(act); |
|
275 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,NUM_OBJECTS)); |
|
276 |
int numObjects = RubikObjectList.getNumObjects(); |
|
277 |
prevObject(act,numObjects); |
|
278 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,numObjects)); |
|
276 | 279 |
} |
277 | 280 |
}); |
278 | 281 |
} |
... | ... | |
290 | 293 |
@Override |
291 | 294 |
public void onClick(View v) |
292 | 295 |
{ |
293 |
nextObject(act); |
|
294 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,NUM_OBJECTS)); |
|
296 |
int numObjects = RubikObjectList.getNumObjects(); |
|
297 |
nextObject(act,numObjects); |
|
298 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,numObjects)); |
|
295 | 299 |
} |
296 | 300 |
}); |
297 | 301 |
} |
298 | 302 |
|
299 | 303 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
300 | 304 |
|
301 |
private void setupTextView(final ConfigActivity act, final float width) |
|
305 |
private void setupTextView(final ConfigActivity act, final float width, int numObjects)
|
|
302 | 306 |
{ |
303 | 307 |
int padding = (int)(width*RubikActivity.PADDING); |
304 | 308 |
int margin = (int)(width*RubikActivity.MARGIN); |
... | ... | |
314 | 318 |
mMovesText.setPadding(padding,0,padding,0); |
315 | 319 |
mMovesText.setGravity(Gravity.CENTER); |
316 | 320 |
mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
317 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,NUM_OBJECTS));
|
|
321 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,numObjects));
|
|
318 | 322 |
} |
319 | 323 |
|
320 | 324 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
321 | 325 |
|
322 | 326 |
void onAttachedToWindow(final ConfigActivity act, final int objectOrdinal) |
323 | 327 |
{ |
328 |
int numObjects = RubikObjectList.getNumObjects(); |
|
324 | 329 |
int width = act.getScreenWidthInPixels(); |
325 | 330 |
mBarHeight = act.getHeightBar(); |
326 | 331 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
327 | 332 |
|
328 |
mRowCount = (NUM_OBJECTS + NUM_COLUMNS-1) / NUM_COLUMNS;
|
|
333 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
|
|
329 | 334 |
mColCount = NUM_COLUMNS; |
330 | 335 |
|
331 | 336 |
mObjectOrdinal = objectOrdinal; |
... | ... | |
344 | 349 |
setupObjectButton(act,width); |
345 | 350 |
setupPrevButton(act); |
346 | 351 |
setupNextButton(act); |
347 |
setupTextView(act,width); |
|
352 |
setupTextView(act,width,numObjects);
|
|
348 | 353 |
setupBackButton(act); |
349 | 354 |
|
350 | 355 |
layoutLeft.addView(mObjectButton); |
Also available in: Unified diff
Progress replacing the enum ObjetType with the class RubikObjectList.