Require minimum luminance of 50% for texts

pull/162/head
M66B 5 years ago
parent 4e1e9db314
commit cb791f30d3

@ -111,7 +111,6 @@ public class Helper {
static final int NOTIFICATION_UPDATE = 4;
static final float LOW_LIGHT = 0.6f;
static final float MIN_LUMINANCE = 0.33f;
static final int BUFFER_SIZE = 8192; // Same as in Files class

@ -85,6 +85,7 @@ import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE;
public class HtmlHelper {
static final int PREVIEW_SIZE = 250; // characters
private static final float MIN_LUMINANCE = 0.5f;
private static final int MAX_AUTO_LINK = 250;
private static final int TRACKING_PIXEL_SURFACE = 25; // pixels
@ -193,13 +194,12 @@ public class HtmlHelper {
}
if (color != null) {
double lum = ColorUtils.calculateLuminance(color);
if (dark
? lum < Helper.MIN_LUMINANCE
: lum > 1 - Helper.MIN_LUMINANCE)
float lum = (float) ColorUtils.calculateLuminance(color);
if (dark ? lum < MIN_LUMINANCE : lum > 1 - MIN_LUMINANCE)
color = ColorUtils.blendARGB(color,
dark ? Color.WHITE : Color.BLACK, Helper.MIN_LUMINANCE);
c = String.format("#%06x", 0xFFFFFF & color);
dark ? Color.WHITE : Color.BLACK,
dark ? MIN_LUMINANCE - lum : lum - (1 - MIN_LUMINANCE));
c = String.format("#%06x", color & 0xFFFFFF);
sb.append("color:").append(c).append(";");
}
break;

@ -33,12 +33,14 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
class Identicon {
private static final float MIN_LUMINANCE = 0.33f;
static Bitmap icon(@NonNull String email, int size, int pixels, boolean dark) {
byte[] hash = getHash(email);
int color = Color.argb(255, hash[0], hash[1], hash[2]);
color = ColorUtils.blendARGB(color,
dark ? Color.WHITE : Color.BLACK, Helper.MIN_LUMINANCE);
dark ? Color.WHITE : Color.BLACK, MIN_LUMINANCE);
Paint paint = new Paint();
paint.setColor(color);
@ -77,8 +79,7 @@ class Identicon {
byte[] hash = getHash(email);
int color = Color.argb(255, hash[0], hash[1], hash[2]);
color = ColorUtils.blendARGB(color,
dark ? Color.WHITE : Color.BLACK, Helper.MIN_LUMINANCE);
color = ColorUtils.blendARGB(color, dark ? Color.WHITE : Color.BLACK, MIN_LUMINANCE);
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);

Loading…
Cancel
Save