Revision 9523ae28
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/helpers/LockController.java | ||
---|---|---|
22 | 22 |
import java.util.Timer; |
23 | 23 |
import java.util.TimerTask; |
24 | 24 |
|
25 |
import android.app.Activity; |
|
25 | 26 |
import android.view.View; |
26 | 27 |
import android.widget.ImageButton; |
27 | 28 |
import android.widget.LinearLayout; |
... | ... | |
29 | 30 |
import org.distorted.main.R; |
30 | 31 |
import org.distorted.main.RubikActivity; |
31 | 32 |
import org.distorted.objectlib.helpers.TwistyActivity; |
33 |
import org.distorted.objectlib.main.ObjectControl; |
|
32 | 34 |
|
33 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 36 |
|
... | ... | |
52 | 54 |
|
53 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 56 |
|
55 |
public void toggleLock(TwistyActivity act)
|
|
57 |
public void toggleLock(ObjectControl control)
|
|
56 | 58 |
{ |
57 |
act.toggleLock(); |
|
58 |
mLockButton.setImageResource(getLockIcon(act,false)); |
|
59 |
control.toggleLock(); |
|
60 |
boolean locked = control.retLocked(); |
|
61 |
mLockButton.setImageResource(getLockIcon(locked,false)); |
|
59 | 62 |
} |
60 | 63 |
|
61 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 65 |
|
63 |
private int getLockIcon(TwistyActivity act, boolean red)
|
|
66 |
private int getLockIcon(boolean locked, boolean red)
|
|
64 | 67 |
{ |
65 |
if( act.retLocked() )
|
|
68 |
if( locked )
|
|
66 | 69 |
{ |
67 | 70 |
if( red ) |
68 | 71 |
{ |
... | ... | |
90 | 93 |
|
91 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
92 | 95 |
|
93 |
private void changeIcon(TwistyActivity act, final boolean red)
|
|
96 |
private void changeIcon(Activity act, boolean locked, boolean red)
|
|
94 | 97 |
{ |
95 | 98 |
act.runOnUiThread(new Runnable() |
96 | 99 |
{ |
... | ... | |
98 | 101 |
public void run() |
99 | 102 |
{ |
100 | 103 |
if( mLockButton!=null ) |
101 |
mLockButton.setImageResource(getLockIcon(act,red));
|
|
104 |
mLockButton.setImageResource(getLockIcon(locked,red));
|
|
102 | 105 |
} |
103 | 106 |
}); |
104 | 107 |
} |
105 | 108 |
|
106 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
107 | 110 |
|
108 |
public void reddenLock(final TwistyActivity act)
|
|
111 |
public void reddenLock(final Activity act, ObjectControl control)
|
|
109 | 112 |
{ |
110 | 113 |
mLockTime = System.currentTimeMillis(); |
111 | 114 |
|
112 | 115 |
if( !mTimerRunning ) |
113 | 116 |
{ |
114 |
changeIcon(act,true); |
|
117 |
boolean locked = control.retLocked(); |
|
118 |
changeIcon(act,locked,true); |
|
115 | 119 |
|
116 | 120 |
mTimerRunning = true; |
117 | 121 |
mTimer = new Timer(); |
... | ... | |
128 | 132 |
{ |
129 | 133 |
if( System.currentTimeMillis()-mLockTime > LOCK_TIME ) |
130 | 134 |
{ |
131 |
changeIcon(act,false); |
|
135 |
boolean locked = control.retLocked(); |
|
136 |
changeIcon(act,locked,false); |
|
132 | 137 |
|
133 | 138 |
if( mTimer!=null ) |
134 | 139 |
{ |
... | ... | |
147 | 152 |
|
148 | 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
149 | 154 |
|
150 |
public void setupButton(final TwistyActivity act, final float width) |
|
155 |
public void setupButton(final TwistyActivity act, ObjectControl control, final float width)
|
|
151 | 156 |
{ |
152 |
final int icon = getLockIcon(act,false); |
|
157 |
boolean locked = control.retLocked(); |
|
158 |
final int icon = getLockIcon(locked,false); |
|
153 | 159 |
mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
154 | 160 |
|
155 | 161 |
mLockButton.setOnClickListener( new View.OnClickListener() |
... | ... | |
157 | 163 |
@Override |
158 | 164 |
public void onClick(View v) |
159 | 165 |
{ |
160 |
toggleLock(act);
|
|
166 |
toggleLock(control);
|
|
161 | 167 |
} |
162 | 168 |
}); |
163 | 169 |
} |
164 | 170 |
|
165 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
166 | 172 |
|
167 |
public void setState(final TwistyActivity act)
|
|
173 |
public void setState(final Activity act, boolean locked)
|
|
168 | 174 |
{ |
169 | 175 |
act.runOnUiThread(new Runnable() |
170 | 176 |
{ |
... | ... | |
172 | 178 |
public void run() |
173 | 179 |
{ |
174 | 180 |
if( mLockButton!=null ) |
175 |
mLockButton.setImageResource(getLockIcon(act,false));
|
|
181 |
mLockButton.setImageResource(getLockIcon(locked,false));
|
|
176 | 182 |
} |
177 | 183 |
}); |
178 | 184 |
} |
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
116 | 116 |
mScreenHeight=displaymetrics.heightPixels; |
117 | 117 |
|
118 | 118 |
mIsChinese = localeIsChinese(); |
119 |
unlock(); |
|
120 | 119 |
|
121 | 120 |
hideNavigationBar(); |
122 | 121 |
cutoutHack(); |
... | ... | |
446 | 445 |
control.changeObject(newObject); |
447 | 446 |
} |
448 | 447 |
|
449 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
450 |
|
|
451 |
public boolean isLocked() |
|
452 |
{ |
|
453 |
ScreenList state = ScreenList.getCurrentScreen(); |
|
454 |
|
|
455 |
if( state== ScreenList.PLAY || state== ScreenList.READ || state== ScreenList.SOLV ) |
|
456 |
{ |
|
457 |
return retLocked(); |
|
458 |
} |
|
459 |
|
|
460 |
return false; |
|
461 |
} |
|
462 |
|
|
463 | 448 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
464 | 449 |
|
465 | 450 |
public void setupObject(ObjectType object, int[][] moves) |
... | ... | |
548 | 533 |
|
549 | 534 |
public void blockEverything(int place) |
550 | 535 |
{ |
551 |
setLock(); |
|
552 |
|
|
553 | 536 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
554 | 537 |
ObjectControl control = view.getObjectControl(); |
555 | 538 |
control.blockEverything(place); |
... | ... | |
562 | 545 |
|
563 | 546 |
public void unblockEverything() |
564 | 547 |
{ |
565 |
unsetLock(); |
|
566 |
|
|
567 | 548 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
568 | 549 |
ObjectControl control = view.getObjectControl(); |
569 | 550 |
control.unblockEverything(); |
src/main/java/org/distorted/screens/RubikScreenBase.java | ||
---|---|---|
22 | 22 |
import android.widget.ImageButton; |
23 | 23 |
import android.widget.LinearLayout; |
24 | 24 |
|
25 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
26 |
import org.distorted.objectlib.main.ObjectControl; |
|
27 |
|
|
25 | 28 |
import org.distorted.helpers.LockController; |
26 | 29 |
import org.distorted.helpers.MovesController; |
27 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
28 | 30 |
import org.distorted.main.R; |
29 |
import org.distorted.main.RubikActivity; |
|
30 | 31 |
|
31 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 33 |
|
... | ... | |
37 | 38 |
|
38 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 40 |
|
40 |
void createBottomPane(final RubikActivity act, float width, ImageButton button)
|
|
41 |
void createBottomPane(final TwistyActivity act, float width, ImageButton button)
|
|
41 | 42 |
{ |
42 | 43 |
mMovesController.clearMoves(act); |
43 | 44 |
|
... | ... | |
55 | 56 |
|
56 | 57 |
mMovesController.setupButton(act,width); |
57 | 58 |
layoutLeft.addView(mMovesController.getButton()); |
58 |
mLockController.setupButton(act,width); |
|
59 |
mLockController.setupButton(act,act.getControl(),width);
|
|
59 | 60 |
layoutMid.addView(mLockController.getButton()); |
60 | 61 |
layoutRight.addView(button); |
61 | 62 |
|
... | ... | |
66 | 67 |
|
67 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 69 |
|
69 |
public void setLockState(final RubikActivity act)
|
|
70 |
public void setLockState(final TwistyActivity act)
|
|
70 | 71 |
{ |
71 |
mLockController.setState(act); |
|
72 |
boolean locked = act.getControl().retLocked(); |
|
73 |
mLockController.setState(act,locked); |
|
72 | 74 |
} |
73 | 75 |
|
74 | 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
91 | 93 |
|
92 | 94 |
public void reddenLock(final TwistyActivity act) |
93 | 95 |
{ |
94 |
mLockController.reddenLock(act); |
|
96 |
ObjectControl control = act.getControl(); |
|
97 |
mLockController.reddenLock(act,control); |
|
95 | 98 |
} |
96 | 99 |
} |
src/main/java/org/distorted/screens/RubikScreenSolution.java | ||
---|---|---|
29 | 29 |
import android.widget.TextView; |
30 | 30 |
|
31 | 31 |
import org.distorted.objectlib.main.ObjectControl; |
32 |
import org.distorted.objectlib.main.TwistyObject; |
|
33 | 32 |
import org.distorted.objectlib.helpers.MovesFinished; |
34 | 33 |
|
35 | 34 |
import org.distorted.helpers.TransparentImageButton; |
src/main/java/org/distorted/screens/RubikScreenSolver.java | ||
---|---|---|
62 | 62 |
|
63 | 63 |
void leaveScreen(RubikActivity act) |
64 | 64 |
{ |
65 |
|
|
65 |
ObjectControl control = act.getControl(); |
|
66 |
control.unsetLock(); |
|
66 | 67 |
} |
67 | 68 |
|
68 | 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
69 | 70 |
|
70 | 71 |
void enterScreen(final RubikActivity act) |
71 | 72 |
{ |
73 |
ObjectControl control = act.getControl(); |
|
74 |
control.setLock(false); |
|
75 |
|
|
72 | 76 |
float width = act.getScreenWidthInPixels(); |
73 | 77 |
float heigh = act.getScreenHeightInPixels(); |
74 | 78 |
|
src/main/java/org/distorted/tutorials/TutorialActivity.java | ||
---|---|---|
84 | 84 |
mObjectOrdinal = b.getInt("obj"); |
85 | 85 |
} |
86 | 86 |
|
87 |
unlock(); |
|
88 | 87 |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); |
89 | 88 |
|
90 | 89 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
... | ... | |
277 | 276 |
return renderer.getScreen(); |
278 | 277 |
} |
279 | 278 |
|
280 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
281 |
|
|
282 |
public boolean isLocked() |
|
283 |
{ |
|
284 |
return retLocked(); |
|
285 |
} |
|
286 |
|
|
287 | 279 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
288 | 280 |
|
289 | 281 |
public static int getDrawableSize() |
src/main/java/org/distorted/tutorials/TutorialScreen.java | ||
---|---|---|
108 | 108 |
layout.removeAllViews(); |
109 | 109 |
|
110 | 110 |
mMovesController.setupButton(act,width); |
111 |
mLockController.setupButton(act,width); |
|
111 |
mLockController.setupButton(act,act.getControl(),width);
|
|
112 | 112 |
setupSolveButton(act,width); |
113 | 113 |
setupScrambleButton(act,width); |
114 | 114 |
setupBackButton(act,width); |
... | ... | |
140 | 140 |
|
141 | 141 |
public void reddenLock(final TwistyActivity act) |
142 | 142 |
{ |
143 |
mLockController.reddenLock(act); |
|
143 |
mLockController.reddenLock(act,act.getControl());
|
|
144 | 144 |
} |
145 | 145 |
} |
Also available in: Unified diff
Hide most of the TwistyActivity methods inside objectlib.