OSDN Git Service

Move setTint into Drawable, unhide getDirtyBounds on Drawable
authorAlan Viverette <alanv@google.com>
Thu, 22 May 2014 06:50:03 +0000 (23:50 -0700)
committerAlan Viverette <alanv@google.com>
Thu, 22 May 2014 06:50:03 +0000 (23:50 -0700)
BUG: 15089957
Change-Id: Ib622ba24b3f4bcf430e1d524895ac5cb104a232e

api/current.txt
graphics/java/android/graphics/drawable/BitmapDrawable.java
graphics/java/android/graphics/drawable/Drawable.java
graphics/java/android/graphics/drawable/NinePatchDrawable.java
graphics/java/android/graphics/drawable/RippleDrawable.java

index 4a32b83..6ce2d55 100644 (file)
@@ -11193,7 +11193,6 @@ package android.graphics.drawable {
     method public final android.graphics.Paint getPaint();
     method public android.graphics.Shader.TileMode getTileModeX();
     method public android.graphics.Shader.TileMode getTileModeY();
-    method public android.content.res.ColorStateList getTint();
     method public boolean hasAntiAlias();
     method public boolean hasMipMap();
     method public final boolean isAutoMirrored();
@@ -11208,8 +11207,6 @@ package android.graphics.drawable {
     method public void setTileModeX(android.graphics.Shader.TileMode);
     method public void setTileModeXY(android.graphics.Shader.TileMode, android.graphics.Shader.TileMode);
     method public final void setTileModeY(android.graphics.Shader.TileMode);
-    method public void setTint(android.content.res.ColorStateList);
-    method public void setTintMode(android.graphics.PorterDuff.Mode);
   }
 
   public class ClipDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Drawable.Callback {
@@ -11262,6 +11259,7 @@ package android.graphics.drawable {
     method public android.graphics.ColorFilter getColorFilter();
     method public android.graphics.drawable.Drawable.ConstantState getConstantState();
     method public android.graphics.drawable.Drawable getCurrent();
+    method public android.graphics.Rect getDirtyBounds();
     method public int getIntrinsicHeight();
     method public int getIntrinsicWidth();
     method public final int getLevel();
@@ -11299,6 +11297,7 @@ package android.graphics.drawable {
     method public void setHotspotBounds(int, int, int, int);
     method public final boolean setLevel(int);
     method public boolean setState(int[]);
+    method public void setTint(android.content.res.ColorStateList, android.graphics.PorterDuff.Mode);
     method public boolean setVisible(boolean, boolean);
     method public void unscheduleSelf(java.lang.Runnable);
   }
@@ -11454,14 +11453,11 @@ package android.graphics.drawable {
     method public void draw(android.graphics.Canvas);
     method public int getOpacity();
     method public android.graphics.Paint getPaint();
-    method public android.content.res.ColorStateList getTint();
     method public void setAlpha(int);
     method public void setColorFilter(android.graphics.ColorFilter);
     method public void setTargetDensity(android.graphics.Canvas);
     method public void setTargetDensity(android.util.DisplayMetrics);
     method public void setTargetDensity(int);
-    method public void setTint(android.content.res.ColorStateList);
-    method public void setTintMode(android.graphics.PorterDuff.Mode);
   }
 
   public class PaintDrawable extends android.graphics.drawable.ShapeDrawable {
@@ -11482,10 +11478,6 @@ package android.graphics.drawable {
   }
 
   public class RippleDrawable extends android.graphics.drawable.LayerDrawable {
-    method public android.graphics.Rect getDirtyBounds();
-    method public android.content.res.ColorStateList getTint();
-    method public void setTint(android.content.res.ColorStateList);
-    method public void setTintMode(android.graphics.PorterDuff.Mode);
   }
 
   public class RotateDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Drawable.Callback {
index 6755f3e..f3fcf2c 100644 (file)
@@ -28,6 +28,7 @@ import android.graphics.ColorFilter;
 import android.graphics.Matrix;
 import android.graphics.Paint;
 import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
 import android.graphics.PorterDuff.Mode;
 import android.graphics.PorterDuffColorFilter;
 import android.graphics.Rect;
@@ -588,47 +589,22 @@ public class BitmapDrawable extends Drawable {
         return mBitmapState.mPaint.getColorFilter();
     }
 
-    /**
-     * Specifies a tint for this drawable.
-     * <p>
-     * Setting a color filter via {@link #setColorFilter(ColorFilter)} overrides
-     * tint.
-     *
-     * @param tint Color state list to use for tinting this drawable, or null to
-     *            clear the tint
-     */
-    public void setTint(ColorStateList tint) {
-        if (mBitmapState.mTint != tint) {
-            mBitmapState.mTint = tint;
-            computeTintFilter();
-            invalidateSelf();
-        }
+    @Override
+    public void setTint(ColorStateList tint, PorterDuff.Mode tintMode) {
+        mBitmapState.mTint = tint;
+        mBitmapState.mTintMode = tintMode;
+        computeTintFilter();
+        invalidateSelf();
     }
 
     /**
-     * Returns the tint color for this drawable.
-     *
-     * @return Color state list to use for tinting this drawable, or null if
-     *         none set
+     * @hide only needed by a hack within ProgressBar
      */
     public ColorStateList getTint() {
         return mBitmapState.mTint;
     }
 
     /**
-     * Specifies the blending mode used to apply tint.
-     *
-     * @param tintMode A Porter-Duff blending mode
-     */
-    public void setTintMode(Mode tintMode) {
-        if (mBitmapState.mTintMode != tintMode) {
-            mBitmapState.mTintMode = tintMode;
-            computeTintFilter();
-            invalidateSelf();
-        }
-    }
-
-    /**
      * @hide only needed by a hack within ProgressBar
      */
     public Mode getTintMode() {
index d6fb9e0..cc2a595 100644 (file)
@@ -24,6 +24,7 @@ import android.os.Trace;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
+import android.content.res.ColorStateList;
 import android.content.res.Resources;
 import android.content.res.Resources.Theme;
 import android.content.res.TypedArray;
@@ -226,7 +227,7 @@ public abstract class Drawable {
      * By default, this returns the full drawable bounds. Custom drawables may
      * override this method to perform more precise invalidation.
      *
-     * @hide
+     * @return The dirty bounds of this drawable
      */
     public Rect getDirtyBounds() {
         return getBounds();
@@ -469,6 +470,18 @@ public abstract class Drawable {
     }
 
     /**
+     * Specifies a tint and blending mode for this drawable.
+     * <p>
+     * Setting a color filter via {@link #setColorFilter(ColorFilter)} overrides
+     * tint.
+     *
+     * @param tint Color state list to use for tinting this drawable, or null to
+     *            clear the tint
+     * @param tintMode A Porter-Duff blending mode
+     */
+    public void setTint(ColorStateList tint, PorterDuff.Mode tintMode) {}
+
+    /**
      * Returns the current color filter, or {@code null} if none set.
      *
      * @return the current color filter, or {@code null} if none set
index 3e09707..0a07332 100644 (file)
@@ -28,6 +28,7 @@ import android.graphics.Insets;
 import android.graphics.NinePatch;
 import android.graphics.Paint;
 import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
 import android.graphics.PorterDuff.Mode;
 import android.graphics.PorterDuffColorFilter;
 import android.graphics.Rect;
@@ -327,44 +328,12 @@ public class NinePatchDrawable extends Drawable {
         invalidateSelf();
     }
 
-    /**
-     * Specifies a tint for this drawable.
-     * <p>
-     * Setting a color filter via {@link #setColorFilter(ColorFilter)} overrides
-     * tint.
-     *
-     * @param tint Color state list to use for tinting this drawable, or null to
-     *            clear the tint
-     */
-    public void setTint(ColorStateList tint) {
-        if (mNinePatchState.mTint != tint) {
-            mNinePatchState.mTint = tint;
-            computeTintFilter();
-            invalidateSelf();
-        }
-    }
-
-    /**
-     * Returns the tint color for this drawable.
-     *
-     * @return Color state list to use for tinting this drawable, or null if
-     *         none set
-     */
-    public ColorStateList getTint() {
-        return mNinePatchState.mTint;
-    }
-
-    /**
-     * Specifies the blending mode used to apply tint.
-     *
-     * @param tintMode A Porter-Duff blending mode
-     */
-    public void setTintMode(Mode tintMode) {
-        if (mNinePatchState.mTintMode != tintMode) {
-            mNinePatchState.mTintMode = tintMode;
-            computeTintFilter();
-            invalidateSelf();
-        }
+    @Override
+    public void setTint(ColorStateList tint, PorterDuff.Mode tintMode) {
+        mNinePatchState.mTint = tint;
+        mNinePatchState.mTintMode = tintMode;
+        computeTintFilter();
+        invalidateSelf();
     }
 
     private void computeTintFilter() {
index add3d84..1bd7cac 100644 (file)
@@ -207,35 +207,9 @@ public class RippleDrawable extends LayerDrawable {
         return true;
     }
 
-    /**
-     * Specifies a tint for drawing touch feedback ripples.
-     *
-     * @param tint Color state list to use for tinting touch feedback ripples,
-     *        or null to clear the tint
-     */
-    public void setTint(ColorStateList tint) {
-        if (mState.mTint != tint) {
-            mState.mTint = tint;
-            invalidateSelf();
-        }
-    }
-
-    /**
-     * Returns the tint color for touch feedback ripples.
-     *
-     * @return Color state list to use for tinting touch feedback ripples, or
-     *         null if none set
-     */
-    public ColorStateList getTint() {
-        return mState.mTint;
-    }
-
-    /**
-     * Specifies the blending mode used to draw touch feedback ripples.
-     *
-     * @param tintMode A Porter-Duff blending mode
-     */
-    public void setTintMode(Mode tintMode) {
+    @Override
+    public void setTint(ColorStateList tint, Mode tintMode) {
+        mState.mTint = tint;
         mState.setTintMode(tintMode);
         invalidateSelf();
     }
@@ -243,11 +217,13 @@ public class RippleDrawable extends LayerDrawable {
     @Override
     public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
             throws XmlPullParserException, IOException {
-        final TypedArray a = obtainAttributes(
-                r, theme, attrs, R.styleable.RippleDrawable);
+        final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.RippleDrawable);
         updateStateFromTypedArray(a);
         a.recycle();
 
+        // Force padding default to STACK before inflating.
+        setPaddingMode(PADDING_MODE_STACK);
+
         super.inflate(r, parser, attrs, theme);
 
         setTargetDensity(r.getDisplayMetrics());
@@ -275,6 +251,25 @@ public class RippleDrawable extends LayerDrawable {
     }
 
     /**
+     * Specifies how layer padding should affect the bounds of subsequent
+     * layers. The default and recommended value for RippleDrawable is
+     * {@link #PADDING_MODE_STACK}.
+     *
+     * @param mode padding mode, one of:
+     *            <ul>
+     *            <li>{@link #PADDING_MODE_NEST} to nest each layer inside the
+     *            padding of the previous layer
+     *            <li>{@link #PADDING_MODE_STACK} to stack each layer directly
+     *            atop the previous layer
+     *            </ul>
+     * @see #getPaddingMode()
+     */
+    @Override
+    public void setPaddingMode(int mode) {
+        super.setPaddingMode(mode);
+    }
+
+    /**
      * Initializes the constant state from the values in the typed array.
      */
     private void updateStateFromTypedArray(TypedArray a) {
@@ -643,8 +638,7 @@ public class RippleDrawable extends LayerDrawable {
         Drawable mMask;
         boolean mPinned = false;
 
-        public RippleState(
-                RippleState orig, RippleDrawable owner, Resources res) {
+        public RippleState(RippleState orig, RippleDrawable owner, Resources res) {
             super(orig, owner, res);
 
             if (orig != null) {
@@ -653,7 +647,6 @@ public class RippleDrawable extends LayerDrawable {
                 mTintXfermode = orig.mTintXfermode;
                 mTintXfermodeInverse = orig.mTintXfermodeInverse;
                 mPinned = orig.mPinned;
-                mMask = orig.mMask;
             }
         }
 
@@ -740,6 +733,8 @@ public class RippleDrawable extends LayerDrawable {
         }
 
         mState = ns;
+        mState.mMask = findDrawableByLayerId(R.id.mask);
+
         mLayerState = ns;
 
         if (ns.mNum > 0) {
@@ -749,7 +744,5 @@ public class RippleDrawable extends LayerDrawable {
         if (needsTheme) {
             applyTheme(theme);
         }
-
-        setPaddingMode(PADDING_MODE_STACK);
     }
 }