Options
All
  • Public
  • Public/Protected
  • All
Menu

Module floating_window

floating_window module provides the function to show floating window, check if the user has permission to show floating window, etc.

Because floating window module involves UI interaction, the function to show floating window needs to be run in UI thread, so at the start of the file you need to specify:

  • "ui-thread nodejs";:only floating window, no UI page activity
  • "ui nodejs"; :both floating window and UI page activity
  • "ui-thread";:only floating window, no UI page activity, and the file name ends with .node.js
  • "ui"; :both floating window and UI page activity, and the file name ends 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();

Index

Type aliases

KeepToEdgeType

KeepToEdgeType: "bounce" | boolean

Whether to automatically stick to the edge. If true, when dragging ends, the floating window will stick to the edge; if is "bounce", it will bounce multiple times and stick to the edge, like Auto.js Pro's floating window.

Variables

Const FLAG_DIM_BEHIND

FLAG_DIM_BEHIND: 2 = 0x00000002

Window flag: everything behind this window will be dimmed. Use {@link #dimAmount} to control the amount of dim.

see

FloatingWindow.addFlags

see

FloatingWindow.removeFlags

see

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_DIM_BEHIND

Const FLAG_FULLSCREEN

FLAG_FULLSCREEN: 1024 = 0x00000400

Window flag: hide all screen decorations (such as the status bar) while this window is displayed. This allows the window to use the entire display space for itself -- the status bar will be hidden when an app window with this flag set is on the top layer. A fullscreen window will ignore a value of {@link #SOFT_INPUT_ADJUST_RESIZE} for the window's {@link #softInputMode} field; the window will stay fullscreen and will not resize.

This flag can be controlled in your theme through the {@link android.R.attr#windowFullscreen} attribute; this attribute is automatically set for you in the standard fullscreen themes such as {@link android.R.style#Theme_NoTitleBar_Fullscreen}, {@link android.R.style#Theme_Black_NoTitleBar_Fullscreen}, {@link android.R.style#Theme_Light_NoTitleBar_Fullscreen}, {@link android.R.style#Theme_Holo_NoActionBar_Fullscreen}, {@link android.R.style#Theme_Holo_Light_NoActionBar_Fullscreen}, {@link android.R.style#Theme_DeviceDefault_NoActionBar_Fullscreen}, and {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_Fullscreen}.

deprecated

Use {@link WindowInsetsController#hide(int)} with {@link Type#statusBars()} instead.

see

FloatingWindow.addFlags

see

FloatingWindow.removeFlags

see

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_FULLSCREEN

Const FLAG_KEEP_SCREEN_ON

FLAG_KEEP_SCREEN_ON: 128 = 0x00000080

设置该标志让窗口显示时保持屏幕常亮。

Window flag: as long as this window is visible to the user, keep the device's screen turned on and bright.

see

FloatingWindow.addFlags

see

FloatingWindow.removeFlags

see

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON

Const FLAG_LAYOUT_IN_SCREEN

FLAG_LAYOUT_IN_SCREEN: 256 = 0x00000100

设置该标志让窗口保持在屏幕内显示。

Window flag for attached windows: Place the window within the entire screen, ignoring any constraints from the parent window.

Note: on displays that have a {@link DisplayCutout}, the window may be placed such that it avoids the {@link DisplayCutout} area if necessary according to the {@link #layoutInDisplayCutoutMode}.

Const FLAG_LAYOUT_NO_LIMITS

FLAG_LAYOUT_NO_LIMITS: 512 = 0x00000200

设置该标志让窗口可超出屏幕范围。

Window flag: allow window to extend outside of the screen.

see

FloatingWindow.addFlags

see

FloatingWindow.removeFlags

see

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_LAYOUT_NO_LIMITS

Const FLAG_NOT_FOCUSABLE

FLAG_NOT_FOCUSABLE: 8 = 0x00000008

设置该标志将让该窗口无法获得焦点。

Window flag: this window won't ever get key input focus, so the user can not send key or other button events to it. Those will instead go to whatever focusable window is behind it. This flag will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that is explicitly set.

Setting this flag also implies that the window will not need to interact with a soft input method, so it will be Z-ordered and positioned independently of any active input method (typically this means it gets Z-ordered on top of the input method, so it can use the full screen for its content and cover the input method if needed. You can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior.

see

FloatingWindow.addFlags

see

FloatingWindow.removeFlags

see

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_NOT_FOCUSABLE

Const FLAG_NOT_TOUCHABLE

FLAG_NOT_TOUCHABLE: 16 = 0x00000010

设置该标志将让该窗口无法获得触摸事件,但在Android 12及以上因系统安全限制无效。

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 {@link 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:

  1. Same UID: This window belongs to the same UID that owns the touch-consuming window.
  2. Trusted windows: This window is trusted. Trusted windows include (but are not limited to) accessibility windows ({@link #TYPE_ACCESSIBILITY_OVERLAY}), the IME ({@link #TYPE_INPUT_METHOD}) and assistant windows (TYPE_VOICE_INTERACTION). Windows of type {@link #TYPE_APPLICATION_OVERLAY} are not trusted, see below.
  3. Invisible windows: This window is {@link View#GONE} or {@link View#INVISIBLE}.
  4. Fully transparent windows: This window has {@link LayoutParams#alpha} equal to 0.
  5. One SAW window with enough transparency: This window is of type {@link #TYPE_APPLICATION_OVERLAY}, has {@link LayoutParams#alpha} below or equal to the maximum obscuring opacity (see below) and it's the only window of type {@link #TYPE_APPLICATION_OVERLAY} from this UID in the touch path.
  6. Multiple SAW windows with enough transparency: The multiple overlapping {@link #TYPE_APPLICATION_OVERLAY} windows in the touch path from this UID have a combined obscuring opacity below or equal to the maximum obscuring opacity. See section Combined obscuring opacity below on how to compute this value.

If none of these cases hold, the touch will not be delivered and a message will be logged to logcat.

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 {@link 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 {@link 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

FloatingWindow.addFlags

see

FloatingWindow.removeFlags

see

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_NOT_TOUCHABLE

Const FLAG_SECURE

FLAG_SECURE: 8192 = 0x00002000

设置该标志让窗口内容无法被截图、录屏。

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 {@link android.view.Display#FLAG_SECURE} for more details about secure surfaces and secure displays.

see

FloatingWindow.addFlags

see

FloatingWindow.removeFlags

see

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_SECURE

Const FLAG_WATCH_OUTSIDE_TOUCH

FLAG_WATCH_OUTSIDE_TOUCH: 262144 = 0x00040000

设置该标志后,窗口将可在有窗口外部的触摸事件时收到ACTION_OUTSIDE事件。

Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you can set this flag to receive a single special MotionEvent with the action {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for touches that occur outside of your window. Note that you will not receive the full down/move/up gesture, only the location of the first down as an ACTION_OUTSIDE.

see

FloatingWindow.addFlags

see

FloatingWindow.removeFlags

see

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_WATCH_OUTSIDE_TOUCH

Functions

canDrawOverlays

  • canDrawOverlays(): boolean
  • Whether the app has floating window permission.

    Returns boolean

    true if the app has floating window permission, otherwise false

createWindow

manageDrawOverlays

  • manageDrawOverlays(): void
  • Jump to the page to manage floating window permission.

    Returns void