Revision f5da732a
Added by Leszek Koltunski almost 3 years ago
src/main/java/org/distorted/screens/ScreenList.java | ||
---|---|---|
41 | 41 |
; |
42 | 42 |
|
43 | 43 |
public static final int LENGTH = values().length; |
44 |
private static final ScreenList[] screens; |
|
44 | 45 |
private final ScreenList mBack; |
45 |
private int mMode; |
|
46 |
private final int mMode;
|
|
46 | 47 |
private final RubikScreenAbstract mClass; |
47 |
private static final ScreenList[] states; |
|
48 | 48 |
|
49 |
private static ScreenList mCurrState;
|
|
49 |
private static ScreenList mCurrScreen;
|
|
50 | 50 |
|
51 | 51 |
static |
52 | 52 |
{ |
53 | 53 |
int i = 0; |
54 |
states = new ScreenList[LENGTH]; |
|
55 |
|
|
56 |
for(ScreenList state: ScreenList.values()) |
|
57 |
{ |
|
58 |
states[i] = state; |
|
59 |
i++; |
|
60 |
} |
|
54 |
screens = new ScreenList[LENGTH]; |
|
55 |
for(ScreenList state: ScreenList.values()) screens[i++] = state; |
|
61 | 56 |
} |
62 | 57 |
|
63 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 59 |
|
65 |
public static ScreenList getState(int ordinal)
|
|
60 |
public static ScreenList getScreen(int ordinal)
|
|
66 | 61 |
{ |
67 |
return ordinal>=0 && ordinal<LENGTH ? states[ordinal] : PLAY;
|
|
62 |
return ordinal>=0 && ordinal<LENGTH ? screens[ordinal] : PLAY;
|
|
68 | 63 |
} |
69 | 64 |
|
70 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
71 | 66 |
|
72 |
public static ScreenList getStateFromName(String name)
|
|
67 |
public static ScreenList getScreenFromName(String name)
|
|
73 | 68 |
{ |
74 | 69 |
for(int i=0; i<LENGTH; i++) |
75 | 70 |
{ |
76 |
if( name.equals(states[i].name()) )
|
|
71 |
if( name.equals(screens[i].name()) )
|
|
77 | 72 |
{ |
78 |
return states[i];
|
|
73 |
return screens[i];
|
|
79 | 74 |
} |
80 | 75 |
} |
81 | 76 |
|
... | ... | |
84 | 79 |
|
85 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
86 | 81 |
|
87 |
public static ScreenList getCurrentState()
|
|
82 |
public static ScreenList getCurrentScreen()
|
|
88 | 83 |
{ |
89 |
return mCurrState;
|
|
84 |
return mCurrScreen;
|
|
90 | 85 |
} |
91 | 86 |
|
92 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
93 | 88 |
|
94 | 89 |
public static int getMode() |
95 | 90 |
{ |
96 |
return mCurrState.mMode;
|
|
91 |
return mCurrScreen.mMode;
|
|
97 | 92 |
} |
98 | 93 |
|
99 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 | 95 |
|
101 | 96 |
public static void savePreferences(SharedPreferences.Editor editor) |
102 | 97 |
{ |
103 |
editor.putString("curr_state_name", mCurrState.name() );
|
|
98 |
editor.putString("curr_state_name", mCurrScreen.name() );
|
|
104 | 99 |
} |
105 | 100 |
|
106 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
107 | 102 |
|
108 | 103 |
public static void restorePreferences(SharedPreferences preferences) |
109 | 104 |
{ |
110 |
String currStateName = preferences.getString("curr_state_name", ScreenList.PLAY.name() );
|
|
111 |
mCurrState = getStateFromName(currStateName);
|
|
105 |
String currScreenName = preferences.getString("curr_state_name", ScreenList.PLAY.name() );
|
|
106 |
mCurrScreen = getScreenFromName(currScreenName);
|
|
112 | 107 |
} |
113 | 108 |
|
114 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
115 | 110 |
|
116 | 111 |
public static void goBack(RubikActivity act) |
117 | 112 |
{ |
118 |
switchState(act, mCurrState.mBack );
|
|
113 |
switchScreen(act, mCurrScreen.mBack );
|
|
119 | 114 |
} |
120 | 115 |
|
121 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
122 | 117 |
|
123 |
public static void setState(RubikActivity act)
|
|
118 |
public static void setScreen(RubikActivity act)
|
|
124 | 119 |
{ |
125 |
mCurrState.enterState(act);
|
|
120 |
mCurrScreen.enterScreen(act);
|
|
126 | 121 |
} |
127 | 122 |
|
128 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
129 | 124 |
|
130 |
public static void switchState(RubikActivity act, ScreenList next)
|
|
125 |
public static void switchScreen(RubikActivity act, ScreenList next)
|
|
131 | 126 |
{ |
132 | 127 |
if( next!=null ) |
133 | 128 |
{ |
... | ... | |
140 | 135 |
analytics.logEvent(FirebaseAnalytics.Event.LEVEL_START, bundle); |
141 | 136 |
} |
142 | 137 |
|
143 |
if( mCurrState!=null ) mCurrState.leaveState(act);
|
|
144 |
next.enterState(act);
|
|
145 |
mCurrState = next;
|
|
138 |
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act);
|
|
139 |
next.enterScreen(act);
|
|
140 |
mCurrScreen = next;
|
|
146 | 141 |
} |
147 | 142 |
else |
148 | 143 |
{ |
... | ... | |
161 | 156 |
|
162 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
163 | 158 |
|
164 |
public RubikScreenAbstract getStateClass()
|
|
159 |
public RubikScreenAbstract getScreenClass()
|
|
165 | 160 |
{ |
166 | 161 |
return mClass; |
167 | 162 |
} |
168 | 163 |
|
169 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
170 | 165 |
|
171 |
public void leaveState(RubikActivity act)
|
|
166 |
public void leaveScreen(RubikActivity act)
|
|
172 | 167 |
{ |
173 |
mClass.leaveState(act);
|
|
168 |
mClass.leaveScreen(act);
|
|
174 | 169 |
} |
175 | 170 |
|
176 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
177 | 172 |
|
178 |
public void enterState(RubikActivity act)
|
|
173 |
public void enterScreen(RubikActivity act)
|
|
179 | 174 |
{ |
180 |
mClass.enterState(act);
|
|
175 |
mClass.enterScreen(act);
|
|
181 | 176 |
} |
182 | 177 |
} |
Also available in: Unified diff
Cube Control: step 2.