summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2010-11-11 13:20:08 -0800
committerChet Haase <chet@google.com>2010-11-11 13:20:08 -0800
commit9891e1fce5f29d0421d34aa481037417bd70853d (patch)
tree5f14b902c6ad8ee3b917d55de8eaf638c7737fb6 /graphics
parentc55fa1b999068fc7f242b88a87270b249ab366eb (diff)
downloadframeworks_base-9891e1fce5f29d0421d34aa481037417bd70853d.zip
frameworks_base-9891e1fce5f29d0421d34aa481037417bd70853d.tar.gz
frameworks_base-9891e1fce5f29d0421d34aa481037417bd70853d.tar.bz2
Add invalidation to Drawable when its properties change
invalidateSelf() already exists on Drawable. This triggers a call to callback listeners so that they know the drawable has been invalidated. For example, the background drawable on View will cause the View itself to be invalidated. Change-Id: I45b231a7600dcf3bc139e4059b7c9940ff49f60c
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/drawable/BitmapDrawable.java40
-rw-r--r--graphics/java/android/graphics/drawable/ColorDrawable.java6
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java5
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java25
-rw-r--r--graphics/java/android/graphics/drawable/NinePatchDrawable.java17
-rw-r--r--graphics/java/android/graphics/drawable/PaintDrawable.java1
-rw-r--r--graphics/java/android/graphics/drawable/ShapeDrawable.java8
7 files changed, 76 insertions, 26 deletions
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index 32111e8..032244f 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -174,11 +174,14 @@ public class BitmapDrawable extends Drawable {
}
private void setBitmap(Bitmap bitmap) {
- mBitmap = bitmap;
- if (bitmap != null) {
- computeBitmapSize();
- } else {
- mBitmapWidth = mBitmapHeight = -1;
+ if (bitmap != mBitmap) {
+ mBitmap = bitmap;
+ if (bitmap != null) {
+ computeBitmapSize();
+ } else {
+ mBitmapWidth = mBitmapHeight = -1;
+ }
+ invalidateSelf();
}
}
@@ -205,10 +208,7 @@ public class BitmapDrawable extends Drawable {
* @see android.graphics.Bitmap#getDensity()
*/
public void setTargetDensity(DisplayMetrics metrics) {
- mTargetDensity = metrics.densityDpi;
- if (mBitmap != null) {
- computeBitmapSize();
- }
+ setTargetDensity(metrics.densityDpi);
}
/**
@@ -220,9 +220,12 @@ public class BitmapDrawable extends Drawable {
* @see android.graphics.Bitmap#getDensity()
*/
public void setTargetDensity(int density) {
- mTargetDensity = density == 0 ? DisplayMetrics.DENSITY_DEFAULT : density;
- if (mBitmap != null) {
- computeBitmapSize();
+ if (mTargetDensity != density) {
+ mTargetDensity = density == 0 ? DisplayMetrics.DENSITY_DEFAULT : density;
+ if (mBitmap != null) {
+ computeBitmapSize();
+ }
+ invalidateSelf();
}
}
@@ -239,22 +242,28 @@ public class BitmapDrawable extends Drawable {
* @param gravity the gravity
*/
public void setGravity(int gravity) {
- mBitmapState.mGravity = gravity;
- mApplyGravity = true;
+ if (mBitmapState.mGravity != gravity) {
+ mBitmapState.mGravity = gravity;
+ mApplyGravity = true;
+ invalidateSelf();
+ }
}
public void setAntiAlias(boolean aa) {
mBitmapState.mPaint.setAntiAlias(aa);
+ invalidateSelf();
}
@Override
public void setFilterBitmap(boolean filter) {
mBitmapState.mPaint.setFilterBitmap(filter);
+ invalidateSelf();
}
@Override
public void setDither(boolean dither) {
mBitmapState.mPaint.setDither(dither);
+ invalidateSelf();
}
public Shader.TileMode getTileModeX() {
@@ -280,6 +289,7 @@ public class BitmapDrawable extends Drawable {
state.mTileModeX = xmode;
state.mTileModeY = ymode;
mRebuildShader = true;
+ invalidateSelf();
}
}
@@ -336,11 +346,13 @@ public class BitmapDrawable extends Drawable {
@Override
public void setAlpha(int alpha) {
mBitmapState.mPaint.setAlpha(alpha);
+ invalidateSelf();
}
@Override
public void setColorFilter(ColorFilter cf) {
mBitmapState.mPaint.setColorFilter(cf);
+ invalidateSelf();
}
/**
diff --git a/graphics/java/android/graphics/drawable/ColorDrawable.java b/graphics/java/android/graphics/drawable/ColorDrawable.java
index 289348a..4d560be 100644
--- a/graphics/java/android/graphics/drawable/ColorDrawable.java
+++ b/graphics/java/android/graphics/drawable/ColorDrawable.java
@@ -87,7 +87,10 @@ public class ColorDrawable extends Drawable {
* @param color The color to draw.
*/
public void setColor(int color) {
- mState.mBaseColor = mState.mUseColor = color;
+ if (mState.mBaseColor != color || mState.mUseColor != color) {
+ invalidateSelf();
+ mState.mBaseColor = mState.mUseColor = color;
+ }
}
/**
@@ -109,6 +112,7 @@ public class ColorDrawable extends Drawable {
int baseAlpha = mState.mBaseColor >>> 24;
int useAlpha = baseAlpha * alpha >> 8;
mState.mUseColor = (mState.mBaseColor << 8 >>> 8) | (useAlpha << 24);
+ invalidateSelf();
}
/**
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index baa9d62..2f13bef 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -488,7 +488,10 @@ public abstract class Drawable {
*/
public boolean setVisible(boolean visible, boolean restart) {
boolean changed = mVisible != visible;
- mVisible = visible;
+ if (changed) {
+ mVisible = visible;
+ invalidateSelf();
+ }
return changed;
}
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index c558632..da8bb1b 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -180,6 +180,7 @@ public class GradientDrawable extends Drawable {
public void setCornerRadii(float[] radii) {
mGradientState.setCornerRadii(radii);
mPathIsDirty = true;
+ invalidateSelf();
}
/**
@@ -189,6 +190,7 @@ public class GradientDrawable extends Drawable {
public void setCornerRadius(float radius) {
mGradientState.setCornerRadius(radius);
mPathIsDirty = true;
+ invalidateSelf();
}
/**
@@ -214,34 +216,41 @@ public class GradientDrawable extends Drawable {
e = new DashPathEffect(new float[] { dashWidth, dashGap }, 0);
}
mStrokePaint.setPathEffect(e);
+ invalidateSelf();
}
public void setSize(int width, int height) {
mGradientState.setSize(width, height);
mPathIsDirty = true;
+ invalidateSelf();
}
public void setShape(int shape) {
mRingPath = null;
mPathIsDirty = true;
mGradientState.setShape(shape);
+ invalidateSelf();
}
public void setGradientType(int gradient) {
mGradientState.setGradientType(gradient);
mRectIsDirty = true;
+ invalidateSelf();
}
public void setGradientCenter(float x, float y) {
mGradientState.setGradientCenter(x, y);
+ invalidateSelf();
}
public void setGradientRadius(float gradientRadius) {
mGradientState.setGradientRadius(gradientRadius);
+ invalidateSelf();
}
public void setUseLevel(boolean useLevel) {
mGradientState.mUseLevel = useLevel;
+ invalidateSelf();
}
private int modulateAlpha(int alpha) {
@@ -433,6 +442,7 @@ public class GradientDrawable extends Drawable {
public void setColor(int argb) {
mGradientState.setSolidColor(argb);
mFillPaint.setColor(argb);
+ invalidateSelf();
}
@Override
@@ -443,17 +453,26 @@ public class GradientDrawable extends Drawable {
@Override
public void setAlpha(int alpha) {
- mAlpha = alpha;
+ if (alpha != mAlpha) {
+ mAlpha = alpha;
+ invalidateSelf();
+ }
}
@Override
public void setDither(boolean dither) {
- mDither = dither;
+ if (dither != mDither) {
+ mDither = dither;
+ invalidateSelf();
+ }
}
@Override
public void setColorFilter(ColorFilter cf) {
- mColorFilter = cf;
+ if (cf != mColorFilter) {
+ mColorFilter = cf;
+ invalidateSelf();
+ }
}
@Override
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index 50b4b75..35b8319 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -132,10 +132,7 @@ public class NinePatchDrawable extends Drawable {
* @see android.graphics.Bitmap#getDensity()
*/
public void setTargetDensity(DisplayMetrics metrics) {
- mTargetDensity = metrics.densityDpi;
- if (mNinePatch != null) {
- computeBitmapSize();
- }
+ setTargetDensity(metrics.densityDpi);
}
/**
@@ -147,9 +144,12 @@ public class NinePatchDrawable extends Drawable {
* @see android.graphics.Bitmap#getDensity()
*/
public void setTargetDensity(int density) {
- mTargetDensity = density == 0 ? DisplayMetrics.DENSITY_DEFAULT : density;
- if (mNinePatch != null) {
- computeBitmapSize();
+ if (density != mTargetDensity) {
+ mTargetDensity = density == 0 ? DisplayMetrics.DENSITY_DEFAULT : density;
+ if (mNinePatch != null) {
+ computeBitmapSize();
+ }
+ invalidateSelf();
}
}
@@ -197,16 +197,19 @@ public class NinePatchDrawable extends Drawable {
@Override
public void setAlpha(int alpha) {
getPaint().setAlpha(alpha);
+ invalidateSelf();
}
@Override
public void setColorFilter(ColorFilter cf) {
getPaint().setColorFilter(cf);
+ invalidateSelf();
}
@Override
public void setDither(boolean dither) {
getPaint().setDither(dither);
+ invalidateSelf();
}
@Override
diff --git a/graphics/java/android/graphics/drawable/PaintDrawable.java b/graphics/java/android/graphics/drawable/PaintDrawable.java
index c86fc46..c71cda1 100644
--- a/graphics/java/android/graphics/drawable/PaintDrawable.java
+++ b/graphics/java/android/graphics/drawable/PaintDrawable.java
@@ -66,6 +66,7 @@ public class PaintDrawable extends ShapeDrawable {
} else {
setShape(new RoundRectShape(radii, null, null));
}
+ invalidateSelf();
}
@Override
diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java
index be1892e..92252fc 100644
--- a/graphics/java/android/graphics/drawable/ShapeDrawable.java
+++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java
@@ -129,6 +129,7 @@ public class ShapeDrawable extends Drawable {
}
mShapeState.mPadding.set(left, top, right, bottom);
}
+ invalidateSelf();
}
/**
@@ -144,6 +145,7 @@ public class ShapeDrawable extends Drawable {
}
mShapeState.mPadding.set(padding);
}
+ invalidateSelf();
}
/**
@@ -153,6 +155,7 @@ public class ShapeDrawable extends Drawable {
*/
public void setIntrinsicWidth(int width) {
mShapeState.mIntrinsicWidth = width;
+ invalidateSelf();
}
/**
@@ -162,6 +165,7 @@ public class ShapeDrawable extends Drawable {
*/
public void setIntrinsicHeight(int height) {
mShapeState.mIntrinsicHeight = height;
+ invalidateSelf();
}
@Override
@@ -236,11 +240,13 @@ public class ShapeDrawable extends Drawable {
*/
@Override public void setAlpha(int alpha) {
mShapeState.mAlpha = alpha;
+ invalidateSelf();
}
@Override
public void setColorFilter(ColorFilter cf) {
mShapeState.mPaint.setColorFilter(cf);
+ invalidateSelf();
}
@Override
@@ -264,6 +270,7 @@ public class ShapeDrawable extends Drawable {
@Override
public void setDither(boolean dither) {
mShapeState.mPaint.setDither(dither);
+ invalidateSelf();
}
@Override
@@ -344,6 +351,7 @@ public class ShapeDrawable extends Drawable {
mShapeState.mPaint.setShader(mShapeState.mShaderFactory.resize(w, h));
}
}
+ invalidateSelf();
}
@Override