1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-12-17 21:29:36 +01:00

fix nav bar color on bottom sheet open

This commit is contained in:
Riko Sakurauchi 2019-07-20 11:10:47 +08:00
parent 5554de2bae
commit c9bc3d75ed
No known key found for this signature in database
GPG Key ID: 25AC0345B92902AF
2 changed files with 43 additions and 27 deletions

View File

@ -52,6 +52,8 @@ import org.telegram.ui.Components.LayoutHelper;
import java.util.ArrayList;
import tw.nekomimi.nekogram.UIHelper;
public class BottomSheet extends Dialog {
protected int currentAccount = UserConfig.selectedAccount;
@ -583,6 +585,7 @@ public class BottomSheet extends Dialog {
return insets.consumeSystemWindowInsets();
});
container.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
UIHelper.updateNavigationBarColor(getWindow());
}
backDrawable.setAlpha(0);

View File

@ -4,6 +4,7 @@ import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.core.graphics.ColorUtils;
@ -12,21 +13,21 @@ import org.telegram.ui.ActionBar.Theme;
public class UIHelper {
static private void setStatusBarColor(Activity parentActivity) {
static private void setStatusBarColor(Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (NekoConfig.transparentStatusBar &&
(Build.VERSION.SDK_INT < Build.VERSION_CODES.O || NekoConfig.navigationBarTint)) {
parentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
parentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
parentActivity.getWindow().setStatusBarColor(Color.TRANSPARENT);
setUIFlagLight(parentActivity);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
setUIFlagLight(window);
}
}
}
static private void setUIFlagLight(Activity parentActivity) {
static private void setUIFlagLight(Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
View view = parentActivity.getWindow().getDecorView();
View view = window.getDecorView();
int colorCode = Theme.getColor(Theme.key_actionBarDefault);
int flags = view.getSystemUiVisibility();
if (ColorUtils.calculateLuminance(colorCode) > 0.8 && NekoConfig.transparentStatusBar &&
@ -40,7 +41,7 @@ public class UIHelper {
}
}
static private void setNavigationBarColor(Activity parentActivity) {
static private void setNavigationBarColor(Window window) {
int color;
switch (NekoConfig.navigationBarColor) {
case 3:
@ -53,22 +54,22 @@ public class UIHelper {
default:
color = 0xff000000;
}
setNavigationBarColor(parentActivity, color);
setNavigationBarColor(window, color);
}
static private void setNavigationBarColor(Activity parentActivity, int color) {
static private void setNavigationBarColor(Window window, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (NekoConfig.navigationBarTint) {
parentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
parentActivity.getWindow().setNavigationBarColor(color);
setUIFlagLightNavBar(parentActivity, color);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setNavigationBarColor(color);
setUIFlagLightNavBar(window, color);
}
}
}
static private void setUIFlagLightNavBar(Activity parentActivity, int color) {
static private void setUIFlagLightNavBar(Window window, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
View view = parentActivity.getWindow().getDecorView();
View view = window.getDecorView();
int flags = view.getSystemUiVisibility();
if (ColorUtils.calculateLuminance(color) > 0.8 && NekoConfig.navigationBarTint) {
flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
@ -80,26 +81,34 @@ public class UIHelper {
}
}
static private void clearColor(Activity parentActivity) {
static private void clearColor(Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
parentActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
parentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
}
static public void updateStatusBarColor(Activity parentActivity) {
updateStatusBarColor(parentActivity.getWindow());
}
static public void updateStatusBarColor(Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (NekoConfig.transparentStatusBar) {
setStatusBarColor(parentActivity);
setStatusBarColor(window);
} else {
clearColor(parentActivity);
setNavigationBarColor(parentActivity);
clearColor(window);
setNavigationBarColor(window);
}
setUIFlagLight(parentActivity);
setUIFlagLight(window);
}
}
public static void updateNavigationBarColor(Activity parentActivity) {
updateNavigationBarColor(parentActivity.getWindow());
}
public static void updateNavigationBarColor(Window window) {
int color;
switch (NekoConfig.navigationBarColor) {
case 3:
@ -112,18 +121,22 @@ public class UIHelper {
default:
color = 0xff000000;
}
updateNavigationBarColor(parentActivity, color);
updateNavigationBarColor(window, color);
}
public static void updateNavigationBarColor(Activity parentActivity, int color) {
updateNavigationBarColor(parentActivity.getWindow(), color);
}
public static void updateNavigationBarColor(Window window, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (NekoConfig.navigationBarTint) {
setNavigationBarColor(parentActivity, color);
setNavigationBarColor(window, color);
} else {
clearColor(parentActivity);
setStatusBarColor(parentActivity);
clearColor(window);
setStatusBarColor(window);
}
setUIFlagLightNavBar(parentActivity, color);
setUIFlagLightNavBar(window, color);
}
}