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
5456656a
authored
Sep 29, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Animation state and response text are restored
parent
cc85b698
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
18 deletions
app/src/main/java/com/paktalin/quickmax/TaskActivity.kt
app/src/main/java/com/paktalin/quickmax/TimerFragment.kt
app/src/main/java/com/paktalin/quickmax/TaskActivity.kt
View file @
5456656a
...
...
@@ -94,6 +94,6 @@ class TaskActivity : AppCompatActivity() {
fun
onTimeOver
()
{
addButtonNextFragment
(
supportFragmentManager
,
false
)
answerSet
.
forEach
{
answer
->
answer
.
card
.
disable
()
}
//
answerSet.forEach { answer -> answer.card.disable() }
}
}
app/src/main/java/com/paktalin/quickmax/TimerFragment.kt
View file @
5456656a
...
...
@@ -13,29 +13,42 @@ import android.view.ViewGroup
import
android.widget.TextView
import
androidx.fragment.app.Fragment
class
TimerFragment
:
Fragment
()
{
private
const
val
RESPONSE_CORRECT
=
"Correct!"
private
const
val
RESPONSE_WRONG
=
"Wrong!"
private
const
val
RESPONSE_TIME_OVER
=
"Time is over!"
class
TimerFragment
:
Fragment
()
{
private
lateinit
var
timer
:
CountDownTimer
private
lateinit
var
tvResponse
:
TextView
private
lateinit
var
colorAnimation
:
ValueAnimator
private
var
colorAnimation
:
ValueAnimator
?
=
null
private
var
millisToSolve
:
Long
=
0
private
var
colorFrom
:
Int
=
-
1
private
val
interval
:
Long
=
1000
private
var
finished
:
Boolean
=
false
private
lateinit
var
mView
:
View
private
var
restoredColor
:
Int
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
millisToSolve
=
arguments
!!
.
getLong
(
"millis_to_solve"
)
colorFrom
=
Color
.
TRANSPARENT
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
gradient_timer
,
container
,
false
)
tvResponse
=
view
!!
.
findViewById
(
R
.
id
.
tv_response
)
mView
=
view
tvResponse
=
mView
.
findViewById
(
R
.
id
.
tv_response
)
if
(
savedInstanceState
!=
null
)
restoreState
(
savedInstanceState
)
else
{
if
(!
finished
)
{
initTimer
()
initColorAnimation
()
}
...
...
@@ -45,34 +58,62 @@ class TimerFragment: Fragment() {
override
fun
onStart
()
{
super
.
onStart
()
timer
.
start
()
// colorAnimation.start()
if
(!
finished
)
{
timer
?.
start
()
colorAnimation
?.
start
()
}
}
override
fun
onSaveInstanceState
(
outState
:
Bundle
)
{
super
.
onSaveInstanceState
(
outState
)
val
text
=
tvResponse
.
text
.
toString
()
if
(
text
==
RESPONSE_CORRECT
||
text
==
RESPONSE_WRONG
||
text
==
RESPONSE_TIME_OVER
)
outState
.
putString
(
"response_text"
,
text
)
else
outState
.
putLong
(
"millis_to_solve"
,
millisToSolve
)
colorAnimation
?.
apply
{
if
(
animatedValue
!=
null
)
restoredColor
=
animatedValue
as
Int
}
restoredColor
?.
let
{
outState
.
putInt
(
"color_from"
,
it
)
}
}
fun
cancelCorrect
()
{
cancel
()
tvResponse
.
text
=
resources
.
getString
(
R
.
string
.
response_correct
)
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
))
tvResponse
.
text
=
RESPONSE_CORRECT
}
fun
cancelWrong
()
{
cancel
()
tvResponse
.
text
=
resources
.
getString
(
R
.
string
.
response_wrong
)
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
))
tvResponse
.
text
=
RESPONSE_WRONG
}
private
fun
restoreState
(
savedInstanceState
:
Bundle
)
{
val
responseText
=
savedInstanceState
.
getString
(
"response_text"
)
if
(
responseText
!=
null
)
{
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
))
tvResponse
.
text
=
responseText
restoredColor
=
savedInstanceState
.
getInt
(
"color_from"
)
restoredColor
?.
let
{
setBackgroundFilter
(
it
)
}
finished
=
true
}
else
{
millisToSolve
=
savedInstanceState
.
getLong
(
"millis_to_solve"
)
initTimer
()
colorFrom
=
savedInstanceState
.
getInt
(
"color_from"
)
}
}
private
fun
cancel
()
{
timer
.
cancel
()
colorAnimation
.
cancel
()
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
)
)
colorAnimation
?.
cancel
()
}
private
fun
setBackgroundFilter
(
color
:
Int
)
{
if
(
isAdded
)
mView
.
background
.
setColorFilter
(
color
,
PorterDuff
.
Mode
.
SRC_ATOP
)
}
private
fun
initTimer
()
{
...
...
@@ -85,20 +126,20 @@ class TimerFragment: Fragment() {
override
fun
onFinish
()
{
if
(
isAdded
)
{
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
))
tvResponse
.
text
=
resources
.
getString
(
R
.
string
.
time_is_over
)
tvResponse
.
text
=
RESPONSE_TIME_OVER
(
activity
as
TaskActivity
).
onTimeOver
()
}
}
}
}
private
fun
initColorAnimation
()
{
val
colorFrom
=
Color
.
TRANSPARENT
val
colorTo
=
color
(
context
!!
,
R
.
color
.
transparent_red
)
colorAnimation
=
ValueAnimator
.
ofObject
(
ArgbEvaluator
(),
colorFrom
,
colorTo
)
.
apply
{
duration
=
millisToSolve
}
colorAnimation
.
addUpdateListener
{
animator
->
view
!!
.
background
.
setColorFilter
(
animator
.
animatedValue
as
Int
,
PorterDuff
.
Mode
.
SRC_ATOP
)
colorAnimation
?
.
addUpdateListener
{
animator
->
setBackgroundFilter
(
animator
.
animatedValue
as
Int
)
}
}
}
\ No newline at end of file
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