Revision ca292407
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/dialogs/RubikDialogSolverError.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialogs; |
|
| 21 |
|
|
| 22 |
import android.app.Dialog; |
|
| 23 |
import android.content.DialogInterface; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.support.annotation.NonNull; |
|
| 26 |
import android.support.v4.app.FragmentActivity; |
|
| 27 |
import android.support.v7.app.AlertDialog; |
|
| 28 |
import android.support.v7.app.AppCompatDialogFragment; |
|
| 29 |
import android.view.LayoutInflater; |
|
| 30 |
import android.view.View; |
|
| 31 |
import android.view.Window; |
|
| 32 |
import android.view.WindowManager; |
|
| 33 |
import android.widget.TextView; |
|
| 34 |
|
|
| 35 |
import org.distorted.main.R; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
public class RubikDialogSolverError extends AppCompatDialogFragment |
|
| 40 |
{
|
|
| 41 |
@Override |
|
| 42 |
public void onStart() |
|
| 43 |
{
|
|
| 44 |
super.onStart(); |
|
| 45 |
|
|
| 46 |
Window window = getDialog().getWindow(); |
|
| 47 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
| 48 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
| 49 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
@NonNull |
|
| 55 |
@Override |
|
| 56 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
| 57 |
{
|
|
| 58 |
FragmentActivity act = getActivity(); |
|
| 59 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 60 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
| 61 |
|
|
| 62 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
| 63 |
tv.setText(R.string.error); |
|
| 64 |
builder.setCustomTitle(tv); |
|
| 65 |
|
|
| 66 |
builder.setCancelable(true); |
|
| 67 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
| 68 |
{
|
|
| 69 |
@Override |
|
| 70 |
public void onClick(DialogInterface dialog, int which) |
|
| 71 |
{
|
|
| 72 |
|
|
| 73 |
} |
|
| 74 |
}); |
|
| 75 |
|
|
| 76 |
Bundle args = getArguments(); |
|
| 77 |
String errorStr; |
|
| 78 |
|
|
| 79 |
try |
|
| 80 |
{
|
|
| 81 |
errorStr = args.getString("error");
|
|
| 82 |
} |
|
| 83 |
catch(Exception e) |
|
| 84 |
{
|
|
| 85 |
errorStr = "Error"; |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
final View view = inflater.inflate(R.layout.dialog_solver_error, null); |
|
| 89 |
TextView text = view.findViewById(R.id.solver_error); |
|
| 90 |
text.setText(errorStr); |
|
| 91 |
builder.setView(view); |
|
| 92 |
|
|
| 93 |
return builder.create(); |
|
| 94 |
} |
|
| 95 |
} |
|
| src/main/java/org/distorted/objects/RubikObject.java | ||
|---|---|---|
| 312 | 312 |
|
| 313 | 313 |
for(int i=0; i<numColors; i++) |
| 314 | 314 |
{
|
| 315 |
createFaceTexture(canvas,paint,i, i*TEXTURE_HEIGHT, 0, TEXTURE_HEIGHT);
|
|
| 315 |
createFaceTexture(canvas, paint, i, i*TEXTURE_HEIGHT, 0, TEXTURE_HEIGHT);
|
|
| 316 | 316 |
} |
| 317 | 317 |
|
| 318 | 318 |
mTexture.setTexture(bitmap); |
| src/main/java/org/distorted/objects/RubikObjectMovement.java | ||
|---|---|---|
| 288 | 288 |
|
| 289 | 289 |
public int getTouchedFace() |
| 290 | 290 |
{
|
| 291 |
return mLastTouchedAxis*mNumFacesPerAxis + mLastTouchedLR;
|
|
| 291 |
return mNumFacesPerAxis==2 ? 2*mLastTouchedAxis + 1 - mLastTouchedLR : mLastTouchedAxis;
|
|
| 292 | 292 |
} |
| 293 | 293 |
|
| 294 | 294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/states/RubikStateSolver.java | ||
|---|---|---|
| 26 | 26 |
import android.graphics.Paint; |
| 27 | 27 |
import android.graphics.PorterDuff; |
| 28 | 28 |
import android.graphics.drawable.Drawable; |
| 29 |
import android.os.Bundle; |
|
| 29 | 30 |
import android.support.v4.content.ContextCompat; |
| 30 | 31 |
import android.util.DisplayMetrics; |
| 31 | 32 |
import android.view.View; |
| ... | ... | |
| 33 | 34 |
import android.widget.ImageButton; |
| 34 | 35 |
import android.widget.LinearLayout; |
| 35 | 36 |
|
| 37 |
import org.distorted.dialogs.RubikDialogSolverError; |
|
| 36 | 38 |
import org.distorted.main.R; |
| 37 | 39 |
import org.distorted.main.RubikActivity; |
| 38 | 40 |
import org.distorted.main.RubikPostRender; |
| ... | ... | |
| 98 | 100 |
else |
| 99 | 101 |
result = org.distorted.solvers.cube3.Search.solution(mCubeString, 24, 20); |
| 100 | 102 |
|
| 103 |
mSolving = false; |
|
| 104 |
|
|
| 101 | 105 |
if (result.contains("Error"))
|
| 102 | 106 |
{
|
| 103 | 107 |
switch (result.charAt(result.length() - 1)) |
| ... | ... | |
| 113 | 117 |
case '9': result = res.getString(R.string.error9); break; |
| 114 | 118 |
} |
| 115 | 119 |
|
| 116 |
// TODO: pop up an error dialog. |
|
| 120 |
RubikDialogSolverError dialog = new RubikDialogSolverError(); |
|
| 121 |
Bundle bundle = new Bundle(); |
|
| 122 |
bundle.putString("error", result );
|
|
| 123 |
dialog.setArguments(bundle); |
|
| 124 |
dialog.show( mAct.getSupportFragmentManager(), null); |
|
| 117 | 125 |
} |
| 118 | 126 |
else |
| 119 | 127 |
{
|
| ... | ... | |
| 169 | 177 |
} |
| 170 | 178 |
|
| 171 | 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 180 |
// TODO |
|
| 172 | 181 |
|
| 173 | 182 |
private void setSolved( RubikActivity act, int numMoves, String moves) |
| 174 | 183 |
{
|
| 175 |
mSolving = false; |
|
| 176 |
|
|
| 177 | 184 |
RubikState.switchState(act,RubikState.SOLU); |
| 178 | 185 |
} |
| 179 | 186 |
|
| src/main/res/layout/dialog_solver_error.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:layout_width="match_parent" |
|
| 4 |
android:layout_height="match_parent" |
|
| 5 |
android:gravity="center_horizontal" |
|
| 6 |
android:orientation="vertical"> |
|
| 7 |
|
|
| 8 |
<LinearLayout |
|
| 9 |
android:layout_width="fill_parent" |
|
| 10 |
android:layout_height="fill_parent" |
|
| 11 |
android:gravity="center|fill_horizontal" |
|
| 12 |
android:layout_marginLeft="10dp" |
|
| 13 |
android:layout_marginRight="10dp" |
|
| 14 |
android:layout_marginTop="0dp" |
|
| 15 |
android:background="@color/grey" |
|
| 16 |
android:orientation="vertical"> |
|
| 17 |
|
|
| 18 |
<TextView |
|
| 19 |
android:id="@+id/solver_error" |
|
| 20 |
android:layout_width="match_parent" |
|
| 21 |
android:layout_height="match_parent" |
|
| 22 |
android:gravity="center" |
|
| 23 |
android:textSize="24sp" |
|
| 24 |
android:layout_marginTop="10dp" |
|
| 25 |
android:layout_marginLeft="10dp" |
|
| 26 |
android:layout_marginRight="10dp" |
|
| 27 |
android:layout_marginBottom="10dp"/> |
|
| 28 |
|
|
| 29 |
</LinearLayout> |
|
| 30 |
</LinearLayout> |
|
| src/main/res/values/strings.xml | ||
|---|---|---|
| 6 | 6 |
<string name="solve">Solve</string> |
| 7 | 7 |
<string name="exit">Exit</string> |
| 8 | 8 |
<string name="play">Play</string> |
| 9 |
<string name="error">Error</string> |
|
| 9 | 10 |
<string name="effects">Effects</string> |
| 10 | 11 |
<string name="scores">High Scores</string> |
| 11 | 12 |
<string name="patterns">Pretty Patterns</string> |
Also available in: Unified diff
Progress with the 3x3x3 Solver.