|
@@ -72,88 +72,141 @@ class AnimationUtil private constructor() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 隐藏buttons控件,从控件顶部往底部回收隐藏
|
|
|
+ * 显示buttons控件,从控件底部往控件顶部扩展显示
|
|
|
*
|
|
|
* @param view
|
|
|
*/
|
|
|
- fun hideViewFromTopToBottom(view: View?, duration: Long = 300) {
|
|
|
- if (showBottomToTop != null && showBottomToTop!!.isRunning())
|
|
|
- return;
|
|
|
+ fun showViewFromBottomToTop(view: View?, duration: Long = 300) {
|
|
|
+ if (showBottomToTop != null && showBottomToTop!!.isRunning) {
|
|
|
+ if (showBottomToTop?.target == view) {
|
|
|
+ showBottomToTop?.cancel()
|
|
|
+ showBottomToTop = null
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (view != null && view.visibility == View.VISIBLE) {
|
|
|
- val pvhA = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0f)
|
|
|
- val pvhY = PropertyValuesHolder.ofFloat("Y", view.top.toFloat(), view.top.toFloat() + view.height)
|
|
|
+ if (view != null) {
|
|
|
+ val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 1.0f)
|
|
|
+ val pvhY = PropertyValuesHolder.ofFloat("Y", Math.max(view.y, view.top.toFloat() + view.height), view.top.toFloat())
|
|
|
showBottomToTop = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhY)
|
|
|
- showBottomToTop!!.interpolator = AccelerateInterpolator()
|
|
|
- showBottomToTop!!.addListener(object : AnimatorListenerAdapter() {
|
|
|
- override fun onAnimationEnd(animation: Animator) {
|
|
|
- super.onAnimationEnd(animation)
|
|
|
- Handler(Looper.getMainLooper()).post { view.visibility = View.INVISIBLE }
|
|
|
- }
|
|
|
- })
|
|
|
- showBottomToTop!!.setDuration(duration).start()
|
|
|
+ showBottomToTop?.apply {
|
|
|
+ interpolator = AccelerateInterpolator()
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationStart(animation: Animator) {
|
|
|
+ super.onAnimationStart(animation)
|
|
|
+ view.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAnimationCancel(animation: Animator?) {
|
|
|
+ super.onAnimationCancel(animation)
|
|
|
+ animation?.removeAllListeners()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setDuration(duration).start()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 显示buttons控件,从控件底部往控件顶部扩展显示
|
|
|
+ * 隐藏buttons控件,从控件顶部往底部回收隐藏
|
|
|
*
|
|
|
* @param view
|
|
|
*/
|
|
|
- fun showViewFromBottomToTop(view: View?, duration: Long = 300) {
|
|
|
- if (showBottomToTop != null && showBottomToTop!!.isRunning())
|
|
|
- return;
|
|
|
+ fun hideViewFromTopToBottom(view: View?, duration: Long = 300) {
|
|
|
+ if (showBottomToTop != null && showBottomToTop!!.isRunning) {
|
|
|
+ if (showBottomToTop?.target == view) {
|
|
|
+ showBottomToTop?.cancel()
|
|
|
+ showBottomToTop = null
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (view != null && view.visibility != View.VISIBLE) {
|
|
|
- val pvhA = PropertyValuesHolder.ofFloat("alpha", 0f, 1.0f)
|
|
|
- val pvhY = PropertyValuesHolder.ofFloat("Y", view.top.toFloat() + view.height, view.top.toFloat())
|
|
|
+ if (view != null) {
|
|
|
+ val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 0f)
|
|
|
+ val pvhY = PropertyValuesHolder.ofFloat("Y", Math.min(view.y, view.top.toFloat()), view.top.toFloat() + view.height)
|
|
|
showBottomToTop = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhY)
|
|
|
- showBottomToTop!!.interpolator = AccelerateInterpolator()
|
|
|
- showBottomToTop!!.addListener(object : AnimatorListenerAdapter() {
|
|
|
- override fun onAnimationStart(animation: Animator) {
|
|
|
- super.onAnimationStart(animation)
|
|
|
- view.visibility = View.VISIBLE
|
|
|
- }
|
|
|
- })
|
|
|
- showBottomToTop!!.setDuration(duration).start()
|
|
|
+ showBottomToTop = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhY)
|
|
|
+ showBottomToTop?.apply {
|
|
|
+ interpolator = AccelerateInterpolator()
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationEnd(animation: Animator) {
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
+ view.visibility = View.INVISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAnimationCancel(animation: Animator?) {
|
|
|
+ super.onAnimationCancel(animation)
|
|
|
+ animation?.removeAllListeners()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setDuration(duration).start()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fun showViewFromRightToLeft(view: View?, duration: Long = 300) {
|
|
|
- if (showRightToLeft != null && showRightToLeft!!.isRunning)
|
|
|
- return
|
|
|
+ if (showRightToLeft != null && showRightToLeft!!.isRunning) {
|
|
|
+ if (showRightToLeft?.target == view) {
|
|
|
+ showRightToLeft?.cancel()
|
|
|
+ showRightToLeft = null
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (view != null && view.visibility != View.VISIBLE) {
|
|
|
- val pvhA = PropertyValuesHolder.ofFloat("alpha", 0f, 1.0f)
|
|
|
- val pvhX = PropertyValuesHolder.ofFloat("X", view.left.toFloat() + view.width, view.left.toFloat())
|
|
|
+ if (view != null) {
|
|
|
+ val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 1.0f)
|
|
|
+ val pvhX = PropertyValuesHolder.ofFloat("X", Math.min(view.x, view.left.toFloat() + view.width), view.left.toFloat())
|
|
|
showRightToLeft = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhX)
|
|
|
- showRightToLeft!!.interpolator = AccelerateInterpolator()
|
|
|
- showRightToLeft!!.addListener(object : AnimatorListenerAdapter() {
|
|
|
- override fun onAnimationStart(animation: Animator) {
|
|
|
- super.onAnimationStart(animation)
|
|
|
- view.visibility = View.VISIBLE
|
|
|
- }
|
|
|
- })
|
|
|
- showRightToLeft!!.setDuration(duration).start()
|
|
|
+ showRightToLeft?.apply {
|
|
|
+ interpolator = AccelerateInterpolator()
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationStart(animation: Animator) {
|
|
|
+ super.onAnimationStart(animation)
|
|
|
+ view.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAnimationCancel(animation: Animator?) {
|
|
|
+ super.onAnimationCancel(animation)
|
|
|
+ animation?.removeAllListeners()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setDuration(duration).start()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fun hideViewFromLeftToRight(view: View?, duration: Long = 300) {
|
|
|
- if (showRightToLeft != null && showRightToLeft!!.isRunning)
|
|
|
- return
|
|
|
+ if (showRightToLeft != null && showRightToLeft!!.isRunning) {
|
|
|
+ if (showRightToLeft?.target == view) {
|
|
|
+ showRightToLeft?.cancel()
|
|
|
+ showRightToLeft = null
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (view != null && view.visibility == View.VISIBLE) {
|
|
|
- val pvhA = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0f)
|
|
|
- val pvhX = PropertyValuesHolder.ofFloat("X", view.left.toFloat(), view.left.toFloat() + view.width)
|
|
|
+ if (view != null) {
|
|
|
+ val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 0f)
|
|
|
+ val pvhX = PropertyValuesHolder.ofFloat("X", Math.max(view.x, view.left.toFloat()), view.left.toFloat() + view.width)
|
|
|
showRightToLeft = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhX)
|
|
|
- showRightToLeft!!.interpolator = AccelerateInterpolator()
|
|
|
- showRightToLeft!!.addListener(object : AnimatorListenerAdapter() {
|
|
|
- override fun onAnimationEnd(animation: Animator) {
|
|
|
- super.onAnimationEnd(animation)
|
|
|
- Handler(Looper.getMainLooper()).post { view.visibility = View.INVISIBLE }
|
|
|
- }
|
|
|
- })
|
|
|
- showRightToLeft!!.setDuration(duration).start()
|
|
|
+ showRightToLeft?.apply {
|
|
|
+ interpolator = AccelerateInterpolator()
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationEnd(animation: Animator) {
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
+ view.visibility = View.INVISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAnimationCancel(animation: Animator?) {
|
|
|
+ super.onAnimationCancel(animation)
|
|
|
+ animation?.removeAllListeners()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setDuration(duration).start()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -163,21 +216,34 @@ class AnimationUtil private constructor() {
|
|
|
* @param view
|
|
|
*/
|
|
|
fun showViewFromTopToBottom(view: View?, duration: Long = 300) {
|
|
|
- if (showTopToBottom != null && showTopToBottom!!.isRunning)
|
|
|
- return
|
|
|
+ if (showTopToBottom != null && showTopToBottom!!.isRunning) {
|
|
|
+ if (showTopToBottom?.target == view) {
|
|
|
+ showTopToBottom?.cancel()
|
|
|
+ showTopToBottom = null
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (view != null && view.visibility != View.VISIBLE) {
|
|
|
- val pvhA = PropertyValuesHolder.ofFloat("alpha", 0f, 1.0f)
|
|
|
- val pvhY = PropertyValuesHolder.ofFloat("Y", view.top.toFloat() - view.height, view.top.toFloat())
|
|
|
+ if (view != null) {
|
|
|
+ val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 1.0f)
|
|
|
+ val pvhY = PropertyValuesHolder.ofFloat("Y", Math.min(view.y, view.top.toFloat() + view.height), view.top.toFloat())
|
|
|
showTopToBottom = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhY)
|
|
|
- showTopToBottom!!.interpolator = AccelerateInterpolator()
|
|
|
- showTopToBottom!!.addListener(object : AnimatorListenerAdapter() {
|
|
|
- override fun onAnimationStart(animation: Animator) {
|
|
|
- super.onAnimationStart(animation)
|
|
|
- view.visibility = View.VISIBLE
|
|
|
- }
|
|
|
- })
|
|
|
- showTopToBottom!!.setDuration(duration).start()
|
|
|
+ showTopToBottom?.apply {
|
|
|
+ interpolator = AccelerateInterpolator()
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationStart(animation: Animator) {
|
|
|
+ super.onAnimationStart(animation)
|
|
|
+ view.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAnimationCancel(animation: Animator?) {
|
|
|
+ super.onAnimationCancel(animation)
|
|
|
+ animation?.removeAllListeners()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setDuration(duration).start()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -187,59 +253,98 @@ class AnimationUtil private constructor() {
|
|
|
* @param view
|
|
|
*/
|
|
|
fun hideViewFromBottomToTop(view: View?, duration: Long = 300) {
|
|
|
- if (showTopToBottom != null && showTopToBottom!!.isRunning)
|
|
|
- return
|
|
|
+ if (showTopToBottom != null && showTopToBottom!!.isRunning) {
|
|
|
+ if (showTopToBottom?.target == view) {
|
|
|
+ showTopToBottom?.cancel()
|
|
|
+ showTopToBottom = null
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (view != null && view.visibility == View.VISIBLE) {
|
|
|
- val pvhA = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0f)
|
|
|
- val pvhY = PropertyValuesHolder.ofFloat("Y", view.top.toFloat(), view.top.toFloat() - view.height)
|
|
|
+ if (view != null) {
|
|
|
+ val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 0f)
|
|
|
+ val pvhY = PropertyValuesHolder.ofFloat("Y", Math.max(view.y, view.top.toFloat()), view.top.toFloat() - view.height)
|
|
|
showTopToBottom = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhY)
|
|
|
- showTopToBottom!!.interpolator = AccelerateInterpolator()
|
|
|
- showTopToBottom!!.addListener(object : AnimatorListenerAdapter() {
|
|
|
- override fun onAnimationEnd(animation: Animator) {
|
|
|
- super.onAnimationEnd(animation)
|
|
|
- Handler(Looper.getMainLooper()).post { view.visibility = View.INVISIBLE }
|
|
|
- }
|
|
|
- })
|
|
|
- showTopToBottom!!.setDuration(duration).start()
|
|
|
+ showTopToBottom?.apply {
|
|
|
+ interpolator = AccelerateInterpolator()
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationEnd(animation: Animator) {
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
+ view.visibility = View.INVISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAnimationCancel(animation: Animator?) {
|
|
|
+ super.onAnimationCancel(animation)
|
|
|
+ animation?.removeAllListeners()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setDuration(duration).start()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fun showViewFromLeftToRight(view: View?, duration: Long = 300) {
|
|
|
- if (showLeftToRight != null && showLeftToRight!!.isRunning)
|
|
|
- return
|
|
|
+ if (showLeftToRight != null && showLeftToRight!!.isRunning) {
|
|
|
+ if (showLeftToRight?.target == view) {
|
|
|
+ showLeftToRight?.cancel()
|
|
|
+ showLeftToRight = null
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (view != null && view.visibility != View.VISIBLE) {
|
|
|
- val pvhA = PropertyValuesHolder.ofFloat("alpha", 0f, 1.0f)
|
|
|
- val pvhX = PropertyValuesHolder.ofFloat("X", view.left.toFloat() - view.width, view.left.toFloat())
|
|
|
+ if (view != null) {
|
|
|
+ val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 1.0f)
|
|
|
+ val pvhX = PropertyValuesHolder.ofFloat("X", Math.max(view.x, view.left.toFloat() - view.width), view.left.toFloat())
|
|
|
showLeftToRight = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhX)
|
|
|
- showLeftToRight!!.interpolator = AccelerateInterpolator()
|
|
|
- showLeftToRight!!.addListener(object : AnimatorListenerAdapter() {
|
|
|
- override fun onAnimationStart(animation: Animator) {
|
|
|
- super.onAnimationStart(animation)
|
|
|
- view.visibility = View.VISIBLE
|
|
|
- }
|
|
|
- })
|
|
|
- showLeftToRight!!.setDuration(duration).start()
|
|
|
+ showLeftToRight?.apply {
|
|
|
+ interpolator = AccelerateInterpolator()
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationStart(animation: Animator) {
|
|
|
+ super.onAnimationStart(animation)
|
|
|
+ view.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAnimationCancel(animation: Animator?) {
|
|
|
+ super.onAnimationCancel(animation)
|
|
|
+ animation?.removeAllListeners()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setDuration(duration).start()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fun hideViewFromRightToLeft(view: View?, duration: Long = 300) {
|
|
|
- if (showLeftToRight != null && showLeftToRight!!.isRunning)
|
|
|
- return
|
|
|
+ if (showLeftToRight != null && showLeftToRight!!.isRunning) {
|
|
|
+ if (showLeftToRight?.target == view) {
|
|
|
+ showLeftToRight?.cancel()
|
|
|
+ showLeftToRight = null
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (view != null && view.visibility == View.VISIBLE) {
|
|
|
- val pvhA = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0f)
|
|
|
- val pvhX = PropertyValuesHolder.ofFloat("X", view.left.toFloat(), view.left.toFloat() - view.width)
|
|
|
+ if (view != null) {
|
|
|
+ val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 0f)
|
|
|
+ val pvhX = PropertyValuesHolder.ofFloat("X", Math.min(view.x, view.left.toFloat()), view.left.toFloat() - view.width)
|
|
|
showLeftToRight = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhX)
|
|
|
- showLeftToRight!!.interpolator = AccelerateInterpolator()
|
|
|
- showLeftToRight!!.addListener(object : AnimatorListenerAdapter() {
|
|
|
- override fun onAnimationEnd(animation: Animator) {
|
|
|
- super.onAnimationEnd(animation)
|
|
|
- Handler(Looper.getMainLooper()).post { view.visibility = View.INVISIBLE }
|
|
|
- }
|
|
|
- })
|
|
|
- showLeftToRight!!.setDuration(duration).start()
|
|
|
+ showLeftToRight?.apply {
|
|
|
+ interpolator = AccelerateInterpolator()
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationEnd(animation: Animator) {
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
+ view.visibility = View.INVISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAnimationCancel(animation: Animator?) {
|
|
|
+ super.onAnimationCancel(animation)
|
|
|
+ animation?.removeAllListeners()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setDuration(duration).start()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -277,14 +382,10 @@ class AnimationUtil private constructor() {
|
|
|
* 结束该动画
|
|
|
*/
|
|
|
fun cancelAnimations() {
|
|
|
- if (showTopToBottom != null)
|
|
|
- showTopToBottom!!.cancel()
|
|
|
- if (showBottomToTop != null)
|
|
|
- showBottomToTop!!.cancel()
|
|
|
- if (showLeftToRight != null)
|
|
|
- showLeftToRight!!.cancel()
|
|
|
- if (showRightToLeft != null)
|
|
|
- showRightToLeft!!.cancel()
|
|
|
+ showTopToBottom?.cancel()
|
|
|
+ showBottomToTop?.cancel()
|
|
|
+ showLeftToRight?.cancel()
|
|
|
+ showRightToLeft?.cancel()
|
|
|
showTopToBottom = null
|
|
|
showBottomToTop = null
|
|
|
showRightToLeft = null
|