Revision 46405bb4
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
81 | 81 |
private static int mScreenWidth, mScreenHeight; |
82 | 82 |
private boolean mPolicyAccepted, mIsChinese; |
83 | 83 |
private int mCurrentApiVersion; |
84 |
private boolean mIsLocked; |
|
84 | 85 |
|
85 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
86 | 87 |
|
... | ... | |
100 | 101 |
mScreenHeight=displaymetrics.heightPixels; |
101 | 102 |
|
102 | 103 |
mIsChinese = localeIsChinese(); |
104 |
mIsLocked = false; |
|
103 | 105 |
|
104 | 106 |
hideNavigationBar(); |
105 | 107 |
huaweiHack(); |
... | ... | |
489 | 491 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
490 | 492 |
return view.isVertical(); |
491 | 493 |
} |
494 |
|
|
495 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
496 |
|
|
497 |
public void toggleLock() |
|
498 |
{ |
|
499 |
mIsLocked = !mIsLocked; |
|
500 |
} |
|
501 |
|
|
502 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
503 |
|
|
504 |
public boolean isLocked() |
|
505 |
{ |
|
506 |
RubikState state = RubikState.getCurrentState(); |
|
507 |
|
|
508 |
if( state==RubikState.PLAY || state==RubikState.READ || state==RubikState.SOLV ) |
|
509 |
{ |
|
510 |
return mIsLocked; |
|
511 |
} |
|
512 |
|
|
513 |
return false; |
|
514 |
} |
|
515 |
|
|
516 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
517 |
|
|
518 |
public boolean retLocked() |
|
519 |
{ |
|
520 |
return mIsLocked; |
|
521 |
} |
|
492 | 522 |
} |
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
338 | 338 |
} |
339 | 339 |
else |
340 | 340 |
{ |
341 |
mDragging = true; |
|
341 |
final RubikActivity act = (RubikActivity)getContext(); |
|
342 |
|
|
343 |
mDragging = !act.isLocked(); |
|
342 | 344 |
mBeginningRotation = false; |
343 | 345 |
mContinuingRotation = false; |
344 | 346 |
} |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
56 | 56 |
private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about }; |
57 | 57 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
58 | 58 |
|
59 |
private ImageButton mObjButton, mMenuButton, mPrevButton, mSolveButton; |
|
59 |
private ImageButton mObjButton, mMenuButton, mPrevButton, mSolveButton, mLockButton;
|
|
60 | 60 |
private Button mPlayButton; |
61 | 61 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
62 | 62 |
private int mObject = DEF_OBJECT; |
... | ... | |
137 | 137 |
|
138 | 138 |
setupPrevButton(act,width); |
139 | 139 |
layoutLeft.addView(mPrevButton); |
140 |
setupLockButton(act,width); |
|
141 |
layoutMid.addView(mLockButton); |
|
140 | 142 |
setupSolveButton(act,width); |
141 | 143 |
layoutRight.addView(mSolveButton); |
142 | 144 |
|
... | ... | |
298 | 300 |
}); |
299 | 301 |
} |
300 | 302 |
|
303 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
304 |
|
|
305 |
private void setupLockButton(final RubikActivity act, final float width) |
|
306 |
{ |
|
307 |
int padding = (int)(width*RubikActivity.PADDING); |
|
308 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
309 |
|
|
310 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); |
|
311 |
params.topMargin = margin; |
|
312 |
params.bottomMargin = margin; |
|
313 |
params.leftMargin = margin; |
|
314 |
params.rightMargin = margin; |
|
315 |
|
|
316 |
mLockButton = new ImageButton(act); |
|
317 |
mLockButton.setLayoutParams(params); |
|
318 |
mLockButton.setPadding(padding,0,padding,0); |
|
319 |
mLockButton.setImageResource(getLockIcon(act)); |
|
320 |
|
|
321 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
322 |
{ |
|
323 |
@Override |
|
324 |
public void onClick(View v) |
|
325 |
{ |
|
326 |
toggleLock(act); |
|
327 |
} |
|
328 |
}); |
|
329 |
} |
|
330 |
|
|
301 | 331 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
302 | 332 |
|
303 | 333 |
private void setupPrevButton(final RubikActivity act, final float width) |
... | ... | |
535 | 565 |
} |
536 | 566 |
} |
537 | 567 |
|
568 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
569 |
|
|
570 |
private void toggleLock(RubikActivity act) |
|
571 |
{ |
|
572 |
act.toggleLock(); |
|
573 |
mLockButton.setImageResource(getLockIcon(act)); |
|
574 |
} |
|
575 |
|
|
576 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
577 |
|
|
578 |
private int getLockIcon(RubikActivity act) |
|
579 |
{ |
|
580 |
if( act.retLocked() ) |
|
581 |
{ |
|
582 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
583 |
} |
|
584 |
else |
|
585 |
{ |
|
586 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
587 |
} |
|
588 |
} |
|
589 |
|
|
538 | 590 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
539 | 591 |
|
540 | 592 |
public void savePreferences(SharedPreferences.Editor editor) |
src/main/java/org/distorted/states/RubikStateReady.java | ||
---|---|---|
23 | 23 |
import android.util.TypedValue; |
24 | 24 |
import android.view.LayoutInflater; |
25 | 25 |
import android.view.View; |
26 |
import android.widget.Button; |
|
27 | 26 |
import android.widget.ImageButton; |
28 | 27 |
import android.widget.LinearLayout; |
29 | 28 |
import android.widget.TextView; |
... | ... | |
35 | 34 |
|
36 | 35 |
public class RubikStateReady extends RubikStateAbstract |
37 | 36 |
{ |
38 |
private ImageButton mPrevButton; |
|
37 |
private ImageButton mPrevButton, mLockButton, mBackButton;
|
|
39 | 38 |
|
40 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 40 |
|
... | ... | |
49 | 48 |
void enterState(final RubikActivity act) |
50 | 49 |
{ |
51 | 50 |
float width = act.getScreenWidthInPixels(); |
52 |
float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
|
53 | 51 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
54 | 52 |
|
55 | 53 |
LayoutInflater inflater = act.getLayoutInflater(); |
... | ... | |
75 | 73 |
LinearLayout layoutRight = new LinearLayout(act); |
76 | 74 |
layoutRight.setLayoutParams(paramsL); |
77 | 75 |
|
78 |
setupPrevMoveButtom(act,width);
|
|
76 |
setupPrevButtom(act,width); |
|
79 | 77 |
layoutLeft.addView(mPrevButton); |
78 |
setupLockButton(act,width); |
|
79 |
layoutMid.addView(mLockButton); |
|
80 |
setupBackButton(act,width); |
|
81 |
layoutRight.addView(mBackButton); |
|
80 | 82 |
|
83 |
layoutBot.addView(layoutLeft); |
|
84 |
layoutBot.addView(layoutMid); |
|
85 |
layoutBot.addView(layoutRight); |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
private void setupBackButton(final RubikActivity act, float width) |
|
91 |
{ |
|
81 | 92 |
int padding = (int)(width*RubikActivity.PADDING); |
82 | 93 |
int margin = (int)(width*RubikActivity.MARGIN); |
94 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back); |
|
95 |
|
|
83 | 96 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
84 | 97 |
params.topMargin = margin; |
85 | 98 |
params.bottomMargin = margin; |
86 | 99 |
params.leftMargin = margin; |
87 | 100 |
params.rightMargin = margin; |
88 | 101 |
|
89 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back); |
|
90 |
|
|
91 |
ImageButton back = new ImageButton(act); |
|
92 |
back.setLayoutParams(params); |
|
93 |
back.setPadding(padding,0,padding,0); |
|
94 |
back.setImageResource(icon); |
|
102 |
mBackButton = new ImageButton(act); |
|
103 |
mBackButton.setLayoutParams(params); |
|
104 |
mBackButton.setPadding(padding,0,padding,0); |
|
105 |
mBackButton.setImageResource(icon); |
|
95 | 106 |
|
96 |
back.setOnClickListener( new View.OnClickListener()
|
|
107 |
mBackButton.setOnClickListener( new View.OnClickListener()
|
|
97 | 108 |
{ |
98 | 109 |
@Override |
99 | 110 |
public void onClick(View v) |
... | ... | |
101 | 112 |
RubikState.goBack(act); |
102 | 113 |
} |
103 | 114 |
}); |
115 |
} |
|
104 | 116 |
|
105 |
layoutRight.addView(back);
|
|
117 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
106 | 118 |
|
107 |
layoutBot.addView(layoutLeft); |
|
108 |
layoutBot.addView(layoutMid); |
|
109 |
layoutBot.addView(layoutRight); |
|
119 |
private void setupLockButton(final RubikActivity act, final float width) |
|
120 |
{ |
|
121 |
int padding = (int)(width*RubikActivity.PADDING); |
|
122 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
123 |
|
|
124 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); |
|
125 |
params.topMargin = margin; |
|
126 |
params.bottomMargin = margin; |
|
127 |
params.leftMargin = margin; |
|
128 |
params.rightMargin = margin; |
|
129 |
|
|
130 |
mLockButton = new ImageButton(act); |
|
131 |
mLockButton.setLayoutParams(params); |
|
132 |
mLockButton.setPadding(padding,0,padding,0); |
|
133 |
mLockButton.setImageResource(getLockIcon(act)); |
|
134 |
|
|
135 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
136 |
{ |
|
137 |
@Override |
|
138 |
public void onClick(View v) |
|
139 |
{ |
|
140 |
toggleLock(act); |
|
141 |
} |
|
142 |
}); |
|
110 | 143 |
} |
111 | 144 |
|
112 | 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
113 | 146 |
|
114 |
private void setupPrevMoveButtom(final RubikActivity act, float width)
|
|
147 |
private void setupPrevButtom(final RubikActivity act, float width) |
|
115 | 148 |
{ |
116 | 149 |
int padding = (int)(width*RubikActivity.PADDING); |
117 | 150 |
int margin = (int)(width*RubikActivity.MARGIN); |
... | ... | |
138 | 171 |
}); |
139 | 172 |
} |
140 | 173 |
|
174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
175 |
|
|
176 |
private void toggleLock(RubikActivity act) |
|
177 |
{ |
|
178 |
act.toggleLock(); |
|
179 |
mLockButton.setImageResource(getLockIcon(act)); |
|
180 |
} |
|
181 |
|
|
182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
183 |
|
|
184 |
private int getLockIcon(RubikActivity act) |
|
185 |
{ |
|
186 |
if( act.retLocked() ) |
|
187 |
{ |
|
188 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
189 |
} |
|
190 |
else |
|
191 |
{ |
|
192 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
141 | 196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
142 | 197 |
|
143 | 198 |
public void savePreferences(SharedPreferences.Editor editor) |
src/main/java/org/distorted/states/RubikStateSolving.java | ||
---|---|---|
23 | 23 |
import android.util.TypedValue; |
24 | 24 |
import android.view.LayoutInflater; |
25 | 25 |
import android.view.View; |
26 |
import android.widget.Button; |
|
27 | 26 |
import android.widget.ImageButton; |
28 | 27 |
import android.widget.LinearLayout; |
29 | 28 |
import android.widget.TextView; |
... | ... | |
50 | 49 |
private long mStartTime; |
51 | 50 |
private boolean mRunning; |
52 | 51 |
private RubikScores mScores; |
53 |
private ImageButton mPrevButton; |
|
52 |
private ImageButton mPrevButton, mLockButton, mBackButton;
|
|
54 | 53 |
private boolean mCanPrevMove; |
55 | 54 |
private ArrayList<Move> mMoves; |
56 | 55 |
private long mElapsed; |
... | ... | |
86 | 85 |
void enterState(final RubikActivity act) |
87 | 86 |
{ |
88 | 87 |
float width = act.getScreenWidthInPixels(); |
89 |
float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
|
90 | 88 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
91 | 89 |
|
92 | 90 |
mCanPrevMove = true; |
... | ... | |
120 | 118 |
LinearLayout layoutRight = new LinearLayout(act); |
121 | 119 |
layoutRight.setLayoutParams(paramsL); |
122 | 120 |
|
123 |
setupPrevMoveButtom(act,width);
|
|
121 |
setupPrevButtom(act,width); |
|
124 | 122 |
layoutLeft.addView(mPrevButton); |
123 |
setupLockButton(act,width); |
|
124 |
layoutMid.addView(mLockButton); |
|
125 |
setupBackButtom(act,width); |
|
126 |
layoutRight.addView(mBackButton); |
|
125 | 127 |
|
128 |
layoutBot.addView(layoutLeft); |
|
129 |
layoutBot.addView(layoutMid); |
|
130 |
layoutBot.addView(layoutRight); |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
135 |
|
|
136 |
private void setupBackButtom(final RubikActivity act, float width) |
|
137 |
{ |
|
126 | 138 |
int padding = (int)(width*RubikActivity.PADDING); |
127 | 139 |
int margin = (int)(width*RubikActivity.MARGIN); |
140 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back); |
|
141 |
|
|
128 | 142 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
129 | 143 |
params.topMargin = margin; |
130 | 144 |
params.bottomMargin = margin; |
131 | 145 |
params.leftMargin = margin; |
132 | 146 |
params.rightMargin = margin; |
133 | 147 |
|
134 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back); |
|
148 |
mBackButton = new ImageButton(act); |
|
149 |
mBackButton.setLayoutParams(params); |
|
150 |
mBackButton.setPadding(padding,0,padding,0); |
|
151 |
mBackButton.setImageResource(icon); |
|
135 | 152 |
|
136 |
ImageButton back = new ImageButton(act); |
|
137 |
back.setLayoutParams(params); |
|
138 |
back.setPadding(padding,0,padding,0); |
|
139 |
back.setImageResource(icon); |
|
140 |
|
|
141 |
back.setOnClickListener( new View.OnClickListener() |
|
153 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
142 | 154 |
{ |
143 | 155 |
@Override |
144 | 156 |
public void onClick(View v) |
... | ... | |
146 | 158 |
RubikState.goBack(act); |
147 | 159 |
} |
148 | 160 |
}); |
161 |
} |
|
149 | 162 |
|
150 |
layoutRight.addView(back);
|
|
163 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
151 | 164 |
|
152 |
layoutBot.addView(layoutLeft); |
|
153 |
layoutBot.addView(layoutMid); |
|
154 |
layoutBot.addView(layoutRight); |
|
165 |
private void setupLockButton(final RubikActivity act, final float width) |
|
166 |
{ |
|
167 |
int padding = (int)(width*RubikActivity.PADDING); |
|
168 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
169 |
|
|
170 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); |
|
171 |
params.topMargin = margin; |
|
172 |
params.bottomMargin = margin; |
|
173 |
params.leftMargin = margin; |
|
174 |
params.rightMargin = margin; |
|
175 |
|
|
176 |
mLockButton = new ImageButton(act); |
|
177 |
mLockButton.setLayoutParams(params); |
|
178 |
mLockButton.setPadding(padding,0,padding,0); |
|
179 |
mLockButton.setImageResource(getLockIcon(act)); |
|
180 |
|
|
181 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
182 |
{ |
|
183 |
@Override |
|
184 |
public void onClick(View v) |
|
185 |
{ |
|
186 |
toggleLock(act); |
|
187 |
} |
|
188 |
}); |
|
155 | 189 |
} |
156 | 190 |
|
157 | 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
158 | 192 |
|
159 |
private void setupPrevMoveButtom(final RubikActivity act, float width)
|
|
193 |
private void setupPrevButtom(final RubikActivity act, float width) |
|
160 | 194 |
{ |
161 | 195 |
int padding = (int)(width*RubikActivity.PADDING); |
162 | 196 |
int margin = (int)(width*RubikActivity.MARGIN); |
... | ... | |
215 | 249 |
} |
216 | 250 |
} |
217 | 251 |
|
252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
|
|
254 |
private void toggleLock(RubikActivity act) |
|
255 |
{ |
|
256 |
act.toggleLock(); |
|
257 |
mLockButton.setImageResource(getLockIcon(act)); |
|
258 |
} |
|
259 |
|
|
260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
261 |
|
|
262 |
private int getLockIcon(RubikActivity act) |
|
263 |
{ |
|
264 |
if( act.retLocked() ) |
|
265 |
{ |
|
266 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
267 |
} |
|
268 |
else |
|
269 |
{ |
|
270 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
271 |
} |
|
272 |
} |
|
273 |
|
|
218 | 274 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
219 | 275 |
|
220 | 276 |
public void addMove(int axis, int row, int angle) |
Also available in: Unified diff
Add lock button.