diff options
Diffstat (limited to 'graphics/java/android')
| -rw-r--r-- | graphics/java/android/graphics/drawable/Drawable.java | 67 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/DrawableContainer.java | 26 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/DrawableWrapper.java | 305 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/InsetDrawable.java | 22 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/LayerDrawable.java | 132 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/RippleDrawable.java (renamed from graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java) | 84 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/RotateDrawable.java | 28 |
7 files changed, 148 insertions, 516 deletions
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index b939636..911fb96 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -484,68 +484,40 @@ public abstract class Drawable { } /** - * Indicates whether the drawable supports hotspots. Hotspots are uniquely - * identifiable coordinates the may be added, updated and removed within a - * drawable. - * - * @return true if hotspots are supported - * @see #setHotspot(int, float, float) - * @see #removeHotspot(int) - * @see #clearHotspots() - */ - public boolean supportsHotspots() { - return false; - } - - /** - * Specifies a hotspot's location within the drawable. - * <p> - * The specified key should be an id declared in the resources of the - * application to ensure it is unique (see the <a - * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). + * Specifies the hotspot's location within the drawable. * - * @param key The key identifying the hotspot * @param x The X coordinate of the center of the hotspot * @param y The Y coordinate of the center of the hotspot */ - public void setHotspot(int key, float x, float y) {} - - /** - * Removes the hotspot with the specified key from the drawable. - * - * @param key The key identifying the hotspot - */ - public void removeHotspot(int key) {} + public void setHotspot(float x, float y) {} /** - * Immediately removes all hotspots from the drawable. - */ - public void clearHotspots() {} - - /** - * Sets the bounds to which hotspots are constrained. - * - * @hide until we finalize these APIs + * Sets the bounds to which the hotspot is constrained, if they should be + * different from the drawable bounds. + * + * @param left + * @param top + * @param right + * @param bottom */ public void setHotspotBounds(int left, int top, int right, int bottom) {} /** * Whether this drawable requests projection. * - * @hide until we finalize these APIs + * @hide magic! */ public boolean isProjected() { return false; } /** - * Indicates whether this view will change its appearance based on state. - * Clients can use this to determine whether it is necessary to calculate - * their state and call setState. - * - * @return True if this view changes its appearance based on state, false - * otherwise. + * Indicates whether this drawable will change its appearance based on + * state. Clients can use this to determine whether it is necessary to + * calculate their state and call setState. * + * @return True if this drawable changes its appearance based on state, + * false otherwise. * @see #setState(int[]) */ public boolean isStateful() { @@ -1032,6 +1004,11 @@ public abstract class Drawable { return createFromXmlInnerThemed(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. + */ public static Drawable createFromXmlInnerThemed(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { final Drawable drawable; @@ -1047,8 +1024,8 @@ public abstract class Drawable { drawable = new LayerDrawable(); } else if (name.equals("transition")) { drawable = new TransitionDrawable(); - } else if (name.equals("touch-feedback")) { - drawable = new TouchFeedbackDrawable(); + } else if (name.equals("ripple")) { + drawable = new RippleDrawable(); } else if (name.equals("color")) { drawable = new ColorDrawable(); } else if (name.equals("shape")) { diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index 08fc99d..ec5c6c6 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -238,35 +238,13 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { } @Override - public void setHotspot(int key, float x, float y) { + public void setHotspot(float x, float y) { if (mCurrDrawable != null) { - mCurrDrawable.setHotspot(key, x, y); + mCurrDrawable.setHotspot(x, y); } } @Override - public void removeHotspot(int key) { - if (mCurrDrawable != null) { - mCurrDrawable.removeHotspot(key); - } - } - - @Override - public void clearHotspots() { - if (mCurrDrawable != null) { - mCurrDrawable.clearHotspots(); - } - } - - @Override - public boolean supportsHotspots() { - if (mCurrDrawable != null) { - return mCurrDrawable.supportsHotspots(); - } - return false; - } - - @Override protected boolean onStateChange(int[] state) { if (mLastDrawable != null) { return mLastDrawable.setState(state); diff --git a/graphics/java/android/graphics/drawable/DrawableWrapper.java b/graphics/java/android/graphics/drawable/DrawableWrapper.java deleted file mode 100644 index 6ab33f8..0000000 --- a/graphics/java/android/graphics/drawable/DrawableWrapper.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -package android.graphics.drawable; - -import android.content.res.Resources; -import android.graphics.Canvas; -import android.graphics.ColorFilter; -import android.graphics.Rect; -import android.graphics.Xfermode; - -/** - * A Drawable that wraps another Drawable. - */ -public class DrawableWrapper extends Drawable implements Drawable.Callback { - private WrapperState mWrapperState; - - /** Local drawable backed by its own constant state. */ - private Drawable mWrappedDrawable; - - private boolean mMutated; - - /** @hide */ - @Override - public boolean isProjected() { - return mWrappedDrawable.isProjected(); - } - - @Override - public void setAutoMirrored(boolean mirrored) { - mWrappedDrawable.setAutoMirrored(mirrored); - } - - @Override - public boolean isAutoMirrored() { - return mWrappedDrawable.isAutoMirrored(); - } - - @Override - public int getMinimumWidth() { - return mWrappedDrawable.getMinimumWidth(); - } - - @Override - public int getMinimumHeight() { - return mWrappedDrawable.getMinimumHeight(); - } - - @Override - public int getIntrinsicWidth() { - return mWrappedDrawable.getIntrinsicWidth(); - } - - @Override - public int getIntrinsicHeight() { - return mWrappedDrawable.getIntrinsicHeight(); - } - - @Override - public Drawable getCurrent() { - return mWrappedDrawable.getCurrent(); - } - - @Override - public void invalidateDrawable(Drawable who) { - final Callback callback = getCallback(); - if (callback != null) { - callback.invalidateDrawable(this); - } - } - - @Override - public void scheduleDrawable(Drawable who, Runnable what, long when) { - final Callback callback = getCallback(); - if (callback != null) { - callback.scheduleDrawable(this, what, when); - } - } - - @Override - public void unscheduleDrawable(Drawable who, Runnable what) { - final Callback callback = getCallback(); - if (callback != null) { - callback.unscheduleDrawable(this, what); - } - } - - @Override - public void draw(Canvas canvas) { - mWrappedDrawable.draw(canvas); - } - - @Override - public int getChangingConfigurations() { - return mWrappedDrawable.getChangingConfigurations(); - } - - @Override - public boolean getPadding(Rect padding) { - return mWrappedDrawable.getPadding(padding); - } - - @Override - public Rect getDirtyBounds() { - return mWrappedDrawable.getDirtyBounds(); - } - - @Override - public boolean supportsHotspots() { - return mWrappedDrawable.supportsHotspots(); - } - - @Override - public void setHotspot(int id, float x, float y) { - mWrappedDrawable.setHotspot(id, x, y); - } - - @Override - public void removeHotspot(int id) { - mWrappedDrawable.removeHotspot(id); - } - - @Override - public void clearHotspots() { - mWrappedDrawable.clearHotspots(); - } - - @Override - public boolean setVisible(boolean visible, boolean restart) { - // Must call through to super(). - super.setVisible(visible, restart); - return mWrappedDrawable.setVisible(visible, restart); - } - - @Override - public void setAlpha(int alpha) { - mWrappedDrawable.setAlpha(alpha); - } - - @Override - public int getAlpha() { - return mWrappedDrawable.getAlpha(); - } - - /** {@hide} */ - @Override - public void setLayoutDirection(int layoutDirection) { - mWrappedDrawable.setLayoutDirection(layoutDirection); - } - - /** {@hide} */ - @Override - public int getLayoutDirection() { - return mWrappedDrawable.getLayoutDirection(); - } - - @Override - public void setColorFilter(ColorFilter cf) { - mWrappedDrawable.setColorFilter(cf); - } - - @Override - public ColorFilter getColorFilter() { - return mWrappedDrawable.getColorFilter(); - } - - @Override - public void setFilterBitmap(boolean filter) { - mWrappedDrawable.setFilterBitmap(filter); - } - - @Override - public void setXfermode(Xfermode mode) { - mWrappedDrawable.setXfermode(mode); - } - - @Override - public int getOpacity() { - return mWrappedDrawable.getOpacity(); - } - - @Override - public boolean isStateful() { - return mWrappedDrawable.isStateful(); - } - - @Override - public final boolean setState(int[] stateSet) { - return super.setState(stateSet); - } - - @Override - public final int[] getState() { - return super.getState(); - } - - @Override - protected boolean onStateChange(int[] state) { - // Don't override setState(), getState(). - return mWrappedDrawable.setState(state); - } - - @Override - protected boolean onLevelChange(int level) { - // Don't override setLevel(), getLevel(). - return mWrappedDrawable.setLevel(level); - } - - @Override - public final void setBounds(int left, int top, int right, int bottom) { - super.setBounds(left, top, right, bottom); - } - - @Override - public final void setBounds(Rect bounds) { - super.setBounds(bounds); - } - - @Override - protected void onBoundsChange(Rect bounds) { - // Don't override setBounds(), getBounds(). - mWrappedDrawable.setBounds(bounds); - } - - protected void setConstantState(WrapperState wrapperState, Resources res) { - mWrapperState = wrapperState; - - // Load a new drawable from the constant state. - if (wrapperState == null || wrapperState.mWrappedConstantState == null) { - mWrappedDrawable = null; - } else if (res != null) { - mWrappedDrawable = wrapperState.mWrappedConstantState.newDrawable(res); - } else { - mWrappedDrawable = wrapperState.mWrappedConstantState.newDrawable(); - } - } - - @Override - public ConstantState getConstantState() { - return mWrapperState; - } - - @Override - public Drawable mutate() { - if (!mMutated) { - mWrappedDrawable = mWrappedDrawable.mutate(); - mMutated = true; - } - return this; - } - - /** - * Sets the wrapped drawable and update the constant state. - * - * @param drawable - * @param res - */ - protected final void setDrawable(Drawable drawable, Resources res) { - if (mWrappedDrawable != null) { - mWrappedDrawable.setCallback(null); - } - - mWrappedDrawable = drawable; - - if (drawable != null) { - drawable.setCallback(this); - - mWrapperState.mWrappedConstantState = drawable.getConstantState(); - } else { - mWrapperState.mWrappedConstantState = null; - } - } - - protected final Drawable getDrawable() { - return mWrappedDrawable; - } - - public static abstract class WrapperState extends ConstantState { - ConstantState mWrappedConstantState; - - WrapperState(WrapperState orig) { - if (orig != null) { - mWrappedConstantState = orig.mWrappedConstantState; - } - } - - @Override - public int getChangingConfigurations() { - return mWrappedConstantState.getChangingConfigurations(); - } - } -} diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index 9384caf..3749339 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -131,6 +131,7 @@ public class InsetDrawable extends Drawable implements Drawable.Callback // overrides from Drawable.Callback + @Override public void invalidateDrawable(Drawable who) { final Callback callback = getCallback(); if (callback != null) { @@ -138,6 +139,7 @@ public class InsetDrawable extends Drawable implements Drawable.Callback } } + @Override public void scheduleDrawable(Drawable who, Runnable what, long when) { final Callback callback = getCallback(); if (callback != null) { @@ -145,6 +147,7 @@ public class InsetDrawable extends Drawable implements Drawable.Callback } } + @Override public void unscheduleDrawable(Drawable who, Runnable what) { final Callback callback = getCallback(); if (callback != null) { @@ -184,23 +187,8 @@ public class InsetDrawable extends Drawable implements Drawable.Callback } @Override - public boolean supportsHotspots() { - return mInsetState.mDrawable.supportsHotspots(); - } - - @Override - public void setHotspot(int id, float x, float y) { - mInsetState.mDrawable.setHotspot(id, x, y); - } - - @Override - public void removeHotspot(int id) { - mInsetState.mDrawable.removeHotspot(id); - } - - @Override - public void clearHotspots() { - mInsetState.mDrawable.clearHotspots(); + public void setHotspot(float x, float y) { + mInsetState.mDrawable.setHotspot(x, y); } @Override diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 7847aad..f446000 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -38,10 +38,12 @@ import java.io.IOException; * order, so the element with the largest index will be drawn on top. * <p> * It can be defined in an XML file with the <code><layer-list></code> element. - * Each Drawable in the layer is defined in a nested <code><item></code>. For more - * information, see the guide to <a - * href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.</p> + * Each Drawable in the layer is defined in a nested <code><item></code>. + * <p> + * For more information, see the guide to + * <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>. * + * @attr ref android.R.styleable#LayerDrawable_paddingMode * @attr ref android.R.styleable#LayerDrawableItem_left * @attr ref android.R.styleable#LayerDrawableItem_top * @attr ref android.R.styleable#LayerDrawableItem_right @@ -53,10 +55,16 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { /** * Padding mode used to nest each layer inside the padding of the previous * layer. + * + * @see #setPaddingMode(int) */ public static final int PADDING_MODE_NEST = 0; - /** Padding mode used to stack each layer directly atop the previous layer. */ + /** + * Padding mode used to stack each layer directly atop the previous layer. + * + * @see #setPaddingMode(int) + */ public static final int PADDING_MODE_STACK = 1; LayerState mLayerState; @@ -127,9 +135,8 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { throws XmlPullParserException, IOException { super.inflate(r, parser, attrs, theme); - final TypedArray a = obtainAttributes( - r, theme, attrs, R.styleable.LayerDrawable); - inflateStateFromTypedArray(a); + final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawable); + updateStateFromTypedArray(a); a.recycle(); inflateLayers(r, parser, attrs, theme); @@ -141,25 +148,19 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { /** * Initializes the constant state from the values in the typed array. */ - private void inflateStateFromTypedArray(TypedArray a) { + private void updateStateFromTypedArray(TypedArray a) { final LayerState state = mLayerState; // Extract the theme attributes, if any. final int[] themeAttrs = a.extractThemeAttrs(); state.mThemeAttrs = themeAttrs; - if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawable_opacity] == 0) { - mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN); - } - - if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawable_autoMirrored] == 0) { - state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored, false); - } + mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, mOpacityOverride); - if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawableItem_drawable] == 0) { - state.mPaddingMode = a.getInteger( - R.styleable.LayerDrawableItem_drawable, PADDING_MODE_NEST); - } + state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored, + state.mAutoMirrored); + state.mPaddingMode = a.getInteger(R.styleable.LayerDrawable_paddingMode, + state.mPaddingMode); } /** @@ -181,9 +182,9 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { continue; } - a = obtainAttributes( - r, theme, attrs, R.styleable.LayerDrawableItem); + a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawableItem); + final int[] themeAttrs = a.extractThemeAttrs(); final int left = a.getDimensionPixelOffset( R.styleable.LayerDrawableItem_left, 0); final int top = a.getDimensionPixelOffset( @@ -197,7 +198,6 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { final int id = a.getResourceId( R.styleable.LayerDrawableItem_id, View.NO_ID); - // TODO: Cache typed array, if necessary. a.recycle(); final Drawable dr; @@ -214,7 +214,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme); } - addLayer(dr, id, left, top, right, bottom); + addLayer(dr, themeAttrs, id, left, top, right, bottom); } } @@ -224,7 +224,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { final LayerState state = mLayerState; if (state == null) { - throw new RuntimeException("Can't apply theme to <layer-list> with no constant state"); + return; } final int[] themeAttrs = state.mThemeAttrs; @@ -239,9 +239,10 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { final ChildDrawable[] array = mLayerState.mChildren; final int N = mLayerState.mNum; for (int i = 0; i < N; i++) { - final Drawable layer = array[i].mDrawable; - if (layer.canApplyTheme()) { - layer.applyTheme(t); + final ChildDrawable layer = array[i]; + final Drawable d = layer.mDrawable; + if (d.canApplyTheme()) { + d.applyTheme(t); } } @@ -249,26 +250,6 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { onStateChange(getState()); } - /** - * Updates the constant state from the values in the typed array. - */ - private void updateStateFromTypedArray(TypedArray a) { - final LayerState state = mLayerState; - - if (a.hasValue(R.styleable.LayerDrawable_opacity)) { - mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN); - } - - if (a.hasValue(R.styleable.LayerDrawable_autoMirrored)) { - state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored, false); - } - - if (a.hasValue(R.styleable.LayerDrawableItem_drawable)) { - state.mPaddingMode = a.getInteger( - R.styleable.LayerDrawableItem_drawable, PADDING_MODE_NEST); - } - } - @Override public boolean canApplyTheme() { final LayerState state = mLayerState; @@ -283,14 +264,15 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { final ChildDrawable[] array = state.mChildren; final int N = state.mNum; for (int i = 0; i < N; i++) { - if (array[i].mDrawable.canApplyTheme()) { + final ChildDrawable layer = array[i]; + if (layer.mThemeAttrs != null || layer.mDrawable.canApplyTheme()) { return true; } } return false; } - + /** * @hide */ @@ -315,13 +297,15 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { * Add a new layer to this drawable. The new layer is identified by an id. * * @param layer The drawable to add as a layer. + * @param themeAttrs Theme attributes extracted from the layer. * @param id The id of the new layer. * @param left The left padding of the new layer. * @param top The top padding of the new layer. * @param right The right padding of the new layer. * @param bottom The bottom padding of the new layer. */ - private void addLayer(Drawable layer, int id, int left, int top, int right, int bottom) { + private void addLayer(Drawable layer, int[] themeAttrs, int id, int left, int top, int right, + int bottom) { final LayerState st = mLayerState; final int N = st.mChildren != null ? st.mChildren.length : 0; final int i = st.mNum; @@ -339,6 +323,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { final ChildDrawable childDrawable = new ChildDrawable(); st.mChildren[i] = childDrawable; childDrawable.mId = id; + childDrawable.mThemeAttrs = themeAttrs; childDrawable.mDrawable = layer; childDrawable.mDrawable.setAutoMirrored(isAutoMirrored()); childDrawable.mInsetL = left; @@ -471,8 +456,14 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { * * @param mode padding mode, one of: * <ul> - * <li>{@link #PADDING_MODE_NEST} <li>{@link #PADDING_MODE_STACK} + * <li>{@link #PADDING_MODE_NEST} to nest each layer inside the + * padding of the previous layer + * <li>{@link #PADDING_MODE_STACK} to stack each layer directly + * atop the previous layer * </ul> + * + * @see #getPaddingMode() + * @attr ref android.R.styleable#LayerDrawable_paddingMode */ public void setPaddingMode(int mode) { if (mLayerState.mPaddingMode != mode) { @@ -482,7 +473,9 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { /** * @return the current padding mode + * * @see #setPaddingMode(int) + * @attr ref android.R.styleable#LayerDrawable_paddingMode */ public int getPaddingMode() { return mLayerState.mPaddingMode; @@ -569,42 +562,11 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { } @Override - public boolean supportsHotspots() { - final ChildDrawable[] array = mLayerState.mChildren; - final int N = mLayerState.mNum; - for (int i = 0; i < N; i++) { - if (array[i].mDrawable.supportsHotspots()) { - return true; - } - } - - return false; - } - - @Override - public void setHotspot(int id, float x, float y) { - final ChildDrawable[] array = mLayerState.mChildren; - final int N = mLayerState.mNum; - for (int i = 0; i < N; i++) { - array[i].mDrawable.setHotspot(id, x, y); - } - } - - @Override - public void removeHotspot(int id) { - final ChildDrawable[] array = mLayerState.mChildren; - final int N = mLayerState.mNum; - for (int i = 0; i < N; i++) { - array[i].mDrawable.removeHotspot(id); - } - } - - @Override - public void clearHotspots() { + public void setHotspot(float x, float y) { final ChildDrawable[] array = mLayerState.mChildren; final int N = mLayerState.mNum; for (int i = 0; i < N; i++) { - array[i].mDrawable.clearHotspots(); + array[i].mDrawable.setHotspot(x, y); } } @@ -936,7 +898,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { private boolean mHaveIsStateful; private boolean mIsStateful; - private boolean mAutoMirrored; + private boolean mAutoMirrored = false; private int mPaddingMode = PADDING_MODE_NEST; diff --git a/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index a55a4b2..6776e66 100644 --- a/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -22,6 +22,7 @@ import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.PointF; @@ -44,7 +45,7 @@ import java.io.IOException; /** * Drawable that shows a ripple effect in response to state changes. The * anchoring position of the ripple for a given state may be specified by - * calling {@link #setHotspot(int, float, float)} with the corresponding state + * calling {@link #setHotspot(float, float)} with the corresponding state * attribute identifier. * <p> * A touch feedback drawable may contain multiple child layers, including a @@ -56,19 +57,19 @@ import java.io.IOException; * <p> * If no mask layer is set, the ripple effect is simply blended onto the * composite of the child layers using the specified - * {@link android.R.styleable#TouchFeedbackDrawable_tintMode}. + * {@link android.R.styleable#RippleDrawable_tintMode}. * <p> * If no child layers or mask is specified and the ripple is set as a View * background, the ripple will be blended onto the first available parent * background within the View's hierarchy using the specified - * {@link android.R.styleable#TouchFeedbackDrawable_tintMode}. In this case, the + * {@link android.R.styleable#RippleDrawable_tintMode}. In this case, the * drawing region may extend outside of the Drawable bounds. * * @attr ref android.R.styleable#DrawableStates_state_focused * @attr ref android.R.styleable#DrawableStates_state_pressed */ -public class TouchFeedbackDrawable extends LayerDrawable { - private static final String LOG_TAG = TouchFeedbackDrawable.class.getSimpleName(); +public class RippleDrawable extends LayerDrawable { + private static final String LOG_TAG = RippleDrawable.class.getSimpleName(); private static final PorterDuffXfermode DST_IN = new PorterDuffXfermode(Mode.DST_IN); private static final PorterDuffXfermode DST_ATOP = new PorterDuffXfermode(Mode.DST_ATOP); private static final PorterDuffXfermode SRC_ATOP = new PorterDuffXfermode(Mode.SRC_ATOP); @@ -88,17 +89,17 @@ public class TouchFeedbackDrawable extends LayerDrawable { /** Current dirty bounds, union of current and previous drawing bounds. */ private final Rect mDirtyBounds = new Rect(); - private final TouchFeedbackState mState; + private final RippleState mState; /** * Lazily-created map of pending hotspot locations. These may be modified by - * calls to {@link #setHotspot(int, float, float)}. + * calls to {@link #setHotspot(float, float)}. */ private SparseArray<PointF> mPendingHotspots; /** * Lazily-created map of active hotspot locations. These may be modified by - * calls to {@link #setHotspot(int, float, float)}. + * calls to {@link #setHotspot(float, float)}. */ private SparseArray<Ripple> mActiveHotspots; @@ -121,8 +122,18 @@ public class TouchFeedbackDrawable extends LayerDrawable { /** Whether bounds are being overridden. */ private boolean mOverrideBounds; - TouchFeedbackDrawable() { - this(new TouchFeedbackState(null, null, null), null, null); + RippleDrawable() { + this(new RippleState(null, null, null), null, null); + } + + @Override + public void setAlpha(int alpha) { + + } + + @Override + public void setColorFilter(ColorFilter cf) { + } @Override @@ -233,7 +244,7 @@ public class TouchFeedbackDrawable extends LayerDrawable { public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { final TypedArray a = obtainAttributes( - r, theme, attrs, R.styleable.TouchFeedbackDrawable); + r, theme, attrs, R.styleable.RippleDrawable); updateStateFromTypedArray(a); a.recycle(); @@ -267,22 +278,22 @@ public class TouchFeedbackDrawable extends LayerDrawable { * Initializes the constant state from the values in the typed array. */ private void updateStateFromTypedArray(TypedArray a) { - final TouchFeedbackState state = mState; + final RippleState state = mState; // Extract the theme attributes, if any. state.mTouchThemeAttrs = a.extractThemeAttrs(); - final ColorStateList tint = a.getColorStateList(R.styleable.TouchFeedbackDrawable_tint); + final ColorStateList tint = a.getColorStateList(R.styleable.RippleDrawable_tint); if (tint != null) { mState.mTint = tint; } - final int tintMode = a.getInt(R.styleable.TouchFeedbackDrawable_tintMode, -1); + final int tintMode = a.getInt(R.styleable.RippleDrawable_tintMode, -1); if (tintMode != -1) { mState.setTintMode(Drawable.parseTintMode(tintMode, Mode.SRC_ATOP)); } - mState.mPinned = a.getBoolean(R.styleable.TouchFeedbackDrawable_pinned, mState.mPinned); + mState.mPinned = a.getBoolean(R.styleable.RippleDrawable_pinned, mState.mPinned); } /** @@ -301,13 +312,13 @@ public class TouchFeedbackDrawable extends LayerDrawable { public void applyTheme(Theme t) { super.applyTheme(t); - final TouchFeedbackState state = mState; + final RippleState state = mState; if (state == null || state.mTouchThemeAttrs == null) { return; } final TypedArray a = t.resolveAttributes(state.mTouchThemeAttrs, - R.styleable.TouchFeedbackDrawable); + R.styleable.RippleDrawable); updateStateFromTypedArray(a); a.recycle(); } @@ -318,17 +329,14 @@ public class TouchFeedbackDrawable extends LayerDrawable { } @Override - public boolean supportsHotspots() { - return true; - } - - @Override - public void setHotspot(int id, float x, float y) { + public void setHotspot(float x, float y) { if (mState.mPinned && !circleContains(mHotspotBounds, x, y)) { x = mHotspotBounds.exactCenterX(); y = mHotspotBounds.exactCenterY(); } + // TODO: We should only have a single pending/active hotspot. + final int id = R.attr.state_pressed; final int[] stateSet = getState(); if (!Arrays.contains(stateSet, id)) { // The hotspot is not active, so just modify the pending location. @@ -423,8 +431,7 @@ public class TouchFeedbackDrawable extends LayerDrawable { mActiveHotspots.put(id, newRipple); } - @Override - public void removeHotspot(int id) { + private void removeHotspot(int id) { if (mActiveHotspots == null) { return; } @@ -437,8 +444,7 @@ public class TouchFeedbackDrawable extends LayerDrawable { } } - @Override - public void clearHotspots() { + private void clearHotspots() { if (mActiveHotspots != null) { mActiveHotspots.clear(); } @@ -632,7 +638,7 @@ public class TouchFeedbackDrawable extends LayerDrawable { return mState; } - static class TouchFeedbackState extends LayerState { + static class RippleState extends LayerState { int[] mTouchThemeAttrs; ColorStateList mTint = null; PorterDuffXfermode mTintXfermode = SRC_ATOP; @@ -640,8 +646,8 @@ public class TouchFeedbackDrawable extends LayerDrawable { Drawable mMask; boolean mPinned = false; - public TouchFeedbackState( - TouchFeedbackState orig, TouchFeedbackDrawable owner, Resources res) { + public RippleState( + RippleState orig, RippleDrawable owner, Resources res) { super(orig, owner, res); if (orig != null) { @@ -655,7 +661,7 @@ public class TouchFeedbackDrawable extends LayerDrawable { } public void setTintMode(Mode mode) { - final Mode invertedMode = TouchFeedbackState.invertPorterDuffMode(mode); + final Mode invertedMode = RippleState.invertPorterDuffMode(mode); mTintXfermodeInverse = new PorterDuffXfermode(invertedMode); mTintXfermode = new PorterDuffXfermode(mode); } @@ -675,17 +681,17 @@ public class TouchFeedbackDrawable extends LayerDrawable { @Override public Drawable newDrawable() { - return new TouchFeedbackDrawable(this, null, null); + return new RippleDrawable(this, null, null); } @Override public Drawable newDrawable(Resources res) { - return new TouchFeedbackDrawable(this, res, null); + return new RippleDrawable(this, res, null); } @Override public Drawable newDrawable(Resources res, Theme theme) { - return new TouchFeedbackDrawable(this, res, theme); + return new RippleDrawable(this, res, theme); } /** @@ -716,20 +722,20 @@ public class TouchFeedbackDrawable extends LayerDrawable { } } - private TouchFeedbackDrawable(TouchFeedbackState state, Resources res, Theme theme) { + private RippleDrawable(RippleState state, Resources res, Theme theme) { boolean needsTheme = false; - final TouchFeedbackState ns; + final RippleState ns; if (theme != null && state != null && state.canApplyTheme()) { - ns = new TouchFeedbackState(state, this, res); + ns = new RippleState(state, this, res); needsTheme = true; } else if (state == null) { - ns = new TouchFeedbackState(null, this, res); + ns = new RippleState(null, this, res); } else { // We always need a new state since child drawables contain local // state but live within the parent's constant state. // TODO: Move child drawables into local state. - ns = new TouchFeedbackState(state, this, res); + ns = new RippleState(state, this, res); } if (res != null) { diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java index edf1091..5f9d1cd 100644 --- a/graphics/java/android/graphics/drawable/RotateDrawable.java +++ b/graphics/java/android/graphics/drawable/RotateDrawable.java @@ -145,6 +145,9 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * Sets the start angle for rotation. * * @param fromDegrees Starting angle in degrees + * + * @see #getFromDegrees() + * @attr ref android.R.styleable#RotateDrawable_fromDegrees */ public void setFromDegrees(float fromDegrees) { if (mState.mFromDegrees != fromDegrees) { @@ -155,6 +158,9 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @return The starting angle for rotation in degrees + * + * @see #setFromDegrees(float) + * @attr ref android.R.styleable#RotateDrawable_fromDegrees */ public float getFromDegrees() { return mState.mFromDegrees; @@ -164,6 +170,9 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * Sets the end angle for rotation. * * @param toDegrees Ending angle in degrees + * + * @see #getToDegrees() + * @attr ref android.R.styleable#RotateDrawable_toDegrees */ public void setToDegrees(float toDegrees) { if (mState.mToDegrees != toDegrees) { @@ -174,6 +183,9 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @return The ending angle for rotation in degrees + * + * @see #setToDegrees(float) + * @attr ref android.R.styleable#RotateDrawable_toDegrees */ public float getToDegrees() { return mState.mToDegrees; @@ -186,7 +198,9 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * relative, the position represents a fraction of the drawable * width. Otherwise, the position represents an absolute value in * pixels. + * * @see #setPivotXRelative(boolean) + * @attr ref android.R.styleable#RotateDrawable_pivotX */ public void setPivotX(float pivotX) { if (mState.mPivotX == pivotX) { @@ -197,7 +211,9 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @return X position around which to rotate + * * @see #setPivotX(float) + * @attr ref android.R.styleable#RotateDrawable_pivotX */ public float getPivotX() { return mState.mPivotX; @@ -209,6 +225,8 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * * @param relative True if the X pivot represents a fraction of the drawable * width, or false if it represents an absolute value in pixels + * + * @see #isPivotXRelative() */ public void setPivotXRelative(boolean relative) { if (mState.mPivotXRel == relative) { @@ -220,6 +238,7 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @return True if the X pivot represents a fraction of the drawable width, * or false if it represents an absolute value in pixels + * * @see #setPivotXRelative(boolean) */ public boolean isPivotXRelative() { @@ -233,7 +252,9 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * relative, the position represents a fraction of the drawable * height. Otherwise, the position represents an absolute value * in pixels. - * @see #setPivotYRelative(boolean) + * + * @see #getPivotY() + * @attr ref android.R.styleable#RotateDrawable_pivotY */ public void setPivotY(float pivotY) { if (mState.mPivotY == pivotY) { @@ -244,7 +265,9 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @return Y position around which to rotate + * * @see #setPivotY(float) + * @attr ref android.R.styleable#RotateDrawable_pivotY */ public float getPivotY() { return mState.mPivotY; @@ -256,6 +279,8 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * * @param relative True if the Y pivot represents a fraction of the drawable * height, or false if it represents an absolute value in pixels + * + * @see #isPivotYRelative() */ public void setPivotYRelative(boolean relative) { if (mState.mPivotYRel == relative) { @@ -267,6 +292,7 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @return True if the Y pivot represents a fraction of the drawable height, * or false if it represents an absolute value in pixels + * * @see #setPivotYRelative(boolean) */ public boolean isPivotYRelative() { |
