diff options
author | Allan Wang <me@allanwang.ca> | 2020-01-19 21:37:19 -0800 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2020-01-19 21:37:19 -0800 |
commit | b7fd1c5c7e848d7cf12c49a1e9e319d4e11d0b5c (patch) | |
tree | 9726de18196a34db738e4561600cd1aa9ab1c162 | |
parent | d0963f367a23e6523af332e66afb1486cbf0f01b (diff) | |
download | kau-b7fd1c5c7e848d7cf12c49a1e9e319d4e11d0b5c.tar.gz kau-b7fd1c5c7e848d7cf12c49a1e9e319d4e11d0b5c.tar.bz2 kau-b7fd1c5c7e848d7cf12c49a1e9e319d4e11d0b5c.zip |
Format code
-rw-r--r-- | core-ui/src/main/res-public/values/public.xml | 6 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt | 103 | ||||
-rw-r--r-- | core/src/main/res-public/values/public.xml | 34 |
3 files changed, 80 insertions, 63 deletions
diff --git a/core-ui/src/main/res-public/values/public.xml b/core-ui/src/main/res-public/values/public.xml index f62ed25..c8c2e56 100644 --- a/core-ui/src/main/res-public/values/public.xml +++ b/core-ui/src/main/res-public/values/public.xml @@ -1,10 +1,10 @@ <resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task --> + <public name='kau_recycler_detached_background' type='layout' /> + <public name='kau_elastic_recycler_activity' type='layout' /> + <public name='kau_recycler_textslider' type='layout' /> <public name='Kau.Translucent' type='style' /> <public name='Kau.Translucent.NoAnimation' type='style' /> <public name='Kau.Translucent.SlideBottom' type='style' /> <public name='Kau.Translucent.SlideTop' type='style' /> - <public name='kau_recycler_detached_background' type='layout' /> - <public name='kau_elastic_recycler_activity' type='layout' /> - <public name='kau_recycler_textslider' type='layout' /> </resources>
\ No newline at end of file diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt index 04989d7..dad825e 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt @@ -33,46 +33,50 @@ class ProgressAnimator private constructor() : ValueAnimator() { companion object { - fun ofFloat(builder: ProgressAnimator.() -> Unit = {}): ProgressAnimator = ProgressAnimator().apply { - setFloatValues(0f, 1f) - addUpdateListener { apply(it.animatedValue as Float) } - addListener(object : AnimatorListenerAdapter() { - override fun onAnimationStart(animation: Animator?, isReverse: Boolean) { - isCancelled = false - startActions.runAll() - } - - override fun onAnimationCancel(animation: Animator?) { - isCancelled = true - cancelActions.runAll() - } - - override fun onAnimationEnd(animation: Animator?) { - endActions.runAll() - isCancelled = false - } - }) - }.apply(builder) + fun ofFloat(builder: ProgressAnimator.() -> Unit = {}): ProgressAnimator = + ProgressAnimator().apply { + setFloatValues(0f, 1f) + addUpdateListener { apply(it.animatedValue as Float) } + addListener(object : AnimatorListenerAdapter() { + override fun onAnimationStart(animation: Animator?, isReverse: Boolean) { + isCancelled = false + startActions.runAll() + } + + override fun onAnimationCancel(animation: Animator?) { + isCancelled = true + cancelActions.runAll() + } + + override fun onAnimationEnd(animation: Animator?) { + endActions.runAll() + isCancelled = false + } + }) + }.apply(builder) /** * Gets output of a linear function starting at [start] when [progress] is 0 and [end] when [progress] is 1 at point [progress]. */ - fun progress(start: Float, end: Float, progress: Float): Float = start + (end - start) * progress - - fun progress(start: Float, end: Float, progress: Float, min: Float, max: Float): Float = when { - min == max -> throw IllegalArgumentException("Progress range cannot be 0 (min == max == $min") - progress <= min -> start - progress >= max -> end - else -> { - val trueProgress = (progress - min) / (max - min) - start + (end - start) * trueProgress + fun progress(start: Float, end: Float, progress: Float): Float = + start + (end - start) * progress + + fun progress(start: Float, end: Float, progress: Float, min: Float, max: Float): Float = + when { + min == max -> throw IllegalArgumentException("Progress range cannot be 0 (min == max == $min") + progress <= min -> start + progress >= max -> end + else -> { + val trueProgress = (progress - min) / (max - min) + start + (end - start) * trueProgress + } } - } /** * Progress variant that takes in and returns int */ - fun progress(start: Int, end: Int, progress: Float): Int = (start + (end - start) * progress).toInt() + fun progress(start: Int, end: Int, progress: Float): Int = + (start + (end - start) * progress).toInt() } private val animators: MutableList<ProgressDisposableAction> = mutableListOf() @@ -114,16 +118,16 @@ class ProgressAnimator private constructor() : ValueAnimator() { } fun withAnimator(action: ProgressAction) = - withDisposableAnimator(action.asDisposable()) + withDisposableAnimator(action.asDisposable()) /** * Range animator. Multiples the range by the current float progress before emission */ fun withAnimator(from: Float, to: Float, action: ProgressAction) = - withDisposableAnimator(from, to, action.asDisposable()) + withDisposableAnimator(from, to, action.asDisposable()) fun withAnimator(from: Int, to: Int, action: ProgressIntAction) = - withDisposableAnimator(from, to, action.asDisposable()) + withDisposableAnimator(from, to, action.asDisposable()) fun withDisposableAnimator(action: ProgressDisposableAction) = animators.add(action) @@ -143,13 +147,19 @@ class ProgressAnimator private constructor() : ValueAnimator() { } } - fun withRangeAnimator(min: Float, max: Float, start: Float, end: Float, action: ProgressAction) { + fun withRangeAnimator( + min: Float, + max: Float, + start: Float, + end: Float, + action: ProgressAction + ) { require(min < max) { "Range animator must have min < max; currently min=$min, max=$max" } withDisposableAnimator { when { it > max -> { - action(end) // apply action in case frames were skipped - true + action(end) // apply action in case frames were skipped + true } it < min -> false else -> { @@ -160,14 +170,20 @@ class ProgressAnimator private constructor() : ValueAnimator() { } } - @Deprecated(level = DeprecationLevel.WARNING, - message = "Renamed to withPointAction", - replaceWith = ReplaceWith("withPointAction(point, action)")) - fun withPointAnimator(point: Float, action: ProgressAction) = withPointAction(point, isAscendingProgress = true, action = action) + @Deprecated( + level = DeprecationLevel.WARNING, + message = "Renamed to withPointAction", + replaceWith = ReplaceWith("withPointAction(point, action)") + ) + fun withPointAnimator(point: Float, action: ProgressAction) = + withPointAction(point, isAscendingProgress = true, action = action) fun withPointAction(point: Float, isAscendingProgress: Boolean = true, action: ProgressAction) { animators.add { - action.runIf((isAscendingProgress && (it >= point) || !isAscendingProgress && (it <= point)), it) + action.runIf( + (isAscendingProgress && (it >= point) || !isAscendingProgress && (it <= point)), + it + ) } } @@ -188,7 +204,8 @@ class ProgressAnimator private constructor() : ValueAnimator() { fun withDisposableStartAction(action: ProgressDisposableRunnable) = startActions.add(action) - fun withCancelAction(action: ProgressRunnable) = withDisposableCancelAction(action.asDisposable()) + fun withCancelAction(action: ProgressRunnable) = + withDisposableCancelAction(action.asDisposable()) fun withDisposableCancelAction(action: ProgressDisposableRunnable) = cancelActions.add(action) diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml index a912019..9f8780e 100644 --- a/core/src/main/res-public/values/public.xml +++ b/core/src/main/res-public/values/public.xml @@ -1,25 +1,20 @@ <resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task --> + <public name='kau_slide_in_top' type='anim' /> <public name='kau_slide_in_left' type='anim' /> - <public name='kau_slide_out_left' type='anim' /> + <public name='kau_slide_out_right' type='anim' /> <public name='kau_slide_out_right_top' type='anim' /> + <public name='kau_fade_in' type='anim' /> + <public name='kau_slide_out_top' type='anim' /> + <public name='kau_slide_out_bottom' type='anim' /> <public name='kau_fade_out' type='anim' /> + <public name='kau_slide_out_left' type='anim' /> <public name='kau_slide_out_left_top' type='anim' /> - <public name='kau_fade_in' type='anim' /> <public name='kau_slide_in_bottom' type='anim' /> <public name='kau_slide_in_right' type='anim' /> - <public name='kau_slide_in_top' type='anim' /> - <public name='kau_slide_out_top' type='anim' /> - <public name='kau_slide_out_bottom' type='anim' /> - <public name='kau_slide_out_right' type='anim' /> - <public name='kau_enter_slide_right' type='transition' /> - <public name='kau_exit_slide_right' type='transition' /> - <public name='kau_exit_slide_top' type='transition' /> - <public name='kau_enter_slide_bottom' type='transition' /> - <public name='kau_enter_slide_left' type='transition' /> - <public name='kau_exit_slide_left' type='transition' /> - <public name='kau_enter_slide_top' type='transition' /> - <public name='kau_exit_slide_bottom' type='transition' /> + <public name='kau_transparent' type='drawable' /> + <public name='kau_selectable_white' type='drawable' /> + <public name='kau_shadow_overlay' type='color' /> <public name='kau_activity_horizontal_margin' type='dimen' /> <public name='kau_activity_vertical_margin' type='dimen' /> <public name='kau_dialog_margin' type='dimen' /> @@ -104,7 +99,6 @@ <public name='kau_bullet_point' type='string' /> <public name='Kau' type='style' /> <public name='Kau.Translucent' type='style' /> - <public name='kau_shadow_overlay' type='color' /> <public name='KauFadeIn' type='style' /> <public name='KauFadeInFadeOut' type='style' /> <public name='KauSlideInRight' type='style' /> @@ -112,6 +106,12 @@ <public name='KauSlideInFadeOut' type='style' /> <public name='KauSlideInSlideOutRight' type='style' /> <public name='KauSlideInSlideOutBottom' type='style' /> - <public name='kau_transparent' type='drawable' /> - <public name='kau_selectable_white' type='drawable' /> + <public name='kau_enter_slide_bottom' type='transition' /> + <public name='kau_enter_slide_top' type='transition' /> + <public name='kau_exit_slide_bottom' type='transition' /> + <public name='kau_exit_slide_top' type='transition' /> + <public name='kau_enter_slide_right' type='transition' /> + <public name='kau_exit_slide_right' type='transition' /> + <public name='kau_exit_slide_left' type='transition' /> + <public name='kau_enter_slide_left' type='transition' /> </resources>
\ No newline at end of file |