Skip to content

Commit

Permalink
- Added Animation Listener
Browse files Browse the repository at this point in the history
  • Loading branch information
rommansabbir committed May 23, 2021
1 parent d57d145 commit 56ede86
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 22 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand All @@ -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")
}

})


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 56ede86

Please sign in to comment.