diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-11 13:51:40 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-11 13:51:40 -0700 |
commit | 11090367b5783d33aae97637cb08360be9659ff9 (patch) | |
tree | 8bd2da584d97fb59d9f176dac75b2f42f8568e6d /library/src/main/kotlin/ca/allanwang | |
parent | 3b7cd18459b5cbe5ff86ca3af9bddd9a222d3e67 (diff) | |
download | kau-11090367b5783d33aae97637cb08360be9659ff9.tar.gz kau-11090367b5783d33aae97637cb08360be9659ff9.tar.bz2 kau-11090367b5783d33aae97637cb08360be9659ff9.zip |
Fix selection and add fade effect
Diffstat (limited to 'library/src/main/kotlin/ca/allanwang')
3 files changed, 31 insertions, 8 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt index 13407db..36c0feb 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt @@ -34,14 +34,14 @@ abstract class KPrefActivity : AppCompatActivity() { fun reload(vararg index: Int) { if (index.isEmpty()) adapter.notifyAdapterDataSetChanged() - else index.forEach { adapter.notifyItemChanged(it, null) } + else index.forEach { adapter.notifyItemChanged(it) } } fun reloadByTitle(@StringRes vararg title: Int) { if (title.isEmpty()) return adapter.adapterItems.forEachIndexed { index, item -> if (title.any { item.title == it }) - adapter.notifyItemChanged(index, null) + adapter.notifyItemChanged(index) } } diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt index cae2979..a15dcc3 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt @@ -30,7 +30,7 @@ abstract class KPrefItemBase<T>(builder: KPrefAdapterBuilder, override fun onPostBindView(viewHolder: ViewHolder, textColor: Int?, accentColor: Int?) { val enabled = enabler.invoke() with(viewHolder) { - container?.isEnabled = enabled + itemView.isEnabled = enabled container?.alpha = if (enabled) 1.0f else 0.3f } } @@ -38,7 +38,7 @@ abstract class KPrefItemBase<T>(builder: KPrefAdapterBuilder, override fun unbindView(holder: ViewHolder) { super.unbindView(holder) with(holder) { - container?.isEnabled = true + itemView.isEnabled = true container?.alpha = 1.0f } } diff --git a/library/src/main/kotlin/ca/allanwang/kau/views/RippleCanvas.kt b/library/src/main/kotlin/ca/allanwang/kau/views/RippleCanvas.kt index eaa9121..805fb21 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/views/RippleCanvas.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/views/RippleCanvas.kt @@ -1,5 +1,6 @@ package ca.allanwang.kau.views +import android.animation.ArgbEvaluator import android.animation.ValueAnimator import android.content.Context import android.graphics.Canvas @@ -71,16 +72,21 @@ class RippleCanvas @JvmOverloads constructor( return color.adjustAlpha(factor) } - fun ripple(color: Int, startX: Float = 0f, startY: Float = 0f, duration: Int = 1000, fade: Boolean = Color.alpha(color) != 255) { + /** + * Creates a ripple effect from the given starting values + * [fade] will gradually transition previous ripples to a transparent color so the resulting background is what we want + * this is typically only necessary if the ripple color has transparency + */ + fun ripple(color: Int, startX: Float = 0f, startY: Float = 0f, duration: Long = 600L, fade: Boolean = Color.alpha(color) != 255) { val w = width.toFloat() val h = height.toFloat() val x = when (startX) { - MIDDLE -> w/2 + MIDDLE -> w / 2 END -> w else -> startX } val y = when (startY) { - MIDDLE -> h/2 + MIDDLE -> h / 2 END -> h else -> startY } @@ -88,7 +94,7 @@ class RippleCanvas @JvmOverloads constructor( val ripple = Ripple(color, x, y, 0f, maxRadius, fade) ripples.add(ripple) val animator = ValueAnimator.ofFloat(0f, maxRadius) - animator.duration = duration.toLong() + animator.duration = duration animator.addUpdateListener { animation -> ripple.radius = animation.animatedValue as Float invalidate() @@ -96,12 +102,29 @@ class RippleCanvas @JvmOverloads constructor( animator.start() } + /** + * Sets a color directly; clears ripple queue if it exists + */ fun set(color: Int) { baseColor = color ripples.clear() invalidate() } + /** + * Sets a color directly but with a transition + */ + fun fade(color: Int, duration: Long = 300L) { + ripples.clear() + val animator = ValueAnimator.ofObject(ArgbEvaluator(), baseColor, color) + animator.duration = duration + animator.addUpdateListener { animation -> + baseColor = animation.animatedValue as Int + invalidate() + } + animator.start() + } + internal class Ripple(val color: Int, val x: Float, val y: Float, |