summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android/widget/MultiselectableRelativeLayout.kt
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-03-20 02:46:01 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-20 02:46:01 -0600
commit1054e54c8976e2ed5aef48a485b6ef28ae4ddcb8 (patch)
tree9552fde641c2b1c3e7c2d405dd6205f2b2978d9b /ui/src/main/java/com/wireguard/android/widget/MultiselectableRelativeLayout.kt
parent2fe5b92035934a24369197c41598c0a3972c44c5 (diff)
widget: rewrite in kotlin
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/widget/MultiselectableRelativeLayout.kt')
-rw-r--r--ui/src/main/java/com/wireguard/android/widget/MultiselectableRelativeLayout.kt49
1 files changed, 49 insertions, 0 deletions
diff --git a/ui/src/main/java/com/wireguard/android/widget/MultiselectableRelativeLayout.kt b/ui/src/main/java/com/wireguard/android/widget/MultiselectableRelativeLayout.kt
new file mode 100644
index 00000000..69ffefc0
--- /dev/null
+++ b/ui/src/main/java/com/wireguard/android/widget/MultiselectableRelativeLayout.kt
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+package com.wireguard.android.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import android.widget.RelativeLayout
+import com.wireguard.android.R
+
+class MultiselectableRelativeLayout : RelativeLayout {
+ private var multiselected = 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) {}
+ constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {}
+
+ override fun onCreateDrawableState(extraSpace: Int): IntArray {
+ if (multiselected) {
+ val drawableState = super.onCreateDrawableState(extraSpace + 1)
+ View.mergeDrawableStates(drawableState, STATE_MULTISELECTED)
+ return drawableState
+ }
+ return super.onCreateDrawableState(extraSpace)
+ }
+
+ fun setMultiSelected(on: Boolean) {
+ if (!multiselected) {
+ multiselected = true
+ refreshDrawableState()
+ }
+ isActivated = on
+ }
+
+ fun setSingleSelected(on: Boolean) {
+ if (multiselected) {
+ multiselected = false
+ refreshDrawableState()
+ }
+ isActivated = on
+ }
+
+ companion object {
+ private val STATE_MULTISELECTED = intArrayOf(R.attr.state_multiselected)
+ }
+}