Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,4 @@ public void onStateUpdate(final int stateId) {
public void onStartStop(final View view) {
model.onStartStop();
}

public void onLapReset(final View view) {
model.onLapReset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum Constants {
;

public static final int SEC_PER_TICK = 1;
public static final int SEC_PER_MIN = 60;
public static final int SEC_PER_HOUR = 3600;
// Constant Max Value 99
public static final int MAX_TIME == 99;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
*/
public interface StopwatchUIListener {
void onStartStop();
void onLapReset();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,4 @@ public void onStartStop() {
stateMachine.onStartStop();
}

@Override
public void onLapReset() {
stateMachine.onLapReset();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.luc.etl.cs313.android.simplestopwatch.model.state;

import edu.luc.etl.cs313.android.simplestopwatch.R;

class AlarmState implements StopwatchState {

public AlarmState(final StopwatchSMStateView sm) {
this.sm = sm;
}

private final StopwatchSMStateView sm;


// Listener for Alarm action?


@Override
public void onStartStop() {
sm.actionStop();
sm.toStoppedState();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,31 @@ public void setModelListener(final StopwatchModelListener listener) {
// these must be synchronized because events can come from the
// UI thread or the timer thread
@Override public synchronized void onStartStop() { state.onStartStop(); }
@Override public synchronized void onLapReset() { state.onLapReset(); }
@Override public synchronized void onTick() { state.onTick(); }

@Override public void updateUIRuntime() { listener.onTimeUpdate(timeModel.getRuntime()); }
@Override public void updateUILaptime() { listener.onTimeUpdate(timeModel.getLaptime()); }


// known states
private final StopwatchState STOPPED = new StoppedState(this);
private final StopwatchState RUNNING = new RunningState(this);
private final StopwatchState LAP_RUNNING = new LapRunningState(this);
private final StopwatchState LAP_STOPPED = new LapStoppedState(this);
//private final StopwatchState ALARMING = new AlarmState(this);

// transitions
@Override public void toRunningState() { setState(RUNNING); }
@Override public void toStoppedState() { setState(STOPPED); }
@Override public void toLapRunningState() { setState(LAP_RUNNING); }
@Override public void toLapStoppedState() { setState(LAP_STOPPED); }
//@Override public void toAlarmState() { /* setState(ALARMING);*/ }

// actions
@Override public void actionInit() { toStoppedState(); actionReset(); }
@Override public void actionReset() { timeModel.resetRuntime(); actionUpdateView(); }

@Override public void actionStart() { clockModel.start(); }
@Override public void actionStop() { clockModel.stop(); }
@Override public void actionLap() { timeModel.setLaptime(); }
@Override public void actionInc() { timeModel.incRuntime(); actionUpdateView(); }
// Timer Countdown Action
@Override public void actionDec() { timeModel.decRuntime(); actionUpdateView(); }
// Alarm Action
//@Override public void actionAlarm() { /* listener.onAlarm(); */ }
@Override public void actionUpdateView() { state.updateView(); }
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ public RunningState(final StopwatchSMStateView sm) {
@Override
public void onStartStop() {
sm.actionStop();
// Reset Time and go to Stopped State
sm.actionReset();
sm.toStoppedState();
}

@Override
public void onLapReset() {
sm.actionLap();
sm.toLapRunningState();
}

@Override
public void onTick() {
sm.actionInc();
sm.toRunningState();
sm.actionDec();
// If time reaches 0, go to Alarm State
if (sm.getRuntime() == 0) {
sm.actionStop();
sm.toAlarmState();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ public StoppedState(final StopwatchSMStateView sm) {

@Override
public void onStartStop() {
sm.actionStart();
sm.toRunningState();
}

@Override
public void onLapReset() {
sm.actionReset();
sm.toStoppedState();
// Change Start/Stop button to Increment
sm.actionInc();
}

@Override
public void onTick() {
throw new UnsupportedOperationException("onTick");
// Need to implement 3s countdown to alarm
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ interface StopwatchSMStateView {
// transitions
void toRunningState();
void toStoppedState();
void toLapRunningState();
void toLapStoppedState();
//void toAlarmState();

// actions
void actionInit();
void actionReset();
void actionStart();
void actionStop();
void actionLap();
// Idle Increment Action
//void resetIdleTick();
//void incIdleTick();
void actionInc();
// Timer Countdown Action
void actionDec();
void actionUpdateView();
// Alarm Action
//void actionAlarm();

// state-dependent UI updates
void updateUIRuntime();
void updateUILaptime();

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,27 @@ public class DefaultTimeModel implements TimeModel {

private int runningTime = 0;

private int lapTime = -1;

@Override
public void resetRuntime() {
runningTime = 0;
}

@Override
public void incRuntime() {
runningTime = (runningTime + SEC_PER_TICK) % SEC_PER_HOUR;
}

@Override
public int getRuntime() {
return runningTime;
if (runningTime < 99) {
runningTime = (runningTime + SEC_PER_TICK);
}
}

@Override
public void setLaptime() {
lapTime = runningTime;
public void decRuntime() {
if (runningTime > 0) {
runningTime = (runningTime - SEC_PER_TICK);
}
}

@Override
public int getLaptime() {
return lapTime;
public int getRuntime() {
return runningTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public interface TimeModel {
void resetRuntime();
void incRuntime();
// New Decrement Runtime Method
void decRuntime();
int getRuntime();
void setLaptime();
int getLaptime();
}
Binary file added doc/ExtendedState-Diagram.pdf
Binary file not shown.