diff options
author | Alan Viverette <alanv@google.com> | 2014-06-02 16:39:04 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-06-02 16:39:04 -0700 |
commit | 6dbe51b50e82057af4d29882889444d22ac19c9c (patch) | |
tree | b06469b2ed2f73a95efb63cd6e5ffdb805a802ca | |
parent | 66268f5d32106aafcbb56370f9800bde0c94cb0d (diff) | |
download | frameworks_base-6dbe51b50e82057af4d29882889444d22ac19c9c.zip frameworks_base-6dbe51b50e82057af4d29882889444d22ac19c9c.tar.gz frameworks_base-6dbe51b50e82057af4d29882889444d22ac19c9c.tar.bz2 |
Clean up drawable theming APIs
Removes APIs for themed creation of a drawable from a stream, since
that doesn't involve any inflation. Also cleans up tinting methods
left over from previous clean up.
BUG: 15089957
Change-Id: I2af7aa9a6d351ae61b33ee1216c674fae1bffe11
Signed-off-by: Alan Viverette <alanv@google.com>
17 files changed, 49 insertions, 97 deletions
diff --git a/api/current.txt b/api/current.txt index da8b3fd..555af77 100644 --- a/api/current.txt +++ b/api/current.txt @@ -11236,14 +11236,11 @@ package android.graphics.drawable { method public static android.graphics.drawable.Drawable createFromPath(java.lang.String); method public static android.graphics.drawable.Drawable createFromResourceStream(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, java.lang.String); method public static android.graphics.drawable.Drawable createFromResourceStream(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, java.lang.String, android.graphics.BitmapFactory.Options); - method public static android.graphics.drawable.Drawable createFromResourceStreamThemed(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, java.lang.String, android.content.res.Resources.Theme); - method public static android.graphics.drawable.Drawable createFromResourceStreamThemed(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, java.lang.String, android.graphics.BitmapFactory.Options, android.content.res.Resources.Theme); method public static android.graphics.drawable.Drawable createFromStream(java.io.InputStream, java.lang.String); - method public static android.graphics.drawable.Drawable createFromStreamThemed(java.io.InputStream, java.lang.String, android.content.res.Resources.Theme); method public static android.graphics.drawable.Drawable createFromXml(android.content.res.Resources, org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static android.graphics.drawable.Drawable createFromXml(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.content.res.Resources.Theme) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; method public static android.graphics.drawable.Drawable createFromXmlInner(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; - method public static android.graphics.drawable.Drawable createFromXmlInnerThemed(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet, android.content.res.Resources.Theme) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; - method public static android.graphics.drawable.Drawable createFromXmlThemed(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.content.res.Resources.Theme) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static android.graphics.drawable.Drawable createFromXmlInner(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet, android.content.res.Resources.Theme) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; method public abstract void draw(android.graphics.Canvas); method public int getAlpha(); method public final android.graphics.Rect getBounds(); @@ -11519,7 +11516,6 @@ package android.graphics.drawable { method public android.graphics.Paint getPaint(); method public android.graphics.drawable.ShapeDrawable.ShaderFactory getShaderFactory(); method public android.graphics.drawable.shapes.Shape getShape(); - method public android.content.res.ColorStateList getTint(); method protected boolean inflateTag(java.lang.String, android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet); method protected void onDraw(android.graphics.drawable.shapes.Shape, android.graphics.Canvas, android.graphics.Paint); method public void setAlpha(int); @@ -11530,7 +11526,6 @@ package android.graphics.drawable { method public void setPadding(android.graphics.Rect); method public void setShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory); method public void setShape(android.graphics.drawable.shapes.Shape); - method public void setTint(android.content.res.ColorStateList); } public static abstract class ShapeDrawable.ShaderFactory { diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 3737638..ed3f9aa 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -702,12 +702,17 @@ public class Resources { * Context.obtainStyledAttributes} with * an array containing the resource ID of interest to create the TypedArray.</p> * + * <p class="note"><strong>Note:</strong> To obtain a themed drawable, use + * {@link android.content.Context#getDrawable(int) Context.getDrawable(int)} + * or {@link #getDrawable(int, Theme)} passing the desired theme.</p> + * * @param id The desired resource identifier, as generated by the aapt * tool. This integer encodes the package, type, and resource * entry. The value 0 is an invalid identifier. * @return Drawable An object that can be used to draw this resource. * @throws NotFoundException Throws NotFoundException if the given ID does * not exist. + * @see #getDrawable(int, Theme) */ public Drawable getDrawable(int id) throws NotFoundException { return getDrawable(id, null); @@ -715,7 +720,9 @@ public class Resources { /** * Return a drawable object associated with a particular resource ID and - * styled for the specified theme. + * styled for the specified theme. Various types of objects will be + * returned depending on the underlying resource -- for example, a solid + * color, PNG image, scalable image, etc. * * @param id The desired resource identifier, as generated by the aapt * tool. This integer encodes the package, type, and resource @@ -755,6 +762,11 @@ public class Resources { * image, scalable image, etc. The Drawable API hides these implementation * details. * + * <p class="note"><strong>Note:</strong> To obtain a themed drawable, use + * {@link android.content.Context#getDrawable(int) Context.getDrawable(int)} + * or {@link #getDrawableForDensity(int, int, Theme)} passing the desired + * theme.</p> + * * @param id The desired resource identifier, as generated by the aapt tool. * This integer encodes the package, type, and resource entry. * The value 0 is an invalid identifier. @@ -2340,12 +2352,12 @@ public class Resources { if (file.endsWith(".xml")) { final XmlResourceParser rp = loadXmlResourceParser( file, id, value.assetCookie, "drawable"); - dr = Drawable.createFromXmlThemed(this, rp, theme); + dr = Drawable.createFromXml(this, rp, theme); rp.close(); } else { final InputStream is = mAssets.openNonAsset( value.assetCookie, file, AssetManager.ACCESS_STREAMING); - dr = Drawable.createFromResourceStreamThemed(this, value, is, file, null, theme); + dr = Drawable.createFromResourceStream(this, value, is, file, null); is.close(); } } catch (Exception e) { diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java index eedacb5..572302a 100644 --- a/core/java/android/widget/ImageView.java +++ b/core/java/android/widget/ImageView.java @@ -664,7 +664,7 @@ public class ImageView extends View { InputStream stream = null; try { stream = mContext.getContentResolver().openInputStream(mUri); - d = Drawable.createFromStreamThemed(stream, null, mContext.getTheme()); + d = Drawable.createFromStream(stream, null); } catch (Exception e) { Log.w("ImageView", "Unable to open content: " + mUri, e); } finally { diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index 0c3715d..b49938c 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -357,9 +357,8 @@ public class ProgressBar extends View { Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); shapeDrawable.getPaint().setShader(bitmapShader); - // Ensure the color filter and tint are propagated. - shapeDrawable.setTint(bitmap.getTint()); - shapeDrawable.setTintMode(bitmap.getTintMode()); + // Ensure the tint and filter are propagated in the correct order. + shapeDrawable.setTint(bitmap.getTint(), bitmap.getTintMode()); shapeDrawable.setColorFilter(bitmap.getColorFilter()); return clip ? new ClipDrawable( diff --git a/core/java/android/widget/SuggestionsAdapter.java b/core/java/android/widget/SuggestionsAdapter.java index 0203301..c8917e0 100644 --- a/core/java/android/widget/SuggestionsAdapter.java +++ b/core/java/android/widget/SuggestionsAdapter.java @@ -574,7 +574,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene throw new FileNotFoundException("Failed to open " + uri); } try { - return Drawable.createFromStreamThemed(stream, null, mContext.getTheme()); + return Drawable.createFromStream(stream, null); } finally { try { stream.close(); diff --git a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java index a37ceef..e8024f7 100644 --- a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java @@ -260,7 +260,7 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac continue; } - if ((drawable = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme)) == null) { + if ((drawable = Drawable.createFromXmlInner(r, parser, attrs, theme)) == null) { Log.w("drawable", "Bad element under <animated-rotate>: " + parser .getName()); } diff --git a/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java b/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java index 42872e9..a5a074c 100644 --- a/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java @@ -301,7 +301,7 @@ public class AnimatedStateListDrawable extends StateListDrawable { + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable"); } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } final AnimationDrawable anim; @@ -355,7 +355,7 @@ public class AnimatedStateListDrawable extends StateListDrawable { + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable"); } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } return mState.addStateSet(states, dr, keyframeId); diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index da4bc10..0ee253a 100644 --- a/graphics/java/android/graphics/drawable/AnimationDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java @@ -293,7 +293,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An ": <item> tag requires a 'drawable' attribute or child tag" + " defining a drawable"); } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } mAnimationState.addFrame(dr, duration); diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java index 3dbd235..3ac9972 100644 --- a/graphics/java/android/graphics/drawable/ClipDrawable.java +++ b/graphics/java/android/graphics/drawable/ClipDrawable.java @@ -95,7 +95,7 @@ public class ClipDrawable extends Drawable implements Drawable.Callback { if (type != XmlPullParser.START_TAG) { continue; } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } if (dr == null) { diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index cc2a595..f29b9f0 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -892,13 +892,9 @@ public abstract class Drawable { * Create a drawable from an inputstream */ public static Drawable createFromStream(InputStream is, String srcName) { - return createFromStreamThemed(is, srcName, null); - } - - public static Drawable createFromStreamThemed(InputStream is, String srcName, Theme theme) { Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, srcName != null ? srcName : "Unknown drawable"); try { - return createFromResourceStreamThemed(null, null, is, srcName, theme); + return createFromResourceStream(null, null, is, srcName); } finally { Trace.traceEnd(Trace.TRACE_TAG_RESOURCES); } @@ -910,14 +906,9 @@ public abstract class Drawable { */ public static Drawable createFromResourceStream(Resources res, TypedValue value, InputStream is, String srcName) { - return createFromResourceStreamThemed(res, value, is, srcName, null); - } - - public static Drawable createFromResourceStreamThemed(Resources res, TypedValue value, - InputStream is, String srcName, Theme theme) { Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, srcName != null ? srcName : "Unknown drawable"); try { - return createFromResourceStreamThemed(res, value, is, srcName, null, theme); + return createFromResourceStream(res, value, is, srcName); } finally { Trace.traceEnd(Trace.TRACE_TAG_RESOURCES); } @@ -929,11 +920,6 @@ public abstract class Drawable { */ public static Drawable createFromResourceStream(Resources res, TypedValue value, InputStream is, String srcName, BitmapFactory.Options opts) { - return createFromResourceStreamThemed(res, value, is, srcName, opts, null); - } - - public static Drawable createFromResourceStreamThemed(Resources res, TypedValue value, - InputStream is, String srcName, BitmapFactory.Options opts, Theme theme) { if (is == null) { return null; } @@ -981,15 +967,15 @@ public abstract class Drawable { */ public static Drawable createFromXml(Resources r, XmlPullParser parser) throws XmlPullParserException, IOException { - return createFromXmlThemed(r, parser, null); + return createFromXml(r, parser, null); } /** - * Create a themed drawable from an XML document. For more information on - * how to create resources in XML, see + * Create a drawable from an XML document using an optional {@link Theme}. + * For more information on how to create resources in XML, see * <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>. */ - public static Drawable createFromXmlThemed(Resources r, XmlPullParser parser, Theme theme) + public static Drawable createFromXml(Resources r, XmlPullParser parser, Theme theme) throws XmlPullParserException, IOException { AttributeSet attrs = Xml.asAttributeSet(parser); @@ -1003,7 +989,7 @@ public abstract class Drawable { throw new XmlPullParserException("No start tag found"); } - Drawable drawable = createFromXmlInnerThemed(r, parser, attrs, theme); + Drawable drawable = createFromXmlInner(r, parser, attrs, theme); if (drawable == null) { throw new RuntimeException("Unknown initial tag: " + parser.getName()); @@ -1019,16 +1005,17 @@ public abstract class Drawable { */ public static Drawable createFromXmlInner(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { - return createFromXmlInnerThemed(r, parser, attrs, null); + return createFromXmlInner(r, parser, attrs, null); } /** - * Create a themed drawable from inside an XML document. Called on a parser - * positioned at a tag in an XML document, tries to create a Drawable from - * that tag. Returns null if the tag is not a valid drawable. + * Create a drawable from inside an XML document using an optional + * {@link Theme}. Called on a parser positioned at a tag in an XML + * document, tries to create a Drawable from that tag. Returns {@code null} + * if the tag is not a valid drawable. */ - public static Drawable createFromXmlInnerThemed(Resources r, XmlPullParser parser, - AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { + public static Drawable createFromXmlInner(Resources r, XmlPullParser parser, AttributeSet attrs, + Theme theme) throws XmlPullParserException, IOException { final Drawable drawable; final String name = parser.getName(); diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index 2fa5929..9e0ab86 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -111,7 +111,7 @@ public class InsetDrawable extends Drawable implements Drawable.Callback + ": <inset> tag requires a 'drawable' attribute or " + "child tag defining a drawable"); } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } if (dr == null) { diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 75cb0a0..27f0a9d 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -211,7 +211,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable"); } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } addLayer(dr, themeAttrs, id, left, top, right, bottom); diff --git a/graphics/java/android/graphics/drawable/LevelListDrawable.java b/graphics/java/android/graphics/drawable/LevelListDrawable.java index 9f6c0ad..7271b0e 100644 --- a/graphics/java/android/graphics/drawable/LevelListDrawable.java +++ b/graphics/java/android/graphics/drawable/LevelListDrawable.java @@ -134,7 +134,7 @@ public class LevelListDrawable extends DrawableContainer { + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable"); } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } mLevelListState.addLevel(low, high, dr); diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java index 5f9d1cd..06aeb98 100644 --- a/graphics/java/android/graphics/drawable/RotateDrawable.java +++ b/graphics/java/android/graphics/drawable/RotateDrawable.java @@ -438,7 +438,7 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { continue; } - if ((drawable = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme)) == null) { + if ((drawable = Drawable.createFromXmlInner(r, parser, attrs, theme)) == null) { Log.w("drawable", "Bad element under <rotate>: " + parser .getName()); } diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index 4c4d9af..f090c11 100644 --- a/graphics/java/android/graphics/drawable/ScaleDrawable.java +++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java @@ -108,7 +108,7 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { if (type != XmlPullParser.START_TAG) { continue; } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } if (dr == null) { diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java index 99ab4dd..024f77c 100644 --- a/graphics/java/android/graphics/drawable/ShapeDrawable.java +++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java @@ -291,41 +291,10 @@ public class ShapeDrawable extends Drawable { return mShapeState.mAlpha; } - /** - * 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 (mShapeState.mTint != tint) { + @Override + public void setTint(ColorStateList tint, Mode tintMode) { + if (mShapeState.mTint != tint || mShapeState.mTintMode != tintMode) { mShapeState.mTint = tint; - updateTintFilter(); - 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 mShapeState.mTint; - } - - /** - * Specifies the blending mode used to apply tint. - * - * @param tintMode A Porter-Duff blending mode - * @hide Pending finalization of supported Modes - */ - public void setTintMode(Mode tintMode) { - if (mShapeState.mTintMode != tintMode) { mShapeState.mTintMode = tintMode; updateTintFilter(); invalidateSelf(); @@ -350,16 +319,6 @@ public class ShapeDrawable extends Drawable { } } - /** - * Returns the blending mode used to apply tint. - * - * @return The Porter-Duff blending mode used to apply tint. - * @hide Pending finalization of supported Modes - */ - public Mode getTintMode() { - return mShapeState.mTintMode; - } - @Override public void setColorFilter(ColorFilter cf) { mShapeState.mPaint.setColorFilter(cf); diff --git a/graphics/java/android/graphics/drawable/StateListDrawable.java b/graphics/java/android/graphics/drawable/StateListDrawable.java index f22a063..b2fac9b 100644 --- a/graphics/java/android/graphics/drawable/StateListDrawable.java +++ b/graphics/java/android/graphics/drawable/StateListDrawable.java @@ -185,7 +185,7 @@ public class StateListDrawable extends DrawableContainer { + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable"); } - dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } mStateListState.addStateSet(states, dr); |