floating_window - Floating window
The floating_window module provides floating-window display, overlay permission checks, and related helpers.
Because floating windows are UI, the script must run on the UI thread. Declare one of these at the top of the file:
"ui-thread nodejs";— floating window only, no full-screen UIActivity"ui nodejs";— both floating window and UIActivity"ui-thread";— floating window only, and the file name must end with.node.js"ui";— both floating window and UIActivity, and the file name must end with.node.js
Example
"ui-thread nodejs";
const { createWindow } = require("floating_window");
const window = createWindow();
window.setViewFromXml(`
<vertical bg="#ffffff">
<text text="Node.js: ${process.version}" textColor="#aa0000" textSize="16" width="*"/>
</vertical>
`);
window.show();
$autojs.keepRunning();Table of contents
Interfaces
Types
Constants
- FLAG_DIM_BEHIND
- FLAG_FULLSCREEN
- FLAG_KEEP_SCREEN_ON
- FLAG_LAYOUT_IN_SCREEN
- FLAG_LAYOUT_NO_LIMITS
- FLAG_NOT_FOCUSABLE
- FLAG_NOT_TOUCHABLE
- FLAG_SECURE
- FLAG_WATCH_OUTSIDE_TOUCH
Functions
Types
KeepToEdgeType
KeepToEdgeType: "bounce" | boolean
Snap-to-edge behavior after dragging. If true, the window snaps to the screen edge when the drag ends. If "bounce", it bounces a few times before snapping, similar to the built-in Auto.js Pro floating window.
Constants
FLAG_DIM_BEHIND
FLAG_DIM_BEHIND:2
Window flag: everything behind this window will be dimmed. Adjust strength with LayoutParams.dimAmount (see WindowManager.LayoutParams).
See also
FLAG_FULLSCREEN
FLAG_FULLSCREEN:1024
Window flag: hide system decorations such as the status bar while this window is on top, so content can use the full display. A fullscreen window typically ignores SOFT_INPUT_ADJUST_RESIZE in softInputMode: it stays fullscreen instead of resizing for the IME.
Themes can set this via windowFullscreen. Stock fullscreen themes (for example Theme.NoTitleBar.Fullscreen and newer Holo / DeviceDefault variants) enable it automatically.
Deprecated
Use WindowInsetsController#hide(int) with Type#statusBars() instead.
See also
FLAG_KEEP_SCREEN_ON
FLAG_KEEP_SCREEN_ON:128
When this flag is set, the screen stays on while the window is visible.
Window flag: as long as this window is visible to the user, keep the device's screen turned on and bright.
See also
FLAG_LAYOUT_IN_SCREEN
FLAG_LAYOUT_IN_SCREEN:256
When this flag is set, the window is laid out within the screen.
Window flag for attached windows: place the window within the entire screen, ignoring any constraints from the parent window.
Note: on displays with a display cutout, placement may follow layoutInDisplayCutoutMode on the window’s LayoutParams.
FLAG_LAYOUT_NO_LIMITS
FLAG_LAYOUT_NO_LIMITS:512
When this flag is set, the window may extend outside the screen bounds.
Window flag: allow window to extend outside of the screen.
See also
FLAG_NOT_FOCUSABLE
FLAG_NOT_FOCUSABLE:8
When this flag is set, the window cannot receive focus.
Window flag: this window never receives key focus, so key events go to the focusable window behind it. Setting this flag also implies FLAG_NOT_TOUCH_MODAL even if you do not add it yourself.
It also tends to decouple the window from the soft keyboard for Z-ordering (often drawn above the IME so content can cover the full screen). You can combine with FLAG_ALT_FOCUSABLE_IM if you need different IME interaction.
See also
FLAG_NOT_TOUCHABLE
FLAG_NOT_TOUCHABLE:16
When this flag is set, the window does not receive touch events. On Android 12 (API 31) and above, behavior is further restricted for security.
Window flag: this window can never receive touch events.
The intention of this flag is to leave the touch to be handled by some window below this window (in Z order).
Starting from Android Build.VERSION_CODES#S, for security reasons, touch events that pass through windows containing this flag (ie. are within the bounds of the window) will only be delivered to the touch-consuming window if one (or more) of the items below are true:
- Same UID: This window belongs to the same UID that owns the touch-consuming window.
- Trusted windows: Includes (but is not limited to)
TYPE_ACCESSIBILITY_OVERLAY, the IMETYPE_INPUT_METHOD, and assistant / voice-interaction layers.TYPE_APPLICATION_OVERLAYwindows are not trusted—see below. - Invisible windows: The view is
GONEorINVISIBLE. - Fully transparent windows:
LayoutParams.alphais 0. - Single overlay with enough transparency: One
TYPE_APPLICATION_OVERLAYwindow on the touch path, alpha ≤ maximum obscuring opacity, and the only overlay from this UID on that path. - Multiple overlays: Several overlapping
TYPE_APPLICATION_OVERLAYwindows from the same UID whose combined obscuring opacity is ≤ that maximum. If none of these cases apply, the touch may be dropped and logcat will show a message.
Maximum obscuring opacity
This value is 0.8. Apps that want to gather this value from the system rather than hard-coding it might want to use android.hardware.input.InputManager#getMaximumObscuringOpacityForTouch().
Combined obscuring opacity
The combined obscuring opacity of a set of windows is obtained by combining the opacity values of all windows in the set using the associative and commutative operation defined as:
opacity({A,B}) = 1 - (1 - opacity(A))*(1 - opacity(B))where {@code opacity(X)} is the LayoutParams#alpha of window X. So, for a set of windows {@code {W1, .., Wn}}, the combined obscuring opacity will be:
opacity({W1, .., Wn}) = 1 - (1 - opacity(W1)) * ... * (1 - opacity(Wn))See also
FLAG_SECURE
FLAG_SECURE:8192
When this flag is set, window content cannot be captured in screenshots or screen recordings.
Window flag: treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.
See also Display.FLAG_SECURE for secure surfaces and displays.
See also
FLAG_WATCH_OUTSIDE_TOUCH
FLAG_WATCH_OUTSIDE_TOUCH:262144
When this flag is set, the window can receive ACTION_OUTSIDE when the user touches outside the window bounds.
Requires FLAG_NOT_TOUCH_MODAL: you then get one synthetic MotionEvent for an outside touch—not a full down/move/up sequence, only the first outside ACTION_DOWN location as ACTION_OUTSIDE.
See also
Functions
canDrawOverlays
canDrawOverlays(): boolean
Returns whether this app can draw overlays (floating window permission).
Returns
boolean
true if overlay permission is granted, otherwise false.
createWindow
createWindow(options?: CreateWindowOptions ): FloatingWindow`
Creates a new floating window. Optional CreateWindowOptions set initial size, position, and other layout flags.
Parameters
options: Optional window creation options.
Returns
manageDrawOverlays
manageDrawOverlays(): void
Opens the system screen where the user can grant or revoke overlay permission for this app.
Returns
void
