From a50ef5d6c77690bef23f7449276f3dac21679a41 Mon Sep 17 00:00:00 2001 From: autenYang Date: Wed, 28 Aug 2019 14:50:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DContext=E5=BC=95=E7=94=A8=20?= =?UTF-8?q?=E5=BC=95=E8=B5=B7=E7=9A=84=20=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/navbar/NavigationBarObserver.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/com/lxj/xpopup/util/navbar/NavigationBarObserver.java b/library/src/main/java/com/lxj/xpopup/util/navbar/NavigationBarObserver.java index 6e2af7f5..e814449c 100644 --- a/library/src/main/java/com/lxj/xpopup/util/navbar/NavigationBarObserver.java +++ b/library/src/main/java/com/lxj/xpopup/util/navbar/NavigationBarObserver.java @@ -27,7 +27,7 @@ public final class NavigationBarObserver extends ContentObserver { static final String IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW = "navigationbar_is_min"; private ArrayList mListeners; - private Context context; + private Context mAppContext; private Boolean mIsRegister = false; public static NavigationBarObserver getInstance() { @@ -39,9 +39,9 @@ private NavigationBarObserver() { } public void register(Context context) { - this.context = context; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && context != null - && context.getContentResolver() != null && !mIsRegister) { + this.mAppContext = context.getApplicationContext(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mAppContext != null + && mAppContext.getContentResolver() != null && !mIsRegister) { Uri uri = null; if (OSUtils.isMIUI()) { uri = Settings.Global.getUriFor(IMMERSION_MIUI_NAVIGATION_BAR_HIDE_SHOW); @@ -53,7 +53,7 @@ public void register(Context context) { } } if (uri != null) { - context.getContentResolver().registerContentObserver(uri, true, this); + mAppContext.getContentResolver().registerContentObserver(uri, true, this); mIsRegister = true; } } @@ -62,16 +62,16 @@ public void register(Context context) { @Override public void onChange(boolean selfChange) { super.onChange(selfChange); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && context != null && context.getContentResolver() != null + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mAppContext != null && mAppContext.getContentResolver() != null && mListeners != null && !mListeners.isEmpty()) { int show = 0; if (OSUtils.isMIUI()) { - show = Settings.Global.getInt(context.getContentResolver(), IMMERSION_MIUI_NAVIGATION_BAR_HIDE_SHOW, 0); + show = Settings.Global.getInt(mAppContext.getContentResolver(), IMMERSION_MIUI_NAVIGATION_BAR_HIDE_SHOW, 0); } else if (OSUtils.isEMUI()) { if (OSUtils.isEMUI3_x() || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - show = Settings.System.getInt(context.getContentResolver(), IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW, 0); + show = Settings.System.getInt(mAppContext.getContentResolver(), IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW, 0); } else { - show = Settings.Global.getInt(context.getContentResolver(), IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW, 0); + show = Settings.Global.getInt(mAppContext.getContentResolver(), IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW, 0); } } for (OnNavigationBarListener onNavigationBarListener : mListeners) {