Project

General

Profile

« Previous | Next » 

Revision 2e8ec627

Added by Leszek Koltunski about 4 years ago

Fixes for the fact that one could easily cheat - just pause the app while solving and come back to it, the time would reset to 0 and the object to unscrambled :(

View differences:

src/main/java/org/distorted/states/RubikStateSolving.java
53 53
  private ImageButton mPrevButton;
54 54
  private boolean mCanPrevMove;
55 55
  private ArrayList<Move> mMoves;
56
  private long mElapsed;
56 57

  
57 58
  private static class Move
58 59
    {
......
86 87
    {
87 88
    mCanPrevMove = true;
88 89

  
90
    startCounting(act);
91

  
89 92
    if( mMoves==null ) mMoves = new ArrayList<>();
90 93
    else               mMoves.clear();
91 94

  
......
97 100
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
98 101
    layoutTop.removeAllViews();
99 102
    mTime = (TextView)inflater.inflate(R.layout.upper_text, null);
100
    mTime.setText(act.getString(R.string.tm_placeholder,0,0));
103
    int elapsed = (int)mElapsed/1000;
104
    mTime.setText(act.getString(R.string.tm_placeholder,elapsed/60,elapsed%60));
101 105
    layoutTop.addView(mTime);
102 106

  
103 107
    // BOT ////////////////////////////
......
212 216
    {
213 217
    mPrevButton = null;
214 218

  
215
    editor.putLong("stateSolving_startTime" , mStartTime);
219
    mElapsed = System.currentTimeMillis()-mStartTime;
220
    editor.putLong("stateSolving_elapsed" , mElapsed);
216 221
    mScores.savePreferences(editor);
217 222
    }
218 223

  
......
220 225

  
221 226
  public void restorePreferences(SharedPreferences preferences)
222 227
    {
223
    mStartTime = preferences.getLong("stateSolving_startTime" , 0 );
228
    mElapsed = preferences.getLong("stateSolving_elapsed" , 0 );
224 229
    mScores.restorePreferences(preferences);
225 230
    }
226 231

  
227 232
///////////////////////////////////////////////////////////////////////////////////////////////////
228 233

  
229
  public void startCounting(final RubikActivity act)
234
  private void startCounting(final RubikActivity act)
230 235
    {
231 236
    if( !mRunning )
232 237
      {
233 238
      mRunning = true;
234
      mStartTime = System.currentTimeMillis();
239
      mStartTime = System.currentTimeMillis() - mElapsed;
235 240
      mTimer = new Timer();
236 241

  
237 242
      mTimer.scheduleAtFixedRate(new TimerTask()
......
266 271
        }
267 272
      mRunning = false;
268 273

  
269
      long timeTaken = System.currentTimeMillis()-mStartTime;
274
      mElapsed = System.currentTimeMillis()-mStartTime;
270 275

  
271 276
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
272 277
      int object  = play.getObject();
......
274 279
      int level   = play.getLevel();
275 280
      int realSize= RubikObjectList.getSizeIndex(object,size);
276 281

  
277
      boolean isNew = mScores.setRecord(object, realSize, level, timeTaken);
282
      boolean isNew = mScores.setRecord(object, realSize, level, mElapsed);
278 283

  
279
      return isNew ? timeTaken : -timeTaken;
284
      return isNew ? mElapsed : -mElapsed;
280 285
      }
281 286

  
282 287
    return 0;
283 288
    }
284 289

  
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

  
292
  public void resetElapsed()
293
    {
294
    mElapsed = 0;
295
    }
296

  
285 297
///////////////////////////////////////////////////////////////////////////////////////////////////
286 298

  
287 299
  public void onActionFinished(final long effectID)

Also available in: Unified diff