am b27d8814: am 21cf9843: am d1084cc0: Add missing native methods. [DO NOT MERGE]

* commit 'b27d881467869539a5c8ec2510e8415912abb617':
  Add missing native methods. [DO NOT MERGE]
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
index b76b8cf..96616aa 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -61,6 +61,7 @@
     private final Config mConfig;
     private BufferedImage mImage;
     private boolean mHasAlpha = true;
+    private boolean mHasMipMap = false;      // TODO: check the default.
     private int mGenerationId = 0;
 
 
@@ -185,6 +186,10 @@
         return mHasAlpha && mConfig != Config.RGB_565;
     }
 
+    public boolean hasMipMap() {
+        // TODO: check if more checks are required as in hasAlpha.
+        return mHasMipMap;
+    }
     /**
      * Update the generationId.
      *
@@ -336,6 +341,17 @@
     }
 
     @LayoutlibDelegate
+    /*package*/ static boolean nativeHasMipMap(int nativeBitmap) {
+        // get the delegate from the native int.
+        Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
+        if (delegate == null) {
+            return true;
+        }
+
+        return delegate.mHasMipMap;
+    }
+
+    @LayoutlibDelegate
     /*package*/ static int nativeGetPixel(int nativeBitmap, int x, int y) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
@@ -469,6 +485,17 @@
     }
 
     @LayoutlibDelegate
+    /*package*/ static void nativeSetHasMipMap(int nativeBitmap, boolean hasMipMap) {
+        // get the delegate from the native int.
+        Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
+        if (delegate == null) {
+            return;
+        }
+
+        delegate.mHasMipMap = hasMipMap;
+    }
+
+    @LayoutlibDelegate
     /*package*/ static boolean nativeSameAs(int nb0, int nb1) {
         Bitmap_Delegate delegate1 = sManager.getDelegate(nb0);
         if (delegate1 == null) {
@@ -524,7 +551,7 @@
         int nativeInt = sManager.addNewDelegate(delegate);
 
         // and create/return a new Bitmap with it
-        return new Bitmap(nativeInt, null /* buffer */, isMutable, null /*ninePatchChunk*/, 
+        return new Bitmap(nativeInt, null /* buffer */, isMutable, null /*ninePatchChunk*/,
                 density);
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
index 9aed8c8..47b178e 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -330,20 +330,12 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setBitmap(int nativeCanvas, int bitmap) {
-        // get the delegate from the native int.
-        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
-        if (canvasDelegate == null) {
-            return;
+    /*package*/ static void native_setBitmap(int nativeCanvas, int nativeBitmap) {
+        Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmap);
+        Canvas_Delegate canvasDelegate = Canvas_Delegate.getDelegate(nativeCanvas);
+        if (canvasDelegate != null && bitmapDelegate != null) {
+            canvasDelegate.setBitmap(bitmapDelegate);
         }
-
-        // get the delegate from the native int.
-        Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
-        if (bitmapDelegate == null) {
-            return;
-        }
-
-        canvasDelegate.setBitmap(bitmapDelegate);
     }
 
     @LayoutlibDelegate
@@ -571,17 +563,15 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_quickReject(int nativeCanvas,
-                                                     RectF rect,
-                                                     int native_edgeType) {
+    /*package*/ static boolean native_quickReject(int nativeCanvas, RectF rect,
+            int native_edgeType) {
         // FIXME properly implement quickReject
         return false;
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_quickReject(int nativeCanvas,
-                                                     int path,
-                                                     int native_edgeType) {
+    /*package*/ static boolean native_quickReject(int nativeCanvas, int path,
+            int native_edgeType) {
         // FIXME properly implement quickReject
         return false;
     }
@@ -994,6 +984,7 @@
                 float x = startX;
                 float y = startY;
                 if (paintDelegate.getTextAlign() != Paint.Align.LEFT.nativeInt) {
+                    // TODO: check the value of bidiFlags.
                     float m = paintDelegate.measureText(text, index, count);
                     if (paintDelegate.getTextAlign() == Paint.Align.CENTER.nativeInt) {
                         x -= m / 2;
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
index 1382641..9d60a18 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
@@ -964,7 +964,8 @@
     @LayoutlibDelegate
     /*package*/ static int native_getTextWidths(int native_object, String text, int start,
             int end, float[] widths) {
-        return native_getTextWidths(native_object, text.toCharArray(), start, end - start, widths);
+        return native_getTextWidths(native_object, text.toCharArray(), start, end - start,
+                widths);
     }
 
     @LayoutlibDelegate
@@ -1068,7 +1069,8 @@
     @LayoutlibDelegate
     /*package*/ static void nativeGetStringBounds(int nativePaint, String text, int start,
             int end, Rect bounds) {
-        nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, bounds);
+        nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start,
+                bounds);
     }
 
     @LayoutlibDelegate
diff --git a/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java b/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java
index 2961f97..09f3e47 100644
--- a/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java
+++ b/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java
@@ -15,6 +15,8 @@
  */
 package android.os;
 
+import java.lang.reflect.Field;
+
 /**
  * Class allowing access to package-protected methods/fields.
  */
@@ -23,5 +25,23 @@
     public static void cleanupThread() {
         // clean up the looper
         Looper.sThreadLocal.remove();
+        try {
+            Field sMainLooper = Looper.class.getDeclaredField("sMainLooper");
+            sMainLooper.setAccessible(true);
+            sMainLooper.set(null, null);
+        } catch (SecurityException e) {
+            catchReflectionException();
+        } catch (IllegalArgumentException e) {
+            catchReflectionException();
+        } catch (NoSuchFieldException e) {
+            catchReflectionException();
+        } catch (IllegalAccessException e) {
+            catchReflectionException();
+        }
+
+    }
+
+    private static void catchReflectionException() {
+        assert(false);
     }
 }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index bf8658e..42257c5 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -428,7 +428,7 @@
         // we need to make sure the Looper has been initialized for this thread.
         // this is required for View that creates Handler objects.
         if (Looper.myLooper() == null) {
-            Looper.prepare();
+            Looper.prepareMainLooper();
         }
     }