Merge "Clean up drawable theming APIs" into lmp-preview-dev

This commit is contained in:
Alan Viverette
2014-06-02 23:41:59 +00:00
committed by Android (Google) Code Review
17 changed files with 49 additions and 97 deletions

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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(

View File

@@ -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();

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);