Revision 55e6be1d
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/effects/EffectController.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.effects; |
21 | 21 |
|
22 |
import org.distorted.helpers.MovesFinished; |
|
22 | 23 |
import org.distorted.library.message.EffectListener; |
23 | 24 |
import org.distorted.main.RubikPreRender; |
24 | 25 |
import org.distorted.objects.TwistyObject; |
... | ... | |
27 | 28 |
|
28 | 29 |
public interface EffectController extends EffectListener |
29 | 30 |
{ |
30 |
void addRotation(RubikPreRender.ActionFinishedListener listener, int axis, int rowBitmap, int angle, long duration);
|
|
31 |
void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration);
|
|
31 | 32 |
TwistyObject getOldObject(); |
32 | 33 |
TwistyObject getObject(); |
33 | 34 |
int getNumScrambles(); |
src/main/java/org/distorted/effects/scramble/ScrambleEffect.java | ||
---|---|---|
20 | 20 |
package org.distorted.effects.scramble; |
21 | 21 |
|
22 | 22 |
import org.distorted.effects.BaseEffect; |
23 |
import org.distorted.helpers.MovesFinished; |
|
23 | 24 |
import org.distorted.library.effect.Effect; |
24 | 25 |
import org.distorted.library.main.DistortedEffects; |
25 | 26 |
import org.distorted.library.main.DistortedScreen; |
... | ... | |
34 | 35 |
|
35 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
36 | 37 |
|
37 |
public abstract class ScrambleEffect extends BaseEffect implements EffectListener, RubikPreRender.ActionFinishedListener
|
|
38 |
public abstract class ScrambleEffect extends BaseEffect implements EffectListener, MovesFinished
|
|
38 | 39 |
{ |
39 | 40 |
public enum Type |
40 | 41 |
{ |
src/main/java/org/distorted/helpers/MovesAndLockController.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2021 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.helpers; |
|
21 |
|
|
22 |
import android.view.View; |
|
23 |
import android.widget.ImageButton; |
|
24 |
import android.widget.LinearLayout; |
|
25 |
|
|
26 |
import org.distorted.main.R; |
|
27 |
import org.distorted.main.RubikActivity; |
|
28 |
|
|
29 |
import java.util.ArrayList; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public class MovesAndLockController implements MovesFinished |
|
34 |
{ |
|
35 |
private static final int MILLIS_PER_DEGREE = 6; |
|
36 |
|
|
37 |
private static class Move |
|
38 |
{ |
|
39 |
private final int mAxis, mRow, mAngle; |
|
40 |
|
|
41 |
Move(int axis, int row, int angle) |
|
42 |
{ |
|
43 |
mAxis = axis; |
|
44 |
mRow = row; |
|
45 |
mAngle= angle; |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
private ArrayList<Move> mMoves; |
|
50 |
private boolean mCanPrevMove; |
|
51 |
private TwistyPreRender mPre; |
|
52 |
private ImageButton mPrevButton, mLockButton; |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
// PUBLIC API |
|
56 |
|
|
57 |
public MovesAndLockController() |
|
58 |
{ |
|
59 |
mCanPrevMove = true; |
|
60 |
|
|
61 |
if( mMoves==null ) mMoves = new ArrayList<>(); |
|
62 |
else mMoves.clear(); |
|
63 |
} |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
public void toggleLock(TwistyActivity act) |
|
68 |
{ |
|
69 |
act.toggleLock(); |
|
70 |
mLockButton.setImageResource(getLockIcon(act)); |
|
71 |
} |
|
72 |
|
|
73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 |
|
|
75 |
public int getLockIcon(TwistyActivity act) |
|
76 |
{ |
|
77 |
if( act.retLocked() ) |
|
78 |
{ |
|
79 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
80 |
} |
|
81 |
else |
|
82 |
{ |
|
83 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
public void backMove(TwistyPreRender pre) |
|
90 |
{ |
|
91 |
if( mCanPrevMove ) |
|
92 |
{ |
|
93 |
int numMoves = mMoves.size(); |
|
94 |
|
|
95 |
if( numMoves>0 ) |
|
96 |
{ |
|
97 |
Move move = mMoves.remove(numMoves-1); |
|
98 |
int axis = move.mAxis; |
|
99 |
int row = (1<<move.mRow); |
|
100 |
int angle = move.mAngle; |
|
101 |
int duration= Math.abs(angle)*MILLIS_PER_DEGREE; |
|
102 |
|
|
103 |
if( angle!=0 ) |
|
104 |
{ |
|
105 |
mCanPrevMove = false; |
|
106 |
mPre = pre; |
|
107 |
pre.blockTouch(); |
|
108 |
pre.addRotation(this, axis, row, -angle, duration); |
|
109 |
} |
|
110 |
else |
|
111 |
{ |
|
112 |
android.util.Log.e("solution", "error: trying to back move of angle 0"); |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
|
120 |
public void addMove(int axis, int row, int angle) |
|
121 |
{ |
|
122 |
mMoves.add(new Move(axis,row,angle)); |
|
123 |
} |
|
124 |
|
|
125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
126 |
|
|
127 |
public void onActionFinished(final long effectID) |
|
128 |
{ |
|
129 |
mCanPrevMove = true; |
|
130 |
mPre.unblockTouch(); |
|
131 |
} |
|
132 |
|
|
133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
134 |
|
|
135 |
public void clearMoves() |
|
136 |
{ |
|
137 |
mMoves.clear(); |
|
138 |
} |
|
139 |
|
|
140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
141 |
|
|
142 |
public void setupPrevButton(final TwistyActivity act, final float width) |
|
143 |
{ |
|
144 |
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); |
|
145 |
mPrevButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT); |
|
146 |
|
|
147 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
148 |
{ |
|
149 |
@Override |
|
150 |
public void onClick(View v) |
|
151 |
{ |
|
152 |
TwistyPreRender pre = act.getTwistyPreRender(); |
|
153 |
backMove(pre); |
|
154 |
} |
|
155 |
}); |
|
156 |
} |
|
157 |
|
|
158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
159 |
|
|
160 |
public void setupLockButton(final TwistyActivity act, final float width) |
|
161 |
{ |
|
162 |
final int icon = getLockIcon(act); |
|
163 |
mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
164 |
|
|
165 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
166 |
{ |
|
167 |
@Override |
|
168 |
public void onClick(View v) |
|
169 |
{ |
|
170 |
toggleLock(act); |
|
171 |
} |
|
172 |
}); |
|
173 |
} |
|
174 |
|
|
175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
176 |
|
|
177 |
public void setLockState(final TwistyActivity act) |
|
178 |
{ |
|
179 |
act.runOnUiThread(new Runnable() |
|
180 |
{ |
|
181 |
@Override |
|
182 |
public void run() |
|
183 |
{ |
|
184 |
if( mLockButton!=null ) |
|
185 |
mLockButton.setImageResource(getLockIcon(act)); |
|
186 |
} |
|
187 |
}); |
|
188 |
} |
|
189 |
|
|
190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 |
|
|
192 |
public ImageButton getPrevButton() |
|
193 |
{ |
|
194 |
return mPrevButton; |
|
195 |
} |
|
196 |
|
|
197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
198 |
|
|
199 |
public ImageButton getLockButton() |
|
200 |
{ |
|
201 |
return mLockButton; |
|
202 |
} |
|
203 |
} |
src/main/java/org/distorted/helpers/MovesFinished.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2021 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.helpers; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public interface MovesFinished |
|
25 |
{ |
|
26 |
void onActionFinished(long effectID); |
|
27 |
} |
src/main/java/org/distorted/helpers/TransparentButton.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.helpers; |
|
21 |
|
|
22 |
import android.annotation.SuppressLint; |
|
23 |
import android.content.Context; |
|
24 |
import android.util.TypedValue; |
|
25 |
import android.widget.LinearLayout; |
|
26 |
|
|
27 |
import org.distorted.main.RubikActivity; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
@SuppressLint("ViewConstructor") |
|
32 |
public class TransparentButton extends androidx.appcompat.widget.AppCompatButton |
|
33 |
{ |
|
34 |
public TransparentButton(Context context, int resId, float size, float scrWidth) |
|
35 |
{ |
|
36 |
super(context); |
|
37 |
|
|
38 |
final int padding = (int)(scrWidth*RubikActivity.PADDING); |
|
39 |
final int margin = (int)(scrWidth*RubikActivity.MARGIN); |
|
40 |
|
|
41 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); |
|
42 |
params.topMargin = margin; |
|
43 |
params.bottomMargin = margin; |
|
44 |
params.leftMargin = margin; |
|
45 |
params.rightMargin = margin; |
|
46 |
|
|
47 |
setLayoutParams(params); |
|
48 |
setPadding(padding,0,padding,0); |
|
49 |
setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
50 |
setText(resId); |
|
51 |
|
|
52 |
TypedValue outValue = new TypedValue(); |
|
53 |
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
54 |
setBackgroundResource(outValue.resourceId); |
|
55 |
} |
|
56 |
} |
src/main/java/org/distorted/helpers/TransparentImageButton.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.helpers; |
|
21 |
|
|
22 |
import android.annotation.SuppressLint; |
|
23 |
import android.content.Context; |
|
24 |
import android.util.TypedValue; |
|
25 |
import android.widget.LinearLayout; |
|
26 |
|
|
27 |
import org.distorted.main.RubikActivity; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
@SuppressLint("ViewConstructor") |
|
32 |
public class TransparentImageButton extends androidx.appcompat.widget.AppCompatImageButton |
|
33 |
{ |
|
34 |
public TransparentImageButton(Context context, int icon, float scrWidth, int butWidth) |
|
35 |
{ |
|
36 |
super(context); |
|
37 |
|
|
38 |
final int padding = (int)(scrWidth*RubikActivity.PADDING); |
|
39 |
final int margin = (int)(scrWidth*RubikActivity.MARGIN); |
|
40 |
|
|
41 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(butWidth,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
42 |
|
|
43 |
params.topMargin = margin; |
|
44 |
params.bottomMargin = margin; |
|
45 |
params.leftMargin = margin; |
|
46 |
params.rightMargin = margin; |
|
47 |
|
|
48 |
setLayoutParams(params); |
|
49 |
setPadding(padding,0,padding,0); |
|
50 |
setImageResource(icon); |
|
51 |
|
|
52 |
TypedValue outValue = new TypedValue(); |
|
53 |
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
54 |
setBackgroundResource(outValue.resourceId); |
|
55 |
} |
|
56 |
} |
src/main/java/org/distorted/helpers/TwistyActivity.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2021 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.helpers; |
|
21 |
|
|
22 |
import androidx.appcompat.app.AppCompatActivity; |
|
23 |
|
|
24 |
import org.distorted.screens.ScreenList; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
abstract public class TwistyActivity extends AppCompatActivity |
|
29 |
{ |
|
30 |
boolean mIsLocked, mRemLocked; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public abstract TwistyPreRender getTwistyPreRender(); |
|
35 |
|
|
36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
37 |
|
|
38 |
public boolean retLocked() |
|
39 |
{ |
|
40 |
return mIsLocked; |
|
41 |
} |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
public void toggleLock() |
|
46 |
{ |
|
47 |
mIsLocked = !mIsLocked; |
|
48 |
} |
|
49 |
|
|
50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
|
|
52 |
public void unlock() |
|
53 |
{ |
|
54 |
mIsLocked = false; |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
public boolean isLocked() |
|
60 |
{ |
|
61 |
ScreenList state = ScreenList.getCurrentScreen(); |
|
62 |
|
|
63 |
if( state== ScreenList.PLAY || state== ScreenList.READ || state== ScreenList.SOLV ) |
|
64 |
{ |
|
65 |
return mIsLocked; |
|
66 |
} |
|
67 |
|
|
68 |
return false; |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
public void setLock() |
|
74 |
{ |
|
75 |
mRemLocked = mIsLocked; |
|
76 |
mIsLocked = true; |
|
77 |
} |
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
|
|
81 |
public void unsetLock() |
|
82 |
{ |
|
83 |
mIsLocked = mRemLocked; |
|
84 |
} |
|
85 |
} |
src/main/java/org/distorted/helpers/TwistyPreRender.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2021 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.helpers; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public interface TwistyPreRender |
|
25 |
{ |
|
26 |
void blockTouch(); |
|
27 |
void unblockTouch(); |
|
28 |
void blockEverything(); |
|
29 |
void unblockEverything(); |
|
30 |
void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration); |
|
31 |
void solveObject(); |
|
32 |
} |
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
25 | 25 |
import android.os.Bundle; |
26 | 26 |
import android.os.LocaleList; |
27 | 27 |
import android.preference.PreferenceManager; |
28 |
import androidx.appcompat.app.AppCompatActivity; |
|
29 | 28 |
|
30 | 29 |
import android.util.DisplayMetrics; |
31 | 30 |
import android.view.DisplayCutout; |
... | ... | |
39 | 38 |
import org.distorted.dialogs.RubikDialogError; |
40 | 39 |
import org.distorted.dialogs.RubikDialogPrivacy; |
41 | 40 |
import org.distorted.effects.BaseEffect; |
41 |
import org.distorted.helpers.TwistyActivity; |
|
42 |
import org.distorted.helpers.TwistyPreRender; |
|
42 | 43 |
import org.distorted.library.main.DistortedLibrary; |
43 | 44 |
|
44 | 45 |
import org.distorted.library.main.DistortedScreen; |
... | ... | |
54 | 55 |
|
55 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 57 |
|
57 |
public class RubikActivity extends AppCompatActivity
|
|
58 |
public class RubikActivity extends TwistyActivity
|
|
58 | 59 |
{ |
59 | 60 |
public static final float PADDING = 0.01f; |
60 | 61 |
public static final float MARGIN = 0.004f; |
... | ... | |
88 | 89 |
private static int mScreenWidth, mScreenHeight; |
89 | 90 |
private boolean mPolicyAccepted, mIsChinese; |
90 | 91 |
private int mCurrentApiVersion; |
91 |
private boolean mIsLocked, mRemLocked; |
|
92 | 92 |
|
93 | 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
94 | 94 |
|
... | ... | |
110 | 110 |
mScreenHeight=displaymetrics.heightPixels; |
111 | 111 |
|
112 | 112 |
mIsChinese = localeIsChinese(); |
113 |
mIsLocked = false;
|
|
113 |
unlock();
|
|
114 | 114 |
|
115 | 115 |
hideNavigationBar(); |
116 | 116 |
cutoutHack(); |
... | ... | |
402 | 402 |
return view.getPreRender(); |
403 | 403 |
} |
404 | 404 |
|
405 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
406 |
|
|
407 |
public TwistyPreRender getTwistyPreRender() |
|
408 |
{ |
|
409 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
410 |
return view.getPreRender(); |
|
411 |
} |
|
412 |
|
|
405 | 413 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
406 | 414 |
|
407 | 415 |
public RubikSurfaceView getSurfaceView() |
... | ... | |
561 | 569 |
return view.isVertical(); |
562 | 570 |
} |
563 | 571 |
|
564 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
565 |
|
|
566 |
public void toggleLock() |
|
567 |
{ |
|
568 |
mIsLocked = !mIsLocked; |
|
569 |
} |
|
570 |
|
|
571 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
572 |
|
|
573 |
public boolean isLocked() |
|
574 |
{ |
|
575 |
ScreenList state = ScreenList.getCurrentScreen(); |
|
576 |
|
|
577 |
if( state== ScreenList.PLAY || state== ScreenList.READ || state== ScreenList.SOLV ) |
|
578 |
{ |
|
579 |
return mIsLocked; |
|
580 |
} |
|
581 |
|
|
582 |
return false; |
|
583 |
} |
|
584 |
|
|
585 | 572 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
586 | 573 |
|
587 | 574 |
public void blockEverything() |
588 | 575 |
{ |
589 |
mRemLocked = mIsLocked; |
|
590 |
mIsLocked = true; |
|
576 |
setLock(); |
|
591 | 577 |
|
592 |
RubikPreRender pre = getPreRender();
|
|
578 |
TwistyPreRender pre = getPreRender();
|
|
593 | 579 |
pre.blockEverything(); |
594 | 580 |
|
595 | 581 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
... | ... | |
600 | 586 |
|
601 | 587 |
public void unblockEverything() |
602 | 588 |
{ |
603 |
mIsLocked = mRemLocked;
|
|
589 |
unsetLock();
|
|
604 | 590 |
|
605 |
RubikPreRender pre = getPreRender();
|
|
591 |
TwistyPreRender pre = getPreRender();
|
|
606 | 592 |
pre.unblockEverything(); |
607 | 593 |
|
608 | 594 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
609 | 595 |
play.setLockState(this); |
610 | 596 |
} |
611 | 597 |
|
612 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
613 |
|
|
614 |
public boolean retLocked() |
|
615 |
{ |
|
616 |
return mIsLocked; |
|
617 |
} |
|
618 |
|
|
619 | 598 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
620 | 599 |
|
621 | 600 |
public void switchTutorial(String url, ObjectList object, int size) |
src/main/java/org/distorted/main/RubikPreRender.java | ||
---|---|---|
39 | 39 |
import org.distorted.effects.BaseEffect; |
40 | 40 |
import org.distorted.effects.EffectController; |
41 | 41 |
import org.distorted.effects.scramble.ScrambleEffect; |
42 |
import org.distorted.helpers.MovesFinished; |
|
43 |
import org.distorted.helpers.TwistyPreRender; |
|
42 | 44 |
import org.distorted.objects.TwistyObject; |
43 | 45 |
import org.distorted.objects.ObjectList; |
44 | 46 |
import org.distorted.network.RubikScores; |
... | ... | |
48 | 50 |
|
49 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
50 | 52 |
|
51 |
public class RubikPreRender implements EffectController |
|
53 |
public class RubikPreRender implements EffectController, TwistyPreRender
|
|
52 | 54 |
{ |
53 |
public interface ActionFinishedListener |
|
54 |
{ |
|
55 |
void onActionFinished(long effectID); |
|
56 |
} |
|
57 |
|
|
58 | 55 |
private final RubikSurfaceView mView; |
59 | 56 |
private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation, |
60 | 57 |
mSetQuat, mChangeObject, mSetupObject, mSolveObject, mScrambleObject, |
... | ... | |
74 | 71 |
private int mScrambleObjectNum; |
75 | 72 |
private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle; |
76 | 73 |
private long mAddRotationDuration; |
77 |
private ActionFinishedListener mAddActionListener;
|
|
74 |
private MovesFinished mAddActionListener;
|
|
78 | 75 |
private long mAddRotationID, mRemoveRotationID; |
79 | 76 |
private int mCubit, mFace, mNewColor; |
80 | 77 |
private int mNearestAngle; |
... | ... | |
602 | 599 |
// PUBLIC API |
603 | 600 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
604 | 601 |
|
605 |
public void addRotation(ActionFinishedListener listener, int axis, int rowBitmap, int angle, long duration)
|
|
602 |
public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration)
|
|
606 | 603 |
{ |
607 | 604 |
mAddRotation = true; |
608 | 605 |
|
src/main/java/org/distorted/patterns/RubikPattern.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.patterns; |
21 | 21 |
|
22 |
import org.distorted.helpers.MovesFinished; |
|
22 | 23 |
import org.distorted.main.RubikPreRender; |
23 | 24 |
|
24 | 25 |
import java.util.ArrayList; |
... | ... | |
192 | 193 |
|
193 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
194 | 195 |
|
195 |
private static class Pattern implements RubikPreRender.ActionFinishedListener
|
|
196 |
private static class Pattern implements MovesFinished
|
|
196 | 197 |
{ |
197 | 198 |
private final String nameStr; |
198 | 199 |
private String moveStr; |
src/main/java/org/distorted/screens/RubikScreenBase.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.screens; |
21 | 21 |
|
22 |
import android.view.View; |
|
23 | 22 |
import android.widget.ImageButton; |
24 | 23 |
import android.widget.LinearLayout; |
25 | 24 |
|
25 |
import org.distorted.helpers.MovesAndLockController; |
|
26 | 26 |
import org.distorted.main.R; |
27 | 27 |
import org.distorted.main.RubikActivity; |
28 |
import org.distorted.main.RubikPreRender; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 | 28 |
|
32 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 | 30 |
|
34 |
abstract class RubikScreenBase extends RubikScreenAbstract implements RubikPreRender.ActionFinishedListener
|
|
31 |
abstract class RubikScreenBase extends RubikScreenAbstract |
|
35 | 32 |
{ |
36 |
private static final int MILLIS_PER_DEGREE = 6; |
|
37 |
|
|
38 |
private ImageButton mPrevButton, mLockButton; |
|
39 |
private boolean mCanPrevMove; |
|
40 |
private RubikPreRender mPre; |
|
41 |
|
|
42 |
private static class Move |
|
43 |
{ |
|
44 |
private final int mAxis, mRow, mAngle; |
|
45 |
|
|
46 |
Move(int axis, int row, int angle) |
|
47 |
{ |
|
48 |
mAxis = axis; |
|
49 |
mRow = row; |
|
50 |
mAngle= angle; |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
ArrayList<Move> mMoves; |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
private void backMove(RubikPreRender pre) |
|
59 |
{ |
|
60 |
if( mCanPrevMove ) |
|
61 |
{ |
|
62 |
int numMoves = mMoves.size(); |
|
63 |
|
|
64 |
if( numMoves>0 ) |
|
65 |
{ |
|
66 |
RubikScreenBase.Move move = mMoves.remove(numMoves-1); |
|
67 |
int axis = move.mAxis; |
|
68 |
int row = (1<<move.mRow); |
|
69 |
int angle = move.mAngle; |
|
70 |
int duration= Math.abs(angle)*MILLIS_PER_DEGREE; |
|
71 |
|
|
72 |
if( angle!=0 ) |
|
73 |
{ |
|
74 |
mCanPrevMove = false; |
|
75 |
mPre = pre; |
|
76 |
pre.blockTouch(); |
|
77 |
pre.addRotation(this, axis, row, -angle, duration); |
|
78 |
} |
|
79 |
else |
|
80 |
{ |
|
81 |
android.util.Log.e("solution", "error: trying to back move of angle 0"); |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
private void toggleLock(RubikActivity act) |
|
90 |
{ |
|
91 |
act.toggleLock(); |
|
92 |
mLockButton.setImageResource(getLockIcon(act)); |
|
93 |
} |
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
|
|
97 |
private int getLockIcon(RubikActivity act) |
|
98 |
{ |
|
99 |
if( act.retLocked() ) |
|
100 |
{ |
|
101 |
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked); |
|
102 |
} |
|
103 |
else |
|
104 |
{ |
|
105 |
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked); |
|
106 |
} |
|
107 |
} |
|
33 |
MovesAndLockController mController; |
|
108 | 34 |
|
109 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
110 | 36 |
|
111 | 37 |
void createBottomPane(final RubikActivity act, float width, ImageButton button) |
112 | 38 |
{ |
113 |
mCanPrevMove = true; |
|
114 |
|
|
115 |
if( mMoves==null ) mMoves = new ArrayList<>(); |
|
116 |
else mMoves.clear(); |
|
39 |
if( mController==null ) mController = new MovesAndLockController(); |
|
117 | 40 |
|
118 | 41 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
119 | 42 |
layoutBot.removeAllViews(); |
... | ... | |
127 | 50 |
LinearLayout layoutRight = new LinearLayout(act); |
128 | 51 |
layoutRight.setLayoutParams(params); |
129 | 52 |
|
130 |
setupPrevButton(act,width); |
|
131 |
layoutLeft.addView(mPrevButton);
|
|
132 |
setupLockButton(act,width); |
|
133 |
layoutMid.addView(mLockButton);
|
|
53 |
mController.setupPrevButton(act,width);
|
|
54 |
layoutLeft.addView(mController.getPrevButton());
|
|
55 |
mController.setupLockButton(act,width);
|
|
56 |
layoutMid.addView(mController.getLockButton());
|
|
134 | 57 |
layoutRight.addView(button); |
135 | 58 |
|
136 | 59 |
layoutBot.addView(layoutLeft); |
... | ... | |
138 | 61 |
layoutBot.addView(layoutRight); |
139 | 62 |
} |
140 | 63 |
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
void setupLockButton(final RubikActivity act, final float width) |
|
144 |
{ |
|
145 |
final int icon = getLockIcon(act); |
|
146 |
mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
147 |
|
|
148 |
mLockButton.setOnClickListener( new View.OnClickListener() |
|
149 |
{ |
|
150 |
@Override |
|
151 |
public void onClick(View v) |
|
152 |
{ |
|
153 |
toggleLock(act); |
|
154 |
} |
|
155 |
}); |
|
156 |
} |
|
157 |
|
|
158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
159 |
|
|
160 |
void setupPrevButton(final RubikActivity act, final float width) |
|
161 |
{ |
|
162 |
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); |
|
163 |
mPrevButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT); |
|
164 |
|
|
165 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
166 |
{ |
|
167 |
@Override |
|
168 |
public void onClick(View v) |
|
169 |
{ |
|
170 |
RubikPreRender pre = act.getPreRender(); |
|
171 |
backMove(pre); |
|
172 |
} |
|
173 |
}); |
|
174 |
} |
|
175 |
|
|
176 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
177 | 65 |
|
178 | 66 |
public void setLockState(final RubikActivity act) |
179 | 67 |
{ |
180 |
act.runOnUiThread(new Runnable() |
|
181 |
{ |
|
182 |
@Override |
|
183 |
public void run() |
|
184 |
{ |
|
185 |
if( mLockButton!=null ) |
|
186 |
mLockButton.setImageResource(getLockIcon(act)); |
|
187 |
} |
|
188 |
}); |
|
68 |
mController.setLockState(act); |
|
189 | 69 |
} |
190 | 70 |
|
191 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
192 | 72 |
|
193 | 73 |
public void addMove(int axis, int row, int angle) |
194 | 74 |
{ |
195 |
mMoves.add(new Move(axis,row,angle)); |
|
196 |
} |
|
197 |
|
|
198 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
199 |
|
|
200 |
public void onActionFinished(final long effectID) |
|
201 |
{ |
|
202 |
mCanPrevMove = true; |
|
203 |
mPre.unblockTouch(); |
|
75 |
mController.addMove(axis,row,angle); |
|
204 | 76 |
} |
205 | 77 |
} |
src/main/java/org/distorted/screens/RubikScreenDone.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
import org.distorted.dialogs.RubikDialogNewRecord; |
33 | 33 |
import org.distorted.dialogs.RubikDialogSolved; |
34 |
import org.distorted.helpers.TransparentImageButton; |
|
34 | 35 |
import org.distorted.main.R; |
35 | 36 |
import org.distorted.main.RubikActivity; |
36 | 37 |
|
src/main/java/org/distorted/screens/RubikScreenPattern.java | ||
---|---|---|
31 | 31 |
import android.widget.TextView; |
32 | 32 |
|
33 | 33 |
import org.distorted.dialogs.RubikDialogPattern; |
34 |
import org.distorted.helpers.TransparentImageButton; |
|
34 | 35 |
import org.distorted.main.R; |
35 | 36 |
import org.distorted.main.RubikActivity; |
36 | 37 |
import org.distorted.main.RubikPreRender; |
src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
---|---|---|
37 | 37 |
import org.distorted.dialogs.RubikDialogPattern; |
38 | 38 |
import org.distorted.dialogs.RubikDialogScores; |
39 | 39 |
import org.distorted.dialogs.RubikDialogTutorial; |
40 |
import org.distorted.helpers.TransparentButton; |
|
41 |
import org.distorted.helpers.TransparentImageButton; |
|
40 | 42 |
import org.distorted.main.R; |
41 | 43 |
import org.distorted.main.RubikActivity; |
42 | 44 |
import org.distorted.main.RubikPreRender; |
... | ... | |
291 | 293 |
mSize = sizes[index]; |
292 | 294 |
act.changeObject(list,sizes[index], true); |
293 | 295 |
adjustLevels(act); |
294 |
mMoves.clear();
|
|
296 |
mController.clearMoves();
|
|
295 | 297 |
} |
296 | 298 |
|
297 | 299 |
mObjectPopup.dismiss(); |
... | ... | |
426 | 428 |
public void onClick(View v) |
427 | 429 |
{ |
428 | 430 |
act.getPreRender().solveObject(); |
429 |
mMoves.clear();
|
|
431 |
mController.clearMoves();
|
|
430 | 432 |
} |
431 | 433 |
}); |
432 | 434 |
} |
src/main/java/org/distorted/screens/RubikScreenReady.java | ||
---|---|---|
27 | 27 |
import android.widget.LinearLayout; |
28 | 28 |
import android.widget.TextView; |
29 | 29 |
|
30 |
import org.distorted.helpers.TransparentImageButton; |
|
30 | 31 |
import org.distorted.main.R; |
31 | 32 |
import org.distorted.main.RubikActivity; |
32 | 33 |
|
src/main/java/org/distorted/screens/RubikScreenSolution.java | ||
---|---|---|
28 | 28 |
import android.widget.LinearLayout; |
29 | 29 |
import android.widget.TextView; |
30 | 30 |
|
31 |
import org.distorted.helpers.MovesFinished; |
|
32 |
import org.distorted.helpers.TransparentImageButton; |
|
31 | 33 |
import org.distorted.main.R; |
32 | 34 |
import org.distorted.main.RubikActivity; |
33 | 35 |
import org.distorted.main.RubikPreRender; |
... | ... | |
36 | 38 |
|
37 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 40 |
|
39 |
public class RubikScreenSolution extends RubikScreenAbstract implements RubikPreRender.ActionFinishedListener
|
|
41 |
public class RubikScreenSolution extends RubikScreenAbstract implements MovesFinished
|
|
40 | 42 |
{ |
41 | 43 |
private static final int MILLIS_PER_DEGREE = 6; |
42 | 44 |
|
src/main/java/org/distorted/screens/RubikScreenSolver.java | ||
---|---|---|
32 | 32 |
import android.widget.LinearLayout; |
33 | 33 |
|
34 | 34 |
import org.distorted.dialogs.RubikDialogSolverError; |
35 |
import org.distorted.helpers.TransparentImageButton; |
|
35 | 36 |
import org.distorted.main.R; |
36 | 37 |
import org.distorted.main.RubikActivity; |
37 | 38 |
import org.distorted.main.RubikPreRender; |
src/main/java/org/distorted/screens/RubikScreenSolving.java | ||
---|---|---|
27 | 27 |
import android.widget.LinearLayout; |
28 | 28 |
import android.widget.TextView; |
29 | 29 |
|
30 |
import org.distorted.helpers.TransparentImageButton; |
|
30 | 31 |
import org.distorted.main.R; |
31 | 32 |
import org.distorted.main.RubikActivity; |
32 | 33 |
import org.distorted.objects.ObjectList; |
src/main/java/org/distorted/screens/TransparentButton.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.screens; |
|
21 |
|
|
22 |
import android.annotation.SuppressLint; |
|
23 |
import android.content.Context; |
|
24 |
import android.util.TypedValue; |
|
25 |
import android.widget.LinearLayout; |
|
26 |
|
|
27 |
import org.distorted.main.RubikActivity; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
@SuppressLint("ViewConstructor") |
|
32 |
public class TransparentButton extends androidx.appcompat.widget.AppCompatButton |
|
33 |
{ |
|
34 |
public TransparentButton(Context context, int resId, float size, float scrWidth) |
|
35 |
{ |
|
36 |
super(context); |
|
37 |
|
|
38 |
final int padding = (int)(scrWidth*RubikActivity.PADDING); |
|
39 |
final int margin = (int)(scrWidth*RubikActivity.MARGIN); |
|
40 |
|
|
41 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); |
|
42 |
params.topMargin = margin; |
|
43 |
params.bottomMargin = margin; |
|
44 |
params.leftMargin = margin; |
|
45 |
params.rightMargin = margin; |
|
46 |
|
|
47 |
setLayoutParams(params); |
|
48 |
setPadding(padding,0,padding,0); |
|
49 |
setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
50 |
setText(resId); |
|
51 |
|
|
52 |
TypedValue outValue = new TypedValue(); |
|
53 |
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
54 |
setBackgroundResource(outValue.resourceId); |
|
55 |
} |
|
56 |
} |
src/main/java/org/distorted/screens/TransparentImageButton.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.screens; |
|
21 |
|
|
22 |
import android.annotation.SuppressLint; |
|
23 |
import android.content.Context; |
|
24 |
import android.util.TypedValue; |
|
25 |
import android.widget.LinearLayout; |
|
26 |
|
|
27 |
import org.distorted.main.RubikActivity; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
@SuppressLint("ViewConstructor") |
|
32 |
public class TransparentImageButton extends androidx.appcompat.widget.AppCompatImageButton |
|
33 |
{ |
|
34 |
public TransparentImageButton(Context context, int icon, float scrWidth, int butWidth) |
|
35 |
{ |
|
36 |
super(context); |
|
37 |
|
|
38 |
final int padding = (int)(scrWidth*RubikActivity.PADDING); |
|
39 |
final int margin = (int)(scrWidth*RubikActivity.MARGIN); |
|
40 |
|
|
41 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(butWidth,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
42 |
|
|
43 |
params.topMargin = margin; |
|
44 |
params.bottomMargin = margin; |
|
45 |
params.leftMargin = margin; |
|
46 |
params.rightMargin = margin; |
|
47 |
|
|
48 |
setLayoutParams(params); |
|
49 |
setPadding(padding,0,padding,0); |
|
50 |
setImageResource(icon); |
|
51 |
|
|
52 |
TypedValue outValue = new TypedValue(); |
|
53 |
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
54 |
setBackgroundResource(outValue.resourceId); |
|
55 |
} |
|
56 |
} |
src/main/java/org/distorted/tutorials/TutorialActivity.java | ||
---|---|---|
28 | 28 |
import android.webkit.WebView; |
29 | 29 |
import android.widget.LinearLayout; |
30 | 30 |
|
31 |
import androidx.appcompat.app.AppCompatActivity; |
|
32 |
|
|
33 | 31 |
import com.google.firebase.analytics.FirebaseAnalytics; |
34 | 32 |
|
35 | 33 |
import org.distorted.dialogs.RubikDialogError; |
34 |
import org.distorted.helpers.TwistyActivity; |
|
35 |
import org.distorted.helpers.TwistyPreRender; |
|
36 | 36 |
import org.distorted.library.main.DistortedLibrary; |
37 | 37 |
import org.distorted.main.R; |
38 | 38 |
import org.distorted.objects.ObjectList; |
39 | 39 |
import org.distorted.objects.TwistyObject; |
40 |
import org.distorted.screens.ScreenList; |
|
41 | 40 |
|
42 | 41 |
import static org.distorted.main.RubikRenderer.BRIGHTNESS; |
43 | 42 |
|
44 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 | 44 |
|
46 |
public class TutorialActivity extends AppCompatActivity
|
|
45 |
public class TutorialActivity extends TwistyActivity
|
|
47 | 46 |
{ |
48 | 47 |
private static final String URL = "https://www.youtube.com/embed/"; |
49 | 48 |
|
... | ... | |
56 | 55 |
| View.SYSTEM_UI_FLAG_FULLSCREEN |
57 | 56 |
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
58 | 57 |
|
59 |
public static final int FLAGS2= View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
60 |
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
|
61 |
|
|
62 |
private boolean mIsLocked; |
|
63 | 58 |
private FirebaseAnalytics mFirebaseAnalytics; |
64 | 59 |
private static int mScreenWidth, mScreenHeight; |
65 | 60 |
private int mCurrentApiVersion; |
... | ... | |
87 | 82 |
mObjectSize = b.getInt("siz"); |
88 | 83 |
} |
89 | 84 |
|
90 |
mIsLocked = false;
|
|
85 |
unlock();
|
|
91 | 86 |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); |
92 | 87 |
|
93 | 88 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
... | ... | |
153 | 148 |
mState.createRightPane(this,width); |
154 | 149 |
|
155 | 150 |
WebView videoView = findViewById(R.id.tutorialVideoView); |
156 |
mWebView = new TutorialWebView(this,videoView);
|
|
151 |
mWebView = new TutorialWebView(videoView); |
|
157 | 152 |
mWebView.load(URL+mURL); |
158 | 153 |
} |
159 | 154 |
|
... | ... | |
285 | 280 |
return view.getPreRender(); |
286 | 281 |
} |
287 | 282 |
|
283 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
284 |
|
|
285 |
public TwistyPreRender getTwistyPreRender() |
|
286 |
{ |
|
287 |
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView); |
|
288 |
return view.getPreRender(); |
|
289 |
} |
|
290 |
|
|
288 | 291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
289 | 292 |
|
290 | 293 |
public static int getDrawableSize() |
... | ... | |
327 | 330 |
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView); |
328 | 331 |
return view.isVertical(); |
329 | 332 |
} |
330 |
|
|
331 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
332 |
|
|
333 |
public void toggleLock() |
|
334 |
{ |
|
335 |
mIsLocked = !mIsLocked; |
|
336 |
} |
|
337 |
|
|
338 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
339 |
|
|
340 |
public boolean isLocked() |
|
341 |
{ |
|
342 |
ScreenList state = ScreenList.getCurrentScreen(); |
|
343 |
|
|
344 |
if( state== ScreenList.PLAY || state== ScreenList.READ || state== ScreenList.SOLV ) |
|
345 |
{ |
|
346 |
return mIsLocked; |
|
347 |
} |
|
348 |
|
|
349 |
return false; |
|
350 |
} |
|
351 |
|
|
352 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
353 |
|
|
354 |
public boolean retLocked() |
|
355 |
{ |
|
356 |
return mIsLocked; |
|
357 |
} |
|
358 | 333 |
} |
src/main/java/org/distorted/tutorials/TutorialPreRender.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import org.distorted.effects.BaseEffect; |
26 | 26 |
import org.distorted.effects.EffectController; |
27 |
import org.distorted.helpers.MovesFinished; |
|
28 |
import org.distorted.helpers.TwistyPreRender; |
|
27 | 29 |
import org.distorted.objects.ObjectList; |
28 | 30 |
import org.distorted.objects.TwistyObject; |
29 |
import org.distorted.main.RubikPreRender.ActionFinishedListener; |
|
30 |
import org.distorted.network.RubikScores; |
|
31 | 31 |
|
32 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 | 33 |
|
34 |
public class TutorialPreRender implements EffectController |
|
34 |
public class TutorialPreRender implements EffectController, TwistyPreRender
|
|
35 | 35 |
{ |
36 |
private ActionFinishedListener mAddActionListener;
|
|
36 |
private MovesFinished mAddActionListener;
|
|
37 | 37 |
private final TutorialSurfaceView mView; |
38 | 38 |
private boolean mFinishRotation, mRemoveRotation, mAddRotation, |
39 | 39 |
mSetQuat, mChangeObject, mSetupObject, mSolveObject, mScrambleObject, |
40 | 40 |
mInitializeObject, mResetAllTextureMaps, mRemovePatternRotation; |
41 |
private boolean mCanPlay, mCanRotate;
|
|
41 |
private boolean mUIBlocked, mTouchBlocked;
|
|
42 | 42 |
private boolean mIsSolved; |
43 | 43 |
private ObjectList mNextObject; |
44 | 44 |
private int mNextSize; |
45 | 45 |
private long mRotationFinishedID; |
46 | 46 |
private int mScreenWidth; |
47 |
private int[][] mNextMoves; |
|
48 | 47 |
private TwistyObject mOldObject, mNewObject; |
49 | 48 |
private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle; |
50 | 49 |
private long mAddRotationDuration; |
... | ... | |
67 | 66 |
mSolveObject = false; |
68 | 67 |
mScrambleObject = false; |
69 | 68 |
|
70 |
mCanRotate = true;
|
|
71 |
mCanPlay = true; |
|
69 |
unblockEverything();
|
|
70 |
|
|
72 | 71 |
mOldObject = null; |
73 | 72 |
mNewObject = null; |
74 | 73 |
|
... | ... | |
80 | 79 |
|
81 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
82 | 81 |
|
83 |
private void createObjectNow(ObjectList object, int size, int[][] moves)
|
|
82 |
private void createObjectNow(ObjectList object, int size) |
|
84 | 83 |
{ |
85 | 84 |
if( mOldObject!=null ) mOldObject.releaseResources(); |
86 | 85 |
mOldObject = mNewObject; |
... | ... | |
88 | 87 |
Context con = mView.getContext(); |
89 | 88 |
Resources res = con.getResources(); |
90 | 89 |
|
91 |
mNewObject = object.create(size, mView.getQuat(), moves, res, mScreenWidth);
|
|
90 |
mNewObject = object.create(size, mView.getQuat(), null, res, mScreenWidth);
|
|
92 | 91 |
|
93 | 92 |
if( mNewObject!=null ) |
94 | 93 |
{ |
... | ... | |
114 | 113 |
} |
115 | 114 |
catch( Exception ex ) |
116 | 115 |
{ |
117 |
mCanPlay = true;
|
|
118 |
mCanRotate= true;
|
|
116 |
android.util.Log.e("renderer", "exception starting effect: "+ex.getMessage());
|
|
117 |
unblockEverything();
|
|
119 | 118 |
} |
120 | 119 |
} |
121 | 120 |
|
... | ... | |
143 | 142 |
mNewObject.removeRotationNow(); |
144 | 143 |
|
145 | 144 |
boolean solved = mNewObject.isSolved(); |
146 |
|
|
147 |
if( solved && !mIsSolved ) |
|
148 |
{ |
|
149 |
doEffectNow( BaseEffect.Type.WIN ); |
|
150 |
} |
|
151 |
else |
|
152 |
{ |
|
153 |
mCanPlay = true; |
|
154 |
} |
|
145 |
unblockEverything(); |
|
146 |
if( solved && !mIsSolved ) doEffectNow( BaseEffect.Type.WIN ); |
|
155 | 147 |
|
156 | 148 |
mIsSolved = solved; |
157 | 149 |
} |
... | ... | |
173 | 165 |
|
174 | 166 |
if( mAddRotationID==0 ) // failed to add effect - should never happen |
175 | 167 |
{ |
176 |
mCanPlay = true; |
|
177 |
mCanRotate= true; |
|
168 |
unblockEverything(); |
|
178 | 169 |
} |
179 | 170 |
} |
180 | 171 |
|
... | ... | |
183 | 174 |
private void finishRotationNow() |
184 | 175 |
{ |
185 | 176 |
mFinishRotation = false; |
186 |
mCanPlay = false;
|
|
177 |
blockEverything();
|
|
187 | 178 |
mRotationFinishedID = mNewObject.finishRotationNow(this, mNearestAngle); |
188 | 179 |
|
189 | 180 |
if( mRotationFinishedID==0 ) // failed to add effect - should never happen |
190 | 181 |
{ |
191 |
mCanPlay = true;
|
|
182 |
unblockEverything();
|
|
192 | 183 |
} |
193 | 184 |
} |
194 | 185 |
|
... | ... | |
200 | 191 |
|
201 | 192 |
if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getNumLayers()!=mNextSize) |
202 | 193 |
{ |
203 |
mCanPlay = false;
|
|
204 |
createObjectNow(mNextObject, mNextSize, null);
|
|
194 |
blockEverything();
|
|
195 |
createObjectNow(mNextObject, mNextSize); |
|
205 | 196 |
doEffectNow( BaseEffect.Type.SIZECHANGE ); |
206 | 197 |
} |
207 | 198 |
} |
... | ... | |
214 | 205 |
|
215 | 206 |
if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getNumLayers()!=mNextSize) |
216 | 207 |
{ |
217 |
mCanPlay = false;
|
|
218 |
createObjectNow(mNextObject, mNextSize, mNextMoves);
|
|
208 |
blockEverything();
|
|
209 |
createObjectNow(mNextObject, mNextSize); |
|
219 | 210 |
doEffectNow( BaseEffect.Type.SIZECHANGE ); |
220 | 211 |
} |
221 | 212 |
else |
222 | 213 |
{ |
223 |
mNewObject.initializeObject(mNextMoves);
|
|
214 |
mNewObject.initializeObject(null);
|
|
224 | 215 |
} |
225 | 216 |
} |
226 | 217 |
|
227 | 218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
228 | 219 |
|
229 |
private void solveObjectNow()
|
|
220 |
private void scrambleObjectNow()
|
|
230 | 221 |
{ |
231 |
mSolveObject = false; |
|
232 |
mCanPlay = false; |
|
233 |
doEffectNow( BaseEffect.Type.SOLVE ); |
|
222 |
mScrambleObject = false; |
|
223 |
mIsSolved = false; |
|
224 |
blockEverything(); |
|
225 |
doEffectNow( BaseEffect.Type.SCRAMBLE ); |
|
234 | 226 |
} |
235 | 227 |
|
236 | 228 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
237 | 229 |
|
238 |
private void scrambleObjectNow()
|
|
230 |
private void solveObjectNow()
|
|
239 | 231 |
{ |
240 |
mScrambleObject = false; |
|
241 |
mCanPlay = false; |
|
242 |
mCanRotate = false; |
|
243 |
mIsSolved = false; |
|
244 |
|
|
245 |
doEffectNow( BaseEffect.Type.SCRAMBLE ); |
|
232 |
mSolveObject = false; |
|
233 |
blockEverything(); |
|
234 |
doEffectNow( BaseEffect.Type.SOLVE ); |
|
246 | 235 |
} |
247 | 236 |
|
248 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
250 | 239 |
private void initializeObjectNow() |
251 | 240 |
{ |
252 | 241 |
mInitializeObject = false; |
253 |
mNewObject.initializeObject(mNextMoves);
|
|
242 |
mNewObject.initializeObject(null);
|
|
254 | 243 |
} |
255 | 244 |
|
256 | 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
333 | 322 |
// PUBLIC API |
334 | 323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
335 | 324 |
|
336 |
public void addRotation(ActionFinishedListener listener, int axis, int rowBitmap, int angle, long duration) |
|
325 |
boolean isTouchBlocked() |
|
326 |
{ |
|
327 |
return mTouchBlocked; |
|
328 |
} |
|
329 |
|
|
330 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
331 |
|
|
332 |
public boolean isUINotBlocked() |
|
333 |
{ |
|
334 |
return !mUIBlocked; |
|
335 |
} |
|
336 |
|
|
337 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
338 |
|
|
339 |
public void blockEverything() |
|
340 |
{ |
|
341 |
mUIBlocked = true; |
|
342 |
mTouchBlocked= true; |
|
343 |
} |
|
344 |
|
|
345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
346 |
|
|
347 |
public void blockTouch() |
|
348 |
{ |
|
349 |
mTouchBlocked= true; |
|
350 |
} |
|
351 |
|
|
352 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
353 |
|
|
354 |
public void unblockEverything() |
|
355 |
{ |
|
356 |
mUIBlocked = false; |
Also available in: Unified diff
Abstract the part that controls the 'Locked' and 'Back Moves' buttons from the two activities: the main one and the tutorial one.
This code had been duplicated there.