Commit 49eba251 by likorn

Background animation instead of progressBar

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