Make optical insets actually work

Change-Id: I9fabf4cb939cc7a868f95580e7229745acde0418
This commit is contained in:
Alan Viverette
2014-07-03 15:16:41 -07:00
parent 40d43b27b4
commit c054966b71
5 changed files with 34 additions and 26 deletions

View File

@@ -16,6 +16,7 @@
package android.graphics;
import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.DisplayMetrics;
@@ -73,7 +74,7 @@ public final class Bitmap implements Parcelable {
private boolean mRequestPremultiplied;
private byte[] mNinePatchChunk; // may be null
private int[] mLayoutBounds; // may be null
private int[] mOpticalInsets; // may be null
private int mWidth;
private int mHeight;
private boolean mRecycled;
@@ -110,7 +111,7 @@ public final class Bitmap implements Parcelable {
@SuppressWarnings({"UnusedDeclaration"}) // called from JNI
Bitmap(long nativeBitmap, byte[] buffer, int width, int height, int density,
boolean isMutable, boolean requestPremultiplied,
byte[] ninePatchChunk, int[] layoutBounds) {
byte[] ninePatchChunk, int[] opticalInsets) {
if (nativeBitmap == 0) {
throw new RuntimeException("internal error: native bitmap is 0");
}
@@ -125,7 +126,7 @@ public final class Bitmap implements Parcelable {
mFinalizer = new BitmapFinalizer(nativeBitmap);
mNinePatchChunk = ninePatchChunk;
mLayoutBounds = layoutBounds;
mOpticalInsets = opticalInsets;
if (density >= 0) {
mDensity = density;
}
@@ -291,16 +292,6 @@ public final class Bitmap implements Parcelable {
mNinePatchChunk = chunk;
}
/**
* Sets the layout bounds as an array of left, top, right, bottom integers
* @param bounds the array containing the padding values
*
* @hide
*/
public void setLayoutBounds(int[] bounds) {
mLayoutBounds = bounds;
}
/**
* Free the native object associated with this bitmap, and clear the
* reference to the pixel data. This will not free the pixel data synchronously;
@@ -949,11 +940,20 @@ public final class Bitmap implements Parcelable {
}
/**
* Populates a rectangle with the bitmap's optical insets.
*
* @param outInsets Rect to populate with optical insets
* @hide
* @return the layout padding [left, right, top, bottom]
*/
public int[] getLayoutBounds() {
return mLayoutBounds;
public void getOpticalInsets(@NonNull Rect outInsets) {
if (mOpticalInsets == null) {
outInsets.setEmpty();
} else {
outInsets.left = mOpticalInsets[0];
outInsets.top = mOpticalInsets[1];
outInsets.right = mOpticalInsets[2];
outInsets.bottom = mOpticalInsets[3];
}
}
/**