summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/ImageView.java
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2013-12-12 19:19:51 -0800
committerAlan Viverette <alanv@google.com>2013-12-12 19:19:51 -0800
commite10dd5389407481f49115b74a95cb4333cd1d63d (patch)
treeb26d2fb9ae8f55512cc087f9e2eb8572d403642d /core/java/android/widget/ImageView.java
parentf51021c32c1998456e1d8f6b0effc0297c2fff05 (diff)
downloadframeworks_base-e10dd5389407481f49115b74a95cb4333cd1d63d.zip
frameworks_base-e10dd5389407481f49115b74a95cb4333cd1d63d.tar.gz
frameworks_base-e10dd5389407481f49115b74a95cb4333cd1d63d.tar.bz2
Correctly report isOpaque() from ImageView
Includes special handling for attributes that can affect the image's drawing opacity and bounds, e.g. xfermode, alpha, and matrix transform. BUG: 12120109 Change-Id: Ieeec11ff35af899c4e6fcf6364633c15ec94241e
Diffstat (limited to 'core/java/android/widget/ImageView.java')
-rw-r--r--core/java/android/widget/ImageView.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index 79d5e5d..0f51fab 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -24,8 +24,10 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
+import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Xfermode;
import android.graphics.drawable.BitmapDrawable;
@@ -1225,6 +1227,37 @@ public class ImageView extends View {
}
}
+ @Override
+ public boolean isOpaque() {
+ return super.isOpaque() || mDrawable != null && mXfermode == null
+ && mDrawable.getOpacity() == PixelFormat.OPAQUE
+ && mAlpha * mViewAlphaScale >> 8 == 255
+ && isFilledByImage();
+ }
+
+ private boolean isFilledByImage() {
+ if (mDrawable == null) {
+ return false;
+ }
+
+ final Rect bounds = mDrawable.getBounds();
+ final Matrix matrix = mDrawMatrix;
+ if (matrix == null) {
+ return bounds.left <= 0 && bounds.top <= 0 && bounds.right >= getWidth()
+ && bounds.bottom >= getHeight();
+ } else if (matrix.rectStaysRect()) {
+ final RectF boundsSrc = mTempSrc;
+ final RectF boundsDst = mTempDst;
+ boundsSrc.set(bounds);
+ matrix.mapRect(boundsDst, boundsSrc);
+ return boundsDst.left <= 0 && boundsDst.top <= 0 && boundsDst.right >= getWidth()
+ && boundsDst.bottom >= getHeight();
+ } else {
+ // If the matrix doesn't map to a rectangle, assume the worst.
+ return false;
+ }
+ }
+
@RemotableViewMethod
@Override
public void setVisibility(int visibility) {