aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-11-12 02:48:36 -0500
committerGitHub <noreply@github.com>2017-11-12 02:48:36 -0500
commit2b51bc4bfa86863ed14b550fe3281840587ab038 (patch)
tree0fd7276e326ed0901b1af980d07d57f3bbb7d7eb /app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt
parentec7fdc2521463d0a773bb9d0be454f3b2a60eee3 (diff)
downloadfrost-2b51bc4bfa86863ed14b550fe3281840587ab038.tar.gz
frost-2b51bc4bfa86863ed14b550fe3281840587ab038.tar.bz2
frost-2b51bc4bfa86863ed14b550fe3281840587ab038.zip
enhancement/video-player (#480)v1.6.3
* Add toolbar visibility toggle and draw it over viewer * Set contract bindings once available * Fix video url param error and prepare progressanimator * Add gif support and better transitions * Interface a lot of things * Reorder back press * Clean up files and fix selector * Add gif support * Redraw bounds when necessary
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt70
1 files changed, 70 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt
new file mode 100644
index 00000000..da852e6e
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt
@@ -0,0 +1,70 @@
+package com.pitchedapps.frost.utils
+
+import android.animation.Animator
+import android.animation.AnimatorListenerAdapter
+import android.animation.ValueAnimator
+import android.view.animation.Interpolator
+
+/**
+ * Created by Allan Wang on 2017-11-10.
+ */
+class ProgressAnimator private constructor(private vararg val values: Float) {
+
+ companion object {
+ inline fun ofFloat(crossinline builder: ProgressAnimator.() -> Unit) = ofFloat(0f, 1f) { builder() }
+
+ fun ofFloat(vararg values: Float, builder: ProgressAnimator.() -> Unit) = ProgressAnimator(*values).apply {
+ builder()
+ build()
+ }
+ }
+
+ private val animators: MutableList<(Float) -> Unit> = mutableListOf()
+ private val startActions: MutableList<() -> Unit> = mutableListOf()
+ private val endActions: MutableList<() -> Unit> = mutableListOf()
+
+ var duration: Long = -1L
+ var interpolator: Interpolator? = null
+
+ /**
+ * Add more changes to the [ValueAnimator] before running
+ */
+ var extraConfigs: ValueAnimator.() -> Unit = {}
+
+ fun withAnimator(from: Float, to: Float, animator: (Float) -> Unit) = animators.add {
+ val range = to - from
+ animator(range * it + from)
+ }
+
+ fun withAnimator(animator: (Float) -> Unit) = animators.add(animator)
+
+ fun withAnimatorInv(animator: (Float) -> Unit) = animators.add { animator(1f - it) }
+
+ fun withStartAction(action: () -> Unit) = startActions.add(action)
+
+ fun withEndAction(action: () -> Unit) = endActions.add(action)
+
+ fun build() {
+ ValueAnimator.ofFloat(*values).apply {
+ if (this@ProgressAnimator.duration > 0L)
+ duration = this@ProgressAnimator.duration
+ if (this@ProgressAnimator.interpolator != null)
+ interpolator = this@ProgressAnimator.interpolator
+ addUpdateListener {
+ val progress = it.animatedValue as Float
+ animators.forEach { it(progress) }
+ }
+ addListener(object : AnimatorListenerAdapter() {
+ override fun onAnimationStart(animation: Animator?) {
+ startActions.forEach { it() }
+ }
+
+ override fun onAnimationEnd(animation: Animator?) {
+ endActions.forEach { it() }
+ }
+ })
+ extraConfigs()
+ start()
+ }
+ }
+} \ No newline at end of file