Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:增加浮窗context初始化时的null check #118

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* Fx-Context提供者,用于构建合适的浮窗View
Expand All @@ -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);
}
29 changes: 14 additions & 15 deletions floatingx/src/main/java/com/petterp/floatingx/util/FxScreenExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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没有按钮
Expand All @@ -275,7 +274,7 @@ private fun samsungNavigationEnabled(context: Context): Int {
return Settings.Global.getInt(
context.contentResolver,
"navigationbar_hide_bar_enabled",
0
0,
)
}

Expand All @@ -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 {
Expand Down
Loading