Use primary color for navigation bar

pull/757/head
Alex Baker 6 years ago
parent cd97dcf81b
commit cd198d82f5

@ -8,6 +8,8 @@ package com.todoroo.andlib.utility;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.View;
@ -195,6 +197,10 @@ public class AndroidUtilities {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
public static boolean atLeastOreoMR1() {
return VERSION.SDK_INT >= VERSION_CODES.O_MR1;
}
public static boolean atLeastNougat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
}

@ -260,6 +260,7 @@ public class MainActivity extends InjectingAppCompatActivity
ThemeColor filterColor = getFilterColor();
filterColor.applyToStatusBar(drawerLayout);
filterColor.applyToNavigationBar(this);
filterColor.applyTaskDescription(this, filter.listingTitle);
theme.withThemeColor(filterColor).applyToContext(this);
}

@ -321,6 +321,6 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi
color.setText(themeColor.getName());
}
themeColor.apply(toolbar);
themeColor.applyToStatusBar(this);
themeColor.applyToSystemBars(this);
}
}

@ -281,7 +281,7 @@ public class TagSettingsActivity extends ThemedInjectingAppCompatActivity
color.setText(themeColor.getName());
}
themeColor.apply(toolbar);
themeColor.applyToStatusBar(this);
themeColor.applyToSystemBars(this);
}
@Override

@ -336,7 +336,7 @@ public class CaldavCalendarSettingsActivity extends ThemedInjectingAppCompatActi
color.setText(themeColor.getName());
}
themeColor.apply(toolbar);
themeColor.applyToStatusBar(this);
themeColor.applyToSystemBars(this);
}
@Override

@ -54,7 +54,7 @@ public class Theme {
}
public void applyStatusBarColor(Activity activity) {
themeColor.applyToStatusBar(activity);
themeColor.applyToSystemBars(activity);
themeColor.applyTaskDescription(activity, activity.getString(R.string.app_name));
}

@ -2,6 +2,7 @@ package org.tasks.themes;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastOreoMR1;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
@ -9,6 +10,7 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.content.res.Resources;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Parcel;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.widget.Toolbar;
@ -140,7 +142,7 @@ public class ThemeColor implements ColorPickerDialog.Pickable {
}
@SuppressLint("NewApi")
public void applyToStatusBar(Activity activity) {
public void applyToSystemBars(Activity activity) {
setStatusBarColor(activity);
if (atLeastMarshmallow()) {
@ -148,6 +150,8 @@ public class ThemeColor implements ColorPickerDialog.Pickable {
int systemUiVisibility = applyLightStatusBarFlag(decorView.getSystemUiVisibility());
decorView.setSystemUiVisibility(systemUiVisibility);
}
applyToNavigationBar(activity);
}
@SuppressLint("NewApi")
@ -168,6 +172,16 @@ public class ThemeColor implements ColorPickerDialog.Pickable {
}
}
public void applyToNavigationBar(Activity activity) {
if (atLeastOreoMR1()) {
activity.getWindow().setNavigationBarColor(getPrimaryColor());
View decorView = activity.getWindow().getDecorView();
int systemUiVisibility = applyLightNavigationBar(decorView.getSystemUiVisibility());
decorView.setSystemUiVisibility(systemUiVisibility);
}
}
@TargetApi(Build.VERSION_CODES.M)
private int applyLightStatusBarFlag(int flag) {
return isDark
@ -175,6 +189,13 @@ public class ThemeColor implements ColorPickerDialog.Pickable {
: flag & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
@TargetApi(VERSION_CODES.O_MR1)
private int applyLightNavigationBar(int flag) {
return isDark
? flag | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
: flag & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
}
public void applyStyle(Resources.Theme theme) {
theme.applyStyle(style, true);
}

@ -158,7 +158,7 @@ public class ShortcutConfigActivity extends InjectingAppCompatActivity {
ThemeColor color = themeCache.getThemeColor(getThemeIndex());
shortcutColor.setText(color.getName());
color.apply(toolbar);
color.applyToStatusBar(this);
color.applyToSystemBars(this);
}
private int getThemeIndex() {

Loading…
Cancel
Save