OverlayController

class OverlayController(context: Context)

Programmatic floating-overlay primitive. Host apps wire this to a settings toggle; no LLM tools expose it directly. Uses TYPE_APPLICATION_OVERLAY so it survives on top of other apps (requires SYSTEM_ALERT_WINDOW permission granted via permissionIntent).

Threading. show and hide may be called from any thread: WindowManager view operations must run on the main thread, so off-main calls are posted to the main looper (and therefore take effect asynchronously). Calls made on the main thread run synchronously.

Constructors

Link copied to clipboard
constructor(context: Context)

Functions

Link copied to clipboard
fun hide()

Remove the overlay if showing. Safe to call from any thread (off-main calls are posted to the main looper). The controller only forgets the view once WindowManager.removeView succeeds (or the view is already detached), so a failed removal can be retried.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun show(config: OverlayConfig)

Show the overlay. Idempotent — calling while already showing replaces the existing overlay with the new config. Safe to call from any thread (off-main calls are posted to the main looper). No-op when the overlay permission is missing, or when the previous overlay could not be removed (so overlays never stack).

fun show(label: String, onClick: () -> Unit)

Convenience overload — equivalent to show(OverlayConfig(label = label, onClick = onClick)).