基于Handler的Android定时器与倒计时器
源码地址:Github AndroidTimer
支持操作 :
- start
- pause
- resume
- cancel
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
...
compile 'com.github.xesam:AndroidTimer:v0.1'
}
- add ticker sequence
new CountTimer(100) {
@Override
public void onTick(long millisFly) { // millisFly is the Elapsed time at *Running State*
vCountSwitcher.setText((millisFly) + "");
Log.d("onTick", millisFly + "");
}
};
new CountDownTimer(10_000, 100) {
@Override
public void onTick(long millisUntilFinished) { // millisUntilFinished is the left time at *Running State*
Log.d("onTick", millisFly + "");
}
@Override
public void onCancel(long millisUntilFinished) {
}
@Override
public void onPause(long millisUntilFinished) {
}
@Override
public void onResume(long millisUntilFinished) {
}
@Override
public void onFinish() {
}
};
参考自 Android SDK 中的 CountDownTimer