Lighten or darken identicon

pull/146/head
M66B 6 years ago
parent e6970faf6e
commit ae47e0fe6e

@ -118,6 +118,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private boolean debug;
private int dp24;
private String theme;
private SelectionTracker<Long> selectionTracker = null;
@ -292,7 +293,9 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
}
if (!photo && identicons) {
if (message.from.length > 0)
ivAvatar.setImageBitmap(Identicon.generate(((InternetAddress) message.from[0]).getAddress(), dp24, 5));
ivAvatar.setImageBitmap(
Identicon.generate(((InternetAddress) message.from[0]).getAddress(),
dp24, 5, "light".equals(theme)));
else
ivAvatar.setImageDrawable(null);
photo = true;
@ -1409,6 +1412,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
this.debug = prefs.getBoolean("debug", false);
this.dp24 = Math.round(24 * Resources.getSystem().getDisplayMetrics().density);
this.theme = prefs.getString("theme", "light");
}
private static final DiffUtil.ItemCallback<TupleMessageEx> DIFF_CALLBACK =

@ -9,8 +9,10 @@ import android.graphics.RectF;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import androidx.core.graphics.ColorUtils;
class Identicon {
static Bitmap generate(String email, int size, int pixels) {
static Bitmap generate(String email, int size, int pixels, boolean dark) {
byte[] hash;
try {
hash = MessageDigest.getInstance("MD5").digest(email.getBytes());
@ -18,12 +20,15 @@ class Identicon {
hash = email.getBytes();
}
int color = Color.argb(255, hash[0], hash[1], hash[2]);
color = ColorUtils.blendARGB(color, dark ? Color.BLACK : Color.WHITE, 0.2f);
Paint paint = new Paint();
paint.setColor(Color.argb(255, hash[0], hash[1], hash[2]));
paint.setColor(color);
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.argb(255, 128, 128, 128));
canvas.drawColor(Color.TRANSPARENT);
float psize = (float) size / pixels;

Loading…
Cancel
Save