Revision cc88f2fa
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/helpers/MovesAndLockController.java | ||
---|---|---|
27 | 27 |
import org.distorted.main.RubikActivity; |
28 | 28 |
|
29 | 29 |
import java.util.ArrayList; |
30 |
import java.util.Timer; |
|
31 |
import java.util.TimerTask; |
|
30 | 32 |
|
31 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 34 |
|
33 | 35 |
public class MovesAndLockController implements MovesFinished |
34 | 36 |
{ |
35 | 37 |
private static final int MILLIS_PER_DEGREE = 6; |
38 |
private static final int LOCK_TIME = 300; |
|
36 | 39 |
|
37 | 40 |
private static class Move |
38 | 41 |
{ |
... | ... | |
50 | 53 |
private boolean mCanPrevMove; |
51 | 54 |
private TwistyPreRender mPre; |
52 | 55 |
private ImageButton mPrevButton, mLockButton; |
56 |
private long mLockTime; |
|
57 |
private Timer mTimer; |
|
58 |
private boolean mTimerRunning; |
|
53 | 59 |
|
54 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 61 |
// PUBLIC API |
56 | 62 |
|
57 | 63 |
public MovesAndLockController() |
58 | 64 |
{ |
65 |
mTimerRunning = false; |
|
66 |
mLockTime = 0; |
|
59 | 67 |
mCanPrevMove = true; |
60 | 68 |
|
61 | 69 |
if( mMoves==null ) mMoves = new ArrayList<>(); |
... | ... | |
67 | 75 |
public void toggleLock(TwistyActivity act) |
68 | 76 |
{ |
69 | 77 |
act.toggleLock(); |
70 |
mLockButton.setImageResource(getLockIcon(act)); |
|
78 |
mLockButton.setImageResource(getLockIcon(act,false));
|
|
71 | 79 |
} |
72 | 80 |
|
73 | 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
74 | 82 |
|
75 |
public int getLockIcon(TwistyActivity act) |
|
83 |
public int getLockIcon(TwistyActivity act, boolean red)
|
|
76 | 84 |
{ |
77 | 85 |
if( act.retLocked() ) |
78 | 86 |
{ |
79 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked, |
|
80 |
R.drawable.ui_medium_locked, |
|
81 |
R.drawable.ui_big_locked, |
|
82 |
R.drawable.ui_huge_locked); |
|
87 |
if( red ) |
|
88 |
{ |
|
89 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked_red, |
|
90 |
R.drawable.ui_medium_locked_red, |
|
91 |
R.drawable.ui_big_locked_red, |
|
92 |
R.drawable.ui_huge_locked_red); |
|
93 |
} |
|
94 |
else |
|
95 |
{ |
|
96 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked, |
|
97 |
R.drawable.ui_medium_locked, |
|
98 |
R.drawable.ui_big_locked, |
|
99 |
R.drawable.ui_huge_locked); |
|
100 |
} |
|
83 | 101 |
} |
84 | 102 |
else |
85 | 103 |
{ |
... | ... | |
158 | 176 |
}); |
159 | 177 |
} |
160 | 178 |
|
179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
180 |
|
|
181 |
private void changeLockIcon(TwistyActivity act, final boolean red) |
|
182 |
{ |
|
183 |
act.runOnUiThread(new Runnable() |
|
184 |
{ |
|
185 |
@Override |
|
186 |
public void run() |
|
187 |
{ |
|
188 |
if( mLockButton!=null ) |
|
189 |
mLockButton.setImageResource(getLockIcon(act,red)); |
|
190 |
} |
|
191 |
}); |
|
192 |
} |
|
193 |
|
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 |
|
|
196 |
public void reddenLock(final TwistyActivity act) |
|
197 |
{ |
|
198 |
mLockTime = System.currentTimeMillis(); |
|
199 |
|
|
200 |
if( !mTimerRunning ) |
|
201 |
{ |
|
202 |
changeLockIcon(act,true); |
|
203 |
|
|
204 |
mTimerRunning = true; |
|
205 |
mTimer = new Timer(); |
|
206 |
|
|
207 |
mTimer.scheduleAtFixedRate(new TimerTask() |
|
208 |
{ |
|
209 |
@Override |
|
210 |
public void run() |
|
211 |
{ |
|
212 |
act.runOnUiThread(new Runnable() |
|
213 |
{ |
|
214 |
@Override |
|
215 |
public void run() |
|
216 |
{ |
|
217 |
if( System.currentTimeMillis()-mLockTime > LOCK_TIME ) |
|
218 |
{ |
|
219 |
changeLockIcon(act,false); |
|
220 |
mTimer.cancel(); |
|
221 |
mTimer = null; |
|
222 |
mTimerRunning = false; |
|
223 |
} |
|
224 |
} |
|
225 |
}); |
|
226 |
} |
|
227 |
}, 0, LOCK_TIME); |
|
228 |
} |
|
229 |
} |
|
230 |
|
|
161 | 231 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
162 | 232 |
|
163 | 233 |
public void addMove(TwistyActivity act, int axis, int row, int angle) |
... | ... | |
202 | 272 |
|
203 | 273 |
public void setupLockButton(final TwistyActivity act, final float width) |
204 | 274 |
{ |
205 |
final int icon = getLockIcon(act); |
|
275 |
final int icon = getLockIcon(act,false);
|
|
206 | 276 |
mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
207 | 277 |
|
208 | 278 |
mLockButton.setOnClickListener( new View.OnClickListener() |
... | ... | |
225 | 295 |
public void run() |
226 | 296 |
{ |
227 | 297 |
if( mLockButton!=null ) |
228 |
mLockButton.setImageResource(getLockIcon(act)); |
|
298 |
mLockButton.setImageResource(getLockIcon(act,false));
|
|
229 | 299 |
} |
230 | 300 |
}); |
231 | 301 |
} |
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
342 | 342 |
else |
343 | 343 |
{ |
344 | 344 |
final RubikActivity act = (RubikActivity)getContext(); |
345 |
|
|
346 |
mDragging = (!act.isLocked() || mIsAutomatic);
|
|
345 |
final boolean locked= act.isLocked(); |
|
346 |
mDragging = (!locked || mIsAutomatic);
|
|
347 | 347 |
mBeginningRotation = false; |
348 | 348 |
mContinuingRotation = false; |
349 |
|
|
350 |
if( locked ) |
|
351 |
{ |
|
352 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
353 |
play.reddenLock(act); |
|
354 |
} |
|
349 | 355 |
} |
350 | 356 |
} |
351 | 357 |
} |
src/main/java/org/distorted/screens/RubikScreenBase.java | ||
---|---|---|
81 | 81 |
{ |
82 | 82 |
mController.addMove(act,axis,row,angle); |
83 | 83 |
} |
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
public void reddenLock(final TwistyActivity act) |
|
88 |
{ |
|
89 |
mController.reddenLock(act); |
|
90 |
} |
|
84 | 91 |
} |
src/main/java/org/distorted/screens/RubikScreenSolving.java | ||
---|---|---|
44 | 44 |
private Timer mTimer; |
45 | 45 |
private long mStartTime; |
46 | 46 |
private boolean mRunning; |
47 |
private RubikScores mScores; |
|
47 |
private final RubikScores mScores;
|
|
48 | 48 |
private long mElapsed; |
49 | 49 |
private ImageButton mBackButton; |
50 | 50 |
|
src/main/java/org/distorted/tutorials/TutorialState.java | ||
---|---|---|
131 | 131 |
{ |
132 | 132 |
mController = new MovesAndLockController(); |
133 | 133 |
} |
134 |
|
|
135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
|
137 |
public void reddenLock(final TwistyActivity act) |
|
138 |
{ |
|
139 |
mController.reddenLock(act); |
|
140 |
} |
|
134 | 141 |
} |
src/main/java/org/distorted/tutorials/TutorialSurfaceView.java | ||
---|---|---|
298 | 298 |
else |
299 | 299 |
{ |
300 | 300 |
final TutorialActivity act = (TutorialActivity)getContext(); |
301 |
mDragging = !act.isLocked(); |
|
301 |
boolean locked = act.isLocked(); |
|
302 |
mDragging = !locked; |
|
302 | 303 |
mContinuingRotation = false; |
303 | 304 |
mBeginningRotation = false; |
305 |
|
|
306 |
if( locked ) |
|
307 |
{ |
|
308 |
TutorialState state = act.getState(); |
|
309 |
state.reddenLock(act); |
|
310 |
} |
|
304 | 311 |
} |
305 | 312 |
} |
306 | 313 |
|
Also available in: Unified diff
Give visual indication when dragging is locked.