aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main/kotlin')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/dialogs/color/CircleView.kt14
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt3
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt15
3 files changed, 27 insertions, 5 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/CircleView.kt b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/CircleView.kt
index a40895e..1b5e0fe 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/CircleView.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/CircleView.kt
@@ -37,6 +37,7 @@ import ca.allanwang.kau.utils.toHSV
*/
class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
+ private val borderWidthMicro: Float = context.getDip(1f)
private val borderWidthSmall: Float = context.getDip(3f)
private val borderWidthLarge: Float = context.getDip(5f)
private var whiteOuterBound: Float = borderWidthLarge
@@ -45,6 +46,14 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
private val whitePaint: Paint = Paint().apply { isAntiAlias = true; color = Color.WHITE }
private val innerPaint: Paint = Paint().apply { isAntiAlias = true }
private var selected: Boolean = false
+ var withBorder: Boolean = false
+ get() = field
+ set(value) {
+ if (field != value) {
+ field = value
+ invalidate()
+ }
+ }
init {
update(Color.DKGRAY)
@@ -134,18 +143,19 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
super.onDraw(canvas)
val centerWidth = (measuredWidth / 2).toFloat()
val centerHeight = (measuredHeight / 2).toFloat()
+ if (withBorder) canvas.drawCircle(centerWidth, centerHeight, centerWidth, whitePaint)
if (selected) {
val whiteRadius = centerWidth - whiteOuterBound
val innerRadius = whiteRadius - borderWidthSmall
if (whiteRadius >= centerWidth) {
canvas.drawCircle(centerWidth, centerHeight, centerWidth, whitePaint)
} else {
- canvas.drawCircle(centerWidth, centerHeight, centerWidth, outerPaint)
+ canvas.drawCircle(centerWidth, centerHeight, if (withBorder) centerWidth - borderWidthMicro else centerWidth, outerPaint)
canvas.drawCircle(centerWidth, centerHeight, whiteRadius, whitePaint)
}
canvas.drawCircle(centerWidth, centerHeight, innerRadius, innerPaint)
} else {
- canvas.drawCircle(centerWidth, centerHeight, centerWidth, innerPaint)
+ canvas.drawCircle(centerWidth, centerHeight, if (withBorder) centerWidth - borderWidthMicro else centerWidth, innerPaint)
}
}
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
index fc3b6ff..62f3d45 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBinder.kt
@@ -46,7 +46,8 @@ class KPrefAdapterBuilder {
enabler: () -> Boolean = { true },
getter: () -> Int,
setter: (value: Int) -> Unit,
- configs: Builder.() -> Unit = {}) = list.add(KPrefColorPicker(this, title, description, iicon, enabler, getter, setter, configs))
+ configs: Builder.() -> Unit = {},
+ showPreview: Boolean = true) = list.add(KPrefColorPicker(this, title, description, iicon, enabler, getter, setter, configs, showPreview))
internal val list: MutableList<KPrefItemCore> = mutableListOf()
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt
index b590233..f157d1c 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefColorPicker.kt
@@ -4,6 +4,7 @@ import android.support.annotation.StringRes
import android.view.View
import ca.allanwang.kau.R
import ca.allanwang.kau.dialogs.color.Builder
+import ca.allanwang.kau.dialogs.color.CircleView
import ca.allanwang.kau.dialogs.color.colorPickerDialog
import ca.allanwang.kau.kpref.KPrefAdapterBuilder
import com.mikepenz.iconics.typeface.IIcon
@@ -21,11 +22,17 @@ class KPrefColorPicker(builder: KPrefAdapterBuilder,
enabler: () -> Boolean = { true },
getter: () -> Int,
setter: (value: Int) -> Unit,
- val configs: Builder.() -> Unit = {}) : KPrefItemBase<Int>(builder, title, description, iicon, enabler, getter, setter) {
+ val configs: Builder.() -> Unit = {},
+ val showPreview: Boolean = false) : KPrefItemBase<Int>(builder, title, description, iicon, enabler, getter, setter) {
override fun onPostBindView(viewHolder: ViewHolder, textColor: Int?, accentColor: Int?) {
super.onPostBindView(viewHolder, textColor, accentColor)
//TODO add color circle view
+ if (showPreview) {
+ val preview = viewHolder.bindInnerView<CircleView>(R.layout.kau_preference_color_preview)
+ preview.setBackgroundColor(pref)
+ preview.withBorder = true
+ }
}
@@ -33,7 +40,11 @@ class KPrefColorPicker(builder: KPrefAdapterBuilder,
itemView.context.colorPickerDialog {
titleRes = this@KPrefColorPicker.title
defaultColor = pref
- colorCallbacks.add { pref = it }
+ colorCallbacks.add {
+ pref = it
+ if (showPreview)
+ (innerContent as CircleView).setBackgroundColor(it)
+ }
applyNestedBuilder(configs)
}.show()
return true