donut snapshot

This commit is contained in:
Jean-Baptiste Queru
2009-07-29 14:25:07 -07:00
parent cf4550c319
commit a8675f67e3
326 changed files with 18109 additions and 5040 deletions

View File

@@ -18,6 +18,7 @@ package android.graphics;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.DisplayMetrics;
import java.io.OutputStream;
import java.nio.Buffer;
@@ -31,8 +32,6 @@ public final class Bitmap implements Parcelable {
*
* @see Bitmap#getDensityScale()
* @see Bitmap#setDensityScale(float)
*
* @hide pending API council approval
*/
public static final float DENSITY_SCALE_UNKNOWN = -1.0f;
@@ -84,11 +83,9 @@ public final class Bitmap implements Parcelable {
* @see #setDensityScale(float)
* @see #isAutoScalingEnabled()
* @see #setAutoScalingEnabled(boolean)
* @see android.util.DisplayMetrics#DEFAULT_DENSITY
* @see android.util.DisplayMetrics#DENSITY_DEFAULT
* @see android.util.DisplayMetrics#density
* @see #DENSITY_SCALE_UNKNOWN
*
* @hide pending API council approval
*/
public float getDensityScale() {
return mDensityScale;
@@ -106,11 +103,9 @@ public final class Bitmap implements Parcelable {
* @see #getDensityScale()
* @see #isAutoScalingEnabled()
* @see #setAutoScalingEnabled(boolean)
* @see android.util.DisplayMetrics#DEFAULT_DENSITY
* @see android.util.DisplayMetrics#DENSITY_DEFAULT
* @see android.util.DisplayMetrics#density
* @see #DENSITY_SCALE_UNKNOWN
*
* @hide pending API council approval
*/
public void setDensityScale(float densityScale) {
mDensityScale = densityScale;
@@ -132,8 +127,6 @@ public final class Bitmap implements Parcelable {
* @see #setAutoScalingEnabled(boolean)
* @see #getDensityScale()
* @see #setDensityScale(float)
*
* @hide pending API council approval
*/
public boolean isAutoScalingEnabled() {
return mAutoScaling;
@@ -150,8 +143,6 @@ public final class Bitmap implements Parcelable {
* the bitmap will never be automatically scaled at drawing time.</p>
*
* @param autoScalingEnabled True to scale the bitmap at drawing time, false otherwise.
*
* @hide pending API council approval
*/
public void setAutoScalingEnabled(boolean autoScalingEnabled) {
mAutoScaling = autoScalingEnabled;
@@ -465,8 +456,8 @@ public final class Bitmap implements Parcelable {
// The new bitmap was created from a known bitmap source so assume that
// they use the same density scale
bitmap.setDensityScale(source.getDensityScale());
bitmap.setAutoScalingEnabled(source.isAutoScalingEnabled());
bitmap.mDensityScale = source.mDensityScale;
bitmap.mAutoScaling = source.mAutoScaling;
return bitmap;
}
@@ -615,26 +606,60 @@ public final class Bitmap implements Parcelable {
* Convenience method that returns the width of this bitmap divided
* by the density scale factor.
*
* @param canvas The Canvas the bitmap will be drawn to.
* @return The scaled width of this bitmap, according to the density scale factor.
*
* @hide pending API council approval
*/
public int getScaledWidth() {
final float scale = getDensityScale();
return scale == DENSITY_SCALE_UNKNOWN ? getWidth() : (int) (getWidth() / scale);
public int getScaledWidth(Canvas canvas) {
final float scale = mDensityScale;
if (!mAutoScaling || scale < 0) {
return getWidth();
}
return (int)(getWidth() * canvas.getDensityScale() / scale);
}
/**
* Convenience method that returns the height of this bitmap divided
* by the density scale factor.
*
* @param canvas The Canvas the bitmap will be drawn to.
* @return The scaled height of this bitmap, according to the density scale factor.
*
* @hide pending API council approval
*/
public int getScaledHeight() {
final float scale = getDensityScale();
return scale == DENSITY_SCALE_UNKNOWN ? getWidth() : (int) (getHeight() / scale);
public int getScaledHeight(Canvas canvas) {
final float scale = mDensityScale;
if (!mAutoScaling || scale < 0) {
return getHeight();
}
return (int)(getHeight() * canvas.getDensityScale() / scale);
}
/**
* Convenience method that returns the width of this bitmap divided
* by the density scale factor.
*
* @param metrics The target display metrics.
* @return The scaled width of this bitmap, according to the density scale factor.
*/
public int getScaledWidth(DisplayMetrics metrics) {
final float scale = mDensityScale;
if (!mAutoScaling || scale < 0) {
return getWidth();
}
return (int)(getWidth() * metrics.density / scale);
}
/**
* Convenience method that returns the height of this bitmap divided
* by the density scale factor.
*
* @param metrics The target display metrics.
* @return The scaled height of this bitmap, according to the density scale factor.
*/
public int getScaledHeight(DisplayMetrics metrics) {
final float scale = mDensityScale;
if (!mAutoScaling || scale < 0) {
return getHeight();
}
return (int)(getHeight() * metrics.density / scale);
}
/**

View File

@@ -81,10 +81,8 @@ public class BitmapFactory {
/**
* The desired pixel density of the bitmap.
*
* @see android.util.DisplayMetrics#DEFAULT_DENSITY
* @see android.util.DisplayMetrics#DENSITY_DEFAULT
* @see android.util.DisplayMetrics#density
*
* @hide pending API council approval
*/
public int inDensity;
@@ -97,8 +95,6 @@ public class BitmapFactory {
* a non-scaled version of the bitmap. In this case,
* {@link android.graphics.Bitmap#setAutoScalingEnabled(boolean)} can be used
* to properly scale the bitmap at drawing time.</p>
*
* @hide pending API council approval
*/
public boolean inScaled;
@@ -128,6 +124,19 @@ public class BitmapFactory {
*/
public boolean inInputShareable;
/**
* Normally bitmap allocations count against the dalvik heap, which
* means they help trigger GCs when a lot have been allocated. However,
* in rare cases, the caller may want to allocate the bitmap outside of
* that heap. To request that, set inNativeAlloc to true. In these
* rare instances, it is solely up to the caller to ensure that OOM is
* managed explicitly by calling bitmap.recycle() as soon as such a
* bitmap is no longer needed.
*
* @hide pending API council approval
*/
public boolean inNativeAlloc;
/**
* The resulting width of the bitmap, set independent of the state of
* inJustDecodeBounds. However, if there is an error trying to decode,
@@ -225,8 +234,6 @@ public class BitmapFactory {
/**
* Decode a new Bitmap from an InputStream. This InputStream was obtained from
* resources, which we pass to be able to scale the bitmap accordingly.
*
* @hide
*/
public static Bitmap decodeStream(Resources res, TypedValue value, InputStream is,
Rect pad, Options opts) {
@@ -238,15 +245,19 @@ public class BitmapFactory {
Bitmap bm = decodeStream(is, pad, opts);
if (bm != null && res != null && value != null) {
final int density = value.density;
if (density == TypedValue.DENSITY_NONE) {
return bm;
}
byte[] np = bm.getNinePatchChunk();
final boolean isNinePatch = np != null && NinePatch.isNinePatchChunk(np);
final int density = value.density;
if (opts.inDensity == 0) {
opts.inDensity = density == TypedValue.DENSITY_DEFAULT ?
DisplayMetrics.DEFAULT_DENSITY : density;
DisplayMetrics.DENSITY_DEFAULT : density;
}
float scale = opts.inDensity / (float) DisplayMetrics.DEFAULT_DENSITY;
float scale = opts.inDensity / (float) DisplayMetrics.DENSITY_DEFAULT;
if (opts.inScaled || isNinePatch) {
bm.setDensityScale(1.0f);

View File

@@ -184,8 +184,6 @@ public class Canvas {
*
* @see #setDensityScale(float)
* @see Bitmap#getDensityScale()
*
* @hide pending API council approval
*/
public float getDensityScale() {
if (mBitmap != null) {
@@ -205,8 +203,6 @@ public class Canvas {
*
* @see #getDensityScale()
* @see Bitmap#setDensityScale(float)
*
* @hide pending API council approval
*/
public void setDensityScale(float densityScale) {
if (mBitmap != null) {

View File

@@ -552,10 +552,10 @@ public final class Rect implements Parcelable {
*/
public void scale(float scale) {
if (scale != 1.0f) {
left *= scale;
top *= scale;
right *= scale;
bottom*= scale;
left = (int) (left * scale + 0.5f);
top = (int) (top * scale + 0.5f);
right = (int) (right * scale + 0.5f);
bottom = (int) (bottom * scale + 0.5f);
}
}
}

View File

@@ -278,10 +278,15 @@ public class ShapeDrawable extends Drawable {
if (name.equals("padding")) {
TypedArray a = r.obtainAttributes(attrs,
com.android.internal.R.styleable.ShapeDrawablePadding);
setPadding(a.getInt(com.android.internal.R.styleable.ShapeDrawablePadding_left, 0),
a.getInt(com.android.internal.R.styleable.ShapeDrawablePadding_top, 0),
a.getInt(com.android.internal.R.styleable.ShapeDrawablePadding_right, 0),
a.getInt(com.android.internal.R.styleable.ShapeDrawablePadding_bottom, 0));
setPadding(
a.getDimensionPixelOffset(
com.android.internal.R.styleable.ShapeDrawablePadding_left, 0),
a.getDimensionPixelOffset(
com.android.internal.R.styleable.ShapeDrawablePadding_top, 0),
a.getDimensionPixelOffset(
com.android.internal.R.styleable.ShapeDrawablePadding_right, 0),
a.getDimensionPixelOffset(
com.android.internal.R.styleable.ShapeDrawablePadding_bottom, 0));
a.recycle();
return true;
}