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
23de08e3
authored
Sep 24, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Card buttons instead of radioButtons
parent
84a2e414
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
172 additions
and
68 deletions
app/build.gradle
app/src/main/java/com/example/quickmax/Answer.kt
app/src/main/java/com/example/quickmax/AnswerSet.kt
app/src/main/java/com/example/quickmax/Calculator.kt
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/java/com/example/quickmax/NumberSet.kt
app/src/main/res/drawable/circle_button.xml
app/src/main/res/layout/activity_main.xml
app/src/main/res/values/strings.xml
app/src/test/java/com/example/quickmax/NumberSetTest.kt → app/src/test/java/com/example/quickmax/AnswerSetTest.kt
app/build.gradle
View file @
23de08e3
...
...
@@ -31,6 +31,7 @@ dependencies {
implementation
'androidx.core:core-ktx:1.1.0'
implementation
'androidx.constraintlayout:constraintlayout:1.1.3'
implementation
'com.google.android.material:material:1.0.0'
implementation
'androidx.cardview:cardview:1.0.0'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'androidx.test:runner:1.2.0'
...
...
app/src/main/java/com/example/quickmax/Answer.kt
0 → 100644
View file @
23de08e3
package
com.example.quickmax
class
Answer
(
val
buttonId
:
Int
,
val
value
:
Int
)
{
var
correct
:
Boolean
=
false
}
\ No newline at end of file
app/src/main/java/com/example/quickmax/AnswerSet.kt
0 → 100644
View file @
23de08e3
package
com.example.quickmax
class
AnswerSet
(
numDigits
:
Int
):
Iterable
<
Answer
>
{
private
val
buttonIds
=
listOf
(
R
.
id
.
btn_left_top
,
R
.
id
.
btn_right_top
,
R
.
id
.
btn_left_bottom
,
R
.
id
.
btn_right_bottom
)
private
val
numOptions
=
4
val
numbers
:
MutableList
<
Answer
>
=
MutableList
(
numOptions
)
{
i
->
Answer
(
buttonIds
[
i
],
generateRandom
(
numDigits
))
}
init
{
val
correctAnswer
=
findSecondMax
(
numbers
.
map
{
n
->
n
.
value
})
numbers
.
forEach
{
n
->
n
.
correct
=
n
.
value
==
correctAnswer
}
}
override
fun
iterator
():
Iterator
<
Answer
>
{
return
numbers
.
iterator
()
}
}
\ No newline at end of file
app/src/main/java/com/example/quickmax/Calculator.kt
View file @
23de08e3
...
...
@@ -8,7 +8,7 @@ fun generateRandom(numDigits: Int): Int {
return
(
start
..
end
).
shuffled
().
first
()
}
fun
findSecondMax
(
numbers
:
Mutable
List
<
Int
>):
Int
{
fun
findSecondMax
(
numbers
:
List
<
Int
>):
Int
{
var
firstMax
=
0
var
secondMax
=
0
...
...
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
23de08e3
...
...
@@ -3,15 +3,15 @@ package com.example.quickmax
import
android.os.Bundle
import
android.os.CountDownTimer
import
android.view.View
import
android.widget.Button
import
android.widget.RadioButton
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.view.get
import
androidx.fragment.app.Fragment
import
androidx.cardview.widget.CardView
import
kotlinx.android.synthetic.main.activity_main.*
class
MainActivity
:
AppCompatActivity
()
{
var
numberSet
=
NumberSet
(
4
,
3
)
private
var
answerSet
=
AnswerSet
(
4
)
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -21,22 +21,19 @@ class MainActivity : AppCompatActivity() {
}
private
fun
addRadioButtons
()
{
for
(
n
in
numberSet
)
{
val
radioButton
=
RadioButton
(
this
)
radioButton
.
id
=
View
.
generateViewId
()
radioButton
.
text
=
n
.
toString
()
radioButton
.
setOnClickListener
{
processAnswer
(
n
)
}
radio_group
.
addView
(
radioButton
)
for
(
answer
in
answerSet
)
{
findViewById
<
Button
>(
answer
.
buttonId
).
text
=
answer
.
value
.
toString
()
findViewById
<
Button
>(
answer
.
buttonId
).
setOnClickListener
{
processAnswer
(
answer
.
correct
)
}
}
}
private
fun
processAnswer
(
answer
:
Int
)
{
private
fun
processAnswer
(
correct
:
Boolean
)
{
timer
.
cancel
()
makeRadioButtonsUncheckable
()
val
responseFragment
=
ResponseFragment
.
newInstance
().
also
{
f
->
f
.
arguments
=
Bundle
().
also
{
b
->
b
.
putBoolean
(
"correct"
,
numberSet
.
isCorrect
(
answer
)
)
}
}
b
->
b
.
putBoolean
(
"correct"
,
correct
)
}
}
supportFragmentManager
.
beginTransaction
()
...
...
@@ -45,8 +42,8 @@ class MainActivity : AppCompatActivity() {
}
private
fun
makeRadioButtonsUncheckable
()
{
for
(
i
in
0
until
radio_group
.
childCoun
t
)
{
radio_group
[
i
]
.
isClickable
=
false
for
(
answer
in
answerSe
t
)
{
findViewById
<
Button
>(
answer
.
buttonId
)
.
isClickable
=
false
}
}
...
...
app/src/main/java/com/example/quickmax/NumberSet.kt
deleted
100644 → 0
View file @
84a2e414
package
com.example.quickmax
class
NumberSet
(
numOptions
:
Int
,
numDigits
:
Int
):
Iterable
<
Int
>
{
val
numbers
:
MutableList
<
Int
>
=
MutableList
(
numOptions
)
{
generateRandom
(
numDigits
)
}
private
val
correct
:
Int
=
findSecondMax
(
numbers
)
override
fun
iterator
():
Iterator
<
Int
>
{
return
numbers
.
iterator
()
}
fun
isCorrect
(
number
:
Int
)
:
Boolean
{
return
number
==
correct
}
}
\ No newline at end of file
app/src/main/res/drawable/circle_button.xml
0 → 100644
View file @
23de08e3
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape=
"oval"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<solid
android:color=
"#FFF44336"
/>
</shape>
app/src/main/res/layout/activity_main.xml
View file @
23de08e3
...
...
@@ -5,54 +5,138 @@
android:id=
"@+id/main_layout"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"#C4BFCC"
tools:context=
".MainActivity"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/
timer_layout
"
android:layout_width=
"
wrap_content
"
android:layout_height=
"
wrap_content
"
android:layout_margin
Top
=
"8dp"
a
ndroid:layout_marginEnd=
"8dp
"
android:id=
"@+id/
layout_answers
"
android:layout_width=
"
0dp
"
android:layout_height=
"
200dp
"
android:layout_margin=
"8dp"
a
pp:layout_constraintBottom_toBottomOf=
"parent
"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
>
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/cv_task"
app:layout_constraintVertical_bias=
"0.5"
app:layout_constraintVertical_chainStyle=
"packed"
>
<ImageView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:tint=
"#4CAF50"
app:layout_constraintEnd_toStartOf=
"@+id/tv_time_left"
<androidx.cardview.widget.CardView
android:id=
"@+id/cv_left_top"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:layout_margin=
"8dp"
app:layout_constraintBottom_toTopOf=
"@+id/cv_left_bottom"
app:layout_constraintEnd_toStartOf=
"@+id/cv_right_top"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@drawable/ic_timer_small"
/>
app:layout_constraintTop_toTopOf=
"parent"
>
<TextView
android:id=
"@+id/tv_time_left"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
<Button
android:id=
"@+id/btn_left_top"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"#00FFFFFF"
android:text=
"Button"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id=
"@+id/cv_right_top"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:layout_margin=
"8dp"
app:layout_constraintBottom_toTopOf=
"@id/cv_right_bottom"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toEndOf=
"@+id/cv_left_top"
app:layout_constraintTop_toTopOf=
"parent"
>
<Button
android:id=
"@+id/btn_right_top"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"#00FFFFFF"
android:text=
"Button"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id=
"@+id/cv_left_bottom"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:layout_margin=
"8dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toStartOf=
"@+id/cv_right_bottom"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/cv_left_top"
>
<Button
android:id=
"@+id/btn_left_bottom"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"#00FFFFFF"
android:text=
"Button"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id=
"@+id/cv_right_bottom"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:layout_margin=
"8dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toEndOf=
"@+id/cv_left_bottom"
app:layout_constraintTop_toBottomOf=
"@+id/cv_right_top"
>
<Button
android:id=
"@+id/btn_right_bottom"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"#00FFFFFF"
android:text=
"Button"
/>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id=
"@+id/task"
android:layout_width=
"wrap_content"
android:id=
"@+id/tv_time_left"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:layout_marginTop=
"16dp"
android:layout_marginEnd=
"16dp"
android:background=
"@drawable/circle_button"
android:gravity=
"center"
android:text=
"3"
android:textAppearance=
"@android:style/TextAppearance.Material.Large"
android:textColor=
"#FFFFFF"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<androidx.cardview.widget.CardView
android:id=
"@+id/cv_task"
style=
"@style/CardView.Light"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:text=
"@string/second_max"
app:layout_constraintLeft_toLeftOf=
"parent"
android:layout_margin=
"16dp"
app:cardBackgroundColor=
"#EBF8F8F8"
app:cardElevation=
"2dp"
app:layout_constraintBottom_toTopOf=
"@+id/layout_answers"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_goneMarginStart=
"8dp"
/>
app:layout_constraintVertical_bias=
"0.5"
app:layout_constraintVertical_chainStyle=
"packed"
>
<RadioGroup
android:id=
"@+id/radio_group"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/task"
app:layout_goneMarginStart=
"8dp"
>
<TextView
android:id=
"@+id/tv_task"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_margin=
"16dp"
android:gravity=
"center"
android:includeFontPadding=
"true"
android:text=
"@string/second_max"
android:textAppearance=
"@style/TextAppearance.MaterialComponents.Headline5"
android:textColor=
"#323753"
/>
</
RadioGroup
>
</
androidx.cardview.widget.CardView
>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
23de08e3
<resources>
<string
name=
"app_name"
>
QuickMax
</string>
<string
name=
"second_max"
>
Выберите второе наибольшее число
</string>
<string
name=
"second_max"
>
Choose the second greatest value
</string>
<string
name=
"response_correct"
>
CORRECT
</string>
<string
name=
"response_wrong"
>
WRONG
</string>
<string
name=
"time_is_over"
>
TIME IS OVER
</string>
...
...
app/src/test/java/com/example/quickmax/
Numb
erSetTest.kt
→
app/src/test/java/com/example/quickmax/
Answ
erSetTest.kt
View file @
23de08e3
...
...
@@ -4,11 +4,11 @@ import org.junit.Test
import
org.junit.Assert.*
class
Numb
erSetTest
{
class
Answ
erSetTest
{
private
val
numOptions
=
4
private
val
numDigits
=
3
private
val
numberSet
=
Numb
erSet
(
numOptions
,
numDigits
)
private
val
numberSet
=
Answ
erSet
(
numOptions
,
numDigits
)
@Test
fun
test_constructor
()
{
...
...
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