-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.kt
29 lines (27 loc) · 828 Bytes
/
Timer.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Timer{
private val mHandler:Handler = Handler()
private var mRunnable:Runnable = Runnable { }
private var seconds = 0
private var startRun = false
private var hours = 0
private var minutes = 0
private var secs = 0
fun onTimerStart(){
mRunnable = Runnable {
hours = seconds/3600
minutes = (seconds%3600)/60
secs = (seconds%60)
val time = String.format("%d:%02d:%02d", hours, minutes, secs)
txtTime.text = time
if (startRun){
seconds++
ed.putInt("SECONDS",seconds).commit()
}
mHandler.postDelayed(mRunnable,1000)
}
mHandler.postDelayed(mRunnable,1000)
}
fun onTimerStop(){
mHandler.removeCallbacks(mRunnable)
}
}