diff --git a/README.md b/README.md index 4435919..9191dc3 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,12 @@ Step 2. Add the dependency | Releases | ------------- | -| 1.0 | -| 1.0.1 | +| 2.0 | + +### Whats new in this version? +- Added Animation Listener +- Performance Improved + # Usages /** @@ -48,7 +52,24 @@ Step 2. Add the dependency /** * To show attention animation, call [animationXAttention] & pass the animation key */ - imageView.animationXAttention(Attention.ATTENTION_BOUNCE) + imageView.animationXAttention(Attention.ATTENTION_BOUNCE, duration = 500, listener = object : Animator.AnimatorListener{ + override fun onAnimationStart(p0: Animator?) { + TODO("Not yet implemented") + } + + override fun onAnimationEnd(p0: Animator?) { + TODO("Not yet implemented") + } + + override fun onAnimationCancel(p0: Animator?) { + TODO("Not yet implemented") + } + + override fun onAnimationRepeat(p0: Animator?) { + TODO("Not yet implemented") + } + + }) /** diff --git a/app/animationx/src/main/java/com/rommansabbir/animationx/AnimationXExtensions.kt b/app/animationx/src/main/java/com/rommansabbir/animationx/AnimationXExtensions.kt index ed5d41c..daec973 100644 --- a/app/animationx/src/main/java/com/rommansabbir/animationx/AnimationXExtensions.kt +++ b/app/animationx/src/main/java/com/rommansabbir/animationx/AnimationXExtensions.kt @@ -1,5 +1,6 @@ package com.rommansabbir.animationx +import android.animation.Animator import android.animation.AnimatorSet import android.view.View import com.rommansabbir.animationx.Attention.ATTENTION @@ -68,41 +69,75 @@ import com.rommansabbir.animationx.Zoom.ZOOM_OUT_RIGHT import com.rommansabbir.animationx.Zoom.ZOOM_OUT_UP -fun View.animationXAttention(animationKey: String, duration: Long = 1000) { - renderAnimation(ATTENTION, animationKey, duration) +fun View.animationXAttention( + animationKey: String, + duration: Long = 1000, + listener: Animator.AnimatorListener? = null +) { + renderAnimation(ATTENTION, animationKey, duration, listener) } -fun View.animationXBounce(animationKey: String, duration: Long = 1000) { - renderAnimation(BOUNCE, animationKey, duration) +fun View.animationXBounce( + animationKey: String, + duration: Long = 1000, + listener: Animator.AnimatorListener? = null +) { + renderAnimation(BOUNCE, animationKey, duration, listener) } -fun View.animationXFade(animationKey: String, duration: Long = 1000) { - renderAnimation(FADE, animationKey, duration) +fun View.animationXFade( + animationKey: String, + duration: Long = 1000, + listener: Animator.AnimatorListener? = null +) { + renderAnimation(FADE, animationKey, duration, listener) } -fun View.animationXFlip(animationKey: String, duration: Long = 1000) { - renderAnimation(FLIP, animationKey, duration) +fun View.animationXFlip( + animationKey: String, + duration: Long = 1000, + listener: Animator.AnimatorListener? = null +) { + renderAnimation(FLIP, animationKey, duration, listener) } -fun View.animationXRotate(animationKey: String, duration: Long = 1000) { - renderAnimation(ROTATE, animationKey, duration) +fun View.animationXRotate( + animationKey: String, + duration: Long = 1000, + listener: Animator.AnimatorListener? = null +) { + renderAnimation(ROTATE, animationKey, duration, listener) } -fun View.animationXSlide(animationKey: String, duration: Long = 1000) { - renderAnimation(SLIDE, animationKey, duration) +fun View.animationXSlide( + animationKey: String, + duration: Long = 1000, + listener: Animator.AnimatorListener? = null +) { + renderAnimation(SLIDE, animationKey, duration, listener) } -fun View.animationXZoom(animationKey: String, duration: Long = 1000) { - renderAnimation(ZOOM, animationKey, duration) +fun View.animationXZoom( + animationKey: String, + duration: Long = 1000, + listener: Animator.AnimatorListener? = null +) { + renderAnimation(ZOOM, animationKey, duration, listener) } -private fun View.renderAnimation(key: String, animationKey: String, duration: Long) { - AnimationX().setDuration(duration) +fun View.renderAnimation( + key: String, + animationKey: String, + duration: Long, + listener: Animator.AnimatorListener? = null +) { + val aniObject = AnimationX().setDuration(duration) .setAnimation(showAnimation(this, key, animationKey, AnimationX().getNewAnimatorSet())) - .start() + aniObject.getNewAnimatorSet().addListener(listener) + aniObject.start() } -fun showAnimation( +private fun showAnimation( view: View, key: String, animationKey: String, diff --git a/app/src/main/java/com/rommansabbir/animationxexample/MainActivity.kt b/app/src/main/java/com/rommansabbir/animationxexample/MainActivity.kt index cecd08e..8c0d73b 100644 --- a/app/src/main/java/com/rommansabbir/animationxexample/MainActivity.kt +++ b/app/src/main/java/com/rommansabbir/animationxexample/MainActivity.kt @@ -1,5 +1,6 @@ package com.rommansabbir.animationxexample +import android.animation.Animator import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.rommansabbir.animationx.* @@ -11,6 +12,7 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + /** * Animation can be applied to all views which extends [View] * Just call the extension function's according to your requirement @@ -22,7 +24,27 @@ class MainActivity : AppCompatActivity() { /** * To show attention animation, call [animationXAttention] & pass the animation key */ - imageView.animationXAttention(Attention.ATTENTION_BOUNCE) + imageView.animationXAttention( + Attention.ATTENTION_BOUNCE, + duration = 500, + listener = object : Animator.AnimatorListener { + override fun onAnimationStart(p0: Animator?) { + + } + + override fun onAnimationEnd(p0: Animator?) { + + } + + override fun onAnimationCancel(p0: Animator?) { + + } + + override fun onAnimationRepeat(p0: Animator?) { + + } + + }) } bounceBtn.setOnClickListener {