lawlorslaw
07/15/2021, 6:00 PMlawlorslaw
07/15/2021, 6:28 PMbrandonmcansh
07/15/2021, 7:14 PMbrandonmcansh
07/15/2021, 7:15 PMbrandonmcansh
07/15/2021, 7:16 PMbrandonmcansh
07/15/2021, 7:20 PMfun generateTipContent(
context: Context,
themeAttrs: TooltipPopupWindow.ThemeAttributes,
styler: TooltipPopupWindow.Styler,
onClick: () -> Unit,
): ConstraintLayout {
val card = View.inflate(context, R.layout.tooltip_content, null) as ConstraintLayout
return card.apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
updateBackground(themeAttrs.popupElevation)
MaterialShapeUtils.setParentAbsoluteElevation(this)
// clipping to outline on <= API 28 prevents the edge treatment to apply
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
clipToOutline = true
}
}.also { contentView ->
contentView.findViewById<MaterialTextView>(R.id.tooltip_message).text = styler.message
val hasUpsell = styler.ctaLabel != null && styler.ctaOnClick != null
contentView.findViewById<MaterialButton>(R.id.tooltip_cta).apply {
isVisible = hasUpsell
if (hasUpsell) {
text = styler.ctaLabel
paintFlags = paintFlags or Paint.UNDERLINE_TEXT_FLAG
setOnClickListener { onClick() }
}
}
}
}
brandonmcansh
07/15/2021, 7:21 PMlawlorslaw
07/15/2021, 7:46 PMlawlorslaw
07/15/2021, 7:49 PMlawlorslaw
07/15/2021, 7:49 PMlawlorslaw
07/15/2021, 7:51 PMbrandonmcansh
07/15/2021, 7:55 PMbrandonmcansh
07/15/2021, 7:55 PMfun generateTriangleEdge(
offset: Float,
size: Float = 10.px.toFloat(),
inside: Boolean = false,
): TriangleEdgeTreatment {
return object : TriangleEdgeTreatment(size, inside) {
override fun getEdgePath(
length: Float,
center: Float,
interpolation: Float,
shapePath: ShapePath
) {
val offsetCenter = (center + offset)
shapePath.lineTo(offsetCenter - size * interpolation, 0f)
shapePath.lineTo(
offsetCenter,
if (inside) size * interpolation else -size * interpolation
)
shapePath.lineTo(offsetCenter + size * interpolation, 0f)
shapePath.lineTo(length, 0f)
}
}
}
lawlorslaw
07/15/2021, 7:59 PMlawlorslaw
07/15/2021, 7:59 PMlawlorslaw
07/15/2021, 7:59 PMbrandonmcansh
07/15/2021, 8:00 PMbrandonmcansh
07/15/2021, 8:01 PM