Revision 972f9eae
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/bandaged/BandagedPlayActivity.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.bandaged; |
21 | 21 |
|
22 |
import android.content.SharedPreferences; |
|
22 | 23 |
import android.os.Build; |
23 | 24 |
import android.os.Bundle; |
25 |
import android.preference.PreferenceManager; |
|
24 | 26 |
import android.util.DisplayMetrics; |
25 | 27 |
import android.view.DisplayCutout; |
26 | 28 |
import android.view.View; |
... | ... | |
191 | 193 |
super.onPause(); |
192 | 194 |
BandagedPlayView view = findViewById(R.id.bandagedPlayView); |
193 | 195 |
view.onPause(); |
196 |
savePreferences(); |
|
194 | 197 |
DistortedLibrary.onPause(ACTIVITY_NUMBER); |
195 | 198 |
} |
196 | 199 |
|
... | ... | |
205 | 208 |
view.onResume(); |
206 | 209 |
|
207 | 210 |
if( mScreen==null ) mScreen = new BandagedPlayScreen(); |
208 |
mScreen.onAttachedToWindow(this); |
|
211 |
mScreen.onAttachedToWindow(this, mObjectName); |
|
212 |
restorePreferences(); |
|
209 | 213 |
|
210 | 214 |
if( mObjectName.length()>0 ) |
211 | 215 |
{ |
... | ... | |
222 | 226 |
DistortedLibrary.onDestroy(ACTIVITY_NUMBER); |
223 | 227 |
} |
224 | 228 |
|
229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
230 |
|
|
231 |
private void savePreferences() |
|
232 |
{ |
|
233 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
234 |
SharedPreferences.Editor editor = preferences.edit(); |
|
235 |
mScreen.savePreferences(this,editor); |
|
236 |
|
|
237 |
editor.apply(); |
|
238 |
} |
|
239 |
|
|
240 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
241 |
|
|
242 |
private void restorePreferences() |
|
243 |
{ |
|
244 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
245 |
mScreen.restorePreferences(this,preferences); |
|
246 |
} |
|
247 |
|
|
225 | 248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
226 | 249 |
|
227 | 250 |
void OpenGLError() |
src/main/java/org/distorted/bandaged/BandagedPlayScreen.java | ||
---|---|---|
40 | 40 |
|
41 | 41 |
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton; |
42 | 42 |
private final LockController mLockController; |
43 |
protected MovesController mMovesController; |
|
43 |
private MovesController mMovesController; |
|
44 |
private String mKey; |
|
44 | 45 |
|
45 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 47 |
|
... | ... | |
112 | 113 |
|
113 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
114 | 115 |
|
115 |
void onAttachedToWindow(final BandagedPlayActivity act) |
|
116 |
void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
|
|
116 | 117 |
{ |
118 |
mKey = "moveController_"+objectName; |
|
119 |
|
|
117 | 120 |
int width = act.getScreenWidthInPixels(); |
118 | 121 |
|
119 | 122 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
... | ... | |
188 | 191 |
|
189 | 192 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
190 | 193 |
|
191 |
public void saveMovePreferences(SharedPreferences.Editor editor)
|
|
194 |
public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
|
|
192 | 195 |
{ |
193 |
mMovesController.savePreferences(editor); |
|
196 |
mMovesController.savePreferences(mKey,editor); |
|
197 |
ObjectControl control = act.getControl(); |
|
198 |
control.savePreferences(editor); |
|
194 | 199 |
} |
195 | 200 |
|
196 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
197 | 202 |
|
198 |
public void restoreMovePreferences(Activity act, SharedPreferences preferences)
|
|
203 |
public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
|
|
199 | 204 |
{ |
200 |
mMovesController.restorePreferences(act,preferences); |
|
205 |
mMovesController.restorePreferences(act,mKey,preferences); |
|
206 |
ObjectControl control = act.getControl(); |
|
207 |
control.restorePreferences(preferences); |
|
201 | 208 |
} |
202 | 209 |
} |
src/main/java/org/distorted/helpers/MovesController.java | ||
---|---|---|
182 | 182 |
|
183 | 183 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
184 | 184 |
|
185 |
public void savePreferences(SharedPreferences.Editor editor) |
|
185 |
public void savePreferences(String key, SharedPreferences.Editor editor)
|
|
186 | 186 |
{ |
187 | 187 |
StringBuilder moves = new StringBuilder(); |
188 | 188 |
int numMoves = getNumMoves(); |
... | ... | |
199 | 199 |
moves.append(move.mAngle); |
200 | 200 |
} |
201 | 201 |
|
202 |
editor.putString("movesController", moves.toString() );
|
|
202 |
editor.putString( key, moves.toString() );
|
|
203 | 203 |
editor.apply(); |
204 | 204 |
} |
205 | 205 |
|
206 | 206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
207 | 207 |
|
208 |
public void restorePreferences(Activity act, SharedPreferences preferences) |
|
208 |
public void restorePreferences(Activity act, String key, SharedPreferences preferences)
|
|
209 | 209 |
{ |
210 |
String objects = preferences.getString("movesController","");
|
|
210 |
String objects = preferences.getString( key,"");
|
|
211 | 211 |
|
212 | 212 |
if( objects.length()>0 ) |
213 | 213 |
{ |
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
100 | 100 |
private static final float RATIO_BAR = 0.10f; |
101 | 101 |
private static final float RATIO_INSET= 0.09f; |
102 | 102 |
|
103 |
private static final String KEY_PLAY = "movesController_play"; |
|
104 |
private static final String KEY_SOLV = "movesController_solv"; |
|
105 |
|
|
103 | 106 |
private boolean mJustStarted; |
104 | 107 |
private FirebaseAnalytics mFirebaseAnalytics; |
105 | 108 |
private static int mScreenWidth, mScreenHeight; |
... | ... | |
325 | 328 |
if( curr==ScreenList.PLAY ) |
326 | 329 |
{ |
327 | 330 |
RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass(); |
328 |
play.saveMovePreferences(editor); |
|
331 |
play.saveMovePreferences(KEY_PLAY,editor);
|
|
329 | 332 |
} |
330 | 333 |
if( curr==ScreenList.SOLV ) |
331 | 334 |
{ |
332 | 335 |
RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass(); |
333 |
solv.saveMovePreferences(editor); |
|
336 |
solv.saveMovePreferences(KEY_SOLV,editor);
|
|
334 | 337 |
} |
335 | 338 |
|
336 | 339 |
editor.apply(); |
... | ... | |
393 | 396 |
if( curr==ScreenList.PLAY ) |
394 | 397 |
{ |
395 | 398 |
RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass(); |
396 |
play.restoreMovePreferences(this,preferences); |
|
399 |
play.restoreMovePreferences(this,KEY_PLAY,preferences);
|
|
397 | 400 |
} |
398 | 401 |
if( curr==ScreenList.SOLV ) |
399 | 402 |
{ |
400 | 403 |
RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass(); |
401 |
solv.restoreMovePreferences(this,preferences); |
|
404 |
solv.restoreMovePreferences(this,KEY_SOLV,preferences);
|
|
402 | 405 |
} |
403 | 406 |
} |
404 | 407 |
|
src/main/java/org/distorted/screens/RubikScreenBase.java | ||
---|---|---|
104 | 104 |
|
105 | 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
106 | 106 |
|
107 |
public void saveMovePreferences(SharedPreferences.Editor editor) |
|
107 |
public void saveMovePreferences(String key,SharedPreferences.Editor editor)
|
|
108 | 108 |
{ |
109 |
mMovesController.savePreferences(editor); |
|
109 |
mMovesController.savePreferences(key,editor);
|
|
110 | 110 |
} |
111 | 111 |
|
112 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
113 | 113 |
|
114 |
public void restoreMovePreferences(Activity act, SharedPreferences preferences) |
|
114 |
public void restoreMovePreferences(Activity act, String key, SharedPreferences preferences)
|
|
115 | 115 |
{ |
116 |
mMovesController.restorePreferences(act,preferences); |
|
116 |
mMovesController.restorePreferences(act,key,preferences);
|
|
117 | 117 |
} |
118 | 118 |
} |
Also available in: Unified diff
Bandaged 3x3: remember object state and move history.