aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-11 13:51:40 -0700
committerAllan Wang <me@allanwang.ca>2017-06-11 13:51:40 -0700
commit11090367b5783d33aae97637cb08360be9659ff9 (patch)
tree8bd2da584d97fb59d9f176dac75b2f42f8568e6d /library
parent3b7cd18459b5cbe5ff86ca3af9bddd9a222d3e67 (diff)
downloadkau-11090367b5783d33aae97637cb08360be9659ff9.tar.gz
kau-11090367b5783d33aae97637cb08360be9659ff9.tar.bz2
kau-11090367b5783d33aae97637cb08360be9659ff9.zip
Fix selection and add fade effect
Diffstat (limited to 'library')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt4
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/items/KPrefItemBase.kt4
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/views/RippleCanvas.kt31
-rw-r--r--library/src/main/res/layout/kau_preference.xml4
4 files changed, 34 insertions, 9 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,
diff --git a/library/src/main/res/layout/kau_preference.xml b/library/src/main/res/layout/kau_preference.xml
index 5123b27..4401145 100644
--- a/library/src/main/res/layout/kau_preference.xml
+++ b/library/src/main/res/layout/kau_preference.xml
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
+
+<!--due to animations, we need a wrapper viewgroup so our changes will stick-->
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
@@ -71,7 +74,6 @@
android:maxLines="10"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary"
- android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/kau_pref_inner_frame"
app:layout_constraintHorizontal_bias="0"