From cf8574557e53140039b6d9b1f7b56781e3c38f40 Mon Sep 17 00:00:00 2001 From: jhj0517 <97279763+jhj0517@users.noreply.github.com> Date: Sat, 6 Apr 2024 16:11:51 +0900 Subject: [PATCH] refactor --- .../views/TooltipView.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Custom_ToolTip_Window/app/src/main/java/com/jhj0517/custom_tooltip_window/views/TooltipView.kt b/Custom_ToolTip_Window/app/src/main/java/com/jhj0517/custom_tooltip_window/views/TooltipView.kt index 592283f..6080dd1 100644 --- a/Custom_ToolTip_Window/app/src/main/java/com/jhj0517/custom_tooltip_window/views/TooltipView.kt +++ b/Custom_ToolTip_Window/app/src/main/java/com/jhj0517/custom_tooltip_window/views/TooltipView.kt @@ -12,6 +12,8 @@ import com.jhj0517.custom_tooltip_window.R import com.jhj0517.custom_tooltip_window.databinding.ViewTooltipBinding import com.jhj0517.custom_tooltip_window.models.ExampleData +const val TOOLTIP_BOTTOM_MARGIN = 20 + class TooltipView( private val context: Context, private val data: ExampleData, @@ -31,23 +33,26 @@ class TooltipView( addAnimation() addDismissListener() } + fun showToolTip() { - val screenPos = IntArray(2) // Get location of anchor view on screen + val screenPos = IntArray(2) anchor.getLocationOnScreen(screenPos) - // Get rect for anchor view + // Get rect with same size as anchor view val anchorRect = Rect( screenPos[0], screenPos[1], screenPos[0] - + anchor.width, screenPos[1] + anchor.height + + anchor.width, screenPos[1] + anchor.height ) + // Define where to show tooltip val posX = 0 - val posY = anchorRect.bottom + 20 + val posY = anchorRect.bottom + TOOLTIP_BOTTOM_MARGIN + tooltipWindow.contentView = binding.root tooltipWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, posX, posY) - if (showCheckMark){ + if (showCheckMark) { overlayCheckMark(anchor) } } @@ -82,6 +87,10 @@ class TooltipView( private fun addAnimation(){ // You can add your own animation here tooltipWindow.animationStyle = androidx.appcompat.R.style.Animation_AppCompat_DropDownUp + // Or you can set enter / exit transition as you want also + tooltipWindow.enterTransition = null + tooltipWindow.exitTransition = null + checkMarkWindow.animationStyle = androidx.appcompat.R.style.Animation_AppCompat_Dialog }