Project

General

Profile

« Previous | Next » 

Revision 807d82b7

Added by Leszek Koltunski about 4 years ago

Add two new UI States: Ready and Done.

View differences:

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