diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt | 24 | ||||
-rw-r--r-- | core/src/main/res-public/values/public.xml | 34 |
2 files changed, 38 insertions, 20 deletions
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 bb4cd88..f735f4d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt @@ -68,6 +68,11 @@ class ProgressAnimator private constructor() : ValueAnimator() { 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() } private val animators: MutableList<ProgressDisposableAction> = mutableListOf() @@ -85,7 +90,7 @@ class ProgressAnimator private constructor() : ValueAnimator() { /** * Converts an action to a disposable action */ - private fun ProgressAction.asDisposable(): ProgressDisposableAction = { this(it); false } + private fun <T> ((T) -> Unit).asDisposable(): (T) -> Boolean = { this(it); false } private fun ProgressRunnable.asDisposable(): ProgressDisposableRunnable = { this(); false } @@ -109,13 +114,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()) fun withDisposableAnimator(action: ProgressDisposableAction) = animators.add(action) @@ -127,6 +135,14 @@ class ProgressAnimator private constructor() : ValueAnimator() { } } + fun withDisposableAnimator(from: Int, to: Int, action: ProgressIntDisposableAction) { + if (to != from) { + animators.add { + action(progress(from, to, it)) + } + } + } + fun withRangeAnimator(min: Float, max: Float, start: Float, end: Float, progress: Float, action: ProgressAction) { if (min >= max) { throw IllegalArgumentException("Range animator must have min < max; currently min=$min, max=$max") @@ -185,5 +201,7 @@ class ProgressAnimator private constructor() : ValueAnimator() { private typealias ProgressAction = (Float) -> Unit private typealias ProgressDisposableAction = (Float) -> Boolean +private typealias ProgressIntAction = (Int) -> Unit +private typealias ProgressIntDisposableAction = (Int) -> Boolean private typealias ProgressRunnable = () -> Unit private typealias ProgressDisposableRunnable = () -> Boolean diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml index 9f8780e..a912019 100644 --- a/core/src/main/res-public/values/public.xml +++ b/core/src/main/res-public/values/public.xml @@ -1,20 +1,25 @@ <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_right' type='anim' /> + <public name='kau_slide_out_left' 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_transparent' type='drawable' /> - <public name='kau_selectable_white' type='drawable' /> - <public name='kau_shadow_overlay' type='color' /> + <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_activity_horizontal_margin' type='dimen' /> <public name='kau_activity_vertical_margin' type='dimen' /> <public name='kau_dialog_margin' type='dimen' /> @@ -99,6 +104,7 @@ <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' /> @@ -106,12 +112,6 @@ <public name='KauSlideInFadeOut' type='style' /> <public name='KauSlideInSlideOutRight' type='style' /> <public name='KauSlideInSlideOutBottom' type='style' /> - <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' /> + <public name='kau_transparent' type='drawable' /> + <public name='kau_selectable_white' type='drawable' /> </resources>
\ No newline at end of file |