Revision 15ed3429
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/main/MainActivity.java | ||
---|---|---|
409 | 409 |
public void switchToPlay(RubikObject object, int scrambles, boolean free) |
410 | 410 |
{ |
411 | 411 |
Intent intent = new Intent(this, PlayActivity.class); |
412 |
intent.putExtra("name", object.getLowerName());
|
|
412 |
intent.putExtra("name", object.getUpperName());
|
|
413 | 413 |
intent.putExtra("scrambles", scrambles); |
414 | 414 |
intent.putExtra("local", object.isLocal() ); |
415 | 415 |
intent.putExtra("ordinal", object.getObjectOrdinal() ); |
src/main/java/org/distorted/playui/PlayActivity.java | ||
---|---|---|
40 | 40 |
|
41 | 41 |
public class PlayActivity extends AppCompatActivity |
42 | 42 |
{ |
43 |
public static final int FLAGS = MainActivity.FLAGS; |
|
44 |
public static final float TITLE_TEXT_SIZE= 0.060f; |
|
43 | 45 |
private static final int ACTIVITY_NUMBER = 6; |
44 | 46 |
private static final float RATIO_BAR = MainActivity.RATIO_BAR; |
45 | 47 |
private static final float RATIO_INSET = 0.09f; |
46 |
public static final int FLAGS = MainActivity.FLAGS; |
|
48 |
|
|
49 |
private static final String KEY_FREE = "movesController_free"; |
|
50 |
private static final String KEY_SOLV = "movesController_solv"; |
|
47 | 51 |
|
48 | 52 |
private static int mScreenWidth, mScreenHeight; |
49 | 53 |
private int mCurrentApiVersion; |
50 |
private PlayScreen mScreen; |
|
51 | 54 |
private String mObjectName; |
52 | 55 |
private int mNumScrambles; |
53 | 56 |
private int mHeightUpperBar; |
... | ... | |
205 | 208 |
PlayView view = findViewById(R.id.playView); |
206 | 209 |
view.onResume(); |
207 | 210 |
|
208 |
if( mScreen==null ) mScreen = new PlayScreen(); |
|
209 |
mScreen.onAttachedToWindow(this, mObjectName); |
|
210 |
restorePreferences(); |
|
211 |
ScreenList.switchScreen(this,ScreenList.FREE); |
|
212 |
|
|
213 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
214 |
restorePreferences(preferences); |
|
215 |
restoreMoves(preferences); |
|
211 | 216 |
|
212 | 217 |
if( mObjectName.length()>0 ) |
213 | 218 |
{ |
... | ... | |
230 | 235 |
{ |
231 | 236 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
232 | 237 |
SharedPreferences.Editor editor = preferences.edit(); |
233 |
mScreen.savePreferences(this,editor); |
|
238 |
|
|
239 |
for( int i=0; i<ScreenList.LENGTH; i++ ) |
|
240 |
{ |
|
241 |
ScreenList.getScreen(i).getScreenClass().savePreferences(editor); |
|
242 |
} |
|
243 |
|
|
244 |
ScreenList.savePreferences(editor); |
|
245 |
|
|
246 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
247 |
|
|
248 |
if( curr==ScreenList.FREE ) |
|
249 |
{ |
|
250 |
ScreenFree free = (ScreenFree) ScreenList.FREE.getScreenClass(); |
|
251 |
free.saveMovePreferences(KEY_FREE,editor); |
|
252 |
} |
|
253 |
if( curr==ScreenList.SOLV ) |
|
254 |
{ |
|
255 |
ScreenSolving solv = (ScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
256 |
solv.saveMovePreferences(KEY_SOLV,editor); |
|
257 |
} |
|
234 | 258 |
|
235 | 259 |
editor.apply(); |
236 | 260 |
} |
237 | 261 |
|
238 | 262 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
239 | 263 |
|
240 |
private void restorePreferences() |
|
264 |
private void restorePreferences(SharedPreferences preferences)
|
|
241 | 265 |
{ |
242 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
243 |
mScreen.restorePreferences(this,preferences); |
|
266 |
for( int i=0; i<ScreenList.LENGTH; i++) |
|
267 |
{ |
|
268 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences); |
|
269 |
} |
|
270 |
|
|
271 |
ScreenList.restorePreferences(preferences); |
|
272 |
} |
|
273 |
|
|
274 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
275 |
|
|
276 |
private void restoreMoves(SharedPreferences preferences) |
|
277 |
{ |
|
278 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
279 |
|
|
280 |
if( curr==ScreenList.FREE ) |
|
281 |
{ |
|
282 |
ScreenFree free = (ScreenFree) ScreenList.FREE.getScreenClass(); |
|
283 |
free.restoreMovePreferences(this,KEY_FREE,preferences); |
|
284 |
} |
|
285 |
if( curr==ScreenList.SOLV ) |
|
286 |
{ |
|
287 |
ScreenSolving solv = (ScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
288 |
solv.restoreMovePreferences(this,KEY_SOLV,preferences); |
|
289 |
} |
|
244 | 290 |
} |
245 | 291 |
|
246 | 292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
255 | 301 |
|
256 | 302 |
private void changeIfDifferent(String upperName, boolean local, int ordinal, ObjectControl control) |
257 | 303 |
{ |
258 |
android.util.Log.e("D", "changing to "+upperName+" local: "+local+" ordinal: "+ordinal); |
|
259 |
|
|
260 | 304 |
if( local ) |
261 | 305 |
{ |
262 | 306 |
RubikFiles files = RubikFiles.getInstance(); |
... | ... | |
309 | 353 |
PlayView view = findViewById(R.id.playView); |
310 | 354 |
return view.getObjectControl(); |
311 | 355 |
} |
312 |
|
|
313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
314 |
|
|
315 |
public PlayScreen getScreen() |
|
316 |
{ |
|
317 |
return mScreen; |
|
318 |
} |
|
319 | 356 |
} |
src/main/java/org/distorted/playui/PlayLibInterface.java | ||
---|---|---|
51 | 51 |
|
52 | 52 |
if( act!=null ) |
53 | 53 |
{ |
54 |
PlayScreen play = act.getScreen(); |
|
55 |
play.addMove(act,axis,row,angle); |
|
54 |
ScreenList screen = ScreenList.getCurrentScreen(); |
|
55 |
|
|
56 |
if( screen==ScreenList.FREE ) ((ScreenFree )screen.getScreenClass()).addMove(act,axis,row,angle); |
|
57 |
if( screen==ScreenList.SOLV ) ((ScreenSolving)screen.getScreenClass()).addMove(act,axis,row,angle); |
|
56 | 58 |
} |
57 | 59 |
} |
58 | 60 |
|
... | ... | |
64 | 66 |
|
65 | 67 |
if( act!=null ) |
66 | 68 |
{ |
67 |
PlayScreen play = act.getScreen(); |
|
68 |
play.reddenLock(act); |
|
69 |
ScreenList screen = ScreenList.getCurrentScreen(); |
|
70 |
|
|
71 |
if( screen==ScreenList.FREE ) ((ScreenFree )screen.getScreenClass()).reddenLock(act); |
|
72 |
if( screen==ScreenList.SOLV ) ((ScreenSolving)screen.getScreenClass()).reddenLock(act); |
|
69 | 73 |
} |
70 | 74 |
} |
71 | 75 |
|
src/main/java/org/distorted/playui/PlayScreen.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.playui; |
|
11 |
|
|
12 |
import android.app.Activity; |
|
13 |
import android.content.SharedPreferences; |
|
14 |
import android.view.View; |
|
15 |
import android.widget.LinearLayout; |
|
16 |
|
|
17 |
import org.distorted.objectlib.effects.BaseEffect; |
|
18 |
import org.distorted.objectlib.main.ObjectControl; |
|
19 |
import org.distorted.os.OSInterface; |
|
20 |
import org.distorted.helpers.LockController; |
|
21 |
import org.distorted.helpers.MovesController; |
|
22 |
import org.distorted.helpers.TransparentImageButton; |
|
23 |
import org.distorted.main.R; |
|
24 |
|
|
25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
26 |
|
|
27 |
public class PlayScreen |
|
28 |
{ |
|
29 |
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton; |
|
30 |
private final LockController mLockController; |
|
31 |
private final MovesController mMovesController; |
|
32 |
private String mKey; |
|
33 |
|
|
34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
|
36 |
public PlayScreen() |
|
37 |
{ |
|
38 |
mLockController = new LockController(); |
|
39 |
mMovesController= new MovesController(); |
|
40 |
} |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
private void setupBackButton(final PlayActivity act) |
|
45 |
{ |
|
46 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
47 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_smallback,params); |
|
48 |
|
|
49 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
50 |
{ |
|
51 |
@Override |
|
52 |
public void onClick(View v) |
|
53 |
{ |
|
54 |
act.finish(); |
|
55 |
} |
|
56 |
}); |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
|
61 |
private void setupSolveButton(final PlayActivity act) |
|
62 |
{ |
|
63 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
64 |
mSolveButton = new TransparentImageButton(act,R.drawable.ui_cube_solve,params); |
|
65 |
|
|
66 |
mSolveButton.setOnClickListener( new View.OnClickListener() |
|
67 |
{ |
|
68 |
@Override |
|
69 |
public void onClick(View v) |
|
70 |
{ |
|
71 |
ObjectControl control = act.getControl(); |
|
72 |
control.solveObject(); |
|
73 |
mMovesController.clearMoves(act); |
|
74 |
} |
|
75 |
}); |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
private void setupScrambleButton(final PlayActivity act) |
|
81 |
{ |
|
82 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
83 |
mScrambleButton = new TransparentImageButton(act,R.drawable.ui_cube_scramble,params); |
|
84 |
|
|
85 |
mScrambleButton.setOnClickListener( new View.OnClickListener() |
|
86 |
{ |
|
87 |
@Override |
|
88 |
public void onClick(View v) |
|
89 |
{ |
|
90 |
ObjectControl control = act.getControl(); |
|
91 |
int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration(); |
|
92 |
int numScrambles = act.getNumScrambles(); |
|
93 |
control.fastScrambleObject(duration,numScrambles); |
|
94 |
mMovesController.clearMoves(act); |
|
95 |
} |
|
96 |
}); |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
void onAttachedToWindow(final PlayActivity act, String objectName) |
|
102 |
{ |
|
103 |
mKey = "moveController_"+objectName; |
|
104 |
|
|
105 |
int width = act.getScreenWidthInPixels(); |
|
106 |
|
|
107 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
108 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT); |
|
109 |
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
110 |
|
|
111 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
112 |
layoutLeft.setLayoutParams(paramsL); |
|
113 |
LinearLayout layoutMid = new LinearLayout(act); |
|
114 |
layoutMid.setLayoutParams(paramsM); |
|
115 |
LinearLayout layoutRight= new LinearLayout(act); |
|
116 |
layoutRight.setLayoutParams(paramsR); |
|
117 |
|
|
118 |
setupBackButton(act); |
|
119 |
ObjectControl control = act.getControl(); |
|
120 |
mMovesController.setupButton(act,control); |
|
121 |
layoutLeft.addView(mMovesController.getButton()); |
|
122 |
mLockController.setupButton(act,control); |
|
123 |
layoutMid.addView(mLockController.getButton()); |
|
124 |
|
|
125 |
layoutRight.addView(mBackButton); |
|
126 |
|
|
127 |
LinearLayout layoutLower = act.findViewById(R.id.lowerBar); |
|
128 |
layoutLower.removeAllViews(); |
|
129 |
layoutLower.addView(layoutLeft); |
|
130 |
layoutLower.addView(layoutMid); |
|
131 |
layoutLower.addView(layoutRight); |
|
132 |
|
|
133 |
setupSolveButton(act); |
|
134 |
setupScrambleButton(act); |
|
135 |
|
|
136 |
LinearLayout layoutUpper = act.findViewById(R.id.upperBar); |
|
137 |
|
|
138 |
LinearLayout layoutLeftU = new LinearLayout(act); |
|
139 |
layoutLeftU.setLayoutParams(paramsL); |
|
140 |
LinearLayout layoutMidU = new LinearLayout(act); |
|
141 |
layoutMidU.setLayoutParams(paramsM); |
|
142 |
LinearLayout layoutRightU= new LinearLayout(act); |
|
143 |
layoutRightU.setLayoutParams(paramsR); |
|
144 |
|
|
145 |
layoutLeftU.addView(mSolveButton); |
|
146 |
layoutRightU.addView(mScrambleButton); |
|
147 |
|
|
148 |
layoutUpper.removeAllViews(); |
|
149 |
layoutUpper.addView(layoutLeftU); |
|
150 |
layoutUpper.addView(layoutMidU); |
|
151 |
layoutUpper.addView(layoutRightU); |
|
152 |
} |
|
153 |
|
|
154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 |
|
|
156 |
public void reddenLock(final PlayActivity act) |
|
157 |
{ |
|
158 |
ObjectControl control = act.getControl(); |
|
159 |
mLockController.reddenLock(act,control); |
|
160 |
} |
|
161 |
|
|
162 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
163 |
|
|
164 |
public void addMove(Activity act, int axis, int row, int angle) |
|
165 |
{ |
|
166 |
mMovesController.addMove(act,axis,row,angle); |
|
167 |
} |
|
168 |
|
|
169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
170 |
|
|
171 |
public void savePreferences(PlayActivity act, SharedPreferences.Editor editor) |
|
172 |
{ |
|
173 |
mMovesController.savePreferences(mKey,editor); |
|
174 |
ObjectControl control = act.getControl(); |
|
175 |
OSInterface os = (OSInterface)control.getOS(); |
|
176 |
os.setEditor(editor); |
|
177 |
control.savePreferences(); |
|
178 |
} |
|
179 |
|
|
180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
181 |
|
|
182 |
public void restorePreferences(PlayActivity act, SharedPreferences preferences) |
|
183 |
{ |
|
184 |
mMovesController.restorePreferences(act,mKey,preferences); |
|
185 |
ObjectControl control = act.getControl(); |
|
186 |
OSInterface os = (OSInterface)control.getOS(); |
|
187 |
os.setPreferences(preferences); |
|
188 |
control.restorePreferences(); |
|
189 |
} |
|
190 |
} |
src/main/java/org/distorted/playui/ScreenAbstract.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.playui; |
|
11 |
|
|
12 |
import android.content.SharedPreferences; |
|
13 |
|
|
14 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
15 |
|
|
16 |
public abstract class ScreenAbstract |
|
17 |
{ |
|
18 |
abstract void enterScreen(PlayActivity act); |
|
19 |
abstract void leaveScreen(PlayActivity act); |
|
20 |
public abstract void savePreferences(SharedPreferences.Editor editor); |
|
21 |
public abstract void restorePreferences(SharedPreferences preferences); |
|
22 |
} |
src/main/java/org/distorted/playui/ScreenBase.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.playui; |
|
11 |
|
|
12 |
import android.content.SharedPreferences; |
|
13 |
import android.widget.LinearLayout; |
|
14 |
|
|
15 |
import org.distorted.helpers.LockController; |
|
16 |
import org.distorted.helpers.MovesController; |
|
17 |
import org.distorted.helpers.TransparentImageButton; |
|
18 |
import org.distorted.main.R; |
|
19 |
import org.distorted.objectlib.main.ObjectControl; |
|
20 |
|
|
21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
22 |
|
|
23 |
abstract class ScreenBase extends ScreenAbstract |
|
24 |
{ |
|
25 |
private final LockController mLockController; |
|
26 |
protected MovesController mMovesController; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
void createBottomPane(final PlayActivity act, TransparentImageButton butt) |
|
31 |
{ |
|
32 |
mMovesController.clearMoves(act); |
|
33 |
|
|
34 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
35 |
layoutBot.removeAllViews(); |
|
36 |
|
|
37 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1); |
|
38 |
|
|
39 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
40 |
layoutLeft.setLayoutParams(params); |
|
41 |
LinearLayout layoutMid = new LinearLayout(act); |
|
42 |
layoutMid.setLayoutParams(params); |
|
43 |
LinearLayout layoutRight = new LinearLayout(act); |
|
44 |
layoutRight.setLayoutParams(params); |
|
45 |
|
|
46 |
ObjectControl control = act.getControl(); |
|
47 |
mMovesController.setupButton(act,control); |
|
48 |
layoutLeft.addView(mMovesController.getButton()); |
|
49 |
mLockController.setupButton(act,control); |
|
50 |
layoutMid.addView(mLockController.getButton()); |
|
51 |
|
|
52 |
if( butt !=null ) layoutRight.addView(butt); |
|
53 |
|
|
54 |
layoutBot.addView(layoutLeft); |
|
55 |
layoutBot.addView(layoutMid); |
|
56 |
layoutBot.addView(layoutRight); |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
|
61 |
public void setLockState(final PlayActivity act) |
|
62 |
{ |
|
63 |
boolean locked = act.getControl().retLocked(); |
|
64 |
mLockController.setState(act,locked); |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
// PUBLIC API |
|
69 |
|
|
70 |
public ScreenBase() |
|
71 |
{ |
|
72 |
mLockController = new LockController(); |
|
73 |
mMovesController= new MovesController(); |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
public void addMove(PlayActivity act, int axis, int row, int angle) |
|
79 |
{ |
|
80 |
mMovesController.addMove(act,axis,row,angle); |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
public void reddenLock(final PlayActivity act) |
|
86 |
{ |
|
87 |
ObjectControl control = act.getControl(); |
|
88 |
mLockController.reddenLock(act,control); |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
public void saveMovePreferences(String key,SharedPreferences.Editor editor) |
|
94 |
{ |
|
95 |
mMovesController.savePreferences(key,editor); |
|
96 |
} |
|
97 |
|
|
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
|
100 |
public void restoreMovePreferences(PlayActivity act, String key, SharedPreferences preferences) |
|
101 |
{ |
|
102 |
mMovesController.restorePreferences(act,key,preferences); |
|
103 |
} |
|
104 |
} |
src/main/java/org/distorted/playui/ScreenDone.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.playui; |
|
11 |
|
|
12 |
import android.content.SharedPreferences; |
|
13 |
import android.util.TypedValue; |
|
14 |
import android.view.LayoutInflater; |
|
15 |
import android.view.View; |
|
16 |
import android.widget.LinearLayout; |
|
17 |
import android.widget.TextView; |
|
18 |
|
|
19 |
import androidx.fragment.app.FragmentManager; |
|
20 |
|
|
21 |
import org.distorted.dialogs.RubikDialogNewRecord; |
|
22 |
import org.distorted.dialogs.RubikDialogSolved; |
|
23 |
import org.distorted.helpers.TransparentImageButton; |
|
24 |
import org.distorted.main.R; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
public class ScreenDone extends ScreenAbstract |
|
29 |
{ |
|
30 |
private TransparentImageButton mBackButton; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
void leaveScreen(PlayActivity act) |
|
35 |
{ |
|
36 |
|
|
37 |
} |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
void enterScreen(final PlayActivity act) |
|
42 |
{ |
|
43 |
float width = act.getScreenWidthInPixels(); |
|
44 |
float titleSize = width*PlayActivity.TITLE_TEXT_SIZE; |
|
45 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
46 |
|
|
47 |
// TOP //////////////////////////// |
|
48 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
49 |
layoutTop.removeAllViews(); |
|
50 |
TextView label = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
51 |
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
52 |
label.setText(R.string.solved); |
|
53 |
layoutTop.addView(label); |
|
54 |
|
|
55 |
// BOT //////////////////////////// |
|
56 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
57 |
layoutBot.removeAllViews(); |
|
58 |
|
|
59 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1); |
|
60 |
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,2); |
|
61 |
|
|
62 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
63 |
layoutLeft.setLayoutParams(paramsL); |
|
64 |
LinearLayout layoutRight = new LinearLayout(act); |
|
65 |
layoutRight.setLayoutParams(paramsR); |
|
66 |
|
|
67 |
setupBackButton(act); |
|
68 |
|
|
69 |
layoutRight.addView(mBackButton); |
|
70 |
layoutBot.addView(layoutLeft); |
|
71 |
layoutBot.addView(layoutRight); |
|
72 |
} |
|
73 |
|
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
private void setupBackButton(final PlayActivity act) |
|
77 |
{ |
|
78 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
79 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params); |
|
80 |
|
|
81 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
82 |
{ |
|
83 |
@Override |
|
84 |
public void onClick(View v) |
|
85 |
{ |
|
86 |
ScreenList.goBack(act); |
|
87 |
|
|
88 |
FragmentManager mana = act.getSupportFragmentManager(); |
|
89 |
RubikDialogNewRecord diag1 = (RubikDialogNewRecord) mana.findFragmentByTag(RubikDialogNewRecord.getDialogTag()); |
|
90 |
RubikDialogSolved diag2 = (RubikDialogSolved ) mana.findFragmentByTag(RubikDialogSolved.getDialogTag()); |
|
91 |
|
|
92 |
if( diag1 !=null ) diag1.dismiss(); |
|
93 |
if( diag2 !=null ) diag2.dismiss(); |
|
94 |
} |
|
95 |
}); |
|
96 |
} |
|
97 |
|
|
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
|
100 |
public void savePreferences(SharedPreferences.Editor editor) |
|
101 |
{ |
|
102 |
|
|
103 |
} |
|
104 |
|
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
public void restorePreferences(SharedPreferences preferences) |
|
108 |
{ |
|
109 |
|
|
110 |
} |
|
111 |
} |
src/main/java/org/distorted/playui/ScreenFree.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.playui; |
|
11 |
|
|
12 |
import android.content.SharedPreferences; |
|
13 |
import android.view.View; |
|
14 |
import android.widget.LinearLayout; |
|
15 |
|
|
16 |
import org.distorted.helpers.TransparentImageButton; |
|
17 |
import org.distorted.main.R; |
|
18 |
import org.distorted.objectlib.effects.BaseEffect; |
|
19 |
import org.distorted.objectlib.main.ObjectControl; |
|
20 |
|
|
21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
22 |
|
|
23 |
public class ScreenFree extends ScreenBase |
|
24 |
{ |
|
25 |
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
void leaveScreen(PlayActivity act) |
|
30 |
{ |
|
31 |
|
|
32 |
} |
|
33 |
|
|
34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
|
36 |
void enterScreen(final PlayActivity act) |
|
37 |
{ |
|
38 |
int width = act.getScreenWidthInPixels(); |
|
39 |
|
|
40 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
41 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT); |
|
42 |
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
43 |
|
|
44 |
// TOP //////////////////////////// |
|
45 |
setupSolveButton(act); |
|
46 |
setupScrambleButton(act); |
|
47 |
|
|
48 |
LinearLayout layoutUpper = act.findViewById(R.id.upperBar); |
|
49 |
|
|
50 |
LinearLayout layoutLeftU = new LinearLayout(act); |
|
51 |
layoutLeftU.setLayoutParams(paramsL); |
|
52 |
LinearLayout layoutMidU = new LinearLayout(act); |
|
53 |
layoutMidU.setLayoutParams(paramsM); |
|
54 |
LinearLayout layoutRightU= new LinearLayout(act); |
|
55 |
layoutRightU.setLayoutParams(paramsR); |
|
56 |
|
|
57 |
layoutLeftU.addView(mSolveButton); |
|
58 |
layoutRightU.addView(mScrambleButton); |
|
59 |
|
|
60 |
layoutUpper.removeAllViews(); |
|
61 |
layoutUpper.addView(layoutLeftU); |
|
62 |
layoutUpper.addView(layoutMidU); |
|
63 |
layoutUpper.addView(layoutRightU); |
|
64 |
|
|
65 |
// BOT //////////////////////////// |
|
66 |
setupBackButton(act); |
|
67 |
createBottomPane(act,mBackButton); |
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
private void setupBackButton(final PlayActivity act) |
|
73 |
{ |
|
74 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
75 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_smallback,params); |
|
76 |
|
|
77 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
78 |
{ |
|
79 |
@Override |
|
80 |
public void onClick(View v) |
|
81 |
{ |
|
82 |
act.finish(); |
|
83 |
} |
|
84 |
}); |
|
85 |
} |
|
86 |
|
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
private void setupSolveButton(final PlayActivity act) |
|
90 |
{ |
|
91 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
92 |
mSolveButton = new TransparentImageButton(act,R.drawable.ui_cube_solve,params); |
|
93 |
|
|
94 |
mSolveButton.setOnClickListener( new View.OnClickListener() |
|
95 |
{ |
|
96 |
@Override |
|
97 |
public void onClick(View v) |
|
98 |
{ |
|
99 |
ObjectControl control = act.getControl(); |
|
100 |
control.solveObject(); |
|
101 |
mMovesController.clearMoves(act); |
|
102 |
} |
|
103 |
}); |
|
104 |
} |
|
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
private void setupScrambleButton(final PlayActivity act) |
|
109 |
{ |
|
110 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
111 |
mScrambleButton = new TransparentImageButton(act,R.drawable.ui_cube_scramble,params); |
|
112 |
|
|
113 |
mScrambleButton.setOnClickListener( new View.OnClickListener() |
|
114 |
{ |
|
115 |
@Override |
|
116 |
public void onClick(View v) |
|
117 |
{ |
|
118 |
ObjectControl control = act.getControl(); |
|
119 |
int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration(); |
|
120 |
int numScrambles = act.getNumScrambles(); |
|
121 |
control.fastScrambleObject(duration,numScrambles); |
|
122 |
mMovesController.clearMoves(act); |
|
123 |
} |
|
124 |
}); |
|
125 |
} |
|
126 |
|
|
127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
128 |
|
|
129 |
public void savePreferences(SharedPreferences.Editor editor) |
|
130 |
{ |
|
131 |
|
|
132 |
} |
|
133 |
|
|
134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
135 |
|
|
136 |
public void restorePreferences(SharedPreferences preferences) |
|
137 |
{ |
|
138 |
|
|
139 |
} |
|
140 |
} |
src/main/java/org/distorted/playui/ScreenList.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.playui; |
|
11 |
|
|
12 |
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG; |
|
13 |
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE; |
|
14 |
|
|
15 |
import android.content.SharedPreferences; |
|
16 |
|
|
17 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
18 |
|
|
19 |
public enum ScreenList |
|
20 |
{ |
|
21 |
FREE ( null , MODE_ROTATE , new ScreenFree() ), |
|
22 |
SCRA ( null , MODE_ROTATE , new ScreenScrambling() ), |
|
23 |
SOLV ( null , MODE_ROTATE , new ScreenSolving() ), |
|
24 |
DONE ( null , MODE_DRAG , new ScreenDone() ), |
|
25 |
; |
|
26 |
|
|
27 |
public static final int LENGTH = values().length; |
|
28 |
private static final ScreenList[] screens; |
|
29 |
private final ScreenList mBack; |
|
30 |
private final int mMode; |
|
31 |
private final ScreenAbstract mClass; |
|
32 |
|
|
33 |
private static ScreenList mCurrScreen; |
|
34 |
|
|
35 |
static |
|
36 |
{ |
|
37 |
int i = 0; |
|
38 |
screens = new ScreenList[LENGTH]; |
|
39 |
for(ScreenList state: ScreenList.values()) screens[i++] = state; |
|
40 |
} |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
public static ScreenList getScreen(int ordinal) |
|
45 |
{ |
|
46 |
return ordinal>=0 && ordinal<LENGTH ? screens[ordinal] : SCRA; |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public static ScreenList getScreenFromName(String name) |
|
52 |
{ |
|
53 |
for(int i=0; i<LENGTH; i++) |
|
54 |
{ |
|
55 |
if( name.equals(screens[i].name()) ) |
|
56 |
{ |
|
57 |
return screens[i]; |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
return SCRA; |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
public static ScreenList getCurrentScreen() |
|
67 |
{ |
|
68 |
return mCurrScreen; |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
public static int getMode() |
|
74 |
{ |
|
75 |
return mCurrScreen.mMode; |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
public static void savePreferences(SharedPreferences.Editor editor) |
|
81 |
{ |
|
82 |
editor.putString("curr_state_name", mCurrScreen.name() ); |
|
83 |
} |
|
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
public static void restorePreferences(SharedPreferences preferences) |
|
88 |
{ |
|
89 |
String currScreenName = preferences.getString("curr_state_name", ScreenList.SCRA.name() ); |
|
90 |
mCurrScreen = getScreenFromName(currScreenName); |
|
91 |
} |
|
92 |
|
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
public static void goBack(PlayActivity act) |
|
96 |
{ |
|
97 |
switchScreen(act, mCurrScreen.mBack ); |
|
98 |
} |
|
99 |
|
|
100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
101 |
|
|
102 |
public static void setScreen(PlayActivity act) |
|
103 |
{ |
|
104 |
mCurrScreen.enterScreen(act); |
|
105 |
} |
|
106 |
|
|
107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
108 |
|
|
109 |
public static void switchScreen(PlayActivity act, ScreenList next) |
|
110 |
{ |
|
111 |
if( next!=null ) |
|
112 |
{ |
|
113 |
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act); |
|
114 |
next.enterScreen(act); |
|
115 |
mCurrScreen = next; |
|
116 |
} |
|
117 |
else |
|
118 |
{ |
|
119 |
act.finish(); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 |
|
|
125 |
ScreenList(ScreenList back, int mode, ScreenAbstract clazz) |
|
126 |
{ |
|
127 |
mBack = back; |
|
128 |
mMode = mode; |
|
129 |
mClass= clazz; |
|
130 |
} |
|
131 |
|
|
132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
|
134 |
public ScreenAbstract getScreenClass() |
|
135 |
{ |
|
136 |
return mClass; |
|
137 |
} |
|
138 |
|
|
139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
140 |
|
|
141 |
public void leaveScreen(PlayActivity act) |
|
142 |
{ |
|
143 |
mClass.leaveScreen(act); |
|
144 |
} |
|
145 |
|
|
146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
147 |
|
|
148 |
public void enterScreen(PlayActivity act) |
|
149 |
{ |
|
150 |
mClass.enterScreen(act); |
|
151 |
} |
|
152 |
} |
src/main/java/org/distorted/playui/ScreenScrambling.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.playui; |
|
11 |
|
|
12 |
import android.content.SharedPreferences; |
|
13 |
import android.util.TypedValue; |
|
14 |
import android.view.LayoutInflater; |
|
15 |
import android.view.View; |
|
16 |
import android.widget.LinearLayout; |
|
17 |
import android.widget.TextView; |
|
18 |
|
|
19 |
import org.distorted.helpers.TransparentImageButton; |
|
20 |
import org.distorted.main.R; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public class ScreenScrambling extends ScreenBase |
|
25 |
{ |
|
26 |
private TransparentImageButton mBackButton; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
void leaveScreen(PlayActivity act) |
|
31 |
{ |
|
32 |
|
|
33 |
} |
|
34 |
|
|
35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
36 |
|
|
37 |
void enterScreen(final PlayActivity act) |
|
38 |
{ |
|
39 |
float width = act.getScreenWidthInPixels(); |
|
40 |
float titleSize = width*PlayActivity.TITLE_TEXT_SIZE; |
|
41 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
42 |
|
|
43 |
// TOP //////////////////////////// |
|
44 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
45 |
layoutTop.removeAllViews(); |
|
46 |
TextView label = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
47 |
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
48 |
label.setText(R.string.ready); |
|
49 |
layoutTop.addView(label); |
|
50 |
|
|
51 |
setupBackButton(act); |
|
52 |
createBottomPane(act,mBackButton); |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
private void setupBackButton(final PlayActivity act) |
|
58 |
{ |
|
59 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
60 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params); |
|
61 |
|
|
62 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
63 |
{ |
|
64 |
@Override |
|
65 |
public void onClick(View v) |
|
66 |
{ |
|
67 |
ScreenList.goBack(act); |
|
68 |
} |
|
69 |
}); |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
public void savePreferences(SharedPreferences.Editor editor) |
|
75 |
{ |
|
76 |
|
|
77 |
} |
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
|
|
81 |
public void restorePreferences(SharedPreferences preferences) |
|
82 |
{ |
|
83 |
|
|
84 |
} |
|
85 |
} |
src/main/java/org/distorted/playui/ScreenSolving.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.playui; |
|
11 |
|
|
12 |
import android.content.SharedPreferences; |
|
13 |
import android.util.TypedValue; |
|
14 |
import android.view.LayoutInflater; |
|
15 |
import android.view.View; |
|
16 |
import android.widget.LinearLayout; |
|
17 |
import android.widget.TextView; |
|
18 |
|
|
19 |
import org.distorted.dialogs.RubikDialogAbandon; |
|
20 |
import org.distorted.external.RubikScores; |
|
21 |
import org.distorted.helpers.TransparentImageButton; |
|
22 |
import org.distorted.main.R; |
|
23 |
import org.distorted.objects.RubikObjectList; |
|
24 |
|
|
25 |
import java.util.Timer; |
|
26 |
import java.util.TimerTask; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
public class ScreenSolving extends ScreenBase |
|
31 |
{ |
|
32 |
private static final int MOVES_THRESHHOLD = 10; |
|
33 |
|
|
34 |
private TextView mTime; |
|
35 |
private Timer mTimer; |
|
36 |
private long mStartTime; |
|
37 |
private boolean mRunning; |
|
38 |
private final RubikScores mScores; |
|
39 |
private long mElapsed; |
|
40 |
private TransparentImageButton mBackButton; |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
ScreenSolving() |
|
45 |
{ |
|
46 |
mScores = RubikScores.getInstance(); |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
void leaveScreen(PlayActivity act) |
|
52 |
{ |
|
53 |
stopCounting(); |
|
54 |
} |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
void enterScreen(final PlayActivity act) |
|
59 |
{ |
|
60 |
float width = act.getScreenWidthInPixels(); |
|
61 |
float titleSize = width*PlayActivity.TITLE_TEXT_SIZE; |
|
62 |
|
|
63 |
startCounting(act); |
|
64 |
|
|
65 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
66 |
|
|
67 |
// TOP //////////////////////////// |
|
68 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
69 |
layoutTop.removeAllViews(); |
|
70 |
mTime = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
71 |
int elapsed = (int)mElapsed/1000; |
|
72 |
mTime.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
73 |
mTime.setText(act.getString(R.string.tm_placeholder,elapsed/60,elapsed%60)); |
|
74 |
layoutTop.addView(mTime); |
|
75 |
|
|
76 |
setupBackButton(act); |
|
77 |
createBottomPane(act,mBackButton); |
|
78 |
} |
|
79 |
|
|
80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 |
|
|
82 |
private void setupBackButton(final PlayActivity act) |
|
83 |
{ |
|
84 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
85 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params); |
|
86 |
|
|
87 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
88 |
{ |
|
89 |
@Override |
|
90 |
public void onClick(View v) |
|
91 |
{ |
|
92 |
if( mMovesController.getNumMoves() > MOVES_THRESHHOLD ) |
|
93 |
{ |
|
94 |
RubikDialogAbandon abaDiag = new RubikDialogAbandon(); |
|
95 |
abaDiag.show(act.getSupportFragmentManager(), null); |
|
96 |
} |
|
97 |
else |
|
98 |
{ |
|
99 |
ScreenList.goBack(act); |
|
100 |
} |
|
101 |
} |
|
102 |
}); |
|
103 |
} |
|
104 |
|
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
public void savePreferences(SharedPreferences.Editor editor) |
|
108 |
{ |
|
109 |
stopCounting(); |
|
110 |
|
|
111 |
mElapsed = System.currentTimeMillis()-mStartTime; |
|
112 |
editor.putLong("stateSolving_elapsed" , mElapsed); |
|
113 |
mScores.savePreferences(editor); |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
public void restorePreferences(SharedPreferences preferences) |
|
119 |
{ |
|
120 |
mElapsed = preferences.getLong("stateSolving_elapsed" , 0 ); |
|
121 |
mScores.restorePreferences(preferences); |
|
122 |
} |
|
123 |
|
|
124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
125 |
|
|
126 |
private void startCounting(final PlayActivity act) |
|
127 |
{ |
|
128 |
if( !mRunning ) |
|
129 |
{ |
|
130 |
mRunning = true; |
|
131 |
mStartTime = System.currentTimeMillis() - mElapsed; |
|
132 |
mTimer = new Timer(); |
|
133 |
|
|
134 |
mTimer.scheduleAtFixedRate(new TimerTask() |
|
135 |
{ |
|
136 |
@Override |
|
137 |
public void run() |
|
138 |
{ |
|
139 |
act.runOnUiThread(new Runnable() |
|
140 |
{ |
|
141 |
@Override |
|
142 |
public void run() |
|
143 |
{ |
|
144 |
int elapsed = (int)(System.currentTimeMillis()-mStartTime)/1000; |
|
145 |
mTime.setText(act.getString(R.string.tm_placeholder,elapsed/60,elapsed%60)); |
|
146 |
} |
|
147 |
}); |
|
148 |
} |
|
149 |
}, 0, 1000); |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
|
155 |
private void stopCounting() |
|
156 |
{ |
|
157 |
if( mTimer!=null ) |
|
158 |
{ |
|
159 |
mTimer.cancel(); |
|
160 |
mTimer = null; |
|
161 |
} |
|
162 |
|
|
163 |
mRunning = false; |
|
164 |
} |
|
165 |
|
|
166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
167 |
|
|
168 |
public int stopTimerAndGetRecord() |
|
169 |
{ |
|
170 |
if( mRunning ) |
|
171 |
{ |
|
172 |
stopCounting(); |
|
173 |
mElapsed = System.currentTimeMillis()-mStartTime; |
|
174 |
return (int)mElapsed; |
|
175 |
} |
|
176 |
|
|
177 |
return 0; |
|
178 |
} |
|
179 |
|
|
180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
181 |
|
|
182 |
public int setRecord() |
|
183 |
{ |
|
184 |
/* |
|
185 |
ScreenPlay play = (ScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
186 |
int level = play.getLevel()-1; |
|
187 |
*/ |
|
188 |
|
|
189 |
int level = 0; |
|
190 |
android.util.Log.e("D", "TODO: implement level!!"); |
|
191 |
|
|
192 |
int object = RubikObjectList.getCurrObject(); |
|
193 |
return mScores.setRecord(object, level, (int)mElapsed); |
|
194 |
} |
|
195 |
|
|
196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
197 |
|
|
198 |
public void resetElapsed() |
|
199 |
{ |
|
200 |
mElapsed = 0; |
|
201 |
} |
|
202 |
} |
Also available in: Unified diff
Progress with the generic PlayActivity.