android:use QMUI to change statusbar status

This commit is contained in:
pengfei.zhou 2020-02-28 14:35:26 +08:00 committed by osborn
parent 0f7794b2f1
commit 7e7e9fed36
3 changed files with 20 additions and 27 deletions

View File

@ -54,6 +54,8 @@ dependencies {
implementation "androidx.navigation:navigation-fragment:$nav_version" implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version" implementation "androidx.navigation:navigation-ui:$nav_version"
implementation "com.qmuiteam:qmui:1.4.0"
} }
apply from: rootProject.file('scripts/upload.gradle') //apply from: rootProject.file('scripts/upload.gradle')

View File

@ -15,6 +15,7 @@
*/ */
package pub.doric.navbar; package pub.doric.navbar;
import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
@ -33,6 +34,11 @@ import android.widget.TextView;
import androidx.annotation.AttrRes; import androidx.annotation.AttrRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; 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; import pub.doric.R;
@ -85,27 +91,22 @@ public class BaseDoricNavBar extends FrameLayout implements IDoricNavBar {
return getVisibility() != VISIBLE; return getVisibility() != VISIBLE;
} }
@Override @Override
public void setHidden(boolean b) { public void setHidden(boolean b) {
if (getVisibility() == (b ? GONE : VISIBLE)) {
return;
}
setVisibility(b ? GONE : VISIBLE); setVisibility(b ? GONE : VISIBLE);
Activity activity = (Activity) getContext(); Activity activity = (Activity) getContext();
Window window = activity.getWindow(); Window window = activity.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (b) { if (b) {
window.getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN QMUIStatusBarHelper.translucent(activity);
| 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);
}
} else { } else {
int visibility = window.getDecorView().getSystemUiVisibility(); int visibility = window.getDecorView().getSystemUiVisibility();
visibility = visibility ^ (SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); visibility = visibility ^ (SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
window.getDecorView().setSystemUiVisibility(visibility); window.getDecorView().setSystemUiVisibility(visibility);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
} }

View File

@ -1,5 +1,6 @@
package pub.doric.plugin; package pub.doric.plugin;
import android.app.Activity;
import android.os.Build; import android.os.Build;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -9,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JavaValue; import com.github.pengfeizhou.jscore.JavaValue;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -24,8 +26,6 @@ import pub.doric.utils.ThreadMode;
@DoricPlugin(name = "statusbar") @DoricPlugin(name = "statusbar")
public class StatusBarPlugin extends DoricJavaPlugin { public class StatusBarPlugin extends DoricJavaPlugin {
private int currentMode = 0;
public StatusBarPlugin(DoricContext doricContext) { public StatusBarPlugin(DoricContext doricContext) {
super(doricContext); super(doricContext);
} }
@ -50,7 +50,6 @@ public class StatusBarPlugin extends DoricJavaPlugin {
} }
((BaseDoricNavBar) getDoricContext().getDoricNavBar()).setLayoutParams(lp); ((BaseDoricNavBar) getDoricContext().getDoricNavBar()).setLayoutParams(lp);
currentMode = 0;
return null; return null;
} }
}, ThreadMode.UI).setCallback(new AsyncResult.Callback<Object>() { }, ThreadMode.UI).setCallback(new AsyncResult.Callback<Object>() {
@ -84,20 +83,11 @@ public class StatusBarPlugin extends DoricJavaPlugin {
getDoricContext().getDriver().asyncCall(new Callable<Object>() { getDoricContext().getDriver().asyncCall(new Callable<Object>() {
@Override @Override
public Object call() { public Object call() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (mode == 0) {
AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext()); QMUIStatusBarHelper.setStatusBarLightMode((Activity) getDoricContext().getContext());
View decorView = activity.getWindow().getDecorView();
int flags = decorView.getSystemUiVisibility();
if (mode == currentMode) {
return null;
} else { } else {
currentMode = mode; QMUIStatusBarHelper.setStatusBarDarkMode((Activity) getDoricContext().getContext());
} }
flags ^= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
decorView.setSystemUiVisibility(flags);
}
return null; return null;
} }
}, ThreadMode.UI).setCallback(new AsyncResult.Callback<Object>() { }, ThreadMode.UI).setCallback(new AsyncResult.Callback<Object>() {