Commit 5d376899 by likorn

CardView to MaterialCardView + refactoring

parent c1ccc474
......@@ -6,7 +6,7 @@ import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView
import com.google.android.material.card.MaterialCardView
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity: AppCompatActivity() {
......@@ -30,7 +30,7 @@ class MainActivity: AppCompatActivity() {
}
private val cardOnClickListener = View.OnClickListener { card ->
val numDigits = ((card as CardView).getChildAt(0) as TextView).text.toString().toInt()
val numDigits = ((card as MaterialCardView).getChildAt(0) as TextView).text.toString().toInt()
saveSelectedValues()
......
......@@ -40,12 +40,6 @@ class TaskActivity : AppCompatActivity() {
startProgressBarAnimation()
}
fun reload() {
val intent = intent
finish()
startActivity(intent)
}
private fun retrieveExtras() {
numDigits = intent.getIntExtra("num_digits", 3)
millisToSolve = 1000 * intent.getIntExtra("sec_to_solve", 4).toLong()
......@@ -56,7 +50,7 @@ class TaskActivity : AppCompatActivity() {
(answer.card.getChildAt(0) as TextView).text = answer.value.toString()
(answer.card.getChildAt(0) as TextView).setTextColor(color(R.color.transparent_black))
answer.card.setOnClickListener { processAnswer(answer) }
answer.card.background.clearColorFilter()
answer.card.setCardBackgroundColor(Color.WHITE)
}
btn_back.setOnClickListener { startActivity(Intent(this@TaskActivity, MainActivity::class.java)) }
btn_next.apply {
......@@ -78,13 +72,13 @@ class TaskActivity : AppCompatActivity() {
if (answer.correct) {
tv_timer.text = resources.getString(R.string.response_correct)
answer.card.background.setColorFilter(color(R.color.colorAccent), PorterDuff.Mode.MULTIPLY)
btn_next.background.setColorFilter(color(R.color.colorAccent), PorterDuff.Mode.MULTIPLY)
answer.card.setCardBackgroundColor(color(R.color.colorAccent))
btn_next.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorAccent)
btn_next.setTextColor(color(R.color.transparent_dark_black))
} else {
tv_timer.text = resources.getString(R.string.response_wrong)
answer.card.background.setColorFilter(color(R.color.colorPrimary), PorterDuff.Mode.MULTIPLY)
btn_next.background.setColorFilter(color(R.color.colorPrimary), PorterDuff.Mode.MULTIPLY)
answer.card.setCardBackgroundColor(color(R.color.colorPrimary))
btn_next.backgroundTintList = ContextCompat.getColorStateList(this, (R.color.colorPrimary))
btn_next.setTextColor(Color.WHITE)
(answer.card.getChildAt(0) as TextView).setTextColor(Color.WHITE)
}
......
package com.example.quickmax.answers
import androidx.cardview.widget.CardView
import com.google.android.material.card.MaterialCardView
class Answer(val card: CardView, val value: Int) {
class Answer(val card: MaterialCardView, val value: Int) {
var correct: Boolean = false
}
\ No newline at end of file
package com.example.quickmax.answers
import androidx.cardview.widget.CardView
import com.google.android.material.card.MaterialCardView
class AnswerSet(numDigits: Int, private val cards: List<CardView>): Iterable<Answer> {
class AnswerSet(numDigits: Int, cards: List<MaterialCardView>): Iterable<Answer> {
private val numAnswers = 4
private lateinit var correctAnswer: Answer
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/Base.CardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient">
......@@ -33,7 +32,7 @@
app:layout_constraintTop_toBottomOf="@+id/tv_how_many_digits"
app:layout_constraintBottom_toTopOf="@+id/seek_bar">
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_2_digits"
style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground"
......@@ -45,9 +44,9 @@
<TextView
style="@style/AnswerCardText"
android:text="@string/number_digits_2" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_3_digits"
style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground"
......@@ -59,9 +58,9 @@
<TextView
style="@style/AnswerCardText"
android:text="@string/number_digits_3" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_4_digits"
style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground"
......@@ -73,7 +72,7 @@
<TextView
style="@style/AnswerCardText"
android:text="@string/number_digits_4" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.crystal.crystalrangeseekbar.widgets.CrystalSeekbar
......
......@@ -44,15 +44,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/cv_task"
style="@style/CardView.Light"
style="@style/MyCard"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_margin="16dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="4dp"
app:cardElevation="2dp"
app:layout_constraintBottom_toTopOf="@+id/layout_answers"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......@@ -76,7 +73,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="#323753" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_answers"
......@@ -93,9 +90,10 @@
app:layout_constraintVertical_bias="0.5"
app:layout_constraintVertical_chainStyle="packed">
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_left_top"
style="@style/MyCard"
app:cardCornerRadius="10dp"
app:layout_constraintBottom_toTopOf="@+id/card_left_bottom"
app:layout_constraintEnd_toStartOf="@+id/card_right_top"
app:layout_constraintHorizontal_bias="0.5"
......@@ -104,9 +102,9 @@
<TextView style="@style/AnswerCardText" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_right_top"
style="@style/MyCard"
app:layout_constraintBottom_toTopOf="@id/card_right_bottom"
......@@ -117,9 +115,9 @@
<TextView style="@style/AnswerCardText" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_left_bottom"
style="@style/MyCard"
app:layout_constraintBottom_toBottomOf="parent"
......@@ -130,9 +128,9 @@
<TextView style="@style/AnswerCardText" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_right_bottom"
style="@style/MyCard"
app:layout_constraintBottom_toBottomOf="parent"
......@@ -143,7 +141,7 @@
<TextView style="@style/AnswerCardText" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
......
......@@ -4,18 +4,18 @@
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!-- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MyCard" parent="CardView">
<style name="MyCard" parent="Widget.MaterialComponents.CardView">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
<item name="android:layout_margin">8dp</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="android:foreground">?attr/selectableItemBackground</item>
<item name="cardCornerRadius">4dp</item>
<item name="cardCornerRadius">6dp</item>
<item name="cardBackgroundColor">@android:color/white</item>
</style>
......@@ -26,14 +26,4 @@
<item name="android:focusable">false</item>
<item name="android:textAppearance">@style/TextAppearance.MaterialComponents.Headline4</item>
</style>
<style name="ButtonNext">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">8dp</item>
<item name="android:layout_marginEnd">24dp</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:background">@android:color/transparent</item>
<item name="tint">@android:color/white</item>
</style>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment