-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
68 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/yenaly/han1meviewer/util/Animations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.yenaly.han1meviewer.util | ||
|
||
import android.animation.ArgbEvaluator | ||
import android.animation.ValueAnimator | ||
import androidx.annotation.ColorInt | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
|
||
/** | ||
* Add an update listener to the [ValueAnimator] and remove it when the [LifecycleOwner] is destroyed. | ||
*/ | ||
fun ValueAnimator.addUpdateListener( | ||
lifecycle: Lifecycle?, | ||
listener: ValueAnimator.AnimatorUpdateListener?, | ||
) { | ||
addUpdateListener(listener) | ||
lifecycle?.addObserver(object : DefaultLifecycleObserver { | ||
override fun onDestroy(owner: LifecycleOwner) { | ||
this@addUpdateListener.removeAllUpdateListeners() | ||
} | ||
}) | ||
} | ||
|
||
fun colorTransition( | ||
@ColorInt fromColor: Int, | ||
@ColorInt toColor: Int, | ||
action: (ValueAnimator.() -> Unit)? = null, | ||
) { | ||
val colorAnimation: ValueAnimator = ValueAnimator.ofObject(ArgbEvaluator(), fromColor, toColor) | ||
action?.invoke(colorAnimation) | ||
|
||
colorAnimation.start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,6 @@ | ||
package com.yenaly.han1meviewer.util | ||
|
||
import android.animation.ArgbEvaluator | ||
import android.animation.ValueAnimator | ||
import android.content.res.ColorStateList | ||
import androidx.annotation.ColorInt | ||
|
||
fun colorTransition( | ||
@ColorInt fromColor: Int, | ||
@ColorInt toColor: Int, | ||
action: (ValueAnimator.() -> Unit)? = null, | ||
) { | ||
val colorAnimation: ValueAnimator = ValueAnimator.ofObject(ArgbEvaluator(), fromColor, toColor) | ||
action?.invoke(colorAnimation) | ||
|
||
colorAnimation.start() | ||
} | ||
|
||
fun @receiver:ColorInt Int.toColorStateList() = ColorStateList.valueOf(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters