Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
quick_max
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a1562c1a
authored
Sep 24, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Progress bar color is animated
parent
50897d67
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
10 deletions
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/res/layout/activity_main.xml
app/src/main/res/values/colors.xml
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
a1562c1a
package
com.example.quickmax
import
android.animation.ArgbEvaluator
import
android.animation.ValueAnimator
import
android.os.Build
import
android.os.Bundle
import
android.os.CountDownTimer
import
android.widget.TextView
import
androidx.appcompat.app.AppCompatActivity
import
androidx.cardview.widget.CardView
import
androidx.core.content.ContextCompat
import
kotlinx.android.synthetic.main.activity_main.*
class
MainActivity
:
AppCompatActivity
()
{
private
lateinit
var
answerSet
:
AnswerSet
private
val
timeToSolve
=
4000
private
val
timeToSolve
:
Long
=
4000
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -19,6 +22,7 @@ class MainActivity : AppCompatActivity() {
answerSet
=
AnswerSet
(
3
)
setUpAnswerButtons
()
timer
.
start
()
startProgressBarAnimation
()
}
private
fun
setUpAnswerButtons
()
{
...
...
@@ -30,7 +34,7 @@ class MainActivity : AppCompatActivity() {
private
fun
processAnswer
(
correct
:
Boolean
)
{
timer
.
cancel
()
make
Radio
ButtonsUncheckable
()
makeButtonsUncheckable
()
val
responseFragment
=
ResponseFragment
.
newInstance
().
also
{
f
->
f
.
arguments
=
Bundle
().
also
{
...
...
@@ -42,29 +46,41 @@ class MainActivity : AppCompatActivity() {
.
commitAllowingStateLoss
()
}
private
fun
make
Radio
ButtonsUncheckable
()
{
private
fun
makeButtonsUncheckable
()
{
for
(
answer
in
answerSet
)
{
findViewById
<
CardView
>(
answer
.
buttonId
).
isClickable
=
false
}
}
private
fun
startProgressBarAnimation
()
{
val
colorFrom
=
ContextCompat
.
getColor
(
this
,
R
.
color
.
gradient_dark
)
val
colorTo
=
ContextCompat
.
getColor
(
this
,
R
.
color
.
red
)
val
colorAnimation
=
ValueAnimator
.
ofObject
(
ArgbEvaluator
(),
colorFrom
,
colorTo
)
colorAnimation
.
duration
=
timeToSolve
colorAnimation
.
addUpdateListener
{
animator
->
progress_bar
.
progressDrawable
.
setColorFilter
(
animator
.
animatedValue
as
Int
,
android
.
graphics
.
PorterDuff
.
Mode
.
SRC_ATOP
)
}
colorAnimation
.
start
()
}
fun
reload
()
{
val
intent
=
intent
finish
()
startActivity
(
intent
)
}
private
val
timer
=
object
:
CountDownTimer
(
timeToSolve
.
toLong
()
,
100
)
{
private
val
timer
=
object
:
CountDownTimer
(
timeToSolve
,
100
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
val
progress
=
((
timeToSolve
-
millisUntilFinished
).
toFloat
()
/
timeToSolve
)
*
100
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
bar_time_left
.
setProgress
(
progress
.
toInt
(),
true
)
progress_bar
.
setProgress
(
progress
.
toInt
(),
true
)
else
bar_time_left
.
progress
=
progress
.
toInt
()
progress_bar
.
progress
=
progress
.
toInt
()
}
override
fun
onFinish
()
{
make
Radio
ButtonsUncheckable
()
makeButtonsUncheckable
()
supportFragmentManager
.
beginTransaction
()
.
add
(
R
.
id
.
main_layout
,
TimeIsOverFragment
.
newInstance
(),
"time_is_over"
)
...
...
app/src/main/res/layout/activity_main.xml
View file @
a1562c1a
...
...
@@ -25,13 +25,14 @@
app:layout_constraintTop_toTopOf=
"parent"
>
<ProgressBar
android:id=
"@+id/
bar_time_left
"
android:id=
"@+id/
progress_bar
"
style=
"?android:attr/progressBarStyleHorizontal"
android:layout_width=
"match_parent"
android:layout_height=
"32dp"
android:layout_gravity=
"center"
android:max=
"100"
android:indeterminate=
"false"
/>
android:foregroundTint=
"#320A64"
android:indeterminate=
"false"
android:max=
"100"
/>
</FrameLayout>
...
...
app/src/main/res/values/colors.xml
View file @
a1562c1a
...
...
@@ -7,5 +7,8 @@
<color
name=
"colorBackground"
>
#C4BFCC
</color>
<color
name=
"colorCorrect"
>
#81C784
</color>
<color
name=
"gradient_dark"
>
#FF4A148C
</color>
<color
name=
"gradient_very_dark"
>
#FF320A64
</color>
<color
name=
"gradient_light"
>
#FF00BCD4
</color>
<color
name=
"white"
>
#FFF
</color>
<color
name=
"red"
>
#F00
</color>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment