diff --git a/doric-android/doric/build.gradle b/doric-android/doric/build.gradle index ed1ca4d1..8683a9ee 100644 --- a/doric-android/doric/build.gradle +++ b/doric-android/doric/build.gradle @@ -54,6 +54,8 @@ dependencies { implementation "androidx.navigation:navigation-fragment:$nav_version" implementation "androidx.navigation:navigation-ui:$nav_version" + + implementation "com.qmuiteam:qmui:1.4.0" } -apply from: rootProject.file('scripts/upload.gradle') \ No newline at end of file +//apply from: rootProject.file('scripts/upload.gradle') \ No newline at end of file diff --git a/doric-android/doric/src/main/java/pub/doric/navbar/BaseDoricNavBar.java b/doric-android/doric/src/main/java/pub/doric/navbar/BaseDoricNavBar.java index e458ba3f..089003d1 100644 --- a/doric-android/doric/src/main/java/pub/doric/navbar/BaseDoricNavBar.java +++ b/doric-android/doric/src/main/java/pub/doric/navbar/BaseDoricNavBar.java @@ -15,6 +15,7 @@ */ package pub.doric.navbar; +import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.graphics.Color; @@ -33,6 +34,11 @@ import android.widget.TextView; import androidx.annotation.AttrRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.view.ViewCompat; + +import com.qmuiteam.qmui.util.QMUIDeviceHelper; +import com.qmuiteam.qmui.util.QMUINotchHelper; +import com.qmuiteam.qmui.util.QMUIStatusBarHelper; import pub.doric.R; @@ -85,27 +91,22 @@ public class BaseDoricNavBar extends FrameLayout implements IDoricNavBar { return getVisibility() != VISIBLE; } + @Override public void setHidden(boolean b) { + if (getVisibility() == (b ? GONE : VISIBLE)) { + return; + } setVisibility(b ? GONE : VISIBLE); Activity activity = (Activity) getContext(); Window window = activity.getWindow(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (b) { - window.getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | SYSTEM_UI_FLAG_LAYOUT_STABLE); - - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.setStatusBarColor(Color.TRANSPARENT); - } + QMUIStatusBarHelper.translucent(activity); } else { int visibility = window.getDecorView().getSystemUiVisibility(); visibility = visibility ^ (SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); window.getDecorView().setSystemUiVisibility(visibility); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); } diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/StatusBarPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/StatusBarPlugin.java index 89ae2a2e..b1a5c179 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/StatusBarPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/StatusBarPlugin.java @@ -1,5 +1,6 @@ package pub.doric.plugin; +import android.app.Activity; import android.os.Build; import android.view.View; import android.widget.LinearLayout; @@ -9,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity; import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JavaValue; +import com.qmuiteam.qmui.util.QMUIStatusBarHelper; import java.util.concurrent.Callable; @@ -24,8 +26,6 @@ import pub.doric.utils.ThreadMode; @DoricPlugin(name = "statusbar") public class StatusBarPlugin extends DoricJavaPlugin { - private int currentMode = 0; - public StatusBarPlugin(DoricContext doricContext) { super(doricContext); } @@ -50,7 +50,6 @@ public class StatusBarPlugin extends DoricJavaPlugin { } ((BaseDoricNavBar) getDoricContext().getDoricNavBar()).setLayoutParams(lp); - currentMode = 0; return null; } }, ThreadMode.UI).setCallback(new AsyncResult.Callback() { @@ -84,20 +83,11 @@ public class StatusBarPlugin extends DoricJavaPlugin { getDoricContext().getDriver().asyncCall(new Callable() { @Override public Object call() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext()); - View decorView = activity.getWindow().getDecorView(); - - int flags = decorView.getSystemUiVisibility(); - if (mode == currentMode) { - return null; - } else { - currentMode = mode; - } - flags ^= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; - decorView.setSystemUiVisibility(flags); + if (mode == 0) { + QMUIStatusBarHelper.setStatusBarLightMode((Activity) getDoricContext().getContext()); + } else { + QMUIStatusBarHelper.setStatusBarDarkMode((Activity) getDoricContext().getContext()); } - return null; } }, ThreadMode.UI).setCallback(new AsyncResult.Callback() {