Commit 49eba251 by likorn

Background animation instead of progressBar

parent cef6183d
......@@ -55,12 +55,12 @@ class TaskActivity : AppCompatActivity() {
}
private fun startProgressBarAnimation() {
val colorFrom = ContextCompat.getColor(this, R.color.colorPrimary)
val colorTo = Color.RED
val colorFrom = Color.TRANSPARENT
val colorTo = ContextCompat.getColor(this, R.color.transparent_red)
val colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo)
colorAnimation.duration = timeToSolve
colorAnimation.addUpdateListener { animator ->
progress_bar.progressDrawable.setColorFilter(animator.animatedValue as Int,
layout_gradient.background.setColorFilter(animator.animatedValue as Int,
android.graphics.PorterDuff.Mode.SRC_ATOP)
}
colorAnimation.start()
......@@ -72,13 +72,9 @@ class TaskActivity : AppCompatActivity() {
startActivity(intent)
}
private val timer = object : CountDownTimer(timeToSolve, 100) {
private val timer = object : CountDownTimer(timeToSolve, 1000) {
override fun onTick(millisUntilFinished: Long) {
val progress = ((timeToSolve - millisUntilFinished).toFloat() / timeToSolve) * 100
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
progress_bar.setProgress(progress.toInt(), true)
else
progress_bar.progress = progress.toInt()
tv_timer.text = (millisUntilFinished/1000).toString()
}
override fun onFinish() {
......
......@@ -9,33 +9,16 @@
tools:context=".TaskActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_gradient"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_height="0dp"
android:layout_marginBottom="32dp"
android:background="@drawable/gradient"
app:layout_constraintBottom_toBottomOf="@+id/cv_task"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="@+id/layout_progress_bar"
android:layout_width="match_parent"
android:layout_height="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_gravity="center"
android:foregroundTint="#320A64"
android:indeterminate="false"
android:max="100" />
</FrameLayout>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
......@@ -45,24 +28,23 @@
android:background="@android:color/transparent"
android:tint="@android:color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_progress_bar"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_back" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/tv_score"
android:id="@+id/tv_timer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_height="0dp"
android:gravity="center"
android:text="Score: 5"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:text="@string/number_digits_3"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="@+id/imageButton"
app:autoSizeTextType="uniform"
app:layout_constraintBottom_toTopOf="@+id/cv_task"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_progress_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintTop_toTopOf="parent" />
<androidx.cardview.widget.CardView
android:id="@+id/cv_task"
......@@ -77,7 +59,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5"
app:layout_constraintVertical_chainStyle="packed">
<TextView
......
......@@ -4,4 +4,5 @@
<color name="colorPrimaryDark">#12005e</color>
<color name="colorAccent">#4dd0e1</color>
<color name="transparent_black">#97000000</color>
<color name="transparent_red">#97FF0000</color>
</resources>
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