Revision 33499c56
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
---|---|---|
26 | 26 |
import android.graphics.PorterDuff; |
27 | 27 |
import android.graphics.drawable.Drawable; |
28 | 28 |
import android.opengl.GLSurfaceView; |
29 |
import android.preference.PreferenceManager; |
|
30 | 29 |
import android.support.v4.content.ContextCompat; |
31 | 30 |
import android.util.AttributeSet; |
32 | 31 |
import android.util.DisplayMetrics; |
... | ... | |
39 | 38 |
import android.widget.LinearLayout; |
40 | 39 |
|
41 | 40 |
import org.distorted.component.HorizontalNumberPicker; |
42 |
import org.distorted.effect.BaseEffect; |
|
43 | 41 |
import org.distorted.library.type.Static2D; |
44 | 42 |
import org.distorted.library.type.Static4D; |
45 | 43 |
import org.distorted.object.RubikCube; |
... | ... | |
50 | 48 |
public class RubikSurfaceView extends GLSurfaceView |
51 | 49 |
{ |
52 | 50 |
public static final int BUTTON_ID_BACK= 1023; |
53 |
public static final int BUTTON_ID_EXIT= 1022; |
|
54 | 51 |
|
55 | 52 |
public static final int MIN_SCRAMBLE = 1; |
56 | 53 |
public static final int DEF_SCRAMBLE = 1; |
... | ... | |
91 | 88 |
|
92 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
93 | 90 |
|
94 |
void savePreferences() |
|
91 |
void savePreferences(SharedPreferences.Editor editor)
|
|
95 | 92 |
{ |
96 |
RubikActivity act = (RubikActivity)getContext(); |
|
97 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(act); |
|
98 |
SharedPreferences.Editor editor = preferences.edit(); |
|
99 |
|
|
100 |
for (int i = 0; i< BaseEffect.Type.LENGTH; i++) |
|
101 |
{ |
|
102 |
BaseEffect.Type.getType(i).savePreferences(editor); |
|
103 |
} |
|
104 |
|
|
105 | 93 |
editor.putInt("scramble", mScrambleValue ); |
106 |
|
|
107 |
editor.apply(); |
|
108 | 94 |
} |
109 | 95 |
|
110 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
111 | 97 |
|
112 |
void restorePreferences() |
|
98 |
void restorePreferences(SharedPreferences preferences)
|
|
113 | 99 |
{ |
114 |
RubikActivity act = (RubikActivity)getContext(); |
|
115 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(act); |
|
116 |
|
|
117 |
for (int i=0; i< BaseEffect.Type.LENGTH; i++) |
|
118 |
{ |
|
119 |
BaseEffect.Type.getType(i).restorePreferences(preferences); |
|
120 |
} |
|
121 |
|
|
122 | 100 |
mScrambleValue= preferences.getInt("scramble", DEF_SCRAMBLE); |
123 | 101 |
} |
124 | 102 |
|
... | ... | |
280 | 258 |
|
281 | 259 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
282 | 260 |
|
283 |
void enterMainState(RubikActivity act) |
|
261 |
void enterState(RubikActivity act, RubikState state) |
|
262 |
{ |
|
263 |
switch(state) |
|
264 |
{ |
|
265 |
case MAIN: enterMainState(act); break; |
|
266 |
case PLAY: enterPlayState(act); break; |
|
267 |
} |
|
268 |
} |
|
269 |
|
|
270 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
271 |
|
|
272 |
private void enterMainState(RubikActivity act) |
|
284 | 273 |
{ |
285 | 274 |
LayoutInflater inflater = act.getLayoutInflater(); |
286 | 275 |
|
... | ... | |
302 | 291 |
|
303 | 292 |
Button buttonL = new Button(act); |
304 | 293 |
buttonL.setLayoutParams(params); |
305 |
buttonL.setId(BUTTON_ID_EXIT);
|
|
294 |
buttonL.setId(BUTTON_ID_BACK);
|
|
306 | 295 |
buttonL.setPadding(padding,0,padding,0); |
307 | 296 |
buttonL.setText(R.string.back); |
308 | 297 |
buttonL.setOnClickListener(act); |
... | ... | |
310 | 299 |
|
311 | 300 |
Button buttonR = new Button(act); |
312 | 301 |
buttonR.setLayoutParams(params); |
313 |
buttonR.setId(BUTTON_ID_EXIT);
|
|
302 |
buttonR.setId(BUTTON_ID_BACK);
|
|
314 | 303 |
buttonR.setPadding(padding,0,padding,0); |
315 | 304 |
buttonR.setText(R.string.exit); |
316 | 305 |
buttonR.setOnClickListener(act); |
... | ... | |
321 | 310 |
|
322 | 311 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
323 | 312 |
|
324 |
void enterPlayState(RubikActivity act) |
|
313 |
private void enterPlayState(RubikActivity act)
|
|
325 | 314 |
{ |
326 | 315 |
LayoutInflater inflater = act.getLayoutInflater(); |
327 | 316 |
|
Also available in: Unified diff
Major rearrangement of the UI.