restore TimerStatus

This commit is contained in:
longerian
2018-04-04 12:47:21 +08:00
parent 341580edf0
commit ef020c0350
4 changed files with 46 additions and 36 deletions
@@ -71,6 +71,7 @@ public class HandlerTimer implements Runnable, ITimer {
/**
* start timer immediately
*/
@Override
public void start() {
start(false);
}
@@ -78,6 +79,7 @@ public class HandlerTimer implements Runnable, ITimer {
/**
* @param bySecond true, start timer with interval alignment; false, start timer immediately
*/
@Override
public void start(boolean bySecond) {
if (this.mStatus != TimerStatus.Running) {
this.mStartTS = bySecond ? 0 : System.currentTimeMillis();
@@ -92,6 +94,7 @@ public class HandlerTimer implements Runnable, ITimer {
/**
* pause timer
*/
@Override
public void pause() {
this.mStatus = TimerStatus.Paused;
mHandler.removeCallbacks(this);
@@ -100,6 +103,7 @@ public class HandlerTimer implements Runnable, ITimer {
/**
* resume timer
*/
@Override
public void restart() {
mHandler.removeCallbacks(this);
this.mStatus = TimerStatus.Running;
@@ -109,6 +113,7 @@ public class HandlerTimer implements Runnable, ITimer {
/**
* stop timer
*/
@Override
public void stop() {
mStatus = TimerStatus.Stopped;
mHandler.removeCallbacks(this);
@@ -117,6 +122,7 @@ public class HandlerTimer implements Runnable, ITimer {
/**
* cancel timer
*/
@Override
public void cancel() {
mStatus = TimerStatus.Stopped;
mHandler.removeCallbacks(this);
@@ -125,9 +131,44 @@ public class HandlerTimer implements Runnable, ITimer {
/**
* @return current status
*/
@Override
public TimerStatus getStatus() {
return mStatus;
}
/**
* Timer status
*/
public enum TimerStatus {
Waiting(0, "Wating"),
Running(1, "Running"),
Paused(-1, "Paused"),
Stopped(-2, "Stopped");
private int code;
private String desc;
private TimerStatus(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
}
@@ -24,6 +24,8 @@
package com.tmall.wireless.tangram.support;
import com.tmall.wireless.tangram.support.HandlerTimer.TimerStatus;
/**
* Created by villadora on 15/8/31.
*/
@@ -64,39 +66,4 @@ public interface ITimer {
*/
TimerStatus getStatus();
/**
* Timer status
*/
enum TimerStatus {
Waiting(0, "Wating"),
Running(1, "Running"),
Paused(-1, "Paused"),
Stopped(-2, "Stopped");
private int code;
private String desc;
private TimerStatus(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
}
@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
import android.support.annotation.NonNull;
import android.support.v4.util.ArrayMap;
import android.util.Log;
import com.tmall.wireless.tangram.support.HandlerTimer.TimerStatus;
import com.tmall.wireless.tangram.support.TimerSupport.OnTickListener;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -25,6 +25,7 @@
package com.tmall.wireless.tangram.support;
import android.support.annotation.NonNull;
import com.tmall.wireless.tangram.support.HandlerTimer.TimerStatus;
import io.reactivex.Observable;
import java.util.concurrent.TimeUnit;
@@ -64,7 +65,7 @@ public class TimerSupport {
/**
* @return current timer status
*/
public HandlerTimer.TimerStatus getStatus() {
public TimerStatus getStatus() {
return mDefaultTimer.getStatus();
}