Revision 2e3488f6
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/helpers/MovesController.java | ||
---|---|---|
22 | 22 |
import java.util.ArrayList; |
23 | 23 |
|
24 | 24 |
import android.app.Activity; |
25 |
import android.content.SharedPreferences; |
|
25 | 26 |
import android.view.View; |
26 | 27 |
import android.widget.LinearLayout; |
27 | 28 |
|
... | ... | |
179 | 180 |
}); |
180 | 181 |
} |
181 | 182 |
|
183 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
184 |
|
|
185 |
public void savePreferences(SharedPreferences.Editor editor) |
|
186 |
{ |
|
187 |
StringBuilder moves = new StringBuilder(); |
|
188 |
int numMoves = getNumMoves(); |
|
189 |
|
|
190 |
for(int m=0; m<numMoves; m++) |
|
191 |
{ |
|
192 |
Move move = mMoves.get(m); |
|
193 |
|
|
194 |
if( m>0 ) moves.append(' '); |
|
195 |
moves.append(move.mAxis); |
|
196 |
moves.append(' '); |
|
197 |
moves.append(move.mRow); |
|
198 |
moves.append(' '); |
|
199 |
moves.append(move.mAngle); |
|
200 |
} |
|
201 |
|
|
202 |
editor.putString("movesController", moves.toString() ); |
|
203 |
editor.apply(); |
|
204 |
} |
|
205 |
|
|
206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
207 |
|
|
208 |
public void restorePreferences(Activity act, SharedPreferences preferences) |
|
209 |
{ |
|
210 |
String objects = preferences.getString("movesController",""); |
|
211 |
|
|
212 |
if( objects.length()>0 ) |
|
213 |
{ |
|
214 |
String[] tokens = objects.split(" "); |
|
215 |
int length = tokens.length; |
|
216 |
|
|
217 |
for(int m=0; m<length/3; m++) |
|
218 |
{ |
|
219 |
String axis = tokens[3*m ]; |
|
220 |
String row = tokens[3*m+1]; |
|
221 |
String angle = tokens[3*m+2]; |
|
222 |
|
|
223 |
try |
|
224 |
{ |
|
225 |
int axisI = Integer.parseInt(axis); |
|
226 |
int rowI = Integer.parseInt(row); |
|
227 |
int angleI= Integer.parseInt(angle); |
|
228 |
|
|
229 |
addMove(act,axisI,rowI,angleI); |
|
230 |
} |
|
231 |
catch(NumberFormatException ex) |
|
232 |
{ |
|
233 |
// ignore |
|
234 |
android.util.Log.e("D", "exception: "+ex.getMessage()); |
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
182 | 240 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
183 | 241 |
|
184 | 242 |
public TransparentImageButton getButton() |
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
56 | 56 |
import org.distorted.external.RubikNetwork; |
57 | 57 |
import org.distorted.objects.RubikObject; |
58 | 58 |
import org.distorted.objects.RubikObjectList; |
59 |
import org.distorted.screens.RubikScreenSolving; |
|
59 | 60 |
import org.distorted.screens.ScreenList; |
60 | 61 |
import org.distorted.screens.RubikScreenPlay; |
61 | 62 |
import org.distorted.tutorials.TutorialActivity; |
... | ... | |
251 | 252 |
ScreenList.setScreen(this); |
252 | 253 |
unblockEverything(); |
253 | 254 |
|
255 |
restoreMoves(); |
|
256 |
|
|
254 | 257 |
if( mJustStarted ) |
255 | 258 |
{ |
256 | 259 |
mJustStarted = false; |
... | ... | |
317 | 320 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
318 | 321 |
view.getObjectControl().savePreferences(editor); |
319 | 322 |
|
323 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
324 |
|
|
325 |
if( curr==ScreenList.PLAY ) |
|
326 |
{ |
|
327 |
RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass(); |
|
328 |
play.saveMovePreferences(editor); |
|
329 |
} |
|
330 |
if( curr==ScreenList.SOLV ) |
|
331 |
{ |
|
332 |
RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass(); |
|
333 |
solv.saveMovePreferences(editor); |
|
334 |
} |
|
335 |
|
|
320 | 336 |
editor.apply(); |
321 | 337 |
} |
322 | 338 |
|
... | ... | |
367 | 383 |
} |
368 | 384 |
} |
369 | 385 |
|
386 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
387 |
|
|
388 |
private void restoreMoves() |
|
389 |
{ |
|
390 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
391 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
392 |
|
|
393 |
if( curr==ScreenList.PLAY ) |
|
394 |
{ |
|
395 |
RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass(); |
|
396 |
play.restoreMovePreferences(this,preferences); |
|
397 |
} |
|
398 |
if( curr==ScreenList.SOLV ) |
|
399 |
{ |
|
400 |
RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass(); |
|
401 |
solv.restoreMovePreferences(this,preferences); |
|
402 |
} |
|
403 |
} |
|
404 |
|
|
370 | 405 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
371 | 406 |
|
372 | 407 |
private void PrivacyPolicy() |
src/main/java/org/distorted/screens/RubikScreenBase.java | ||
---|---|---|
20 | 20 |
package org.distorted.screens; |
21 | 21 |
|
22 | 22 |
import android.app.Activity; |
23 |
import android.content.SharedPreferences; |
|
23 | 24 |
import android.widget.LinearLayout; |
24 | 25 |
|
25 | 26 |
import org.distorted.helpers.TransparentImageButton; |
... | ... | |
100 | 101 |
ObjectControl control = act.getControl(); |
101 | 102 |
mLockController.reddenLock(act,control); |
102 | 103 |
} |
104 |
|
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
public void saveMovePreferences(SharedPreferences.Editor editor) |
|
108 |
{ |
|
109 |
mMovesController.savePreferences(editor); |
|
110 |
} |
|
111 |
|
|
112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
113 |
|
|
114 |
public void restoreMovePreferences(Activity act, SharedPreferences preferences) |
|
115 |
{ |
|
116 |
mMovesController.restorePreferences(act,preferences); |
|
117 |
} |
|
103 | 118 |
} |
Also available in: Unified diff
Remember move history in the PLAY and SOLV screens.