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
24244d9e
authored
Sep 25, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NumDigits and SecondsToSolve are passed dynamically from MainActivity
parent
49eba251
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
13 deletions
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/java/com/example/quickmax/TaskActivity.kt
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
24244d9e
...
@@ -2,7 +2,10 @@ package com.example.quickmax
...
@@ -2,7 +2,10 @@ package com.example.quickmax
import
android.content.Intent
import
android.content.Intent
import
android.os.Bundle
import
android.os.Bundle
import
android.view.View
import
android.widget.TextView
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.app.AppCompatActivity
import
androidx.cardview.widget.CardView
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.activity_main.*
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
...
@@ -16,8 +19,19 @@ class MainActivity: AppCompatActivity() {
...
@@ -16,8 +19,19 @@ class MainActivity: AppCompatActivity() {
}
}
seek_bar
.
setMinStartValue
(
4f
).
apply
()
seek_bar
.
setMinStartValue
(
4f
).
apply
()
card_3_digits
.
setOnClickListener
{
card_2_digits
.
setOnClickListener
(
cardOnClickListener
)
startActivity
(
Intent
(
this
,
TaskActivity
::
class
.
java
))
card_3_digits
.
setOnClickListener
(
cardOnClickListener
)
card_4_digits
.
setOnClickListener
(
cardOnClickListener
)
}
}
private
val
cardOnClickListener
=
View
.
OnClickListener
{
card
->
val
numDigits
=
((
card
as
CardView
).
getChildAt
(
0
)
as
TextView
).
text
.
toString
().
toInt
()
val
secToSolve
=
seek_bar
.
selectedMinValue
.
toInt
()
val
intent
=
Intent
(
this
,
TaskActivity
::
class
.
java
).
also
{
i
->
i
.
putExtra
(
"num_digits"
,
numDigits
)
i
.
putExtra
(
"sec_to_solve"
,
secToSolve
)
}
startActivity
(
intent
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/example/quickmax/TaskActivity.kt
View file @
24244d9e
...
@@ -3,7 +3,6 @@ package com.example.quickmax
...
@@ -3,7 +3,6 @@ package com.example.quickmax
import
android.animation.ArgbEvaluator
import
android.animation.ArgbEvaluator
import
android.animation.ValueAnimator
import
android.animation.ValueAnimator
import
android.graphics.Color
import
android.graphics.Color
import
android.os.Build
import
android.os.Bundle
import
android.os.Bundle
import
android.os.CountDownTimer
import
android.os.CountDownTimer
import
android.widget.TextView
import
android.widget.TextView
...
@@ -16,17 +15,28 @@ import kotlinx.android.synthetic.main.activity_task.*
...
@@ -16,17 +15,28 @@ import kotlinx.android.synthetic.main.activity_task.*
class
TaskActivity
:
AppCompatActivity
()
{
class
TaskActivity
:
AppCompatActivity
()
{
private
lateinit
var
answerSet
:
AnswerSet
private
lateinit
var
answerSet
:
AnswerSet
private
val
timeToSolve
:
Long
=
4000
private
var
millisToSolve
:
Long
=
4000
private
lateinit
var
timer
:
CountDownTimer
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_task
)
setContentView
(
R
.
layout
.
activity_task
)
answerSet
=
AnswerSet
(
3
)
val
numDigits
=
intent
.
getIntExtra
(
"num_digits"
,
3
)
millisToSolve
=
1000
*
intent
.
getIntExtra
(
"sec_to_solve"
,
4
).
toLong
()
initTimer
()
answerSet
=
AnswerSet
(
numDigits
)
setUpAnswerButtons
()
setUpAnswerButtons
()
timer
.
start
()
timer
.
start
()
startProgressBarAnimation
()
startProgressBarAnimation
()
}
}
fun
reload
()
{
val
intent
=
intent
finish
()
startActivity
(
intent
)
}
private
fun
setUpAnswerButtons
()
{
private
fun
setUpAnswerButtons
()
{
for
(
answer
in
answerSet
)
{
for
(
answer
in
answerSet
)
{
(
findViewById
<
CardView
>(
answer
.
buttonId
).
getChildAt
(
0
)
as
TextView
).
text
=
answer
.
value
.
toString
()
(
findViewById
<
CardView
>(
answer
.
buttonId
).
getChildAt
(
0
)
as
TextView
).
text
=
answer
.
value
.
toString
()
...
@@ -58,7 +68,7 @@ class TaskActivity : AppCompatActivity() {
...
@@ -58,7 +68,7 @@ class TaskActivity : AppCompatActivity() {
val
colorFrom
=
Color
.
TRANSPARENT
val
colorFrom
=
Color
.
TRANSPARENT
val
colorTo
=
ContextCompat
.
getColor
(
this
,
R
.
color
.
transparent_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
=
time
ToSolve
colorAnimation
.
duration
=
millis
ToSolve
colorAnimation
.
addUpdateListener
{
animator
->
colorAnimation
.
addUpdateListener
{
animator
->
layout_gradient
.
background
.
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
)
...
@@ -66,13 +76,8 @@ class TaskActivity : AppCompatActivity() {
...
@@ -66,13 +76,8 @@ class TaskActivity : AppCompatActivity() {
colorAnimation
.
start
()
colorAnimation
.
start
()
}
}
fun
reload
()
{
private
fun
initTimer
()
{
val
intent
=
intent
timer
=
object
:
CountDownTimer
(
millisToSolve
,
1000
)
{
finish
()
startActivity
(
intent
)
}
private
val
timer
=
object
:
CountDownTimer
(
timeToSolve
,
1000
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
tv_timer
.
text
=
(
millisUntilFinished
/
1000
).
toString
()
tv_timer
.
text
=
(
millisUntilFinished
/
1000
).
toString
()
}
}
...
@@ -86,4 +91,5 @@ class TaskActivity : AppCompatActivity() {
...
@@ -86,4 +91,5 @@ class TaskActivity : AppCompatActivity() {
.
commitAllowingStateLoss
()
.
commitAllowingStateLoss
()
}
}
}
}
}
}
}
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