Revision 807d82b7
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/main/RubikPostRender.java | ||
|---|---|---|
| 153 | 153 |
if( RubikState.getCurrentState()==RubikState.SOLV ) |
| 154 | 154 |
{
|
| 155 | 155 |
RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass(); |
| 156 |
mNewRecord = solving.stopCounting((RubikActivity)mView.getContext());
|
|
| 156 |
mNewRecord = solving.stopCounting(); |
|
| 157 | 157 |
|
| 158 | 158 |
if( mNewRecord< 0 ) |
| 159 | 159 |
{
|
| ... | ... | |
| 519 | 519 |
if( i==BaseEffect.Type.SCRAMBLE.ordinal() ) |
| 520 | 520 |
{
|
| 521 | 521 |
final RubikActivity act = (RubikActivity)mView.getContext(); |
| 522 |
RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass(); |
|
| 523 |
solving.resetUpperText(); |
|
| 524 | 522 |
|
| 525 | 523 |
act.runOnUiThread(new Runnable() |
| 526 | 524 |
{
|
| 527 | 525 |
@Override |
| 528 | 526 |
public void run() |
| 529 | 527 |
{
|
| 530 |
RubikState.switchState( act, RubikState.SOLV);
|
|
| 528 |
RubikState.switchState( act, RubikState.READ);
|
|
| 531 | 529 |
} |
| 532 | 530 |
}); |
| 533 | 531 |
} |
| ... | ... | |
| 552 | 550 |
dialog.setArguments(bundle); |
| 553 | 551 |
dialog.show( act.getSupportFragmentManager(), null); |
| 554 | 552 |
} |
| 553 |
|
|
| 554 |
act.runOnUiThread(new Runnable() |
|
| 555 |
{
|
|
| 556 |
@Override |
|
| 557 |
public void run() |
|
| 558 |
{
|
|
| 559 |
RubikState.switchState( act, RubikState.DONE); |
|
| 560 |
} |
|
| 561 |
}); |
|
| 555 | 562 |
} |
| 556 | 563 |
} |
| 557 | 564 |
|
| src/main/java/org/distorted/main/RubikSurfaceView.java | ||
|---|---|---|
| 373 | 373 |
|
| 374 | 374 |
object.beginNewRotation( mCurrentAxis, mCurrentRow ); |
| 375 | 375 |
|
| 376 |
if( RubikState.getCurrentState()==RubikState.SOLV )
|
|
| 376 |
if( RubikState.getCurrentState()==RubikState.READ )
|
|
| 377 | 377 |
{
|
| 378 |
final RubikActivity act = (RubikActivity)getContext(); |
|
| 379 |
|
|
| 380 |
act.runOnUiThread(new Runnable() |
|
| 381 |
{
|
|
| 382 |
@Override |
|
| 383 |
public void run() |
|
| 384 |
{
|
|
| 385 |
RubikState.switchState( act, RubikState.SOLV); |
|
| 386 |
} |
|
| 387 |
}); |
|
| 388 |
|
|
| 378 | 389 |
RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass(); |
| 379 | 390 |
solving.startCounting( (RubikActivity)getContext() ); |
| 380 | 391 |
} |
| src/main/java/org/distorted/states/RubikState.java | ||
|---|---|---|
| 33 | 33 |
PATT ( MAIN , MODE_DRAG , new RubikStatePattern() ), |
| 34 | 34 |
SVER ( MAIN , MODE_REPLACE, new RubikStateSolver() ), |
| 35 | 35 |
SOLU ( SVER , MODE_DRAG , new RubikStateSolution() ), |
| 36 |
READ ( PLAY , MODE_ROTATE , new RubikStateReady() ), |
|
| 37 |
DONE ( PLAY , MODE_DRAG , new RubikStateDone() ), |
|
| 36 | 38 |
; |
| 37 | 39 |
|
| 38 | 40 |
public static final int LENGTH = values().length; |
| src/main/java/org/distorted/states/RubikStateDone.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.states; |
|
| 21 |
|
|
| 22 |
import android.content.SharedPreferences; |
|
| 23 |
import android.util.DisplayMetrics; |
|
| 24 |
import android.view.LayoutInflater; |
|
| 25 |
import android.view.View; |
|
| 26 |
import android.widget.Button; |
|
| 27 |
import android.widget.LinearLayout; |
|
| 28 |
import android.widget.TextView; |
|
| 29 |
|
|
| 30 |
import org.distorted.main.R; |
|
| 31 |
import org.distorted.main.RubikActivity; |
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
public class RubikStateDone extends RubikStateAbstract |
|
| 36 |
{
|
|
| 37 |
void leaveState(RubikActivity act) |
|
| 38 |
{
|
|
| 39 |
|
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
void enterState(final RubikActivity act) |
|
| 45 |
{
|
|
| 46 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 47 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
| 48 |
float scale = metrics.density; |
|
| 49 |
|
|
| 50 |
// TOP //////////////////////////// |
|
| 51 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
| 52 |
layoutTop.removeAllViews(); |
|
| 53 |
TextView label = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
| 54 |
label.setText(R.string.solved); |
|
| 55 |
layoutTop.addView(label); |
|
| 56 |
|
|
| 57 |
// BOT //////////////////////////// |
|
| 58 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
|
| 59 |
layoutLeft.removeAllViews(); |
|
| 60 |
|
|
| 61 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
|
| 62 |
layoutRight.removeAllViews(); |
|
| 63 |
|
|
| 64 |
int padding = (int)(5*scale + 0.5f); |
|
| 65 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 66 |
|
|
| 67 |
Button back = new Button(act); |
|
| 68 |
back.setLayoutParams(params); |
|
| 69 |
back.setPadding(padding,0,padding,0); |
|
| 70 |
back.setText(R.string.back); |
|
| 71 |
|
|
| 72 |
back.setOnClickListener( new View.OnClickListener() |
|
| 73 |
{
|
|
| 74 |
@Override |
|
| 75 |
public void onClick(View v) |
|
| 76 |
{
|
|
| 77 |
RubikState.goBack(act); |
|
| 78 |
} |
|
| 79 |
}); |
|
| 80 |
|
|
| 81 |
layoutRight.addView(back); |
|
| 82 |
} |
|
| 83 |
|
|
| 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 85 |
|
|
| 86 |
public void savePreferences(SharedPreferences.Editor editor) |
|
| 87 |
{
|
|
| 88 |
|
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
|
|
| 93 |
public void restorePreferences(SharedPreferences preferences) |
|
| 94 |
{
|
|
| 95 |
|
|
| 96 |
} |
|
| 97 |
} |
|
| src/main/java/org/distorted/states/RubikStateReady.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.states; |
|
| 21 |
|
|
| 22 |
import android.content.SharedPreferences; |
|
| 23 |
import android.util.DisplayMetrics; |
|
| 24 |
import android.view.LayoutInflater; |
|
| 25 |
import android.view.View; |
|
| 26 |
import android.widget.Button; |
|
| 27 |
import android.widget.LinearLayout; |
|
| 28 |
import android.widget.TextView; |
|
| 29 |
|
|
| 30 |
import org.distorted.main.R; |
|
| 31 |
import org.distorted.main.RubikActivity; |
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
public class RubikStateReady extends RubikStateAbstract |
|
| 36 |
{
|
|
| 37 |
void leaveState(RubikActivity act) |
|
| 38 |
{
|
|
| 39 |
|
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
void enterState(final RubikActivity act) |
|
| 45 |
{
|
|
| 46 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 47 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
| 48 |
float scale = metrics.density; |
|
| 49 |
|
|
| 50 |
// TOP //////////////////////////// |
|
| 51 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
| 52 |
layoutTop.removeAllViews(); |
|
| 53 |
TextView label = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
| 54 |
label.setText(R.string.ready); |
|
| 55 |
layoutTop.addView(label); |
|
| 56 |
|
|
| 57 |
// BOT //////////////////////////// |
|
| 58 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
|
| 59 |
layoutLeft.removeAllViews(); |
|
| 60 |
|
|
| 61 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
|
| 62 |
layoutRight.removeAllViews(); |
|
| 63 |
|
|
| 64 |
int padding = (int)(5*scale + 0.5f); |
|
| 65 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 66 |
|
|
| 67 |
Button back = new Button(act); |
|
| 68 |
back.setLayoutParams(params); |
|
| 69 |
back.setPadding(padding,0,padding,0); |
|
| 70 |
back.setText(R.string.back); |
|
| 71 |
|
|
| 72 |
back.setOnClickListener( new View.OnClickListener() |
|
| 73 |
{
|
|
| 74 |
@Override |
|
| 75 |
public void onClick(View v) |
|
| 76 |
{
|
|
| 77 |
RubikState.goBack(act); |
|
| 78 |
} |
|
| 79 |
}); |
|
| 80 |
|
|
| 81 |
layoutRight.addView(back); |
|
| 82 |
} |
|
| 83 |
|
|
| 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 85 |
|
|
| 86 |
public void savePreferences(SharedPreferences.Editor editor) |
|
| 87 |
{
|
|
| 88 |
|
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
|
|
| 93 |
public void restorePreferences(SharedPreferences preferences) |
|
| 94 |
{
|
|
| 95 |
|
|
| 96 |
} |
|
| 97 |
} |
|
| src/main/java/org/distorted/states/RubikStateSolving.java | ||
|---|---|---|
| 45 | 45 |
{
|
| 46 | 46 |
private static final int DURATION_MILLIS = 750; |
| 47 | 47 |
|
| 48 |
private int mUpperText; |
|
| 49 | 48 |
private TextView mTime; |
| 50 | 49 |
private Timer mTimer; |
| 51 | 50 |
private long mStartTime; |
| 52 | 51 |
private boolean mRunning; |
| 53 | 52 |
private RubikScores mScores; |
| 54 |
private Button mBack; |
|
| 55 | 53 |
private ImageButton mPrevButton; |
| 56 | 54 |
private boolean mCanPrevMove; |
| 57 | 55 |
private ArrayList<Move> mMoves; |
| ... | ... | |
| 79 | 77 |
|
| 80 | 78 |
void leaveState(RubikActivity act) |
| 81 | 79 |
{
|
| 82 |
stopCounting(act);
|
|
| 80 |
stopCounting(); |
|
| 83 | 81 |
} |
| 84 | 82 |
|
| 85 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 88 | 86 |
{
|
| 89 | 87 |
mCanPrevMove = true; |
| 90 | 88 |
|
| 91 |
if( mUpperText==0 ) resetUpperText(); |
|
| 92 |
|
|
| 93 | 89 |
if( mMoves==null ) mMoves = new ArrayList<>(); |
| 94 | 90 |
else mMoves.clear(); |
| 95 | 91 |
|
| ... | ... | |
| 101 | 97 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
| 102 | 98 |
layoutTop.removeAllViews(); |
| 103 | 99 |
mTime = (TextView)inflater.inflate(R.layout.upper_text, null); |
| 104 |
mTime.setText(mUpperText);
|
|
| 100 |
mTime.setText(act.getString(R.string.tm_placeholder,0,0));
|
|
| 105 | 101 |
layoutTop.addView(mTime); |
| 106 | 102 |
|
| 107 | 103 |
// BOT //////////////////////////// |
| ... | ... | |
| 117 | 113 |
int padding = (int)(5*scale + 0.5f); |
| 118 | 114 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
| 119 | 115 |
|
| 120 |
mBack = new Button(act);
|
|
| 121 |
mBack.setLayoutParams(params);
|
|
| 122 |
mBack.setPadding(padding,0,padding,0);
|
|
| 123 |
mBack.setText(R.string.back);
|
|
| 116 |
Button back = new Button(act);
|
|
| 117 |
back.setLayoutParams(params);
|
|
| 118 |
back.setPadding(padding,0,padding,0);
|
|
| 119 |
back.setText(R.string.back);
|
|
| 124 | 120 |
|
| 125 |
mBack.setOnClickListener( new View.OnClickListener()
|
|
| 121 |
back.setOnClickListener( new View.OnClickListener()
|
|
| 126 | 122 |
{
|
| 127 | 123 |
@Override |
| 128 | 124 |
public void onClick(View v) |
| ... | ... | |
| 131 | 127 |
} |
| 132 | 128 |
}); |
| 133 | 129 |
|
| 134 |
layoutRight.addView(mBack);
|
|
| 130 |
layoutRight.addView(back);
|
|
| 135 | 131 |
} |
| 136 | 132 |
|
| 137 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 216 | 212 |
{
|
| 217 | 213 |
mPrevButton = null; |
| 218 | 214 |
|
| 215 |
editor.putLong("stateSolving_startTime" , mStartTime);
|
|
| 219 | 216 |
mScores.savePreferences(editor); |
| 220 | 217 |
} |
| 221 | 218 |
|
| ... | ... | |
| 223 | 220 |
|
| 224 | 221 |
public void restorePreferences(SharedPreferences preferences) |
| 225 | 222 |
{
|
| 223 |
mStartTime = preferences.getLong("stateSolving_startTime" , 0 );
|
|
| 226 | 224 |
mScores.restorePreferences(preferences); |
| 227 | 225 |
} |
| 228 | 226 |
|
| ... | ... | |
| 257 | 255 |
|
| 258 | 256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 259 | 257 |
|
| 260 |
public long stopCounting(RubikActivity act)
|
|
| 258 |
public long stopCounting() |
|
| 261 | 259 |
{
|
| 262 | 260 |
if( mRunning ) |
| 263 | 261 |
{
|
| 264 |
act.runOnUiThread(new Runnable() |
|
| 265 |
{
|
|
| 266 |
@Override |
|
| 267 |
public void run() |
|
| 268 |
{
|
|
| 269 |
mUpperText = R.string.solved; |
|
| 270 |
mTime.setText(mUpperText); |
|
| 271 |
mBack.setClickable(false); |
|
| 272 |
mPrevButton.setVisibility(View.INVISIBLE); |
|
| 273 |
} |
|
| 274 |
}); |
|
| 275 |
|
|
| 276 | 262 |
if( mTimer!=null ) |
| 277 | 263 |
{
|
| 278 | 264 |
mTimer.cancel(); |
| ... | ... | |
| 296 | 282 |
return 0; |
| 297 | 283 |
} |
| 298 | 284 |
|
| 299 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 300 |
|
|
| 301 |
public void resetUpperText() |
|
| 302 |
{
|
|
| 303 |
mUpperText = R.string.ready; |
|
| 304 |
} |
|
| 305 |
|
|
| 306 | 285 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 307 | 286 |
|
| 308 | 287 |
public void onActionFinished(final long effectID) |
Also available in: Unified diff
Add two new UI States: Ready and Done.