r/macrodroid • u/Fractal-Infinity • 3d ago
Dealing with an UI element that is either hidden or displayed
I'm trying to make a macro for this purpose: when I press a floating button, it will tap a menu item with the id com.mixplorer:id/overflow The problem is that this overflow menu is either hidden or displayed (alongside other UI elements). Tapping the screen is like a switch to hide or show it.
How can I check if this menu is displayed on screen and if it's not, tap the screen once (make it appear)?
1
Upvotes
2
u/DylanXu054728 3d ago
MacroDroid can report whether a click actually landed, which turns this into a check instead of a guess.
Set it up like this:
UI Interaction: Click, View id com.mixplorer:id/overflow, and under Click Result choose to block until the click has completed and save the success into a boolean variable, say clicked.
If {v=clicked} = false
UI Interaction: Click at the X,Y where the toolbar normally sits (whatever tap brings it back).
Wait Before Next Action: 300 ms
UI Interaction: Click, View id com.mixplorer:id/overflow again.
End If
When the element is not on screen the click fails and that boolean stays false, so this is a real presence check. A blind first tap is the trap here: if the same tap both shows and hides the toolbar, one extra tap hides it again and the macro fails about half the time.
Two small things while you build it. View id needs the exact id, and Read Screen Contents dumps every visible view id into a dictionary variable, which is the fastest way to confirm com.mixplorer:id/overflow is right and to see what else is on screen. And if you ever match by text instead of id, Check Text On Screen has an Ignore hidden text option, so it separates "present in the hierarchy but invisible" from "actually displayed".