Commit 2c5fa167 by likorn

Updated Material library version

parent 5d376899
......@@ -30,11 +30,10 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
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 'com.google.android.material:material:1.1.0-alpha10'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
......
......@@ -4,9 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.card.MaterialCardView
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity: AppCompatActivity() {
......@@ -30,7 +28,7 @@ class MainActivity: AppCompatActivity() {
}
private val cardOnClickListener = View.OnClickListener { card ->
val numDigits = ((card as MaterialCardView).getChildAt(0) as TextView).text.toString().toInt()
val numDigits = getTextView(card).text.toString().toInt()
saveSelectedValues()
......
......@@ -9,7 +9,6 @@ import android.os.Bundle
import android.os.CountDownTimer
import android.util.TypedValue
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.example.quickmax.answers.Answer
......@@ -47,8 +46,8 @@ class TaskActivity : AppCompatActivity() {
private fun setUpButtons() {
for (answer in answerSet) {
(answer.card.getChildAt(0) as TextView).text = answer.value.toString()
(answer.card.getChildAt(0) as TextView).setTextColor(color(R.color.transparent_black))
getTextView(answer.card).text = answer.value.toString()
getTextView(answer.card).setTextColor(color(this, R.color.transparent_black))
answer.card.setOnClickListener { processAnswer(answer) }
answer.card.setCardBackgroundColor(Color.WHITE)
}
......@@ -67,20 +66,20 @@ class TaskActivity : AppCompatActivity() {
}
private fun setResponseText(answer: Answer) {
tv_timer.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size))
tv_response.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size))
btn_next.visibility = View.VISIBLE
if (answer.correct) {
tv_timer.text = resources.getString(R.string.response_correct)
answer.card.setCardBackgroundColor(color(R.color.colorAccent))
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.setTextColor(color(R.color.transparent_dark_black))
btn_next.setTextColor(color(this, R.color.transparent_dark_black))
} else {
tv_timer.text = resources.getString(R.string.response_wrong)
answer.card.setCardBackgroundColor(color(R.color.colorPrimary))
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)
(answer.card.getChildAt(0) as TextView).setTextColor(Color.WHITE)
getTextView(answer.card).setTextColor(Color.WHITE)
}
}
......@@ -92,7 +91,7 @@ class TaskActivity : AppCompatActivity() {
private fun startProgressBarAnimation() {
val colorFrom = Color.TRANSPARENT
val colorTo = color(R.color.transparent_red)
val colorTo = color(this, R.color.transparent_red)
colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo)
colorAnimation.duration = millisToSolve
colorAnimation.addUpdateListener { animator ->
......@@ -105,20 +104,16 @@ class TaskActivity : AppCompatActivity() {
private fun initTimer() {
timer = object : CountDownTimer(millisToSolve, 1000) {
override fun onTick(millisUntilFinished: Long) {
tv_timer.text = (millisUntilFinished/1000).toString()
tv_response.text = (millisUntilFinished/1000).toString()
}
override fun onFinish() {
tv_timer.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size))
tv_timer.text = resources.getString(R.string.time_is_over)
btn_next.background.setColorFilter(color(R.color.colorPrimary), PorterDuff.Mode.MULTIPLY)
tv_response.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size))
tv_response.text = resources.getString(R.string.time_is_over)
btn_next.background.setColorFilter(color(this@TaskActivity, R.color.colorPrimary), PorterDuff.Mode.MULTIPLY)
btn_next.setTextColor(Color.WHITE)
btn_next.visibility = View.VISIBLE
}
}
}
private fun color(id: Int): Int {
return ContextCompat.getColor(this, id)
}
}
package com.example.quickmax
import android.content.Context
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.google.android.material.card.MaterialCardView
fun getTextView(card: View): TextView {
return ((card as MaterialCardView).getChildAt(0) as FrameLayout).getChildAt(0) as TextView
}
fun color(context: Context, id: Int): Int {
return ContextCompat.getColor(context, id)
}
\ No newline at end of file
......@@ -32,7 +32,7 @@
</LinearLayout>
<TextView
android:id="@+id/tv_timer"
android:id="@+id/tv_response"
style="@style/TextAppearance.MaterialComponents.Headline4"
android:layout_width="0dp"
android:layout_height="0dp"
......
......@@ -14,9 +14,9 @@
<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="android:checkable">true</item>
<item name="android:selectable">true</item>
<item name="cardCornerRadius">6dp</item>
<item name="cardBackgroundColor">@android:color/white</item>
</style>
<style name="AnswerCardText">
......
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