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
4a6665cc
authored
Sep 23, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Timer is stopped after answering
parent
b367ef90
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
22 deletions
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/java/com/example/quickmax/ResponseCorrectFragment.kt
app/src/main/res/layout/fragment_response_correct.xml
app/src/main/res/layout/fragment_response_wrong.xml
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
4a6665cc
...
@@ -17,23 +17,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -17,23 +17,7 @@ class MainActivity : AppCompatActivity() {
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
setContentView
(
R
.
layout
.
activity_main
)
addRadioButtons
()
addRadioButtons
()
setTimer
()
timer
.
start
()
}
private
fun
setTimer
()
{
object
:
CountDownTimer
(
4000
,
1000
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
tv_time_left
.
text
=
(
millisUntilFinished
/
1000
).
toString
()
}
override
fun
onFinish
()
{
makeRadioButtonsUncheckable
()
supportFragmentManager
.
beginTransaction
()
.
add
(
R
.
id
.
main_layout
,
TimeIsOverFragment
.
newInstance
(),
"time_is_over"
)
.
commitAllowingStateLoss
()
}
}.
start
()
}
}
private
fun
addRadioButtons
()
{
private
fun
addRadioButtons
()
{
...
@@ -47,6 +31,9 @@ class MainActivity : AppCompatActivity() {
...
@@ -47,6 +31,9 @@ class MainActivity : AppCompatActivity() {
}
}
private
fun
processAnswer
(
answer
:
Int
)
{
private
fun
processAnswer
(
answer
:
Int
)
{
timer
.
cancel
()
makeRadioButtonsUncheckable
()
val
responseFragment
:
Fragment
=
if
(
numberSet
.
isCorrect
(
answer
))
{
val
responseFragment
:
Fragment
=
if
(
numberSet
.
isCorrect
(
answer
))
{
ResponseCorrectFragment
.
newInstance
()
ResponseCorrectFragment
.
newInstance
()
}
else
}
else
...
@@ -56,7 +43,6 @@ class MainActivity : AppCompatActivity() {
...
@@ -56,7 +43,6 @@ class MainActivity : AppCompatActivity() {
.
beginTransaction
()
.
beginTransaction
()
.
add
(
R
.
id
.
main_layout
,
responseFragment
,
"response"
)
.
add
(
R
.
id
.
main_layout
,
responseFragment
,
"response"
)
.
commitAllowingStateLoss
()
.
commitAllowingStateLoss
()
makeRadioButtonsUncheckable
()
}
}
private
fun
makeRadioButtonsUncheckable
()
{
private
fun
makeRadioButtonsUncheckable
()
{
...
@@ -64,4 +50,18 @@ class MainActivity : AppCompatActivity() {
...
@@ -64,4 +50,18 @@ class MainActivity : AppCompatActivity() {
radio_group
[
i
].
isClickable
=
false
radio_group
[
i
].
isClickable
=
false
}
}
}
}
private
val
timer
=
object
:
CountDownTimer
(
4000
,
1000
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
tv_time_left
.
text
=
(
millisUntilFinished
/
1000
).
toString
()
}
override
fun
onFinish
()
{
makeRadioButtonsUncheckable
()
supportFragmentManager
.
beginTransaction
()
.
add
(
R
.
id
.
main_layout
,
TimeIsOverFragment
.
newInstance
(),
"time_is_over"
)
.
commitAllowingStateLoss
()
}
}
}
}
app/src/main/java/com/example/quickmax/ResponseCorrectFragment.kt
View file @
4a6665cc
...
@@ -4,6 +4,7 @@ import android.os.Bundle
...
@@ -4,6 +4,7 @@ import android.os.Bundle
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.ImageButton
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.Fragment
class
ResponseCorrectFragment
:
Fragment
()
{
class
ResponseCorrectFragment
:
Fragment
()
{
...
@@ -17,6 +18,14 @@ class ResponseCorrectFragment: Fragment() {
...
@@ -17,6 +18,14 @@ class ResponseCorrectFragment: Fragment() {
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_response_correct
,
container
,
false
)
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_response_correct
,
container
,
false
)
view
.
findViewById
<
ImageButton
>(
R
.
id
.
btn_next
).
setOnClickListener
{
reloadActivity
()
}
return
view
}
private
fun
reloadActivity
()
{
val
intent
=
activity
?.
intent
activity
?.
finish
()
activity
?.
startActivity
(
intent
)
}
}
}
}
\ No newline at end of file
app/src/main/res/layout/fragment_response_correct.xml
View file @
4a6665cc
...
@@ -7,11 +7,10 @@
...
@@ -7,11 +7,10 @@
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
android:background=
"#4CAF50"
android:background=
"#4CAF50"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
xmlns:tools=
"http://schemas.android.com/tools"
>
<ImageButton
<ImageButton
android:id=
"@+id/
imageButton
"
android:id=
"@+id/
btn_next
"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
...
...
app/src/main/res/layout/fragment_response_wrong.xml
View file @
4a6665cc
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
app:layout_constraintStart_toStartOf=
"parent"
>
app:layout_constraintStart_toStartOf=
"parent"
>
<ImageButton
<ImageButton
android:id=
"@+id/btn_next"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
...
...
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