android:use QMUI to change statusbar status
This commit is contained in:
parent
0f7794b2f1
commit
7e7e9fed36
@ -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')
|
||||
//apply from: rootProject.file('scripts/upload.gradle')
|
@ -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);
|
||||
}
|
||||
|
@ -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<Object>() {
|
||||
@ -84,20 +83,11 @@ public class StatusBarPlugin extends DoricJavaPlugin {
|
||||
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
|
||||
@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<Object>() {
|
||||
|
Reference in New Issue
Block a user