floating_window
CloudControl Pro 9 Docs / floating_window
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();
Table of contents
Interfaces
Type Aliases
Variables
- 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
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 CloudControl Pro's floating window.
Variables
FLAG_DIM_BEHIND
• Const
FLAG_DIM_BEHIND: 2
Window flag: everything behind this window will be dimmed. Use #dimAmount to control the amount of dim.
See
- addFlags
- removeFlags
- https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_DIM_BEHIND
FLAG_FULLSCREEN
• Const
FLAG_FULLSCREEN: 1024
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 #SOFT_INPUT_ADJUST_RESIZE for the window's #softInputMode field; the window will stay fullscreen and will not resize.
This flag can be controlled in your theme through the android.R.attr#windowFullscreen attribute; this attribute is automatically set for you in the standard fullscreen themes such as android.R.style#Theme_NoTitleBar_Fullscreen, android.R.style#Theme_Black_NoTitleBar_Fullscreen, android.R.style#Theme_Light_NoTitleBar_Fullscreen, android.R.style#Theme_Holo_NoActionBar_Fullscreen, android.R.style#Theme_Holo_Light_NoActionBar_Fullscreen, android.R.style#Theme_DeviceDefault_NoActionBar_Fullscreen, and android.R.style#Theme_DeviceDefault_Light_NoActionBar_Fullscreen.
Deprecated
Use WindowInsetsController#hide(int) with Type#statusBars() instead.
See
- addFlags
- removeFlags
- https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_FULLSCREEN
FLAG_KEEP_SCREEN_ON
• Const
FLAG_KEEP_SCREEN_ON: 128
设置该标志让窗口显示时保持屏幕常亮。
Window flag: as long as this window is visible to the user, keep the device's screen turned on and bright.
See
- addFlags
- removeFlags
- https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON
FLAG_LAYOUT_IN_SCREEN
• Const
FLAG_LAYOUT_IN_SCREEN: 256
设置该标志让窗口保持在屏幕内显示。
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 DisplayCutout, the window may be placed such that it avoids the DisplayCutout area if necessary according to the #layoutInDisplayCutoutMode.
FLAG_LAYOUT_NO_LIMITS
• Const
FLAG_LAYOUT_NO_LIMITS: 512
设置该标志让窗口可超出屏幕范围。
Window flag: allow window to extend outside of the screen.
See
- addFlags
- removeFlags
- https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_LAYOUT_NO_LIMITS
FLAG_NOT_FOCUSABLE
• Const
FLAG_NOT_FOCUSABLE: 8
设置该标志将让该窗口无法获得焦点。
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 #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 #FLAG_ALT_FOCUSABLE_IM to modify this behavior.
See
- addFlags
- removeFlags
- https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_NOT_FOCUSABLE
FLAG_NOT_TOUCHABLE
• Const
FLAG_NOT_TOUCHABLE: 16
设置该标志将让该窗口无法获得触摸事件,但在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 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: This window is trusted. Trusted windows include (but are not limited to) accessibility windows (#TYPE_ACCESSIBILITY_OVERLAY), the IME (#TYPE_INPUT_METHOD) and assistant windows (TYPE_VOICE_INTERACTION). Windows of type #TYPE_APPLICATION_OVERLAY are not trusted, see below.
- Invisible windows: This window is View#GONE or View#INVISIBLE.
- Fully transparent windows: This window has LayoutParams#alpha equal to 0.
- One SAW window with enough transparency: This window is of type #TYPE_APPLICATION_OVERLAY, has LayoutParams#alpha below or equal to the maximum obscuring opacity (see below) and it's the only window of type #TYPE_APPLICATION_OVERLAY from this UID in the touch path.
- Multiple SAW windows with enough transparency: The multiple overlapping #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 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
- addFlags
- removeFlags
- https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_NOT_TOUCHABLE
FLAG_SECURE
• Const
FLAG_SECURE: 8192
设置该标志让窗口内容无法被截图、录屏。
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 android.view.Display#FLAG_SECURE for more details about secure surfaces and secure displays.
See
- addFlags
- removeFlags
- https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_SECURE
FLAG_WATCH_OUTSIDE_TOUCH
• Const
FLAG_WATCH_OUTSIDE_TOUCH: 262144
设置该标志后,窗口将可在有窗口外部的触摸事件时收到ACTION_OUTSIDE事件。
Window flag: if you have set #FLAG_NOT_TOUCH_MODAL, you can set this flag to receive a single special MotionEvent with the action 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
- addFlags
- removeFlags
- 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
▸ createWindow(options?
): FloatingWindow
Create a new floating window, with options to specify the initial size, position, etc.
Parameters
Name | Type | Description |
---|---|---|
options? |
CreateWindowOptions |
create window options, see CreateWindowOptions |
Returns
manageDrawOverlays
▸ manageDrawOverlays(): void
Jump to the page to manage floating window permission.
Returns
void