@@ -75,7 +75,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
7575 private val isLastOfSequence: Boolean = builder.mIsLastOfSequence!!
7676
7777 // References
78- private var foregroundLayoutWithBlur : RelativeLayout ? = null
78+ private var backgroundDimLayout : RelativeLayout ? = null
7979 private var bubbleMessageViewBuilder: BubbleMessageView .Builder ? = null
8080
8181 fun show (){
@@ -89,7 +89,8 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
8989 }
9090
9191 val rootView = getViewRoot(mActivity.get()!! )
92- foregroundLayoutWithBlur = getForegroundLayoutWithBlur()
92+ backgroundDimLayout = getBackgroundDimLayout()
93+ setBackgroundDimListener(backgroundDimLayout)
9394 bubbleMessageViewBuilder = getBubbleMessageViewBuilder()
9495
9596 if (mTargetView != null && mArrowPositionList.size <= 1 ) {
@@ -104,33 +105,37 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
104105 }
105106
106107 if (ScreenUtils .isVisibleOnScreen(target)) {
107- addTargetViewAtForegroundLayout (target, foregroundLayoutWithBlur )
108- addBubbleMessageViewDependingOnTargetView(target, bubbleMessageViewBuilder!! , foregroundLayoutWithBlur )
108+ addTargetViewAtBackgroundDimLayout (target, backgroundDimLayout )
109+ addBubbleMessageViewDependingOnTargetView(target, bubbleMessageViewBuilder!! , backgroundDimLayout )
109110 } else {
110111 dismiss()
111112 }
112113 }, DURATION_BACKGROUND_ANIMATION .toLong())
113114 } else {
114- addBubbleMessageViewOnScreenCenter(bubbleMessageViewBuilder!! , foregroundLayoutWithBlur )
115+ addBubbleMessageViewOnScreenCenter(bubbleMessageViewBuilder!! , backgroundDimLayout )
115116 }
116117 if (isFirstOfSequence){
117- // Add the foreground layout above the root view
118+ // Add the background dim layout above the root view
118119 val animation = AnimationUtils .getFadeInAnimation(0 , DURATION_BACKGROUND_ANIMATION )
119- foregroundLayoutWithBlur ?.let { rootView.addView(AnimationUtils .setAnimationToView(foregroundLayoutWithBlur !! , animation)) }
120+ backgroundDimLayout ?.let { rootView.addView(AnimationUtils .setAnimationToView(backgroundDimLayout !! , animation)) }
120121 }
121122 }
122123
123124 fun dismiss () {
124- notifyDismissToSequenceListener()
125- if (foregroundLayoutWithBlur != null && isLastOfSequence) {
126- // Remove foreground layout if the BubbleShowCase is the last of the sequence
127- val rootView = getViewRoot(mActivity.get()!! )
128- rootView.removeView(foregroundLayoutWithBlur)
129- foregroundLayoutWithBlur = null
125+ if (backgroundDimLayout != null && isLastOfSequence) {
126+ // Remove background dim layout if the BubbleShowCase is the last of the sequence
127+ finishSequence()
130128 } else {
131- // Remove all the views created over the foreground layout waiting for the next BubbleShowCsse in the sequence
132- foregroundLayoutWithBlur ?.removeAllViews()
129+ // Remove all the views created over the background dim layout waiting for the next BubbleShowCsse in the sequence
130+ backgroundDimLayout ?.removeAllViews()
133131 }
132+ notifyDismissToSequenceListener()
133+ }
134+
135+ fun finishSequence () {
136+ val rootView = getViewRoot(mActivity.get()!! )
137+ rootView.removeView(backgroundDimLayout)
138+ backgroundDimLayout = null
134139 }
135140
136141 private fun notifyDismissToSequenceListener (){
@@ -142,7 +147,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
142147 return androidContent.parent.parent as ViewGroup
143148 }
144149
145- private fun getForegroundLayoutWithBlur (): RelativeLayout {
150+ private fun getBackgroundDimLayout (): RelativeLayout {
146151 if (mActivity.get()!! .findViewById<RelativeLayout >(FOREGROUND_LAYOUT_ID ) != null )
147152 return mActivity.get()!! .findViewById(FOREGROUND_LAYOUT_ID )
148153 val backgroundLayout = RelativeLayout (mActivity.get()!! )
@@ -153,6 +158,10 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
153158 return backgroundLayout
154159 }
155160
161+ private fun setBackgroundDimListener (backgroundDimLayout : RelativeLayout ? ){
162+ backgroundDimLayout?.setOnClickListener { mBubbleShowCaseListener?.onBackgroundDimClick(this ) }
163+ }
164+
156165 private fun getBubbleMessageViewBuilder (): BubbleMessageView .Builder {
157166 return BubbleMessageView .Builder ()
158167 .from(mActivity.get()!! )
@@ -166,10 +175,14 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
166175 .image(mImage)
167176 .closeActionImage(mCloseAction)
168177 .disableCloseAction(mDisableCloseAction)
169- .listener(object : OnDismissBubbleMessageViewListener {
170- override fun onDismiss () {
178+ .listener(object : OnBubbleMessageViewListener {
179+ override fun onBubbleClick () {
180+ mBubbleShowCaseListener?.onBubbleClick(this @BubbleShowCase)
181+ }
182+
183+ override fun onCloseActionImageClick () {
171184 dismiss()
172- mBubbleShowCaseListener?.onClose (this @BubbleShowCase)
185+ mBubbleShowCaseListener?.onCloseActionImageClick (this @BubbleShowCase)
173186 }
174187 })
175188 }
@@ -184,11 +197,11 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
184197 setString(mPrefs, id, id)
185198 }
186199
187- fun getString (mPrefs : SharedPreferences , key : String ): String? {
200+ private fun getString (mPrefs : SharedPreferences , key : String ): String? {
188201 return mPrefs.getString(key, null )
189202 }
190203
191- fun setString (mPrefs : SharedPreferences , key : String , value : String ) {
204+ private fun setString (mPrefs : SharedPreferences , key : String , value : String ) {
192205 val editor = mPrefs.edit()
193206 editor.putString(key, value)
194207 editor.apply ()
@@ -198,7 +211,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
198211 /* *
199212 * This function takes a screenshot of the targetView, creating an ImageView from it. This new ImageView is also set on the layout passed by param
200213 */
201- private fun addTargetViewAtForegroundLayout (targetView : View ? , foregroundLayout : RelativeLayout ? ) {
214+ private fun addTargetViewAtBackgroundDimLayout (targetView : View ? , backgroundDimLayout : RelativeLayout ? ) {
202215 if (targetView== null ) return
203216
204217 val targetScreenshot = takeScreenshot(targetView, mHighlightMode)
@@ -212,13 +225,13 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
212225
213226 val targetViewParams = RelativeLayout .LayoutParams (RelativeLayout .LayoutParams .WRAP_CONTENT , RelativeLayout .LayoutParams .WRAP_CONTENT )
214227 targetViewParams.setMargins(getXposition(targetView), getYposition(targetView), getScreenWidth(mActivity.get()!! ) - (getXposition(targetView) + targetView.width), 0 )
215- foregroundLayout ?.addView(AnimationUtils .setBouncingAnimation(targetScreenshotView, 0 , DURATION_BEATING_ANIMATION ), targetViewParams)
228+ backgroundDimLayout ?.addView(AnimationUtils .setBouncingAnimation(targetScreenshotView, 0 , DURATION_BEATING_ANIMATION ), targetViewParams)
216229 }
217230
218231 /* *
219232 * This function creates the BubbleMessageView depending the position of the target and the desired arrow position. This new view is also set on the layout passed by param
220233 */
221- private fun addBubbleMessageViewDependingOnTargetView (targetView : View ? , bubbleMessageViewBuilder : BubbleMessageView .Builder , foregroundLayout : RelativeLayout ? ) {
234+ private fun addBubbleMessageViewDependingOnTargetView (targetView : View ? , bubbleMessageViewBuilder : BubbleMessageView .Builder , backgroundDimLayout : RelativeLayout ? ) {
222235 if (targetView== null ) return
223236 val showCaseParams = RelativeLayout .LayoutParams (RelativeLayout .LayoutParams .MATCH_PARENT , RelativeLayout .LayoutParams .WRAP_CONTENT )
224237
@@ -302,13 +315,13 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
302315
303316 bubbleMessageView.id = createViewId()
304317 val animation = AnimationUtils .getScaleAnimation(0 , DURATION_SHOW_CASE_ANIMATION )
305- foregroundLayout ?.addView(AnimationUtils .setAnimationToView(bubbleMessageView, animation), showCaseParams)
318+ backgroundDimLayout ?.addView(AnimationUtils .setAnimationToView(bubbleMessageView, animation), showCaseParams)
306319 }
307320
308321 /* *
309322 * This function creates a BubbleMessageView and it is set on the center of the layout passed by param
310323 */
311- private fun addBubbleMessageViewOnScreenCenter (bubbleMessageViewBuilder : BubbleMessageView .Builder , foregroundLayout : RelativeLayout ? ) {
324+ private fun addBubbleMessageViewOnScreenCenter (bubbleMessageViewBuilder : BubbleMessageView .Builder , backgroundDimLayout : RelativeLayout ? ) {
312325 val showCaseParams = RelativeLayout .LayoutParams (RelativeLayout .LayoutParams .MATCH_PARENT , RelativeLayout .LayoutParams .WRAP_CONTENT )
313326 showCaseParams.addRule(RelativeLayout . CENTER_VERTICAL )
314327 val bubbleMessageView: BubbleMessageView = bubbleMessageViewBuilder.build()
@@ -319,7 +332,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
319332 if (isTablet()) getScreenWidth(mActivity.get()!! )/ 2 - ScreenUtils .dpToPx(MAX_WIDTH_MESSAGE_VIEW_TABLET )/ 2 else 0 ,
320333 0 )
321334 val animation = AnimationUtils .getScaleAnimation(0 , DURATION_SHOW_CASE_ANIMATION )
322- foregroundLayout ?.addView(AnimationUtils .setAnimationToView(bubbleMessageView, animation), showCaseParams)
335+ backgroundDimLayout ?.addView(AnimationUtils .setAnimationToView(bubbleMessageView, animation), showCaseParams)
323336 }
324337
325338 private fun createViewId (): Int {
@@ -379,11 +392,11 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
379392 }
380393
381394 private fun getScreenVerticalOffset (): Int {
382- return if (foregroundLayoutWithBlur != null ) ScreenUtils .getAxisYpositionOfViewOnScreen(foregroundLayoutWithBlur !! ) else 0
395+ return if (backgroundDimLayout != null ) ScreenUtils .getAxisYpositionOfViewOnScreen(backgroundDimLayout !! ) else 0
383396 }
384397
385398 private fun getScreenHorizontalOffset (): Int {
386- return if (foregroundLayoutWithBlur != null ) ScreenUtils .getAxisXpositionOfViewOnScreen(foregroundLayoutWithBlur !! ) else 0
399+ return if (backgroundDimLayout != null ) ScreenUtils .getAxisXpositionOfViewOnScreen(backgroundDimLayout !! ) else 0
387400 }
388401
389402 private fun getMessageViewWidthOnTablet (availableSpace : Int ): Int {
0 commit comments