AnswerCardView.kt
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.paktalin.quickmax
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import androidx.core.content.ContextCompat
import com.google.android.material.card.MaterialCardView
class AnswerCardView : 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 initial(context: Context, text: Int) {
isCheckable = true
isEnabled = true
isChecked = false
setCardBackgroundColor(Color.WHITE)
getTextView(this).setTextColor(
color(
context,
R.color.transparent_black
)
)
getTextView(this).text = text.toString()
setOnClickListener { isChecked = true }
}
fun markCorrect(context: Context) {
checkedIcon = context.resources.getDrawable(R.drawable.ic_check, null)
foregroundTintList = ContextCompat.getColorStateList(context,
R.color.colorAccent
)
}
fun markWrong(context: Context) {
checkedIcon = context.resources.getDrawable(R.drawable.ic_cancel, null)
foregroundTintList = ContextCompat.getColorStateList(context,
R.color.red
)
}
fun disable() {
isCheckable = false
isEnabled = false
}
}