diff --git a/floatingx/src/main/java/com/petterp/floatingx/impl/control/FxBasisControlImpl.kt b/floatingx/src/main/java/com/petterp/floatingx/impl/control/FxBasisControlImpl.kt index b614e22..e8d61c6 100644 --- a/floatingx/src/main/java/com/petterp/floatingx/impl/control/FxBasisControlImpl.kt +++ b/floatingx/src/main/java/com/petterp/floatingx/impl/control/FxBasisControlImpl.kt @@ -82,8 +82,7 @@ open class FxBasisControlImpl(private val helper: BasisHelper) : IFxControl, IFx } override fun updateView(provider: IFxContextProvider) { - val view = provider.build(context()) - updateView(view) + updateView(provider.build(context())) } override fun updateViewContent(provider: IFxHolderProvider) { @@ -207,7 +206,8 @@ open class FxBasisControlImpl(private val helper: BasisHelper) : IFxControl, IFx } protected open fun initManager() { - managerView = FxManagerView(context()).init(helper) + val context = context() ?: return + managerView = FxManagerView(context).init(helper) val fxContentView = managerView?.childFxView ?: return viewHolder = FxViewHolder(fxContentView) val fxViewLifecycle = helper.iFxViewLifecycle ?: return @@ -238,11 +238,12 @@ open class FxBasisControlImpl(private val helper: BasisHelper) : IFxControl, IFx detach(containerGroup) } - protected open fun context(): Context { - if (mContainer?.get()?.context == null) { - throw NullPointerException("context cannot be null") + protected open fun context(): Context? { + val context = mContainer?.get()?.context + if (context == null) { + helper.fxLog?.e("context = null,check your rule!") } - return mContainer?.get()?.context!! + return context } protected fun clearContainer() { diff --git a/floatingx/src/main/java/com/petterp/floatingx/listener/provider/IFxContextProvider.java b/floatingx/src/main/java/com/petterp/floatingx/listener/provider/IFxContextProvider.java index 2eead7b..aac29a6 100644 --- a/floatingx/src/main/java/com/petterp/floatingx/listener/provider/IFxContextProvider.java +++ b/floatingx/src/main/java/com/petterp/floatingx/listener/provider/IFxContextProvider.java @@ -4,6 +4,7 @@ import android.view.View; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; /** * Fx-Context提供者,用于构建合适的浮窗View @@ -12,6 +13,12 @@ * @author petterp */ public interface IFxContextProvider { + + /** + * 用于获取合适的context,从而构建合适位置的view + * + * @param context 注意该context在非全局浮窗时可能为null,建议在调用时注意做好check + */ @NonNull - View build(@NonNull Context context); + View build(@Nullable Context context); } diff --git a/floatingx/src/main/java/com/petterp/floatingx/util/FxScreenExt.kt b/floatingx/src/main/java/com/petterp/floatingx/util/FxScreenExt.kt index e06d496..46ffdde 100644 --- a/floatingx/src/main/java/com/petterp/floatingx/util/FxScreenExt.kt +++ b/floatingx/src/main/java/com/petterp/floatingx/util/FxScreenExt.kt @@ -161,11 +161,10 @@ private fun checkNavigationBarShow(context: Context): Boolean { val m = systemPropertiesClass.getMethod("get", String::class.java) val navBarOverride = m.invoke(systemPropertiesClass, "qemu.hw.mainkeys") as String // 判断是否隐藏了底部虚拟导航 - var navigationBarIsMin = 0 - navigationBarIsMin = Settings.Global.getInt( + val navigationBarIsMin: Int = Settings.Global.getInt( context.contentResolver, "navigationbar_is_min", - 0 + 0, ) if ("1" == navBarOverride || 1 == navigationBarIsMin) { hasNavigationBar = false @@ -262,7 +261,7 @@ private fun onePlusNavigationEnabled(context: Context): Int { if (result == 2 && Settings.System.getInt( context.contentResolver, "buttons_show_on_screen_navkeys", - 0 + 0, ) != 0 ) { // 两种手势 0有按钮, 1没有按钮 @@ -275,7 +274,7 @@ private fun samsungNavigationEnabled(context: Context): Int { return Settings.Global.getInt( context.contentResolver, "navigationbar_hide_bar_enabled", - 0 + 0, ) } @@ -285,17 +284,17 @@ private fun smartisanNavigationEnabled(context: Context): Int { private fun nokiaNavigationEnabled(context: Context): Int { val result = ( - Settings.Secure.getInt( + Settings.Secure.getInt( + context.contentResolver, + "swipe_up_to_switch_apps_enabled", + 0, + ) != 0 || + Settings.System.getInt( context.contentResolver, - "swipe_up_to_switch_apps_enabled", - 0 - ) != 0 || - Settings.System.getInt( - context.contentResolver, - "navigation_bar_can_hiden", - 0 - ) != 0 - ) + "navigation_bar_can_hiden", + 0, + ) != 0 + ) return if (result) { 1 } else {