Skip to content

Commit

Permalink
Use dark text color when the dominant color is too light
Browse files Browse the repository at this point in the history
  • Loading branch information
vbh committed Nov 13, 2021
1 parent 4978600 commit 7d050dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
24 changes: 17 additions & 7 deletions app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java
Expand Up @@ -5,6 +5,7 @@
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.ColorUtils;
import androidx.palette.graphics.Palette;

import android.view.View;
Expand Down Expand Up @@ -143,15 +144,24 @@ static void setPlaceholderVisibility(TextView placeholder, boolean textAndImageC
if (placeholder != null) {
if (textAndImageCombined || showTitle) {
int bgColor = placeholder.getContext().getResources().getColor(R.color.feed_text_bg);
if (bitmap != null && showTitle) {
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
public void onGenerated(Palette p) {
placeholder.setBackgroundColor(p.getDominantColor(bgColor));
}
});
if (bitmap == null || !showTitle) {
placeholder.setBackgroundColor(bgColor);
return;
}
placeholder.setBackgroundColor(bgColor);
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
public void onGenerated(Palette p) {
if (p == null) {
placeholder.setBackgroundColor(bgColor);
return;
}
int dominantColor = p.getDominantColor(bgColor);
if (ColorUtils.calculateLuminance(dominantColor) > 0.6) {
placeholder.setTextColor(placeholder.getContext()
.getResources().getColor(R.color.black));
}
placeholder.setBackgroundColor(dominantColor);
}
});
} else {
placeholder.setVisibility(View.INVISIBLE);
}
Expand Down
@@ -1,6 +1,7 @@
package de.danoeh.antennapod.adapter;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.text.TextUtils;
Expand Down Expand Up @@ -209,12 +210,14 @@ public void bind(NavDrawerData.DrawerItem drawerItem) {

if (UserPreferences.shouldShowSubscriptionTitle()) {
updateLayoutParams(feedTitle);
} else {
if (lastParams != null) {
feedTitle.setLayoutParams(lastParams);
feedTitle.setTextColor(android.R.attr.textColorPrimary);
}
} else if (lastParams != null) {
feedTitle.setLayoutParams(lastParams);
TypedArray res = feedTitle.getContext().getTheme().obtainStyledAttributes(
new int[] { android.R.attr.textColorPrimary });
int textColorPrimary = res.getColor(0, 0);
feedTitle.setTextColor(textColorPrimary);
}

if (drawerItem.type == NavDrawerData.DrawerItem.Type.FEED) {
Feed feed = ((NavDrawerData.FeedDrawerItem) drawerItem).feed;
boolean textAndImageCombind = feed.isLocalFeed()
Expand Down

0 comments on commit 7d050dd

Please sign in to comment.