summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2014-12-11 15:23:48 +0100
committerDanny Baumann <dannybaumann@web.de>2014-12-11 15:28:38 +0100
commite486a7f531f6710aa59abaf1d4eeeb1f8417b129 (patch)
tree5e398cb92d5a8b86c4b5784b447b69bb996fe16a
parent5d3fe79d9ce4800084d5826041b13f0ae01408a6 (diff)
downloadandroid_packages_apps_ContactsCommon-e486a7f531f6710aa59abaf1d4eeeb1f8417b129.tar.gz
android_packages_apps_ContactsCommon-e486a7f531f6710aa59abaf1d4eeeb1f8417b129.tar.bz2
android_packages_apps_ContactsCommon-e486a7f531f6710aa59abaf1d4eeeb1f8417b129.zip
Fix checkmarks being displayed stretched for contact pictures.
Taking the intrinsic size of the contact picture for the whole drawable has the unwanted side effect of the picture size being applied to the checkmark drawable as well. Fix it by not applying an intrinsic size to the flip drawable and doing the scaling formerly done by ImageView by ourselves. Also take some cleanup potential. Change-Id: I0fb07d0631781a345e6a0602ac181a6d76cdf476
-rw-r--r--src/com/android/contacts/common/widget/CheckableFlipDrawable.java104
-rw-r--r--src/com/android/contacts/common/widget/CheckableImageView.java25
-rw-r--r--src/com/android/contacts/common/widget/CheckableQuickContactBadge.java25
-rw-r--r--src/com/android/contacts/common/widget/FlipDrawable.java10
4 files changed, 111 insertions, 53 deletions
diff --git a/src/com/android/contacts/common/widget/CheckableFlipDrawable.java b/src/com/android/contacts/common/widget/CheckableFlipDrawable.java
index cca82886..329b665c 100644
--- a/src/com/android/contacts/common/widget/CheckableFlipDrawable.java
+++ b/src/com/android/contacts/common/widget/CheckableFlipDrawable.java
@@ -22,6 +22,7 @@ import com.android.contacts.common.R;
public class CheckableFlipDrawable extends FlipDrawable implements
ValueAnimator.AnimatorUpdateListener {
+ private final FrontDrawable mFrontDrawable;
private final CheckmarkDrawable mCheckmarkDrawable;
private final ValueAnimator mCheckmarkScaleAnimator;
@@ -37,9 +38,10 @@ public class CheckableFlipDrawable extends FlipDrawable implements
public CheckableFlipDrawable(Drawable front, final Resources res,
final int checkBackgroundColor, final int flipDurationMs) {
- super(front, new CheckmarkDrawable(res, checkBackgroundColor),
+ super(new FrontDrawable(front), new CheckmarkDrawable(res, checkBackgroundColor),
flipDurationMs, 0 /* preFlipDurationMs */, POST_FLIP_DURATION_MS);
+ mFrontDrawable = (FrontDrawable) mFront;
mCheckmarkDrawable = (CheckmarkDrawable) mBack;
// We will create checkmark animations that are synchronized with the
@@ -67,17 +69,7 @@ public class CheckableFlipDrawable extends FlipDrawable implements
}
public void setFront(Drawable front) {
- mFront.setCallback(null);
-
- mFront = front;
-
- mFront.setCallback(this);
- mFront.setBounds(getBounds());
- mFront.setAlpha(getAlpha());
- mFront.setColorFilter(getColorFilter());
- mFront.setLevel(getLevel());
-
- reset();
+ mFrontDrawable.setInnerDrawable(front);
invalidateSelf();
}
@@ -130,6 +122,94 @@ public class CheckableFlipDrawable extends FlipDrawable implements
}
}
+ private static class FrontDrawable extends Drawable implements Drawable.Callback {
+ private Drawable mDrawable;
+
+ public FrontDrawable(Drawable d) {
+ mDrawable = d;
+ mDrawable.setCallback(this);
+ }
+
+ public void setInnerDrawable(Drawable d) {
+ mDrawable.setCallback(null);
+ mDrawable = d;
+ mDrawable.setCallback(this);
+ assignDrawableBounds(getBounds());
+ invalidateSelf();
+ }
+
+ @Override
+ protected void onBoundsChange(final Rect bounds) {
+ super.onBoundsChange(bounds);
+ assignDrawableBounds(bounds);
+ }
+
+ private void assignDrawableBounds(Rect bounds) {
+ int w = mDrawable.getIntrinsicWidth();
+ int h = mDrawable.getIntrinsicHeight();
+ if (w > 0 && h > 0) {
+ mDrawable.setBounds(0, 0, w, h);
+ } else {
+ mDrawable.setBounds(bounds);
+ }
+ }
+
+ @Override
+ public void draw(final Canvas canvas) {
+ final Rect bounds = getBounds();
+ if (!isVisible() || bounds.isEmpty()) {
+ return;
+ }
+
+ int w = mDrawable.getIntrinsicWidth();
+ int h = mDrawable.getIntrinsicHeight();
+
+ if (w <= 0 || h <= 0) {
+ mDrawable.draw(canvas);
+ } else {
+ final float widthScale = (float) bounds.width() / (float) w;
+ final float heightScale = (float) bounds.height() / (float) h;
+ final float scale = Math.max(widthScale, heightScale);
+
+ canvas.save();
+ canvas.scale(scale, scale);
+ canvas.translate(bounds.left, bounds.top);
+ mDrawable.draw(canvas);
+ canvas.restore();
+ }
+ }
+
+ @Override
+ public void setAlpha(final int alpha) {
+ mDrawable.setAlpha(alpha);
+ }
+
+ @Override
+ public void setColorFilter(final ColorFilter cf) {
+ mDrawable.setColorFilter(cf);
+ }
+
+ @Override
+ public int getOpacity() {
+ return mDrawable.getOpacity();
+ }
+
+ @Override
+ public void invalidateDrawable(final Drawable who) {
+ invalidateSelf();
+ }
+
+ @Override
+ public void scheduleDrawable(final Drawable who, final Runnable what, final long when) {
+ scheduleSelf(what, when);
+ }
+
+ @Override
+ public void unscheduleDrawable(final Drawable who, final Runnable what) {
+ unscheduleSelf(what);
+ }
+ }
+
private static class CheckmarkDrawable extends Drawable {
private static Bitmap sCheckMark;
diff --git a/src/com/android/contacts/common/widget/CheckableImageView.java b/src/com/android/contacts/common/widget/CheckableImageView.java
index 914d4eaf..57bac3e0 100644
--- a/src/com/android/contacts/common/widget/CheckableImageView.java
+++ b/src/com/android/contacts/common/widget/CheckableImageView.java
@@ -69,15 +69,7 @@ public class CheckableImageView extends ImageView implements Checkable {
}
mChecked = checked;
-
- Drawable d = getDrawable();
- if (d instanceof CheckableFlipDrawable) {
- CheckableFlipDrawable cfd = (CheckableFlipDrawable) d;
- cfd.flipTo(!mChecked);
- if (!animate) {
- cfd.reset();
- }
- }
+ applyCheckState(animate);
}
@Override
@@ -86,18 +78,19 @@ public class CheckableImageView extends ImageView implements Checkable {
if (mDrawable == null) {
mDrawable = new CheckableFlipDrawable(d, getResources(),
mCheckMarkBackgroundColor, 150);
+ applyCheckState(false);
} else {
- int oldWidth = mDrawable.getIntrinsicWidth();
- int oldHeight = mDrawable.getIntrinsicHeight();
mDrawable.setFront(d);
- if (oldWidth != mDrawable.getIntrinsicWidth()
- || oldHeight != mDrawable.getIntrinsicHeight()) {
- // enforce drawable size update + layout
- super.setImageDrawable(null);
- }
}
d = mDrawable;
}
super.setImageDrawable(d);
}
+
+ private void applyCheckState(boolean animate) {
+ mDrawable.flipTo(!mChecked);
+ if (!animate) {
+ mDrawable.reset();
+ }
+ }
}
diff --git a/src/com/android/contacts/common/widget/CheckableQuickContactBadge.java b/src/com/android/contacts/common/widget/CheckableQuickContactBadge.java
index 85160569..27b64660 100644
--- a/src/com/android/contacts/common/widget/CheckableQuickContactBadge.java
+++ b/src/com/android/contacts/common/widget/CheckableQuickContactBadge.java
@@ -69,14 +69,8 @@ public class CheckableQuickContactBadge extends QuickContactBadge implements Che
}
mChecked = checked;
-
- Drawable d = getDrawable();
- if (d instanceof CheckableFlipDrawable) {
- CheckableFlipDrawable cfd = (CheckableFlipDrawable) d;
- cfd.flipTo(!mChecked);
- if (!animate) {
- cfd.reset();
- }
+ if (mDrawable != null) {
+ applyCheckState(animate);
}
}
@@ -86,18 +80,19 @@ public class CheckableQuickContactBadge extends QuickContactBadge implements Che
if (mDrawable == null) {
mDrawable = new CheckableFlipDrawable(d, getResources(),
mCheckMarkBackgroundColor, 150);
+ applyCheckState(false);
} else {
- int oldWidth = mDrawable.getIntrinsicWidth();
- int oldHeight = mDrawable.getIntrinsicHeight();
mDrawable.setFront(d);
- if (oldWidth != mDrawable.getIntrinsicWidth()
- || oldHeight != mDrawable.getIntrinsicHeight()) {
- // enforce drawable size update + layout
- super.setImageDrawable(null);
- }
}
d = mDrawable;
}
super.setImageDrawable(d);
}
+
+ private void applyCheckState(boolean animate) {
+ mDrawable.flipTo(!mChecked);
+ if (!animate) {
+ mDrawable.reset();
+ }
+ }
}
diff --git a/src/com/android/contacts/common/widget/FlipDrawable.java b/src/com/android/contacts/common/widget/FlipDrawable.java
index ff14b508..ba62e0fe 100644
--- a/src/com/android/contacts/common/widget/FlipDrawable.java
+++ b/src/com/android/contacts/common/widget/FlipDrawable.java
@@ -115,16 +115,6 @@ public class FlipDrawable extends Drawable implements Drawable.Callback {
}
@Override
- public int getIntrinsicWidth() {
- return mFront.getIntrinsicWidth();
- }
-
- @Override
- public int getIntrinsicHeight() {
- return mFront.getIntrinsicHeight();
- }
-
- @Override
protected void onBoundsChange(final Rect bounds) {
super.onBoundsChange(bounds);
if (bounds.isEmpty()) {