diff --git a/README.md b/README.md index 6701642..77fcfc2 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt b/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt index dbc4a1d..a45270a 100644 --- a/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt +++ b/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt @@ -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 @@ -70,6 +93,8 @@ class MainActivity : BaseActivity() { FancyShowCaseView.Builder(this) .focusOn(it) .title(spanned) + .enterAnimation(null) + .exitAnimation(null) .enableAutoTextPosition() .build() .show() diff --git a/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FadeInAnimation.kt b/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FadeInAnimation.kt new file mode 100644 index 0000000..0bf1a09 --- /dev/null +++ b/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FadeInAnimation.kt @@ -0,0 +1,10 @@ +package me.toptas.fancyshowcase + +import android.view.animation.AlphaAnimation + +internal class FadeInAnimation : AlphaAnimation(0f, 1f) { + init { + fillAfter = true + duration = 400 + } +} \ No newline at end of file diff --git a/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FadeOutAnimation.kt b/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FadeOutAnimation.kt new file mode 100644 index 0000000..881352f --- /dev/null +++ b/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FadeOutAnimation.kt @@ -0,0 +1,10 @@ +package me.toptas.fancyshowcase + +import android.view.animation.AlphaAnimation + +internal class FadeOutAnimation : AlphaAnimation(1f, 0f) { + init { + fillAfter = true + duration = 400 + } +} \ No newline at end of file diff --git a/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FancyShowCaseView.kt b/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FancyShowCaseView.kt index 98e3928..af65da7 100644 --- a/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FancyShowCaseView.kt +++ b/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FancyShowCaseView.kt @@ -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 @@ -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) @@ -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) } } } @@ -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() } } @@ -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 @@ -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 } @@ -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 } diff --git a/fancyshowcaseview/src/main/res/anim/fscv_fade_in.xml b/fancyshowcaseview/src/main/res/anim/fscv_fade_in.xml deleted file mode 100644 index a248366..0000000 --- a/fancyshowcaseview/src/main/res/anim/fscv_fade_in.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - \ No newline at end of file diff --git a/fancyshowcaseview/src/main/res/anim/fscv_fade_out.xml b/fancyshowcaseview/src/main/res/anim/fscv_fade_out.xml deleted file mode 100644 index 6c83462..0000000 --- a/fancyshowcaseview/src/main/res/anim/fscv_fade_out.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - \ No newline at end of file diff --git a/versions.gradle b/versions.gradle index 5319a78..da9378f 100644 --- a/versions.gradle +++ b/versions.gradle @@ -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' } \ No newline at end of file