mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 16:40:32 +00:00
Merge pull request #6152 from Isira-Seneviratne/Use_Animator_addListener
Use Animator.addListener() extension.
This commit is contained in:
commit
72ee4be495
@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
package org.schabi.newpipe.ktx
|
package org.schabi.newpipe.ktx
|
||||||
|
|
||||||
import android.animation.Animator
|
|
||||||
import android.animation.AnimatorListenerAdapter
|
|
||||||
import android.animation.ArgbEvaluator
|
import android.animation.ArgbEvaluator
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.core.animation.addListener
|
||||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
|
|
||||||
@ -34,14 +33,6 @@ fun TextView.animateTextColor(duration: Long, @ColorInt colorStart: Int, @ColorI
|
|||||||
viewPropertyAnimator.interpolator = FastOutSlowInInterpolator()
|
viewPropertyAnimator.interpolator = FastOutSlowInInterpolator()
|
||||||
viewPropertyAnimator.duration = duration
|
viewPropertyAnimator.duration = duration
|
||||||
viewPropertyAnimator.addUpdateListener { setTextColor(it.animatedValue as Int) }
|
viewPropertyAnimator.addUpdateListener { setTextColor(it.animatedValue as Int) }
|
||||||
viewPropertyAnimator.addListener(object : AnimatorListenerAdapter() {
|
viewPropertyAnimator.addListener(onCancel = { setTextColor(colorEnd) }, onEnd = { setTextColor(colorEnd) })
|
||||||
override fun onAnimationEnd(animation: Animator) {
|
|
||||||
setTextColor(colorEnd)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAnimationCancel(animation: Animator) {
|
|
||||||
setTextColor(colorEnd)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
viewPropertyAnimator.start()
|
viewPropertyAnimator.start()
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import android.util.Log
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.FloatRange
|
import androidx.annotation.FloatRange
|
||||||
|
import androidx.core.animation.addListener
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
@ -106,15 +107,10 @@ fun View.animateBackgroundColor(duration: Long, @ColorInt colorStart: Int, @Colo
|
|||||||
viewPropertyAnimator.addUpdateListener { animation: ValueAnimator ->
|
viewPropertyAnimator.addUpdateListener { animation: ValueAnimator ->
|
||||||
backgroundTintListCompat = ColorStateList(empty, intArrayOf(animation.animatedValue as Int))
|
backgroundTintListCompat = ColorStateList(empty, intArrayOf(animation.animatedValue as Int))
|
||||||
}
|
}
|
||||||
viewPropertyAnimator.addListener(object : AnimatorListenerAdapter() {
|
viewPropertyAnimator.addListener(
|
||||||
override fun onAnimationEnd(animation: Animator) {
|
onCancel = { backgroundTintListCompat = ColorStateList(empty, intArrayOf(colorEnd)) },
|
||||||
backgroundTintListCompat = ColorStateList(empty, intArrayOf(colorEnd))
|
onEnd = { backgroundTintListCompat = ColorStateList(empty, intArrayOf(colorEnd)) }
|
||||||
}
|
)
|
||||||
|
|
||||||
override fun onAnimationCancel(animation: Animator) {
|
|
||||||
onAnimationEnd(animation)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
viewPropertyAnimator.start()
|
viewPropertyAnimator.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,17 +130,16 @@ fun View.animateHeight(duration: Long, targetHeight: Int): ValueAnimator {
|
|||||||
layoutParams.height = value.toInt()
|
layoutParams.height = value.toInt()
|
||||||
requestLayout()
|
requestLayout()
|
||||||
}
|
}
|
||||||
animator.addListener(object : AnimatorListenerAdapter() {
|
animator.addListener(
|
||||||
override fun onAnimationEnd(animation: Animator) {
|
onCancel = {
|
||||||
|
layoutParams.height = targetHeight
|
||||||
|
requestLayout()
|
||||||
|
},
|
||||||
|
onEnd = {
|
||||||
layoutParams.height = targetHeight
|
layoutParams.height = targetHeight
|
||||||
requestLayout()
|
requestLayout()
|
||||||
}
|
}
|
||||||
|
)
|
||||||
override fun onAnimationCancel(animation: Animator) {
|
|
||||||
layoutParams.height = targetHeight
|
|
||||||
requestLayout()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
animator.start()
|
animator.start()
|
||||||
return animator
|
return animator
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user