summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2009-07-29 14:57:05 -0700
committerJean-Baptiste Queru <jbq@google.com>2009-07-29 14:57:05 -0700
commit61e4248f8f6ae8a8f40550cc0800e5190cd1dc09 (patch)
tree07d964042985825b97f51b3744977c25b685b2f1 /graphics/java
parent2af1b3db3d4f687d008db74b150f149e956b4bc6 (diff)
parenta8675f67e33bc7337d148358783b0fd138b501ff (diff)
downloadframeworks_base-61e4248f8f6ae8a8f40550cc0800e5190cd1dc09.zip
frameworks_base-61e4248f8f6ae8a8f40550cc0800e5190cd1dc09.tar.gz
frameworks_base-61e4248f8f6ae8a8f40550cc0800e5190cd1dc09.tar.bz2
merge from donut
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/Bitmap.java71
-rw-r--r--graphics/java/android/graphics/BitmapFactory.java31
-rw-r--r--graphics/java/android/graphics/Canvas.java4
-rw-r--r--graphics/java/android/graphics/Rect.java8
-rw-r--r--graphics/java/android/graphics/drawable/ShapeDrawable.java13
5 files changed, 82 insertions, 45 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index e2e93eb..df659ef 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -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.
+ */
+ 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.
*
- * @hide pending API council approval
+ * @param metrics The target display metrics.
+ * @return The scaled height of this bitmap, according to the density scale factor.
*/
- public int getScaledHeight() {
- final float scale = getDensityScale();
- return scale == DENSITY_SCALE_UNKNOWN ? getWidth() : (int) (getHeight() / scale);
+ public int getScaledHeight(DisplayMetrics metrics) {
+ final float scale = mDensityScale;
+ if (!mAutoScaling || scale < 0) {
+ return getHeight();
+ }
+ return (int)(getHeight() * metrics.density / scale);
}
/**
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
index e5a9aab..76abaa2 100644
--- a/graphics/java/android/graphics/BitmapFactory.java
+++ b/graphics/java/android/graphics/BitmapFactory.java
@@ -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;
@@ -129,6 +125,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,
* outWidth will be set to -1.
@@ -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);
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index 4498e1a..da73597 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -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) {
diff --git a/graphics/java/android/graphics/Rect.java b/graphics/java/android/graphics/Rect.java
index 50ab566..42a14ce 100644
--- a/graphics/java/android/graphics/Rect.java
+++ b/graphics/java/android/graphics/Rect.java
@@ -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);
}
}
}
diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java
index d24194f..6677a35 100644
--- a/graphics/java/android/graphics/drawable/ShapeDrawable.java
+++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java
@@ -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;
}