Skip to content

Commit

Permalink
Merge pull request #2 from akndmr/feature/text-colors
Browse files Browse the repository at this point in the history
Feature/text colors
  • Loading branch information
akndmr authored Apr 11, 2022
2 parents 5334622 + b2c27a2 commit f222059
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0.5-beta"
versionName "1.0.6-beta"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ class MainActivity : AppCompatActivity() {
.prevString(string.previous)
.nextString(nextStringText = "Sonraki")
.finishString(finishStringText = "Bitir da!")
.nextTextColorRes(R.color.green)
.finishTextColorRes(R.color.blue)
.useCircleIndicator(true)
.showBottomContainer(false)
.showBottomContainer(true)
.clickable(true)
.useArrow(true)
.useSkipWord(false)
.setFragmentManager(this.supportFragmentManager)
.lineColorRes(color.line_color)
.lineWidthRes(dimen.line_width)
.shouldShowIcons(true)
.shouldShowIcons(false)
.setTooltipRadius(dimen.tooltip_radius)
.showSpotlight(true)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class TooltipBuilder() : Parcelable {
private var layoutRes = 0
private var titleTextColorRes = 0
private var textColorRes = 0
private var prevTextColorRes = 0
private var nextTextColorRes = 0
private var finishTextColorRes = 0
private var shadowColorRes = 0
private var titleTextSizeRes = 0
private var textSizeRes = 0
Expand Down Expand Up @@ -96,6 +99,21 @@ class TooltipBuilder() : Parcelable {
return this
}

fun prevTextColorRes(@ColorRes prevTextColorRes: Int): TooltipBuilder {
this.prevTextColorRes = prevTextColorRes
return this
}

fun nextTextColorRes(@ColorRes nextTextColorRes: Int): TooltipBuilder {
this.nextTextColorRes = nextTextColorRes
return this
}

fun finishTextColorRes(@ColorRes finishTextColorRes: Int): TooltipBuilder {
this.finishTextColorRes = finishTextColorRes
return this
}

fun shadowColorRes(@ColorRes shadowColorRes: Int): TooltipBuilder {
this.shadowColorRes = shadowColorRes
return this
Expand Down Expand Up @@ -220,6 +238,18 @@ class TooltipBuilder() : Parcelable {
return titleTextColorRes
}

fun getPrevTextColorRes(): Int {
return prevTextColorRes
}

fun getNextTextColorRes(): Int {
return nextTextColorRes
}

fun getFinishTextColorRes(): Int {
return finishTextColorRes
}

fun getTitleTextSizeRes(): Int {
return titleTextSizeRes
}
Expand Down Expand Up @@ -345,6 +375,9 @@ class TooltipBuilder() : Parcelable {
arrowWidth = `in`.readInt()
skipStringRes = `in`.readInt()
useSkipWord = `in`.readByte().toInt() != 0
prevTextColorRes = `in`.readInt()
nextTextColorRes = `in`.readInt()
finishTextColorRes = `in`.readInt()
}

constructor(parcel: Parcel) : this() {
Expand Down
83 changes: 58 additions & 25 deletions ugly-tooltip/src/main/java/io/akndmr/ugly_tooltip/TooltipLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class TooltipLayout : FrameLayout {
private var layoutRes = 0
private var textColor = 0
private var titleTextColor = 0
private var prevTextColor = 0
private var nextTextColor = 0
private var finishTextColor = 0
private var shadowColor = 0
private var textSize = 0f
private var textTitleSize = 0f
Expand Down Expand Up @@ -164,7 +167,7 @@ class TooltipLayout : FrameLayout {
private fun initFrame() {
setWillNotDraw(false)
viewPaint = Paint(Paint.ANTI_ALIAS_FLAG)
if (showSpotlight){
if (showSpotlight) {
viewPaint!!.xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
}

Expand Down Expand Up @@ -244,8 +247,10 @@ class TooltipLayout : FrameLayout {
if (nextButton != null) {
if (isLast) {
nextButton!!.text = finishString
nextButton!!.setTextColor(finishTextColor)
} else if (currentTutorIndex < tutorsListSize - 1) { // has next
nextButton!!.text = nextString
nextButton!!.setTextColor(nextTextColor)
}
}

Expand Down Expand Up @@ -330,10 +335,10 @@ class TooltipLayout : FrameLayout {
this.visibility = View.VISIBLE
}

fun getBitmapFromView(view: View): Bitmap? {
var bitmap =
private fun getBitmapFromView(view: View): Bitmap? {
val bitmap =
Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
var canvas = Canvas(bitmap)
val canvas = Canvas(bitmap)
view.draw(canvas)
return bitmap
}
Expand Down Expand Up @@ -411,6 +416,9 @@ class TooltipLayout : FrameLayout {
layoutRes = layout.tutorial_view
textColor = Color.WHITE
titleTextColor = Color.WHITE
prevTextColor = Color.WHITE
nextTextColor = Color.WHITE
finishTextColor = Color.WHITE
textTitleSize = resources.getDimension(dimen.title_size)
textSize = resources.getDimension(dimen.text_normal)
shadowColor = ContextCompat.getColor(context, color.shadow)
Expand Down Expand Up @@ -473,54 +481,82 @@ class TooltipLayout : FrameLayout {
context,
builder.getTextColorRes()
) else textColor

titleTextColor = if (builder.getTitleTextColorRes() != 0) ContextCompat.getColor(
context,
builder.getTitleTextColorRes()
) else titleTextColor

prevTextColor = if (builder.getPrevTextColorRes() != 0) ContextCompat.getColor(
context,
builder.getPrevTextColorRes()
) else prevTextColor

nextTextColor = if (builder.getNextTextColorRes() != 0) ContextCompat.getColor(
context,
builder.getNextTextColorRes()
) else nextTextColor

finishTextColor = if (builder.getFinishTextColorRes() != 0) ContextCompat.getColor(
context,
builder.getFinishTextColorRes()
) else finishTextColor

textTitleSize =
if (builder.getTitleTextSizeRes() != 0) resources.getDimension(builder.getTitleTextSizeRes()) else textTitleSize

textSize =
if (builder.getTextSizeRes() != 0) resources.getDimension(builder.getTextSizeRes()) else textSize

backgroundContentColor =
if (builder.getBackgroundContentColorRes() != 0) ContextCompat.getColor(
context,
builder.getBackgroundContentColorRes()
) else backgroundContentColor

shadowColor = if (builder.getShadowColorRes() != 0) ContextCompat.getColor(
context,
builder.getShadowColorRes()
) else shadowColor

spacing = if (builder.getSpacingRes() != 0) resources.getDimension(builder.getSpacingRes())
.toInt() else spacing

circleBackgroundDrawableRes =
if (builder.getCircleIndicatorBackgroundDrawableRes() != 0) builder.getCircleIndicatorBackgroundDrawableRes() else circleBackgroundDrawableRes

prevString =
when {
builder.getPrevStringRes() != 0 -> getContext().getString(builder.getPrevStringRes())
builder.getPrevStringText().isNotEmpty() -> builder.getPrevStringText()
else -> prevString
}

nextString =
when {
builder.getNextStringRes() != 0 -> getContext().getString(builder.getNextStringRes())
builder.getNextStringText().isNotEmpty() -> builder.getNextStringText()
else -> nextString
}

finishString =
when {
builder.getFinishStringRes() != 0 -> getContext().getString(builder.getFinishStringRes())
builder.getFinishStringText().isNotEmpty() -> builder.getFinishStringText()
else -> finishString
}

skipString =
when {
builder.getSkipStringRes() != 0 -> getContext().getString(builder.getSkipStringRes())
builder.getSkipStringText().isNotEmpty() -> builder.getSkipStringText()
else -> skipString
}

useCircleIndicator = builder.useCircleIndicator()
hasSkipWord = builder.isUseSkipWord()
isCancelable = builder.isClickable()

if (builder.isUseArrow()) {
arrowMargin = spacing / 3
arrowWidth =
Expand Down Expand Up @@ -600,10 +636,6 @@ class TooltipLayout : FrameLayout {
textViewDesc = viewGroupTutorContent.findViewById(text_description)
textViewDesc!!.setTextColor(textColor)
textViewDesc!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
val line: View = viewGroupTutorContent.findViewById(view_line)
if (line != null) {
line.setBackgroundColor(textColor)
}
prevButton = viewGroupTutorContent.findViewById(text_previous)
nextButton = viewGroupTutorContent.findViewById(text_next)
prevImageView = viewGroupTutorContent.findViewById(ic_previous)
Expand All @@ -618,15 +650,16 @@ class TooltipLayout : FrameLayout {
bottomContainer?.let {
it.visibility = View.VISIBLE
}
if (lineView != null) {
lineView!!.visibility = View.VISIBLE
lineView!!.setBackgroundColor(lineColorRes)
lineView!!.layoutParams.height = lineWidthRes

lineView?.apply {
setBackgroundColor(lineColorRes)
layoutParams.height = 0
visibility = if(lineWidthRes > 0) VISIBLE else GONE
}

if (prevButton != null) {
prevButton!!.text = prevString
prevButton!!.setTextColor(textColor)
prevButton!!.setTextColor(prevTextColor)
prevButton!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
prevButton!!.setOnClickListener {
if (tooltipListener != null) {
Expand All @@ -642,7 +675,7 @@ class TooltipLayout : FrameLayout {
}
}
if (nextButton != null) {
nextButton!!.setTextColor(textColor)
nextButton!!.setTextColor(nextTextColor)
nextButton!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
nextButton!!.setOnClickListener { onNextClicked() }
if (shouldShowIcons) {
Expand Down Expand Up @@ -757,7 +790,7 @@ class TooltipLayout : FrameLayout {

if (recalcArrowWidth == 0) {
path = Path()
path!!.moveTo(highlightXend + arrowMargin, arrowStartY + arrowWidth/2)
path!!.moveTo(highlightXend + arrowMargin, arrowStartY + arrowWidth / 2)
path!!.lineTo(
highlightXend + spacing,
arrowEndY
Expand Down Expand Up @@ -819,7 +852,7 @@ class TooltipLayout : FrameLayout {

if (recalcArrowWidth == 0) {
path = Path()
path!!.moveTo(highlightXstart - arrowMargin, arrowStartY + arrowWidth/2)
path!!.moveTo(highlightXstart - arrowMargin, arrowStartY + arrowWidth / 2)
path!!.lineTo(
highlightXstart - spacing,
arrowEndY
Expand Down Expand Up @@ -872,7 +905,7 @@ class TooltipLayout : FrameLayout {
} else {
0f
}
} else if (isOnTheRightEdgeOfTheScreen){
} else if (isOnTheRightEdgeOfTheScreen) {
if (highlightXstart > width - (spacing + tooltipRadius)) {
highlightXstart - (width - (spacing + tooltipRadius))
} else {
Expand All @@ -892,11 +925,11 @@ class TooltipLayout : FrameLayout {
highlightXstart - bufferX
}
} else {
if (isOnTheLeftEdgeOfTheScreen) {
highlightXend + spotlightWidth/2 + arrowWidth/2
} else {
highlightXstart - spotlightWidth/2 - arrowWidth/2
}
if (isOnTheLeftEdgeOfTheScreen) {
highlightXend + spotlightWidth / 2 + arrowWidth / 2
} else {
highlightXstart - spotlightWidth / 2 - arrowWidth / 2
}
}

path = Path()
Expand Down Expand Up @@ -953,7 +986,7 @@ class TooltipLayout : FrameLayout {
} else {
0f
}
} else if (isOnTheRightEdgeOfTheScreen){
} else if (isOnTheRightEdgeOfTheScreen) {
if (highlightXstart > width - (spacing + tooltipRadius)) {
highlightXstart - (width - (spacing + tooltipRadius))
} else {
Expand All @@ -974,9 +1007,9 @@ class TooltipLayout : FrameLayout {
}
} else {
if (isOnTheLeftEdgeOfTheScreen) {
highlightXend + spotlightWidth/2 + arrowWidth/2
highlightXend + spotlightWidth / 2 + arrowWidth / 2
} else {
highlightXstart - spotlightWidth/2 - arrowWidth/2
highlightXstart - spotlightWidth / 2 - arrowWidth / 2
}
}

Expand Down

0 comments on commit f222059

Please sign in to comment.