summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java16
-rw-r--r--graphics/java/android/graphics/drawable/BitmapDrawable.java34
-rw-r--r--graphics/java/android/graphics/drawable/DrawableContainer.java7
3 files changed, 51 insertions, 6 deletions
diff --git a/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java b/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java
index 46e3401..42872e9 100644
--- a/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java
@@ -80,6 +80,22 @@ public class AnimatedStateListDrawable extends StateListDrawable {
this(null, null);
}
+ @Override
+ public boolean setVisible(boolean visible, boolean restart) {
+ final boolean changed = super.setVisible(visible, restart);
+ if (mAnim != null) {
+ if (visible) {
+ if (changed || restart) {
+ // TODO: Should this support restart?
+ mAnim.end();
+ }
+ } else {
+ mAnim.end();
+ }
+ }
+ return changed;
+ }
+
/**
* Add a new drawable to the set of keyframes.
*
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index f3fcf2c..89a2fe9 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -25,6 +25,7 @@ import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
+import android.graphics.Insets;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
@@ -92,6 +93,9 @@ public class BitmapDrawable extends Drawable {
private int mBitmapWidth;
private int mBitmapHeight;
+ /** Optical insets due to gravity. */
+ private Insets mOpticalInsets = null;
+
// Mirroring matrix for using with Shaders
private Matrix mMirrorMatrix;
@@ -456,9 +460,9 @@ public class BitmapDrawable extends Drawable {
@Override
protected void onBoundsChange(Rect bounds) {
- super.onBoundsChange(bounds);
mApplyGravity = true;
- Shader shader = mBitmapState.mPaint.getShader();
+
+ final Shader shader = mBitmapState.mPaint.getShader();
if (shader != null) {
if (needMirroring()) {
updateMirrorMatrix(bounds.right - bounds.left);
@@ -517,9 +521,7 @@ public class BitmapDrawable extends Drawable {
final boolean needMirroring = needMirroring();
if (shader == null) {
if (mApplyGravity) {
- final int layoutDirection = getLayoutDirection();
- Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight,
- getBounds(), mDstRect, layoutDirection);
+ applyGravity();
mApplyGravity = false;
}
@@ -565,6 +567,28 @@ public class BitmapDrawable extends Drawable {
}
@Override
+ public Insets getOpticalInsets() {
+ if (mApplyGravity && mBitmapState.mPaint.getShader() == null) {
+ applyGravity();
+ mApplyGravity = false;
+ }
+ return mOpticalInsets == null ? Insets.NONE : mOpticalInsets;
+ }
+
+ private void applyGravity() {
+ final Rect bounds = getBounds();
+ final int layoutDirection = getLayoutDirection();
+ Gravity.apply(mBitmapState.mGravity, mBitmapWidth, mBitmapHeight,
+ bounds, mDstRect, layoutDirection);
+
+ final int left = mDstRect.left - bounds.left;
+ final int top = mDstRect.top - bounds.top;
+ final int right = bounds.right - mDstRect.right;
+ final int bottom = bounds.bottom - mDstRect.bottom;
+ mOpticalInsets = Insets.of(left, top, right, bottom);
+ }
+
+ @Override
public void setAlpha(int alpha) {
final int oldAlpha = mBitmapState.mPaint.getAlpha();
if (alpha != oldAlpha) {
diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java
index 04373d4..2aef39f 100644
--- a/graphics/java/android/graphics/drawable/DrawableContainer.java
+++ b/graphics/java/android/graphics/drawable/DrawableContainer.java
@@ -187,6 +187,9 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
}
if (mCurrDrawable != null) {
mCurrDrawable.setBounds(bounds);
+
+ // Must obtain optical insets after setting bounds.
+ mInsets = mCurrDrawable.getOpticalInsets();
}
}
@@ -385,7 +388,6 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
mCurrDrawable = d;
mCurIndex = idx;
if (d != null) {
- mInsets = d.getOpticalInsets();
d.mutate();
if (mDrawableContainerState.mEnterFadeDuration > 0) {
mEnterAnimationEnd = now + mDrawableContainerState.mEnterFadeDuration;
@@ -402,6 +404,9 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
d.setBounds(getBounds());
d.setLayoutDirection(getLayoutDirection());
d.setAutoMirrored(mDrawableContainerState.mAutoMirrored);
+
+ // Must obtain optical insets after setting bounds.
+ mInsets = d.getOpticalInsets();
} else {
mInsets = Insets.NONE;
}