From 8280145b2d52b5fd12fe678e449ca37fa22d50ba Mon Sep 17 00:00:00 2001 From: petterp Date: Tue, 26 Nov 2024 00:17:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=8C=BA=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../floatingx/assist/helper/FxAppHelper.kt | 11 ++++++++++- .../imp/app/FxAppPlatformProvider.kt | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/floatingx/src/main/java/com/petterp/floatingx/assist/helper/FxAppHelper.kt b/floatingx/src/main/java/com/petterp/floatingx/assist/helper/FxAppHelper.kt index 358b874..1b273b0 100644 --- a/floatingx/src/main/java/com/petterp/floatingx/assist/helper/FxAppHelper.kt +++ b/floatingx/src/main/java/com/petterp/floatingx/assist/helper/FxAppHelper.kt @@ -35,11 +35,12 @@ class FxAppHelper( @JvmSynthetic internal var editTextIds: List?, @JvmSynthetic + internal var isEnableSafeArea: Boolean, + @JvmSynthetic internal var isEnableKeyBoardAdapt: Boolean = false, /** 显示悬浮窗的Activity生命周期回调 */ @JvmSynthetic internal val fxLifecycleExpand: IFxProxyTagActivityLifecycle?, - @JvmSynthetic internal val fxAskPermissionInterceptor: IFxPermissionInterceptor?, ) : FxBasisHelper() { @@ -78,6 +79,7 @@ class FxAppHelper( private var editTextIds: List? = null private var isEnableKeyBoardAdapt: Boolean = false private var scopeEnum: FxScopeType = FxScopeType.APP + private var isEnableSafeArea: Boolean = true private var fxLifecycleExpand: IFxProxyTagActivityLifecycle? = null private var askPermissionInterceptor: IFxPermissionInterceptor? = null private var whiteInsertList: MutableList = mutableListOf() @@ -134,6 +136,12 @@ class FxAppHelper( return this } + /** 是否启用安全区,即禁止浮窗在状态栏与导航栏展示,仅限App浮窗有效 */ + fun setEnableSafeArea(isEnable: Boolean): Builder { + isEnableSafeArea = isEnable + return this + } + /** * 启用键盘适配,启用System浮窗将支持键盘弹出与关闭 * @param isEnable 是否启用 @@ -220,6 +228,7 @@ class FxAppHelper( isEnableAllInstall, scopeEnum, editTextIds, + isEnableSafeArea, isEnableKeyBoardAdapt, fxLifecycleExpand, askPermissionInterceptor, diff --git a/floatingx/src/main/java/com/petterp/floatingx/imp/app/FxAppPlatformProvider.kt b/floatingx/src/main/java/com/petterp/floatingx/imp/app/FxAppPlatformProvider.kt index b5eea06..e3c98a6 100644 --- a/floatingx/src/main/java/com/petterp/floatingx/imp/app/FxAppPlatformProvider.kt +++ b/floatingx/src/main/java/com/petterp/floatingx/imp/app/FxAppPlatformProvider.kt @@ -58,11 +58,9 @@ class FxAppPlatformProvider( return false } if (_internalView == null) { - initWindowsInsetsListener() - helper.updateNavigationBar(act) - helper.updateStatsBar(act) _internalView = FxDefaultContainerView(helper, helper.context) _internalView?.initView() + checkOrInitSafeArea(act) attach(act) } return true @@ -142,18 +140,21 @@ class FxAppPlatformProvider( _containerGroup = null } - private fun initWindowsInsetsListener() { - val fxView = _internalView ?: return - ViewCompat.setOnApplyWindowInsetsListener(fxView, windowsInsetsListener) - fxView.requestApplyInsets() - } - private fun checkRegisterAppLifecycle() { if (!helper.enableFx || _lifecycleImp != null) return _lifecycleImp = FxAppLifecycleImp(helper, control) helper.context.registerActivityLifecycleCallbacks(_lifecycleImp) } + private fun checkOrInitSafeArea(act: Activity) { + if (!helper.isEnableSafeArea) return + helper.updateStatsBar(act) + helper.updateNavigationBar(act) + val fxView = _internalView ?: return + ViewCompat.setOnApplyWindowInsetsListener(fxView, windowsInsetsListener) + fxView.requestApplyInsets() + } + private fun clearWindowsInsetsListener() { val managerView = _internalView ?: return ViewCompat.setOnApplyWindowInsetsListener(managerView, null)