Revision a8576d91
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/dialogs/RubikDialogAbout.java | ||
---|---|---|
80 | 80 |
TextView text = view.findViewById(R.id.about_version); |
81 | 81 |
String appName = getString(R.string.app_name); |
82 | 82 |
|
83 |
|
|
84 | 83 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
85 | 84 |
text.setText(getString(R.string.ap_placeholder,appName, getAppVers(act))); |
86 | 85 |
|
... | ... | |
115 | 114 |
|
116 | 115 |
if( window!=null ) |
117 | 116 |
{ |
118 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
119 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
120 | 117 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
121 | 118 |
} |
122 | 119 |
|
src/main/java/org/distorted/dialogs/RubikDialogEffects.java | ||
---|---|---|
261 | 261 |
} |
262 | 262 |
|
263 | 263 |
Dialog dialog = builder.create(); |
264 |
|
|
265 | 264 |
dialog.setCanceledOnTouchOutside(false); |
266 |
|
|
267 | 265 |
Window window = dialog.getWindow(); |
268 | 266 |
|
269 | 267 |
if( window!=null ) |
270 | 268 |
{ |
271 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
272 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
273 | 269 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
274 | 270 |
} |
275 | 271 |
|
src/main/java/org/distorted/dialogs/RubikDialogError.java | ||
---|---|---|
83 | 83 |
|
84 | 84 |
if( window!=null ) |
85 | 85 |
{ |
86 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
87 | 86 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
88 | 87 |
} |
89 | 88 |
|
src/main/java/org/distorted/dialogs/RubikDialogInfo.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.dialogs; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.content.DialogInterface; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.util.DisplayMetrics; |
|
26 |
import android.util.TypedValue; |
|
27 |
import android.view.LayoutInflater; |
|
28 |
import android.view.View; |
|
29 |
import android.view.Window; |
|
30 |
import android.widget.Button; |
|
31 |
import android.widget.TextView; |
|
32 |
|
|
33 |
import androidx.annotation.NonNull; |
|
34 |
import androidx.appcompat.app.AlertDialog; |
|
35 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
36 |
import androidx.fragment.app.FragmentActivity; |
|
37 |
|
|
38 |
import org.distorted.main.R; |
|
39 |
import org.distorted.main.RubikActivity; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public class RubikDialogInfo extends AppCompatDialogFragment |
|
44 |
{ |
|
45 |
@NonNull |
|
46 |
@Override |
|
47 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
48 |
{ |
|
49 |
final FragmentActivity act = getActivity(); |
|
50 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
51 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
52 |
|
|
53 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
54 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
55 |
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE; |
|
56 |
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE; |
|
57 |
|
|
58 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
59 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
60 |
tv.setText(R.string.opengl_error); |
|
61 |
builder.setCustomTitle(tv); |
|
62 |
|
|
63 |
final View view = inflater.inflate(R.layout.dialog_error, null); |
|
64 |
TextView text = view.findViewById(R.id.error_string); |
|
65 |
text.setText(R.string.opengl_error_text); |
|
66 |
|
|
67 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
68 |
{ |
|
69 |
@Override |
|
70 |
public void onClick(DialogInterface dialog, int which) |
|
71 |
{ |
|
72 |
|
|
73 |
} |
|
74 |
}); |
|
75 |
|
|
76 |
builder.setView(view); |
|
77 |
|
|
78 |
final Dialog dialog = builder.create(); |
|
79 |
dialog.setCanceledOnTouchOutside(false); |
|
80 |
|
|
81 |
Window window = dialog.getWindow(); |
|
82 |
|
|
83 |
if( window!=null ) |
|
84 |
{ |
|
85 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
86 |
} |
|
87 |
|
|
88 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
89 |
{ |
|
90 |
@Override |
|
91 |
public void onShow(DialogInterface dialog) |
|
92 |
{ |
|
93 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
94 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize); |
|
95 |
} |
|
96 |
}); |
|
97 |
|
|
98 |
return dialog; |
|
99 |
} |
|
100 |
} |
src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java | ||
---|---|---|
47 | 47 |
|
48 | 48 |
public class RubikDialogNewRecord extends AppCompatDialogFragment |
49 | 49 |
{ |
50 |
@Override |
|
51 |
public void onStart() |
|
52 |
{ |
|
53 |
super.onStart(); |
|
54 |
|
|
55 |
Dialog dialog = getDialog(); |
|
56 |
|
|
57 |
if( dialog!=null ) |
|
58 |
{ |
|
59 |
dialog.setCanceledOnTouchOutside(false); |
|
60 |
|
|
61 |
Window window = dialog.getWindow(); |
|
62 |
|
|
63 |
if( window!=null ) |
|
64 |
{ |
|
65 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 | 50 |
@NonNull |
73 | 51 |
@Override |
74 | 52 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
... | ... | |
157 | 135 |
submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
158 | 136 |
|
159 | 137 |
Dialog dialog = builder.create(); |
160 |
|
|
161 | 138 |
dialog.setCanceledOnTouchOutside(false); |
162 |
|
|
163 | 139 |
Window window = dialog.getWindow(); |
164 | 140 |
|
165 | 141 |
if( window!=null ) |
166 | 142 |
{ |
167 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
168 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
169 | 143 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
170 | 144 |
} |
171 | 145 |
|
src/main/java/org/distorted/dialogs/RubikDialogPattern.java | ||
---|---|---|
56 | 56 |
@Override |
57 | 57 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
58 | 58 |
{ |
59 |
FragmentActivity act = getActivity(); |
|
59 |
final FragmentActivity act = getActivity();
|
|
60 | 60 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
61 | 61 |
|
62 | 62 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
... | ... | |
70 | 70 |
tv.setText(R.string.choose_pattern); |
71 | 71 |
builder.setCustomTitle(tv); |
72 | 72 |
|
73 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
74 |
{ |
|
75 |
@Override |
|
76 |
public void onClick(DialogInterface dialog, int which) |
|
77 |
{ |
|
78 |
|
|
79 |
} |
|
80 |
}); |
|
81 |
|
|
73 | 82 |
Bundle args = getArguments(); |
74 | 83 |
int curTab; |
75 | 84 |
|
... | ... | |
106 | 115 |
} |
107 | 116 |
|
108 | 117 |
Dialog dialog = builder.create(); |
109 |
|
|
110 | 118 |
dialog.setCanceledOnTouchOutside(false); |
111 |
|
|
112 | 119 |
Window window = dialog.getWindow(); |
113 | 120 |
|
114 | 121 |
if( window!=null ) |
115 | 122 |
{ |
116 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
117 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
118 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
119 |
|
|
120 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
121 | 123 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
122 | 124 |
} |
123 | 125 |
|
src/main/java/org/distorted/dialogs/RubikDialogPatternView.java | ||
---|---|---|
92 | 92 |
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) |
93 | 93 |
{ |
94 | 94 |
RubikPattern pattern = RubikPattern.getInstance(); |
95 |
int[][] moves = pattern.reInitialize(mTab, groupPosition, childPosition); |
|
96 |
|
|
95 |
int[][] moves = pattern.reInitialize(mTab, groupPosition, childPosition); |
|
97 | 96 |
ObjectList list = RubikPatternList.getObject(mTab); |
98 |
int size = RubikPatternList.getSize(mTab);
|
|
97 |
int size = RubikPatternList.getSize(mTab); |
|
99 | 98 |
|
100 | 99 |
ract.setupObject(list, size, moves); |
101 | 100 |
|
101 |
StateList.switchState(ract,StateList.PATT); |
|
102 | 102 |
RubikStatePattern state = (RubikStatePattern) StateList.PATT.getStateClass(); |
103 |
|
|
104 | 103 |
state.setPattern(ract, mTab, groupPosition, childPosition); |
105 | 104 |
|
106 | 105 |
mDialog.rememberState(); |
src/main/java/org/distorted/dialogs/RubikDialogPrivacy.java | ||
---|---|---|
94 | 94 |
|
95 | 95 |
final Dialog dialog = builder.create(); |
96 | 96 |
dialog.setCanceledOnTouchOutside(false); |
97 |
|
|
98 | 97 |
Window window = dialog.getWindow(); |
99 | 98 |
|
100 | 99 |
if( window!=null ) |
101 | 100 |
{ |
102 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
103 | 101 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
104 | 102 |
} |
105 | 103 |
|
src/main/java/org/distorted/dialogs/RubikDialogScores.java | ||
---|---|---|
123 | 123 |
} |
124 | 124 |
|
125 | 125 |
Dialog dialog = builder.create(); |
126 |
|
|
127 | 126 |
dialog.setCanceledOnTouchOutside(false); |
128 |
|
|
129 | 127 |
Window window = dialog.getWindow(); |
130 | 128 |
|
131 | 129 |
if( window!=null ) |
132 | 130 |
{ |
133 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
134 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
135 | 131 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
136 | 132 |
} |
137 | 133 |
|
src/main/java/org/distorted/dialogs/RubikDialogSetName.java | ||
---|---|---|
183 | 183 |
}); |
184 | 184 |
|
185 | 185 |
dialog.setCanceledOnTouchOutside(false); |
186 |
|
|
187 | 186 |
Window window = dialog.getWindow(); |
188 | 187 |
|
189 | 188 |
if( window!=null ) |
190 | 189 |
{ |
191 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
192 | 190 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS2); |
193 | 191 |
} |
194 | 192 |
|
src/main/java/org/distorted/dialogs/RubikDialogSolved.java | ||
---|---|---|
93 | 93 |
builder.setView(view); |
94 | 94 |
|
95 | 95 |
Dialog dialog = builder.create(); |
96 |
|
|
97 | 96 |
dialog.setCanceledOnTouchOutside(false); |
98 |
|
|
99 | 97 |
Window window = dialog.getWindow(); |
100 | 98 |
|
101 | 99 |
if( window!=null ) |
102 | 100 |
{ |
103 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
104 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
105 | 101 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
106 | 102 |
} |
107 | 103 |
|
src/main/java/org/distorted/dialogs/RubikDialogSolverError.java | ||
---|---|---|
91 | 91 |
builder.setView(view); |
92 | 92 |
|
93 | 93 |
Dialog dialog = builder.create(); |
94 |
|
|
95 | 94 |
dialog.setCanceledOnTouchOutside(false); |
96 |
|
|
97 | 95 |
Window window = dialog.getWindow(); |
98 | 96 |
|
99 | 97 |
if( window!=null ) |
100 | 98 |
{ |
101 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
102 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
|
103 | 99 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
104 | 100 |
} |
105 | 101 |
|
src/main/java/org/distorted/states/RubikStateAbstract.java | ||
---|---|---|
25 | 25 |
import android.widget.LinearLayout; |
26 | 26 |
|
27 | 27 |
import org.distorted.main.RubikActivity; |
28 |
import org.distorted.objects.ObjectList; |
|
29 |
import org.distorted.patterns.RubikPatternList; |
|
28 | 30 |
|
29 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 32 |
|
... | ... | |
84 | 86 |
} |
85 | 87 |
} |
86 | 88 |
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
int getPatternOrdinal() |
|
92 |
{ |
|
93 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass(); |
|
94 |
int obj = play.getObject(); |
|
95 |
int size = play.getSize(); |
|
96 |
int ret = RubikPatternList.getOrdinal(obj,size); |
|
97 |
|
|
98 |
if( ret<0 ) |
|
99 |
{ |
|
100 |
ret = ObjectList.getSizeIndex(RubikStatePlay.DEF_OBJECT,RubikStatePlay.DEF_SIZE); |
|
101 |
} |
|
102 |
|
|
103 |
return ret; |
|
104 |
} |
|
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
87 | 108 |
abstract void enterState(RubikActivity act); |
88 | 109 |
abstract void leaveState(RubikActivity act); |
89 | 110 |
public abstract void savePreferences(SharedPreferences.Editor editor); |
src/main/java/org/distorted/states/RubikStateBase.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.states; |
|
21 |
|
|
22 |
import android.view.View; |
|
23 |
import android.widget.ImageButton; |
|
24 |
import android.widget.LinearLayout; |
|
25 |
|
|
26 |
import org.distorted.dialogs.RubikDialogInfo; |
|
27 |
import org.distorted.main.R; |
|
28 |
import org.distorted.main.RubikActivity; |
|
29 |
import org.distorted.main.RubikPreRender; |
|
30 |
import org.distorted.objects.TwistyObject; |
|
31 |
|
|
32 |
import java.util.ArrayList; |
|
33 |
|
|
34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
|
36 |
abstract class RubikStateBase extends RubikStateAbstract implements RubikPreRender.ActionFinishedListener |
|
37 |
{ |
|
38 |
private static final int DURATION_MILLIS = 750; |
|
39 |
|
|
40 |
private ImageButton mPrevButton, mLockButton, mInfoButton; |
|
41 |
|
|
42 |
private boolean mCanPrevMove; |
|
43 |
|
|
44 |
private static class Move |
|
45 |
{ |
|
46 |
private int mAxis, mRow, mAngle; |
|
47 |
|
|
48 |
Move(int axis, int row, int angle) |
|
49 |
{ |
|
50 |
mAxis = axis; |
|
51 |
mRow = row; |
|
52 |
mAngle= angle; |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
ArrayList<Move> mMoves; |
|
57 |
|
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
private void backMove(RubikPreRender pre) |
|
61 |
{ |
|
62 |
if( mCanPrevMove ) |
|
63 |
{ |
|
64 |
int numMoves = mMoves.size(); |
|
65 |
|
|
66 |
if( numMoves>0 ) |
|
67 |
{ |
|
68 |
RubikStateBase.Move move = mMoves.remove(numMoves-1); |
|
69 |
TwistyObject object = pre.getObject(); |
|
70 |
|
|
71 |
int axis = move.mAxis; |
|
72 |
int row = (1<<move.mRow); |
|
73 |
int angle = move.mAngle; |
|
74 |
int numRot= Math.abs(angle*object.getBasicAngle()/360); |
|
75 |
|
|
76 |
if( angle!=0 ) |
|
77 |
{ |
|
78 |
mCanPrevMove = false; |
|
79 |
pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS); |
|
80 |
} |
|
81 |
else |
|
82 |
{ |
|
83 |
android.util.Log.e("solution", "error: trying to back move of angle 0"); |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
private void toggleLock(RubikActivity act) |
|
92 |
{ |
|
93 |
act.toggleLock(); |
|
94 |
mLockButton.setImageResource(getLockIcon(act)); |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
private int getLockIcon(RubikActivity act) |
|
100 |
{ |
|
101 |
if( act.retLocked() ) |
|
102 |
{ |
|
103 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
104 |
} |
|
105 |
else |
|
106 |
{ |
|
107 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 |
|
|
113 |
void createBottomPane(final RubikActivity act, float width, ImageButton button) |
|
114 |
{ |
|
115 |
mCanPrevMove = true; |
|
116 |
|
|
117 |
if( mMoves==null ) mMoves = new ArrayList<>(); |
|
118 |
else mMoves.clear(); |
|
119 |
|
|
120 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
121 |
layoutBot.removeAllViews(); |
|
122 |
|
|
123 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1); |
|
124 |
|
|
125 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
126 |
layoutLeft.setLayoutParams(params); |
|
127 |
LinearLayout layoutMid = new LinearLayout(act); |
|
128 |
layoutMid.setLayoutParams(params); |
|
129 |
LinearLayout layoutRight = new LinearLayout(act); |
|
130 |
layoutRight.setLayoutParams(params); |
|
131 |
|
|
132 |
setupPrevButton(act,width); |
|
133 |
layoutLeft.addView(mPrevButton); |
|
134 |
setupLockButton(act,width); |
|
135 |
layoutMid.addView(mLockButton); |
|
136 |
setupInfoButton(act,width); |
|
137 |
layoutMid.addView(mInfoButton); |
|
138 |
layoutRight.addView(button); |
|
139 |
|
|
140 |
layoutBot.addView(layoutLeft); |
|
141 |
layoutBot.addView(layoutMid); |
|
142 |
layoutBot.addView(layoutRight); |
|
143 |
} |
|
144 |
|
|
145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 |
|
|
147 |
void setupLockButton(final RubikActivity act, final float width) |
|
148 |
{ |
|
149 |
final int icon = getLockIcon(act); |
|
150 |
mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
151 |
|
|
152 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
153 |
{ |
|
154 |
@Override |
|
155 |
public void onClick(View v) |
|
156 |
{ |
|
157 |
toggleLock(act); |
|
158 |
} |
|
159 |
}); |
|
160 |
} |
|
161 |
|
|
162 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
163 |
|
|
164 |
void setupInfoButton(final RubikActivity act, final float width) |
|
165 |
{ |
|
166 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info); |
|
167 |
mInfoButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
168 |
|
|
169 |
mInfoButton.setOnClickListener( new View.OnClickListener() |
|
170 |
{ |
|
171 |
@Override |
|
172 |
public void onClick(View v) |
|
173 |
{ |
|
174 |
RubikDialogInfo infoDiag = new RubikDialogInfo(); |
|
175 |
infoDiag.show(act.getSupportFragmentManager(), null); |
|
176 |
} |
|
177 |
}); |
|
178 |
} |
|
179 |
|
|
180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
181 |
|
|
182 |
void setupPrevButton(final RubikActivity act, final float width) |
|
183 |
{ |
|
184 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back); |
|
185 |
mPrevButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
186 |
|
|
187 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
188 |
{ |
|
189 |
@Override |
|
190 |
public void onClick(View v) |
|
191 |
{ |
|
192 |
RubikPreRender pre = act.getPreRender(); |
|
193 |
backMove(pre); |
|
194 |
} |
|
195 |
}); |
|
196 |
} |
|
197 |
|
|
198 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
199 |
|
|
200 |
public void addMove(int axis, int row, int angle) |
|
201 |
{ |
|
202 |
mMoves.add(new Move(axis,row,angle)); |
|
203 |
} |
|
204 |
|
|
205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
206 |
|
|
207 |
public void onActionFinished(final long effectID) |
|
208 |
{ |
|
209 |
mCanPrevMove = true; |
|
210 |
} |
|
211 |
} |
src/main/java/org/distorted/states/RubikStatePattern.java | ||
---|---|---|
81 | 81 |
float width = act.getScreenWidthInPixels(); |
82 | 82 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
83 | 83 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
84 |
|
|
85 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass(); |
|
86 |
int obj = play.getObject(); |
|
87 |
int size = play.getSize(); |
|
88 |
|
|
89 |
mPatternOrdinal = RubikPatternList.getOrdinal(obj,size); |
|
90 |
|
|
91 |
if( mPatternOrdinal<0 ) |
|
92 |
{ |
|
93 |
mPatternOrdinal = ObjectList.getSizeIndex(RubikStatePlay.DEF_OBJECT,RubikStatePlay.DEF_SIZE); |
|
94 |
} |
|
95 |
|
|
96 |
FragmentManager mana = act.getSupportFragmentManager(); |
|
97 |
RubikDialogPattern diag = (RubikDialogPattern) mana.findFragmentByTag(RubikDialogPattern.getDialogTag()); |
|
98 |
|
|
99 |
if( diag==null ) showDialog(mana); |
|
100 |
|
|
84 |
mPatternOrdinal = getPatternOrdinal(); |
|
101 | 85 |
LayoutInflater inflater = act.getLayoutInflater(); |
102 | 86 |
|
103 | 87 |
// TOP //////////////////////////// |
... | ... | |
177 | 161 |
public void onClick(View v) |
178 | 162 |
{ |
179 | 163 |
FragmentManager mana = act.getSupportFragmentManager(); |
180 |
RubikDialogPattern diag = (RubikDialogPattern) mana.findFragmentByTag(RubikDialogPattern.getDialogTag()); |
|
181 |
|
|
182 |
if( diag==null ) |
|
183 |
{ |
|
184 |
showDialog(mana); |
|
185 |
setTrioState(false); |
|
186 |
} |
|
187 |
else |
|
188 |
{ |
|
189 |
diag.rememberState(); |
|
190 |
diag.dismiss(); |
|
191 |
StateList.goBack(act); |
|
192 |
} |
|
164 |
StateList.goBack(act); |
|
165 |
showDialog(mana); |
|
193 | 166 |
} |
194 | 167 |
}); |
195 | 168 |
} |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
32 | 32 |
import android.widget.LinearLayout; |
33 | 33 |
import android.widget.PopupWindow; |
34 | 34 |
|
35 |
import androidx.fragment.app.FragmentManager; |
|
36 |
|
|
35 | 37 |
import org.distorted.dialogs.RubikDialogAbout; |
38 |
import org.distorted.dialogs.RubikDialogPattern; |
|
36 | 39 |
import org.distorted.dialogs.RubikDialogScores; |
37 | 40 |
import org.distorted.main.R; |
38 | 41 |
import org.distorted.main.RubikActivity; |
39 |
import org.distorted.main.RubikPreRender; |
|
40 |
import org.distorted.objects.TwistyObject; |
|
41 | 42 |
import org.distorted.objects.ObjectList; |
42 | 43 |
import org.distorted.scores.RubikScores; |
43 | 44 |
|
44 |
import java.util.ArrayList; |
|
45 |
|
|
46 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | 46 |
|
48 |
public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender.ActionFinishedListener
|
|
47 |
public class RubikStatePlay extends RubikStateBase
|
|
49 | 48 |
{ |
50 |
private static final int DURATION_MILLIS = 750; |
|
51 | 49 |
private static final int LEVELS_SHOWN = 10; |
52 | 50 |
public static final int DEF_OBJECT= ObjectList.CUBE.ordinal(); |
53 | 51 |
public static final int DEF_SIZE = 3; |
... | ... | |
55 | 53 |
private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about }; |
56 | 54 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
57 | 55 |
|
58 |
private ImageButton mObjButton, mMenuButton, mPrevButton, mSolveButton, mLockButton;
|
|
56 |
private ImageButton mObjButton, mMenuButton, mSolveButton;
|
|
59 | 57 |
private Button mPlayButton; |
60 | 58 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
61 | 59 |
private int mObject = DEF_OBJECT; |
... | ... | |
66 | 64 |
private int mColCount, mRowCount; |
67 | 65 |
private LinearLayout mPlayLayout; |
68 | 66 |
|
69 |
private ArrayList<Move> mMoves; |
|
70 |
private boolean mCanPrevMove; |
|
71 |
|
|
72 |
private static class Move |
|
73 |
{ |
|
74 |
private int mAxis, mRow, mAngle; |
|
75 |
|
|
76 |
Move(int axis, int row, int angle) |
|
77 |
{ |
|
78 |
mAxis = axis; |
|
79 |
mRow = row; |
|
80 |
mAngle= angle; |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
85 | 68 |
|
86 | 69 |
void leaveState(RubikActivity act) |
... | ... | |
93 | 76 |
void enterState(final RubikActivity act) |
94 | 77 |
{ |
95 | 78 |
float width = act.getScreenWidthInPixels(); |
79 |
|
|
96 | 80 |
mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE; |
97 | 81 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
98 | 82 |
mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE; |
99 | 83 |
|
100 |
mCanPrevMove = true; |
|
101 |
|
|
102 |
if( mMoves==null ) mMoves = new ArrayList<>(); |
|
103 |
else mMoves.clear(); |
|
104 |
|
|
105 | 84 |
mRowCount = ObjectList.getRowCount(); |
106 | 85 |
mColCount = ObjectList.getColumnCount(); |
107 | 86 |
|
... | ... | |
121 | 100 |
setupPlayButton(act,width); |
122 | 101 |
layoutTop.addView(mPlayButton); |
123 | 102 |
|
124 |
// BOT //////////////////////////// |
|
125 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
126 |
layoutBot.removeAllViews(); |
|
127 |
|
|
128 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1); |
|
129 |
|
|
130 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
131 |
layoutLeft.setLayoutParams(params); |
|
132 |
LinearLayout layoutMid = new LinearLayout(act); |
|
133 |
layoutMid.setLayoutParams(params); |
|
134 |
LinearLayout layoutRight = new LinearLayout(act); |
|
135 |
layoutRight.setLayoutParams(params); |
|
136 |
|
|
137 |
setupPrevButton(act,width); |
|
138 |
layoutLeft.addView(mPrevButton); |
|
139 |
setupLockButton(act,width); |
|
140 |
layoutMid.addView(mLockButton); |
|
141 | 103 |
setupSolveButton(act,width); |
142 |
layoutRight.addView(mSolveButton); |
|
143 |
|
|
144 |
layoutBot.addView(layoutLeft); |
|
145 |
layoutBot.addView(layoutMid); |
|
146 |
layoutBot.addView(layoutRight); |
|
104 |
createBottomPane(act,width,mSolveButton); |
|
147 | 105 |
} |
148 | 106 |
|
149 | 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
263 | 221 |
}); |
264 | 222 |
} |
265 | 223 |
|
266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
267 |
|
|
268 |
private void setupSolveButton(final RubikActivity act, final float width) |
|
269 |
{ |
|
270 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve); |
|
271 |
mSolveButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
272 |
|
|
273 |
mSolveButton.setOnClickListener( new View.OnClickListener() |
|
274 |
{ |
|
275 |
@Override |
|
276 |
public void onClick(View v) |
|
277 |
{ |
|
278 |
act.getPreRender().solveObject(); |
|
279 |
mMoves.clear(); |
|
280 |
} |
|
281 |
}); |
|
282 |
} |
|
283 |
|
|
284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
285 |
|
|
286 |
private void setupLockButton(final RubikActivity act, final float width) |
|
287 |
{ |
|
288 |
final int icon = getLockIcon(act); |
|
289 |
mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
290 |
|
|
291 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
292 |
{ |
|
293 |
@Override |
|
294 |
public void onClick(View v) |
|
295 |
{ |
|
296 |
toggleLock(act); |
|
297 |
} |
|
298 |
}); |
|
299 |
} |
|
300 |
|
|
301 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
302 |
|
|
303 |
private void setupPrevButton(final RubikActivity act, final float width) |
|
304 |
{ |
|
305 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back); |
|
306 |
mPrevButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
307 |
|
|
308 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
309 |
{ |
|
310 |
@Override |
|
311 |
public void onClick(View v) |
|
312 |
{ |
|
313 |
RubikPreRender pre = act.getPreRender(); |
|
314 |
backMove(pre); |
|
315 |
} |
|
316 |
}); |
|
317 |
} |
|
318 |
|
|
319 | 224 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
320 | 225 |
|
321 | 226 |
private void setupObjectWindow(final RubikActivity act, final float width) |
... | ... | |
463 | 368 |
adjustLevels(act); |
464 | 369 |
} |
465 | 370 |
|
466 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
467 |
|
|
468 |
private void backMove(RubikPreRender pre) |
|
469 |
{ |
|
470 |
if( mCanPrevMove ) |
|
471 |
{ |
|
472 |
int numMoves = mMoves.size(); |
|
473 |
|
|
474 |
if( numMoves>0 ) |
|
475 |
{ |
|
476 |
Move move = mMoves.remove(numMoves-1); |
|
477 |
TwistyObject object = pre.getObject(); |
|
478 |
|
|
479 |
int axis = move.mAxis; |
|
480 |
int row = (1<<move.mRow); |
|
481 |
int angle = move.mAngle; |
|
482 |
int numRot= Math.abs(angle*object.getBasicAngle()/360); |
|
483 |
|
|
484 |
if( angle!=0 ) |
|
485 |
{ |
|
486 |
mCanPrevMove = false; |
|
487 |
pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS); |
|
488 |
} |
|
489 |
else |
|
490 |
{ |
|
491 |
android.util.Log.e("solution", "error: trying to back move of angle 0"); |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
|
|
497 | 371 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
498 | 372 |
|
499 | 373 |
private void MenuAction(RubikActivity act, int button) |
... | ... | |
504 | 378 |
int object = play.getObject(); |
505 | 379 |
int size = play.getSize(); |
506 | 380 |
int sizeIndex = ObjectList.getSizeIndex(object,size); |
507 |
|
|
508 |
Bundle bundle = new Bundle(); |
|
509 |
bundle.putInt("tab", ObjectList.pack(object,sizeIndex) ); |
|
510 |
bundle.putBoolean("submitting", false); |
|
511 |
|
|
381 |
Bundle sBundle = new Bundle(); |
|
382 |
sBundle.putInt("tab", ObjectList.pack(object,sizeIndex) ); |
|
383 |
sBundle.putBoolean("submitting", false); |
|
512 | 384 |
RubikDialogScores scores = new RubikDialogScores(); |
513 |
scores.setArguments(bundle);
|
|
385 |
scores.setArguments(sBundle);
|
|
514 | 386 |
scores.show(act.getSupportFragmentManager(), null); |
515 | 387 |
break; |
516 |
case 1: StateList.switchState(act, StateList.PATT); |
|
388 |
case 1: FragmentManager mana = act.getSupportFragmentManager(); |
|
389 |
RubikDialogPattern pDiag = new RubikDialogPattern(); |
|
390 |
Bundle pBundle = new Bundle(); |
|
391 |
int ordinal = getPatternOrdinal(); |
|
392 |
pBundle.putInt("tab", ordinal ); |
|
393 |
pDiag.setArguments(pBundle); |
|
394 |
pDiag.show( mana, RubikDialogPattern.getDialogTag() ); |
|
517 | 395 |
break; |
518 | 396 |
case 2: StateList.switchState(act, StateList.SVER); |
519 | 397 |
break; |
520 |
case 3: RubikDialogAbout diag = new RubikDialogAbout();
|
|
521 |
diag.show(act.getSupportFragmentManager(), null);
|
|
398 |
case 3: RubikDialogAbout aDiag = new RubikDialogAbout();
|
|
399 |
aDiag.show(act.getSupportFragmentManager(), null);
|
|
522 | 400 |
break; |
523 | 401 |
} |
524 | 402 |
} |
525 | 403 |
|
526 | 404 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
527 | 405 |
|
528 |
private void toggleLock(RubikActivity act)
|
|
406 |
void setupSolveButton(final RubikActivity act, final float width)
|
|
529 | 407 |
{ |
530 |
act.toggleLock(); |
|
531 |
mLockButton.setImageResource(getLockIcon(act)); |
|
532 |
} |
|
533 |
|
|
534 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
408 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve); |
|
409 |
mSolveButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
535 | 410 |
|
536 |
private int getLockIcon(RubikActivity act) |
|
537 |
{ |
|
538 |
if( act.retLocked() ) |
|
539 |
{ |
|
540 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
541 |
} |
|
542 |
else |
|
411 |
mSolveButton.setOnClickListener( new View.OnClickListener() |
|
543 | 412 |
{ |
544 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
545 |
} |
|
413 |
@Override |
|
414 |
public void onClick(View v) |
|
415 |
{ |
|
416 |
act.getPreRender().solveObject(); |
|
417 |
mMoves.clear(); |
|
418 |
} |
|
419 |
}); |
|
546 | 420 |
} |
547 | 421 |
|
548 | 422 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
671 | 545 |
return mLevelValue; |
672 | 546 |
} |
673 | 547 |
|
674 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
675 |
|
|
676 |
public void addMove(int axis, int row, int angle) |
|
677 |
{ |
|
678 |
mMoves.add(new Move(axis,row,angle)); |
|
679 |
} |
|
680 |
|
|
681 | 548 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
682 | 549 |
|
683 | 550 |
public int getObject() |
... | ... | |
691 | 558 |
{ |
692 | 559 |
return mSize; |
693 | 560 |
} |
694 |
|
|
695 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
696 |
|
|
697 |
public void onActionFinished(final long effectID) |
|
698 |
{ |
|
699 |
mCanPrevMove = true; |
|
700 |
} |
|
701 | 561 |
} |
src/main/java/org/distorted/states/RubikStateReady.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 34 |
|
35 |
public class RubikStateReady extends RubikStateAbstract
|
|
35 |
public class RubikStateReady extends RubikStateBase
|
|
36 | 36 |
{ |
37 |
private ImageButton mPrevButton, mLockButton, mBackButton;
|
|
37 |
private ImageButton mBackButton; |
|
38 | 38 |
|
39 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 40 |
|
... | ... | |
48 | 48 |
void enterState(final RubikActivity act) |
49 | 49 |
{ |
50 | 50 |
float width = act.getScreenWidthInPixels(); |
51 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE;
|
|
51 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
|
52 | 52 |
|
53 | 53 |
LayoutInflater inflater = act.getLayoutInflater(); |
54 | 54 |
|
... | ... | |
60 | 60 |
label.setText(R.string.ready); |
61 | 61 |
layoutTop.addView(label); |
62 | 62 |
|
63 |
// BOT //////////////////////////// |
|
64 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
65 |
layoutBot.removeAllViews(); |
|
66 |
|
|
67 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1); |
|
68 |
|
|
69 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
70 |
layoutLeft.setLayoutParams(paramsL); |
|
71 |
LinearLayout layoutMid = new LinearLayout(act); |
|
72 |
layoutMid.setLayoutParams(paramsL); |
|
73 |
LinearLayout layoutRight = new LinearLayout(act); |
|
74 |
layoutRight.setLayoutParams(paramsL); |
|
75 |
|
|
76 |
setupPrevButtom(act,width); |
|
77 |
layoutLeft.addView(mPrevButton); |
|
78 |
setupLockButton(act,width); |
|
79 |
layoutMid.addView(mLockButton); |
|
80 | 63 |
setupBackButton(act,width); |
81 |
layoutRight.addView(mBackButton); |
|
82 |
|
|
83 |
layoutBot.addView(layoutLeft); |
|
84 |
layoutBot.addView(layoutMid); |
|
85 |
layoutBot.addView(layoutRight); |
|
64 |
createBottomPane(act,width,mBackButton); |
|
86 | 65 |
} |
87 | 66 |
|
88 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
89 | 68 |
|
90 |
private void setupBackButton(final RubikActivity act, float width) |
|
69 |
private void setupBackButton(final RubikActivity act, final float width)
|
|
91 | 70 |
{ |
92 |
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);
|
|
71 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back); |
|
93 | 72 |
mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT); |
94 | 73 |
|
95 | 74 |
mBackButton.setOnClickListener( new View.OnClickListener() |
... | ... | |
102 | 81 |
}); |
103 | 82 |
} |
104 | 83 |
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
private void setupLockButton(final RubikActivity act, final float width) |
|
108 |
{ |
|
109 |
final int icon = getLockIcon(act); |
|
110 |
mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
111 |
|
|
112 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
113 |
{ |
|
114 |
@Override |
|
115 |
public void onClick(View v) |
|
116 |
{ |
|
117 |
toggleLock(act); |
|
118 |
} |
|
119 |
}); |
|
120 |
} |
|
121 |
|
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
private void setupPrevButtom(final RubikActivity act, float width) |
|
125 |
{ |
|
126 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back); |
|
127 |
mPrevButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT); |
|
128 |
|
|
129 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
130 |
{ |
|
131 |
@Override |
|
132 |
public void onClick(View v) |
|
133 |
{ |
|
134 |
// empty |
|
135 |
} |
|
136 |
}); |
|
137 |
} |
|
138 |
|
|
139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
140 |
|
|
141 |
private void toggleLock(RubikActivity act) |
|
142 |
{ |
|
143 |
act.toggleLock(); |
|
144 |
mLockButton.setImageResource(getLockIcon(act)); |
|
145 |
} |
|
146 |
|
|
147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
148 |
|
|
149 |
private int getLockIcon(RubikActivity act) |
|
150 |
{ |
|
151 |
if( act.retLocked() ) |
|
152 |
{ |
|
153 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
154 |
} |
|
155 |
else |
|
156 |
{ |
|
157 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
162 | 85 |
|
163 | 86 |
public void savePreferences(SharedPreferences.Editor editor) |
src/main/java/org/distorted/states/RubikStateSolving.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import org.distorted.main.R; |
31 | 31 |
import org.distorted.main.RubikActivity; |
32 |
import org.distorted.main.RubikPreRender; |
|
33 |
import org.distorted.objects.TwistyObject; |
|
34 | 32 |
import org.distorted.objects.ObjectList; |
35 | 33 |
import org.distorted.scores.RubikScores; |
36 | 34 |
|
37 |
import java.util.ArrayList; |
|
38 | 35 |
import java.util.Timer; |
39 | 36 |
import java.util.TimerTask; |
40 | 37 |
|
41 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 39 |
|
43 |
public class RubikStateSolving extends RubikStateAbstract implements RubikPreRender.ActionFinishedListener
|
|
40 |
public class RubikStateSolving extends RubikStateBase
|
|
44 | 41 |
{ |
45 |
private static final int DURATION_MILLIS = 750; |
|
46 |
|
|
47 | 42 |
private TextView mTime; |
48 | 43 |
private Timer mTimer; |
49 | 44 |
private long mStartTime; |
50 | 45 |
private boolean mRunning; |
51 | 46 |
private RubikScores mScores; |
52 |
private ImageButton mPrevButton, mLockButton, mBackButton; |
|
53 |
private boolean mCanPrevMove; |
|
54 |
private ArrayList<Move> mMoves; |
|
55 | 47 |
private long mElapsed; |
56 |
|
|
57 |
private static class Move |
|
58 |
{ |
|
59 |
private int mAxis, mRow, mAngle; |
|
60 |
|
|
61 |
Move(int axis, int row, int angle) |
|
62 |
{ |
|
63 |
mAxis = axis; |
|
64 |
mRow = row; |
|
65 |
mAngle= angle; |
|
66 |
} |
|
67 |
} |
|
48 |
private ImageButton mBackButton; |
|
68 | 49 |
|
69 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
70 | 51 |
|
... | ... | |
87 | 68 |
float width = act.getScreenWidthInPixels(); |
88 | 69 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
89 | 70 |
|
90 |
mCanPrevMove = true; |
|
91 |
|
|
92 | 71 |
startCounting(act); |
93 | 72 |
|
94 |
if( mMoves==null ) mMoves = new ArrayList<>(); |
|
95 |
else mMoves.clear(); |
|
96 |
|
|
97 | 73 |
LayoutInflater inflater = act.getLayoutInflater(); |
98 | 74 |
|
99 | 75 |
// TOP //////////////////////////// |
... | ... | |
105 | 81 |
mTime.setText(act.getString(R.string.tm_placeholder,elapsed/60,elapsed%60)); |
106 | 82 |
layoutTop.addView(mTime); |
107 | 83 |
|
108 |
// BOT //////////////////////////// |
|
109 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
110 |
layoutBot.removeAllViews(); |
|
111 |
|
|
112 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1); |
|
113 |
|
|
114 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
115 |
layoutLeft.setLayoutParams(paramsL); |
|
116 |
LinearLayout layoutMid = new LinearLayout(act); |
|
117 |
layoutMid.setLayoutParams(paramsL); |
|
118 |
LinearLayout layoutRight = new LinearLayout(act); |
|
119 |
layoutRight.setLayoutParams(paramsL); |
|
120 |
|
|
121 |
setupPrevButtom(act,width); |
|
122 |
layoutLeft.addView(mPrevButton); |
|
123 |
setupLockButton(act,width); |
|
124 |
layoutMid.addView(mLockButton); |
|
125 |
setupBackButtom(act,width); |
|
126 |
layoutRight.addView(mBackButton); |
|
127 |
|
|
128 |
layoutBot.addView(layoutLeft); |
|
129 |
layoutBot.addView(layoutMid); |
|
130 |
layoutBot.addView(layoutRight); |
|
84 |
setupBackButton(act,width); |
|
85 |
createBottomPane(act,width,mBackButton); |
|
131 | 86 |
} |
132 | 87 |
|
133 |
|
|
134 | 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
135 | 89 |
|
136 |
private void setupBackButtom(final RubikActivity act, float width)
|
|
90 |
private void setupBackButton(final RubikActivity act, final float width)
|
|
137 | 91 |
{ |
138 |
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);
|
|
92 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back); |
|
139 | 93 |
mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT); |
140 | 94 |
|
141 | 95 |
mBackButton.setOnClickListener( new View.OnClickListener() |
... | ... | |
148 | 102 |
}); |
149 | 103 |
} |
150 | 104 |
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
|
|
153 |
private void setupLockButton(final RubikActivity act, final float width) |
|
154 |
{ |
|
155 |
final int icon = getLockIcon(act); |
|
156 |
mLockButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT); |
|
157 |
|
|
158 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
159 |
{ |
|
160 |
@Override |
|
161 |
public void onClick(View v) |
|
162 |
{ |
|
163 |
toggleLock(act); |
|
164 |
} |
|
165 |
}); |
|
166 |
} |
|
167 |
|
|
168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
169 |
|
|
170 |
private void setupPrevButtom(final RubikActivity act, float width) |
|
171 |
{ |
|
172 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back); |
|
173 |
mPrevButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT); |
|
174 |
|
|
175 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
176 |
{ |
|
177 |
@Override |
|
178 |
public void onClick(View v) |
|
179 |
{ |
|
180 |
RubikPreRender pre = act.getPreRender(); |
|
181 |
backMove(pre); |
|
182 |
} |
|
183 |
}); |
|
184 |
} |
|
185 |
|
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
|
|
188 |
private void backMove(RubikPreRender pre) |
|
189 |
{ |
|
190 |
if( mCanPrevMove ) |
|
191 |
{ |
|
192 |
int numMoves = mMoves.size(); |
|
193 |
|
|
194 |
if( numMoves>0 ) |
|
195 |
{ |
|
196 |
Move move = mMoves.remove(numMoves-1); |
|
197 |
TwistyObject object = pre.getObject(); |
|
198 |
|
|
199 |
int axis = move.mAxis; |
|
200 |
int row = (1<<move.mRow); |
|
201 |
int angle = move.mAngle; |
|
202 |
int numRot= Math.abs(angle*object.getBasicAngle()/360); |
|
203 |
|
|
204 |
if( angle!=0 ) |
|
205 |
{ |
|
206 |
mCanPrevMove = false; |
|
207 |
pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS); |
|
208 |
} |
|
209 |
else |
|
210 |
{ |
|
211 |
android.util.Log.e("solution", "error: trying to back move of angle 0"); |
|
212 |
} |
|
213 |
} |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
218 |
|
|
219 |
private void toggleLock(RubikActivity act) |
|
220 |
{ |
|
221 |
act.toggleLock(); |
|
222 |
mLockButton.setImageResource(getLockIcon(act)); |
|
223 |
} |
|
224 |
|
|
225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
226 |
|
|
227 |
private int getLockIcon(RubikActivity act) |
|
228 |
{ |
|
229 |
if( act.retLocked() ) |
|
230 |
{ |
|
231 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
232 |
} |
|
233 |
else |
|
234 |
{ |
|
235 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
240 |
|
|
241 |
public void addMove(int axis, int row, int angle) |
|
242 |
{ |
|
243 |
mMoves.add(new Move(axis,row,angle)); |
|
244 |
} |
|
245 |
|
|
246 | 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
247 | 106 |
|
248 | 107 |
public void savePreferences(SharedPreferences.Editor editor) |
... | ... | |
332 | 191 |
{ |
333 | 192 |
mElapsed = 0; |
334 | 193 |
} |
335 |
|
|
336 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
337 |
|
|
338 |
public void onActionFinished(final long effectID) |
|
339 |
{ |
|
340 |
mCanPrevMove = true; |
|
341 |
} |
|
342 | 194 |
} |
src/main/res/layout/main.xml | ||
---|---|---|
24 | 24 |
<LinearLayout |
25 | 25 |
android:id="@+id/upperBar" |
26 | 26 |
android:layout_below="@id/hiddenBar" |
27 |
android:layout_width="fill_parent"
|
|
27 |
android:layout_width="match_parent"
|
|
28 | 28 |
android:layout_height="0dp" |
29 | 29 |
android:gravity="center" |
30 | 30 |
android:orientation="horizontal" |
Also available in: Unified diff
Lots of changes:
1) new 'info' button (not working yet)
2) make all dialogs modal; rework the way the Pattern Dialog appears.