Better handling of identicon backgrounds
This commit is contained in:
@ -15,11 +15,11 @@ public class Identicon extends IdenticonBase {
|
||||
return 5;
|
||||
}
|
||||
|
||||
protected int getSymmetricColumnIndex(int row) {
|
||||
if (row < CENTER_COLUMN_INDEX) {
|
||||
return row;
|
||||
protected int getSymmetricColumnIndex(int col) {
|
||||
if (col < CENTER_COLUMN_INDEX) {
|
||||
return col;
|
||||
} else {
|
||||
return getColumnCount() - row - 1;
|
||||
return getColumnCount() - col - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,4 +32,14 @@ public class Identicon extends IdenticonBase {
|
||||
protected int getIconColor() {
|
||||
return Color.rgb(getByte(0) + 128, getByte(1) + 128, getByte(2) + 128);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBackgroundColor() {
|
||||
float[] hsv = new float[3];
|
||||
Color.colorToHSV(getIconColor(), hsv);
|
||||
if (hsv[2] < 0.5)
|
||||
return Color.parseColor("#ffeeeeee"); // @color/background_material_light
|
||||
else
|
||||
return Color.parseColor("#ff303030"); // @color/background_material_dark
|
||||
}
|
||||
}
|
||||
|
@ -53,13 +53,14 @@ public abstract class IdenticonBase {
|
||||
protected void setupColors() {
|
||||
mColors = new int[mRowCount][mColumnCount];
|
||||
int colorVisible = getIconColor();
|
||||
int colorInvisible = getBackgroundColor();
|
||||
|
||||
for (int r = 0; r < mRowCount; r++) {
|
||||
for (int c = 0; c < mColumnCount; c++) {
|
||||
if (isCellVisible(r, c)) {
|
||||
mColors[r][c] = colorVisible;
|
||||
} else {
|
||||
mColors[r][c] = Color.TRANSPARENT;
|
||||
mColors[r][c] = colorInvisible;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,6 +95,10 @@ public abstract class IdenticonBase {
|
||||
|
||||
abstract protected int getIconColor();
|
||||
|
||||
protected int getBackgroundColor() {
|
||||
return Color.TRANSPARENT;
|
||||
}
|
||||
|
||||
public void updateSize(int w, int h) {
|
||||
mCellWidth = w / mColumnCount;
|
||||
mCellHeight = h / mRowCount;
|
||||
|
@ -10,7 +10,6 @@
|
||||
android:id="@+id/contact_picture"
|
||||
android:layout_width="@dimen/contact_chip_height"
|
||||
android:layout_height="@dimen/contact_chip_height"
|
||||
android:background="@color/background_material_light"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_contact_picture"/>
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@color/background_material_light"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_contact_picture"/>
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@color/background_material_light"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_contact_picture"/>
|
||||
|
||||
|
Reference in New Issue
Block a user