summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2013-10-16 20:27:51 -0700
committerThe Android Automerger <android-build@google.com>2013-10-23 14:19:39 -0700
commitc0ba61337b80ebedd6b90286a5d1cb2b134e69a2 (patch)
treea1606de273f8c807d90b41b3f13928a2e2c0062a
parent0ccd79984a94b9cd03896f1e548dc9aee0d9d11b (diff)
downloadbase-c0ba61337b80ebedd6b90286a5d1cb2b134e69a2.tar.gz
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
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java35
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/view/WindowManagerImpl.java4
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java21
-rw-r--r--tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java5
4 files changed, 50 insertions, 15 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
index be27b54bb828..fa687962719e 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();
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/view/WindowManagerImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/view/WindowManagerImpl.java
index 9a633bf27f74..7e5ae8d8c756 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/view/WindowManagerImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/view/WindowManagerImpl.java
@@ -17,6 +17,7 @@ package com.android.layoutlib.bridge.android.view;
import android.util.DisplayMetrics;
import android.view.Display;
+import android.view.DisplayAdjustments;
import android.view.DisplayInfo;
import android.view.View;
import android.view.WindowManager;
@@ -32,7 +33,8 @@ public class WindowManagerImpl implements WindowManager {
DisplayInfo info = new DisplayInfo();
info.logicalHeight = mMetrics.heightPixels;
info.logicalWidth = mMetrics.widthPixels;
- mDisplay = new Display(null, Display.DEFAULT_DISPLAY, info, null);
+ mDisplay = new Display(null, Display.DEFAULT_DISPLAY, info,
+ DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS);
}
@Override
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
index 87047b34371e..23d08e343bdb 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
@@ -248,11 +248,16 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
* The counterpart is {@link #setUp()}.
*/
private void tearDown() {
- // Make sure to remove static references, otherwise we could not unload the lib
- mContext.disposeResources();
+ // The context may be null, if there was an error during init().
+ if (mContext != null) {
+ // Make sure to remove static references, otherwise we could not unload the lib
+ mContext.disposeResources();
+ }
- // quit HandlerThread created during this session.
- HandlerThread_Delegate.cleanUp(sCurrentContext);
+ if (sCurrentContext != null) {
+ // quit HandlerThread created during this session.
+ HandlerThread_Delegate.cleanUp(sCurrentContext);
+ }
// clear the stored ViewConfiguration since the map is per density and not per context.
ViewConfiguration_Accessor.clearConfigurations();
@@ -263,8 +268,12 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
sCurrentContext = null;
Bridge.setLog(null);
- mContext.getRenderResources().setFrameworkResourceIdProvider(null);
- mContext.getRenderResources().setLogger(null);
+ if (mContext != null) {
+ mContext.getRenderResources().setFrameworkResourceIdProvider(null);
+ mContext.getRenderResources().setLogger(null);
+ }
+
+ mContext = null;
}
public static BridgeContext getCurrentContext() {
diff --git a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java
index cd4f82bee925..ff2f6988ae00 100644
--- a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java
+++ b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java
@@ -17,6 +17,8 @@
package libcore.icu;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
+import com.ibm.icu.text.DateTimePatternGenerator;
+import com.ibm.icu.util.ULocale;
import java.util.Locale;
@@ -45,7 +47,8 @@ public class ICU_Delegate {
@LayoutlibDelegate
/*package*/ static String getBestDateTimePattern(String skeleton, String localeName) {
- return ""; // TODO: check what the right value should be.
+ return DateTimePatternGenerator.getInstance(new ULocale(localeName))
+ .getBestPattern(skeleton);
}
@LayoutlibDelegate