diff options
| author | Deepanshu Gupta <deepanshu@google.com> | 2013-10-16 20:27:51 -0700 |
|---|---|---|
| committer | Deepanshu Gupta <deepanshu@google.com> | 2013-10-16 21:49:02 -0700 |
| commit | 39e75835399f4d979cf82069dae2bd1ec496fb81 (patch) | |
| tree | 257a72bb4cb9af3ffa44869328ec9ce71e83a8e4 /tools/layoutlib/bridge/src/android/graphics | |
| parent | 1bab3f5306f0682eafd74d17517a90c0f4ac4d5c (diff) | |
| download | frameworks_base-39e75835399f4d979cf82069dae2bd1ec496fb81.zip frameworks_base-39e75835399f4d979cf82069dae2bd1ec496fb81.tar.gz frameworks_base-39e75835399f4d979cf82069dae2bd1ec496fb81.tar.bz2 | |
Fix layoutlib for KK
Fix a NPE, update the native methods for NinePatch and update an ICU
method to return the right value as required by DatePicker widget.
Bug: 11140701
Change-Id: Id92fc5359acf6dde1bcdbc781aaf637fdb6eecbf
Diffstat (limited to 'tools/layoutlib/bridge/src/android/graphics')
| -rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java index be27b54..fa68796 100644 --- a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java @@ -48,6 +48,11 @@ import java.util.Map; */ public final class NinePatch_Delegate { + // ---- delegate manager ---- + private static final DelegateManager<NinePatch_Delegate> sManager = + new DelegateManager<NinePatch_Delegate>(NinePatch_Delegate.class); + + // ---- delegate helper data ---- /** * Cache map for {@link NinePatchChunk}. * When the chunks are created they are serialized into a byte[], and both are put @@ -60,6 +65,10 @@ public final class NinePatch_Delegate { private final static Map<byte[], SoftReference<NinePatchChunk>> sChunkCache = new HashMap<byte[], SoftReference<NinePatchChunk>>(); + // ---- delegate data ---- + private byte[] chunk; + + // ---- Public Helper methods ---- /** @@ -149,32 +158,39 @@ public final class NinePatch_Delegate { } @LayoutlibDelegate - /*package*/ static void validateNinePatchChunk(int bitmap, byte[] chunk) { + /*package*/ static int validateNinePatchChunk(int bitmap, byte[] chunk) { // the default JNI implementation only checks that the byte[] has the same // size as the C struct it represent. Since we cannot do the same check (serialization // will return different size depending on content), we do nothing. + NinePatch_Delegate newDelegate = new NinePatch_Delegate(); + newDelegate.chunk = chunk; + return sManager.addNewDelegate(newDelegate); + } + + /*package*/ static void nativeFinalize(int chunk) { + sManager.removeJavaReferenceFor(chunk); } @LayoutlibDelegate /*package*/ static void nativeDraw(int canvas_instance, RectF loc, int bitmap_instance, - byte[] c, int paint_instance_or_null, int destDensity, int srcDensity) { + int chunk, int paint_instance_or_null, int destDensity, int srcDensity) { draw(canvas_instance, (int) loc.left, (int) loc.top, (int) loc.width(), (int) loc.height(), - bitmap_instance, c, paint_instance_or_null, + bitmap_instance, chunk, paint_instance_or_null, destDensity, srcDensity); } @LayoutlibDelegate /*package*/ static void nativeDraw(int canvas_instance, Rect loc, int bitmap_instance, - byte[] c, int paint_instance_or_null, int destDensity, int srcDensity) { + int chunk, int paint_instance_or_null, int destDensity, int srcDensity) { draw(canvas_instance, loc.left, loc.top, loc.width(), loc.height(), - bitmap_instance, c, paint_instance_or_null, + bitmap_instance, chunk, paint_instance_or_null, destDensity, srcDensity); } @LayoutlibDelegate - /*package*/ static int nativeGetTransparentRegion(int bitmap, byte[] chunk, Rect location) { + /*package*/ static int nativeGetTransparentRegion(int bitmap, int chunk, Rect location) { return 0; } @@ -182,7 +198,7 @@ public final class NinePatch_Delegate { private static void draw(int canvas_instance, final int left, final int top, final int right, final int bottom, - int bitmap_instance, byte[] c, int paint_instance_or_null, + int bitmap_instance, int chunk, int paint_instance_or_null, final int destDensity, final int srcDensity) { // get the delegate from the native int. final Bitmap_Delegate bitmap_delegate = Bitmap_Delegate.getDelegate(bitmap_instance); @@ -190,6 +206,11 @@ public final class NinePatch_Delegate { return; } + byte[] c = null; + NinePatch_Delegate delegate = sManager.getDelegate(chunk); + if (delegate != null) { + c = delegate.chunk; + } if (c == null) { // not a 9-patch? BufferedImage image = bitmap_delegate.getImage(); |
