Revision d18993ac
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/uistate/RubikState.java | ||
---|---|---|
36 | 36 |
private final RubikStateAbstract mClass; |
37 | 37 |
private static final RubikState[] sizes; |
38 | 38 |
|
39 |
private static RubikState mCurrentState;
|
|
39 |
private static RubikState mCurrState, mPrevState;
|
|
40 | 40 |
|
41 | 41 |
static |
42 | 42 |
{ |
... | ... | |
61 | 61 |
|
62 | 62 |
public static RubikState getCurrentState() |
63 | 63 |
{ |
64 |
return mCurrentState;
|
|
64 |
return mCurrState; |
|
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 68 |
|
69 | 69 |
public static void savePreferences(SharedPreferences.Editor editor) |
70 | 70 |
{ |
71 |
editor.putInt("state", mCurrentState.ordinal() ); |
|
71 |
editor.putInt("curr_state", mCurrState.ordinal() ); |
|
72 |
editor.putInt("prev_state", mPrevState.ordinal() ); |
|
72 | 73 |
} |
73 | 74 |
|
74 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
75 | 76 |
|
76 | 77 |
public static void restorePreferences(SharedPreferences preferences) |
77 | 78 |
{ |
78 |
int stateOrdinal = preferences.getInt("state", RubikState.MAIN.ordinal() ); |
|
79 |
mCurrentState = getState(stateOrdinal); |
|
79 |
int currState = preferences.getInt("curr_state", RubikState.MAIN.ordinal() ); |
|
80 |
int prevState = preferences.getInt("prev_state", RubikState.MAIN.ordinal() ); |
|
81 |
|
|
82 |
mCurrState = getState(currState); |
|
83 |
mPrevState = getState(prevState); |
|
80 | 84 |
} |
81 | 85 |
|
82 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 87 |
|
84 | 88 |
public static void goBack(RubikActivity act) |
85 | 89 |
{ |
86 |
switchState(act, mCurrentState.mBack );
|
|
90 |
switchState(act, mCurrState.mBack ); |
|
87 | 91 |
} |
88 | 92 |
|
89 | 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
90 | 94 |
|
91 | 95 |
public static void setState(RubikActivity act) |
92 | 96 |
{ |
93 |
mCurrentState.enterState(act);
|
|
97 |
mCurrState.enterState(act,mPrevState);
|
|
94 | 98 |
} |
95 | 99 |
|
96 | 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
99 | 103 |
{ |
100 | 104 |
if( state!=null ) |
101 | 105 |
{ |
102 |
if( mCurrentState!=null ) mCurrentState.leaveState(act); |
|
103 |
state.enterState(act); |
|
104 |
mCurrentState = state; |
|
106 |
if( mCurrState!=null ) mCurrState.leaveState(act); |
|
107 |
state.enterState(act,mCurrState); |
|
108 |
mPrevState = mCurrState; |
|
109 |
mCurrState = state; |
|
105 | 110 |
} |
106 | 111 |
else |
107 | 112 |
{ |
... | ... | |
133 | 138 |
|
134 | 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
135 | 140 |
|
136 |
public void enterState(RubikActivity act) |
|
141 |
public void enterState(RubikActivity act, RubikState prevState)
|
|
137 | 142 |
{ |
138 |
mClass.enterState(act); |
|
143 |
mClass.enterState(act,prevState);
|
|
139 | 144 |
} |
140 | 145 |
} |
Also available in: Unified diff
Progress with Pretty Patterns.