From ecb83e9408685e267cc3b1165ecd68eba823a95b Mon Sep 17 00:00:00 2001 From: Rajnish23 Date: Tue, 29 Oct 2019 12:12:51 +0300 Subject: [PATCH 1/2] Fixed FancyShowCaseView not hiding for CUSTOM VIEW --- .../fancyshowcasesample/MainActivity.kt | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt b/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt index a45270a..e8cfe4d 100644 --- a/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt +++ b/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt @@ -21,6 +21,7 @@ import android.graphics.Color import android.os.Bundle import android.text.Html import android.text.Spanned +import android.util.Log import android.util.TypedValue import android.view.Gravity import android.view.Menu @@ -251,27 +252,33 @@ class MainActivity : BaseActivity() { //Shows a FancyShowCaseView view custom view inflation btn_custom_view.setOnClickListener { - mFancyShowCaseView = FancyShowCaseView.Builder(this) - .focusOn(it) - .enableTouchOnFocusedView(true) - .customView(R.layout.layout_my_custom_view_arrow, object : OnViewInflateListener { - override fun onViewInflated(view: View) { - val image = (view as RelativeLayout).findViewById(R.id.iv_custom_view) - val params = image.layoutParams as RelativeLayout.LayoutParams - val calculator = mFancyShowCaseView!!.focusCalculator!! - - image.post { - params.leftMargin = calculator.circleCenterX - image.width / 2 - params.topMargin = calculator.circleCenterY - calculator.focusHeight - image.height - image.layoutParams = params + if(FancyShowCaseView.isVisible(this)){ + FancyShowCaseView.hideCurrent(this); + } + else { + mFancyShowCaseView = FancyShowCaseView.Builder(this) + .focusOn(it) + .enableTouchOnFocusedView(true) + .customView(R.layout.layout_my_custom_view_arrow, object : OnViewInflateListener { + override fun onViewInflated(view: View) { + val image = (view as RelativeLayout).findViewById(R.id.iv_custom_view) + val params = image.layoutParams as RelativeLayout.LayoutParams + val calculator = mFancyShowCaseView!!.focusCalculator!! + + image.post { + params.leftMargin = calculator.circleCenterX - image.width / 2 + params.topMargin = calculator.circleCenterY - calculator.focusHeight - image.height + image.layoutParams = params + } + + view.findViewById(R.id.btn_action_1).setOnClickListener(mClickListener) } + }) + .closeOnTouch(false) + .build() - view.findViewById(R.id.btn_action_1).setOnClickListener(mClickListener) - } - }) - .closeOnTouch(false) - .build() - mFancyShowCaseView?.show() + mFancyShowCaseView?.show() + } } From 081937a714cd6a6beeba3c243b314453cd21b41e Mon Sep 17 00:00:00 2001 From: Rajnish23 Date: Mon, 4 Nov 2019 11:20:13 +0300 Subject: [PATCH 2/2] Fixed FancyImageView added multiple times --- .../fancyshowcasesample/MainActivity.kt | 63 ++++++++----------- .../toptas/fancyshowcase/FancyShowCaseView.kt | 3 + 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt b/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt index e8cfe4d..584f5b8 100644 --- a/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt +++ b/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.kt @@ -125,25 +125,21 @@ class MainActivity : BaseActivity() { //Shows a FancyShowCaseView that focus on a view btn_focus_dismiss_on_focus_area.setOnClickListener { - if (FancyShowCaseView.isVisible(this)) { - Toast.makeText(this, "Clickable button", Toast.LENGTH_SHORT).show() - FancyShowCaseView.hideCurrent(this) - } else { - FancyShowCaseView.Builder(this) + Toast.makeText(this, "Clickable button", Toast.LENGTH_SHORT).show() + + FancyShowCaseView.Builder(this) .focusOn(findViewById(R.id.btn_focus_dismiss_on_focus_area)) .enableTouchOnFocusedView(true) .title("Focus on View \n(dismiss on focus area)") .build() .show() - } + } //Shows a FancyShowCaseView with rounded rect focus shape btn_rounded_rect_dismiss_on_focus_area.setOnClickListener { - if (FancyShowCaseView.isVisible(this)) { - Toast.makeText(this, "Clickable button", Toast.LENGTH_SHORT).show() - FancyShowCaseView.hideCurrent(this) - } else { + Toast.makeText(this, "Clickable button", Toast.LENGTH_SHORT).show() + FancyShowCaseView.Builder(this) .focusOn(it) .focusShape(FocusShape.ROUNDED_RECTANGLE) @@ -152,7 +148,7 @@ class MainActivity : BaseActivity() { .title("Focus on View \n(dismiss on focus area)") .build() .show() - } + } //Shows FancyShowCaseView with focusCircleRadiusFactor 1.5 and title gravity @@ -252,33 +248,28 @@ class MainActivity : BaseActivity() { //Shows a FancyShowCaseView view custom view inflation btn_custom_view.setOnClickListener { - if(FancyShowCaseView.isVisible(this)){ - FancyShowCaseView.hideCurrent(this); - } - else { - mFancyShowCaseView = FancyShowCaseView.Builder(this) - .focusOn(it) - .enableTouchOnFocusedView(true) - .customView(R.layout.layout_my_custom_view_arrow, object : OnViewInflateListener { - override fun onViewInflated(view: View) { - val image = (view as RelativeLayout).findViewById(R.id.iv_custom_view) - val params = image.layoutParams as RelativeLayout.LayoutParams - val calculator = mFancyShowCaseView!!.focusCalculator!! - - image.post { - params.leftMargin = calculator.circleCenterX - image.width / 2 - params.topMargin = calculator.circleCenterY - calculator.focusHeight - image.height - image.layoutParams = params - } - - view.findViewById(R.id.btn_action_1).setOnClickListener(mClickListener) + mFancyShowCaseView = FancyShowCaseView.Builder(this) + .focusOn(it) + .enableTouchOnFocusedView(true) + .customView(R.layout.layout_my_custom_view_arrow, object : OnViewInflateListener { + override fun onViewInflated(view: View) { + val image = (view as RelativeLayout).findViewById(R.id.iv_custom_view) + val params = image.layoutParams as RelativeLayout.LayoutParams + val calculator = mFancyShowCaseView!!.focusCalculator!! + + image.post { + params.leftMargin = calculator.circleCenterX - image.width / 2 + params.topMargin = calculator.circleCenterY - calculator.focusHeight - image.height + image.layoutParams = params } - }) - .closeOnTouch(false) - .build() - mFancyShowCaseView?.show() - } + view.findViewById(R.id.btn_action_1).setOnClickListener(mClickListener) + } + }) + .closeOnTouch(false) + .build() + + mFancyShowCaseView?.show() } diff --git a/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FancyShowCaseView.kt b/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FancyShowCaseView.kt index af65da7..67002c2 100644 --- a/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FancyShowCaseView.kt +++ b/fancyshowcaseview/src/main/java/me/toptas/fancyshowcase/FancyShowCaseView.kt @@ -902,6 +902,9 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri * @return [FancyShowCaseView] with given parameters */ fun build(): FancyShowCaseView { + if(isVisible(activity)){ + hideCurrent(activity) + } return FancyShowCaseView(activity, focusedView, clickableView, mId, mTitle, mSpannedTitle, mTitleGravity, mTitleStyle, mTitleSize, mTitleSizeUnit, focusCircleRadiusFactor, mBackgroundColor, mFocusBorderColor, mFocusBorderSize, mCustomViewRes, viewInflateListener, mEnterAnimation, mExitAnimation, mAnimationListener, mCloseOnTouch, mEnableTouchOnFocusedView, fitSystemWindows, mFocusShape, mDismissListener, mRoundRectRadius,