Project

General

Profile

« Previous | Next » 

Revision 329c0aeb

Added by Leszek Koltunski about 4 years ago

Many small improvements.

View differences:

src/main/java/org/distorted/uistate/RubikStateSolving.java
33 33
import java.util.TimerTask;
34 34

  
35 35
import static android.view.View.INVISIBLE;
36
import static org.distorted.object.RubikObject.LENGTH;
37
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
36 38

  
37 39
///////////////////////////////////////////////////////////////////////////////////////////////////
38 40

  
39 41
public class RubikStateSolving extends RubikStateAbstract
40 42
  {
43
  private static final int NO_RECORD = Integer.MAX_VALUE;
44

  
41 45
  private TextView mTime;
42 46
  private Timer mTimer;
43 47
  private long mStartTime;
44 48
  private boolean mRunning;
45 49

  
50
  private long[][] mRecords;
51

  
46 52
///////////////////////////////////////////////////////////////////////////////////////////////////
47 53

  
48
  public void leaveState(RubikActivity act)
54
  RubikStateSolving()
55
    {
56
    mRecords = new long[LENGTH][MAX_SCRAMBLE];
57

  
58
    for(int i=0; i<LENGTH; i++)
59
      for(int j=0; j<MAX_SCRAMBLE; j++)
60
        {
61
        mRecords[i][j] = NO_RECORD;
62
        }
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  void leaveState(RubikActivity act)
49 68
    {
50 69
    stopCounting();
51 70
    }
52 71

  
53 72
///////////////////////////////////////////////////////////////////////////////////////////////////
54 73

  
55
  public void enterState(RubikActivity act)
74
  void enterState(RubikActivity act)
56 75
    {
57 76
    LayoutInflater inflater = act.getLayoutInflater();
58 77

  
......
96 115

  
97 116
  public void savePreferences(SharedPreferences.Editor editor)
98 117
    {
99

  
118
    for(int i=0; i<LENGTH; i++)
119
      for(int j=0; j<MAX_SCRAMBLE; j++)
120
        {
121
        if( mRecords[i][j]!=NO_RECORD)
122
          {
123
          editor.putLong("record_"+i+"_"+j, mRecords[i][j]);
124
          }
125
        }
100 126
    }
101 127

  
102 128
///////////////////////////////////////////////////////////////////////////////////////////////////
103 129

  
104 130
  public void restorePreferences(SharedPreferences preferences)
105 131
    {
106

  
132
    for(int i=0; i<LENGTH; i++)
133
      for(int j=0; j<MAX_SCRAMBLE; j++)
134
        {
135
        mRecords[i][j] = preferences.getInt("record_"+i+"_"+j, NO_RECORD );
136
        }
107 137
    }
108 138

  
109 139
///////////////////////////////////////////////////////////////////////////////////////////////////
......
148 178
        }
149 179
      mRunning = false;
150 180

  
151
      return System.currentTimeMillis()-mStartTime;
181
      long timeTaken = System.currentTimeMillis()-mStartTime;
182

  
183
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
184
      int object  = play.getButton();
185
      int scramble= play.getPicker();
186

  
187
      if( object>=0 && object<LENGTH && scramble>=0 && scramble<MAX_SCRAMBLE )
188
        {
189
        if( mRecords[object][scramble]> timeTaken )
190
          {
191
          mRecords[object][scramble] = timeTaken;
192
          android.util.Log.e("solv","new record!");
193
          }
194
        }
195

  
196
      return timeTaken;
152 197
      }
153 198

  
154 199
    return 0;

Also available in: Unified diff