summaryrefslogtreecommitdiffstats
path: root/graphics/java/android/graphics/NinePatch.java
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2014-07-08 17:13:08 -0700
committerChris Craik <ccraik@google.com>2014-07-14 15:01:27 -0700
commit47cd8e921db73e894f94ec4729ade90da50996f5 (patch)
treedc087c5a19fec4c564ef73f6d487f1d72cf1cdb4 /graphics/java/android/graphics/NinePatch.java
parent5028fb035794c207698e52b276c54de109dd5022 (diff)
downloadframeworks_base-47cd8e921db73e894f94ec4729ade90da50996f5.zip
frameworks_base-47cd8e921db73e894f94ec4729ade90da50996f5.tar.gz
frameworks_base-47cd8e921db73e894f94ec4729ade90da50996f5.tar.bz2
Implement outline support for nine patches
b/15856895 Nine patches now have outline round rect metadata stored as optional png tags. aapt generates these automatically by inspecting the bitmap pixels to estimate outline bounds and round rect radius, based on opacity. Change-Id: I226e328a97873010d9e1adb797ac48f93a31183c
Diffstat (limited to 'graphics/java/android/graphics/NinePatch.java')
-rw-r--r--graphics/java/android/graphics/NinePatch.java34
1 files changed, 33 insertions, 1 deletions
diff --git a/graphics/java/android/graphics/NinePatch.java b/graphics/java/android/graphics/NinePatch.java
index befac92..335bce0 100644
--- a/graphics/java/android/graphics/NinePatch.java
+++ b/graphics/java/android/graphics/NinePatch.java
@@ -16,7 +16,6 @@
package android.graphics;
-
/**
* The NinePatch class permits drawing a bitmap in nine or more sections.
* Essentially, it allows the creation of custom graphics that will scale the
@@ -32,6 +31,39 @@ package android.graphics;
* </p>
*/
public class NinePatch {
+ /**
+ * Struct of inset information attached to a 9 patch bitmap.
+ *
+ * Present on a 9 patch bitmap if it optical insets were manually included,
+ * or if outline insets were automatically included by aapt.
+ *
+ * @hide
+ */
+ public static class InsetStruct {
+ @SuppressWarnings({"UnusedDeclaration"}) // called from JNI
+ InsetStruct(int opticalLeft, int opticalTop, int opticalRight, int opticalBottom,
+ int outlineLeft, int outlineTop, int outlineRight, int outlineBottom,
+ float outlineRadius, boolean outlineFilled, float decodeScale) {
+ opticalRect = new Rect(opticalLeft, opticalTop, opticalRight, opticalBottom);
+ outlineRect = new Rect(outlineLeft, outlineTop, outlineRight, outlineBottom);
+
+ if (decodeScale != 1.0f) {
+ // if bitmap was scaled when decoded, scale the insets from the metadata values
+ opticalRect.scale(decodeScale);
+
+ // round inward while scaling outline, as the outline should always be conservative
+ outlineRect.scaleRoundIn(decodeScale);
+ }
+ this.outlineRadius = outlineRadius * decodeScale;
+ this.outlineFilled = outlineFilled;
+ }
+
+ public final Rect opticalRect;
+ public final Rect outlineRect;
+ public final float outlineRadius;
+ public final boolean outlineFilled;
+ }
+
private final Bitmap mBitmap;
/**