proper toolbar theming ignoring dark/light theme for toolbar colors

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2020-03-30 15:27:25 +02:00
parent 76a093e63f
commit 27e6c7b205
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
4 changed files with 18 additions and 8 deletions

View file

@ -288,6 +288,9 @@ public abstract class DrawerActivity extends ToolbarActivity
}
};
// proper coloring of drawer menu icon
mDrawerToggle.getDrawerArrowDrawable().setColor(ThemeUtils.toolbarTextColor(this));
// Set the drawer toggle as the DrawerListener
mDrawerLayout.addDrawerListener(mDrawerToggle);
mDrawerToggle.setDrawerIndicatorEnabled(true);

View file

@ -751,8 +751,8 @@ public class SettingsActivity extends ThemedPreferenceActivity
actionBar.setBackgroundDrawable(new ColorDrawable(ThemeUtils.primaryColor(this)));
Drawable backArrow = getResources().getDrawable(R.drawable.ic_arrow_back);
actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor(this,
!ThemeUtils.darkTheme(this))));
actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow,
ThemeUtils.toolbarTextColor(this)));
}
Window window = getWindow();

View file

@ -65,7 +65,7 @@ public abstract class ToolbarActivity extends BaseActivity {
*/
protected void setupToolbar(boolean useBackgroundImage) {
int primaryColor = ThemeUtils.primaryColor(this, false);
int fontColor = ThemeUtils.fontColor(this, !ThemeUtils.darkTheme(getApplicationContext()));
int toolbarTextColor = ThemeUtils.toolbarTextColor(this);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
@ -86,11 +86,11 @@ public abstract class ToolbarActivity extends BaseActivity {
ThemeUtils.colorStatusBar(this, primaryColor);
if (toolbar.getOverflowIcon() != null) {
ThemeUtils.tintDrawable(toolbar.getOverflowIcon(), fontColor);
ThemeUtils.tintDrawable(toolbar.getOverflowIcon(), toolbarTextColor);
}
if (toolbar.getNavigationIcon() != null) {
ThemeUtils.tintDrawable(toolbar.getNavigationIcon(), fontColor);
ThemeUtils.tintDrawable(toolbar.getNavigationIcon(), toolbarTextColor);
}
if (!useBackgroundImage) {

View file

@ -188,8 +188,11 @@ public final class ThemeUtils {
}
/**
* returns the font color based on the server side theming and uses black/white as a fallback based on replaceWhite.
*
* @param context the context
* @param replaceWhite FLAG to return white/black if server side color isn't available
* @return int font color to use
* adapted from https://github.com/nextcloud/server/blob/master/apps/theming/lib/Util.php#L90-L102
*/
public static int fontColor(Context context, boolean replaceWhite) {
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
@ -200,6 +203,10 @@ public final class ThemeUtils {
}
}
return toolbarTextColor(context);
}
public static int toolbarTextColor(Context context) {
try {
return Color.parseColor(getCapability(context).getServerTextColor());
} catch (Exception e) {
@ -249,7 +256,7 @@ public final class ThemeUtils {
actionBar.setTitle(title);
} else {
Spannable text = new SpannableString(title);
text.setSpan(new ForegroundColorSpan(fontColor(context, !darkTheme(context))),
text.setSpan(new ForegroundColorSpan(toolbarTextColor(context)),
0,
text.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
@ -612,7 +619,7 @@ public final class ThemeUtils {
drawable, Context context) {
button.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.primaryColor(context)));
button.setRippleColor(ThemeUtils.primaryDarkColor(context));
button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.fontColor(context)));
button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.toolbarTextColor(context)));
}
private static OCCapability getCapability(Context context) {