Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ class DebugOverlayManager private constructor(
initialWindowY = overlayLayoutParams.y
initialTouchX = event.rawX
initialTouchY = event.rawY
isDragging = false
false
}

MotionEvent.ACTION_MOVE -> {
val deltaX = (event.rawX - initialTouchX).toInt()
val deltaY = (event.rawY - initialTouchY).toInt()
if (isDragging || deltaX > touchSlop || deltaY > touchSlop) {
v.parent.requestDisallowInterceptTouchEvent(true)
if (isDragging || abs(deltaX) > touchSlop || abs(deltaY) > touchSlop) {
isDragging = true
v.isPressed = false
v.parent.requestDisallowInterceptTouchEvent(true)
overlayLayoutParams.x = initialWindowX + deltaX
overlayLayoutParams.y = initialWindowY + deltaY
windowManager.updateViewLayout(binding.root, overlayLayoutParams)
Expand All @@ -62,13 +64,17 @@ class DebugOverlayManager private constructor(
}

MotionEvent.ACTION_UP -> {
isDragging = false
val deltaX = abs(event.rawX - initialTouchX)
val deltaY = abs(event.rawY - initialTouchY)
if (deltaX < touchSlop && deltaY < touchSlop) {
if (isDragging) {
isDragging = false
true
} else {
v.performClick()
}
true
false
}}

MotionEvent.ACTION_CANCEL -> {
isDragging = false
false
}

else -> false
Expand All @@ -78,7 +84,7 @@ class DebugOverlayManager private constructor(
binding.dragHandle.root.setOnLongClickListener { view ->
TooltipManager.showIdeCategoryTooltip(
context = view.context,
anchorView = view,
anchorView = view.rootView,
tag = TooltipTag.DEBUGGER_ACTION_MOVE
)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DebuggerActionsOverlayAdapter(
setOnLongClickListener {
TooltipManager.showIdeCategoryTooltip(
context = this.context,
anchorView = this,
anchorView = this.rootView,
tag = action.tooltipTag
)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,39 @@ object TooltipManager {

popupWindow.isFocusable = true
popupWindow.isOutsideTouchable = true
popupWindow.showAtLocation(anchorView, Gravity.CENTER, 0, 0)
if (anchorView.isInOverlayWindow()) {
showOverlayTooltip(popupWindow, popupView, anchorView)
} else {
popupWindow.showAtLocation(anchorView, Gravity.CENTER, 0, 0)
}

val iconTintColor = if (anchorView.isInOverlayWindow()) {
Color.WHITE
} else {
getColor(
context,
if (isDarkMode) ResR.color.tooltip_text_color_dark
else ResR.color.tooltip_text_color_light
)
}

val infoButton = popupView.findViewById<ImageButton>(R.id.icon_info)
infoButton.setOnClickListener {
onInfoButtonClicked(context, popupWindow, tooltipItem)
infoButton.apply {
setColorFilter(iconTintColor)
setOnClickListener {
onInfoButtonClicked(context, popupWindow, tooltipItem)
}
}

val feedbackButton = popupView.findViewById<ImageButton>(R.id.feedback_button)
val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse_animation)
feedbackButton.startAnimation(pulseAnimation)

feedbackButton.setOnClickListener {
onFeedbackButtonClicked(context, popupWindow, tooltipItem)
feedbackButton.apply {
setOnClickListener {
onFeedbackButtonClicked(context, popupWindow, tooltipItem)
}
setColorFilter(iconTintColor)
}
}

Expand Down Expand Up @@ -459,4 +479,33 @@ object TooltipManager {
""".trimIndent()
}

private fun View.isInOverlayWindow(): Boolean {
val params = layoutParams
return params is WindowManager.LayoutParams &&
params.type == WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
}

private fun showOverlayTooltip(
popupWindow: PopupWindow,
popupView: View,
parentView: View
) {
popupView.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
)

val popupWidth = popupView.measuredWidth
val popupHeight = popupView.measuredHeight

val displayMetrics = parentView.resources.displayMetrics
val screenWidth = displayMetrics.widthPixels
val screenHeight = displayMetrics.heightPixels

val x = (screenWidth - popupWidth) / 2
val y = (screenHeight - popupHeight) / 2

popupWindow.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y)
}

}