nav bar and status bar

This commit is contained in:
Riko Sakurauchi 2020-01-01 21:26:18 +08:00
parent 0326c187ad
commit fb177cd090
No known key found for this signature in database
GPG Key ID: 25AC0345B92902AF
8 changed files with 15 additions and 242 deletions

View File

@ -3208,17 +3208,24 @@ public class AndroidUtilities {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final View decorView = window.getDecorView();
int flags = decorView.getSystemUiVisibility();
if (NekoConfig.transparentStatusBar) {
window.setStatusBarColor(Color.TRANSPARENT);
}
if (enable) {
if (!NekoConfig.transparentStatusBar) {
window.setStatusBarColor(0x0f000000);
}
if ((flags & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) == 0) {
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
decorView.setSystemUiVisibility(flags);
window.setStatusBarColor(0x0f000000);
}
} else {
if (!NekoConfig.transparentStatusBar) {
window.setStatusBarColor(0x33000000);
}
if ((flags & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) != 0) {
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
decorView.setSystemUiVisibility(flags);
window.setStatusBarColor(0x33000000);
}
}
}

View File

@ -48,8 +48,6 @@ import org.telegram.ui.Components.LayoutHelper;
import java.util.ArrayList;
import tw.nekomimi.nekogram.UIHelper;
public class ActionBarLayout extends FrameLayout {
public interface ActionBarLayoutDelegate {
@ -234,8 +232,6 @@ public class ActionBarLayout extends FrameLayout {
for (BaseFragment fragment : fragmentsStack) {
fragment.setParentLayout(this);
}
UIHelper.updateStatusBarColor(parentActivity);
UIHelper.updateNavigationBarColor(parentActivity);
}
@Override
@ -1435,8 +1431,6 @@ public class ActionBarLayout extends FrameLayout {
Theme.setAnimatingColor(false);
presentingFragmentDescriptions = null;
themeAnimatorSet = null;
UIHelper.updateStatusBarColor(parentActivity);
UIHelper.updateNavigationBarColor(parentActivity);
}
}
@ -1452,8 +1446,6 @@ public class ActionBarLayout extends FrameLayout {
Theme.setAnimatingColor(false);
presentingFragmentDescriptions = null;
themeAnimatorSet = null;
UIHelper.updateStatusBarColor(parentActivity);
UIHelper.updateNavigationBarColor(parentActivity);
}
}
});
@ -1487,8 +1479,6 @@ public class ActionBarLayout extends FrameLayout {
if (showLastAfter) {
showLastFragment();
}
UIHelper.updateStatusBarColor(parentActivity);
UIHelper.updateNavigationBarColor(parentActivity);
}
public boolean onKeyUp(int keyCode, KeyEvent event) {

View File

@ -54,8 +54,6 @@ 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;
@ -598,7 +596,6 @@ 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

@ -77,8 +77,6 @@ import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import tw.nekomimi.nekogram.UIHelper;
public class ThemeEditorView {
private FrameLayout windowView;
@ -896,8 +894,6 @@ public class ThemeEditorView {
for (int a = 0; a < currentThemeDesription.size(); a++) {
currentThemeDesription.get(a).setDefaultColor();
}
UIHelper.updateStatusBarColor(parentActivity);
UIHelper.updateNavigationBarColor(parentActivity);
setColorPickerVisible(false);
});
@ -911,8 +907,6 @@ public class ThemeEditorView {
saveButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
linearLayout.addView(saveButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
saveButton.setOnClickListener(v -> {
UIHelper.updateStatusBarColor(parentActivity);
UIHelper.updateNavigationBarColor(parentActivity);
setColorPickerVisible(false);
});
}

View File

@ -178,8 +178,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import tw.nekomimi.nekogram.UIHelper;
@SuppressWarnings("unchecked")
public class PhotoViewer implements NotificationCenter.NotificationCenterDelegate, GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
@ -7104,7 +7102,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
UIHelper.updateNavigationBarColor(parentActivity, 0xff0000);
} else {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
}
@ -7870,7 +7867,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (object != null) {
object.imageReceiver.setVisible(true, true);
}
UIHelper.updateNavigationBarColor(parentActivity);
}
private void redraw(final int count) {

View File

@ -19,8 +19,6 @@ public class NekoConfig {
public static int nameOrder = 1;
public static int mapPreviewProvider = 0;
public static boolean transparentStatusBar = true;
public static boolean navigationBarTint = true;
public static int navigationBarColor = 2;
public static boolean residentNotification = false;
public static boolean showAddToSavedMessages = true;
@ -54,8 +52,6 @@ public class NekoConfig {
editor.putInt("nameOrder", nameOrder);
editor.putInt("mapPreviewProvider", mapPreviewProvider);
editor.putBoolean("transparentStatusBar", transparentStatusBar);
editor.putBoolean("navigationBarTint", navigationBarTint);
editor.putInt("navigationBarColor", navigationBarColor);
editor.putBoolean("residentNotification", residentNotification);
editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages);
editor.putBoolean("showReport", showReport);
@ -89,8 +85,6 @@ public class NekoConfig {
nameOrder = preferences.getInt("nameOrder", 1);
mapPreviewProvider = preferences.getInt("mapPreviewProvider", 0);
transparentStatusBar = preferences.getBoolean("transparentStatusBar", true);
navigationBarTint = preferences.getBoolean("navigationBarTint", true);
navigationBarColor = preferences.getInt("navigationBarColor", 2);
residentNotification = preferences.getBoolean("residentNotification", false);
showAddToSavedMessages = preferences.getBoolean("showAddToSavedMessages", true);
showReport = preferences.getBoolean("showReport", false);
@ -211,22 +205,6 @@ public class NekoConfig {
editor.commit();
}
public static void toggleNavigationBarTint() {
navigationBarTint = !navigationBarTint;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("navigationBarTint", navigationBarTint);
editor.commit();
}
public static void setNavigationBarColor(int color) {
navigationBarColor = color;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("navigationBarColor", navigationBarColor);
editor.commit();
}
public static void toggleResidentNotification() {
residentNotification = !residentNotification;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);

View File

@ -21,6 +21,7 @@ import org.telegram.messenger.BuildVars;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.UserConfig;
@ -74,8 +75,6 @@ public class NekoSettingsActivity extends BaseFragment {
private int hidePhoneRow;
private int nameOrderRow;
private int transparentStatusBarRow;
private int navigationBarTintRow;
private int navigationBarColorRow;
private int forceTabletRow;
private int xmasRow;
private int newYearRow;
@ -186,37 +185,11 @@ public class NekoSettingsActivity extends BaseFragment {
((TextCheckCell) view).setChecked(NekoConfig.ignoreBlocked);
}
} else if (position == transparentStatusBarRow) {
if (!(NekoConfig.navigationBarTint || Build.VERSION.SDK_INT < Build.VERSION_CODES.O))
return;
NekoConfig.toggleTransparentStatusBar();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.transparentStatusBar);
}
UIHelper.updateStatusBarColor(getParentActivity());
} else if (position == navigationBarTintRow) {
NekoConfig.toggleNavigationBarTint();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.navigationBarTint);
}
updateRows(true);
UIHelper.updateStatusBarColor(getParentActivity());
UIHelper.updateNavigationBarColor(getParentActivity());
} else if (position == navigationBarColorRow) {
if (!NekoConfig.navigationBarTint)
return;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("NavigationBarColor", R.string.NavigationBarColor));
CharSequence[] items = new CharSequence[]{
LocaleController.getString("NavigationBarColorBlack", R.string.NavigationBarColorBlack),
LocaleController.getString("NavigationBarColorActionBar", R.string.NavigationBarColorActionBar),
LocaleController.getString("NavigationBarColorMessagePanel", R.string.NavigationBarColorMessagePanel),
};
builder.setItems(items, (dialog, which) -> {
NekoConfig.setNavigationBarColor(which + 1);
listAdapter.notifyItemChanged(navigationBarColorRow);
UIHelper.updateNavigationBarColor(getParentActivity());
});
showDialog(builder.create());
AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didSetNewTheme, false));
} else if (position == useSystemEmojiRow) {
SharedConfig.useSystemEmoji = !SharedConfig.useSystemEmoji;
SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit();
@ -310,9 +283,7 @@ public class NekoSettingsActivity extends BaseFragment {
settingsRow = rowCount++;
hidePhoneRow = rowCount++;
typefaceRow = rowCount++;
navigationBarTintRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? rowCount++ : -1;
transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1;
navigationBarColorRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? rowCount++ : -1;
forceTabletRow = rowCount++;
nameOrderRow = rowCount++;
xmasRow = rowCount++;
@ -398,20 +369,6 @@ public class NekoSettingsActivity extends BaseFragment {
break;
}
textCell.setTextAndValue(LocaleController.getString("NameOrder", R.string.NameOrder), value, true);
} else if (position == navigationBarColorRow) {
String value;
switch (NekoConfig.navigationBarColor) {
case 3:
value = LocaleController.getString("NavigationBarColorMessagePanel", R.string.NavigationBarColorMessagePanel);
break;
case 2:
value = LocaleController.getString("NavigationBarColorActionBar", R.string.NavigationBarColorActionBar);
break;
case 1:
default:
value = LocaleController.getString("NavigationBarColorBlack", R.string.NavigationBarColorBlack);
}
textCell.setTextAndValue(LocaleController.getString("NavigationBarColor", R.string.NavigationBarColor), value, true);
} else if (position == mapPreviewRow) {
String value;
switch (NekoConfig.mapPreviewProvider) {
@ -449,8 +406,6 @@ public class NekoSettingsActivity extends BaseFragment {
textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), SharedConfig.inappCamera, true);
} else if (position == transparentStatusBarRow) {
textCell.setTextAndCheck(LocaleController.getString("TransparentStatusBar", R.string.TransparentStatusBar), NekoConfig.transparentStatusBar, true);
} else if (position == navigationBarTintRow) {
textCell.setTextAndCheck(LocaleController.getString("NavigationBarTint", R.string.NavigationBarTint), NekoConfig.navigationBarTint, true);
} else if (position == useSystemEmojiRow) {
textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), SharedConfig.useSystemEmoji, true);
} else if (position == typefaceRow) {
@ -496,14 +451,13 @@ public class NekoSettingsActivity extends BaseFragment {
@Override
public boolean isEnabled(RecyclerView.ViewHolder holder) {
int position = holder.getAdapterPosition();
return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow || position == navigationBarTintRow ||
return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow ||
position == useSystemEmojiRow || position == ipv6Row || position == typefaceRow ||
position == showChangePermissionsRow || position == showAdminActionsRow || position == showReportRow ||
position == showPrPrRow || position == showAddToSavedMessagesRow ||
position == nameOrderRow || position == forceTabletRow || position == mapPreviewRow ||
position == xmasRow || position == newYearRow || position == newYearEveRow || position == fireworksRow ||
(position == transparentStatusBarRow && (NekoConfig.navigationBarTint || Build.VERSION.SDK_INT < Build.VERSION_CODES.O)) ||
(position == navigationBarColorRow && NekoConfig.navigationBarTint);
position == transparentStatusBarRow;
}
@Override
@ -546,12 +500,12 @@ public class NekoSettingsActivity extends BaseFragment {
public int getItemViewType(int position) {
if (position == messageMenu2Row || position == connection2Row || position == chat2Row) {
return 1;
} else if (position == nameOrderRow || position == navigationBarColorRow || position == mapPreviewRow) {
} else if (position == nameOrderRow || position == mapPreviewRow) {
return 2;
} else if (position == ipv6Row || position == hidePhoneRow || position == inappCameraRow ||
position == showAddToSavedMessagesRow || position == showPrPrRow || position == showReportRow ||
position == showAdminActionsRow || position == showChangePermissionsRow ||
position == transparentStatusBarRow || position == navigationBarTintRow ||
position == transparentStatusBarRow ||
position == ignoreBlockedRow || position == useSystemEmojiRow || position == typefaceRow ||
position == forceTabletRow || position == xmasRow || position == newYearRow || position == newYearEveRow ||
position == fireworksRow) {

View File

@ -1,143 +0,0 @@
package tw.nekomimi.nekogram;
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;
import org.telegram.ui.ActionBar.Theme;
public class UIHelper {
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)) {
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(Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
View view = window.getDecorView();
int colorCode = Theme.getColor(Theme.key_actionBarDefault);
int flags = view.getSystemUiVisibility();
if (ColorUtils.calculateLuminance(colorCode) > 0.8 && NekoConfig.transparentStatusBar &&
(Build.VERSION.SDK_INT < Build.VERSION_CODES.O || NekoConfig.navigationBarTint)) {
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
view.setSystemUiVisibility(flags);
} else {
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
view.setSystemUiVisibility(flags);
}
}
}
static private void setNavigationBarColor(Window window) {
int color;
switch (NekoConfig.navigationBarColor) {
case 3:
color = Theme.getColor(Theme.key_chat_messagePanelBackground);
break;
case 2:
color = Theme.getColor(Theme.key_actionBarDefault);
break;
case 1:
default:
color = 0xff000000;
}
setNavigationBarColor(window, color);
}
static private void setNavigationBarColor(Window window, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (NekoConfig.navigationBarTint) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setNavigationBarColor(color);
setUIFlagLightNavBar(window, color);
}
}
}
static private void setUIFlagLightNavBar(Window window, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
View view = window.getDecorView();
int flags = view.getSystemUiVisibility();
if (ColorUtils.calculateLuminance(color) > 0.8 && NekoConfig.navigationBarTint) {
flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
view.setSystemUiVisibility(flags);
} else {
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
view.setSystemUiVisibility(flags);
}
}
}
static private void clearColor(Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
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(window);
} else {
clearColor(window);
setNavigationBarColor(window);
}
setUIFlagLight(window);
}
}
public static void updateNavigationBarColor(Activity parentActivity) {
updateNavigationBarColor(parentActivity.getWindow());
}
public static void updateNavigationBarColor(Window window) {
int color;
switch (NekoConfig.navigationBarColor) {
case 3:
color = Theme.getColor(Theme.key_chat_messagePanelBackground);
break;
case 2:
color = Theme.getColor(Theme.key_actionBarDefault);
break;
case 1:
default:
color = 0xff000000;
}
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(window, color);
} else {
clearColor(window);
setStatusBarColor(window);
}
setUIFlagLightNavBar(window, color);
}
}
}