auto import from //depot/cupcake/@132589

This commit is contained in:
The Android Open Source Project
2009-03-03 14:04:24 -08:00
parent 3dec7d563a
commit 076357b856
310 changed files with 4072 additions and 18131 deletions

View File

@@ -17,15 +17,6 @@
package android.graphics.drawable;
import android.graphics.*;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.TypedValue;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.InputStream;
/**
*
@@ -41,9 +32,6 @@ public class NinePatchDrawable extends Drawable {
private Paint mPaint;
private boolean mMutated;
NinePatchDrawable() {
}
public NinePatchDrawable(Bitmap bitmap, byte[] chunk, Rect padding, String srcName) {
this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding));
}
@@ -52,13 +40,6 @@ public class NinePatchDrawable extends Drawable {
this(new NinePatchState(patch, null));
}
private void setNinePatchState(NinePatchState state) {
mNinePatchState = state;
mNinePatch = state.mNinePatch;
mPadding = state.mPadding;
if (state.mDither) setDither(state.mDither);
}
// overrides
@Override
@@ -92,55 +73,6 @@ public class NinePatchDrawable extends Drawable {
getPaint().setDither(dither);
}
@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
throws XmlPullParserException, IOException {
super.inflate(r, parser, attrs);
TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.NinePatchDrawable);
final int id = a.getResourceId(com.android.internal.R.styleable.NinePatchDrawable_src, 0);
if (id == 0) {
throw new XmlPullParserException(parser.getPositionDescription() +
": <nine-patch> requires a valid src attribute");
}
final boolean dither = a.getBoolean(
com.android.internal.R.styleable.NinePatchDrawable_dither, false);
final BitmapFactory.Options options = new BitmapFactory.Options();
if (dither) {
options.inDither = false;
}
final Rect padding = new Rect();
Bitmap bitmap = null;
try {
final TypedValue value = new TypedValue();
final InputStream is = r.openRawResource(id, value);
bitmap = BitmapFactory.decodeStream(r, value, is, padding, options);
is.close();
} catch (IOException e) {
// Ignore
}
if (bitmap == null) {
throw new XmlPullParserException(parser.getPositionDescription() +
": <nine-patch> requires a valid src attribute");
} else if (bitmap.getNinePatchChunk() == null) {
throw new XmlPullParserException(parser.getPositionDescription() +
": <nine-patch> requires a valid 9-patch source image");
}
setNinePatchState(new NinePatchState(
new NinePatch(bitmap, bitmap.getNinePatchChunk(), "XML 9-patch"), padding, dither));
a.recycle();
}
public Paint getPaint() {
if (mPaint == null) {
mPaint = new Paint();
@@ -209,24 +141,17 @@ public class NinePatchDrawable extends Drawable {
final static class NinePatchState extends ConstantState {
final NinePatch mNinePatch;
final Rect mPadding;
final boolean mDither;
int mChangingConfigurations;
NinePatchState(NinePatch ninePatch, Rect padding) {
this(ninePatch, padding, false);
}
NinePatchState(NinePatch ninePatch, Rect rect, boolean dither) {
mNinePatch = ninePatch;
mPadding = rect;
mDither = dither;
mPadding = padding;
}
NinePatchState(NinePatchState state) {
mNinePatch = new NinePatch(state.mNinePatch);
mPadding = new Rect(state.mPadding);
mChangingConfigurations = state.mChangingConfigurations;
mDither = state.mDither;
}
@Override
@@ -241,7 +166,9 @@ public class NinePatchDrawable extends Drawable {
}
private NinePatchDrawable(NinePatchState state) {
setNinePatchState(state);
mNinePatchState = state;
mNinePatch = state.mNinePatch;
mPadding = state.mPadding;
}
}