Revision 4235de9b
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.magic; |
21 | 21 |
|
22 |
import android.content.SharedPreferences; |
|
23 |
import android.opengl.GLSurfaceView; |
|
24 | 22 |
import android.os.Bundle; |
25 |
import android.preference.PreferenceManager; |
|
26 | 23 |
import android.support.v7.app.AppCompatActivity; |
27 | 24 |
import android.view.View; |
28 | 25 |
|
29 |
import org.distorted.component.HorizontalNumberPicker; |
|
30 | 26 |
import org.distorted.library.main.DistortedLibrary; |
31 |
import org.distorted.effect.BaseEffect; |
|
32 | 27 |
|
33 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 29 |
|
35 | 30 |
public class RubikActivity extends AppCompatActivity implements View.OnClickListener |
36 | 31 |
{ |
37 |
public static final int MIN_SCRAMBLE = 1; |
|
38 |
public static final int DEF_SCRAMBLE = 1; |
|
39 |
public static final int MAX_SCRAMBLE = 18; |
|
40 |
|
|
41 |
private HorizontalNumberPicker mPicker; |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
private void savePreferences() |
|
46 |
{ |
|
47 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
48 |
SharedPreferences.Editor editor = preferences.edit(); |
|
49 |
|
|
50 |
for (int i=0; i< BaseEffect.Type.LENGTH; i++) |
|
51 |
{ |
|
52 |
BaseEffect.Type.getType(i).savePreferences(editor); |
|
53 |
} |
|
54 |
|
|
55 |
editor.putInt("scramble", mPicker.getValue() ); |
|
56 |
|
|
57 |
editor.apply(); |
|
58 |
} |
|
59 |
|
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
private void restorePreferences() |
|
63 |
{ |
|
64 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
65 |
|
|
66 |
for (int i=0; i< BaseEffect.Type.LENGTH; i++) |
|
67 |
{ |
|
68 |
BaseEffect.Type.getType(i).restorePreferences(preferences); |
|
69 |
} |
|
70 |
|
|
71 |
int scramble= preferences.getInt("scramble", DEF_SCRAMBLE); |
|
72 |
|
|
73 |
mPicker.setValue(scramble); |
|
74 |
} |
|
32 |
private RubikDialogMain mMain; |
|
75 | 33 |
|
76 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
77 | 35 |
|
... | ... | |
81 | 39 |
super.onCreate(savedState); |
82 | 40 |
setTheme(R.style.CustomActivityThemeNoActionBar); |
83 | 41 |
setContentView(R.layout.main); |
84 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
85 |
view.addSizeButtons(this); |
|
86 |
view.markButton(RubikSurfaceView.getRedButton()); |
|
87 | 42 |
|
88 |
mPicker = findViewById(R.id.rubikNumberPicker); |
|
89 |
mPicker.setMin(MIN_SCRAMBLE); |
|
90 |
mPicker.setMax(MAX_SCRAMBLE); |
|
43 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
44 |
view.enterMainState(this); |
|
91 | 45 |
|
92 |
restorePreferences(); |
|
46 |
if( savedState==null ) |
|
47 |
{ |
|
48 |
mMain = new RubikDialogMain(); |
|
49 |
mMain.show(getSupportFragmentManager(), null); |
|
50 |
} |
|
93 | 51 |
} |
94 | 52 |
|
95 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
97 | 55 |
@Override |
98 | 56 |
protected void onPause() |
99 | 57 |
{ |
100 |
GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
|
58 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
|
101 | 59 |
view.onPause(); |
102 | 60 |
DistortedLibrary.onPause(); |
103 | 61 |
RubikScoresDownloader.onPause(); |
104 |
savePreferences(); |
|
62 |
view.savePreferences();
|
|
105 | 63 |
super.onPause(); |
106 | 64 |
} |
107 | 65 |
|
... | ... | |
111 | 69 |
protected void onResume() |
112 | 70 |
{ |
113 | 71 |
super.onResume(); |
114 |
GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
|
72 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
|
115 | 73 |
view.onResume(); |
74 |
view.restorePreferences(); |
|
116 | 75 |
} |
117 | 76 |
|
118 | 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
143 | 102 |
view.markButton(id); |
144 | 103 |
} |
145 | 104 |
} |
105 |
|
|
106 |
if( id == RubikSurfaceView.BUTTON_ID_BACK ) |
|
107 |
{ |
|
108 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
109 |
view.enterMainState(this); |
|
110 |
mMain.show(getSupportFragmentManager(), null); |
|
111 |
} |
|
112 |
if( id == RubikSurfaceView.BUTTON_ID_EXIT ) |
|
113 |
{ |
|
114 |
finish(); |
|
115 |
} |
|
146 | 116 |
} |
147 | 117 |
|
148 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
149 | 119 |
// PUBLIC API |
120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
121 |
|
|
122 |
public void Play(View v) |
|
123 |
{ |
|
124 |
mMain.dismiss(); |
|
125 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
126 |
view.enterPlayState(this); |
|
127 |
} |
|
128 |
|
|
150 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
151 | 130 |
|
152 | 131 |
public void Settings(View v) |
... | ... | |
159 | 138 |
|
160 | 139 |
public void Scores(View v) |
161 | 140 |
{ |
162 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
163 | 141 |
Bundle bundle = new Bundle(); |
164 |
bundle.putInt("tab", view.getRedButton());
|
|
142 |
bundle.putInt("tab", RubikSurfaceView.getRedButton());
|
|
165 | 143 |
|
166 | 144 |
RubikDialogScores scores = new RubikDialogScores(); |
167 | 145 |
scores.setArguments(bundle); |
... | ... | |
180 | 158 |
|
181 | 159 |
public void Scramble(View v) |
182 | 160 |
{ |
183 |
int scramble = mPicker.getValue(); |
|
184 |
|
|
185 | 161 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
186 |
view.getRenderer().scrambleCube(scramble); |
|
187 |
view.enterScrambleMode(); |
|
162 |
view.scramble(); |
|
188 | 163 |
} |
189 | 164 |
|
190 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
193 | 168 |
{ |
194 | 169 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
195 | 170 |
view.getRenderer().solveCube(); |
196 |
view.leaveScrambleMode(); |
|
197 | 171 |
} |
198 | 172 |
} |
Also available in: Unified diff
Major rearrangement of the UI.