Revision 22fdfc36
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
122 | 122 |
{ |
123 | 123 |
Bundle args = new Bundle(); |
124 | 124 |
|
125 |
args.putInt("sizechangePos" , mSizeChangePos );
|
|
126 |
args.putInt("solvePos" , mSolvePos );
|
|
127 |
args.putInt("scramblePos" , mScramblePos );
|
|
128 |
args.putInt("sizechangeType", mSizeChangeType);
|
|
129 |
args.putInt("solveType" , mSolveType );
|
|
130 |
args.putInt("scrambleType" , mScrambleType );
|
|
125 |
args.putInt("SIZECHANGE_Pos" , mSizeChangePos );
|
|
126 |
args.putInt("SOLVE_Pos" , mSolvePos );
|
|
127 |
args.putInt("SCRAMBLE_Pos" , mScramblePos );
|
|
128 |
args.putInt("SIZECHANGE_Type", mSizeChangeType);
|
|
129 |
args.putInt("SOLVE_Type" , mSolveType );
|
|
130 |
args.putInt("SCRAMBLE_Type" , mScrambleType );
|
|
131 | 131 |
|
132 | 132 |
RubikSettings settings = new RubikSettings(); |
133 | 133 |
settings.setArguments(args); |
... | ... | |
162 | 162 |
|
163 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
164 | 164 |
|
165 |
public void onComplete(int sizeP, int unscP, int scraP, int sizeT, int unscT, int scraT )
|
|
165 |
public void onComplete(int sizeP, int solvP, int scraP, int sizeT, int solvT, int scraT )
|
|
166 | 166 |
{ |
167 | 167 |
mSizeChangePos = sizeP; |
168 |
mSolvePos = unscP;
|
|
168 |
mSolvePos = solvP;
|
|
169 | 169 |
mScramblePos = scraP; |
170 | 170 |
mSizeChangeType= sizeT; |
171 |
mSolveType = unscT;
|
|
171 |
mSolveType = solvT;
|
|
172 | 172 |
mScrambleType = scraT; |
173 | 173 |
|
174 | 174 |
applyPreferences(); |
... | ... | |
224 | 224 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
225 | 225 |
SharedPreferences.Editor editor = preferences.edit(); |
226 | 226 |
|
227 |
editor.putInt("sizechangePos" , mSizeChangePos );
|
|
228 |
editor.putInt("solvePos" , mSolvePos );
|
|
229 |
editor.putInt("scramblePos" , mScramblePos );
|
|
230 |
editor.putInt("sizechangeType", mSizeChangeType);
|
|
231 |
editor.putInt("solveType" , mSolveType );
|
|
232 |
editor.putInt("scrambleType" , mScrambleType );
|
|
233 |
editor.putInt("scramble" , mPicker.getValue() ); |
|
227 |
editor.putInt("SIZECHANGE_Pos" , mSizeChangePos );
|
|
228 |
editor.putInt("SOLVE_Pos" , mSolvePos );
|
|
229 |
editor.putInt("SCRAMBLE_Pos" , mScramblePos );
|
|
230 |
editor.putInt("SIZECHANGE_Type", mSizeChangeType);
|
|
231 |
editor.putInt("SOLVE_Type" , mSolveType );
|
|
232 |
editor.putInt("SCRAMBLE_Type" , mScrambleType );
|
|
233 |
editor.putInt("scramble" , mPicker.getValue() );
|
|
234 | 234 |
|
235 | 235 |
editor.apply(); |
236 | 236 |
} |
... | ... | |
241 | 241 |
{ |
242 | 242 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
243 | 243 |
|
244 |
mSizeChangePos = preferences.getInt("sizechangePos" , DEFAULT_SIZECHANGE_POS );
|
|
245 |
mSolvePos = preferences.getInt("solvePos" , DEFAULT_SOLVE_POS );
|
|
246 |
mScramblePos = preferences.getInt("scramblePos" , DEFAULT_SCRAMBLE_POS );
|
|
247 |
mSizeChangeType= preferences.getInt("sizechangeType", DEFAULT_SIZECHANGE_TYPE);
|
|
248 |
mSolveType = preferences.getInt("solveType" , DEFAULT_SOLVE_TYPE );
|
|
249 |
mScrambleType = preferences.getInt("scrambleType" , DEFAULT_SCRAMBLE_TYPE );
|
|
250 |
int scramble = preferences.getInt("scramble" , MIN_SCRAMBLE ); |
|
244 |
mSizeChangePos = preferences.getInt("SIZECHANGE_Pos" , DEFAULT_SIZECHANGE_POS );
|
|
245 |
mSolvePos = preferences.getInt("SOLVE_Pos" , DEFAULT_SOLVE_POS );
|
|
246 |
mScramblePos = preferences.getInt("SCRAMBLE_Pos" , DEFAULT_SCRAMBLE_POS );
|
|
247 |
mSizeChangeType= preferences.getInt("SIZECHANGE_Type", DEFAULT_SIZECHANGE_TYPE);
|
|
248 |
mSolveType = preferences.getInt("SOLVE_Type" , DEFAULT_SOLVE_TYPE );
|
|
249 |
mScrambleType = preferences.getInt("SCRAMBLE_Type" , DEFAULT_SCRAMBLE_TYPE );
|
|
250 |
int scramble = preferences.getInt("scramble" , MIN_SCRAMBLE );
|
|
251 | 251 |
|
252 | 252 |
mPicker.setValue(scramble); |
253 | 253 |
} |
src/main/java/org/distorted/magic/RubikSettings.java | ||
---|---|---|
28 | 28 |
import android.support.v4.app.FragmentActivity; |
29 | 29 |
import android.support.v7.app.AlertDialog; |
30 | 30 |
import android.support.v7.app.AppCompatDialogFragment; |
31 |
import android.view.Gravity; |
|
31 | 32 |
import android.view.LayoutInflater; |
32 | 33 |
import android.view.View; |
33 | 34 |
import android.widget.AdapterView; |
34 | 35 |
import android.widget.ArrayAdapter; |
36 |
import android.widget.LinearLayout; |
|
35 | 37 |
import android.widget.SeekBar; |
36 | 38 |
import android.widget.Spinner; |
37 | 39 |
import android.widget.TextView; |
38 | 40 |
|
39 |
import org.distorted.effect.SizeChangeEffect; |
|
40 |
import org.distorted.effect.SolveEffect; |
|
41 |
import org.distorted.effect.ScrambleEffect; |
|
42 |
|
|
43 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 42 |
|
45 | 43 |
public class RubikSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener |
46 | 44 |
{ |
47 | 45 |
public interface OnCompleteListener |
48 | 46 |
{ |
49 |
void onComplete(int sizeP, int uscrP, int scraP, int sizeT, int unscT, int scraT);
|
|
47 |
void onComplete(int sizeP, int solvP, int scraP, int sizeT, int solvT, int scraT);
|
|
50 | 48 |
} |
51 | 49 |
|
52 | 50 |
private OnCompleteListener mListener; |
53 |
private int mSizeChangePos, mSolvePos, mScramblePos; |
|
54 |
private int mSizeChangeType, mSolveType, mScrambleType; |
|
55 |
private TextView mSizeChangeDuration, mSolveDuration, mScrambleDuration; |
|
51 |
|
|
52 |
private TextView[] mDurationText; |
|
53 |
private int[] mSeekBarID; |
|
54 |
private int[] mSpinnerID; |
|
55 |
private int[] mPos; |
|
56 |
private int[] mType; |
|
57 |
|
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
public RubikSettings() |
|
61 |
{ |
|
62 |
mDurationText = new TextView[RubikSettingsEnum.LENGTH]; |
|
63 |
mSeekBarID = new int[RubikSettingsEnum.LENGTH]; |
|
64 |
mSpinnerID = new int[RubikSettingsEnum.LENGTH]; |
|
65 |
mPos = new int[RubikSettingsEnum.LENGTH]; |
|
66 |
mType = new int[RubikSettingsEnum.LENGTH]; |
|
67 |
} |
|
56 | 68 |
|
57 | 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
58 | 70 |
|
... | ... | |
80 | 92 |
|
81 | 93 |
Bundle args = getArguments(); |
82 | 94 |
|
83 |
try |
|
84 |
{ |
|
85 |
mSizeChangePos = args.getInt("sizechangePos"); |
|
86 |
mSolvePos = args.getInt("solvePos"); |
|
87 |
mScramblePos = args.getInt("scramblePos"); |
|
88 |
mSizeChangeType= args.getInt("sizechangeType"); |
|
89 |
mSolveType = args.getInt("solveType"); |
|
90 |
mScrambleType = args.getInt("scrambleType"); |
|
91 |
} |
|
92 |
catch(NullPointerException ex) |
|
95 |
String name; |
|
96 |
|
|
97 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
93 | 98 |
{ |
94 |
mSizeChangePos = RubikActivity.DEFAULT_SIZECHANGE_POS; |
|
95 |
mSolvePos = RubikActivity.DEFAULT_SOLVE_POS; |
|
96 |
mScramblePos = RubikActivity.DEFAULT_SCRAMBLE_POS; |
|
97 |
mSizeChangeType= RubikActivity.DEFAULT_SIZECHANGE_TYPE; |
|
98 |
mSolveType = RubikActivity.DEFAULT_SOLVE_TYPE; |
|
99 |
mScrambleType = RubikActivity.DEFAULT_SCRAMBLE_TYPE; |
|
99 |
RubikSettingsEnum rse = RubikSettingsEnum.getEnum(i); |
|
100 |
name = rse.name(); |
|
101 |
|
|
102 |
try |
|
103 |
{ |
|
104 |
mPos[i] = args.getInt(name+"_Pos" ); |
|
105 |
mType[i] = args.getInt(name+"_Type"); |
|
106 |
} |
|
107 |
catch(NullPointerException ex) |
|
108 |
{ |
|
109 |
mPos[i] = rse.getDefaultPos(); |
|
110 |
mType[i] = rse.getDefaultType(); |
|
111 |
} |
|
100 | 112 |
} |
101 | 113 |
} |
102 | 114 |
|
... | ... | |
123 | 135 |
final View view = inflater.inflate(R.layout.settings, null); |
124 | 136 |
builder.setView(view); |
125 | 137 |
|
126 |
mSizeChangeDuration = view.findViewById(R.id.sizechangeDurationText); |
|
127 |
mSolveDuration = view.findViewById(R.id.solveDurationText); |
|
128 |
mScrambleDuration = view.findViewById(R.id.scrambleDurationText); |
|
129 |
|
|
130 |
/// SIZE CHANGE /////////////////////////////////////////////////////// |
|
131 |
Spinner sizechangeTypeSpinner = view.findViewById(R.id.sizechangeType); |
|
138 |
LinearLayout linearLayout = view.findViewById(R.id.main_settings_layout); |
|
132 | 139 |
|
133 |
if( sizechangeTypeSpinner!=null )
|
|
140 |
if( linearLayout!=null )
|
|
134 | 141 |
{ |
135 |
sizechangeTypeSpinner.setOnItemSelectedListener(this); |
|
136 |
String[] appear = SizeChangeEffect.getNames(); |
|
137 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); |
|
138 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
139 |
sizechangeTypeSpinner.setAdapter(adapterType); |
|
140 |
|
|
141 |
if(mSizeChangeType>=0 && mSizeChangeType<appear.length) |
|
142 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
142 | 143 |
{ |
143 |
sizechangeTypeSpinner.setSelection(mSizeChangeType);
|
|
144 |
createSettingsSection(act,linearLayout,i);
|
|
144 | 145 |
} |
145 | 146 |
} |
146 | 147 |
else |
147 | 148 |
{ |
148 |
android.util.Log.e("dialog", "SIZE CHANGE TYPE SPINNER NULL!!");
|
|
149 |
android.util.Log.e("settings", "linearLayout NULL!");
|
|
149 | 150 |
} |
150 | 151 |
|
151 |
SeekBar sizechangeBar = view.findViewById(R.id.sizechangeDuration); |
|
152 |
sizechangeBar.setOnSeekBarChangeListener(this); |
|
153 |
sizechangeBar.setProgress(mSizeChangePos); |
|
152 |
return builder.create(); |
|
153 |
} |
|
154 | 154 |
|
155 |
/// SOLVE ///////////////////////////////////////////////////////////// |
|
156 |
Spinner solveTypeSpinner = view.findViewById(R.id.solveType); |
|
155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
157 | 156 |
|
158 |
if( solveTypeSpinner!=null )
|
|
157 |
private void createSettingsSection(FragmentActivity act, LinearLayout layout, int index)
|
|
159 | 158 |
{ |
160 |
solveTypeSpinner.setOnItemSelectedListener(this); |
|
161 |
String[] solve = SolveEffect.getNames(); |
|
162 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, solve); |
|
159 |
RubikSettingsEnum rsEnum = RubikSettingsEnum.getEnum(index); |
|
160 |
float scale = act.getResources().getDisplayMetrics().density; |
|
161 |
|
|
162 |
///// TEXT /////////////////////////////////////////////////////////////////////////// |
|
163 |
|
|
164 |
int layoutHeight = (int)(scale*48 + 0.5f); |
|
165 |
int padding = (int)(scale*15 + 0.5f); |
|
166 |
|
|
167 |
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); |
|
168 |
|
|
169 |
TextView textView = new TextView(act); |
|
170 |
textView.setText(rsEnum.getText()); |
|
171 |
textView.setLayoutParams(textParams); |
|
172 |
textView.setGravity(Gravity.START|Gravity.CENTER); |
|
173 |
textView.setPadding(padding,0,padding,0); |
|
174 |
textView.setTextAppearance(android.R.style.TextAppearance_Medium); |
|
175 |
layout.addView(textView); |
|
176 |
|
|
177 |
///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// |
|
178 |
|
|
179 |
int margin = (int)(scale*10 + 0.5f); |
|
180 |
int color = act.getResources().getColor(R.color.grey); |
|
181 |
LinearLayout outerLayout = new LinearLayout(act); |
|
182 |
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); |
|
183 |
outerLayoutParams.bottomMargin = margin; |
|
184 |
outerLayoutParams.leftMargin = margin; |
|
185 |
outerLayoutParams.rightMargin = margin; |
|
186 |
|
|
187 |
outerLayout.setLayoutParams(outerLayoutParams); |
|
188 |
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
189 |
outerLayout.setBackgroundColor(color); |
|
190 |
outerLayout.setOrientation(LinearLayout.VERTICAL); |
|
191 |
layout.addView(outerLayout); |
|
192 |
|
|
193 |
///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// |
|
194 |
|
|
195 |
int innerLayout1Height = (int)(scale*36 + 0.5f); |
|
196 |
LinearLayout innerLayout1 = new LinearLayout(act); |
|
197 |
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); |
|
198 |
|
|
199 |
innerLayout1.setLayoutParams(innerLayout1Params); |
|
200 |
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
201 |
innerLayout1.setOrientation(LinearLayout.HORIZONTAL); |
|
202 |
outerLayout.addView(innerLayout1); |
|
203 |
|
|
204 |
///// STUFF INSIDE INNER LAYOUT1 ///////////////////////////////////////////////////// |
|
205 |
|
|
206 |
int text1Padding = (int)(scale*5 + 0.5f); |
|
207 |
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
208 |
|
|
209 |
TextView text1View = new TextView(act); |
|
210 |
text1View.setText(R.string.duration); |
|
211 |
text1View.setLayoutParams(text1LayoutParams); |
|
212 |
text1View.setGravity(Gravity.START|Gravity.CENTER); |
|
213 |
text1View.setPadding(text1Padding,0,text1Padding,0); |
|
214 |
text1View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
215 |
innerLayout1.addView(text1View); |
|
216 |
////////////////////////////////////////////////////////////////// |
|
217 |
int text2Padding = (int)(scale*5 + 0.5f); |
|
218 |
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
219 |
|
|
220 |
mDurationText[index] = new TextView(act); |
|
221 |
mDurationText[index].setLayoutParams(text2LayoutParams); |
|
222 |
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER); |
|
223 |
mDurationText[index].setPadding(text2Padding,0,text2Padding,0); |
|
224 |
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small); |
|
225 |
innerLayout1.addView(mDurationText[index]); |
|
226 |
////////////////////////////////////////////////////////////////// |
|
227 |
int seekPadding = (int)(scale*10 + 0.5f); |
|
228 |
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
229 |
|
|
230 |
SeekBar seekBar = new SeekBar(act); |
|
231 |
seekBar.setLayoutParams(seekLayoutParams); |
|
232 |
seekBar.setPadding(seekPadding,0,seekPadding,0); |
|
233 |
seekBar.setId(index); |
|
234 |
innerLayout1.addView(seekBar); |
|
235 |
|
|
236 |
mSeekBarID[index] = seekBar.getId(); |
|
237 |
|
|
238 |
seekBar.setOnSeekBarChangeListener(this); |
|
239 |
seekBar.setProgress(mPos[index]); |
|
240 |
|
|
241 |
///// INNER LAYOUT2 ////////////////////////////////////////////////////////////////// |
|
242 |
|
|
243 |
int innerLayout2Height = (int)(scale*36 + 0.5f); |
|
244 |
LinearLayout innerLayout2 = new LinearLayout(act); |
|
245 |
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height); |
|
246 |
|
|
247 |
innerLayout2.setLayoutParams(innerLayout2Params); |
|
248 |
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
249 |
innerLayout2.setOrientation(LinearLayout.HORIZONTAL); |
|
250 |
outerLayout.addView(innerLayout2); |
|
251 |
|
|
252 |
///// STUFF INSIDE INNER LAYOUT2 ///////////////////////////////////////////////////// |
|
253 |
|
|
254 |
int text3Padding = (int)(scale*5 + 0.5f); |
|
255 |
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f); |
|
256 |
|
|
257 |
TextView text3View = new TextView(act); |
|
258 |
text3View.setText(R.string.type); |
|
259 |
text3View.setLayoutParams(text3LayoutParams); |
|
260 |
text3View.setGravity(Gravity.START|Gravity.CENTER); |
|
261 |
text3View.setPadding(text3Padding,0,text3Padding,0); |
|
262 |
text3View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
263 |
innerLayout2.addView(text3View); |
|
264 |
////////////////////////////////////////////////////////////////// |
|
265 |
int spinnerPadding = (int)(scale*10 + 0.5f); |
|
266 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
267 |
|
|
268 |
Spinner spinner = new Spinner(act); |
|
269 |
spinner.setLayoutParams(spinnerLayoutParams); |
|
270 |
spinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
|
271 |
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
|
272 |
spinner.setId(index); |
|
273 |
innerLayout2.addView(spinner); |
|
274 |
|
|
275 |
mSpinnerID[index] = spinner.getId(); |
|
276 |
|
|
277 |
spinner.setOnItemSelectedListener(this); |
|
278 |
String[] appear = RubikSettingsEnum.getNames(index); |
|
279 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); |
|
163 | 280 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
164 |
solveTypeSpinner.setAdapter(adapterType);
|
|
281 |
spinner.setAdapter(adapterType); |
|
165 | 282 |
|
166 |
if(mSolveType>=0 && mSolveType<solve.length) |
|
167 |
{ |
|
168 |
solveTypeSpinner.setSelection(mSolveType); |
|
169 |
} |
|
170 |
} |
|
171 |
else |
|
172 |
{ |
|
173 |
android.util.Log.e("dialog", "SOLVE TYPE SPINNER NULL!!"); |
|
174 |
} |
|
175 |
|
|
176 |
SeekBar solveBar = view.findViewById(R.id.solveDuration); |
|
177 |
solveBar.setOnSeekBarChangeListener(this); |
|
178 |
solveBar.setProgress(mSolvePos); |
|
283 |
int type = mType[index]; |
|
179 | 284 |
|
180 |
/// SCRAMBLE ////////////////////////////////////////////////////////// |
|
181 |
Spinner scrambleTypeSpinner = view.findViewById(R.id.scrambleType); |
|
182 |
|
|
183 |
if( scrambleTypeSpinner!=null ) |
|
184 |
{ |
|
185 |
scrambleTypeSpinner.setOnItemSelectedListener(this); |
|
186 |
String[] scramble = ScrambleEffect.getNames(); |
|
187 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, scramble); |
|
188 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
189 |
scrambleTypeSpinner.setAdapter(adapterType); |
|
190 |
|
|
191 |
if(mScrambleType>=0 && mScrambleType<scramble.length) |
|
285 |
if(type>=0 && type<appear.length) |
|
192 | 286 |
{ |
193 |
scrambleTypeSpinner.setSelection(mScrambleType);
|
|
287 |
spinner.setSelection(type);
|
|
194 | 288 |
} |
195 | 289 |
} |
196 |
else |
|
197 |
{ |
|
198 |
android.util.Log.e("dialog", "SCRAMBLE TYPE SPINNER NULL!!"); |
|
199 |
} |
|
200 | 290 |
|
201 |
SeekBar scrambleBar = view.findViewById(R.id.scrambleDuration); |
|
202 |
scrambleBar.setOnSeekBarChangeListener(this); |
|
203 |
scrambleBar.setProgress(mScramblePos); |
|
204 |
|
|
205 |
return builder.create(); |
|
206 |
} |
|
207 | 291 |
|
208 | 292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
209 | 293 |
|
210 | 294 |
private void saveOptions() |
211 | 295 |
{ |
212 |
mListener.onComplete(mSizeChangePos, mSolvePos, mScramblePos, mSizeChangeType, mSolveType, mScrambleType);
|
|
296 |
mListener.onComplete(mPos[0], mPos[1], mPos[2], mType[0], mType[1], mType[2]);
|
|
213 | 297 |
} |
214 | 298 |
|
215 | 299 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
216 | 300 |
|
217 | 301 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
218 | 302 |
{ |
219 |
switch(parent.getId()) |
|
303 |
int parentID = parent.getId(); |
|
304 |
|
|
305 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
220 | 306 |
{ |
221 |
case R.id.sizechangeType: mSizeChangeType= pos; break; |
|
222 |
case R.id.solveType : mSolveType = pos; break; |
|
223 |
case R.id.scrambleType : mScrambleType = pos; break; |
|
307 |
if( mSpinnerID[i] == parentID ) |
|
308 |
{ |
|
309 |
mType[i] = pos; |
|
310 |
break; |
|
311 |
} |
|
224 | 312 |
} |
225 | 313 |
} |
226 | 314 |
|
... | ... | |
228 | 316 |
|
229 | 317 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
230 | 318 |
{ |
231 |
switch (bar.getId()) |
|
319 |
int barID = bar.getId(); |
|
320 |
|
|
321 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
232 | 322 |
{ |
233 |
case R.id.sizechangeDuration: mSizeChangePos= progress; |
|
234 |
int sizechange_ms= RubikActivity.translateDuration(mSizeChangePos); |
|
235 |
mSizeChangeDuration.setText(getString(R.string.ms_placeholder,sizechange_ms)); |
|
236 |
break; |
|
237 |
case R.id.solveDuration : mSolvePos= progress; |
|
238 |
int solve_ms= RubikActivity.translateDuration(mSolvePos); |
|
239 |
mSolveDuration.setText(getString(R.string.ms_placeholder,solve_ms)); |
|
240 |
break; |
|
241 |
case R.id.scrambleDuration : mScramblePos= progress; |
|
242 |
int scramble_ms= RubikActivity.translateDuration(mScramblePos); |
|
243 |
mScrambleDuration.setText(getString(R.string.ms_placeholder,scramble_ms)); |
|
244 |
break; |
|
323 |
if( mSeekBarID[i] == barID ) |
|
324 |
{ |
|
325 |
mPos[i] = progress; |
|
326 |
int ms = RubikActivity.translateDuration(mPos[i]); |
|
327 |
mDurationText[i].setText(getString(R.string.ms_placeholder,ms)); |
|
328 |
break; |
|
329 |
} |
|
245 | 330 |
} |
246 | 331 |
} |
247 | 332 |
|
src/main/java/org/distorted/magic/RubikSettingsEnum.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted 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 |
// Distorted 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 Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.magic; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
import org.distorted.effect.ScrambleEffect; |
|
25 |
import org.distorted.effect.SizeChangeEffect; |
|
26 |
import org.distorted.effect.SolveEffect; |
|
27 |
|
|
28 |
enum RubikSettingsEnum |
|
29 |
{ |
|
30 |
SIZECHANGE ( 20, 1, R.string.sizechange_effect ), |
|
31 |
SOLVE ( 20, 1, R.string.solve_effect ), |
|
32 |
SCRAMBLE ( 100, 0, R.string.scramble_effect ); |
|
33 |
|
|
34 |
public static final int LENGTH = values().length; |
|
35 |
private int mDefaultPos, mDefaultType; |
|
36 |
private int mText; |
|
37 |
|
|
38 |
private static final RubikSettingsEnum[] enums; // copy the values() to a local variable so that we |
|
39 |
// don't have to keep recreating the array every time |
|
40 |
static |
|
41 |
{ |
|
42 |
int i=0; |
|
43 |
|
|
44 |
enums= new RubikSettingsEnum[LENGTH]; |
|
45 |
|
|
46 |
for(RubikSettingsEnum name: RubikSettingsEnum.values()) |
|
47 |
{ |
|
48 |
enums[i] = name; |
|
49 |
i++; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
RubikSettingsEnum( int dPos, int dType, int text ) |
|
56 |
{ |
|
57 |
mDefaultPos = dPos; |
|
58 |
mDefaultType = dType; |
|
59 |
mText = text; |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
int getDefaultPos() |
|
65 |
{ |
|
66 |
return mDefaultPos; |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
int getDefaultType() |
|
72 |
{ |
|
73 |
return mDefaultType; |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
int getText() |
|
79 |
{ |
|
80 |
return mText; |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
static RubikSettingsEnum getEnum(int ordinal) |
|
86 |
{ |
|
87 |
return enums[ordinal]; |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
static String[] getNames(int ordinal) |
|
93 |
{ |
|
94 |
switch(ordinal) |
|
95 |
{ |
|
96 |
case 0: return SizeChangeEffect.getNames(); |
|
97 |
case 1: return SolveEffect.getNames(); |
|
98 |
case 2: return ScrambleEffect.getNames(); |
|
99 |
} |
|
100 |
|
|
101 |
return null; |
|
102 |
} |
|
103 |
} |
src/main/res/layout/settings.xml | ||
---|---|---|
2 | 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
3 | 3 |
android:layout_width="match_parent" |
4 | 4 |
android:layout_height="match_parent" |
5 |
android:id="@+id/main_settings_layout" |
|
5 | 6 |
android:gravity="center_horizontal" |
6 | 7 |
android:orientation="vertical"> |
7 | 8 |
|
8 |
<TextView |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="48dp" |
|
11 |
android:paddingStart="15dp" |
|
12 |
android:paddingEnd="15dp" |
|
13 |
android:gravity="start|center" |
|
14 |
android:text="@string/sizechange_effect" |
|
15 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
16 |
|
|
17 |
<LinearLayout |
|
18 |
android:layout_width="fill_parent" |
|
19 |
android:layout_height="fill_parent" |
|
20 |
android:layout_weight="0.5" |
|
21 |
android:gravity="center|fill_horizontal" |
|
22 |
android:layout_marginLeft="10dp" |
|
23 |
android:layout_marginRight="10dp" |
|
24 |
android:layout_marginBottom="10dp" |
|
25 |
android:background="@color/grey" |
|
26 |
android:orientation="vertical"> |
|
27 |
|
|
28 |
<LinearLayout |
|
29 |
android:layout_width="fill_parent" |
|
30 |
android:layout_height="36dp" |
|
31 |
android:gravity="center|fill_horizontal" |
|
32 |
android:orientation="horizontal"> |
|
33 |
|
|
34 |
<TextView |
|
35 |
android:layout_weight="0.2" |
|
36 |
android:layout_width="0dp" |
|
37 |
android:layout_height="fill_parent" |
|
38 |
android:paddingStart="5dp" |
|
39 |
android:paddingEnd="5dp" |
|
40 |
android:gravity="start|center" |
|
41 |
android:text="@string/duration" |
|
42 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
43 |
|
|
44 |
<TextView |
|
45 |
android:id="@+id/sizechangeDurationText" |
|
46 |
android:layout_weight="0.2" |
|
47 |
android:layout_width="0dp" |
|
48 |
android:layout_height="fill_parent" |
|
49 |
android:paddingStart="5dp" |
|
50 |
android:paddingEnd="5dp" |
|
51 |
android:gravity="end|center" |
|
52 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
53 |
|
|
54 |
<SeekBar |
|
55 |
android:id="@+id/sizechangeDuration" |
|
56 |
android:layout_weight="0.6" |
|
57 |
android:layout_width="0dp" |
|
58 |
android:layout_height="fill_parent" |
|
59 |
android:paddingLeft="10dp" |
|
60 |
android:paddingRight="10dp" /> |
|
61 |
|
|
62 |
</LinearLayout> |
|
63 |
|
|
64 |
<LinearLayout |
|
65 |
android:layout_width="fill_parent" |
|
66 |
android:layout_height="36dp" |
|
67 |
android:gravity="center|fill_horizontal" |
|
68 |
android:orientation="horizontal"> |
|
69 |
|
|
70 |
<TextView |
|
71 |
android:layout_weight="0.4" |
|
72 |
android:layout_width="0dp" |
|
73 |
android:layout_height="fill_parent" |
|
74 |
android:paddingStart="5dp" |
|
75 |
android:paddingEnd="5dp" |
|
76 |
android:gravity="start|center" |
|
77 |
android:text="@string/type" |
|
78 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
79 |
|
|
80 |
<Spinner |
|
81 |
android:id="@+id/sizechangeType" |
|
82 |
android:layout_weight="0.6" |
|
83 |
android:layout_width="0dp" |
|
84 |
android:layout_height="fill_parent" |
|
85 |
android:textAlignment="center" |
|
86 |
android:paddingLeft="10dp" |
|
87 |
android:paddingRight="10dp" /> |
|
88 |
|
|
89 |
</LinearLayout> |
|
90 |
</LinearLayout> |
|
91 |
|
|
92 |
<TextView |
|
93 |
android:layout_width="fill_parent" |
|
94 |
android:layout_height="48dp" |
|
95 |
android:paddingStart="15dp" |
|
96 |
android:paddingEnd="15dp" |
|
97 |
android:gravity="start|center" |
|
98 |
android:text="@string/unscramble_effect" |
|
99 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
100 |
|
|
101 |
<LinearLayout |
|
102 |
android:layout_width="fill_parent" |
|
103 |
android:layout_height="fill_parent" |
|
104 |
android:layout_weight="0.5" |
|
105 |
android:gravity="center|fill_horizontal" |
|
106 |
android:layout_marginLeft="10dp" |
|
107 |
android:layout_marginRight="10dp" |
|
108 |
android:layout_marginBottom="10dp" |
|
109 |
android:background="@color/grey" |
|
110 |
android:orientation="vertical"> |
|
111 |
|
|
112 |
<LinearLayout |
|
113 |
android:layout_width="fill_parent" |
|
114 |
android:layout_height="36dp" |
|
115 |
android:gravity="center|fill_horizontal" |
|
116 |
android:orientation="horizontal"> |
|
117 |
|
|
118 |
<TextView |
|
119 |
android:layout_weight="0.2" |
|
120 |
android:layout_width="0dp" |
|
121 |
android:layout_height="fill_parent" |
|
122 |
android:paddingStart="5dp" |
|
123 |
android:paddingEnd="5dp" |
|
124 |
android:gravity="start|center" |
|
125 |
android:text="@string/duration" |
|
126 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
127 |
|
|
128 |
<TextView |
|
129 |
android:id="@+id/solveDurationText" |
|
130 |
android:layout_weight="0.2" |
|
131 |
android:layout_width="0dp" |
|
132 |
android:layout_height="fill_parent" |
|
133 |
android:paddingStart="5dp" |
|
134 |
android:paddingEnd="5dp" |
|
135 |
android:gravity="end|center" |
|
136 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
137 |
|
|
138 |
<SeekBar |
|
139 |
android:id="@+id/solveDuration" |
|
140 |
android:layout_weight="0.6" |
|
141 |
android:layout_width="0dp" |
|
142 |
android:layout_height="fill_parent" |
|
143 |
android:paddingLeft="10dp" |
|
144 |
android:paddingRight="10dp" /> |
|
145 |
|
|
146 |
</LinearLayout> |
|
147 |
|
|
148 |
<LinearLayout |
|
149 |
android:layout_width="fill_parent" |
|
150 |
android:layout_height="36dp" |
|
151 |
android:gravity="center|fill_horizontal" |
|
152 |
android:orientation="horizontal"> |
|
153 |
|
|
154 |
<TextView |
|
155 |
android:layout_weight="0.4" |
|
156 |
android:layout_width="0dp" |
|
157 |
android:layout_height="fill_parent" |
|
158 |
android:paddingStart="5dp" |
|
159 |
android:paddingEnd="5dp" |
|
160 |
android:gravity="start|center" |
|
161 |
android:text="@string/type" |
|
162 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
163 |
|
|
164 |
<Spinner |
|
165 |
android:id="@+id/solveType" |
|
166 |
android:layout_weight="0.6" |
|
167 |
android:layout_width="0dp" |
|
168 |
android:layout_height="fill_parent" |
|
169 |
android:textAlignment="center" |
|
170 |
android:paddingLeft="10dp" |
|
171 |
android:paddingRight="10dp" /> |
|
172 |
|
|
173 |
</LinearLayout> |
|
174 |
</LinearLayout> |
|
175 |
|
|
176 |
<TextView |
|
177 |
android:layout_width="fill_parent" |
|
178 |
android:layout_height="48dp" |
|
179 |
android:paddingStart="15dp" |
|
180 |
android:paddingEnd="15dp" |
|
181 |
android:gravity="start|center" |
|
182 |
android:text="@string/scramble_effect" |
|
183 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
184 |
|
|
185 |
<LinearLayout |
|
186 |
android:layout_width="fill_parent" |
|
187 |
android:layout_height="fill_parent" |
|
188 |
android:layout_weight="0.5" |
|
189 |
android:gravity="center|fill_horizontal" |
|
190 |
android:layout_marginLeft="10dp" |
|
191 |
android:layout_marginRight="10dp" |
|
192 |
android:background="@color/grey" |
|
193 |
android:orientation="vertical"> |
|
194 |
|
|
195 |
<LinearLayout |
|
196 |
android:layout_width="fill_parent" |
|
197 |
android:layout_height="36dp" |
|
198 |
android:gravity="center|fill_horizontal" |
|
199 |
android:orientation="horizontal"> |
|
200 |
|
|
201 |
<TextView |
|
202 |
android:layout_weight="0.2" |
|
203 |
android:layout_width="0dp" |
|
204 |
android:layout_height="fill_parent" |
|
205 |
android:paddingStart="5dp" |
|
206 |
android:paddingEnd="5dp" |
|
207 |
android:gravity="start|center" |
|
208 |
android:text="@string/duration" |
|
209 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
210 |
|
|
211 |
<TextView |
|
212 |
android:id="@+id/scrambleDurationText" |
|
213 |
android:layout_weight="0.2" |
|
214 |
android:layout_width="0dp" |
|
215 |
android:layout_height="fill_parent" |
|
216 |
android:paddingStart="5dp" |
|
217 |
android:paddingEnd="5dp" |
|
218 |
android:gravity="end|center" |
|
219 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
220 |
|
|
221 |
<SeekBar |
|
222 |
android:id="@+id/scrambleDuration" |
|
223 |
android:layout_weight="0.6" |
|
224 |
android:layout_width="0dp" |
|
225 |
android:layout_height="fill_parent" |
|
226 |
android:paddingLeft="10dp" |
|
227 |
android:paddingRight="10dp" /> |
|
228 |
|
|
229 |
</LinearLayout> |
|
230 |
|
|
231 |
<LinearLayout |
|
232 |
android:layout_width="fill_parent" |
|
233 |
android:layout_height="36dp" |
|
234 |
android:gravity="center|fill_horizontal" |
|
235 |
android:orientation="horizontal"> |
|
236 |
|
|
237 |
<TextView |
|
238 |
android:layout_weight="0.4" |
|
239 |
android:layout_width="0dp" |
|
240 |
android:layout_height="fill_parent" |
|
241 |
android:paddingStart="5dp" |
|
242 |
android:paddingEnd="5dp" |
|
243 |
android:gravity="start|center" |
|
244 |
android:text="@string/type" |
|
245 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
246 |
|
|
247 |
<Spinner |
|
248 |
android:id="@+id/scrambleType" |
|
249 |
android:layout_weight="0.6" |
|
250 |
android:layout_width="0dp" |
|
251 |
android:layout_height="fill_parent" |
|
252 |
android:textAlignment="center" |
|
253 |
android:paddingLeft="10dp" |
|
254 |
android:paddingRight="10dp" /> |
|
255 |
|
|
256 |
</LinearLayout> |
|
257 |
</LinearLayout> |
|
258 | 9 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
8 | 8 |
<string name="about">About</string> |
9 | 9 |
<string name="save">SAVE</string> |
10 | 10 |
<string name="ok">OK</string> |
11 |
<string name="sizechange_effect">Cube Size Change Effect:</string>
|
|
12 |
<string name="unscramble_effect">Cube Unscramble Effect:</string>
|
|
13 |
<string name="scramble_effect">Cube Scramble Effect:</string>
|
|
11 |
<string name="sizechange_effect">Size Change Effect:</string> |
|
12 |
<string name="solve_effect">Solve Effect:</string>
|
|
13 |
<string name="scramble_effect">Scramble Effect:</string> |
|
14 | 14 |
<string name="duration">Duration:</string> |
15 | 15 |
<string name="type">Type:</string> |
16 | 16 |
<string name="credits1">Open Source app developed using the Distorted graphics library. </string> |
17 | 17 |
<string name="credits2">Code, tutorials, learn how to write your own graphics effect: <a href="http://www.distorted.org/cube">Distorted.org</a></string> |
18 |
|
|
18 | 19 |
<string name="ms_placeholder">%1$d ms</string> |
19 | 20 |
</resources> |
Also available in: Unified diff
RubikCube: major progress with a separate RubikSettingsEnum enum - has been introduced into RubikSettings.