diff options
author | Alan Viverette <alanv@google.com> | 2015-02-13 11:11:12 -0800 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2015-02-13 11:11:12 -0800 |
commit | 88d44d4adaa68db02e4eef68606591028a92add0 (patch) | |
tree | 45493ac1bf605678166a6faa839ae940d66c1c7f | |
parent | bc26d2eafd6185a197a968b2dffde5871791cf0b (diff) | |
download | frameworks_base-88d44d4adaa68db02e4eef68606591028a92add0.zip frameworks_base-88d44d4adaa68db02e4eef68606591028a92add0.tar.gz frameworks_base-88d44d4adaa68db02e4eef68606591028a92add0.tar.bz2 |
Add attribute for controlling ripple radius
Sets up the action bar item and control styles to use a 20dp radius
ripple to match latest Material spec.
Bug: 19370157
Change-Id: I87cba01076ee83937a6bfd36fc7dc188e1eb4672
-rw-r--r-- | api/current.txt | 3 | ||||
-rw-r--r-- | api/system-current.txt | 3 | ||||
-rw-r--r-- | core/res/res/drawable/action_bar_item_background_material.xml | 19 | ||||
-rw-r--r-- | core/res/res/drawable/control_background_material.xml | 3 | ||||
-rw-r--r-- | core/res/res/values/attrs.xml | 3 | ||||
-rw-r--r-- | core/res/res/values/themes_material.xml | 4 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/Ripple.java | 7 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/RippleBackground.java | 7 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/RippleDrawable.java | 71 |
9 files changed, 71 insertions, 49 deletions
diff --git a/api/current.txt b/api/current.txt index d1b6ba0..e2bd0da 100644 --- a/api/current.txt +++ b/api/current.txt @@ -12069,7 +12069,10 @@ package android.graphics.drawable { public class RippleDrawable extends android.graphics.drawable.LayerDrawable { ctor public RippleDrawable(android.content.res.ColorStateList, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable); + method public int getRadius(); method public void setColor(android.content.res.ColorStateList); + method public void setRadius(int); + field public static final int RADIUS_AUTO = -1; // 0xffffffff } public class RotateDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Drawable.Callback { diff --git a/api/system-current.txt b/api/system-current.txt index fd6e2c8..b333f95 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -12343,7 +12343,10 @@ package android.graphics.drawable { public class RippleDrawable extends android.graphics.drawable.LayerDrawable { ctor public RippleDrawable(android.content.res.ColorStateList, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable); + method public int getRadius(); method public void setColor(android.content.res.ColorStateList); + method public void setRadius(int); + field public static final int RADIUS_AUTO = -1; // 0xffffffff } public class RotateDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Drawable.Callback { diff --git a/core/res/res/drawable/action_bar_item_background_material.xml b/core/res/res/drawable/action_bar_item_background_material.xml new file mode 100644 index 0000000..8228e3f --- /dev/null +++ b/core/res/res/drawable/action_bar_item_background_material.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2015 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="?attr/colorControlHighlight" + android:radius="20dp" /> diff --git a/core/res/res/drawable/control_background_material.xml b/core/res/res/drawable/control_background_material.xml index ae3181a..7b78349 100644 --- a/core/res/res/drawable/control_background_material.xml +++ b/core/res/res/drawable/control_background_material.xml @@ -15,4 +15,5 @@ --> <ripple xmlns:android="http://schemas.android.com/apk/res/android" - android:color="@color/control_highlight_material" /> + android:color="@color/control_highlight_material" + android:radius="20dp" /> diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index b90ac65..bc20378 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -5291,6 +5291,9 @@ <declare-styleable name="RippleDrawable"> <!-- The color to use for ripple effects. This attribute is required. --> <attr name="color" /> + <!-- The radius of the ripple when fully expanded. By default, the + radius is computed based on the size of the ripple's container. --> + <attr name="radius" /> </declare-styleable> <declare-styleable name="ScaleDrawable"> diff --git a/core/res/res/values/themes_material.xml b/core/res/res/values/themes_material.xml index 57041fd..f9c4da7 100644 --- a/core/res/res/values/themes_material.xml +++ b/core/res/res/values/themes_material.xml @@ -327,7 +327,7 @@ please see themes_device_defaults.xml. <item name="actionBarWidgetTheme">@null</item> <item name="actionBarPopupTheme">?attr/popupTheme</item> <item name="actionBarTheme">@style/ThemeOverlay.Material.ActionBar</item> - <item name="actionBarItemBackground">?attr/selectableItemBackgroundBorderless</item> + <item name="actionBarItemBackground">@drawable/action_bar_item_background_material</item> <item name="actionModeCutDrawable">@drawable/ic_menu_cut_material</item> <item name="actionModeCopyDrawable">@drawable/ic_menu_copy_material</item> @@ -681,7 +681,7 @@ please see themes_device_defaults.xml. <item name="actionModePopupWindowStyle">@style/Widget.Material.Light.PopupWindow.ActionMode</item> <item name="actionBarWidgetTheme">@null</item> <item name="actionBarTheme">@style/ThemeOverlay.Material.ActionBar</item> - <item name="actionBarItemBackground">?attr/selectableItemBackgroundBorderless</item> + <item name="actionBarItemBackground">@drawable/action_bar_item_background_material</item> <item name="actionModeCutDrawable">@drawable/ic_menu_cut_material</item> <item name="actionModeCopyDrawable">@drawable/ic_menu_copy_material</item> diff --git a/graphics/java/android/graphics/drawable/Ripple.java b/graphics/java/android/graphics/drawable/Ripple.java index bb1d3cb..138d73a 100644 --- a/graphics/java/android/graphics/drawable/Ripple.java +++ b/graphics/java/android/graphics/drawable/Ripple.java @@ -46,8 +46,7 @@ class Ripple { private static final long RIPPLE_ENTER_DELAY = 80; // Hardware animators. - private final ArrayList<RenderNodeAnimator> mRunningAnimations = - new ArrayList<RenderNodeAnimator>(); + private final ArrayList<RenderNodeAnimator> mRunningAnimations = new ArrayList<>(); private final RippleDrawable mOwner; @@ -117,8 +116,8 @@ class Ripple { mStartingY = startingY; } - public void setup(int maxRadius, float density) { - if (maxRadius != RippleDrawable.RADIUS_AUTO) { + public void setup(float maxRadius, float density) { + if (maxRadius >= 0) { mHasMaxRadius = true; mOuterRadius = maxRadius; } else { diff --git a/graphics/java/android/graphics/drawable/RippleBackground.java b/graphics/java/android/graphics/drawable/RippleBackground.java index fae4902..ef35289 100644 --- a/graphics/java/android/graphics/drawable/RippleBackground.java +++ b/graphics/java/android/graphics/drawable/RippleBackground.java @@ -49,8 +49,7 @@ class RippleBackground { private static final int ENTER_DURATION_FAST = 100; // Hardware animators. - private final ArrayList<RenderNodeAnimator> mRunningAnimations = - new ArrayList<RenderNodeAnimator>(); + private final ArrayList<RenderNodeAnimator> mRunningAnimations = new ArrayList<>(); private final RippleDrawable mOwner; @@ -105,8 +104,8 @@ class RippleBackground { mBounds = bounds; } - public void setup(int maxRadius, float density) { - if (maxRadius != RippleDrawable.RADIUS_AUTO) { + public void setup(float maxRadius, float density) { + if (maxRadius >= 0) { mHasMaxRadius = true; mOuterRadius = maxRadius; } else { diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index ca9f714..556c59f 100644 --- a/graphics/java/android/graphics/drawable/RippleDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -92,19 +92,17 @@ import java.util.Arrays; * @attr ref android.R.styleable#RippleDrawable_color */ public class RippleDrawable extends LayerDrawable { + /** + * Radius value that specifies the ripple radius should be computed based + * on the size of the ripple's container. + */ + public static final int RADIUS_AUTO = -1; + private static final int MASK_UNKNOWN = -1; private static final int MASK_NONE = 0; private static final int MASK_CONTENT = 1; private static final int MASK_EXPLICIT = 2; - /** - * Constant for automatically determining the maximum ripple radius. - * - * @see #setMaxRadius(int) - * @hide - */ - public static final int RADIUS_AUTO = -1; - /** The maximum number of ripples supported. */ private static final int MAX_RIPPLES = 10; @@ -356,12 +354,36 @@ public class RippleDrawable extends LayerDrawable { * Sets the ripple color. * * @param color Ripple color as a color state list. + * + * @attr ref android.R.styleable#RippleDrawable_color */ public void setColor(ColorStateList color) { mState.mColor = color; invalidateSelf(); } + /** + * Sets the radius in pixels of the fully expanded ripple. + * + * @param radius ripple radius in pixels, or {@link #RADIUS_AUTO} to + * compute the radius based on the container size + * @attr ref android.R.styleable#RippleDrawable_radius + */ + public void setRadius(int radius) { + mState.mMaxRadius = radius; + invalidateSelf(); + } + + /** + * @return the radius in pixels of the fully expanded ripple if an explicit + * radius has been set, or {@link #RADIUS_AUTO} if the radius is + * computed based on the container size + * @attr ref android.R.styleable#RippleDrawable_radius + */ + public int getRadius() { + return mState.mMaxRadius; + } + @Override public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { @@ -428,6 +450,9 @@ public class RippleDrawable extends LayerDrawable { mState.mColor = color; } + mState.mMaxRadius = a.getDimensionPixelSize( + R.styleable.RippleDrawable_radius, mState.mMaxRadius); + verifyRequiredAttributes(a); } @@ -959,36 +984,6 @@ public class RippleDrawable extends LayerDrawable { } } - /** - * Sets the maximum ripple radius in pixels. The default value of - * {@link #RADIUS_AUTO} defines the radius as the distance from the center - * of the drawable bounds (or hotspot bounds, if specified) to a corner. - * - * @param maxRadius the maximum ripple radius in pixels or - * {@link #RADIUS_AUTO} to automatically determine the maximum - * radius based on the bounds - * @see #getMaxRadius() - * @see #setHotspotBounds(int, int, int, int) - * @hide - */ - public void setMaxRadius(int maxRadius) { - if (maxRadius != RADIUS_AUTO && maxRadius < 0) { - throw new IllegalArgumentException("maxRadius must be RADIUS_AUTO or >= 0"); - } - - mState.mMaxRadius = maxRadius; - } - - /** - * @return the maximum ripple radius in pixels, or {@link #RADIUS_AUTO} if - * the radius is determined automatically - * @see #setMaxRadius(int) - * @hide - */ - public int getMaxRadius() { - return mState.mMaxRadius; - } - private RippleDrawable(RippleState state, Resources res) { mState = new RippleState(state, this, res); mLayerState = mState; |