diff --git a/lib/src/android/support/design/chip/Chip.java b/lib/src/android/support/design/chip/Chip.java index 1e0843e1e..efa938a5d 100644 --- a/lib/src/android/support/design/chip/Chip.java +++ b/lib/src/android/support/design/chip/Chip.java @@ -62,8 +62,8 @@ import java.util.List; * or {@link #setOnCheckedChangeListener(OnCheckedChangeListener)}. You can register a listener on * the close icon with {@link #setOnCloseIconClickListener(OnClickListener)}. * - *
Do not use the {@code android:button} attribute. It will be ignored because Chip manages its - * own button Drawable. + *
All attributes from {@link R.styleable#ChipDrawable} are supported. Do not use the {@code
+ * android:button} attribute. It will be ignored because Chip manages its own button Drawable.
*
* @see ChipDrawable
*/
diff --git a/lib/src/android/support/design/chip/ChipDrawable.java b/lib/src/android/support/design/chip/ChipDrawable.java
index 24dc54384..243c216aa 100644
--- a/lib/src/android/support/design/chip/ChipDrawable.java
+++ b/lib/src/android/support/design/chip/ChipDrawable.java
@@ -18,6 +18,8 @@ package android.support.design.chip;
import android.content.Context;
import android.content.res.ColorStateList;
+import android.content.res.Resources;
+import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
@@ -43,6 +45,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;
+import android.support.annotation.XmlRes;
import android.support.design.animation.MotionSpec;
import android.support.design.canvas.CanvasCompat;
import android.support.design.drawable.DrawableUtils;
@@ -52,11 +55,15 @@ import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.graphics.drawable.TintAwareDrawable;
import android.support.v7.content.res.AppCompatResources;
import android.text.TextPaint;
+import android.text.TextUtils;
import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
-import android.util.StateSet;
+import android.util.Xml;
import android.view.View;
+import java.io.IOException;
import java.util.Arrays;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
/**
* ChipDrawable contains all the layout and draw logic for {@link Chip}.
@@ -103,6 +110,7 @@ import java.util.Arrays;
public class ChipDrawable extends Drawable implements TintAwareDrawable, Callback {
private static final boolean DEBUG = false;
+ private static final int[] DEFAULT_STATE = new int[] {android.R.attr.state_enabled};
// Visuals
@Nullable private ColorStateList chipBackgroundColor;
@@ -184,7 +192,7 @@ public class ChipDrawable extends Drawable implements TintAwareDrawable, Callbac
@Nullable private PorterDuffColorFilter tintFilter;
@Nullable private ColorStateList tint;
@Nullable private Mode tintMode = Mode.SRC_IN;
- private int[] closeIconStateSet = StateSet.WILD_CARD;
+ private int[] closeIconStateSet;
/** Returns a ChipDrawable from the given attributes. */
public static ChipDrawable createFromAttributes(
@@ -194,11 +202,54 @@ public class ChipDrawable extends Drawable implements TintAwareDrawable, Callbac
return chip;
}
+ /**
+ * Returns a ChipDrawable from the given XML resource. All attributes from {@link
+ * R.styleable#ChipDrawable} and a custom style attribute are supported. A chip
+ * resource may look like:
+ *
+ *
{@code
+ *
+ * }
+ */
+ public static ChipDrawable createFromResource(Context context, @XmlRes int id) {
+ try {
+ XmlPullParser parser = context.getResources().getXml(id);
+
+ int type;
+ do {
+ type = parser.next();
+ } while (type != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT);
+ if (type != XmlPullParser.START_TAG) {
+ throw new XmlPullParserException("No start tag found");
+ }
+
+ if (!TextUtils.equals(parser.getName(), "chip")) {
+ throw new XmlPullParserException("Must have a