| 1 |
7289fd6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
| 3 |
|
|
// //
|
| 4 |
|
|
// This file is part of Magic Cube. //
|
| 5 |
|
|
// //
|
| 6 |
3782bd44
|
Leszek Koltunski
|
// 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 |
7289fd6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 9 |
|
|
|
| 10 |
fcd5b990
|
Leszek Koltunski
|
package org.distorted.screens;
|
| 11 |
7289fd6c
|
Leszek Koltunski
|
|
| 12 |
8145d8b8
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.*;
|
| 13 |
|
|
|
| 14 |
3f7a4363
|
Leszek Koltunski
|
import java.lang.ref.WeakReference;
|
| 15 |
|
|
|
| 16 |
7289fd6c
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
| 17 |
|
|
import android.graphics.Bitmap;
|
| 18 |
|
|
import android.graphics.Canvas;
|
| 19 |
|
|
import android.graphics.Paint;
|
| 20 |
473611ee
|
Leszek Koltunski
|
import android.graphics.PorterDuff;
|
| 21 |
|
|
import android.graphics.drawable.Drawable;
|
| 22 |
ca292407
|
Leszek Koltunski
|
import android.os.Bundle;
|
| 23 |
66e777b0
|
Leszek Koltunski
|
import androidx.core.content.ContextCompat;
|
| 24 |
7289fd6c
|
Leszek Koltunski
|
import android.view.View;
|
| 25 |
|
|
import android.widget.ImageButton;
|
| 26 |
|
|
import android.widget.LinearLayout;
|
| 27 |
|
|
|
| 28 |
2afc6754
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectControl;
|
| 29 |
de697069
|
leszek
|
import org.distorted.objectlib.signature.ObjectConstants;
|
| 30 |
3f7a4363
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyObject;
|
| 31 |
|
|
|
| 32 |
ca292407
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogSolverError;
|
| 33 |
55e6be1d
|
Leszek Koltunski
|
import org.distorted.helpers.TransparentImageButton;
|
| 34 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
| 35 |
|
|
import org.distorted.main.RubikActivity;
|
| 36 |
d8cf6f49
|
Leszek Koltunski
|
import org.distorted.objectlib.shape.ShapeDiamond;
|
| 37 |
|
|
import org.distorted.objectlib.shape.ShapeDodecahedron;
|
| 38 |
|
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
| 39 |
379b3273
|
Leszek Koltunski
|
import org.distorted.objectlib.shape.ShapeIcosahedron;
|
| 40 |
d8cf6f49
|
Leszek Koltunski
|
import org.distorted.objectlib.shape.ShapeOctahedron;
|
| 41 |
|
|
import org.distorted.objectlib.shape.ShapeTetrahedron;
|
| 42 |
400ff34d
|
Leszek Koltunski
|
import org.distorted.objects.RubikObjectList;
|
| 43 |
373fa45f
|
Leszek Koltunski
|
import org.distorted.solvers.ImplementedSolversList;
|
| 44 |
a304ee64
|
Leszek Koltunski
|
import org.distorted.solvers.SolverMain;
|
| 45 |
7289fd6c
|
Leszek Koltunski
|
|
| 46 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 47 |
|
|
|
| 48 |
fcd5b990
|
Leszek Koltunski
|
public class RubikScreenSolver extends RubikScreenAbstract
|
| 49 |
7289fd6c
|
Leszek Koltunski
|
{
|
| 50 |
7a60305a
|
Leszek Koltunski
|
private static final int RESET_DURATION = 1000;
|
| 51 |
b3a907f1
|
Leszek Koltunski
|
private static final int MODE_NORMAL = 0;
|
| 52 |
|
|
private static final int MODE_DINO_4 = 1;
|
| 53 |
7a60305a
|
Leszek Koltunski
|
|
| 54 |
7289fd6c
|
Leszek Koltunski
|
private static Bitmap[] mBitmap;
|
| 55 |
|
|
private ImageButton[] mColorButton;
|
| 56 |
7a60305a
|
Leszek Koltunski
|
private TransparentImageButton mResetButton,mBackButton, mSolveButton;
|
| 57 |
5660465b
|
Leszek Koltunski
|
private boolean mSolving;
|
| 58 |
b3a907f1
|
Leszek Koltunski
|
private int mCurrentColor, mCurrentButton;
|
| 59 |
41748f19
|
Leszek Koltunski
|
private int[] mFaceColors;
|
| 60 |
b3a907f1
|
Leszek Koltunski
|
private int mColorMode;
|
| 61 |
57dea1ac
|
Leszek Koltunski
|
private int mNumColors;
|
| 62 |
7ea57482
|
Leszek Koltunski
|
private float mBitmapSize;
|
| 63 |
373fa45f
|
Leszek Koltunski
|
private WeakReference<RubikActivity> mWeakAct;
|
| 64 |
|
|
|
| 65 |
7289fd6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 66 |
|
|
|
| 67 |
f5da732a
|
Leszek Koltunski
|
void leaveScreen(RubikActivity act)
|
| 68 |
7289fd6c
|
Leszek Koltunski
|
{
|
| 69 |
9523ae28
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
| 70 |
|
|
control.unsetLock();
|
| 71 |
7289fd6c
|
Leszek Koltunski
|
}
|
| 72 |
|
|
|
| 73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 74 |
|
|
|
| 75 |
f5da732a
|
Leszek Koltunski
|
void enterScreen(final RubikActivity act)
|
| 76 |
7289fd6c
|
Leszek Koltunski
|
{
|
| 77 |
9523ae28
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
| 78 |
|
|
control.setLock(false);
|
| 79 |
|
|
|
| 80 |
e3c74c0f
|
Leszek Koltunski
|
float width = act.getScreenWidthInPixels();
|
| 81 |
6d4d56cb
|
Leszek Koltunski
|
float heigh = act.getScreenHeightInPixels();
|
| 82 |
7ea57482
|
Leszek Koltunski
|
|
| 83 |
373fa45f
|
Leszek Koltunski
|
mWeakAct = new WeakReference<>(act);
|
| 84 |
5660465b
|
Leszek Koltunski
|
mSolving = false;
|
| 85 |
|
|
|
| 86 |
67d7fb28
|
Leszek Koltunski
|
int solverIndex= act.getSolverIndex();
|
| 87 |
|
|
ImplementedSolversList currentSolver = ImplementedSolversList.getSolver(solverIndex);
|
| 88 |
|
|
int currentObject = currentSolver.getObject();
|
| 89 |
b20e89d2
|
Leszek Koltunski
|
act.changeIfDifferent(currentObject,control);
|
| 90 |
33f6abfd
|
Leszek Koltunski
|
control.solveOnly();
|
| 91 |
1088a219
|
Leszek Koltunski
|
RubikObjectList.setCurrObject(currentObject);
|
| 92 |
7289fd6c
|
Leszek Koltunski
|
|
| 93 |
d8cf6f49
|
Leszek Koltunski
|
generateFaceColors(currentObject);
|
| 94 |
20931cf6
|
Leszek Koltunski
|
|
| 95 |
57dea1ac
|
Leszek Koltunski
|
final float BUTTON_RATIO = 0.75f;
|
| 96 |
|
|
int sizeV = (int)(heigh*RubikActivity.RATIO_BAR*BUTTON_RATIO);
|
| 97 |
|
|
int sizeH = (int)((width/mNumColors)*BUTTON_RATIO);
|
| 98 |
|
|
mBitmapSize = Math.min(sizeV,sizeH);
|
| 99 |
|
|
|
| 100 |
7289fd6c
|
Leszek Koltunski
|
// TOP ////////////////////////////
|
| 101 |
|
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
| 102 |
|
|
layoutTop.removeAllViews();
|
| 103 |
|
|
|
| 104 |
57dea1ac
|
Leszek Koltunski
|
if( mNumColors>0 )
|
| 105 |
41748f19
|
Leszek Koltunski
|
{
|
| 106 |
7ebd72f7
|
Leszek Koltunski
|
setupBitmaps();
|
| 107 |
ad0c8e0e
|
Leszek Koltunski
|
setupColorButtons(act,width);
|
| 108 |
41748f19
|
Leszek Koltunski
|
markButton(act);
|
| 109 |
|
|
}
|
| 110 |
473611ee
|
Leszek Koltunski
|
|
| 111 |
7289fd6c
|
Leszek Koltunski
|
for(ImageButton button: mColorButton) layoutTop.addView(button);
|
| 112 |
|
|
|
| 113 |
|
|
// BOT ////////////////////////////
|
| 114 |
57dea1ac
|
Leszek Koltunski
|
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 |
92843d3b
|
Leszek Koltunski
|
LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
|
| 124 |
|
|
layoutBot.removeAllViews();
|
| 125 |
264af0ad
|
Leszek Koltunski
|
|
| 126 |
7a60305a
|
Leszek Koltunski
|
setupResetButton(act);
|
| 127 |
dd874ae8
|
Leszek Koltunski
|
setupSolveButton(act);
|
| 128 |
|
|
setupBackButton(act);
|
| 129 |
7289fd6c
|
Leszek Koltunski
|
|
| 130 |
7a60305a
|
Leszek Koltunski
|
layoutL.addView(mResetButton);
|
| 131 |
|
|
layoutM.addView(mSolveButton);
|
| 132 |
57dea1ac
|
Leszek Koltunski
|
layoutR.addView(mBackButton);
|
| 133 |
af133d41
|
Leszek Koltunski
|
|
| 134 |
57dea1ac
|
Leszek Koltunski
|
layoutBot.addView(layoutL);
|
| 135 |
|
|
layoutBot.addView(layoutM);
|
| 136 |
|
|
layoutBot.addView(layoutR);
|
| 137 |
7289fd6c
|
Leszek Koltunski
|
}
|
| 138 |
|
|
|
| 139 |
4ab3d91b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 140 |
d8cf6f49
|
Leszek Koltunski
|
// 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 |
4ab3d91b
|
Leszek Koltunski
|
|
| 143 |
d8cf6f49
|
Leszek Koltunski
|
public void generateFaceColors(int object)
|
| 144 |
4ab3d91b
|
Leszek Koltunski
|
{
|
| 145 |
b3a907f1
|
Leszek Koltunski
|
mColorMode = MODE_NORMAL;
|
| 146 |
|
|
|
| 147 |
de697069
|
leszek
|
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 |
d8cf6f49
|
Leszek Koltunski
|
{
|
| 156 |
57dea1ac
|
Leszek Koltunski
|
mNumColors = ShapeTetrahedron.NUM_FACES;
|
| 157 |
d8cf6f49
|
Leszek Koltunski
|
mFaceColors = ShapeTetrahedron.FACE_COLORS;
|
| 158 |
|
|
}
|
| 159 |
de697069
|
leszek
|
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 |
d8cf6f49
|
Leszek Koltunski
|
{
|
| 166 |
57dea1ac
|
Leszek Koltunski
|
mNumColors = ShapeOctahedron.NUM_FACES;
|
| 167 |
d8cf6f49
|
Leszek Koltunski
|
mFaceColors = ShapeOctahedron.FACE_COLORS;
|
| 168 |
|
|
}
|
| 169 |
de697069
|
leszek
|
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 |
d8cf6f49
|
Leszek Koltunski
|
{
|
| 177 |
57dea1ac
|
Leszek Koltunski
|
mNumColors = ShapeDodecahedron.NUM_FACES;
|
| 178 |
d8cf6f49
|
Leszek Koltunski
|
mFaceColors = ShapeDodecahedron.FACE_COLORS;
|
| 179 |
|
|
}
|
| 180 |
de697069
|
leszek
|
else if( object== ObjectConstants.BALL_4 )
|
| 181 |
d8cf6f49
|
Leszek Koltunski
|
{
|
| 182 |
57dea1ac
|
Leszek Koltunski
|
mNumColors = ShapeDiamond.NUM_FACES;
|
| 183 |
d8cf6f49
|
Leszek Koltunski
|
mFaceColors = ShapeDiamond.FACE_COLORS;
|
| 184 |
|
|
}
|
| 185 |
de697069
|
leszek
|
else if( object== ObjectConstants.ICOS_2 )
|
| 186 |
379b3273
|
Leszek Koltunski
|
{
|
| 187 |
|
|
mNumColors = ShapeIcosahedron.NUM_FACES;
|
| 188 |
|
|
mFaceColors = ShapeIcosahedron.FACE_COLORS;
|
| 189 |
|
|
}
|
| 190 |
de697069
|
leszek
|
else if( object== ObjectConstants.DIN4_3 )
|
| 191 |
8145d8b8
|
Leszek Koltunski
|
{
|
| 192 |
|
|
mNumColors = 4;
|
| 193 |
|
|
mFaceColors = new int[] { COLOR_YELLOW, COLOR_RED, COLOR_BLUE, COLOR_WHITE };
|
| 194 |
b3a907f1
|
Leszek Koltunski
|
mColorMode = MODE_DINO_4;
|
| 195 |
8145d8b8
|
Leszek Koltunski
|
}
|
| 196 |
d8cf6f49
|
Leszek Koltunski
|
else
|
| 197 |
|
|
{
|
| 198 |
57dea1ac
|
Leszek Koltunski
|
mNumColors = ShapeHexahedron.NUM_FACES;
|
| 199 |
d8cf6f49
|
Leszek Koltunski
|
mFaceColors = ShapeHexahedron.FACE_COLORS;
|
| 200 |
|
|
}
|
| 201 |
4ab3d91b
|
Leszek Koltunski
|
}
|
| 202 |
|
|
|
| 203 |
5660465b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 204 |
7289fd6c
|
Leszek Koltunski
|
|
| 205 |
7ebd72f7
|
Leszek Koltunski
|
private void setupBitmaps()
|
| 206 |
7289fd6c
|
Leszek Koltunski
|
{
|
| 207 |
1bd07548
|
Leszek Koltunski
|
final int SIZE = (int)mBitmapSize;
|
| 208 |
|
|
final float R = SIZE*0.15f;
|
| 209 |
|
|
final float M = SIZE*0.08f;
|
| 210 |
7289fd6c
|
Leszek Koltunski
|
|
| 211 |
57dea1ac
|
Leszek Koltunski
|
mBitmap = new Bitmap[mNumColors];
|
| 212 |
7289fd6c
|
Leszek Koltunski
|
|
| 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 |
57dea1ac
|
Leszek Koltunski
|
for(int i=0; i<mNumColors; i++)
|
| 222 |
7289fd6c
|
Leszek Koltunski
|
{
|
| 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 |
41748f19
|
Leszek Koltunski
|
paint.setColor(mFaceColors[i]);
|
| 230 |
7289fd6c
|
Leszek Koltunski
|
canvas.drawRoundRect( M, M, SIZE-M, SIZE-M, R, R, paint);
|
| 231 |
|
|
}
|
| 232 |
|
|
}
|
| 233 |
|
|
|
| 234 |
b3a907f1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 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 |
7289fd6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 251 |
|
|
|
| 252 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupColorButtons(final RubikActivity act, final float width)
|
| 253 |
7289fd6c
|
Leszek Koltunski
|
{
|
| 254 |
57dea1ac
|
Leszek Koltunski
|
mColorButton = new ImageButton[mNumColors];
|
| 255 |
ad0c8e0e
|
Leszek Koltunski
|
int padding = (int)(width*RubikActivity.PADDING);
|
| 256 |
c651024f
|
Leszek Koltunski
|
int margin = (int)(width*RubikActivity.SMALL_MARGIN);
|
| 257 |
7289fd6c
|
Leszek Koltunski
|
|
| 258 |
57dea1ac
|
Leszek Koltunski
|
for(int i=0; i<mNumColors; i++)
|
| 259 |
7289fd6c
|
Leszek Koltunski
|
{
|
| 260 |
|
|
final int ii = i;
|
| 261 |
ad0c8e0e
|
Leszek Koltunski
|
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 |
7289fd6c
|
Leszek Koltunski
|
mColorButton[i] = new ImageButton(act);
|
| 268 |
ad0c8e0e
|
Leszek Koltunski
|
mColorButton[i].setLayoutParams(params);
|
| 269 |
7289fd6c
|
Leszek Koltunski
|
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 |
b3a907f1
|
Leszek Koltunski
|
mCurrentColor = translateColor(ii);
|
| 278 |
|
|
mCurrentButton= ii;
|
| 279 |
473611ee
|
Leszek Koltunski
|
markButton(act);
|
| 280 |
7289fd6c
|
Leszek Koltunski
|
}
|
| 281 |
|
|
});
|
| 282 |
|
|
}
|
| 283 |
|
|
}
|
| 284 |
|
|
|
| 285 |
7a60305a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 286 |
|
|
|
| 287 |
|
|
private void setupResetButton(final RubikActivity act)
|
| 288 |
|
|
{
|
| 289 |
|
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_reset,R.drawable.ui_medium_reset, R.drawable.ui_big_reset, R.drawable.ui_huge_reset);
|
| 290 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
| 291 |
|
|
mResetButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
| 292 |
|
|
|
| 293 |
|
|
mResetButton.setOnClickListener( new View.OnClickListener()
|
| 294 |
|
|
{
|
| 295 |
|
|
@Override
|
| 296 |
|
|
public void onClick(View v)
|
| 297 |
|
|
{
|
| 298 |
|
|
ObjectControl control = act.getControl();
|
| 299 |
|
|
control.resetTextureMapsEffect(RESET_DURATION);
|
| 300 |
|
|
}
|
| 301 |
|
|
});
|
| 302 |
|
|
}
|
| 303 |
|
|
|
| 304 |
264af0ad
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 305 |
|
|
|
| 306 |
dd874ae8
|
Leszek Koltunski
|
private void setupSolveButton(final RubikActivity act)
|
| 307 |
264af0ad
|
Leszek Koltunski
|
{
|
| 308 |
23ac2462
|
Leszek Koltunski
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_solve,R.drawable.ui_medium_solve, R.drawable.ui_big_solve, R.drawable.ui_huge_solve);
|
| 309 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
| 310 |
|
|
mSolveButton = new TransparentImageButton(act,icon,TransparentImageButton.GRAVITY_MIDDLE,params);
|
| 311 |
264af0ad
|
Leszek Koltunski
|
|
| 312 |
|
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
| 313 |
|
|
{
|
| 314 |
|
|
@Override
|
| 315 |
|
|
public void onClick(View v)
|
| 316 |
|
|
{
|
| 317 |
5660465b
|
Leszek Koltunski
|
if( !mSolving )
|
| 318 |
|
|
{
|
| 319 |
|
|
mSolving = true;
|
| 320 |
9c2f0c91
|
Leszek Koltunski
|
TwistyObject object = act.getObject();
|
| 321 |
da57afae
|
Leszek Koltunski
|
SolverMain solver = new SolverMain( act.getInterface(), act.getResources(), object );
|
| 322 |
f0336037
|
Leszek Koltunski
|
solver.start();
|
| 323 |
5660465b
|
Leszek Koltunski
|
}
|
| 324 |
264af0ad
|
Leszek Koltunski
|
}
|
| 325 |
|
|
});
|
| 326 |
|
|
}
|
| 327 |
|
|
|
| 328 |
7289fd6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 329 |
|
|
|
| 330 |
dd874ae8
|
Leszek Koltunski
|
private void setupBackButton(final RubikActivity act)
|
| 331 |
7289fd6c
|
Leszek Koltunski
|
{
|
| 332 |
4fb1fc0d
|
Leszek Koltunski
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back);
|
| 333 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
| 334 |
|
|
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
| 335 |
7289fd6c
|
Leszek Koltunski
|
|
| 336 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
| 337 |
|
|
{
|
| 338 |
|
|
@Override
|
| 339 |
|
|
public void onClick(View v)
|
| 340 |
|
|
{
|
| 341 |
2afc6754
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
| 342 |
|
|
control.resetAllTextureMaps();
|
| 343 |
fcd5b990
|
Leszek Koltunski
|
ScreenList.goBack(act);
|
| 344 |
7289fd6c
|
Leszek Koltunski
|
}
|
| 345 |
|
|
});
|
| 346 |
|
|
}
|
| 347 |
|
|
|
| 348 |
473611ee
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 349 |
|
|
|
| 350 |
|
|
private void markButton(RubikActivity act)
|
| 351 |
|
|
{
|
| 352 |
757420b3
|
leszek
|
if( mCurrentButton>=mNumColors )
|
| 353 |
|
|
{
|
| 354 |
|
|
mCurrentButton = 0;
|
| 355 |
|
|
mCurrentColor = translateColor(0);
|
| 356 |
|
|
}
|
| 357 |
|
|
|
| 358 |
57dea1ac
|
Leszek Koltunski
|
for(int b=0; b<mNumColors; b++)
|
| 359 |
473611ee
|
Leszek Koltunski
|
{
|
| 360 |
|
|
Drawable d = mColorButton[b].getBackground();
|
| 361 |
|
|
|
| 362 |
b3a907f1
|
Leszek Koltunski
|
if( b==mCurrentButton )
|
| 363 |
473611ee
|
Leszek Koltunski
|
{
|
| 364 |
|
|
d.setColorFilter(ContextCompat.getColor(act,R.color.red), PorterDuff.Mode.MULTIPLY);
|
| 365 |
|
|
}
|
| 366 |
|
|
else
|
| 367 |
|
|
{
|
| 368 |
|
|
d.clearColorFilter();
|
| 369 |
|
|
}
|
| 370 |
|
|
}
|
| 371 |
|
|
}
|
| 372 |
|
|
|
| 373 |
7289fd6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 374 |
|
|
|
| 375 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
| 376 |
|
|
{
|
| 377 |
b3a907f1
|
Leszek Koltunski
|
editor.putInt("stateSolver_color" , mCurrentColor );
|
| 378 |
|
|
editor.putInt("stateSolver_button", mCurrentButton);
|
| 379 |
7289fd6c
|
Leszek Koltunski
|
}
|
| 380 |
|
|
|
| 381 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 382 |
|
|
|
| 383 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
| 384 |
|
|
{
|
| 385 |
b3a907f1
|
Leszek Koltunski
|
mCurrentColor = preferences.getInt("stateSolver_color" , 0);
|
| 386 |
|
|
mCurrentButton= preferences.getInt("stateSolver_button", 0);
|
| 387 |
7289fd6c
|
Leszek Koltunski
|
}
|
| 388 |
473611ee
|
Leszek Koltunski
|
|
| 389 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 390 |
|
|
|
| 391 |
|
|
public int getCurrentColor()
|
| 392 |
|
|
{
|
| 393 |
|
|
return mCurrentColor;
|
| 394 |
|
|
}
|
| 395 |
f0336037
|
Leszek Koltunski
|
|
| 396 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 397 |
|
|
|
| 398 |
373fa45f
|
Leszek Koltunski
|
public void setSolved(final String moves)
|
| 399 |
f0336037
|
Leszek Koltunski
|
{
|
| 400 |
|
|
mSolving = false;
|
| 401 |
373fa45f
|
Leszek Koltunski
|
final RubikActivity act = mWeakAct.get();
|
| 402 |
f0336037
|
Leszek Koltunski
|
|
| 403 |
373fa45f
|
Leszek Koltunski
|
if( act!=null )
|
| 404 |
f0336037
|
Leszek Koltunski
|
{
|
| 405 |
373fa45f
|
Leszek Koltunski
|
act.runOnUiThread(new Runnable()
|
| 406 |
f0336037
|
Leszek Koltunski
|
{
|
| 407 |
373fa45f
|
Leszek Koltunski
|
@Override
|
| 408 |
|
|
public void run()
|
| 409 |
|
|
{
|
| 410 |
f5da732a
|
Leszek Koltunski
|
ScreenList.switchScreen(act, ScreenList.SOLU);
|
| 411 |
|
|
RubikScreenSolution solution = (RubikScreenSolution) ScreenList.SOLU.getScreenClass();
|
| 412 |
373fa45f
|
Leszek Koltunski
|
solution.setupMoves(act, moves);
|
| 413 |
|
|
}
|
| 414 |
|
|
});
|
| 415 |
|
|
}
|
| 416 |
f0336037
|
Leszek Koltunski
|
}
|
| 417 |
|
|
|
| 418 |
277401c0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 419 |
|
|
|
| 420 |
|
|
public void setSolved(final int[][] moves)
|
| 421 |
|
|
{
|
| 422 |
|
|
mSolving = false;
|
| 423 |
|
|
final RubikActivity act = mWeakAct.get();
|
| 424 |
|
|
|
| 425 |
|
|
if( act!=null )
|
| 426 |
|
|
{
|
| 427 |
|
|
act.runOnUiThread(new Runnable()
|
| 428 |
|
|
{
|
| 429 |
|
|
@Override
|
| 430 |
|
|
public void run()
|
| 431 |
|
|
{
|
| 432 |
|
|
ScreenList.switchScreen(act, ScreenList.SOLU);
|
| 433 |
|
|
RubikScreenSolution solution = (RubikScreenSolution) ScreenList.SOLU.getScreenClass();
|
| 434 |
|
|
solution.setupMoves(act, moves);
|
| 435 |
|
|
}
|
| 436 |
|
|
});
|
| 437 |
|
|
}
|
| 438 |
|
|
}
|
| 439 |
|
|
|
| 440 |
f0336037
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 441 |
|
|
|
| 442 |
c02fa107
|
Leszek Koltunski
|
public void displayErrorDialog(String message)
|
| 443 |
f0336037
|
Leszek Koltunski
|
{
|
| 444 |
|
|
mSolving = false;
|
| 445 |
373fa45f
|
Leszek Koltunski
|
RubikActivity act = mWeakAct.get();
|
| 446 |
f0336037
|
Leszek Koltunski
|
|
| 447 |
373fa45f
|
Leszek Koltunski
|
if( act!=null )
|
| 448 |
|
|
{
|
| 449 |
|
|
RubikDialogSolverError dialog = new RubikDialogSolverError();
|
| 450 |
|
|
Bundle bundle = new Bundle();
|
| 451 |
c02fa107
|
Leszek Koltunski
|
bundle.putString("argument", message );
|
| 452 |
373fa45f
|
Leszek Koltunski
|
dialog.setArguments(bundle);
|
| 453 |
|
|
dialog.show( act.getSupportFragmentManager(), null);
|
| 454 |
|
|
}
|
| 455 |
f0336037
|
Leszek Koltunski
|
}
|
| 456 |
7289fd6c
|
Leszek Koltunski
|
}
|