Skip to content

Commit

Permalink
Merge pull request #25 from Trendyol/toolTipVisibilityAndHighlightRadius
Browse files Browse the repository at this point in the history
add highlight radius and toolTip visibility
  • Loading branch information
belfuogretir authored Jul 7, 2022
2 parents f013250 + 48c3813 commit c25380e
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ showcaseManager.show(context) // or showcaseManager.show(context, REQUEST_CODE_S
| `builder.imageUrl(String)` | show image on tooltip | yes | null | no |
| `builder.customContent(Int)` | show given layout | yes | null | no |
| `builder.statusBarVisible(Boolean)` | statusBar visibility of window | yes | true | no |
| `builder.toolTipVisible(Boolean)` | tooltip visibility | yes | true | no |
| `builder.highlightRadius(Float, Float, Float, Float)` | tooltip visibility | yes | 0f, 0f, 0f, 0f | no |
| `builder.setSlidableContentList(List<SlidableContent>)` | show slidable content | yes | null | no |
| `builder.build()` | will return ShowcaseManager instance | no | | |
| `showcaseManager.show(Context)` | show the tooltip with set attributes on | no | | |
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
defaultConfig {
minSdkVersion 17
targetSdkVersion 30
versionCode 13
versionName "1.1.0"
versionCode 14
versionName "1.2.0"

vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,18 @@ class ShowcaseManager private constructor(

@StyleRes
private var resId: Int? = null
private var cancellableFromOutsideTouch: Boolean = Constants.DEFAULT_CANCELLABLE_FROM_OUTSIDE_TOUCH
private var cancellableFromOutsideTouch: Boolean =
Constants.DEFAULT_CANCELLABLE_FROM_OUTSIDE_TOUCH
private var isShowcaseViewClickable: Boolean = Constants.DEFAULT_SHOWCASE_VIEW_CLICKABLE
private var isDebugMode: Boolean = false
private var attachOnParentLifecycle: Boolean = false
private var textPosition: TextPosition = Constants.DEFAULT_TEXT_POSITION
private var imageUrl: String = Constants.DEFAULT_TEXT
private var radiusTopStart: Float = Constants.DEFAULT_HIGHLIGHT_RADIUS
private var radiusTopEnd: Float = Constants.DEFAULT_HIGHLIGHT_RADIUS
private var radiusBottomStart: Float = Constants.DEFAULT_HIGHLIGHT_RADIUS
private var radiusBottomEnd: Float = Constants.DEFAULT_HIGHLIGHT_RADIUS
private var isToolTipVisible: Boolean = true

@LayoutRes
private var customContent: Int? = null
Expand Down Expand Up @@ -177,7 +183,8 @@ class ShowcaseManager private constructor(
*
* @param fontFamily assigns fontFamily to descriptionText
*/
fun descriptionTextFontFamily(fontFamily: String) = apply { descriptionTextFontFamily = fontFamily }
fun descriptionTextFontFamily(fontFamily: String) =
apply { descriptionTextFontFamily = fontFamily }

/**
* Assign textStyle to descriptionText
Expand Down Expand Up @@ -242,7 +249,31 @@ class ShowcaseManager private constructor(
*
* @param clickable Set the value to true so that the showcase view is clickable
*/
fun showcaseViewClickable(clickable: Boolean) = apply { isShowcaseViewClickable = clickable }
fun showcaseViewClickable(clickable: Boolean) =
apply { isShowcaseViewClickable = clickable }

/**
*
* radius for highlight area.
*/
fun highlightRadius(
topStartRadius: Float = Constants.DEFAULT_HIGHLIGHT_RADIUS,
topEndRadius: Float = Constants.DEFAULT_HIGHLIGHT_RADIUS,
bottomStartRadius: Float = Constants.DEFAULT_HIGHLIGHT_RADIUS,
bottomEndRadius: Float = Constants.DEFAULT_HIGHLIGHT_RADIUS
) = apply {
radiusTopStart = topStartRadius
radiusTopEnd = topEndRadius
radiusBottomStart = bottomStartRadius
radiusBottomEnd = bottomEndRadius
}

/**
*
* show toolTip or not.
*/
fun toolTipVisible(isToolTipVisible: Boolean) =
apply { this.isToolTipVisible = isToolTipVisible }

/**
* Running in debug mode or not
Expand Down Expand Up @@ -314,6 +345,11 @@ class ShowcaseManager private constructor(
customContent = customContent,
isStatusBarVisible = isStatusBarVisible,
slidableContentList = slidableContentList,
radiusTopStart = radiusTopStart,
radiusTopEnd = radiusTopEnd,
radiusBottomEnd = radiusBottomEnd,
radiusBottomStart = radiusBottomStart,
isToolTipVisible = isToolTipVisible
)

return ShowcaseManager(showcaseModel = showcaseModel, resId = resId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ data class ShowcaseModel(
@LayoutRes val customContent: Int?,
val isStatusBarVisible: Boolean,
val slidableContentList: List<SlidableContent>?,
val radiusTopStart: Float,
val radiusTopEnd: Float,
val radiusBottomEnd: Float,
val radiusBottomStart: Float,
val isToolTipVisible: Boolean
) : Parcelable {

fun horizontalCenter() = rectF.left + ((rectF.right - rectF.left) / 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class ShowcaseView @JvmOverloads constructor(
left = model.rectF.left - (model.highlightPadding / 2),
top = model.rectF.top - (model.highlightPadding / 2),
right = model.rectF.right + (model.highlightPadding / 2),
bottom = model.rectF.bottom + (model.highlightPadding / 2)
bottom = model.rectF.bottom + (model.highlightPadding / 2),
radiusTopStart = model.radiusTopStart,
radiusTopEnd = model.radiusTopEnd,
radiusBottomEnd = model.radiusBottomEnd,
radiusBottomStart = model.radiusBottomStart
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ internal data class TooltipViewState(
fun isShowcaseViewClickable() = showcaseModel.isShowcaseViewClickable

fun isSlidableContentVisible() = showcaseModel.slidableContentList.isNullOrEmpty().not()

fun isToolTipVisible() = showcaseModel.isToolTipVisible
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ object Constants {
val DEFAULT_TEXT_POSITION = TextPosition.START
const val DEFAULT_CANCELLABLE_FROM_OUTSIDE_TOUCH = false
const val DEFAULT_SHOWCASE_VIEW_CLICKABLE = false
const val DEFAULT_HIGHLIGHT_RADIUS = 0f
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.trendyol.showcase.util.shape

import android.graphics.Canvas
import android.graphics.Path
import android.graphics.RectF

class RectangleShape(
Expand All @@ -10,12 +11,29 @@ class RectangleShape(
private val left: Float,
private val top: Float,
private val right: Float,
private val bottom: Float
private val bottom: Float,
private val radiusTopStart: Float,
private val radiusTopEnd: Float,
private val radiusBottomEnd: Float,
private val radiusBottomStart: Float,
) : Shape(screenWidth, screenHeight) {

private val path = Path()
private val corners = floatArrayOf(
radiusTopStart,
radiusTopStart,
radiusTopEnd,
radiusTopEnd,
radiusBottomEnd,
radiusBottomEnd,
radiusBottomStart,
radiusBottomStart
)

override fun draw(windowBackgroundColor: Int, windowBackgroundAlpha: Int, canvas: Canvas) {
super.draw(windowBackgroundColor, windowBackgroundAlpha, canvas)
val rectF = RectF(left, top + statusBarDiff, right, bottom + statusBarDiff)
canvas.drawRect(rectF, paint)
path.addRoundRect(rectF, corners, Path.Direction.CW)
canvas.drawPath(path, paint)
}
}
1 change: 1 addition & 0 deletions library/src/main/res/layout/layout_showcase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
android:id="@+id/tooltipView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:isVisible="@{tooltipViewState.isToolTipVisible()}"
app:applyMargin="@{showcaseViewState.margin}"
app:arrowPosition="@{tooltipViewState.arrowPosition}"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
8 changes: 8 additions & 0 deletions sample/src/main/java/com/trendyol/sample/SampleFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ class SampleFragment : Fragment() {
.highlightType(HighlightType.RECTANGLE)
.highlightPadding(8f)
.textPosition(TextPosition.START)
.highlightRadius(
bottomEndRadius = 16f,
topStartRadius = 16f,
topEndRadius = 16f,
bottomStartRadius = 16f
)
.cancellableFromOutsideTouch(true)
.toolTipVisible(false)
.statusBarVisible(isStatusBarVisible)
.build()
.show(this@SampleFragment, REQUEST_CODE_SHOWCASE_CLICKED)
Expand Down

0 comments on commit c25380e

Please sign in to comment.