diff --git a/lib/res/animator/mtrl_chip_state_list_anim.xml b/lib/res/animator/mtrl_chip_state_list_anim.xml
new file mode 100644
index 000000000..dcdb4d189
--- /dev/null
+++ b/lib/res/animator/mtrl_chip_state_list_anim.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
diff --git a/lib/res/color/mtrl_chip_background_color.xml b/lib/res/color/mtrl_chip_background_color.xml
new file mode 100644
index 000000000..174e9f5ee
--- /dev/null
+++ b/lib/res/color/mtrl_chip_background_color.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/res/color/mtrl_chip_ripple_alpha.xml b/lib/res/color/mtrl_chip_ripple_alpha.xml
new file mode 100644
index 000000000..153da0f06
--- /dev/null
+++ b/lib/res/color/mtrl_chip_ripple_alpha.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/res/drawable/ic_mtrl_chip_checked_circle.xml b/lib/res/drawable/ic_mtrl_chip_checked_circle.xml
new file mode 100644
index 000000000..ce1d31dc8
--- /dev/null
+++ b/lib/res/drawable/ic_mtrl_chip_checked_circle.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
diff --git a/lib/res/drawable/ic_mtrl_chip_close_circle.xml b/lib/res/drawable/ic_mtrl_chip_close_circle.xml
new file mode 100644
index 000000000..e7e325592
--- /dev/null
+++ b/lib/res/drawable/ic_mtrl_chip_close_circle.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
diff --git a/lib/res/values/colors.xml b/lib/res/values/colors.xml
index 7a76aedf9..0567e5d61 100644
--- a/lib/res/values/colors.xml
+++ b/lib/res/values/colors.xml
@@ -61,6 +61,9 @@
#00ffffff
+ #191919
+ #DE000000
+
#52000000
diff --git a/lib/res/values/dimens.xml b/lib/res/values/dimens.xml
index b9e48709e..a7d01c337 100644
--- a/lib/res/values/dimens.xml
+++ b/lib/res/values/dimens.xml
@@ -94,4 +94,7 @@
2dp
6dp
+ 3dp
+ 14sp
+
diff --git a/lib/res/values/integers.xml b/lib/res/values/integers.xml
index e0496b9e2..1007dc0fc 100644
--- a/lib/res/values/integers.xml
+++ b/lib/res/values/integers.xml
@@ -17,4 +17,5 @@
150
150
+ 100
diff --git a/lib/res/values/styles.xml b/lib/res/values/styles.xml
index b7322d11b..6e26696f8 100644
--- a/lib/res/values/styles.xml
+++ b/lib/res/values/styles.xml
@@ -220,25 +220,27 @@
- true
- true
- false
+ - @animator/mtrl_chip_state_list_anim
+
+ - @null
+ - @drawable/ic_mtrl_chip_checked_circle
+ - @drawable/ic_mtrl_chip_close_circle
+
+ - @null
+ - @style/TextAppearance.MaterialComponents.Chip
+ - @null
+
+ - @color/mtrl_chip_background_color
+ - #00000000
+ - 0dp
+ - @color/mtrl_chip_ripple_color
+ - @color/mtrl_chip_ripple_alpha
-
- - #00ff00
- 32dp
- 16dp
- - #0000ff
- - 1dp
- - #ffffff
- - #aa000000
- - Hello, world!
- - @style/TextAppearance.Design.Error
- - @drawable/abc_ic_ab_back_material
- 24dp
- - @drawable/abc_ic_go_search_api_material
- - #ff000000
- 18dp
- - @drawable/abc_ic_arrow_drop_right_black_24dp
- - @animator/design_fab_show_motion_spec
- - @animator/design_fab_hide_motion_spec
+
- 4dp
- 0dp
- 0dp
@@ -247,6 +249,11 @@
- 2dp
- 2dp
- 6dp
+
+
+ - @animator/design_fab_show_motion_spec
+ - @animator/design_fab_hide_motion_spec
+
+
+
diff --git a/lib/src/android/support/design/chip/Chip.java b/lib/src/android/support/design/chip/Chip.java
index db34c8a85..ca793f8e8 100644
--- a/lib/src/android/support/design/chip/Chip.java
+++ b/lib/src/android/support/design/chip/Chip.java
@@ -69,13 +69,26 @@ import java.util.List;
* accessibility navigation. The main chip and close icon are considered to be separate logical
* sub-views, and contain their own navigation behavior and state.
*
+ *
All attributes from {@link R.styleable#ChipDrawable} are supported. Do not use the {@code
+ * android:button} and {@code android:text} attributes. They will be ignored because Chip manages
+ * its own button Drawable and text. The basic attributes you can set are:
+ *
+ *
+ * - {@link android.R.attr#checkable android:checkable} - If true, the chip can be toggled. If
+ * false, the chip acts like a button.
+ *
- {@link R.attr#chipText app:chipText} - Sets the text of the chip.
+ *
- {@link R.attr#chipIcon app:chipIcon} - Sets the icon of the chip, or use @null to display
+ * no icon. Usually on the left.
+ *
- {@link R.attr#checkedIcon app:checkedIcon} - Sets a custom icon to use when checked, or
+ * use @null to display no icon. Usually on the left.
+ *
- {@link R.attr#closeIcon app:closeIcon} - Sets a custom icon that the user can click to
+ * close, or use @null to display no icon. Usually on the right.
+ *
+ *
* You can register a listener on the main chip with {@link #setOnClickListener(OnClickListener)}
* or {@link #setOnCheckedChangeListener(OnCheckedChangeListener)}. You can register a listener on
* the close icon with {@link #setOnCloseIconClickListener(OnClickListener)}.
*
- *
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
*/
public class Chip extends AppCompatCheckBox implements Delegate {
diff --git a/lib/src/android/support/design/chip/ChipDrawable.java b/lib/src/android/support/design/chip/ChipDrawable.java
index ee968757f..29150e884 100644
--- a/lib/src/android/support/design/chip/ChipDrawable.java
+++ b/lib/src/android/support/design/chip/ChipDrawable.java
@@ -22,6 +22,7 @@ import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Outline;
import android.graphics.Paint;
@@ -54,6 +55,7 @@ import android.support.design.drawable.DrawableUtils;
import android.support.design.resources.MaterialResources;
import android.support.design.ripple.RippleUtils;
import android.support.v4.content.ContextCompat;
+import android.support.v4.graphics.ColorUtils;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.graphics.drawable.TintAwareDrawable;
import android.support.v4.text.BidiFormatter;
@@ -75,8 +77,30 @@ import org.xmlpull.v1.XmlPullParserException;
*
*
You can use ChipDrawable directly in contexts that require a Drawable. For example, an
* auto-complete enabled EditText can replace snippets of text with a ChipDrawable to represent it
- * as a semantic entity. When used in this stand-alone mode, the host view must explicitly manage
- * the ChipDrawable's state:
+ * as a semantic entity. To create an instance of ChipDrawable, use {@link
+ * ChipDrawable#createFromResource(Context, int)} and pass in an XML resource in this form:
+ *
+ *
{@code
+ *
+ * }
+ *
+ * The basic attributes you can set are:
+ *
+ *
+ * - {@link android.R.attr#checkable android:checkable} - If true, the chip can be toggled. If
+ * false, the chip acts like a button.
+ *
- {@link R.attr#chipText app:chipText} - Sets the text of the chip.
+ *
- {@link R.attr#chipIcon app:chipIcon} - Sets the icon of the chip, or use @null to display
+ * no icon. Usually on the left.
+ *
- {@link R.attr#checkedIcon app:checkedIcon} - Sets a custom icon to use when checked, or
+ * use @null to display no icon. Usually on the left.
+ *
- {@link R.attr#closeIcon app:closeIcon} - Sets a custom icon that the user can click to
+ * close, or use @null to display no icon. Usually on the right.
+ *
+ *
+ * When used in this stand-alone mode, the host view must explicitly manage the ChipDrawable's
+ * state:
*
*
* - {@link ChipDrawable#setBounds(int, int, int, int)}, taking into account {@link
@@ -275,6 +299,9 @@ public class ChipDrawable extends Drawable implements TintAwareDrawable, Callbac
textPaint.density = context.getResources().getDisplayMetrics().density;
debugPaint = DEBUG ? new Paint(Paint.ANTI_ALIAS_FLAG) : null;
+ if (debugPaint != null) {
+ debugPaint.setStyle(Style.STROKE);
+ }
setState(DEFAULT_STATE);
setCloseIconState(DEFAULT_STATE);
@@ -595,9 +622,39 @@ public class ChipDrawable extends Drawable implements TintAwareDrawable, Callbac
}
private void drawDebug(@NonNull Canvas canvas, Rect bounds) {
- if (DEBUG) {
- canvas.drawLine(
- bounds.left, bounds.exactCenterY(), bounds.right, bounds.exactCenterY(), debugPaint);
+ if (debugPaint != null) {
+ debugPaint.setColor(ColorUtils.setAlphaComponent(Color.BLACK, 255 / 2));
+
+ // Background.
+ canvas.drawRect(bounds, debugPaint);
+
+ // Chip and checked icon.
+ if (chipIcon != null || (checkedIcon != null && currentChecked)) {
+ calculateChipIconBounds(bounds, rectF);
+ canvas.drawRect(rectF, debugPaint);
+ }
+
+ // Chip text.
+ if (chipText != null) {
+ canvas.drawLine(
+ bounds.left, bounds.exactCenterY(), bounds.right, bounds.exactCenterY(), debugPaint);
+ }
+
+ // Close icon.
+ if (closeIcon != null) {
+ calculateCloseIconBounds(bounds, rectF);
+ canvas.drawRect(rectF, debugPaint);
+ }
+
+ // Chip touch bounds.
+ debugPaint.setColor(ColorUtils.setAlphaComponent(Color.RED, 255 / 2));
+ calculateChipTouchBounds(bounds, rectF);
+ canvas.drawRect(rectF, debugPaint);
+
+ // Close icon touch bounds.
+ debugPaint.setColor(ColorUtils.setAlphaComponent(Color.GREEN, 255 / 2));
+ calculateCloseIconTouchBounds(bounds, rectF);
+ canvas.drawRect(rectF, debugPaint);
}
}