forked from GitHub-Mirror/riotX-android
45 lines
1.2 KiB
Kotlin
45 lines
1.2 KiB
Kotlin
package im.vector.riotredesign.core.platform
|
|
|
|
import android.content.Context
|
|
import android.support.constraint.ConstraintLayout
|
|
import android.util.AttributeSet
|
|
import android.view.View
|
|
import android.widget.Checkable
|
|
|
|
class CheckableConstraintLayout : ConstraintLayout, Checkable {
|
|
|
|
private var mChecked = false
|
|
|
|
constructor(context: Context) : super(context) {}
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}
|
|
|
|
override fun isChecked(): Boolean {
|
|
return mChecked
|
|
}
|
|
|
|
override fun setChecked(b: Boolean) {
|
|
if (b != mChecked) {
|
|
mChecked = b
|
|
refreshDrawableState()
|
|
}
|
|
}
|
|
|
|
override fun toggle() {
|
|
isChecked = !mChecked
|
|
}
|
|
|
|
public override fun onCreateDrawableState(extraSpace: Int): IntArray {
|
|
val drawableState = super.onCreateDrawableState(extraSpace + 1)
|
|
if (isChecked) {
|
|
View.mergeDrawableStates(drawableState, CHECKED_STATE_SET)
|
|
}
|
|
return drawableState
|
|
}
|
|
|
|
companion object {
|
|
private val CHECKED_STATE_SET = intArrayOf(android.R.attr.state_checked)
|
|
}
|
|
} |