Revision 8e3898c8
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
32 | 32 |
import android.widget.ImageButton; |
33 | 33 |
import android.widget.LinearLayout; |
34 | 34 |
import android.widget.PopupWindow; |
35 |
import android.widget.Spinner;
|
|
35 |
import android.support.v7.widget.AppCompatSpinner;
|
|
36 | 36 |
|
37 | 37 |
import org.distorted.main.R; |
38 | 38 |
import org.distorted.main.RubikActivity; |
... | ... | |
43 | 43 |
public class RubikStatePlay extends RubikStateAbstract implements AdapterView.OnItemSelectedListener |
44 | 44 |
{ |
45 | 45 |
private static final int DEF_LEVEL = 1; |
46 |
public static final int MAX_LEVEL = 18; |
|
47 | 46 |
public static final int DEF_OBJECT= RubikObjectList.CUBE.ordinal(); |
48 | 47 |
public static final int DEF_SIZE = 3; |
49 | 48 |
|
... | ... | |
54 | 53 |
private int mSize = DEF_SIZE; |
55 | 54 |
private int mLayoutWidth; |
56 | 55 |
private LinearLayout mLayout; |
57 |
private Spinner mLevelSpinner; |
|
56 |
private AppCompatSpinner mLevelSpinner; |
|
57 |
private ArrayAdapter<String> mSpinnerAdapter; |
|
58 | 58 |
private int mLevelValue; |
59 | 59 |
|
60 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
143 | 143 |
spinnerLayoutParams.leftMargin = spinnerMargin; |
144 | 144 |
spinnerLayoutParams.rightMargin = 2*spinnerMargin; |
145 | 145 |
|
146 |
mLevelSpinner = new Spinner(act); |
|
146 |
mLevelSpinner = new AppCompatSpinner(act);
|
|
147 | 147 |
mLevelSpinner.setLayoutParams(spinnerLayoutParams); |
148 | 148 |
mLevelSpinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
149 | 149 |
mLevelSpinner.setBackgroundResource(R.drawable.spinner); |
150 | 150 |
mLevelSpinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
151 | 151 |
|
152 | 152 |
mLevelSpinner.setOnItemSelectedListener(this); |
153 |
String[] levels = new String[MAX_LEVEL]; |
|
153 |
int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize); |
|
154 |
int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex); |
|
155 |
String[] levels = new String[maxLevel]; |
|
154 | 156 |
|
155 |
for(int i=0; i<MAX_LEVEL; i++)
|
|
157 |
for(int i=0; i<maxLevel; i++)
|
|
156 | 158 |
{ |
157 | 159 |
levels[i] = act.getString(R.string.lv_placeholder,i+1); |
158 | 160 |
} |
159 | 161 |
|
160 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels);
|
|
161 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
162 |
mLevelSpinner.setAdapter(adapterType);
|
|
162 |
mSpinnerAdapter = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels);
|
|
163 |
mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
164 |
mLevelSpinner.setAdapter(mSpinnerAdapter);
|
|
163 | 165 |
mLevelSpinner.setSelection(mLevelValue-1); |
164 | 166 |
} |
165 | 167 |
|
... | ... | |
272 | 274 |
mObject = obj; |
273 | 275 |
mSize = sizes[size]; |
274 | 276 |
act.changeObject(list,sizes[size],null); |
277 |
|
|
278 |
int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize); |
|
279 |
int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex); |
|
280 |
String[] levels = new String[maxLevel]; |
|
281 |
|
|
282 |
for(int i=0; i<maxLevel; i++) |
|
283 |
{ |
|
284 |
levels[i] = act.getString(R.string.lv_placeholder,i+1); |
|
285 |
} |
|
286 |
|
|
287 |
mSpinnerAdapter = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels); |
|
288 |
mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
289 |
mLevelSpinner.setAdapter(mSpinnerAdapter); |
|
275 | 290 |
} |
291 |
|
|
276 | 292 |
mPopup.dismiss(); |
277 | 293 |
} |
278 | 294 |
}); |
Also available in: Unified diff
Each object size now has its own number of levels (not always 18!)