diff options
author | Andrew Sapperstein <asapperstein@google.com> | 2013-05-06 14:41:48 -0700 |
---|---|---|
committer | Andrew Sapperstein <asapperstein@google.com> | 2013-05-06 16:05:05 -0700 |
commit | 296bac875c2932d0bf3f7388a873fa250222804d (patch) | |
tree | d81633e50e196b71e771fcb25a292b2c5e856495 | |
parent | 8f1b384f3a8b435e88f8fa37785748563f5a698b (diff) | |
download | android_packages_apps_UnifiedEmail-296bac875c2932d0bf3f7388a873fa250222804d.tar.gz android_packages_apps_UnifiedEmail-296bac875c2932d0bf3f7388a873fa250222804d.tar.bz2 android_packages_apps_UnifiedEmail-296bac875c2932d0bf3f7388a873fa250222804d.zip |
Use icon with colored background for sender image.
Fixes b/8794452. Instead of defaulting to boring grey man,
we now use the same colored background when
we don't have a sender image and draw a generic
white icon on top of the color.
Also, deleted LetterTileUtils since we no longer
use it.
Change-Id: I3b905afdffbc70eeeca4f030dc57f5ab3748ee64
-rw-r--r-- | res/drawable-hdpi/ic_generic_man.png | bin | 0 -> 2375 bytes | |||
-rw-r--r-- | res/drawable-mdpi/ic_generic_man.png | bin | 0 -> 1657 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_generic_man.png | bin | 0 -> 3149 bytes | |||
-rw-r--r-- | src/com/android/mail/browse/LetterTileUtils.java | 128 | ||||
-rw-r--r-- | src/com/android/mail/photomanager/LetterTileProvider.java | 37 |
5 files changed, 22 insertions, 143 deletions
diff --git a/res/drawable-hdpi/ic_generic_man.png b/res/drawable-hdpi/ic_generic_man.png Binary files differnew file mode 100644 index 000000000..b6b3129f5 --- /dev/null +++ b/res/drawable-hdpi/ic_generic_man.png diff --git a/res/drawable-mdpi/ic_generic_man.png b/res/drawable-mdpi/ic_generic_man.png Binary files differnew file mode 100644 index 000000000..f763dd259 --- /dev/null +++ b/res/drawable-mdpi/ic_generic_man.png diff --git a/res/drawable-xhdpi/ic_generic_man.png b/res/drawable-xhdpi/ic_generic_man.png Binary files differnew file mode 100644 index 000000000..212293db0 --- /dev/null +++ b/res/drawable-xhdpi/ic_generic_man.png diff --git a/src/com/android/mail/browse/LetterTileUtils.java b/src/com/android/mail/browse/LetterTileUtils.java deleted file mode 100644 index ae2f6e7c5..000000000 --- a/src/com/android/mail/browse/LetterTileUtils.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mail.browse; - -import android.content.Context; -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.Rect; -import android.graphics.Typeface; -import android.graphics.Paint.Align; -import android.text.TextPaint; -import android.text.TextUtils; - -import com.android.mail.R; -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * LetterTileUtils is a static-use class for getting a bitmap corresponding - * to a given account. Spits out a colored tile with a single letter, which - * is the default for when a contact photo is missing (or if the language is - * one without English letters, uses the default grey character image). - */ -public class LetterTileUtils { - private static Typeface sSansSerifLight; - private static Rect sBounds; - private static int sTileLetterFontSize = -1; - private static int sTileLetterFontSizeSmall; - private static int sTileFontColor; - private static final TextPaint sPaint = new TextPaint(); - private static final int DEFAULT_AVATAR_DRAWABLE = R.drawable.ic_contact_picture; - private static final Pattern ALPHABET = Pattern.compile("[A-Z0-9]"); - - // This should match the total number of colors defined in colors.xml for letter_tile_color - private static final int NUM_OF_TILE_COLORS = 7; - - /** - * Creates a letter tile to act as an account/contact photo based on the account address/name - * in the given width & height. - * - * @param displayName account's custom name - * @param address account email address - * @param context current context of the app - * @param width width of final bitmap in px (input converted number) - * @param height height of final bitmap in px (input converted number) - * @return Bitmap with a colored background and a letter tile corresponding to the account - */ - public static Bitmap generateLetterTile( - String displayName, String address, Context context, int width, int height) { - Bitmap bitmap = null; - final String display = !TextUtils.isEmpty(displayName) ? displayName : address; - final String firstChar = display.substring(0, 1).toUpperCase(Locale.US); - - // If its a valid English alphabet letter... - if (isLetter(firstChar)) { - // Generate letter tile bitmap based on the first letter in name - final Resources res = context.getResources(); - if (sTileLetterFontSize == -1) { - sTileLetterFontSize = res.getDimensionPixelSize(R.dimen.tile_letter_font_size); - sTileLetterFontSizeSmall = res - .getDimensionPixelSize(R.dimen.tile_letter_font_size_small); - sTileFontColor = res.getColor(R.color.letter_tile_font_color); - sSansSerifLight = Typeface.create("sans-serif-light", Typeface.NORMAL); - sBounds = new Rect(); - sPaint.setTypeface(sSansSerifLight); - sPaint.setColor(sTileFontColor); - sPaint.setTextAlign(Align.CENTER); - sPaint.setAntiAlias(true); - } - bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - final Canvas c = new Canvas(bitmap); - c.drawColor(pickColor(res, address)); - sPaint.setTextSize(sTileLetterFontSize); - sPaint.getTextBounds(firstChar, 0, firstChar.length(), sBounds); - c.drawText(firstChar, 0 + width / 2, 0 + height / 2 + (sBounds.bottom - sBounds.top) - / 2, sPaint); - } else { - // Use default image - final BitmapFactory.Options options = new BitmapFactory.Options(); - bitmap = BitmapFactory.decodeResource(context.getResources(), - DEFAULT_AVATAR_DRAWABLE, options); - } - return bitmap; - } - - /** - * Check against the English alphabet regex if the letter is usable for the bitmap. - * - * @param letter Letter to test against - * @return true if usable in Letter Tile, false otherwise - */ - private static boolean isLetter(final String letter) { - final Matcher m = ALPHABET.matcher(letter); - return m.matches(); - } - - /** - * Choose a color based on the given resource and the email address's hashCode. - * - * @param emailAddress Address for which we are choosing a color - * @return Color for the tile represented as an int - */ - private static int pickColor(Resources res, 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()) % NUM_OF_TILE_COLORS; - TypedArray colors = res.obtainTypedArray(R.array.letter_tile_colors); - return colors.getColor(color, R.color.letter_tile_default_color); - } -} diff --git a/src/com/android/mail/photomanager/LetterTileProvider.java b/src/com/android/mail/photomanager/LetterTileProvider.java index cf752c224..39d9a40d1 100644 --- a/src/com/android/mail/photomanager/LetterTileProvider.java +++ b/src/com/android/mail/photomanager/LetterTileProvider.java @@ -22,6 +22,7 @@ import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; +import android.graphics.Matrix; import android.graphics.Paint.Align; import android.graphics.Rect; import android.graphics.Typeface; @@ -82,7 +83,7 @@ public class LetterTileProvider implements DefaultImageProvider { mPaint.setAntiAlias(true); mBitmapBackgroundCache = new Bitmap[POSSIBLE_BITMAP_SIZES]; - mDefaultBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_contact_picture); + mDefaultBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_generic_man); mDefaultBitmapCache = new Bitmap[POSSIBLE_BITMAP_SIZES]; mColors = res.obtainTypedArray(R.array.letter_tile_colors); @@ -106,27 +107,33 @@ public class LetterTileProvider implements DefaultImageProvider { final String display = !TextUtils.isEmpty(displayName) ? displayName : address; final char firstChar = display.charAt(0); dividedImageView.getDesiredDimensions(address, mDims); - // If its a valid English alphabet letter... + + // get an empty bitmap + bitmap = getBitmap(mDims, false /* getDefault */); + if (bitmap == null) { + LogUtils.w(TAG, "LetterTileProvider width(%d) or height(%d) is 0" + + " for name %s and address %s.", + dividedImageView.getWidth(), dividedImageView.getHeight(), displayName, + address); + return; + } + + final Canvas c = mCanvas; + c.setBitmap(bitmap); + c.drawColor(pickColor(address)); + + // If its a valid English alphabet letter, + // draw the letter on top of the color if (isEnglishLetterOrDigit(firstChar)) { mFirstChar[0] = Character.toUpperCase(firstChar); - bitmap = getBitmap(mDims, false /* getDefault */); - if (bitmap == null) { - LogUtils.w(TAG, "LetterTileProvider width(%d) or height(%d) is 0" + - " for name %s and address %s.", - dividedImageView.getWidth(), dividedImageView.getHeight(), displayName, - address); - return; - } - final Canvas c = mCanvas; - c.setBitmap(bitmap); - c.drawColor(pickColor(address)); mPaint.setTextSize(getFontSize(mDims.scale)); mPaint.getTextBounds(mFirstChar, 0, 1, mBounds); c.drawText(mFirstChar, 0, 1, 0 + mDims.width / 2, 0 + mDims.height / 2 + (mBounds.bottom - mBounds.top) / 2, mPaint); - } else { - bitmap = getBitmap(mDims, true /* getDefault */); + } else { // draw the generic icon on top + c.drawBitmap(getBitmap(mDims, true /* getDefault */), 0, 0, null); } + dividedImageView.addDivisionImage(bitmap, address); } |