summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/drawable/BitmapDrawable.java9
-rw-r--r--graphics/java/android/graphics/drawable/ColorDrawable.java2
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java6
-rw-r--r--graphics/java/android/graphics/drawable/DrawableContainer.java8
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java61
-rw-r--r--graphics/java/android/graphics/drawable/NinePatchDrawable.java5
6 files changed, 56 insertions, 35 deletions
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index 7a4a1ca..e82ccd4 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -80,7 +80,6 @@ public class BitmapDrawable extends Drawable {
@Deprecated
public BitmapDrawable() {
mBitmapState = new BitmapState((Bitmap) null);
- mMutated = true;
}
/**
@@ -91,7 +90,6 @@ public class BitmapDrawable extends Drawable {
public BitmapDrawable(Resources res) {
mBitmapState = new BitmapState((Bitmap) null);
mBitmapState.mTargetDensity = mTargetDensity;
- mMutated = true;
}
/**
@@ -102,7 +100,6 @@ public class BitmapDrawable extends Drawable {
@Deprecated
public BitmapDrawable(Bitmap bitmap) {
this(new BitmapState(bitmap), null);
- mMutated = true;
}
/**
@@ -112,7 +109,6 @@ public class BitmapDrawable extends Drawable {
public BitmapDrawable(Resources res, Bitmap bitmap) {
this(new BitmapState(bitmap), res);
mBitmapState.mTargetDensity = mTargetDensity;
- mMutated = true;
}
/**
@@ -126,7 +122,6 @@ public class BitmapDrawable extends Drawable {
if (mBitmap == null) {
android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath);
}
- mMutated = true;
}
/**
@@ -139,7 +134,6 @@ public class BitmapDrawable extends Drawable {
if (mBitmap == null) {
android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath);
}
- mMutated = true;
}
/**
@@ -153,7 +147,6 @@ public class BitmapDrawable extends Drawable {
if (mBitmap == null) {
android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is);
}
- mMutated = true;
}
/**
@@ -166,7 +159,6 @@ public class BitmapDrawable extends Drawable {
if (mBitmap == null) {
android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is);
}
- mMutated = true;
}
/**
@@ -560,7 +552,6 @@ public class BitmapDrawable extends Drawable {
} else {
mTargetDensity = state.mTargetDensity;
}
- mMutated = false;
setBitmap(state != null ? state.mBitmap : null);
}
}
diff --git a/graphics/java/android/graphics/drawable/ColorDrawable.java b/graphics/java/android/graphics/drawable/ColorDrawable.java
index f8e3944..4561397 100644
--- a/graphics/java/android/graphics/drawable/ColorDrawable.java
+++ b/graphics/java/android/graphics/drawable/ColorDrawable.java
@@ -43,7 +43,6 @@ public class ColorDrawable extends Drawable {
*/
public ColorDrawable() {
this(null);
- mMutated = true;
}
/**
@@ -54,7 +53,6 @@ public class ColorDrawable extends Drawable {
public ColorDrawable(int color) {
this(null);
setColor(color);
- mMutated = true;
}
private ColorDrawable(ColorState state) {
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index 020a54f..f9392e4 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -37,7 +37,6 @@ import android.util.DisplayMetrics;
import android.util.StateSet;
import android.util.TypedValue;
import android.util.Xml;
-import android.view.View;
import java.io.IOException;
import java.io.InputStream;
@@ -378,6 +377,8 @@ public abstract class Drawable {
*
* @return One of {@link android.view.View#LAYOUT_DIRECTION_LTR},
* {@link android.view.View#LAYOUT_DIRECTION_RTL}
+ *
+ * @hide
*/
public int getLayoutDirection() {
return mLayoutDirection;
@@ -388,8 +389,9 @@ public abstract class Drawable {
* Drawable as no capacity to do the resolution on his own.
*
* @param layoutDirection One of {@link android.view.View#LAYOUT_DIRECTION_LTR},
- * {@link android.view.View#LAYOUT_DIRECTION_RTL},
+ * {@link android.view.View#LAYOUT_DIRECTION_RTL}
*
+ * @hide
*/
public void setLayoutDirection(int layoutDirection) {
if (getLayoutDirection() != layoutDirection) {
diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java
index 486390c..41b272d 100644
--- a/graphics/java/android/graphics/drawable/DrawableContainer.java
+++ b/graphics/java/android/graphics/drawable/DrawableContainer.java
@@ -444,7 +444,6 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
int mConstantMinimumWidth;
int mConstantMinimumHeight;
- boolean mHaveOpacity = false;
int mOpacity;
boolean mHaveStateful = false;
@@ -493,7 +492,6 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
mConstantWidth = orig.mConstantWidth;
mConstantHeight = orig.mConstantHeight;
- mHaveOpacity = orig.mHaveOpacity;
mOpacity = orig.mOpacity;
mHaveStateful = orig.mHaveStateful;
mStateful = orig.mStateful;
@@ -528,7 +526,6 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
mDrawables[pos] = dr;
mNumChildren++;
mChildrenChangingConfigurations |= dr.getChangingConfigurations();
- mHaveOpacity = false;
mHaveStateful = false;
mConstantPadding = null;
@@ -656,10 +653,6 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
}
public final int getOpacity() {
- if (mHaveOpacity) {
- return mOpacity;
- }
-
final int N = getChildCount();
final Drawable[] drawables = mDrawables;
int op = N > 0 ? drawables[0].getOpacity() : PixelFormat.TRANSPARENT;
@@ -667,7 +660,6 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
op = Drawable.resolveOpacity(op, drawables[i].getOpacity());
}
mOpacity = op;
- mHaveOpacity = true;
return op;
}
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index 21344f4..2ca54d4 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -124,7 +124,7 @@ public class GradientDrawable extends Drawable {
private Paint mLayerPaint; // internal, used if we use saveLayer()
private boolean mRectIsDirty; // internal state
- private boolean mMutated = true;
+ private boolean mMutated;
private Path mRingPath;
private boolean mPathIsDirty = true;
@@ -435,7 +435,8 @@ public class GradientDrawable extends Drawable {
final int currFillAlpha = modulateAlpha(prevFillAlpha);
final int currStrokeAlpha = modulateAlpha(prevStrokeAlpha);
- final boolean haveStroke = currStrokeAlpha > 0 && mStrokePaint.getStrokeWidth() > 0;
+ final boolean haveStroke = currStrokeAlpha > 0 && mStrokePaint != null &&
+ mStrokePaint.getStrokeWidth() > 0;
final boolean haveFill = currFillAlpha > 0;
final GradientState st = mGradientState;
/* we need a layer iff we're drawing both a fill and stroke, and the
@@ -603,9 +604,9 @@ public class GradientDrawable extends Drawable {
/**
* <p>Changes this drawbale to use a single color instead of a gradient.</p>
- * <p><strong>Note</strong>: changing orientation will affect all instances
+ * <p><strong>Note</strong>: changing color will affect all instances
* of a drawable loaded from a resource. It is recommended to invoke
- * {@link #mutate()} before changing the orientation.</p>
+ * {@link #mutate()} before changing the color.</p>
*
* @param argb The color used to fill the shape
*
@@ -649,7 +650,7 @@ public class GradientDrawable extends Drawable {
@Override
public int getOpacity() {
- return PixelFormat.TRANSLUCENT;
+ return mGradientState.mOpaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT;
}
@Override
@@ -1011,7 +1012,10 @@ public class GradientDrawable extends Drawable {
} else {
Log.w("drawable", "Bad element under <shape>: " + name);
}
+
}
+
+ mGradientState.computeOpacity();
}
private static float getFloatOrFraction(TypedArray a, int index, float defaultValue) {
@@ -1079,10 +1083,11 @@ public class GradientDrawable extends Drawable {
private float mGradientRadius = 0.5f;
private boolean mUseLevel;
private boolean mUseLevelForShape;
+ private boolean mOpaque;
GradientState(Orientation orientation, int[] colors) {
mOrientation = orientation;
- mColors = colors;
+ setColors(colors);
}
public GradientState(GradientState state) {
@@ -1120,6 +1125,7 @@ public class GradientDrawable extends Drawable {
mGradientRadius = state.mGradientRadius;
mUseLevel = state.mUseLevel;
mUseLevelForShape = state.mUseLevelForShape;
+ mOpaque = state.mOpaque;
}
@Override
@@ -1139,6 +1145,7 @@ public class GradientDrawable extends Drawable {
public void setShape(int shape) {
mShape = shape;
+ computeOpacity();
}
public void setGradientType(int gradient) {
@@ -1153,24 +1160,60 @@ public class GradientDrawable extends Drawable {
public void setColors(int[] colors) {
mHasSolidColor = false;
mColors = colors;
+ computeOpacity();
}
public void setSolidColor(int argb) {
mHasSolidColor = true;
mSolidColor = argb;
mColors = null;
+ computeOpacity();
+ }
+
+ private void computeOpacity() {
+ if (mShape != RECTANGLE) {
+ mOpaque = false;
+ return;
+ }
+
+ if (mStrokeWidth > 0 && !isOpaque(mStrokeColor)) {
+ mOpaque = false;
+ return;
+ }
+
+ if (mHasSolidColor) {
+ mOpaque = isOpaque(mSolidColor);
+ return;
+ }
+
+ if (mColors != null) {
+ for (int i = 0; i < mColors.length; i++) {
+ if (!isOpaque(mColors[i])) {
+ mOpaque = false;
+ return;
+ }
+ }
+ }
+
+ mOpaque = true;
+ }
+
+ private static boolean isOpaque(int color) {
+ return ((color >> 24) & 0xff) == 0xff;
}
public void setStroke(int width, int color) {
mStrokeWidth = width;
mStrokeColor = color;
+ computeOpacity();
}
-
+
public void setStroke(int width, int color, float dashWidth, float dashGap) {
mStrokeWidth = width;
mStrokeColor = color;
mStrokeDashWidth = dashWidth;
mStrokeDashGap = dashGap;
+ computeOpacity();
}
public void setCornerRadius(float radius) {
@@ -1180,14 +1223,14 @@ public class GradientDrawable extends Drawable {
mRadius = radius;
mRadiusArray = null;
}
-
+
public void setCornerRadii(float[] radii) {
mRadiusArray = radii;
if (radii == null) {
mRadius = 0;
}
}
-
+
public void setSize(int width, int height) {
mWidth = width;
mHeight = height;
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index 7a43496..2ee6233 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -77,7 +77,6 @@ public class NinePatchDrawable extends Drawable {
@Deprecated
public NinePatchDrawable(Bitmap bitmap, byte[] chunk, Rect padding, String srcName) {
this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding), null);
- mMutated = true;
}
/**
@@ -88,7 +87,6 @@ public class NinePatchDrawable extends Drawable {
Rect padding, String srcName) {
this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding), res);
mNinePatchState.mTargetDensity = mTargetDensity;
- mMutated = true;
}
/**
@@ -101,7 +99,6 @@ public class NinePatchDrawable extends Drawable {
Rect padding, Rect layoutInsets, String srcName) {
this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding, layoutInsets), res);
mNinePatchState.mTargetDensity = mTargetDensity;
- mMutated = true;
}
/**
@@ -112,7 +109,6 @@ public class NinePatchDrawable extends Drawable {
@Deprecated
public NinePatchDrawable(NinePatch patch) {
this(new NinePatchState(patch, new Rect()), null);
- mMutated = true;
}
/**
@@ -122,7 +118,6 @@ public class NinePatchDrawable extends Drawable {
public NinePatchDrawable(Resources res, NinePatch patch) {
this(new NinePatchState(patch, new Rect()), res);
mNinePatchState.mTargetDensity = mTargetDensity;
- mMutated = true;
}
private void setNinePatchState(NinePatchState state, Resources res) {