diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:43 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:43 -0800 |
commit | f013e1afd1e68af5e3b868c26a653bbfb39538f8 (patch) | |
tree | 7ad6c8fd9c7b55f4b4017171dec1cb760bbd26bf /graphics | |
parent | e70cfafe580c6f2994c4827cd8a534aabf3eb05c (diff) | |
download | frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.zip frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.gz frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'graphics')
8 files changed, 203 insertions, 88 deletions
diff --git a/graphics/java/android/graphics/Rect.java b/graphics/java/android/graphics/Rect.java index d8d7136..2005344 100644 --- a/graphics/java/android/graphics/Rect.java +++ b/graphics/java/android/graphics/Rect.java @@ -78,10 +78,17 @@ public final class Rect implements Parcelable { } public String toString() { - return "Rect(" + left + ", " + top + ", " + right + ", " + bottom + ")"; + return "Rect(" + left + ", " + top + " - " + right + ", " + bottom + ")"; } /** + * Return a string representation of the rectangle in a compact form. + */ + public String toShortString() { + return "[" + left + "," + top + "][" + right + "," + bottom + "]"; + } + + /** * Returns true if the rectangle is empty (left >= right or top >= bottom) */ public final boolean isEmpty() { diff --git a/graphics/java/android/graphics/RectF.aidl b/graphics/java/android/graphics/RectF.aidl new file mode 100644 index 0000000..0254f6d --- /dev/null +++ b/graphics/java/android/graphics/RectF.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2008 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; + +parcelable RectF; diff --git a/graphics/java/android/graphics/RectF.java b/graphics/java/android/graphics/RectF.java index d71f2dc..2b3aa33 100644 --- a/graphics/java/android/graphics/RectF.java +++ b/graphics/java/android/graphics/RectF.java @@ -16,6 +16,8 @@ package android.graphics; +import android.os.Parcel; +import android.os.Parcelable; import android.util.FloatMath; import com.android.internal.util.FastMath; @@ -26,7 +28,7 @@ import com.android.internal.util.FastMath; * the rectangle's width and height. Note: most methods do not check to see that * the coordinates are sorted correctly (i.e. left <= right and top <= bottom). */ -public class RectF { +public class RectF implements Parcelable { public float left; public float top; public float right; @@ -475,4 +477,54 @@ public class RectF { bottom = temp; } } + + /** + * Parcelable interface methods + */ + public int describeContents() { + return 0; + } + + /** + * Write this rectangle to the specified parcel. To restore a rectangle from + * a parcel, use readFromParcel() + * @param out The parcel to write the rectangle's coordinates into + */ + public void writeToParcel(Parcel out, int flags) { + out.writeFloat(left); + out.writeFloat(top); + out.writeFloat(right); + out.writeFloat(bottom); + } + + public static final Parcelable.Creator<RectF> CREATOR = new Parcelable.Creator<RectF>() { + /** + * Return a new rectangle from the data in the specified parcel. + */ + public RectF createFromParcel(Parcel in) { + RectF r = new RectF(); + r.readFromParcel(in); + return r; + } + + /** + * Return an array of rectangles of the specified size. + */ + public RectF[] newArray(int size) { + return new RectF[size]; + } + }; + + /** + * Set the rectangle's coordinates from the data stored in the specified + * parcel. To write a rectangle to a parcel, call writeToParcel(). + * + * @param in The parcel to read the rectangle's coordinates from + */ + public void readFromParcel(Parcel in) { + left = in.readFloat(); + top = in.readFloat(); + right = in.readFloat(); + bottom = in.readFloat(); + } } diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index 26e50cd..cd78043 100644 --- a/graphics/java/android/graphics/drawable/AnimationDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java @@ -23,7 +23,6 @@ import org.xmlpull.v1.XmlPullParserException; import android.content.res.Resources; import android.content.res.TypedArray; -import android.graphics.Canvas; import android.os.SystemClock; import android.util.AttributeSet; @@ -65,6 +64,9 @@ import android.util.AttributeSet; * </pre> */ public class AnimationDrawable extends DrawableContainer implements Runnable { + private final AnimationState mAnimationState; + private int mCurFrame = -1; + public AnimationDrawable() { this(null); } @@ -187,7 +189,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable { if (next >= N) { next = 0; } - setFrame(next, unschedule, !mAnimationState.mOneShot || next < (N-1)); + setFrame(next, unschedule, !mAnimationState.mOneShot || next < (N - 1)); } private void setFrame(int frame, boolean unschedule, boolean animate) { @@ -200,14 +202,12 @@ public class AnimationDrawable extends DrawableContainer implements Runnable { unscheduleSelf(this); } if (animate) { - scheduleSelf(this, SystemClock.uptimeMillis() - + mAnimationState.mDurations[frame]); + scheduleSelf(this, SystemClock.uptimeMillis() + mAnimationState.mDurations[frame]); } } @Override - public void inflate(Resources r, XmlPullParser parser, - AttributeSet attrs) + public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { TypedArray a = r.obtainAttributes(attrs, @@ -228,9 +228,8 @@ public class AnimationDrawable extends DrawableContainer implements Runnable { final int innerDepth = parser.getDepth()+1; int depth; - while ((type=parser.next()) != XmlPullParser.END_DOCUMENT - && ((depth=parser.getDepth()) >= innerDepth - || type != XmlPullParser.END_TAG)) { + while ((type=parser.next()) != XmlPullParser.END_DOCUMENT && + ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG) { continue; } @@ -239,9 +238,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable { continue; } - a = r.obtainAttributes(attrs, - com.android.internal.R.styleable.AnimationDrawableItem); - + a = r.obtainAttributes(attrs, com.android.internal.R.styleable.AnimationDrawableItem); int duration = a.getInt( com.android.internal.R.styleable.AnimationDrawableItem_duration, -1); if (duration < 0) { @@ -259,12 +256,12 @@ public class AnimationDrawable extends DrawableContainer implements Runnable { dr = r.getDrawable(drawableRes); } else { while ((type=parser.next()) == XmlPullParser.TEXT) { + // Empty } if (type != XmlPullParser.START_TAG) { - throw new XmlPullParserException( - parser.getPositionDescription() - + ": <item> tag requires a 'drawable' attribute or " - + "child tag defining a drawable"); + throw new XmlPullParserException(parser.getPositionDescription() + + ": <item> tag requires a 'drawable' attribute or child tag" + + " defining a drawable"); } dr = Drawable.createFromXmlInner(r, parser, attrs); } @@ -278,10 +275,11 @@ public class AnimationDrawable extends DrawableContainer implements Runnable { setFrame(0, true, false); } - private final static class AnimationState extends DrawableContainerState - { - AnimationState(AnimationState orig, AnimationDrawable owner) - { + private final static class AnimationState extends DrawableContainerState { + private int[] mDurations; + private boolean mOneShot; + + AnimationState(AnimationState orig, AnimationDrawable owner) { super(orig, owner); if (orig != null) { @@ -294,28 +292,24 @@ public class AnimationDrawable extends DrawableContainer implements Runnable { } @Override - public Drawable newDrawable() - { + public Drawable newDrawable() { return new AnimationDrawable(this); } - public void addFrame(Drawable dr, int dur) - { + public void addFrame(Drawable dr, int dur) { + // Do not combine the following. The array index must be evaluated before + // the array is accessed because super.addChild(dr) has a side effect on mDurations. int pos = super.addChild(dr); mDurations[pos] = dur; } @Override - public void growArray(int oldSize, int newSize) - { + public void growArray(int oldSize, int newSize) { super.growArray(oldSize, newSize); int[] newDurations = new int[newSize]; System.arraycopy(mDurations, 0, newDurations, 0, oldSize); mDurations = newDurations; } - - private int[] mDurations; - private boolean mOneShot; } private AnimationDrawable(AnimationState state) { @@ -326,9 +320,5 @@ public class AnimationDrawable extends DrawableContainer implements Runnable { setFrame(0, true, false); } } - - private final AnimationState mAnimationState; - - private int mCurFrame = -1; } diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 97b44ba..a838c5f 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -20,7 +20,6 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.BlurMaskFilter; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Paint; diff --git a/graphics/java/android/graphics/drawable/ColorDrawable.java b/graphics/java/android/graphics/drawable/ColorDrawable.java index 4f4eda6..bebb461 100644 --- a/graphics/java/android/graphics/drawable/ColorDrawable.java +++ b/graphics/java/android/graphics/drawable/ColorDrawable.java @@ -57,8 +57,7 @@ public class ColorDrawable extends Drawable { @Override public int getChangingConfigurations() { - return super.getChangingConfigurations() - | mState.mChangingConfigurations; + return super.getChangingConfigurations() | mState.mChangingConfigurations; } @Override diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 6e9d9ba..c389eb3 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -31,39 +31,53 @@ import java.io.IOException; order, so the element with the largest index will be drawn on top. */ public class LayerDrawable extends Drawable implements Drawable.Callback { - - /* package */ LayerState mLayerState; + LayerState mLayerState; + + private int[] mPaddingL; + private int[] mPaddingT; + private int[] mPaddingR; + private int[] mPaddingB; - private int[] mPaddingL; - private int[] mPaddingT; - private int[] mPaddingR; - private int[] mPaddingB; + private final Rect mTmpRect = new Rect(); - private final Rect mTmpRect = new Rect(); + /** + * Create a new layer drawable with the list of specified layers. + * + * @param layers A list of drawables to use as layers in this new drawable. + */ + public LayerDrawable(Drawable[] layers) { + this(layers, null); + } - public LayerDrawable(Drawable[] array) { - this((LayerState)null); - int length = array.length; + /** + * Create a new layer drawable with the specified list of layers and the specified + * constant state. + * + * @param layers The list of layers to add to this drawable. + * @param state The constant drawable state. + */ + LayerDrawable(Drawable[] layers, LayerState state) { + this(state); + int length = layers.length; Rec[] r = new Rec[length]; for (int i = 0; i < length; i++) { r[i] = new Rec(); - r[i].mDrawable = array[i]; - array[i].setCallback(this); - mLayerState.mChildrenChangingConfigurations - |= array[i].getChangingConfigurations(); + r[i].mDrawable = layers[i]; + layers[i].setCallback(this); + mLayerState.mChildrenChangingConfigurations |= layers[i].getChangingConfigurations(); } mLayerState.mNum = length; mLayerState.mArray = r; + ensurePadding(); } - /* package */ LayerDrawable() { + LayerDrawable() { this((LayerState) null); } - - /* package */ LayerDrawable(LayerState state) { + LayerDrawable(LayerState state) { LayerState as = createConstantState(state); mLayerState = as; if (as.mNum > 0) { @@ -71,10 +85,9 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { } } - /* package */ LayerState createConstantState(LayerState state) { + LayerState createConstantState(LayerState state) { return new LayerState(state, this); } - @Override public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) @@ -127,14 +140,24 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { dr = Drawable.createFromXmlInner(r, parser, attrs); } - addLayer(id, dr, left, top, right, bottom); + addLayer(dr, id, left, top, right, bottom); } ensurePadding(); onStateChange(getState()); } - private void addLayer(int id, Drawable dr, int l, int t, int r, int b) { + /** + * 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 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) { final LayerState st = mLayerState; int N = st.mArray != null ? st.mArray.length : 0; int i = st.mNum; @@ -146,20 +169,19 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { st.mArray = nu; } - mLayerState.mChildrenChangingConfigurations - |= dr.getChangingConfigurations(); + mLayerState.mChildrenChangingConfigurations |= layer.getChangingConfigurations(); Rec rec = new Rec(); st.mArray[i] = rec; rec.mId = id; - rec.mDrawable = dr; - rec.mInsetL = l; - rec.mInsetT = t; - rec.mInsetR = r; - rec.mInsetB = b; + rec.mDrawable = layer; + rec.mInsetL = left; + rec.mInsetT = top; + rec.mInsetR = right; + rec.mInsetB = bottom; st.mNum++; - dr.setCallback(this); + layer.setCallback(this); } /** @@ -194,21 +216,32 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { * Returns the number of layers contained within this. * @return The number of layers. */ - // TODO: Remove this once XML inflation is there for ShapeDrawable? public int getNumberOfLayers() { return mLayerState.mNum; } - - // TODO: Remove once XML inflation... + + /** + * Returns the drawable at the specified layer index. + * + * @param index The layer index of the drawable to retrieve. + * + * @return The {@link android.graphics.drawable.Drawable} at the specified layer index. + */ public Drawable getDrawable(int index) { return mLayerState.mArray[index].mDrawable; } - + + /** + * Returns the id of the specified layer. + * + * @param index The index of the layer. + * + * @return The id of the layer or {@link android.view.View#NO_ID} if the layer has no id. + */ public int getId(int index) { return mLayerState.mArray[index].mId; } - /** * Sets (or replaces) the {@link Drawable} for the layer with the given id. * @@ -295,10 +328,10 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { final int N = mLayerState.mNum; for (int i=0; i<N; i++) { reapplyPadding(i, array[i]); - padding.left += mPaddingL[i]; - padding.top += mPaddingT[i]; - padding.right += mPaddingR[i]; - padding.bottom += mPaddingB[i]; + padding.left = Math.max(padding.left, mPaddingL[i]); + padding.top = Math.max(padding.top, mPaddingT[i]); + padding.right = Math.max(padding.right, mPaddingR[i]); + padding.bottom = Math.max(padding.bottom, mPaddingB[i]); } return true; } @@ -427,7 +460,6 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { padL += mPaddingL[i]; padR += mPaddingR[i]; } - //System.out.println("Intrinsic width: " + width); return width; } @@ -439,23 +471,21 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { int padT=0, padB=0; for (int i=0; i<N; i++) { final Rec r = array[i]; - int h = r.mDrawable.getIntrinsicHeight() - + r.mInsetT + r.mInsetB + + padT + padB; + int h = r.mDrawable.getIntrinsicHeight() + r.mInsetT + r.mInsetB + + padT + padB; if (h > height) { height = h; } padT += mPaddingT[i]; padB += mPaddingB[i]; } - //System.out.println("Intrinsic height: " + height); return height; } private boolean reapplyPadding(int i, Rec r) { final Rect rect = mTmpRect; r.mDrawable.getPadding(rect); - if (rect.left != mPaddingL[i] || rect.top != mPaddingT[i] - || rect.right != mPaddingR[i] || rect.bottom != mPaddingB[i]) { + if (rect.left != mPaddingL[i] || rect.top != mPaddingT[i] || + rect.right != mPaddingR[i] || rect.bottom != mPaddingB[i]) { mPaddingL[i] = rect.left; mPaddingT[i] = rect.top; mPaddingR[i] = rect.right; @@ -485,13 +515,13 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { return null; } - /* package */ static class Rec { + static class Rec { public Drawable mDrawable; public int mInsetL, mInsetT, mInsetR, mInsetB; public int mId; } - /* package */ static class LayerState extends ConstantState { + static class LayerState extends ConstantState { int mNum; Rec[] mArray; diff --git a/graphics/java/android/graphics/drawable/TransitionDrawable.java b/graphics/java/android/graphics/drawable/TransitionDrawable.java index dd65636..e12f4b5 100644 --- a/graphics/java/android/graphics/drawable/TransitionDrawable.java +++ b/graphics/java/android/graphics/drawable/TransitionDrawable.java @@ -55,18 +55,37 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba private int mDuration; private TransitionState mState; + /** + * Create a new transition drawable with the specified list of layers. At least + * 2 layers are required for this drawable to work properly. + */ + public TransitionDrawable(Drawable[] layers) { + this(new TransitionState(null, null), layers); + } + + /** + * Create a new transition drawable with no layer. To work correctly, at least 2 + * layers must be added to this drawable. + * + * @see #TransitionDrawable(Drawable[]) + */ TransitionDrawable() { this(new TransitionState(null, null)); } - + private TransitionDrawable(TransitionState state) { super(state); mState = state; } - + + private TransitionDrawable(TransitionState state, Drawable[] layers) { + super(layers, state); + mState = state; + } + @Override LayerState createConstantState(LayerState state) { - return new TransitionState((TransitionState)state, this); + return new TransitionState((TransitionState) state, this); } /** @@ -213,7 +232,7 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba public Drawable newDrawable() { return new TransitionDrawable(this); } - + @Override public int getChangingConfigurations() { return mChangingConfigurations; |