Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 5, 2025

This PR implements the ability to block clicks outside app-level floating windows, providing Dialog-like modal behavior as requested in the original issue.

What's New

Block Outside Clicks Feature - App-level floating windows can now prevent user interaction with content behind them, similar to how Android Dialog works.

Implementation Details

API Changes

Builder Configuration:

private val modalFx by createFx {
    setLayout(R.layout.item_floating)
    setBlockOutsideClicks(true)  // Enable modal behavior
    setGravity(FxGravity.CENTER)
    build().toControl(this@YourActivity)
}

Runtime Control:

// Enable/disable at runtime
floatingWindowControl.configControl.setBlockOutsideClicks(true)
floatingWindowControl.configControl.setBlockOutsideClicks(false)

Technical Approach

  • Touch Interception: Uses OnTouchListener on the DecorView to intercept touch events
  • Coordinate Detection: Calculates floating window bounds using getLocationOnScreen() and compares with rawX/rawY coordinates
  • Selective Blocking: Only consumes touch events outside the floating window area
  • Efficient Design: No overlay views created, minimal performance impact
  • Proper Cleanup: Automatic cleanup when floating window is hidden or destroyed

Scope & Limitations

  • APP-level Only: Feature works exclusively with app-level floating windows (FxScopeType.APP)
  • Not for System Windows: System floating windows cannot block touches to other applications (by Android design)
  • Activity Scoped: Each Activity's floating windows are managed independently

Demo & Testing

Added comprehensive demo with BlockOutsideClicksTestActivity that demonstrates:

  • Background buttons that become unclickable when modal floating window is shown
  • Toggle functionality to enable/disable blocking behavior
  • Comparison between modal and normal floating window behavior

Documentation

  • Updated README files (Chinese & English) with new feature
  • Created detailed usage guide in BLOCK_OUTSIDE_CLICKS.md
  • Added unit tests for coordinate calculation logic

This feature directly addresses the original request: "能否像Dialog那样,不让touch outside?" - Now app-level floating windows can behave exactly like modal dialogs, preventing interaction with background content.

Fixes #212.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/8fdzzxam9lo77uruaibtsldo0/gradle-8.14.3/lib/gradle-daemon-main-8.14.3.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/8fdzzxam9lo77uruaibtsldo0/gradle-8.14.3/lib/agents/gradle-instrumentation-agent-8.14.3.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.14.3 (dns block)
  • jitpack.io
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/8fdzzxam9lo77uruaibtsldo0/gradle-8.14.3/lib/gradle-daemon-main-8.14.3.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/8fdzzxam9lo77uruaibtsldo0/gradle-8.14.3/lib/agents/gradle-instrumentation-agent-8.14.3.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.14.3 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits September 5, 2025 03:27
Co-authored-by: Petterpx <41142188+Petterpx@users.noreply.github.com>
Co-authored-by: Petterpx <41142188+Petterpx@users.noreply.github.com>
Co-authored-by: Petterpx <41142188+Petterpx@users.noreply.github.com>
Co-authored-by: Petterpx <41142188+Petterpx@users.noreply.github.com>
Copilot AI changed the title [WIP] App内的模式,能否实现屏蔽点击弹窗外部的区域 Add block outside clicks feature for app-level floating windows Sep 5, 2025
Copilot AI requested a review from Petterpx September 5, 2025 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App内的模式,能否实现屏蔽点击弹窗外部的区域

2 participants