Update avatar drawable in LetterTileDrawable
Use the same image as QC uses. Except, instead of scaling down
the ~140dp image start with a 64dp image.
The images provided by allen don't have an amount of border built into
it that looks good inside the LetterTileDrawable. Therefore, I wrapped
the image inside a ScaleDrawable. To do this, I changed LetterTileDrawable
to operate on internal drawables instead of internal bitmaps.
Bug: 16290899
Change-Id: I741c3a603d025068614c7004ea61fb349f6d6944
diff --git a/src/com/android/contacts/common/lettertiles/LetterTileDrawable.java b/src/com/android/contacts/common/lettertiles/LetterTileDrawable.java
index 5aaf29a..4bc8ba4 100644
--- a/src/com/android/contacts/common/lettertiles/LetterTileDrawable.java
+++ b/src/com/android/contacts/common/lettertiles/LetterTileDrawable.java
@@ -18,8 +18,6 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
@@ -28,10 +26,8 @@
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
-import android.util.Log;
import com.android.contacts.common.R;
-import com.android.contacts.common.util.BitmapUtil;
import junit.framework.Assert;
@@ -50,9 +46,9 @@
private static int sDefaultColor;
private static int sTileFontColor;
private static float sLetterToTileRatio;
- private static Bitmap DEFAULT_PERSON_AVATAR;
- private static Bitmap DEFAULT_BUSINESS_AVATAR;
- private static Bitmap DEFAULT_VOICEMAIL_AVATAR;
+ private static Drawable DEFAULT_PERSON_AVATAR;
+ private static Drawable DEFAULT_BUSINESS_AVATAR;
+ private static Drawable DEFAULT_VOICEMAIL_AVATAR;
/** Reusable components to avoid new allocations */
private static final Paint sPaint = new Paint();
@@ -74,7 +70,6 @@
public LetterTileDrawable(final Resources res) {
mPaint = new Paint();
- mPaint.setFilterBitmap(true);
mPaint.setDither(true);
if (sColors == null) {
@@ -82,12 +77,11 @@
sDefaultColor = res.getColor(R.color.letter_tile_default_color);
sTileFontColor = res.getColor(R.color.letter_tile_font_color);
sLetterToTileRatio = res.getFraction(R.dimen.letter_to_tile_ratio, 1, 1);
- DEFAULT_PERSON_AVATAR = BitmapFactory.decodeResource(res,
- R.drawable.ic_list_item_avatar);
- DEFAULT_BUSINESS_AVATAR = BitmapFactory.decodeResource(res,
- R.drawable.ic_list_item_businessavatar);
- DEFAULT_VOICEMAIL_AVATAR = BitmapFactory.decodeResource(res,
- R.drawable.ic_voicemail_avatar);
+ DEFAULT_BUSINESS_AVATAR = res.getDrawable(R.drawable.ic_list_item_businessavatar);
+ DEFAULT_VOICEMAIL_AVATAR = res.getDrawable(R.drawable.ic_voicemail_avatar);
+ DEFAULT_PERSON_AVATAR = res.getDrawable(R.drawable.ic_tile_letter_avatar_white);
+ // This drawable contains a ScaleDrawable that won't be visible without setLevel(1).
+ DEFAULT_PERSON_AVATAR.setLevel(1);
sPaint.setTypeface(Typeface.create(
res.getString(R.string.letter_tile_letter_font_family), Typeface.NORMAL));
sPaint.setTextAlign(Align.CENTER);
@@ -106,11 +100,11 @@
}
/**
- * Draw the bitmap onto the canvas at the current bounds taking into account the current scale.
+ * Draw the inner drawable onto the canvas at the current bounds taking into account the current
+ * scale.
*/
- private void drawBitmap(final Bitmap bitmap, final int width, final int height,
- final Canvas canvas) {
- // The bitmap should be drawn in the middle of the canvas without changing its width to
+ private void drawInnerDrawable(final Drawable drawable, final Canvas canvas) {
+ // The drawable should be drawn in the middle of the canvas without changing its width to
// height ratio.
final Rect destRect = copyBounds();
@@ -122,10 +116,11 @@
destRect.centerX() + halfLength,
(int) (destRect.centerY() + halfLength + mOffset * destRect.height()));
- // Source rectangle remains the entire bounds of the source bitmap.
- sRect.set(0, 0, width, height);
-
- canvas.drawBitmap(bitmap, sRect, destRect, mPaint);
+ drawable.setDither(true);
+ drawable.setFilterBitmap(true);
+ drawable.setBounds(destRect);
+ drawable.setAlpha(mPaint.getAlpha());
+ drawable.draw(canvas);
}
private void drawLetterTile(final Canvas canvas) {
@@ -133,7 +128,6 @@
sPaint.setColor(pickColor(mIdentifier));
sPaint.setAlpha(mPaint.getAlpha());
- sPaint.setColorFilter(mPaint.getColorFilter());
final Rect bounds = getBounds();
final int minDimension = Math.min(bounds.width(), bounds.height());
@@ -161,9 +155,8 @@
sPaint);
} else {
// Draw the default image if there is no letter/digit to be drawn
- final Bitmap bitmap = getBitmapForContactType(mContactType);
- drawBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(),
- canvas);
+ final Drawable innerDrawable = getInnerDrawableForContactType(mContactType);
+ drawInnerDrawable(innerDrawable, canvas);
}
}
@@ -185,7 +178,7 @@
return sColors.getColor(color, sDefaultColor);
}
- private static Bitmap getBitmapForContactType(int contactType) {
+ private static Drawable getInnerDrawableForContactType(int contactType) {
switch (contactType) {
case TYPE_PERSON:
return DEFAULT_PERSON_AVATAR;