Revision cb30e768
Added by Leszek Koltunski about 1 year ago
src/main/AndroidManifest.xml | ||
---|---|---|
35 | 35 |
<activity android:name="org.distorted.bandaged.BandagedCreatorActivity" android:exported="false" android:screenOrientation="portrait"/> |
36 | 36 |
<activity android:name="org.distorted.bandaged.BandagedPlayActivity" android:exported="false" android:screenOrientation="portrait"/> |
37 | 37 |
<activity android:name="org.distorted.purchase.PurchaseActivity" android:exported="false" android:screenOrientation="portrait"/> |
38 |
<activity android:name="org.distorted.solverui.SolverActivity" android:exported="false" android:screenOrientation="portrait"/> |
|
38 | 39 |
|
39 | 40 |
<service |
40 | 41 |
android:name="org.distorted.messaging.RubikMessagingService" |
src/main/java/org/distorted/main/MainActivity.java | ||
---|---|---|
46 | 46 |
import org.distorted.messaging.RubikInAppMessanging; |
47 | 47 |
import org.distorted.objects.RubikObjectList; |
48 | 48 |
import org.distorted.purchase.PurchaseActivity; |
49 |
import org.distorted.solverui.SolverActivity; |
|
49 | 50 |
import org.distorted.tutorials.TutorialActivity; |
50 | 51 |
|
51 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
63 | 64 |
private FirebaseAnalytics mFirebaseAnalytics; |
64 | 65 |
private int mCurrentApiVersion; |
65 | 66 |
private String mOldVersion, mCurrVersion; |
66 |
private int mSolverIndex; |
|
67 | 67 |
private int mScreenWidth; |
68 | 68 |
private TextView mBubbleUpdates; |
69 | 69 |
private int mNumUpdates; |
... | ... | |
76 | 76 |
{ |
77 | 77 |
super.onCreate(savedState); |
78 | 78 |
setTheme(R.style.MaterialThemeNoActionBar); |
79 |
setContentView(R.layout.new_main);
|
|
79 |
setContentView(R.layout.main); |
|
80 | 80 |
hideNavigationBar(); |
81 | 81 |
|
82 | 82 |
mJustStarted = true; |
... | ... | |
86 | 86 |
computeHeights(); |
87 | 87 |
|
88 | 88 |
mCurrVersion = getAppVers(); |
89 |
mSolverIndex = 0; |
|
90 | 89 |
|
91 | 90 |
Thread thread = new Thread() |
92 | 91 |
{ |
... | ... | |
300 | 299 |
SharedPreferences.Editor editor = preferences.edit(); |
301 | 300 |
|
302 | 301 |
editor.putString("appVersion", mCurrVersion ); |
303 |
editor.putInt("solverIndex", mSolverIndex ); |
|
304 | 302 |
|
305 | 303 |
RubikObjectList.savePreferences(editor); |
306 | 304 |
RubikObjectList.saveMeshState(editor); |
... | ... | |
314 | 312 |
private void restorePreferences(SharedPreferences preferences, boolean justStarted) |
315 | 313 |
{ |
316 | 314 |
mOldVersion = preferences.getString("appVersion",""); |
317 |
mSolverIndex = preferences.getInt("solverIndex",0); |
|
318 | 315 |
|
319 | 316 |
RubikObjectList.restorePreferences(this,preferences,justStarted); |
320 | 317 |
RubikScores scores = RubikScores.getInstance(); |
... | ... | |
392 | 389 |
|
393 | 390 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
394 | 391 |
|
395 |
public void switchToPurchase(int objectOrdinal)
|
|
392 |
public void switchToSolver(int objectOrdinal)
|
|
396 | 393 |
{ |
397 |
Intent intent = new Intent(this, PurchaseActivity.class);
|
|
394 |
Intent intent = new Intent(this, SolverActivity.class);
|
|
398 | 395 |
intent.putExtra("obj", objectOrdinal); |
399 | 396 |
startActivity(intent); |
400 | 397 |
} |
401 | 398 |
|
402 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
403 |
|
|
404 |
public void setSolverIndex(int index) |
|
405 |
{ |
|
406 |
mSolverIndex = index; |
|
407 |
} |
|
408 |
|
|
409 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
410 |
|
|
411 |
public int getSolverIndex() |
|
412 |
{ |
|
413 |
return mSolverIndex; |
|
414 |
} |
|
415 |
|
|
416 | 399 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
417 | 400 |
|
418 | 401 |
public void onScores(View v) |
src/main/java/org/distorted/main/MainObjectPopup.java | ||
---|---|---|
71 | 71 |
@Override |
72 | 72 |
public void onClick(View v) |
73 | 73 |
{ |
74 |
|
|
74 |
mPopup.dismiss(); |
|
75 |
act.switchToSolver(ordinal); |
|
75 | 76 |
} |
76 | 77 |
}); |
77 | 78 |
} |
src/main/java/org/distorted/main_old/RubikActivity.java | ||
---|---|---|
112 | 112 |
super.onCreate(savedState); |
113 | 113 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
114 | 114 |
setTheme(R.style.MaterialThemeNoActionBar); |
115 |
setContentView(R.layout.main); |
|
115 |
setContentView(R.layout.old_main);
|
|
116 | 116 |
hideNavigationBar(); |
117 | 117 |
|
118 | 118 |
mJustStarted = true; |
src/main/java/org/distorted/solvers/SolverCube3.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import org.distorted.main.R; |
15 | 15 |
import org.distorted.objectlib.helpers.OperatingSystemInterface; |
16 |
import org.distorted.screens.RubikScreenSolver;
|
|
16 |
import org.distorted.solverui.ScreenSolver;
|
|
17 | 17 |
import org.distorted.objectlib.main.TwistyObject; |
18 | 18 |
import org.distorted.objectlib.kociemba.SolverSearch; |
19 | 19 |
|
... | ... | |
175 | 175 |
|
176 | 176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
177 | 177 |
|
178 |
public void solve(RubikScreenSolver solver)
|
|
178 |
public void solve(ScreenSolver solver) |
|
179 | 179 |
{ |
180 | 180 |
String result; |
181 | 181 |
|
src/main/java/org/distorted/solvers/SolverMain.java | ||
---|---|---|
16 | 16 |
import org.distorted.objectlib.main.TwistyObject; |
17 | 17 |
|
18 | 18 |
import org.distorted.main.R; |
19 |
import org.distorted.screens.ScreenList;
|
|
20 |
import org.distorted.screens.RubikScreenSolver;
|
|
19 |
import org.distorted.solverui.ScreenList;
|
|
20 |
import org.distorted.solverui.ScreenSolver;
|
|
21 | 21 |
|
22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
|
... | ... | |
72 | 72 |
|
73 | 73 |
public void run() |
74 | 74 |
{ |
75 |
RubikScreenSolver screen = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
|
|
75 |
ScreenSolver screen = (ScreenSolver) ScreenList.SVER.getScreenClass();
|
|
76 | 76 |
|
77 | 77 |
if( mSignature==ObjectConstants.CUBE_3 ) |
78 | 78 |
{ |
src/main/java/org/distorted/solvers/SolverTablebase.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import org.distorted.objectlib.helpers.OperatingSystemInterface; |
15 | 15 |
import org.distorted.objectlib.main.TwistyObject; |
16 |
import org.distorted.screens.RubikScreenSolver;
|
|
16 |
import org.distorted.solverui.ScreenSolver;
|
|
17 | 17 |
|
18 | 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
19 | 19 |
|
... | ... | |
42 | 42 |
|
43 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 44 |
|
45 |
public void solve(RubikScreenSolver screen)
|
|
45 |
public void solve(ScreenSolver screen) |
|
46 | 46 |
{ |
47 | 47 |
int index = tablebaseIndex(mObject); |
48 | 48 |
|
src/main/java/org/distorted/solverui/ScreenAbstract.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.solverui; |
|
11 |
|
|
12 |
import android.content.SharedPreferences; |
|
13 |
|
|
14 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
15 |
|
|
16 |
public abstract class ScreenAbstract |
|
17 |
{ |
|
18 |
abstract void enterScreen(SolverActivity act); |
|
19 |
abstract void leaveScreen(SolverActivity act); |
|
20 |
public abstract void savePreferences(SharedPreferences.Editor editor); |
|
21 |
public abstract void restorePreferences(SharedPreferences preferences); |
|
22 |
} |
src/main/java/org/distorted/solverui/ScreenList.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.solverui; |
|
11 |
|
|
12 |
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG; |
|
13 |
import static org.distorted.objectlib.main.ObjectControl.MODE_REPLACE; |
|
14 |
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE; |
|
15 |
|
|
16 |
import android.content.SharedPreferences; |
|
17 |
|
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
public enum ScreenList |
|
21 |
{ |
|
22 |
SVER ( null , MODE_REPLACE, new ScreenSolver() ), |
|
23 |
SOLU ( SVER , MODE_DRAG , new ScreenSolution() ), |
|
24 |
; |
|
25 |
|
|
26 |
public static final int LENGTH = values().length; |
|
27 |
private static final ScreenList[] screens; |
|
28 |
private final ScreenList mBack; |
|
29 |
private final int mMode; |
|
30 |
private final ScreenAbstract mClass; |
|
31 |
|
|
32 |
private static ScreenList mCurrScreen; |
|
33 |
|
|
34 |
static |
|
35 |
{ |
|
36 |
int i = 0; |
|
37 |
screens = new ScreenList[LENGTH]; |
|
38 |
for(ScreenList state: ScreenList.values()) screens[i++] = state; |
|
39 |
} |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public static ScreenList getScreen(int ordinal) |
|
44 |
{ |
|
45 |
return ordinal>=0 && ordinal<LENGTH ? screens[ordinal] : SVER; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
public static ScreenList getScreenFromName(String name) |
|
51 |
{ |
|
52 |
for(int i=0; i<LENGTH; i++) |
|
53 |
{ |
|
54 |
if( name.equals(screens[i].name()) ) |
|
55 |
{ |
|
56 |
return screens[i]; |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
return SVER; |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
public static ScreenList getCurrentScreen() |
|
66 |
{ |
|
67 |
return mCurrScreen; |
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
public static int getMode() |
|
73 |
{ |
|
74 |
return mCurrScreen.mMode; |
|
75 |
} |
|
76 |
|
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
public static void savePreferences(SharedPreferences.Editor editor) |
|
80 |
{ |
|
81 |
editor.putString("curr_state_name", mCurrScreen.name() ); |
|
82 |
} |
|
83 |
|
|
84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
|
86 |
public static void restorePreferences(SharedPreferences preferences) |
|
87 |
{ |
|
88 |
String currScreenName = preferences.getString("curr_state_name", ScreenList.SVER.name() ); |
|
89 |
mCurrScreen = getScreenFromName(currScreenName); |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public static void goBack(SolverActivity act) |
|
95 |
{ |
|
96 |
switchScreen(act, mCurrScreen.mBack ); |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
public static void setScreen(SolverActivity act) |
|
102 |
{ |
|
103 |
mCurrScreen.enterScreen(act); |
|
104 |
} |
|
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
public static void switchScreen(SolverActivity act, ScreenList next) |
|
109 |
{ |
|
110 |
if( next!=null ) |
|
111 |
{ |
|
112 |
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act); |
|
113 |
next.enterScreen(act); |
|
114 |
mCurrScreen = next; |
|
115 |
} |
|
116 |
else |
|
117 |
{ |
|
118 |
act.finish(); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
ScreenList(ScreenList back, int mode, ScreenAbstract clazz) |
|
125 |
{ |
|
126 |
mBack = back; |
|
127 |
mMode = mode; |
|
128 |
mClass= clazz; |
|
129 |
} |
|
130 |
|
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 |
|
|
133 |
public ScreenAbstract getScreenClass() |
|
134 |
{ |
|
135 |
return mClass; |
|
136 |
} |
|
137 |
|
|
138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
139 |
|
|
140 |
public void leaveScreen(SolverActivity act) |
|
141 |
{ |
|
142 |
mClass.leaveScreen(act); |
|
143 |
} |
|
144 |
|
|
145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 |
|
|
147 |
public void enterScreen(SolverActivity act) |
|
148 |
{ |
|
149 |
mClass.enterScreen(act); |
|
150 |
} |
|
151 |
} |
src/main/java/org/distorted/solverui/ScreenSolution.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.solverui; |
|
11 |
|
|
12 |
import android.content.SharedPreferences; |
|
13 |
import android.util.TypedValue; |
|
14 |
import android.view.Gravity; |
|
15 |
import android.view.LayoutInflater; |
|
16 |
import android.view.View; |
|
17 |
import android.widget.LinearLayout; |
|
18 |
import android.widget.TextView; |
|
19 |
|
|
20 |
import org.distorted.helpers.TransparentImageButton; |
|
21 |
import org.distorted.main.R; |
|
22 |
import org.distorted.objectlib.helpers.MovesFinished; |
|
23 |
import org.distorted.objectlib.main.ObjectControl; |
|
24 |
import org.distorted.objectlib.patterns.RubikPattern; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
public class ScreenSolution extends ScreenAbstract implements MovesFinished |
|
29 |
{ |
|
30 |
private static final int MILLIS_PER_DEGREE = 6; |
|
31 |
|
|
32 |
private TransparentImageButton mPrevButton, mNextButton, mBackButton; |
|
33 |
private TextView mMovesText; |
|
34 |
private int[][] mMoves; |
|
35 |
private int mCurrMove, mNumMoves; |
|
36 |
private boolean mCanRotate; |
|
37 |
private float mButtonSize; |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
void leaveScreen(SolverActivity act) |
|
42 |
{ |
|
43 |
ObjectControl control = act.getControl(); |
|
44 |
control.solveOnly(); |
|
45 |
} |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
void enterScreen(final SolverActivity act) |
|
50 |
{ |
|
51 |
float width = act.getScreenWidthInPixels(); |
|
52 |
mButtonSize = width*SolverActivity.BUTTON_TEXT_SIZE; |
|
53 |
float titleSize = width*SolverActivity.TITLE_TEXT_SIZE; |
|
54 |
|
|
55 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
56 |
|
|
57 |
// TOP //////////////////////////// |
|
58 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
59 |
layoutTop.removeAllViews(); |
|
60 |
|
|
61 |
final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
62 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
63 |
text.setText(R.string.solution); |
|
64 |
layoutTop.addView(text); |
|
65 |
|
|
66 |
// BOT //////////////////////////// |
|
67 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
68 |
layoutBot.removeAllViews(); |
|
69 |
|
|
70 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT); |
|
71 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT); |
|
72 |
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT); |
|
73 |
|
|
74 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
75 |
layoutLeft.setLayoutParams(paramsL); |
|
76 |
LinearLayout layoutMid = new LinearLayout(act); |
|
77 |
layoutMid.setLayoutParams(paramsM); |
|
78 |
LinearLayout layoutRight = new LinearLayout(act); |
|
79 |
layoutRight.setLayoutParams(paramsR); |
|
80 |
|
|
81 |
setupPrevButton(act); |
|
82 |
setupNextButton(act); |
|
83 |
setupTextView(act,width); |
|
84 |
|
|
85 |
layoutLeft.addView(mPrevButton); |
|
86 |
layoutLeft.addView(mMovesText); |
|
87 |
layoutLeft.addView(mNextButton); |
|
88 |
|
|
89 |
setupBackButton(act); |
|
90 |
|
|
91 |
layoutRight.addView(mBackButton); |
|
92 |
|
|
93 |
layoutBot.addView(layoutLeft); |
|
94 |
layoutBot.addView(layoutMid); |
|
95 |
layoutBot.addView(layoutRight); |
|
96 |
} |
|
97 |
|
|
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
|
100 |
private void setupPrevButton(final SolverActivity act) |
|
101 |
{ |
|
102 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
103 |
mPrevButton = new TransparentImageButton(act,R.drawable.ui_left,params); |
|
104 |
|
|
105 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
106 |
{ |
|
107 |
@Override |
|
108 |
public void onClick(View v) |
|
109 |
{ |
|
110 |
ObjectControl control = act.getControl(); |
|
111 |
backMove(control); |
|
112 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
113 |
} |
|
114 |
}); |
|
115 |
} |
|
116 |
|
|
117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
118 |
|
|
119 |
private void setupNextButton(final SolverActivity act) |
|
120 |
{ |
|
121 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
122 |
mNextButton = new TransparentImageButton(act,R.drawable.ui_right,params); |
|
123 |
|
|
124 |
mNextButton.setOnClickListener( new View.OnClickListener() |
|
125 |
{ |
|
126 |
@Override |
|
127 |
public void onClick(View v) |
|
128 |
{ |
|
129 |
ObjectControl control = act.getControl(); |
|
130 |
makeMove(control); |
|
131 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
132 |
} |
|
133 |
}); |
|
134 |
} |
|
135 |
|
|
136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
137 |
|
|
138 |
private void setupTextView(final SolverActivity act, final float width) |
|
139 |
{ |
|
140 |
int padding = (int)(width*SolverActivity.PADDING); |
|
141 |
int margin = (int)(width*SolverActivity.SMALL_MARGIN); |
|
142 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f); |
|
143 |
params.topMargin = margin; |
|
144 |
params.bottomMargin = margin; |
|
145 |
params.leftMargin = margin; |
|
146 |
params.rightMargin = margin; |
|
147 |
|
|
148 |
mMovesText = new TextView(act); |
|
149 |
mMovesText.setTextSize(20); |
|
150 |
mMovesText.setLayoutParams(params); |
|
151 |
mMovesText.setPadding(padding,0,padding,0); |
|
152 |
mMovesText.setGravity(Gravity.CENTER); |
|
153 |
mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
|
154 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
155 |
} |
|
156 |
|
|
157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
158 |
|
|
159 |
private void setupBackButton(final SolverActivity act) |
|
160 |
{ |
|
161 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
162 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params); |
|
163 |
|
|
164 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
165 |
{ |
|
166 |
@Override |
|
167 |
public void onClick(View v) |
|
168 |
{ |
|
169 |
ScreenList.goBack(act); |
|
170 |
} |
|
171 |
}); |
|
172 |
} |
|
173 |
|
|
174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
175 |
|
|
176 |
private void makeMove(ObjectControl control) |
|
177 |
{ |
|
178 |
if( mCanRotate ) |
|
179 |
{ |
|
180 |
mCurrMove++; |
|
181 |
|
|
182 |
if( mCurrMove>mNumMoves ) |
|
183 |
{ |
|
184 |
mCurrMove= 0; |
|
185 |
control.initializeObject(null); |
|
186 |
} |
|
187 |
else |
|
188 |
{ |
|
189 |
int axis = mMoves[mCurrMove-1][0]; |
|
190 |
int rowBitmap = mMoves[mCurrMove-1][1]; |
|
191 |
int bareAngle = mMoves[mCurrMove-1][2]; |
|
192 |
|
|
193 |
if( bareAngle!=0 ) |
|
194 |
{ |
|
195 |
mCanRotate = false; |
|
196 |
control.addRotation(this, axis, rowBitmap, bareAngle, MILLIS_PER_DEGREE); |
|
197 |
} |
|
198 |
else |
|
199 |
{ |
|
200 |
android.util.Log.e("solution", "error: solution contains angle 0"); |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
else |
|
205 |
{ |
|
206 |
android.util.Log.e("solution", "failed to make move!"); |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
211 |
|
|
212 |
private void backMove(ObjectControl control) |
|
213 |
{ |
|
214 |
if( mCanRotate ) |
|
215 |
{ |
|
216 |
mCurrMove--; |
|
217 |
|
|
218 |
if( mCurrMove<0 ) |
|
219 |
{ |
|
220 |
mCurrMove=mNumMoves; |
|
221 |
control.initializeObject(mMoves); |
|
222 |
} |
|
223 |
else |
|
224 |
{ |
|
225 |
int axis = mMoves[mCurrMove][0]; |
|
226 |
int rowBitmap = mMoves[mCurrMove][1]; |
|
227 |
int bareAngle = mMoves[mCurrMove][2]; |
|
228 |
|
|
229 |
if( bareAngle!=0 ) |
|
230 |
{ |
|
231 |
mCanRotate = false; |
|
232 |
control.addRotation(this, axis, rowBitmap, -bareAngle, MILLIS_PER_DEGREE); |
|
233 |
} |
|
234 |
else |
|
235 |
{ |
|
236 |
android.util.Log.e("solution", "error: solution contains angle 0"); |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
else |
|
241 |
{ |
|
242 |
android.util.Log.e("solution", "failed to back move!"); |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
247 |
|
|
248 |
void setupMoves(final SolverActivity act, String moves) |
|
249 |
{ |
|
250 |
mCanRotate= true; |
|
251 |
mCurrMove = 0; |
|
252 |
mNumMoves = moves.length()/4; |
|
253 |
mMoves = new int[mNumMoves][3]; |
|
254 |
|
|
255 |
RubikPattern.parseMoves(mMoves,mNumMoves,moves); |
|
256 |
|
|
257 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
258 |
} |
|
259 |
|
|
260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
261 |
|
|
262 |
void setupMoves(final SolverActivity act, int[][] moves) |
|
263 |
{ |
|
264 |
mCanRotate= true; |
|
265 |
mCurrMove = 0; |
|
266 |
mNumMoves = moves==null ? 0 : moves.length; |
|
267 |
mMoves = moves; |
|
268 |
|
|
269 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
270 |
} |
|
271 |
|
|
272 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
273 |
|
|
274 |
public void savePreferences(SharedPreferences.Editor editor) |
|
275 |
{ |
|
276 |
|
|
277 |
} |
|
278 |
|
|
279 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
280 |
|
|
281 |
public void restorePreferences(SharedPreferences preferences) |
|
282 |
{ |
|
283 |
|
|
284 |
} |
|
285 |
|
|
286 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
287 |
|
|
288 |
public void onActionFinished(final long effectID) |
|
289 |
{ |
|
290 |
mCanRotate = true; |
|
291 |
} |
|
292 |
} |
src/main/java/org/distorted/solverui/ScreenSolver.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.solverui; |
|
11 |
|
|
12 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_BLUE; |
|
13 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_RED; |
|
14 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_WHITE; |
|
15 |
import static org.distorted.objectlib.main.TwistyObject.COLOR_YELLOW; |
|
16 |
|
|
17 |
import android.content.SharedPreferences; |
|
18 |
import android.graphics.Bitmap; |
|
19 |
import android.graphics.Canvas; |
|
20 |
import android.graphics.Paint; |
|
21 |
import android.graphics.PorterDuff; |
|
22 |
import android.graphics.drawable.Drawable; |
|
23 |
import android.os.Bundle; |
|
24 |
import android.view.View; |
|
25 |
import android.widget.ImageButton; |
|
26 |
import android.widget.LinearLayout; |
|
27 |
|
|
28 |
import androidx.core.content.ContextCompat; |
|
29 |
|
|
30 |
import org.distorted.dialogs.RubikDialogSolverError; |
|
31 |
import org.distorted.dialogs.RubikDialogSolverImpossible; |
|
32 |
import org.distorted.helpers.TransparentImageButton; |
|
33 |
import org.distorted.main.MainActivity; |
|
34 |
import org.distorted.main.R; |
|
35 |
import org.distorted.objectlib.main.ObjectControl; |
|
36 |
import org.distorted.objectlib.main.TwistyObject; |
|
37 |
import org.distorted.objectlib.shape.ShapeDiamond; |
|
38 |
import org.distorted.objectlib.shape.ShapeDodecahedron; |
|
39 |
import org.distorted.objectlib.shape.ShapeHexahedron; |
|
40 |
import org.distorted.objectlib.shape.ShapeIcosahedron; |
|
41 |
import org.distorted.objectlib.shape.ShapeOctahedron; |
|
42 |
import org.distorted.objectlib.shape.ShapeTetrahedron; |
|
43 |
import org.distorted.objectlib.signature.ObjectConstants; |
|
44 |
import org.distorted.solvers.ImplementedSolversList; |
|
45 |
import org.distorted.solvers.SolverMain; |
|
46 |
|
|
47 |
import java.lang.ref.WeakReference; |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public class ScreenSolver extends ScreenAbstract |
|
52 |
{ |
|
53 |
private static final int RESET_DURATION = 1000; |
|
54 |
private static final int MODE_NORMAL = 0; |
|
55 |
private static final int MODE_DINO_4 = 1; |
|
56 |
|
|
57 |
private static Bitmap[] mBitmap; |
|
58 |
private ImageButton[] mColorButton; |
|
59 |
private TransparentImageButton mResetButton,mBackButton, mSolveButton; |
|
60 |
private boolean mSolving; |
|
61 |
private int mCurrentColor, mCurrentButton; |
|
62 |
private int[] mFaceColors; |
|
63 |
private int mColorMode; |
|
64 |
private int mNumColors; |
|
65 |
private float mBitmapSize; |
|
66 |
private WeakReference<SolverActivity> mWeakAct; |
|
67 |
|
|
68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 |
|
|
70 |
void leaveScreen(SolverActivity act) |
|
71 |
{ |
|
72 |
ObjectControl control = act.getControl(); |
|
73 |
control.unsetLock(); |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
void enterScreen(final SolverActivity act) |
|
79 |
{ |
|
80 |
ObjectControl control = act.getControl(); |
|
81 |
control.setLock(false); |
|
82 |
|
|
83 |
float width = act.getScreenWidthInPixels(); |
|
84 |
float heigh = act.getScreenHeightInPixels(); |
|
85 |
|
|
86 |
mWeakAct = new WeakReference<>(act); |
|
87 |
mSolving = false; |
|
88 |
|
|
89 |
int solverIndex= act.getSolverOrdinal(); |
|
90 |
ImplementedSolversList currentSolver = ImplementedSolversList.getSolver(solverIndex); |
|
91 |
int currentObject = currentSolver.getObject(); |
|
92 |
control.solveOnly(); |
|
93 |
generateFaceColors(currentObject); |
|
94 |
|
|
95 |
final float BUTTON_RATIO = 0.75f; |
|
96 |
int sizeV = (int)(heigh*MainActivity.RATIO_BAR*BUTTON_RATIO); |
|
97 |
int sizeH = (int)((width/mNumColors)*BUTTON_RATIO); |
|
98 |
mBitmapSize = Math.min(sizeV,sizeH); |
|
99 |
|
|
100 |
// TOP //////////////////////////// |
|
101 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
102 |
layoutTop.removeAllViews(); |
|
103 |
|
|
104 |
if( mNumColors>0 ) |
|
105 |
{ |
|
106 |
setupBitmaps(); |
|
107 |
setupColorButtons(act,width); |
|
108 |
markButton(act); |
|
109 |
} |
|
110 |
|
|
111 |
for(ImageButton button: mColorButton) layoutTop.addView(button); |
|
112 |
|
|
113 |
// BOT //////////////////////////// |
|
114 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1); |
|
115 |
|
|
116 |
LinearLayout layoutL = new LinearLayout(act); |
|
117 |
layoutL.setLayoutParams(params); |
|
118 |
LinearLayout layoutM = new LinearLayout(act); |
|
119 |
layoutM.setLayoutParams(params); |
|
120 |
LinearLayout layoutR = new LinearLayout(act); |
|
121 |
layoutR.setLayoutParams(params); |
|
122 |
|
|
123 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
124 |
layoutBot.removeAllViews(); |
|
125 |
|
|
126 |
setupResetButton(act); |
|
127 |
setupSolveButton(act); |
|
128 |
setupBackButton(act); |
|
129 |
|
|
130 |
layoutL.addView(mResetButton); |
|
131 |
layoutM.addView(mSolveButton); |
|
132 |
layoutR.addView(mBackButton); |
|
133 |
|
|
134 |
layoutBot.addView(layoutL); |
|
135 |
layoutBot.addView(layoutM); |
|
136 |
layoutBot.addView(layoutR); |
|
137 |
} |
|
138 |
|
|
139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
140 |
// This doesn't quite work in many cases, but in case of the solvers that will pop up in foreseeable |
|
141 |
// future it should be ok. |
|
142 |
|
|
143 |
public void generateFaceColors(int object) |
|
144 |
{ |
|
145 |
mColorMode = MODE_NORMAL; |
|
146 |
|
|
147 |
if( object== ObjectConstants.PYRA_3 || |
|
148 |
object== ObjectConstants.PYRA_4 || |
|
149 |
object== ObjectConstants.PYRA_5 || |
|
150 |
object== ObjectConstants.PDUO_2 || |
|
151 |
object== ObjectConstants.JING_2 || |
|
152 |
object== ObjectConstants.MORP_2 || |
|
153 |
object== ObjectConstants.MORP_3 || |
|
154 |
object== ObjectConstants.MORP_4 ) |
|
155 |
{ |
|
156 |
mNumColors = ShapeTetrahedron.NUM_FACES; |
|
157 |
mFaceColors = ShapeTetrahedron.FACE_COLORS; |
|
158 |
} |
|
159 |
else if( object== ObjectConstants.DIAM_2 || |
|
160 |
object== ObjectConstants.DIAM_3 || |
|
161 |
object== ObjectConstants.DIAM_4 || |
|
162 |
object== ObjectConstants.TRAJ_3 || |
|
163 |
object== ObjectConstants.TRAJ_4 || |
|
164 |
object== ObjectConstants.PDIA_3 ) |
|
165 |
{ |
|
166 |
mNumColors = ShapeOctahedron.NUM_FACES; |
|
167 |
mFaceColors = ShapeOctahedron.FACE_COLORS; |
|
168 |
} |
|
169 |
else if( object== ObjectConstants.CRYS_3 || |
|
170 |
object== ObjectConstants.STAR_3 || |
|
171 |
object== ObjectConstants.PENT_2 || |
|
172 |
object== ObjectConstants.KILO_3 || |
|
173 |
object== ObjectConstants.KILO_5 || |
|
174 |
object== ObjectConstants.MEGA_3 || |
|
175 |
object== ObjectConstants.MEGA_5 ) |
|
176 |
{ |
|
177 |
mNumColors = ShapeDodecahedron.NUM_FACES; |
|
178 |
mFaceColors = ShapeDodecahedron.FACE_COLORS; |
|
179 |
} |
|
180 |
else if( object== ObjectConstants.BALL_4 ) |
|
181 |
{ |
|
182 |
mNumColors = ShapeDiamond.NUM_FACES; |
|
183 |
mFaceColors = ShapeDiamond.FACE_COLORS; |
|
184 |
} |
|
185 |
else if( object== ObjectConstants.ICOS_2 ) |
|
186 |
{ |
|
187 |
mNumColors = ShapeIcosahedron.NUM_FACES; |
|
188 |
mFaceColors = ShapeIcosahedron.FACE_COLORS; |
|
189 |
} |
|
190 |
else if( object== ObjectConstants.DIN4_3 ) |
|
191 |
{ |
|
192 |
mNumColors = 4; |
|
193 |
mFaceColors = new int[] { COLOR_YELLOW, COLOR_RED, COLOR_BLUE, COLOR_WHITE }; |
|
194 |
mColorMode = MODE_DINO_4; |
|
195 |
} |
|
196 |
else |
|
197 |
{ |
|
198 |
mNumColors = ShapeHexahedron.NUM_FACES; |
|
199 |
mFaceColors = ShapeHexahedron.FACE_COLORS; |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
204 |
|
|
205 |
private void setupBitmaps() |
|
206 |
{ |
|
207 |
final int SIZE = (int)mBitmapSize; |
|
208 |
final float R = SIZE*0.15f; |
|
209 |
final float M = SIZE*0.08f; |
|
210 |
|
|
211 |
mBitmap = new Bitmap[mNumColors]; |
|
212 |
|
|
213 |
Paint paint = new Paint(); |
|
214 |
paint.setColor(0xff008800); |
|
215 |
paint.setStyle(Paint.Style.FILL); |
|
216 |
|
|
217 |
paint.setAntiAlias(true); |
|
218 |
paint.setTextAlign(Paint.Align.CENTER); |
|
219 |
paint.setStyle(Paint.Style.FILL); |
|
220 |
|
|
221 |
for(int i=0; i<mNumColors; i++) |
|
222 |
{ |
|
223 |
mBitmap[i] = Bitmap.createBitmap(SIZE, SIZE, Bitmap.Config.ARGB_8888); |
|
224 |
Canvas canvas = new Canvas(mBitmap[i]); |
|
225 |
|
|
226 |
paint.setColor(0xff000000); |
|
227 |
canvas.drawRect(0, 0, SIZE, SIZE, paint); |
|
228 |
|
|
229 |
paint.setColor(mFaceColors[i]); |
|
230 |
canvas.drawRoundRect( M, M, SIZE-M, SIZE-M, R, R, paint); |
|
231 |
} |
|
232 |
} |
|
233 |
|
|
234 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
235 |
|
|
236 |
private int translateColor(int color) |
|
237 |
{ |
|
238 |
if( mColorMode==MODE_DINO_4 ) |
|
239 |
{ |
|
240 |
int realColor = mFaceColors[color]; |
|
241 |
int[] hexColors = ShapeHexahedron.FACE_COLORS; |
|
242 |
|
|
243 |
for(int i=0; i<6; i++) |
|
244 |
if( hexColors[i]==realColor ) return i; |
|
245 |
} |
|
246 |
|
|
247 |
return color; |
|
248 |
} |
|
249 |
|
|
250 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
251 |
|
|
252 |
private void setupColorButtons(final SolverActivity act, final float width) |
|
253 |
{ |
|
254 |
mColorButton = new ImageButton[mNumColors]; |
|
255 |
int padding = (int)(width*SolverActivity.PADDING); |
|
256 |
int margin = (int)(width*SolverActivity.SMALL_MARGIN); |
|
257 |
|
|
258 |
for(int i=0; i<mNumColors; i++) |
|
259 |
{ |
|
260 |
final int ii = i; |
|
261 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); |
|
262 |
params.topMargin = margin; |
|
263 |
params.bottomMargin = margin; |
|
264 |
params.leftMargin = margin; |
|
265 |
params.rightMargin = margin; |
|
266 |
|
|
267 |
mColorButton[i] = new ImageButton(act); |
|
268 |
mColorButton[i].setLayoutParams(params); |
|
269 |
mColorButton[i].setPadding(padding,0,padding,0); |
|
270 |
mColorButton[i].setImageBitmap(mBitmap[i]); |
|
271 |
|
|
272 |
mColorButton[i].setOnClickListener( new View.OnClickListener() |
|
273 |
{ |
|
274 |
@Override |
|
275 |
public void onClick(View view) |
|
276 |
{ |
|
277 |
mCurrentColor = translateColor(ii); |
|
278 |
mCurrentButton= ii; |
|
279 |
markButton(act); |
|
280 |
} |
|
281 |
}); |
|
282 |
} |
|
283 |
} |
|
284 |
|
|
285 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
286 |
|
|
287 |
private void setupResetButton(final SolverActivity act) |
|
288 |
{ |
|
289 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
290 |
mResetButton = new TransparentImageButton(act, R.drawable.ui_reset, params); |
|
291 |
|
|
292 |
mResetButton.setOnClickListener( new View.OnClickListener() |
|
293 |
{ |
|
294 |
@Override |
|
295 |
public void onClick(View v) |
|
296 |
{ |
|
297 |
ObjectControl control = act.getControl(); |
|
298 |
control.resetTextureMapsEffect(RESET_DURATION); |
|
299 |
} |
|
300 |
}); |
|
301 |
} |
|
302 |
|
|
303 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
304 |
|
|
305 |
private void setupSolveButton(final SolverActivity act) |
|
306 |
{ |
|
307 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
308 |
mSolveButton = new TransparentImageButton(act,R.drawable.ui_solve,params); |
|
309 |
|
|
310 |
mSolveButton.setOnClickListener( new View.OnClickListener() |
|
311 |
{ |
|
312 |
@Override |
|
313 |
public void onClick(View v) |
|
314 |
{ |
|
315 |
if( !mSolving ) |
|
316 |
{ |
|
317 |
mSolving = true; |
|
318 |
TwistyObject object = act.getObject(); |
|
319 |
SolverMain solver = new SolverMain( act.getInterface(), act.getResources(), object ); |
|
320 |
solver.start(); |
|
321 |
} |
|
322 |
} |
|
323 |
}); |
|
324 |
} |
|
325 |
|
|
326 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
327 |
|
|
328 |
private void setupBackButton(final SolverActivity act) |
|
329 |
{ |
|
330 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
331 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params); |
|
332 |
|
|
333 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
334 |
{ |
|
335 |
@Override |
|
336 |
public void onClick(View v) |
|
337 |
{ |
|
338 |
ObjectControl control = act.getControl(); |
|
339 |
control.resetAllTextureMaps(); |
|
340 |
ScreenList.goBack(act); |
|
341 |
} |
|
342 |
}); |
|
343 |
} |
|
344 |
|
|
345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
346 |
|
|
347 |
private void markButton(SolverActivity act) |
|
348 |
{ |
|
349 |
if( mCurrentButton>=mNumColors ) |
|
350 |
{ |
|
351 |
mCurrentButton = 0; |
|
352 |
mCurrentColor = translateColor(0); |
|
353 |
} |
|
354 |
|
|
355 |
for(int b=0; b<mNumColors; b++) |
|
356 |
{ |
|
357 |
Drawable d = mColorButton[b].getBackground(); |
|
358 |
|
|
359 |
if( b==mCurrentButton ) |
|
360 |
{ |
|
361 |
d.setColorFilter(ContextCompat.getColor(act,R.color.red), PorterDuff.Mode.MULTIPLY); |
|
362 |
} |
|
363 |
else |
|
364 |
{ |
|
365 |
d.clearColorFilter(); |
|
366 |
} |
|
367 |
} |
|
368 |
} |
|
369 |
|
|
370 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
371 |
|
|
372 |
public void savePreferences(SharedPreferences.Editor editor) |
|
373 |
{ |
|
374 |
editor.putInt("stateSolver_color" , mCurrentColor ); |
|
375 |
editor.putInt("stateSolver_button", mCurrentButton); |
|
376 |
} |
|
377 |
|
|
378 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
379 |
|
|
380 |
public void restorePreferences(SharedPreferences preferences) |
|
381 |
{ |
|
382 |
mCurrentColor = preferences.getInt("stateSolver_color" , 0); |
|
383 |
mCurrentButton= preferences.getInt("stateSolver_button", 0); |
|
384 |
} |
|
385 |
|
|
386 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
387 |
|
|
388 |
public int getCurrentColor() |
|
389 |
{ |
|
390 |
return mCurrentColor; |
|
391 |
} |
|
392 |
|
|
393 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
394 |
|
|
395 |
public void setSolved(final String moves) |
|
396 |
{ |
|
397 |
mSolving = false; |
|
398 |
final SolverActivity act = mWeakAct.get(); |
|
399 |
|
|
400 |
if( act!=null ) |
|
401 |
{ |
|
402 |
act.runOnUiThread(new Runnable() |
|
403 |
{ |
|
404 |
@Override |
|
405 |
public void run() |
|
406 |
{ |
|
407 |
ScreenList.switchScreen(act, ScreenList.SOLU); |
|
408 |
ScreenSolution solution = (ScreenSolution) ScreenList.SOLU.getScreenClass(); |
|
409 |
solution.setupMoves(act, moves); |
|
410 |
} |
|
411 |
}); |
|
412 |
} |
|
413 |
} |
|
414 |
|
|
415 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
416 |
|
|
417 |
public void setSolved(final int[][] moves) |
|
418 |
{ |
|
419 |
mSolving = false; |
|
420 |
final SolverActivity act = mWeakAct.get(); |
|
421 |
|
|
422 |
if( act!=null ) |
|
423 |
{ |
|
424 |
act.runOnUiThread(new Runnable() |
|
425 |
{ |
|
426 |
@Override |
|
427 |
public void run() |
|
428 |
{ |
|
429 |
ScreenList.switchScreen(act, ScreenList.SOLU); |
|
430 |
ScreenSolution solution = (ScreenSolution) ScreenList.SOLU.getScreenClass(); |
|
431 |
solution.setupMoves(act, moves); |
|
432 |
} |
|
433 |
}); |
|
434 |
} |
|
435 |
} |
|
436 |
|
|
437 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
438 |
|
|
439 |
public void displayErrorDialog(String message) |
|
440 |
{ |
|
441 |
mSolving = false; |
|
442 |
SolverActivity act = mWeakAct.get(); |
|
443 |
|
|
444 |
if( act!=null ) |
|
445 |
{ |
|
446 |
RubikDialogSolverError dialog = new RubikDialogSolverError(); |
|
447 |
Bundle bundle = new Bundle(); |
|
448 |
bundle.putString("argument", message ); |
|
449 |
dialog.setArguments(bundle); |
|
450 |
dialog.show( act.getSupportFragmentManager(), null); |
|
451 |
} |
|
452 |
} |
|
453 |
|
|
454 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
455 |
|
|
456 |
public void displayImpossibleDialog(String message) |
|
457 |
{ |
|
458 |
mSolving = false; |
|
459 |
SolverActivity act = mWeakAct.get(); |
|
460 |
|
|
461 |
if( act!=null ) |
|
462 |
{ |
|
463 |
RubikDialogSolverImpossible dialog = new RubikDialogSolverImpossible(); |
|
464 |
Bundle bundle = new Bundle(); |
|
465 |
bundle.putString("argument", message ); |
|
466 |
dialog.setArguments(bundle); |
|
467 |
dialog.show( act.getSupportFragmentManager(), null); |
|
468 |
} |
|
469 |
} |
|
470 |
} |
src/main/java/org/distorted/solverui/SolverActivity.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.solverui; |
|
11 |
|
|
12 |
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE; |
|
13 |
|
|
14 |
import android.content.SharedPreferences; |
|
15 |
import android.os.Build; |
|
16 |
import android.os.Bundle; |
|
17 |
import android.util.DisplayMetrics; |
|
18 |
import android.view.DisplayCutout; |
|
19 |
import android.view.View; |
|
20 |
import android.view.ViewGroup; |
|
21 |
import android.view.WindowManager; |
|
22 |
import android.widget.LinearLayout; |
|
23 |
|
|
24 |
import androidx.appcompat.app.AppCompatActivity; |
|
25 |
import androidx.preference.PreferenceManager; |
|
26 |
|
|
27 |
import org.distorted.dialogs.RubikDialogError; |
|
28 |
import org.distorted.library.main.DistortedLibrary; |
|
29 |
import org.distorted.library.main.DistortedScreen; |
|
30 |
import org.distorted.main.MainActivity; |
|
31 |
import org.distorted.main.R; |
|
32 |
import org.distorted.objectlib.helpers.OperatingSystemInterface; |
|
33 |
import org.distorted.objectlib.main.InitAssets; |
|
34 |
import org.distorted.objectlib.main.ObjectControl; |
|
35 |
import org.distorted.objectlib.main.TwistyObject; |
|
36 |
import org.distorted.objects.RubikObject; |
|
37 |
import org.distorted.objects.RubikObjectList; |
|
38 |
import org.distorted.os.OSInterface; |
|
39 |
import org.distorted.solvers.ImplementedSolversList; |
|
40 |
|
|
41 |
import java.io.InputStream; |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
public class SolverActivity extends AppCompatActivity |
|
46 |
{ |
|
47 |
public static final float RATIO_BAR = 0.100f; |
|
48 |
public static final float PADDING = 0.010f; |
|
49 |
public static final float SMALL_MARGIN = 0.004f; |
|
50 |
public static final float BUTTON_TEXT_SIZE= 0.050f; |
|
51 |
public static final float TITLE_TEXT_SIZE = 0.060f; |
|
52 |
|
|
53 |
private static final int ACTIVITY_NUMBER = 0; |
|
54 |
private static final float RATIO_INSET= 0.09f; |
|
55 |
|
|
56 |
private boolean mJustStarted; |
|
57 |
private static int mScreenWidth, mScreenHeight; |
|
58 |
private int mCurrentApiVersion; |
|
59 |
private int mHeightUpperBar; |
|
60 |
private int mSolverOrdinal; |
|
61 |
private int mObjectOrdinal; |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
@Override |
|
66 |
protected void onCreate(Bundle savedState) |
|
67 |
{ |
|
68 |
super.onCreate(savedState); |
|
69 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
|
70 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
71 |
setContentView(R.layout.solver); |
|
72 |
hideNavigationBar(); |
|
73 |
|
|
74 |
mJustStarted = true; |
|
75 |
|
|
76 |
Bundle b = getIntent().getExtras(); |
|
77 |
mObjectOrdinal = b!=null ? b.getInt("obj") : 0; |
|
78 |
mSolverOrdinal = ImplementedSolversList.getSolverOrdinal(mObjectOrdinal); |
|
79 |
|
|
80 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
81 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
82 |
mScreenWidth =displaymetrics.widthPixels; |
|
83 |
mScreenHeight=displaymetrics.heightPixels; |
|
84 |
|
|
85 |
cutoutHack(); |
|
86 |
computeBarHeights(); |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
// this does not include possible insets |
|
91 |
|
|
92 |
private void computeBarHeights() |
|
93 |
{ |
|
94 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
95 |
mHeightUpperBar = barHeight; |
|
96 |
|
|
97 |
LinearLayout layoutTop = findViewById(R.id.upperBar); |
|
98 |
LinearLayout layoutBot = findViewById(R.id.lowerBar); |
|
99 |
|
|
100 |
ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams(); |
|
101 |
paramsTop.height = mHeightUpperBar; |
|
102 |
layoutTop.setLayoutParams(paramsTop); |
|
103 |
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams(); |
|
104 |
paramsBot.height = barHeight; |
|
105 |
layoutBot.setLayoutParams(paramsBot); |
|
106 |
} |
|
107 |
|
|
108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
109 |
|
|
110 |
private void hideNavigationBar() |
|
111 |
{ |
|
112 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
113 |
|
|
114 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
115 |
{ |
|
116 |
final View decorView = getWindow().getDecorView(); |
|
117 |
|
|
118 |
decorView.setSystemUiVisibility(MainActivity.FLAGS); |
|
119 |
|
|
120 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
121 |
{ |
|
122 |
@Override |
|
123 |
public void onSystemUiVisibilityChange(int visibility) |
|
124 |
{ |
|
125 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
126 |
{ |
|
127 |
decorView.setSystemUiVisibility(MainActivity.FLAGS); |
|
128 |
} |
|
129 |
} |
|
130 |
}); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
135 |
|
|
136 |
@Override |
|
137 |
public void onAttachedToWindow() |
|
138 |
{ |
|
139 |
super.onAttachedToWindow(); |
|
140 |
|
|
141 |
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ) |
|
142 |
{ |
|
143 |
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout(); |
|
144 |
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0; |
|
145 |
|
|
146 |
LinearLayout layoutHid = findViewById(R.id.hiddenBar); |
|
147 |
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams(); |
|
148 |
paramsHid.height = (int)(insetHeight*RATIO_INSET); |
|
149 |
layoutHid.setLayoutParams(paramsHid); |
|
150 |
mHeightUpperBar += paramsHid.height; |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 |
// do not avoid cutouts |
|
156 |
|
|
157 |
private void cutoutHack() |
|
158 |
{ |
|
159 |
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ) |
|
160 |
{ |
|
161 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
|
167 |
@Override |
|
168 |
public void onWindowFocusChanged(boolean hasFocus) |
|
169 |
{ |
|
170 |
super.onWindowFocusChanged(hasFocus); |
|
171 |
|
|
172 |
if( mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus ) |
|
173 |
{ |
|
174 |
getWindow().getDecorView().setSystemUiVisibility(MainActivity.FLAGS); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
179 |
|
|
180 |
@Override |
|
181 |
protected void onPause() |
|
182 |
{ |
|
183 |
super.onPause(); |
|
184 |
SolverSurfaceView view = findViewById(R.id.solverSurfaceView); |
|
185 |
view.onPause(); |
|
186 |
DistortedLibrary.onPause(ACTIVITY_NUMBER); |
|
187 |
savePreferences(); |
|
188 |
} |
|
189 |
|
|
190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 |
|
|
192 |
@Override |
|
193 |
protected void onResume() |
|
194 |
{ |
|
195 |
super.onResume(); |
|
196 |
DistortedLibrary.onResume(ACTIVITY_NUMBER); |
|
197 |
SolverSurfaceView view = findViewById(R.id.solverSurfaceView); |
|
198 |
view.onResume(); |
|
199 |
|
|
200 |
createObject(); |
|
201 |
|
|
202 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
203 |
restorePreferences(preferences,mJustStarted); |
|
204 |
ScreenList.setScreen(this); |
|
205 |
|
|
206 |
if( mJustStarted ) |
|
207 |
{ |
|
208 |
mJustStarted = false; |
|
209 |
RubikObjectList.restoreMeshState(preferences); |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
214 |
|
|
215 |
@Override |
|
216 |
protected void onDestroy() |
|
217 |
{ |
|
218 |
DistortedLibrary.onDestroy(ACTIVITY_NUMBER); |
|
219 |
super.onDestroy(); |
|
220 |
} |
|
221 |
|
|
222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
223 |
|
|
224 |
private void savePreferences() |
|
225 |
{ |
|
226 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
227 |
SharedPreferences.Editor editor = preferences.edit(); |
|
228 |
|
|
229 |
editor.putInt("solverIndex", mSolverOrdinal ); |
|
230 |
|
|
231 |
for( int i=0; i< ScreenList.LENGTH; i++ ) |
|
232 |
{ |
|
233 |
ScreenList.getScreen(i).getScreenClass().savePreferences(editor); |
|
234 |
} |
|
235 |
|
|
236 |
RubikObjectList.savePreferences(editor); |
|
237 |
RubikObjectList.saveMeshState(editor); |
|
238 |
ScreenList.savePreferences(editor); |
|
239 |
SolverSurfaceView view = findViewById(R.id.solverSurfaceView); |
|
240 |
OSInterface os = view.getInterface(); |
|
241 |
os.setEditor(editor); |
|
242 |
view.getObjectControl().savePreferences(); |
|
243 |
|
|
244 |
boolean success = editor.commit(); |
|
245 |
if( !success ) android.util.Log.e("D", "Failed to save preferences"); |
|
246 |
} |
|
247 |
|
|
248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
249 |
|
|
250 |
private void restorePreferences(SharedPreferences preferences, boolean justStarted) |
|
251 |
{ |
|
252 |
mSolverOrdinal = preferences.getInt("solverIndex",0); |
|
253 |
|
|
254 |
RubikObjectList.restorePreferences(this,preferences,justStarted); |
|
255 |
|
|
256 |
for (int i=0; i<ScreenList.LENGTH; i++) |
|
257 |
{ |
|
258 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences); |
|
259 |
} |
|
260 |
|
|
261 |
ScreenList.restorePreferences(preferences); |
|
262 |
|
|
263 |
SolverSurfaceView view = findViewById(R.id.solverSurfaceView); |
|
264 |
OSInterface os = view.getInterface(); |
|
265 |
os.setPreferences(preferences); |
|
266 |
view.getObjectControl().restorePreferences(); |
|
267 |
} |
|
268 |
|
|
269 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
270 |
|
|
271 |
void OpenGLError() |
|
272 |
{ |
|
273 |
RubikDialogError errDiag = new RubikDialogError(); |
|
274 |
errDiag.show(getSupportFragmentManager(), null); |
|
275 |
} |
|
276 |
|
|
277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
278 |
// PUBLIC API |
|
279 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
280 |
|
|
281 |
public TwistyObject getObject() |
|
282 |
{ |
|
283 |
SolverSurfaceView view = findViewById(R.id.solverSurfaceView); |
|
284 |
return view.getObjectControl().getObject(); |
|
285 |
} |
|
286 |
|
|
287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
288 |
|
|
289 |
public DistortedScreen getScreen() |
|
290 |
{ |
|
291 |
SolverSurfaceView view = findViewById(R.id.solverSurfaceView); |
|
292 |
return view.getRenderer().getScreen(); |
|
293 |
} |
|
294 |
|
|
295 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
296 |
|
|
297 |
public ObjectControl getControl() |
|
298 |
{ |
|
299 |
SolverSurfaceView view = findViewById(R.id.solverSurfaceView); |
|
300 |
return view.getObjectControl(); |
|
301 |
} |
|
302 |
|
|
303 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
304 |
|
|
305 |
public int getScreenWidthInPixels() |
|
306 |
{ |
|
307 |
return mScreenWidth; |
|
308 |
} |
|
309 |
|
|
310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
311 |
|
|
312 |
public int getScreenHeightInPixels() |
|
313 |
{ |
|
314 |
return mScreenHeight; |
|
315 |
} |
|
316 |
|
|
317 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
318 |
|
|
319 |
public int getSolverOrdinal() |
|
320 |
{ |
|
321 |
return mSolverOrdinal; |
|
322 |
} |
|
323 |
|
|
324 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
325 |
|
|
326 |
public void createObject() |
|
327 |
{ |
|
328 |
SolverSurfaceView view = findViewById(R.id.solverSurfaceView); |
|
329 |
ObjectControl control = view.getObjectControl(); |
|
330 |
RubikObject object = RubikObjectList.getObject(mObjectOrdinal); |
|
331 |
int iconMode = TwistyObject.MODE_NORM; |
|
332 |
InputStream jsonStream = object==null ? null : object.getObjectStream(this); |
|
333 |
InputStream meshStream = object==null ? null : object.getMeshStream(this); |
|
334 |
String name = object==null ? "NULL" : object.getUpperName(); |
|
335 |
OSInterface os = view.getInterface(); |
|
336 |
InitAssets asset = new InitAssets(jsonStream,meshStream,os); |
|
337 |
|
|
338 |
control.changeIfDifferent(mObjectOrdinal,name,MESH_NICE,iconMode,asset); |
|
339 |
} |
Also available in: Unified diff
Version 2.0: add Solver Activity.