概览
在某些 Android 设备上,系统窗口(权限提示、对话框或屏幕键盘)在应用上方关闭后,应用的屏幕可能保持黑屏。应用仍在运行,但在下一次变化之前不会绘制任何内容。
KlugBlackScreen 会在此类窗口关闭后立即重绘应用的视图。启动时开启一次,即可在后台自动工作。对于特殊情况,也可以直接触发。
特性
- 自动模式:开启一次,每次系统窗口关闭后都会重绘
- 针对特殊情况的手动重绘
- 无闪烁的柔和重绘,以及针对顽固情况的强力重绘
- 在其他平台上不执行任何操作,因此代码可以保留在跨平台应用中
支持的平台
Android arm64 · armv7
入门
将扩展添加到您的应用描述文件中:
<extensions>
<extensionID>com.klug.blackscreen</extensionID>
</extensions>
代码示例
三个流程。每次调用都会立即返回,并在 Android UI 线程上完成工作;在其他平台上这些调用不执行任何操作。
1 · 在启动时开启一次
import com.klug.blackscreen.BlackScreen; // once, in the constructor of your main class: from now on the view is redrawn // whenever the app window gets the focus back, after a permission prompt, // a dialog, the keyboard or another activity BlackScreen.getInstance().startAuto(); // a second call has no effect // iOS, macOS and desktop: isSupported is false and every call does nothing, // so no platform check is needed. stopAuto() switches it off again (rarely needed).
2 · 系统窗口关闭后重绘
// call this from the result handler of any system window that covered the app: // a permission prompt, a share sheet, a native dialog, a sign-in page function onSystemWindowClosed():void { BlackScreen.getInstance().fix(); // redraw once, no flicker } // example: your own permission flow reports back myPermissionFlow.onResult = function( granted:Boolean ):void { onSystemWindowClosed(); if ( granted ) startCamera(); else showPermissionHint(); };
3 · 返回应用时的强力重绘
import flash.desktop.NativeApplication; import flash.events.Event; // back from another activity (share sheet, browser, system settings) and fix() // is not enough on a given runtime build: the stronger redraw may flicker once NativeApplication.nativeApplication.addEventListener( Event.ACTIVATE, function( e:Event ):void { BlackScreen.getInstance().fixHard(); }); // the first fixHard() replaces the launch background of the window with plain white, // so the short toggle does not show the splash image
API 概览
| BlackScreen.getInstance() | 返回唯一实例。 |
| isSupported | 在 Android 上为 True;在 iOS、macOS 和桌面上为 false,这些平台上每次调用都不执行任何操作。 |
| startAuto() | 每当应用窗口重新获得焦点时自动重绘,例如系统窗口关闭之后。启动时调用一次;再次调用无效。 |
| stopAuto() | 停止自动模式。 |
| fix() | 重绘视图一次,无闪烁。 |
| fixHard() | 针对顽固情况的强力重绘,会有短暂闪烁。首次调用会将窗口的启动背景替换为纯白色。 |
要求
| AIR SDK | 51.x (HARMAN) |
| Android | Android 6.0 (API 23) 或更高版本 |
| 权限 | 无 |