Merge "Fix layoutlib for KK" into klp-dev

This commit is contained in:
Deepanshu Gupta
2013-10-18 02:07:30 +00:00
committed by Android (Google) Code Review
4 changed files with 50 additions and 15 deletions

View File

@@ -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();

View File

@@ -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

View File

@@ -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() {

View File

@@ -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