Skip to content

Commit

Permalink
Added resume() function
Browse files Browse the repository at this point in the history
Added isPaused() function
  • Loading branch information
carlosmuvi committed Jul 6, 2017
1 parent f5da7c8 commit a6ef942
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions app/src/main/java/com/carlosmuvi/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MainActivity extends AppCompatActivity {
SegmentedProgressBar segmentedProgressBar;
Button startButton;
Button startWithoutAnimationButton;
Button pauseButton;
Button pauseResumeButton;
Button resetButton;

@Override protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -21,7 +21,7 @@ public class MainActivity extends AppCompatActivity {
initSegmentedProgressBar();

startButton = (Button) findViewById(R.id.button);
pauseButton = (Button) findViewById(R.id.button3);
pauseResumeButton = (Button) findViewById(R.id.button3);
resetButton = (Button) findViewById(R.id.button2);
startWithoutAnimationButton = (Button) findViewById(R.id.button4);

Expand All @@ -31,9 +31,13 @@ public class MainActivity extends AppCompatActivity {
}
});

pauseButton.setOnClickListener(new View.OnClickListener() {
pauseResumeButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
segmentedProgressBar.pause();
if (segmentedProgressBar.isPaused()) {
segmentedProgressBar.resume();
} else {
segmentedProgressBar.pause();
}
}
});
startWithoutAnimationButton.setOnClickListener(new View.OnClickListener() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/button"
android:text="Pause"
android:text="Pause/Resume"
/>

<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public void pause() {
}
}

public void resume() {
if (timerState == TimerState.PAUSED) {
timerState = TimerState.RUNNING;
runDrawingTask();
}
}

public void reset() {
pause();
timerState = TimerState.IDLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ class SegmentedProgressBar : View {
}
}

fun pause() {
drawingTimer.pause()
}
fun pause() = drawingTimer.pause()
fun resume() = drawingTimer.resume()
fun reset() = setCompletedSegments(0)
fun isPaused() = drawingTimer.isPaused

fun setCompletedSegments(completedSegments: Int) {
if (completedSegments <= properties.segmentCount) {
Expand All @@ -110,10 +111,6 @@ class SegmentedProgressBar : View {
}
}

fun reset() {
setCompletedSegments(0)
}

/*
PRIVATE METHODS
*/
Expand Down

0 comments on commit a6ef942

Please sign in to comment.