Skip to content

Commit 346268b

Browse files
committed
fix(tooltip): prevent focus stealing by adding requestFocus parameter
Extracts hover delay constant and disables focus request for editor action tooltips.
1 parent daaccab commit 346268b

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ open class EditorHandlerActivity :
437437
TooltipManager.showIdeCategoryTooltip(
438438
context = this@EditorHandlerActivity,
439439
anchorView = anchor,
440-
tag = action.retrieveTooltipTag(false)
440+
tag = action.retrieveTooltipTag(false),
441+
requestFocus = false,
441442
)
442443
},
443444
onHoverExit = {

common/src/main/java/com/itsaky/androidide/ui/ProjectActionsToolbar.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class ProjectActionsToolbar @JvmOverloads constructor(
2020
var onNavIconLongClick: (() -> Unit)? = null
2121
) : MaterialToolbar(context, attrs) {
2222

23+
companion object {
24+
private const val TOOLTIP_HOVER_SHOW_DELAY_MS = 600L
25+
}
26+
2327
init {
2428
// Navigation icon is no longer used in ProjectActionsToolbar
2529
// It's now handled by the title toolbar
@@ -71,7 +75,7 @@ class ProjectActionsToolbar @JvmOverloads constructor(
7175
MotionEvent.ACTION_HOVER_ENTER -> {
7276
hoverRunnable?.let { view.removeCallbacks(it) }
7377
hoverRunnable = Runnable { onHover?.invoke(view) }
74-
view.postDelayed(hoverRunnable, 600L)
78+
view.postDelayed(hoverRunnable, TOOLTIP_HOVER_SHOW_DELAY_MS)
7579
}
7680
MotionEvent.ACTION_HOVER_EXIT -> {
7781
hoverRunnable?.let { view.removeCallbacks(it) }
@@ -102,4 +106,3 @@ class ProjectActionsToolbar @JvmOverloads constructor(
102106
this.onNavIconLongClick = listener
103107
}
104108
}
105-

idetooltips/src/main/java/com/itsaky/androidide/idetooltips/ToolTipManager.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,29 @@ object TooltipManager {
180180

181181
// Displays a tooltip for category [TooltipCategory.CATEGORY_IDE] in a particular context
182182
// (An Activity, Fragment, Dialog etc)
183-
fun showIdeCategoryTooltip(context: Context, anchorView: View, tag: String) {
183+
fun showIdeCategoryTooltip(
184+
context: Context,
185+
anchorView: View,
186+
tag: String,
187+
requestFocus: Boolean = true,
188+
) {
184189
showTooltip(
185190
context = context,
186191
anchorView = anchorView,
187192
category = TooltipCategory.CATEGORY_IDE,
188-
tag = tag
193+
tag = tag,
194+
requestFocus = requestFocus,
189195
)
190196
}
191197

192198
// Displays a tooltip in a particular context with a specific category
193-
fun showTooltip(context: Context, anchorView: View, category: String, tag: String) {
199+
fun showTooltip(
200+
context: Context,
201+
anchorView: View,
202+
category: String,
203+
tag: String,
204+
requestFocus: Boolean = true,
205+
) {
194206
CoroutineScope(Dispatchers.Main).launch {
195207
val tooltipItem = getTooltip(
196208
context,
@@ -203,6 +215,7 @@ object TooltipManager {
203215
anchorView = anchorView,
204216
level = 0,
205217
tooltipItem = tooltipItem,
218+
requestFocus = requestFocus,
206219
onHelpLinkClicked = { context, url, title ->
207220
val intent =
208221
Intent(context, HelpActivity::class.java).apply {
@@ -229,20 +242,22 @@ object TooltipManager {
229242
anchorView: View,
230243
level: Int,
231244
tooltipItem: IDETooltipItem,
245+
requestFocus: Boolean,
232246
onHelpLinkClicked: (context: Context, url: String, title: String) -> Unit
233247
) {
234248
setupAndShowTooltipPopup(
235249
context = context,
236250
anchorView = anchorView,
237251
level = level,
238252
tooltipItem = tooltipItem,
253+
requestFocus = requestFocus,
239254
onActionButtonClick = { popupWindow, urlContent ->
240255
popupWindow.dismiss()
241256
onHelpLinkClicked(context, urlContent.first, urlContent.second)
242257
},
243258
onSeeMoreClicked = { popupWindow, nextLevel, item ->
244259
popupWindow.dismiss()
245-
showTooltipPopup(context, anchorView, nextLevel, item, onHelpLinkClicked)
260+
showTooltipPopup(context, anchorView, nextLevel, item, requestFocus, onHelpLinkClicked)
246261
}
247262
)
248263
}
@@ -279,6 +294,7 @@ object TooltipManager {
279294
anchorView: View,
280295
level: Int,
281296
tooltipItem: IDETooltipItem,
297+
requestFocus: Boolean,
282298
onActionButtonClick: (popupWindow: PopupWindow, url: Pair<String, String>) -> Unit,
283299
onSeeMoreClicked: (popupWindow: PopupWindow, nextLevel: Int, tooltipItem: IDETooltipItem) -> Unit,
284300
) {
@@ -394,7 +410,7 @@ object TooltipManager {
394410
}
395411
}
396412

397-
popupWindow.isFocusable = true
413+
popupWindow.isFocusable = requestFocus
398414
popupWindow.isOutsideTouchable = true
399415
if (anchorView.isInOverlayWindow()) {
400416
showOverlayTooltip(popupWindow, popupView, anchorView)

0 commit comments

Comments
 (0)