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
538cc042
authored
5 years ago
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put styling methods into extended MaterialCardView
parent
39bb884d
master
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
72 deletions
app/src/main/java/com/example/quickmax/CardStyle.kt
app/src/main/java/com/example/quickmax/MyMaterialCard.kt
app/src/main/java/com/example/quickmax/TaskActivity.kt
app/src/main/java/com/example/quickmax/answers/Answer.kt
app/src/main/java/com/example/quickmax/answers/AnswerSet.kt
app/src/main/res/layout/activity_task.xml
app/src/main/java/com/example/quickmax/CardStyle.kt
deleted
100644 → 0
View file @
39bb884d
package
com.example.quickmax
import
android.content.Context
import
android.graphics.Color
class
CardStyle
private
constructor
(
var
isCheckable
:
Boolean
,
var
isEnabled
:
Boolean
,
var
isChecked
:
Boolean
,
var
backgroundColor
:
Int
,
var
textColor
:
Int
)
{
companion
object
{
fun
initial
(
context
:
Context
):
CardStyle
{
return
CardStyle
(
isCheckable
=
true
,
isEnabled
=
true
,
isChecked
=
false
,
backgroundColor
=
Color
.
WHITE
,
textColor
=
color
(
context
,
R
.
color
.
transparent_black
))
}
fun
correct
(
context
:
Context
):
CardStyle
{
return
CardStyle
(
isCheckable
=
true
,
isEnabled
=
true
,
isChecked
=
true
,
backgroundColor
=
color
(
context
,
R
.
color
.
colorAccent
),
textColor
=
color
(
context
,
R
.
color
.
transparent_black
))
}
/* fun wrong(context: Context): CardStyle {
return CardStyle(
isCheckable = true,
isEnabled = true,
isChecked = true,
backgroundColor = color(context, R.color.colorAccent),
textColor = color(context, R.color.transparent_black))
}*/
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/quickmax/MyMaterialCard.kt
0 → 100644
View file @
538cc042
package
com.example.quickmax
import
android.content.Context
import
android.graphics.Color
import
android.util.AttributeSet
import
com.google.android.material.card.MaterialCardView
class
MyMaterialCard
:
MaterialCardView
{
constructor
(
context
:
Context
?)
:
super
(
context
)
constructor
(
context
:
Context
?,
attrs
:
AttributeSet
?)
:
super
(
context
,
attrs
)
constructor
(
context
:
Context
?,
attrs
:
AttributeSet
?,
defStyleAttr
:
Int
)
:
super
(
context
,
attrs
,
defStyleAttr
)
fun
clean
(
context
:
Context
)
{
isCheckable
=
true
isEnabled
=
true
isChecked
=
false
setCardBackgroundColor
(
Color
.
WHITE
)
getTextView
(
this
).
setTextColor
(
color
(
context
,
R
.
color
.
transparent_black
))
}
fun
markCorrect
()
{
setCardBackgroundColor
(
color
(
context
,
R
.
color
.
colorAccent
))
}
fun
markWrong
(
context
:
Context
)
{
setCardBackgroundColor
(
color
(
context
,
R
.
color
.
colorPrimary
))
getTextView
(
this
).
setTextColor
(
Color
.
WHITE
)
}
fun
disable
()
{
isCheckable
=
false
isEnabled
=
false
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/quickmax/TaskActivity.kt
View file @
538cc042
...
...
@@ -13,7 +13,6 @@ import androidx.appcompat.app.AppCompatActivity
import
androidx.core.content.ContextCompat
import
com.example.quickmax.answers.Answer
import
com.example.quickmax.answers.AnswerSet
import
com.google.android.material.card.MaterialCardView
import
kotlinx.android.synthetic.main.activity_task.*
class
TaskActivity
:
AppCompatActivity
()
{
...
...
@@ -50,7 +49,7 @@ class TaskActivity : AppCompatActivity() {
answer
.
card
.
setOnClickListener
{
answer
.
card
.
isChecked
=
true
}
answer
.
card
.
setOnCheckedChangeListener
{
_
,
isChecked
->
if
(
isChecked
)
processAnswer
(
answer
)
}
getTextView
(
answer
.
card
).
text
=
answer
.
value
.
toString
()
styleCard
(
answer
.
card
,
CardStyle
.
initial
(
this
)
)
answer
.
card
.
clean
(
this
@TaskActivity
)
}
btn_back
.
setOnClickListener
{
startActivity
(
Intent
(
this
@TaskActivity
,
MainActivity
::
class
.
java
))
}
btn_next
.
apply
{
...
...
@@ -59,14 +58,6 @@ class TaskActivity : AppCompatActivity() {
}
}
private
fun
styleCard
(
card
:
MaterialCardView
,
style
:
CardStyle
)
{
card
.
isCheckable
=
style
.
isCheckable
card
.
isEnabled
=
style
.
isEnabled
card
.
isChecked
=
style
.
isChecked
card
.
setCardBackgroundColor
(
style
.
backgroundColor
)
getTextView
(
card
).
setTextColor
(
style
.
textColor
)
}
private
fun
processAnswer
(
answer
:
Answer
)
{
timer
.
cancel
()
colorAnimation
.
cancel
()
...
...
@@ -79,25 +70,20 @@ class TaskActivity : AppCompatActivity() {
btn_next
.
visibility
=
View
.
VISIBLE
if
(
answer
.
correct
)
{
styleCard
(
answer
.
card
,
CardStyle
.
correct
(
this
)
)
answer
.
card
.
markCorrect
(
)
tv_response
.
text
=
resources
.
getString
(
R
.
string
.
response_correct
)
answer
.
card
.
setCardBackgroundColor
(
color
(
this
,
R
.
color
.
colorAccent
))
// btn_next.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorAccent)
btn_next
.
backgroundTintList
=
ContextCompat
.
getColorStateList
(
this
,
R
.
color
.
colorAccent
)
btn_next
.
setTextColor
(
color
(
this
,
R
.
color
.
transparent_dark_black
))
}
else
{
answer
.
card
.
markWrong
(
this
@TaskActivity
)
tv_response
.
text
=
resources
.
getString
(
R
.
string
.
response_wrong
)
answer
.
card
.
setCardBackgroundColor
(
color
(
this
,
R
.
color
.
colorPrimary
))
btn_next
.
backgroundTintList
=
ContextCompat
.
getColorStateList
(
this
,
(
R
.
color
.
colorPrimary
))
btn_next
.
setTextColor
(
Color
.
WHITE
)
getTextView
(
answer
.
card
).
setTextColor
(
Color
.
WHITE
)
}
}
private
fun
disableCards
()
{
for
(
answer
in
answerSet
)
{
answer
.
card
.
isCheckable
=
false
answer
.
card
.
isEnabled
=
false
}
answerSet
.
forEach
{
answer
->
answer
.
card
.
disable
()}
}
private
fun
startProgressBarAnimation
()
{
...
...
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/quickmax/answers/Answer.kt
View file @
538cc042
package
com.example.quickmax.answers
import
com.
google.android.material.card.MaterialCardView
import
com.
example.quickmax.MyMaterialCard
class
Answer
(
val
card
:
M
aterialCardView
,
val
value
:
Int
)
{
class
Answer
(
val
card
:
M
yMaterialCard
,
val
value
:
Int
)
{
var
correct
:
Boolean
=
false
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/quickmax/answers/AnswerSet.kt
View file @
538cc042
package
com.example.quickmax.answers
import
com.
google.android.material.card.MaterialCardView
import
com.
example.quickmax.MyMaterialCard
class
AnswerSet
(
numDigits
:
Int
,
cards
:
List
<
M
aterialCardView
>):
Iterable
<
Answer
>
{
class
AnswerSet
(
numDigits
:
Int
,
cards
:
List
<
M
yMaterialCard
>):
Iterable
<
Answer
>
{
private
val
numAnswers
=
4
private
lateinit
var
correctAnswer
:
Answer
...
...
This diff is collapsed.
Click to expand it.
app/src/main/res/layout/activity_task.xml
View file @
538cc042
...
...
@@ -90,7 +90,7 @@
app:layout_constraintVertical_bias=
"0.5"
app:layout_constraintVertical_chainStyle=
"packed"
>
<com.
google.android.material.card.MaterialCardView
<com.
example.quickmax.MyMaterialCard
android:id=
"@+id/card_left_top"
style=
"@style/MyCard"
app:cardCornerRadius=
"10dp"
...
...
@@ -102,9 +102,9 @@
<TextView
style=
"@style/AnswerCardText"
/>
</com.
google.android.material.card.MaterialCardView
>
</com.
example.quickmax.MyMaterialCard
>
<com.
google.android.material.card.MaterialCardView
<com.
example.quickmax.MyMaterialCard
android:id=
"@+id/card_right_top"
style=
"@style/MyCard"
app:layout_constraintBottom_toTopOf=
"@id/card_right_bottom"
...
...
@@ -115,9 +115,9 @@
<TextView
style=
"@style/AnswerCardText"
/>
</com.
google.android.material.card.MaterialCardView
>
</com.
example.quickmax.MyMaterialCard
>
<com.
google.android.material.card.MaterialCardView
<com.
example.quickmax.MyMaterialCard
android:id=
"@+id/card_left_bottom"
style=
"@style/MyCard"
app:layout_constraintBottom_toBottomOf=
"parent"
...
...
@@ -128,9 +128,9 @@
<TextView
style=
"@style/AnswerCardText"
/>
</com.
google.android.material.card.MaterialCardView
>
</com.
example.quickmax.MyMaterialCard
>
<com.
google.android.material.card.MaterialCardView
<com.
example.quickmax.MyMaterialCard
android:id=
"@+id/card_right_bottom"
style=
"@style/MyCard"
app:layout_constraintBottom_toBottomOf=
"parent"
...
...
@@ -141,7 +141,7 @@
<TextView
style=
"@style/AnswerCardText"
/>
</com.
google.android.material.card.MaterialCardView
>
</com.
example.quickmax.MyMaterialCard
>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
...
...
This diff is collapsed.
Click to expand it.
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