Better handling of identicon backgrounds

This commit is contained in:
str4d
2014-11-18 03:07:01 +00:00
parent 4fa16cfdef
commit 98f7cad19c
5 changed files with 20 additions and 8 deletions

View File

@ -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
}
}

View File

@ -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;

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>