Skip to content

Border and start from any position #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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

import java.util.ArrayList

/**
* Created by jcampos on 05/09/2018.
*/

class BubbleMessageView : ConstraintLayout {
class BubbleMessageView : FrameLayout {

private val WIDTH_ARROW = 20

Expand All @@ -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<BubbleShowCase.ArrowPosition>()

private var paint: Paint? = null
Expand All @@ -55,7 +52,6 @@ class BubbleMessageView : ConstraintLayout {

private fun initView() {
setWillNotDraw(false)

inflateXML()
bindViews()
}
Expand Down Expand Up @@ -104,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
}
Expand Down Expand Up @@ -142,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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -247,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
Expand Down Expand Up @@ -293,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -167,6 +168,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
.from(mActivity.get()!!)
.arrowPosition(mArrowPositionList)
.backgroundColor(mBackgroundColor)
.borderColor(mBorderColor)
.textColor(mTextColor)
.titleTextSize(mTitleTextSize)
.subtitleTextSize(mSubtitleTextSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,7 +95,6 @@ class BubbleShowCaseBuilder{
return this
}


/**
* Background color of the BubbleShowCase.
* - #3F51B5 color will be set if this param is not defined
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}
Loading