summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/mail/bitmap/AccountAvatarDrawable.java5
-rw-r--r--src/com/android/mail/bitmap/CheckableContactFlipDrawable.java (renamed from src/com/android/mail/bitmap/ContactCheckableGridDrawable.java)37
-rw-r--r--src/com/android/mail/bitmap/CompositeDrawable.java162
-rw-r--r--src/com/android/mail/bitmap/ContactDrawable.java97
-rw-r--r--src/com/android/mail/bitmap/ContactGridDrawable.java162
-rw-r--r--src/com/android/mail/bitmap/TileDrawable.java148
-rw-r--r--src/com/android/mail/browse/ConversationItemView.java34
7 files changed, 94 insertions, 551 deletions
diff --git a/src/com/android/mail/bitmap/AccountAvatarDrawable.java b/src/com/android/mail/bitmap/AccountAvatarDrawable.java
index d957d9c04..20beae0cf 100644
--- a/src/com/android/mail/bitmap/AccountAvatarDrawable.java
+++ b/src/com/android/mail/bitmap/AccountAvatarDrawable.java
@@ -27,7 +27,7 @@ public class AccountAvatarDrawable extends Drawable implements ContactDrawableIn
private ContactRequest mContactRequest;
private ReusableBitmap mBitmap;
- private float mBorderWidth;
+ private final float mBorderWidth;
private final Paint mBitmapPaint;
private final Paint mBorderPaint;
private final Matrix mMatrix;
@@ -46,13 +46,14 @@ public class AccountAvatarDrawable extends Drawable implements ContactDrawableIn
mBitmapPaint.setFilterBitmap(true);
mBitmapPaint.setDither(true);
+ mBorderWidth = res.getDimensionPixelSize(R.dimen.avatar_border_width);
+
mBorderPaint = new Paint();
mBorderPaint.setColor(Color.TRANSPARENT);
mBorderPaint.setStyle(Style.STROKE);
mBorderPaint.setStrokeWidth(mBorderWidth);
mBorderPaint.setAntiAlias(true);
- mBorderWidth = res.getDimensionPixelSize(R.dimen.avatar_border_width);
mMatrix = new Matrix();
if (DEFAULT_AVATAR == null) {
diff --git a/src/com/android/mail/bitmap/ContactCheckableGridDrawable.java b/src/com/android/mail/bitmap/CheckableContactFlipDrawable.java
index 3f55c1847..f590919ce 100644
--- a/src/com/android/mail/bitmap/ContactCheckableGridDrawable.java
+++ b/src/com/android/mail/bitmap/CheckableContactFlipDrawable.java
@@ -28,16 +28,15 @@ import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
-import com.android.bitmap.BitmapCache;
import com.android.mail.R;
/**
- * Custom FlipDrawable which has a {@link ContactGridDrawable} on the front,
+ * Custom FlipDrawable which has a {@link ContactDrawable} on the front,
* and a {@link CheckmarkDrawable} on the back.
*/
-public class ContactCheckableGridDrawable extends FlipDrawable implements AnimatorUpdateListener {
+public class CheckableContactFlipDrawable extends FlipDrawable implements AnimatorUpdateListener {
- private final ContactGridDrawable mContactGridDrawable;
+ private final ContactDrawable mContactDrawable;
private final CheckmarkDrawable mCheckmarkDrawable;
private final ValueAnimator mCheckmarkScaleAnimator;
@@ -51,11 +50,11 @@ public class ContactCheckableGridDrawable extends FlipDrawable implements Animat
/** Must be <= 1f since the animation value is used as a percentage. */
private static final float END_VALUE = 1f;
- public ContactCheckableGridDrawable(final Resources res, final int flipDurationMs) {
- super(new ContactGridDrawable(res), new CheckmarkDrawable(res), flipDurationMs,
+ public CheckableContactFlipDrawable(final Resources res, final int flipDurationMs) {
+ super(new ContactDrawable(res), new CheckmarkDrawable(res), flipDurationMs,
0 /* preFlipDurationMs */, POST_FLIP_DURATION_MS);
- mContactGridDrawable = (ContactGridDrawable) mFront;
+ mContactDrawable = (ContactDrawable) mFront;
mCheckmarkDrawable = (CheckmarkDrawable) mBack;
// We will create checkmark animations that are synchronized with the flipping animation.
@@ -113,26 +112,8 @@ public class ContactCheckableGridDrawable extends FlipDrawable implements Animat
}
}
- public ContactDrawable getOrCreateDrawable(final int i) {
- return mContactGridDrawable.getOrCreateDrawable(i);
- }
-
- public void setBitmapCache(final BitmapCache cache) {
- mContactGridDrawable.setBitmapCache(cache);
- }
-
- public void setContactResolver(final ContactResolver contactResolver) {
- mContactGridDrawable.setContactResolver(contactResolver);
- }
-
- public int getCount() {
- return mContactGridDrawable.getCount();
- }
-
- public void setCount(final int count) {
- mContactGridDrawable.setCount(count);
- // Side effect needs to happen here too.
- setBounds(0, 0, 0, 0);
+ public ContactDrawable getContactDrawable() {
+ return mContactDrawable;
}
@Override
@@ -181,7 +162,7 @@ public class ContactCheckableGridDrawable extends FlipDrawable implements Animat
return;
}
- canvas.drawRect(getBounds(), mPaint);
+ canvas.drawCircle(bounds.centerX(), bounds.centerY(), bounds.width() / 2, mPaint);
// Scale the checkmark.
sMatrix.reset();
diff --git a/src/com/android/mail/bitmap/CompositeDrawable.java b/src/com/android/mail/bitmap/CompositeDrawable.java
deleted file mode 100644
index 3516683da..000000000
--- a/src/com/android/mail/bitmap/CompositeDrawable.java
+++ /dev/null
@@ -1,162 +0,0 @@
-package com.android.mail.bitmap;
-
-import android.graphics.Canvas;
-import android.graphics.ColorFilter;
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-
-import com.android.bitmap.util.Trace;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A drawable that contains up to 4 other smaller drawables in a regular grid. This class attempts
- * to reuse inner drawables when feasible to promote object reuse. This design goal makes the API
- * to reuse an instance a little awkward: you must first zero out the count, then set it to a new
- * value, then populate the entries with {@link #getOrCreateDrawable(int)} and a drawable subclass
- * bind() method of your design.
- */
-public abstract class CompositeDrawable<T extends Drawable> extends Drawable
- implements Drawable.Callback {
-
- public static final int MAX_COMPOSITE_DRAWABLES = 4;
-
- protected final List<T> mDrawables;
- protected int mCount;
-
- public CompositeDrawable(int maxDivisions) {
- if (maxDivisions > MAX_COMPOSITE_DRAWABLES) {
- throw new IllegalArgumentException("CompositeDrawable only supports 4 divisions");
- }
- mDrawables = new ArrayList<T>(maxDivisions);
- for (int i = 0; i < maxDivisions; i++) {
- mDrawables.add(i, null);
- }
- mCount = 0;
- }
-
- protected abstract T createDivisionDrawable(final int i);
-
- public void setCount(int count) {
- // zero out the composite bounds, which will propagate to the division drawables
- // this invalidates any old division bounds, which may change with the count
- setBounds(0, 0, 0, 0);
- mCount = count;
- }
-
- public int getCount() {
- return mCount;
- }
-
- public T getOrCreateDrawable(int i) {
- if (i >= mCount) {
- throw new IllegalArgumentException("bad index: " + i);
- }
-
- T result = mDrawables.get(i);
- if (result == null) {
- Trace.beginSection("create division drawable");
- result = createDivisionDrawable(i);
- mDrawables.set(i, result);
- result.setCallback(this);
- // Make sure drawables created after the bounds were already set have their bounds
- // set initially (the other unaffected drawables basically de-bounce this).
- onBoundsChange(getBounds());
- Trace.endSection();
- }
- return result;
- }
-
- @Override
- protected void onBoundsChange(Rect bounds) {
- final int w = bounds.width();
- final int h = bounds.height();
- final int mw = w / 2;
- final int mh = h / 2;
- switch (mCount) {
- case 1:
- // 1 bitmap: passthrough
- applyBounds(0, 0, 0, w, h);
- break;
- case 2:
- // 2 bitmaps split vertically
- applyBounds(0, 0, 0, mw, h);
- applyBounds(1, mw, 0, w, h);
- break;
- case 3:
- // 1st is tall on the left, 2nd/3rd stacked vertically on the right
- applyBounds(0, 0, 0, mw, h);
- applyBounds(1, mw, 0, w, mh);
- applyBounds(2, mw, mh, w, h);
- break;
- case 4:
- // 4 bitmaps in a 2x2 grid
- applyBounds(0, 0, 0, mw, mh);
- applyBounds(1, mw, 0, w, mh);
- applyBounds(2, 0, mh, mw, h);
- applyBounds(3, mw, mh, w, h);
- break;
- }
- }
-
- private void applyBounds(int index, int left, int top, int right, int bottom) {
- final T d = mDrawables.get(index);
- if (d == null) {
- return;
- }
- d.setBounds(left, top, right, bottom);
- }
-
- @Override
- public void draw(Canvas canvas) {
- final Rect bounds = getBounds();
- if (!isVisible() || bounds.isEmpty()) {
- return;
- }
-
- for (int i = 0; i < mCount; i++) {
- mDrawables.get(i).draw(canvas);
- }
- }
-
- @Override
- public void setAlpha(int alpha) {
- for (int i = 0; i < mCount; i++) {
- mDrawables.get(i).setAlpha(alpha);
- }
- }
-
- @Override
- public void setColorFilter(ColorFilter cf) {
- for (int i = 0; i < mCount; i++) {
- mDrawables.get(i).setColorFilter(cf);
- }
- }
-
- @Override
- public int getOpacity() {
- int opacity = PixelFormat.OPAQUE;
- for (int i = 0; i < mCount; i++) {
- opacity = resolveOpacity(opacity, mDrawables.get(i).getOpacity());
- }
- return opacity;
- }
-
- @Override
- public void invalidateDrawable(Drawable who) {
- invalidateSelf();
- }
-
- @Override
- public void scheduleDrawable(Drawable who, Runnable what, long when) {
- scheduleSelf(what, when);
- }
-
- @Override
- public void unscheduleDrawable(Drawable who, Runnable what) {
- unscheduleSelf(what);
- }
-
-}
diff --git a/src/com/android/mail/bitmap/ContactDrawable.java b/src/com/android/mail/bitmap/ContactDrawable.java
index 97e5e4f55..9f929af62 100644
--- a/src/com/android/mail/bitmap/ContactDrawable.java
+++ b/src/com/android/mail/bitmap/ContactDrawable.java
@@ -19,11 +19,15 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.BitmapShader;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.ColorFilter;
+import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
+import android.graphics.Shader;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
@@ -43,19 +47,17 @@ import com.android.mail.bitmap.ContactResolver.ContactDrawableInterface;
*/
public class ContactDrawable extends Drawable implements ContactDrawableInterface {
- private final BitmapCache mCache;
- private final ContactResolver mContactResolver;
+ private BitmapCache mCache;
+ private ContactResolver mContactResolver;
private ContactRequest mContactRequest;
private ReusableBitmap mBitmap;
private final Paint mPaint;
- private int mScale;
/** Letter tile */
private static TypedArray sColors;
private static int sDefaultColor;
private static int sTileLetterFontSize;
- private static int sTileLetterFontSizeSmall;
private static int sTileFontColor;
private static Bitmap DEFAULT_AVATAR;
/** Reusable components to avoid new allocations */
@@ -66,23 +68,38 @@ public class ContactDrawable extends Drawable implements ContactDrawableInterfac
/** This should match the total number of colors defined in colors.xml for letter_tile_color */
private static final int NUM_OF_TILE_COLORS = 12;
+ private final float mBorderWidth;
+ private final Paint mBitmapPaint;
+ private final Paint mBorderPaint;
+ private final Matrix mMatrix;
+
private int mDecodeWidth;
private int mDecodeHeight;
- public ContactDrawable(final Resources res, final BitmapCache cache,
- final ContactResolver contactResolver) {
- mCache = cache;
- mContactResolver = contactResolver;
+ public ContactDrawable(final Resources res) {
mPaint = new Paint();
mPaint.setFilterBitmap(true);
mPaint.setDither(true);
+ mBitmapPaint = new Paint();
+ mBitmapPaint.setAntiAlias(true);
+ mBitmapPaint.setFilterBitmap(true);
+ mBitmapPaint.setDither(true);
+
+ mBorderWidth = res.getDimensionPixelSize(R.dimen.avatar_border_width);
+
+ mBorderPaint = new Paint();
+ mBorderPaint.setColor(Color.TRANSPARENT);
+ mBorderPaint.setStyle(Paint.Style.STROKE);
+ mBorderPaint.setStrokeWidth(mBorderWidth);
+ mBorderPaint.setAntiAlias(true);
+
+ mMatrix = new Matrix();
+
if (sColors == null) {
sColors = res.obtainTypedArray(R.array.letter_tile_colors);
sDefaultColor = res.getColor(R.color.letter_tile_default_color);
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);
DEFAULT_AVATAR = BitmapFactory.decodeResource(res, R.drawable.ic_generic_man);
@@ -92,6 +109,14 @@ public class ContactDrawable extends Drawable implements ContactDrawableInterfac
}
}
+ public void setBitmapCache(final BitmapCache cache) {
+ mCache = cache;
+ }
+
+ public void setContactResolver(final ContactResolver contactResolver) {
+ mContactResolver = contactResolver;
+ }
+
@Override
public void draw(final Canvas canvas) {
final Rect bounds = getBounds();
@@ -114,14 +139,27 @@ public class ContactDrawable extends Drawable implements ContactDrawableInterfac
private void drawBitmap(final Bitmap bitmap, final int width, final int height,
final Canvas canvas) {
final Rect bounds = getBounds();
-
- if (mScale != ContactGridDrawable.SCALE_TYPE_HALF) {
- sRect.set(0, 0, width, height);
- } else {
- // For skinny bounds, draw the middle two quarters.
- sRect.set(width / 4, 0, width / 4 * 3, height);
- }
- canvas.drawBitmap(bitmap, sRect, bounds, mPaint);
+ // Draw bitmap through shader first.
+ final BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP,
+ Shader.TileMode.CLAMP);
+ mMatrix.reset();
+
+ // Fit bitmap to bounds.
+ final float boundsWidth = (float) bounds.width();
+ final float boundsHeight = (float) bounds.height();
+ final float scale = Math.max(boundsWidth / width, boundsHeight / height);
+ mMatrix.postScale(scale, scale);
+
+ // Translate bitmap to dst bounds.
+ mMatrix.postTranslate(bounds.left, bounds.top);
+
+ shader.setLocalMatrix(mMatrix);
+ mBitmapPaint.setShader(shader);
+ drawCircle(canvas, bounds, mBitmapPaint);
+
+ // Then draw the border.
+ final float radius = bounds.width() / 2f - mBorderWidth / 2;
+ canvas.drawCircle(bounds.centerX(), bounds.centerY(), radius, mBorderPaint);
}
private void drawLetterTile(final Canvas canvas) {
@@ -129,21 +167,21 @@ public class ContactDrawable extends Drawable implements ContactDrawableInterfac
return;
}
+ final Rect bounds = getBounds();
+
// Draw background color.
final String email = mContactRequest.getEmail();
sPaint.setColor(pickColor(email));
sPaint.setAlpha(mPaint.getAlpha());
- canvas.drawRect(getBounds(), sPaint);
+ drawCircle(canvas, bounds, sPaint);
// Draw letter/digit or generic avatar.
final String displayName = mContactRequest.getDisplayName();
final char firstChar = displayName.charAt(0);
- final Rect bounds = getBounds();
if (isEnglishLetterOrDigit(firstChar)) {
// Draw letter or digit.
sFirstChar[0] = Character.toUpperCase(firstChar);
- sPaint.setTextSize(mScale == ContactGridDrawable.SCALE_TYPE_ONE ? sTileLetterFontSize
- : sTileLetterFontSizeSmall);
+ sPaint.setTextSize(sTileLetterFontSize);
sPaint.getTextBounds(sFirstChar, 0, 1, sRect);
sPaint.setColor(sTileFontColor);
canvas.drawText(sFirstChar, 0, 1, bounds.centerX(),
@@ -154,6 +192,17 @@ public class ContactDrawable extends Drawable implements ContactDrawableInterfac
}
}
+ /**
+ * Draws the largest circle that fits within the given <code>bounds</code>.
+ *
+ * @param canvas the canvas on which to draw
+ * @param bounds the bounding box of the circle
+ * @param paint the paint with which to draw
+ */
+ private static void drawCircle(Canvas canvas, Rect bounds, Paint paint) {
+ canvas.drawCircle(bounds.centerX(), bounds.centerY(), bounds.width() / 2, paint);
+ }
+
private static int pickColor(final String email) {
// 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.
@@ -186,10 +235,6 @@ public class ContactDrawable extends Drawable implements ContactDrawableInterfac
mDecodeHeight = decodeHeight;
}
- public void setScale(final int scale) {
- mScale = scale;
- }
-
public void unbind() {
setImage(null);
}
diff --git a/src/com/android/mail/bitmap/ContactGridDrawable.java b/src/com/android/mail/bitmap/ContactGridDrawable.java
deleted file mode 100644
index 590f80681..000000000
--- a/src/com/android/mail/bitmap/ContactGridDrawable.java
+++ /dev/null
@@ -1,162 +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.bitmap;
-
-import android.content.res.Resources;
-import android.graphics.Canvas;
-import android.graphics.ColorFilter;
-import android.graphics.Paint;
-import android.graphics.Rect;
-
-import com.android.bitmap.BitmapCache;
-import com.android.mail.R;
-
-/**
- * A 2x2 grid of contact drawables. Adds horizontal and vertical dividers.
- */
-public class ContactGridDrawable extends CompositeDrawable<ContactDrawable> {
-
- public static final int SCALE_TYPE_ONE = 0;
- public static final int SCALE_TYPE_HALF = 1;
- public static final int SCALE_TYPE_QUARTER = 2;
-
- private static final int MAX_CONTACTS_COUNT = 4;
-
- private ContactResolver mContactResolver;
- private BitmapCache mCache;
- private final Resources mRes;
- private Paint mPaint;
-
- private static int sDividerWidth = -1;
- private static int sDividerColor;
-
- public ContactGridDrawable(final Resources res) {
- super(MAX_CONTACTS_COUNT);
-
- if (sDividerWidth == -1) {
- sDividerWidth = res.getDimensionPixelSize(R.dimen.tile_divider_width);
- sDividerColor = res.getColor(R.color.tile_divider_color);
- }
-
- mRes = res;
- mPaint = new Paint();
- mPaint.setStrokeWidth(sDividerWidth);
- mPaint.setColor(sDividerColor);
- }
-
- @Override
- protected ContactDrawable createDivisionDrawable(final int i) {
- final ContactDrawable drawable = new ContactDrawable(mRes, mCache, mContactResolver);
- drawable.setScale(calculateScale(i));
- return drawable;
- }
-
- @Override
- public void setCount(final int count) {
- super.setCount(count);
-
- for (int i = 0; i < mCount; i++) {
- final ContactDrawable drawable = mDrawables.get(i);
- if (drawable != null) {
- drawable.setScale(calculateScale(i));
- }
- }
- }
-
- /**
- * Given which section a drawable is in, calculate its scale based on the current total count.
- * @param i The section, indexed by 0.
- */
- private int calculateScale(final int i) {
- switch (mCount) {
- case 1:
- // 1 bitmap: passthrough
- return SCALE_TYPE_ONE;
- case 2:
- // 2 bitmaps split vertically
- return SCALE_TYPE_HALF;
- case 3:
- // 1st is tall on the left, 2nd/3rd stacked vertically on the right
- return i == 0 ? SCALE_TYPE_HALF : SCALE_TYPE_QUARTER;
- case 4:
- // 4 bitmaps in a 2x2 grid
- return SCALE_TYPE_QUARTER;
- default:
- return SCALE_TYPE_ONE;
- }
- }
-
- @Override
- public void draw(final Canvas canvas) {
- super.draw(canvas);
-
- final Rect bounds = getBounds();
- if (!isVisible() || bounds.isEmpty()) {
- return;
- }
-
- // Draw horizontal and vertical dividers.
- switch (mCount) {
- case 1:
- // 1 bitmap: passthrough
- break;
- case 2:
- // 2 bitmaps split vertically
- canvas.drawLine(bounds.centerX(), bounds.top, bounds.centerX(), bounds.bottom,
- mPaint);
- break;
- case 3:
- // 1st is tall on the left, 2nd/3rd stacked vertically on the right
- canvas.drawLine(bounds.centerX(), bounds.top, bounds.centerX(), bounds.bottom,
- mPaint);
- canvas.drawLine(bounds.centerX(), bounds.centerY(), bounds.right, bounds.centerY(),
- mPaint);
- break;
- case 4:
- // 4 bitmaps in a 2x2 grid
- canvas.drawLine(bounds.centerX(), bounds.top, bounds.centerX(), bounds.bottom,
- mPaint);
- canvas.drawLine(bounds.left, bounds.centerY(), bounds.right, bounds.centerY(),
- mPaint);
- break;
- }
- }
-
- @Override
- public void setAlpha(final int alpha) {
- super.setAlpha(alpha);
- final int old = mPaint.getAlpha();
- mPaint.setAlpha(alpha);
- if (alpha != old) {
- invalidateSelf();
- }
- }
-
- @Override
- public void setColorFilter(final ColorFilter cf) {
- super.setColorFilter(cf);
- mPaint.setColorFilter(cf);
- invalidateSelf();
- }
-
- public void setBitmapCache(final BitmapCache cache) {
- mCache = cache;
- }
-
- public void setContactResolver(final ContactResolver contactResolver) {
- mContactResolver = contactResolver;
- }
-}
diff --git a/src/com/android/mail/bitmap/TileDrawable.java b/src/com/android/mail/bitmap/TileDrawable.java
deleted file mode 100644
index 1d7708586..000000000
--- a/src/com/android/mail/bitmap/TileDrawable.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package com.android.mail.bitmap;
-
-import android.animation.ValueAnimator;
-import android.animation.ValueAnimator.AnimatorUpdateListener;
-import android.graphics.Canvas;
-import android.graphics.ColorFilter;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-
-/**
- * A drawable that wraps another drawable and places it in the center of this space. This drawable
- * allows a background color for the "tile", and has a fade-out transition when
- * {@link #setVisible(boolean, boolean)} indicates that it is no longer visible.
- */
-public class TileDrawable extends Drawable implements Drawable.Callback {
-
- private final Paint mPaint = new Paint();
- private final Drawable mInner;
- private final int mInnerWidth;
- private final int mInnerHeight;
-
- protected final ValueAnimator mFadeOutAnimator;
-
- public TileDrawable(Drawable inner, int innerWidth, int innerHeight,
- int backgroundColor, int fadeOutDurationMs) {
- mInner = inner.mutate();
- mInnerWidth = innerWidth;
- mInnerHeight = innerHeight;
- mPaint.setColor(backgroundColor);
- mInner.setCallback(this);
-
- mFadeOutAnimator = ValueAnimator.ofInt(255, 0)
- .setDuration(fadeOutDurationMs);
- mFadeOutAnimator.addUpdateListener(new AnimatorUpdateListener() {
- @Override
- public void onAnimationUpdate(ValueAnimator animation) {
- setAlpha((Integer) animation.getAnimatedValue());
- }
- });
-
- reset();
- }
-
- public void reset() {
- setAlpha(0);
- setVisible(false);
- }
-
- @Override
- protected void onBoundsChange(Rect bounds) {
- super.onBoundsChange(bounds);
-
- if (bounds.isEmpty()) {
- mInner.setBounds(0, 0, 0, 0);
- } else {
- final int l = bounds.left + (bounds.width() / 2) - (mInnerWidth / 2);
- final int t = bounds.top + (bounds.height() / 2) - (mInnerHeight / 2);
- mInner.setBounds(l, t, l + mInnerWidth, t + mInnerHeight);
- }
- }
-
- @Override
- public void draw(Canvas canvas) {
- if (!isVisible() && mPaint.getAlpha() == 0) {
- return;
- }
- canvas.drawRect(getBounds(), mPaint);
- mInner.draw(canvas);
- }
-
- @Override
- public void setAlpha(int alpha) {
- final int old = mPaint.getAlpha();
- mPaint.setAlpha(alpha);
- setInnerAlpha(alpha);
- if (alpha != old) {
- invalidateSelf();
- }
- }
-
- @Override
- public void setColorFilter(ColorFilter cf) {
- mPaint.setColorFilter(cf);
- mInner.setColorFilter(cf);
- }
-
- @Override
- public int getOpacity() {
- return 0;
- }
-
- protected int getCurrentAlpha() {
- return mPaint.getAlpha();
- }
-
- public boolean setVisible(boolean visible) {
- return setVisible(visible, true /* dontcare */);
- }
-
- @Override
- public boolean setVisible(boolean visible, boolean restart) {
- mInner.setVisible(visible, restart);
- final boolean changed = super.setVisible(visible, restart);
- if (changed) {
- if (isVisible()) {
- // pop in (no-op)
- // the transition will still be smooth if the previous state's layer fades out
- mFadeOutAnimator.cancel();
- setAlpha(255);
- } else {
- // fade out
- if (mPaint.getAlpha() == 255 && !getBounds().isEmpty()) {
- mFadeOutAnimator.start();
- }
- }
- }
- return changed;
- }
-
- @Override
- protected boolean onLevelChange(int level) {
- return mInner.setLevel(level);
- }
-
- /**
- * Changes the alpha on just the inner wrapped drawable.
- */
- public void setInnerAlpha(int alpha) {
- mInner.setAlpha(alpha);
- }
-
- @Override
- public void invalidateDrawable(Drawable who) {
- invalidateSelf();
- }
-
- @Override
- public void scheduleDrawable(Drawable who, Runnable what, long when) {
- scheduleSelf(what, when);
- }
-
- @Override
- public void unscheduleDrawable(Drawable who, Runnable what) {
- unscheduleSelf(what);
- }
-
-}
diff --git a/src/com/android/mail/browse/ConversationItemView.java b/src/com/android/mail/browse/ConversationItemView.java
index 023c1c3a6..84b3105c1 100644
--- a/src/com/android/mail/browse/ConversationItemView.java
+++ b/src/com/android/mail/browse/ConversationItemView.java
@@ -67,7 +67,7 @@ import android.widget.TextView;
import com.android.mail.R;
import com.android.mail.analytics.Analytics;
-import com.android.mail.bitmap.ContactCheckableGridDrawable;
+import com.android.mail.bitmap.CheckableContactFlipDrawable;
import com.android.mail.bitmap.ContactDrawable;
import com.android.mail.perf.Timer;
import com.android.mail.providers.Conversation;
@@ -80,7 +80,6 @@ import com.android.mail.ui.AnimatedAdapter;
import com.android.mail.ui.ControllableActivity;
import com.android.mail.ui.ConversationSelectionSet;
import com.android.mail.ui.ConversationSetObserver;
-import com.android.mail.ui.DividedImageCanvas;
import com.android.mail.ui.DividedImageCanvas.InvalidateCallback;
import com.android.mail.ui.FolderDisplayer;
import com.android.mail.ui.SwipeableItemView;
@@ -210,7 +209,7 @@ public class ConversationItemView extends View
private static int sScrollSlop;
private static CharacterStyle sActivatedTextSpan;
- private final ContactCheckableGridDrawable mSendersImageView;
+ private final CheckableContactFlipDrawable mSendersImageView;
/** The resource id of the color to use to override the background. */
private int mBackgroundOverrideResId = -1;
@@ -407,7 +406,7 @@ public class ConversationItemView extends View
ViewCompat.setLayoutDirection(mSnippetTextView, layoutDir);
ViewUtils.setTextAlignment(mSnippetTextView, View.TEXT_ALIGNMENT_VIEW_START);
- mSendersImageView = new ContactCheckableGridDrawable(res, sCabAnimationDuration);
+ mSendersImageView = new CheckableContactFlipDrawable(res, sCabAnimationDuration);
mSendersImageView.setCallback(this);
Utils.traceEndSection();
@@ -528,10 +527,7 @@ public class ConversationItemView extends View
// manager requests.
if (newlyBound || (mHeader.displayableNames != null && !mHeader
.displayableNames.equals(header.displayableNames))) {
- for (int i = 0; i < mSendersImageView.getCount(); i++) {
- mSendersImageView.getOrCreateDrawable(i).unbind();
- }
- mSendersImageView.setCount(0);
+ mSendersImageView.getContactDrawable().unbind();
}
if (newlyBound) {
@@ -554,8 +550,8 @@ public class ConversationItemView extends View
mAdapter = adapter;
Utils.traceBeginSection("drawables");
- mSendersImageView.setBitmapCache(mAdapter.getSendersImagesCache());
- mSendersImageView.setContactResolver(mAdapter.getContactResolver());
+ mSendersImageView.getContactDrawable().setBitmapCache(mAdapter.getSendersImagesCache());
+ mSendersImageView.getContactDrawable().setContactResolver(mAdapter.getContactResolver());
Utils.traceEndSection();
if (checkboxOrSenderImage == ConversationListIcon.SENDER_IMAGE) {
@@ -857,22 +853,14 @@ public class ConversationItemView extends View
return;
}
- Utils.traceBeginSection("load sender images");
- final int count = mHeader.displayableEmails.size();
-
- mSendersImageView.setCount(count);
mSendersImageView
.setBounds(0, 0, mCoordinates.contactImagesWidth, mCoordinates.contactImagesHeight);
- for (int i = 0; i < DividedImageCanvas.MAX_DIVISIONS && i < count; i++) {
- Utils.traceBeginSection("load single sender image");
- final ContactDrawable drawable = mSendersImageView.getOrCreateDrawable(i);
- drawable.setDecodeDimensions(mCoordinates.contactImagesWidth,
- mCoordinates.contactImagesHeight);
- drawable.bind(mHeader.displayableNames.get(i),
- mHeader.displayableEmails.get(i));
- Utils.traceEndSection();
- }
+ Utils.traceBeginSection("load sender image");
+ final ContactDrawable drawable = mSendersImageView.getContactDrawable();
+ drawable.setDecodeDimensions(mCoordinates.contactImagesWidth,
+ mCoordinates.contactImagesHeight);
+ drawable.bind(mHeader.displayableNames.get(0), mHeader.displayableEmails.get(0));
Utils.traceEndSection();
}