Skip to content

Commit

Permalink
Add support to disable enter/exit animations #154
Browse files Browse the repository at this point in the history
  • Loading branch information
faruktoptas committed Aug 6, 2019
1 parent 0a7a4b8 commit fe5085e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 81 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ An easy-to-use customizable show case view with circular reveal animation.

## Download
```gradle
implementation 'me.toptas.fancyshowcase:fancyshowcaseview:1.2.0'
implementation 'me.toptas.fancyshowcase:fancyshowcaseview:1.2.1'
```

## Download (For non-androidx projects)
Expand Down
29 changes: 27 additions & 2 deletions app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,36 @@ import android.os.Bundle
import android.text.Html
import android.text.Spanned
import android.util.TypedValue
import android.view.*
import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main.btn_anim
import kotlinx.android.synthetic.main.activity_main.btn_another_activity
import kotlinx.android.synthetic.main.activity_main.btn_background_color
import kotlinx.android.synthetic.main.activity_main.btn_border_color
import kotlinx.android.synthetic.main.activity_main.btn_custom_queue
import kotlinx.android.synthetic.main.activity_main.btn_custom_view
import kotlinx.android.synthetic.main.activity_main.btn_custom_view2
import kotlinx.android.synthetic.main.activity_main.btn_focus
import kotlinx.android.synthetic.main.activity_main.btn_focus2
import kotlinx.android.synthetic.main.activity_main.btn_focus_delay
import kotlinx.android.synthetic.main.activity_main.btn_focus_dismiss_on_focus_area
import kotlinx.android.synthetic.main.activity_main.btn_focus_rect_color
import kotlinx.android.synthetic.main.activity_main.btn_no_anim
import kotlinx.android.synthetic.main.activity_main.btn_queue
import kotlinx.android.synthetic.main.activity_main.btn_rect_position
import kotlinx.android.synthetic.main.activity_main.btn_recycler_view
import kotlinx.android.synthetic.main.activity_main.btn_rounded_rect
import kotlinx.android.synthetic.main.activity_main.btn_rounded_rect_dismiss_on_focus_area
import kotlinx.android.synthetic.main.activity_main.btn_simple
import kotlinx.android.synthetic.main.activity_main.btn_spanned
import kotlinx.android.synthetic.main.activity_main.btn_title_size
import me.toptas.fancyshowcase.FancyShowCaseView
import me.toptas.fancyshowcase.FocusShape
import me.toptas.fancyshowcase.listener.DismissListener
Expand Down Expand Up @@ -70,6 +93,8 @@ class MainActivity : BaseActivity() {
FancyShowCaseView.Builder(this)
.focusOn(it)
.title(spanned)
.enterAnimation(null)
.exitAnimation(null)
.enableAutoTextPosition()
.build()
.show()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.toptas.fancyshowcase

import android.view.animation.AlphaAnimation

internal class FadeInAnimation : AlphaAnimation(0f, 1f) {
init {
fillAfter = true
duration = 400
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.toptas.fancyshowcase

import android.view.animation.AlphaAnimation

internal class FadeOutAnimation : AlphaAnimation(1f, 0f) {
init {
fillAfter = true
duration = 400
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ import android.os.Build
import android.text.Spanned
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.view.*
import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
import android.view.ViewAnimationUtils
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.FrameLayout
Expand Down Expand Up @@ -314,7 +319,7 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
if (mFocusBorderColor != 0 && mFocusBorderSize > 0) {
setBorderParameters(mFocusBorderColor, mFocusBorderSize)
}
if (mRoundRectRadius > 0) {
if (mRoundRectRadius >= 0) {
roundRectRadius = mRoundRectRadius
}
addView(this)
Expand Down Expand Up @@ -392,23 +397,11 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
* Starts enter animation of FancyShowCaseView
*/
private fun startEnterAnimation() {
when {
mEnterAnimation != null -> startAnimation(mEnterAnimation)
shouldShowCircularAnimation() -> doCircularEnterAnimation()
else -> {
val fadeInAnimation = AnimationUtils.loadAnimation(activity, R.anim.fscv_fade_in)
fadeInAnimation.fillAfter = true
fadeInAnimation.setAnimationListener(object : Animation.AnimationListener {

override fun onAnimationEnd(animation: Animation) {
mAnimationListener?.onEnterAnimationEnd()
}

override fun onAnimationRepeat(p0: Animation?) {}

override fun onAnimationStart(p0: Animation?) {}
})
startAnimation(fadeInAnimation)
if (mEnterAnimation != null) {
if (mEnterAnimation is FadeInAnimation && shouldShowCircularAnimation()) {
doCircularEnterAnimation()
} else {
startAnimation(mEnterAnimation)
}
}
}
Expand All @@ -417,24 +410,27 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
* Hides FancyShowCaseView with animation
*/
fun hide() {
when {
mExitAnimation != null -> startAnimation(mExitAnimation)
shouldShowCircularAnimation() -> doCircularExitAnimation()
else -> {
val fadeOut = AnimationUtils.loadAnimation(activity, R.anim.fscv_fade_out)
fadeOut.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationEnd(animation: Animation) {
if (mExitAnimation != null) {
if (mExitAnimation is FadeOutAnimation && shouldShowCircularAnimation()) {
doCircularExitAnimation()
} else {
mExitAnimation?.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationRepeat(animation: Animation?) {

}

override fun onAnimationEnd(animation: Animation?) {
removeView()
mAnimationListener?.onExitAnimationEnd()
}

override fun onAnimationRepeat(p0: Animation?) {}

override fun onAnimationStart(p0: Animation?) {}
override fun onAnimationStart(animation: Animation?) {
}
})
fadeOut.fillAfter = true
startAnimation(fadeOut)
startAnimation(mExitAnimation)
}
} else {
removeView()
}
}

Expand Down Expand Up @@ -611,8 +607,8 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
private var mCustomViewRes: Int = 0
private var mRoundRectRadius: Int = 0
private var viewInflateListener: OnViewInflateListener? = null
private var mEnterAnimation: Animation? = null
private var mExitAnimation: Animation? = null
private var mEnterAnimation: Animation? = FadeInAnimation()
private var mExitAnimation: Animation? = FadeOutAnimation()
private var mAnimationListener: AnimationListener? = null
private var mCloseOnTouch = true
private var mEnableTouchOnFocusedView: Boolean = false
Expand Down Expand Up @@ -763,7 +759,7 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
* @param enterAnimation enter animation for FancyShowCaseView
* @return Builder
*/
fun enterAnimation(enterAnimation: Animation): Builder {
fun enterAnimation(enterAnimation: Animation?): Builder {
mEnterAnimation = enterAnimation
return this
}
Expand All @@ -783,7 +779,7 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
* @param exitAnimation exit animation for FancyShowCaseView
* @return Builder
*/
fun exitAnimation(exitAnimation: Animation): Builder {
fun exitAnimation(exitAnimation: Animation?): Builder {
mExitAnimation = exitAnimation
return this
}
Expand Down
21 changes: 0 additions & 21 deletions fancyshowcaseview/src/main/res/anim/fscv_fade_in.xml

This file was deleted.

21 changes: 0 additions & 21 deletions fancyshowcaseview/src/main/res/anim/fscv_fade_out.xml

This file was deleted.

2 changes: 1 addition & 1 deletion versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
ext.compile_sdk_version = 28
ext.min_sdk_version = 14
ext.target_sdk_version = 28
ext.version_name = '1.2.0'
ext.version_name = '1.2.1'
ext.appcompat = '1.0.2'
ext.material = '1.0.0'
}

0 comments on commit fe5085e

Please sign in to comment.