LayoutLib: Use the new ninepatch API to suppor density.

LayoutLib now compiles against a prebuilt of ninepatch.

Change-Id: I0a1ca60af90933c171ab3aa456b47f0329df2f55
diff --git a/tools/layoutlib/bridge/.classpath b/tools/layoutlib/bridge/.classpath
index 7204ace..2102eb1 100644
--- a/tools/layoutlib/bridge/.classpath
+++ b/tools/layoutlib/bridge/.classpath
@@ -6,7 +6,7 @@
 	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
 	<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/layoutlib_api/layoutlib_api-prebuilt.jar"/>
 	<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/kxml2/kxml2-2.3.0.jar" sourcepath="/ANDROID_PLAT_SRC/dalvik/libcore/xml/src/main/java"/>
-	<classpathentry kind="var" path="ANDROID_PLAT_OUT_FRAMEWORK/ninepatch.jar" sourcepath="/ANDROID_PLAT_SRC/development/tools/ninepatch/src"/>
 	<classpathentry kind="var" path="ANDROID_PLAT_SRC/out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar" sourcepath="/ANDROID_PLAT_SRC/frameworks/base"/>
+	<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/ninepatch/ninepatch-prebuilt.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/tools/layoutlib/bridge/Android.mk b/tools/layoutlib/bridge/Android.mk
index b7a602a..9b7bc5f9 100644
--- a/tools/layoutlib/bridge/Android.mk
+++ b/tools/layoutlib/bridge/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_JAVA_LIBRARIES := \
 	kxml2-2.3.0 \
 	layoutlib_api-prebuilt \
-	ninepatch
+	ninepatch-prebuilt
 
 LOCAL_STATIC_JAVA_LIBRARIES := temp_layoutlib
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
index a6c6dfd..95663ec 100644
--- a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
@@ -167,7 +167,7 @@
 
        try {
            chunkObject.draw(bitmap_delegate.getImage(), graphics,
-                   left, top, right - left, bottom - top);
+                   left, top, right - left, bottom - top, destDensity, srcDensity);
        } finally {
            if (paint_delegate != null) {
                graphics.dispose();
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
index 13f0f4a7..f03931f 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
@@ -48,7 +48,7 @@
 import java.util.regex.Pattern;
 
 /**
- * Helper class to provide various convertion method used in handling android resources.
+ * Helper class to provide various conversion method used in handling android resources.
  */
 public final class ResourceHelper {
 
@@ -133,7 +133,8 @@
                 // if either chunk or bitmap is null, then we reload the 9-patch file.
                 if (chunk == null || bitmap == null) {
                     try {
-                        NinePatch ninePatch = NinePatch.load(file.toURL(), false /* convert */);
+                        NinePatch ninePatch = NinePatch.load(file.toURI().toURL(),
+                                false /* convert */);
                         if (ninePatch != null) {
                             if (chunk == null) {
                                 chunk = ninePatch.getChunk();
@@ -161,6 +162,7 @@
                         // URL is wrong, we'll return null below
                     } catch (IOException e) {
                         // failed to read the file, we'll return null below.
+                        Bridge.getLog().error(null, e);
                     }
                 }
 
@@ -176,7 +178,7 @@
 
             return null;
         } else if (lowerCaseValue.endsWith(".xml")) {
-            // create a blockparser for the file
+            // create a block parser for the file
             File f = new File(stringValue);
             if (f.isFile()) {
                 try {
@@ -220,7 +222,7 @@
                     return new BitmapDrawable(context.getResources(), bitmap);
                 } catch (IOException e) {
                     // we'll return null below
-                    // TODO: log the error.
+                    Bridge.getLog().error(null, e);
                 }
             } else {
                 // attempt to get a color from the value
@@ -229,7 +231,8 @@
                     return new ColorDrawable(color);
                 } catch (NumberFormatException e) {
                     // we'll return null below.
-                    // TODO: log the error
+                    Bridge.getLog().error(null,
+                            "failed to convert " + stringValue + " into a drawable");
                 }
             }
         }