Revision 4888e97c
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/uistate/RubikStatePlay.java | ||
---|---|---|
43 | 43 |
private static final int MIN_SCRAMBLE = 1; |
44 | 44 |
private static final int DEF_SCRAMBLE = 1; |
45 | 45 |
public static final int MAX_SCRAMBLE = 18; |
46 |
private static final int DEF_BUTTON = RubikObjectList.CUBE3.ordinal(); |
|
46 |
private static final int DEF_OBJECT = RubikObjectList.CUBE.ordinal(); |
|
47 |
private static final int DEF_SIZE = 1; // i.e. the second from the list of CUBE's sizes |
|
47 | 48 |
|
48 | 49 |
private HorizontalNumberPicker mPicker; |
49 | 50 |
private int mPickerValue; |
50 |
private int mButton = DEF_BUTTON; |
|
51 |
private int mObject = DEF_OBJECT; |
|
52 |
private int mSize = DEF_SIZE; |
|
51 | 53 |
|
52 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
53 | 55 |
|
... | ... | |
79 | 81 |
int padding = (int)(3*scale + 0.5f); |
80 | 82 |
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(size,size); |
81 | 83 |
|
82 |
for(int i = 0; i< RubikObjectList.LENGTH; i++)
|
|
84 |
for(int i=0; i< RubikObjectList.NUM_OBJECTS; i++)
|
|
83 | 85 |
{ |
84 |
ImageButton button = new ImageButton(act); |
|
85 |
button.setLayoutParams(params); |
|
86 |
button.setId(i); |
|
87 |
button.setPadding(padding,0,padding,0); |
|
88 |
int iconID = RubikObjectList.getObject(i).getIconID(); |
|
89 |
button.setImageResource(iconID); |
|
90 |
button.setOnClickListener(act); |
|
91 |
layoutBot.addView(button); |
|
86 |
int[] iconIDs = RubikObjectList.getObject(i).getIconIDs(); |
|
87 |
int len = iconIDs.length; |
|
88 |
|
|
89 |
for(int s=0; s<len; s++) |
|
90 |
{ |
|
91 |
ImageButton button = new ImageButton(act); |
|
92 |
button.setLayoutParams(params); |
|
93 |
button.setId(RubikObjectList.pack(i,s)); |
|
94 |
button.setPadding(padding,0,padding,0); |
|
95 |
button.setImageResource(iconIDs[s]); |
|
96 |
button.setOnClickListener(act); |
|
97 |
layoutBot.addView(button); |
|
98 |
} |
|
92 | 99 |
} |
93 | 100 |
|
94 | 101 |
ViewGroup.LayoutParams params2 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,size); |
... | ... | |
101 | 108 |
button.setOnClickListener(act); |
102 | 109 |
layoutBot.addView(button); |
103 | 110 |
|
104 |
markButton(act,mButton);
|
|
111 |
markButton(act,mObject,mSize);
|
|
105 | 112 |
|
106 | 113 |
mPicker = act.findViewById(R.id.rubikNumberPicker); |
107 | 114 |
|
... | ... | |
119 | 126 |
{ |
120 | 127 |
if( mPicker!=null ) |
121 | 128 |
{ |
122 |
editor.putInt("scramble", mPicker.getValue() ); |
|
129 |
editor.putInt("statePlay_scramble", mPicker.getValue() );
|
|
123 | 130 |
} |
124 | 131 |
|
125 |
editor.putInt("button", mButton); |
|
132 |
editor.putInt("statePlay_object", mObject); |
|
133 |
editor.putInt("statePlay_size" , mSize); |
|
126 | 134 |
} |
127 | 135 |
|
128 | 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
129 | 137 |
|
130 | 138 |
public void restorePreferences(SharedPreferences preferences) |
131 | 139 |
{ |
132 |
mPickerValue= preferences.getInt("scramble", DEF_SCRAMBLE); |
|
133 |
mButton = preferences.getInt("button" , DEF_BUTTON ); |
|
140 |
mPickerValue= preferences.getInt("statePlay_scramble", DEF_SCRAMBLE); |
|
141 |
mObject = preferences.getInt("statePlay_object" , DEF_OBJECT ); |
|
142 |
mSize = preferences.getInt("statePlay_size" , DEF_SIZE ); |
|
134 | 143 |
} |
135 | 144 |
|
136 | 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
142 | 151 |
|
143 | 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
144 | 153 |
|
145 |
public int getButton()
|
|
154 |
public int getObject()
|
|
146 | 155 |
{ |
147 |
return mButton;
|
|
156 |
return mObject;
|
|
148 | 157 |
} |
149 | 158 |
|
150 | 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
151 | 160 |
|
152 |
public void markButton(RubikActivity act, int button)
|
|
161 |
public int getSize()
|
|
153 | 162 |
{ |
154 |
mButton = button; |
|
163 |
return mSize; |
|
164 |
} |
|
165 |
|
|
166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
167 |
|
|
168 |
public void markButton(RubikActivity act, int object, int size) |
|
169 |
{ |
|
170 |
mObject = object; |
|
171 |
mSize = size; |
|
172 |
|
|
173 |
int lookingFor = RubikObjectList.pack(object,size); |
|
174 |
int len = RubikObjectList.getTotal(); |
|
155 | 175 |
|
156 |
for(int b = 0; b< RubikObjectList.LENGTH; b++)
|
|
176 |
for(int button=0; button<len; button++)
|
|
157 | 177 |
{ |
158 |
Drawable d = act.findViewById(b).getBackground(); |
|
178 |
Drawable d = act.findViewById(button).getBackground();
|
|
159 | 179 |
|
160 |
if( b==button )
|
|
180 |
if( button==lookingFor )
|
|
161 | 181 |
{ |
162 | 182 |
d.setColorFilter(ContextCompat.getColor(act,R.color.red), PorterDuff.Mode.MULTIPLY); |
163 | 183 |
} |
Also available in: Unified diff
Major restructuring around making it possible to include different kinds of RubikObjects in the UI.