From b8c2404a77ef59329f6487c5547222130d60437f Mon Sep 17 00:00:00 2001 From: David Gonzalez Date: Tue, 28 Jul 2020 21:32:08 -0500 Subject: [PATCH 1/2] Add a method to start the sequence from a specific position --- .idea/codeStyles/Project.xml | 116 ++++++++++++++++++ .../bubbleshowcase/BubbleMessageView.kt | 25 ++-- .../bubbleshowcase/BubbleShowCaseSequence.kt | 20 +++ 3 files changed, 146 insertions(+), 15 deletions(-) create mode 100644 .idea/codeStyles/Project.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt index 43bf422..2694176 100644 --- a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt +++ b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt @@ -14,8 +14,8 @@ import android.view.View import android.widget.ImageView import android.widget.TextView import java.lang.ref.WeakReference - -import java.util.ArrayList +import java.util.* +import kotlin.math.roundToInt /** * Created by jcampos on 05/09/2018. @@ -55,7 +55,6 @@ class BubbleMessageView : ConstraintLayout { private fun initView() { setWillNotDraw(false) - inflateXML() bindViews() } @@ -182,23 +181,19 @@ class BubbleMessageView : ConstraintLayout { } private fun getArrowHorizontalPositionDependingOnTarget(targetViewLocationOnScreen: RectF?): Int { - val xPosition: Int - when { - isOutOfRightBound(targetViewLocationOnScreen) -> xPosition = width - getSecurityArrowMargin() - isOutOfLeftBound(targetViewLocationOnScreen) -> xPosition = getSecurityArrowMargin() - else -> xPosition = Math.round(targetViewLocationOnScreen!!.centerX() - ScreenUtils.getAxisXpositionOfViewOnScreen(this)) + return when { + isOutOfRightBound(targetViewLocationOnScreen) -> width - getSecurityArrowMargin() + isOutOfLeftBound(targetViewLocationOnScreen) -> getSecurityArrowMargin() + else -> (targetViewLocationOnScreen!!.centerX() - ScreenUtils.getAxisXpositionOfViewOnScreen(this)).roundToInt() } - return xPosition } private fun getArrowVerticalPositionDependingOnTarget(targetViewLocationOnScreen: RectF?): Int { - val yPosition: Int - when { - isOutOfBottomBound(targetViewLocationOnScreen) -> yPosition = height - getSecurityArrowMargin() - isOutOfTopBound(targetViewLocationOnScreen) -> yPosition = getSecurityArrowMargin() - else -> yPosition = Math.round(targetViewLocationOnScreen!!.centerY() + ScreenUtils.getStatusBarHeight(context) - ScreenUtils.getAxisYpositionOfViewOnScreen(this)) + return when { + isOutOfBottomBound(targetViewLocationOnScreen) -> height - getSecurityArrowMargin() + isOutOfTopBound(targetViewLocationOnScreen) -> getSecurityArrowMargin() + else -> (targetViewLocationOnScreen!!.centerY() + ScreenUtils.getStatusBarHeight(context) - ScreenUtils.getAxisYpositionOfViewOnScreen(this)).roundToInt() } - return yPosition } private fun isOutOfRightBound(targetViewLocationOnScreen: RectF?): Boolean { diff --git a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseSequence.kt b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseSequence.kt index f86b45f..3308199 100644 --- a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseSequence.kt +++ b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseSequence.kt @@ -47,4 +47,24 @@ class BubbleShowCaseSequence{ }).show() } + fun showStartingAtPosition(position: Int) { + if(position >= mBubbleShowCaseBuilderList.size) + return + + mBubbleShowCaseBuilderList[position].isFirstOfSequence(true) + when(position){ + mBubbleShowCaseBuilderList.size-1 -> { + mBubbleShowCaseBuilderList[position].isLastOfSequence(true) + } + else -> { + mBubbleShowCaseBuilderList[position].isLastOfSequence(false) + } + } + mBubbleShowCaseBuilderList[position].sequenceListener(object : SequenceShowCaseListener{ + override fun onDismiss() { + show(position + 1) + } + }).show() + } + } \ No newline at end of file From 2033a3adcc162ae8d2b0ac2485f3785738b9e027 Mon Sep 17 00:00:00 2001 From: David Gonzalez Date: Tue, 28 Jul 2020 21:53:51 -0500 Subject: [PATCH 2/2] Add border with customizable color --- .../bubbleshowcase/BubbleMessageView.kt | 22 ++-- .../bubbleshowcase/BubbleShowCase.kt | 2 + .../bubbleshowcase/BubbleShowCaseBuilder.kt | 20 ++- .../main/res/layout/view_bubble_message.xml | 121 +++++++++--------- 4 files changed, 97 insertions(+), 68 deletions(-) diff --git a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt index 2694176..5ba8cc4 100644 --- a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt +++ b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt @@ -11,17 +11,14 @@ import android.support.v4.content.ContextCompat import android.util.AttributeSet import android.util.TypedValue import android.view.View +import android.widget.FrameLayout import android.widget.ImageView import android.widget.TextView import java.lang.ref.WeakReference import java.util.* import kotlin.math.roundToInt -/** - * Created by jcampos on 05/09/2018. - */ - -class BubbleMessageView : ConstraintLayout { +class BubbleMessageView : FrameLayout { private val WIDTH_ARROW = 20 @@ -34,7 +31,7 @@ class BubbleMessageView : ConstraintLayout { private var showCaseMessageViewLayout: ConstraintLayout? = null private var targetViewScreenLocation: RectF? = null - private var mBackgroundColor: Int = ContextCompat.getColor(context, R.color.blue_default) + private var mBorderColor: Int = ContextCompat.getColor(context, R.color.white) private var arrowPositionList = ArrayList() private var paint: Paint? = null @@ -103,7 +100,10 @@ class BubbleMessageView : ConstraintLayout { builder.mSubtitleTextSize?.let { textViewSubtitle?.setTextSize(TypedValue.COMPLEX_UNIT_SP, builder.mSubtitleTextSize!!.toFloat()) } - builder.mBackgroundColor?.let { mBackgroundColor = builder.mBackgroundColor!! } + builder.mBackgroundColor?.let { + showCaseMessageViewLayout!!.setBackgroundColor(builder.mBackgroundColor!!) + } + builder.mBorderColor?.let { mBorderColor = builder.mBorderColor!! } arrowPositionList = builder.mArrowPosition targetViewScreenLocation = builder.mTargetViewScreenLocation } @@ -141,7 +141,7 @@ class BubbleMessageView : ConstraintLayout { private fun prepareToDraw() { paint = Paint(Paint.ANTI_ALIAS_FLAG) - paint!!.color = mBackgroundColor + paint!!.color = mBorderColor paint!!.style = Paint.Style.FILL paint!!.strokeWidth = 4.0f } @@ -242,6 +242,7 @@ class BubbleMessageView : ConstraintLayout { var mSubtitle: String? = null var mCloseAction: Drawable? = null var mBackgroundColor: Int? = null + var mBorderColor: Int? = null var mTextColor: Int? = null var mTitleTextSize: Int? = null var mSubtitleTextSize: Int? = null @@ -288,6 +289,11 @@ class BubbleMessageView : ConstraintLayout { return this } + fun borderColor(borderColor: Int?): Builder { + mBorderColor = borderColor + return this + } + fun textColor(textColor: Int?): Builder { mTextColor = textColor return this diff --git a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCase.kt b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCase.kt index f1460b5..3d6d6ea 100644 --- a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCase.kt +++ b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCase.kt @@ -58,6 +58,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){ private val mSubtitle: String? = builder.mSubtitle private val mCloseAction: Drawable? = builder.mCloseAction private val mBackgroundColor: Int? = builder.mBackgroundColor + private val mBorderColor: Int? = builder.mBorderColor private val mTextColor: Int? = builder.mTextColor private val mTitleTextSize: Int? = builder.mTitleTextSize private val mSubtitleTextSize: Int? = builder.mSubtitleTextSize @@ -167,6 +168,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){ .from(mActivity.get()!!) .arrowPosition(mArrowPositionList) .backgroundColor(mBackgroundColor) + .borderColor(mBorderColor) .textColor(mTextColor) .titleTextSize(mTitleTextSize) .subtitleTextSize(mSubtitleTextSize) diff --git a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseBuilder.kt b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseBuilder.kt index a0dc459..d16c75a 100644 --- a/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseBuilder.kt +++ b/bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseBuilder.kt @@ -19,6 +19,7 @@ class BubbleShowCaseBuilder{ internal var mSubtitle: String? = null internal var mCloseAction: Drawable? = null internal var mBackgroundColor: Int? = null + internal var mBorderColor: Int? = null internal var mTextColor: Int? = null internal var mTitleTextSize: Int? = null internal var mSubtitleTextSize: Int? = null @@ -94,7 +95,6 @@ class BubbleShowCaseBuilder{ return this } - /** * Background color of the BubbleShowCase. * - #3F51B5 color will be set if this param is not defined @@ -104,6 +104,15 @@ class BubbleShowCaseBuilder{ return this } + /** + * Border color of the BubbleShowCase. + * - #FFF color will be set if this param is not defined + */ + fun borderColor(color: Int): BubbleShowCaseBuilder { + mBorderColor = color + return this + } + /** * Background color of the BubbleShowCase. * - #3F51B5 color will be set if this param is not defined @@ -113,6 +122,15 @@ class BubbleShowCaseBuilder{ return this } + /** + * Border color of the BubbleShowCase. + * - #FFF color will be set if this param is not defined + */ + fun borderColorResourceId(colorResId: Int): BubbleShowCaseBuilder { + mBorderColor = ContextCompat.getColor(mActivity!!.get(), colorResId) + return this + } + /** * Text color of the BubbleShowCase. * - White color will be set if this param is not defined diff --git a/bubbleshowcase/src/main/res/layout/view_bubble_message.xml b/bubbleshowcase/src/main/res/layout/view_bubble_message.xml index a437e22..ddb465f 100644 --- a/bubbleshowcase/src/main/res/layout/view_bubble_message.xml +++ b/bubbleshowcase/src/main/res/layout/view_bubble_message.xml @@ -1,73 +1,76 @@ - - - - + android:background="@color/blue_default" + android:padding="8dp"> - + android:layout_marginTop="16dp" + android:src="@drawable/rounded_rectangle" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + android:layout_marginStart="8dp" + android:layout_marginLeft="8dp" + android:orientation="vertical" + app:layout_constraintEnd_toStartOf="@+id/imageViewShowCaseClose" + app:layout_constraintStart_toEndOf="@+id/imageViewShowCase" + app:layout_constraintTop_toTopOf="parent"> + + + + + + - + - + - \ No newline at end of file +