summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2014-05-22 22:43:59 -0700
committerAlan Viverette <alanv@google.com>2014-05-22 22:43:59 -0700
commit2356c5e69b0911e6334ebf6374217898371be5ac (patch)
tree6320dad09a0606cda175f400c08f063c7f48dbef /graphics
parent42b30e1b832df5bbf109db2f4f864f8ba4cfd44a (diff)
downloadframeworks_base-2356c5e69b0911e6334ebf6374217898371be5ac.zip
frameworks_base-2356c5e69b0911e6334ebf6374217898371be5ac.tar.gz
frameworks_base-2356c5e69b0911e6334ebf6374217898371be5ac.tar.bz2
Update switch, checkbox, radio button, button, and toggle button
Add optical inset support to BitmapDrawable with gravity. Fix optical inset support in DrawableContainer. Fix visibility change support in AnimatedStateListDrawable. Adds a whole bunch of missing drawable support to CheckedTextView. BUG: 15127013 BUG: 15126976 BUG: 15125529 BUG: 15025806 BUG: 14597955 BUG: 14594498 BUG: 15152746 Change-Id: Id2d99e10838d25b6f927ca1e49996c8da8e78ab1
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;
}