Commit 50897d67 by likorn

Progress bar works as a timer

parent 6024ee21
package com.example.quickmax package com.example.quickmax
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.CountDownTimer import android.os.CountDownTimer
import android.widget.TextView import android.widget.TextView
...@@ -10,6 +11,7 @@ import kotlinx.android.synthetic.main.activity_main.* ...@@ -10,6 +11,7 @@ import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
private lateinit var answerSet: AnswerSet private lateinit var answerSet: AnswerSet
private val timeToSolve = 4000
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -52,9 +54,13 @@ class MainActivity : AppCompatActivity() { ...@@ -52,9 +54,13 @@ class MainActivity : AppCompatActivity() {
startActivity(intent) startActivity(intent)
} }
private val timer = object : CountDownTimer(4000, 1000) { private val timer = object : CountDownTimer(timeToSolve.toLong(), 100) {
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
// tv_time_left.text = (millisUntilFinished / 1000).toString() val progress = ((timeToSolve - millisUntilFinished).toFloat() / timeToSolve) * 100
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
bar_time_left.setProgress(progress.toInt(), true)
else
bar_time_left.progress = progress.toInt()
} }
override fun onFinish() { override fun onFinish() {
......
...@@ -25,14 +25,13 @@ ...@@ -25,14 +25,13 @@
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<ProgressBar <ProgressBar
android:id="@+id/bar_time_left"
style="?android:attr/progressBarStyleHorizontal" style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="32dp" android:layout_height="32dp"
android:layout_gravity="center" android:layout_gravity="center"
android:indeterminate="true" android:max="100"
android:indeterminateTint="#FFFFFF" android:indeterminate="false" />
android:progressTint="#FF9800"
android:progressTintMode="src_atop" />
</FrameLayout> </FrameLayout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment