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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
20 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() {
...
@@ -94,6 +94,6 @@ class TaskActivity : AppCompatActivity() {
fun
onTimeOver
()
{
fun
onTimeOver
()
{
addButtonNextFragment
(
supportFragmentManager
,
false
)
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
...
@@ -13,29 +13,42 @@ import android.view.ViewGroup
import
android.widget.TextView
import
android.widget.TextView
import
androidx.fragment.app.Fragment
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
timer
:
CountDownTimer
private
lateinit
var
tvResponse
:
TextView
private
lateinit
var
tvResponse
:
TextView
private
lateinit
var
colorAnimation
:
ValueAnimator
private
var
colorAnimation
:
ValueAnimator
?
=
null
private
var
millisToSolve
:
Long
=
0
private
var
millisToSolve
:
Long
=
0
private
var
colorFrom
:
Int
=
-
1
private
val
interval
:
Long
=
1000
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
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
millisToSolve
=
arguments
!!
.
getLong
(
"millis_to_solve"
)
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
)
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
)
if
(
savedInstanceState
!=
null
)
restoreState
(
savedInstanceState
)
restoreState
(
savedInstanceState
)
else
{
if
(!
finished
)
{
initTimer
()
initTimer
()
initColorAnimation
()
initColorAnimation
()
}
}
...
@@ -45,34 +58,62 @@ class TimerFragment: Fragment() {
...
@@ -45,34 +58,62 @@ class TimerFragment: Fragment() {
override
fun
onStart
()
{
override
fun
onStart
()
{
super
.
onStart
()
super
.
onStart
()
timer
.
start
()
if
(!
finished
)
{
// colorAnimation.start()
timer
?.
start
()
colorAnimation
?.
start
()
}
}
}
override
fun
onSaveInstanceState
(
outState
:
Bundle
)
{
override
fun
onSaveInstanceState
(
outState
:
Bundle
)
{
super
.
onSaveInstanceState
(
outState
)
super
.
onSaveInstanceState
(
outState
)
outState
.
putLong
(
"millis_to_solve"
,
millisToSolve
)
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
()
{
fun
cancelCorrect
()
{
cancel
()
cancel
()
tvResponse
.
text
=
resources
.
getString
(
R
.
string
.
response_correct
)
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
))
tvResponse
.
text
=
RESPONSE_CORRECT
}
}
fun
cancelWrong
()
{
fun
cancelWrong
()
{
cancel
()
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
)
{
private
fun
restoreState
(
savedInstanceState
:
Bundle
)
{
millisToSolve
=
savedInstanceState
.
getLong
(
"millis_to_solve"
)
val
responseText
=
savedInstanceState
.
getString
(
"response_text"
)
initTimer
()
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"
)
colorFrom
=
savedInstanceState
.
getInt
(
"color_from"
)
}
}
}
private
fun
cancel
()
{
private
fun
cancel
()
{
timer
.
cancel
()
timer
.
cancel
()
colorAnimation
.
cancel
()
colorAnimation
?.
cancel
()
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
)
)
}
private
fun
setBackgroundFilter
(
color
:
Int
)
{
if
(
isAdded
)
mView
.
background
.
setColorFilter
(
color
,
PorterDuff
.
Mode
.
SRC_ATOP
)
}
}
private
fun
initTimer
()
{
private
fun
initTimer
()
{
...
@@ -85,20 +126,20 @@ class TimerFragment: Fragment() {
...
@@ -85,20 +126,20 @@ class TimerFragment: Fragment() {
override
fun
onFinish
()
{
override
fun
onFinish
()
{
if
(
isAdded
)
{
if
(
isAdded
)
{
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
))
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
()
(
activity
as
TaskActivity
).
onTimeOver
()
}
}
}
}
}
}
}
}
private
fun
initColorAnimation
()
{
private
fun
initColorAnimation
()
{
val
colorFrom
=
Color
.
TRANSPARENT
val
colorTo
=
color
(
context
!!
,
R
.
color
.
transparent_red
)
val
colorTo
=
color
(
context
!!
,
R
.
color
.
transparent_red
)
colorAnimation
=
ValueAnimator
.
ofObject
(
ArgbEvaluator
(),
colorFrom
,
colorTo
)
colorAnimation
=
ValueAnimator
.
ofObject
(
ArgbEvaluator
(),
colorFrom
,
colorTo
)
.
apply
{
duration
=
millisToSolve
}
.
apply
{
duration
=
millisToSolve
}
colorAnimation
.
addUpdateListener
{
animator
->
colorAnimation
?
.
addUpdateListener
{
animator
->
view
!!
.
background
.
setColorFilter
(
animator
.
animatedValue
as
Int
,
PorterDuff
.
Mode
.
SRC_ATOP
)
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