summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail/photomanager/LetterTileProvider.java
diff options
context:
space:
mode:
authorRégis Décamps <regisd@google.com>2014-09-01 11:55:44 +0200
committerRégis Décamps <regisd@google.com>2014-09-02 19:03:03 +0200
commitced3b3c93afd2225b803584f700bdb1531b85810 (patch)
treea56b9a9fdaec600b466bd1870f1befc9be34fc7e /src/com/android/mail/photomanager/LetterTileProvider.java
parent81277fe9218a3d35c61200cf64221777620db0ac (diff)
downloadandroid_packages_apps_UnifiedEmail-ced3b3c93afd2225b803584f700bdb1531b85810.tar.gz
android_packages_apps_UnifiedEmail-ced3b3c93afd2225b803584f700bdb1531b85810.tar.bz2
android_packages_apps_UnifiedEmail-ced3b3c93afd2225b803584f700bdb1531b85810.zip
Refactoring in ContactDrawable to pick a color.
Strategy pattern to pick a color in the letter tile. Thanks to this, subimplementations can draw the letter tiles for avatars differently, and still use the all the features of the ContactDrawable. Bug: 16378212 Draw letter tile for non-Gmail avatars Change-Id: I999aa43724ba0e4dd23f2106133aaa34ee3ba008
Diffstat (limited to 'src/com/android/mail/photomanager/LetterTileProvider.java')
-rw-r--r--src/com/android/mail/photomanager/LetterTileProvider.java21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/com/android/mail/photomanager/LetterTileProvider.java b/src/com/android/mail/photomanager/LetterTileProvider.java
index bf17acbac..ca70e72a4 100644
--- a/src/com/android/mail/photomanager/LetterTileProvider.java
+++ b/src/com/android/mail/photomanager/LetterTileProvider.java
@@ -29,6 +29,7 @@ import android.text.TextPaint;
import android.text.TextUtils;
import com.android.mail.R;
+import com.android.mail.bitmap.ColorPicker;
import com.android.mail.ui.ImageCanvas.Dimensions;
import com.android.mail.utils.BitmapUtil;
import com.android.mail.utils.LogTag;
@@ -54,14 +55,11 @@ public class LetterTileProvider {
private final int mTileLetterFontSizeSmall;
private final int mTileFontColor;
private final TextPaint mPaint = new TextPaint();
- private final TypedArray mColors;
- private final int mColorCount;
- private final int mDefaultColor;
private final Canvas mCanvas = new Canvas();
- private final Dimensions mDims = new Dimensions();
private final char[] mFirstChar = new char[1];
private static final int POSSIBLE_BITMAP_SIZES = 3;
+ private ColorPicker sTileColorPicker;
public LetterTileProvider(Context context) {
final Resources res = context.getResources();
@@ -80,9 +78,9 @@ public class LetterTileProvider {
mDefaultBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_generic_man);
mDefaultBitmapCache = new Bitmap[POSSIBLE_BITMAP_SIZES];
- mColors = res.obtainTypedArray(R.array.letter_tile_colors);
- mColorCount = mColors.length();
- mDefaultColor = res.getColor(R.color.letter_tile_default_color);
+ if (sTileColorPicker == null) {
+ sTileColorPicker = new ColorPicker.PaletteColorPicker(res);
+ }
}
public Bitmap getLetterTile(final Dimensions dimensions, final String displayName,
@@ -100,7 +98,7 @@ public class LetterTileProvider {
final Canvas c = mCanvas;
c.setBitmap(bitmap);
- c.drawColor(pickColor(address));
+ c.drawColor(sTileColorPicker.pickColor(address));
// If its a valid English alphabet letter,
// draw the letter on top of the color
@@ -163,11 +161,4 @@ public class LetterTileProvider {
return mTileLetterFontSizeSmall;
}
}
-
- private int pickColor(String emailAddress) {
- // String.hashCode() implementation is not supposed to change across java versions, so
- // this should guarantee the same email address always maps to the same color.
- int color = Math.abs(emailAddress.hashCode()) % mColorCount;
- return mColors.getColor(color, mDefaultColor);
- }
}