File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed
app/src/main/java/com/qomunal/opensource/androidresearch/ui/main Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change 11package com.qomunal.opensource.androidresearch.ui.main
22
33import android.os.Bundle
4+ import android.os.CountDownTimer
45import androidx.activity.viewModels
56import com.qomunal.opensource.androidresearch.common.base.BaseActivity
6- import com.qomunal.opensource.androidresearch.common.ext.showToast
77import com.qomunal.opensource.androidresearch.databinding.ActivityMainBinding
8+ import java.text.DecimalFormat
9+ import java.text.NumberFormat
10+
811
912class MainActivity : BaseActivity <ActivityMainBinding >() {
1013
@@ -23,9 +26,21 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
2326
2427 override fun initUI () {
2528 binding.apply {
26- btnTest.setOnClickListener {
27- showToast(" Yes u click on me" )
28- }
29+ object : CountDownTimer (50000 , 1000 ) {
30+ override fun onTick (millisUntilFinished : Long ) {
31+ // Used for formatting digits to be in 2 digits only
32+ val f: NumberFormat = DecimalFormat (" 00" )
33+ val hour = (millisUntilFinished / 3600000 ) % 24
34+ val min = (millisUntilFinished / 60000 ) % 60
35+ val sec = (millisUntilFinished / 1000 ) % 60
36+ btnTest.text = f.format(hour) + " :" + f.format(min) + " :" + f.format(sec)
37+ }
38+
39+ override fun onFinish () {
40+ // When the task is over it will print 00:00:00
41+ btnTest.text = " 00:00:00"
42+ }
43+ }.start()
2944 }
3045 }
3146
You can’t perform that action at this time.
0 commit comments