ECLaboratorio / BubbleShowCase-Android

BubbleShowCase is a framework that let you to use informative bubbles to help your users pointing out different App features.
MIT License
599 stars 89 forks source link

It crashes on some devices on java.lang.IndexOutOfBoundsException #29

Open adnaanaeem opened 5 years ago

adnaanaeem commented 5 years ago

private fun addBubbleMessageViewDependingOnTargetView(targetView: View?, bubbleMessageViewBuilder: BubbleMessageView.Builder, backgroundDimLayout: RelativeLayout?) { if(targetView==null) return val showCaseParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT)

    when (bubbleMessageViewBuilder.mArrowPosition[0]) {
        ArrowPosition.LEFT -> {
            showCaseParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT)
            if(ScreenUtils.isViewLocatedAtHalfTopOfTheScreen(mActivity.get()!!, targetView)){
                showCaseParams.setMargins(
                        getXposition(targetView) + targetView.width,
                        getYposition(targetView),
                        if(isTablet()) getScreenWidth(mActivity.get()!!) - (getXposition(targetView) + targetView.width) - getMessageViewWidthOnTablet(getScreenWidth(mActivity.get()!!) - (getXposition(targetView) + targetView.width)) else 0,
                        0)
                showCaseParams.addRule(RelativeLayout.ALIGN_PARENT_TOP)
            } else{
                showCaseParams.setMargins(
                        getXposition(targetView) + targetView.width,
                        0,
                        if(isTablet()) getScreenWidth(mActivity.get()!!) - (getXposition(targetView) + targetView.width) - getMessageViewWidthOnTablet(getScreenWidth(mActivity.get()!!) - (getXposition(targetView) + targetView.width)) else 0,
                        getScreenHeight(mActivity.get()!!) - getYposition(targetView) - targetView.height)
                showCaseParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
            }
        }
        ArrowPosition.RIGHT -> {
            showCaseParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
            if(ScreenUtils.isViewLocatedAtHalfTopOfTheScreen(mActivity.get()!!, targetView)){
                showCaseParams.setMargins(
                        if(isTablet()) getXposition(targetView) - getMessageViewWidthOnTablet(getXposition(targetView)) else 0,
                        getYposition(targetView),
                        getScreenWidth(mActivity.get()!!) - getXposition(targetView),
                        0)
                showCaseParams.addRule(RelativeLayout.ALIGN_PARENT_TOP)
            } else{
                showCaseParams.setMargins(
                        if(isTablet()) getXposition(targetView) - getMessageViewWidthOnTablet(getXposition(targetView)) else 0,
                        0,
                        getScreenWidth(mActivity.get()!!) - getXposition(targetView),
                        getScreenHeight(mActivity.get()!!) - getYposition(targetView) - targetView.height)
                showCaseParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
            }
        }
        ArrowPosition.TOP -> {
            showCaseParams.addRule(RelativeLayout.ALIGN_PARENT_TOP)
            if(ScreenUtils.isViewLocatedAtHalfLeftOfTheScreen(mActivity.get()!!, targetView)){
                showCaseParams.setMargins(
                        if (isTablet()) getXposition(targetView) else 0,
                        getYposition(targetView) + targetView.height,
                        if (isTablet()) getScreenWidth(mActivity.get()!!) - getXposition(targetView) - getMessageViewWidthOnTablet(getScreenWidth(mActivity.get()!!) - getXposition(targetView)) else 0,
                        0)
            } else{
                showCaseParams.setMargins(
                        if (isTablet()) getXposition(targetView) + targetView.width - getMessageViewWidthOnTablet(getXposition(targetView)) else 0,
                        getYposition(targetView) + targetView.height,
                        if (isTablet()) getScreenWidth(mActivity.get()!!) - getXposition(targetView) - targetView.width else 0,
                        0)
            }
        }
        ArrowPosition.BOTTOM -> {
            showCaseParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
            if(ScreenUtils.isViewLocatedAtHalfLeftOfTheScreen(mActivity.get()!!, targetView)){
                showCaseParams.setMargins(
                        if (isTablet()) getXposition(targetView) else 0,
                        0,
                        if (isTablet()) getScreenWidth(mActivity.get()!!) - getXposition(targetView) - getMessageViewWidthOnTablet(getScreenWidth(mActivity.get()!!) - getXposition(targetView)) else 0,
                        getScreenHeight(mActivity.get()!!) - getYposition(targetView))
            } else {
                showCaseParams.setMargins(
                        if (isTablet()) getXposition(targetView) + targetView.width - getMessageViewWidthOnTablet(getXposition(targetView)) else 0,
                        0,
                        if (isTablet()) getScreenWidth(mActivity.get()!!) - getXposition(targetView) - targetView.width else 0,
                        getScreenHeight(mActivity.get()!!) - getYposition(targetView))
            }
        }
    }

    val bubbleMessageView = bubbleMessageViewBuilder.targetViewScreenLocation(RectF(
            getXposition(targetView).toFloat(),
            getYposition(targetView).toFloat(),
            getXposition(targetView).toFloat() + targetView.width,
            getYposition(targetView).toFloat() + targetView.height))
            .build()

    bubbleMessageView.id = createViewId()
    val animation = AnimationUtils.getScaleAnimation(0, DURATION_SHOW_CASE_ANIMATION)
    backgroundDimLayout?.addView(AnimationUtils.setAnimationToView(bubbleMessageView, animation), showCaseParams)
}
gabrielseibel1 commented 5 years ago

Same thing happening for me, when using a BubbleShowCaseSequence that has two bubbles with different targets. When I remove one of the two targets, it works fine. My workaround was to show the second bubble in the listener of the first one.

abdulwajid725 commented 5 years ago

@gabrielseibel1 can u share your code with me.I have to make it work on 5 targets.

mayankneeds commented 4 years ago

This same issue is occurring at my side as well.

Fatal Exception: java.lang.IndexOutOfBoundsException
com.elconfidencial.bubbleshowcase.BubbleShowCase.addBubbleMessageViewDependingOnTargetView (BubbleShowCase.kt:238)
Monabr commented 3 years ago

Have the same problem. Is there any solution to this?