Loading tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +28 −1 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ public final class Bitmap_Delegate { private final Config mConfig; private BufferedImage mImage; private boolean mHasAlpha = true; private boolean mHasMipMap = false; // TODO: check the default. private int mGenerationId = 0; Loading Loading @@ -185,6 +186,10 @@ public final class Bitmap_Delegate { return mHasAlpha && mConfig != Config.RGB_565; } public boolean hasMipMap() { // TODO: check if more checks are required as in hasAlpha. return mHasMipMap; } /** * Update the generationId. * Loading Loading @@ -335,6 +340,17 @@ public final class Bitmap_Delegate { return delegate.mHasAlpha; } @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. Loading Loading @@ -468,6 +484,17 @@ public final class Bitmap_Delegate { delegate.mHasAlpha = hasAlpha; } @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); Loading tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +11 −14 Original line number Diff line number Diff line Loading @@ -330,20 +330,19 @@ public final class Canvas_Delegate { } @LayoutlibDelegate /*package*/ static void native_setBitmap(int nativeCanvas, int bitmap) { /*package*/ static void copyNativeCanvasState(int srcCanvas, int dstCanvas) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { Canvas_Delegate srcCanvasDelegate = sManager.getDelegate(srcCanvas); if (srcCanvasDelegate == null) { return; } // get the delegate from the native int. Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap); if (bitmapDelegate == null) { Canvas_Delegate dstCanvasDelegate = sManager.getDelegate(dstCanvas); if (dstCanvasDelegate == null) { return; } canvasDelegate.setBitmap(bitmapDelegate); // TODO: actually copy the canvas state. } @LayoutlibDelegate Loading Loading @@ -572,16 +571,14 @@ public final class Canvas_Delegate { @LayoutlibDelegate /*package*/ static boolean native_quickReject(int nativeCanvas, RectF rect, int native_edgeType) { RectF rect) { // FIXME properly implement quickReject return false; } @LayoutlibDelegate /*package*/ static boolean native_quickReject(int nativeCanvas, int path, int native_edgeType) { int path) { // FIXME properly implement quickReject return false; } Loading @@ -589,8 +586,7 @@ public final class Canvas_Delegate { @LayoutlibDelegate /*package*/ static boolean native_quickReject(int nativeCanvas, float left, float top, float right, float bottom, int native_edgeType) { float right, float bottom) { // FIXME properly implement quickReject return false; } Loading Loading @@ -994,7 +990,8 @@ public final class Canvas_Delegate { float x = startX; float y = startY; if (paintDelegate.getTextAlign() != Paint.Align.LEFT.nativeInt) { float m = paintDelegate.measureText(text, index, count); // TODO: check the value of bidiFlags. float m = paintDelegate.measureText(text, index, count, 0); if (paintDelegate.getTextAlign() == Paint.Align.CENTER.nativeInt) { x -= m / 2; } else if (paintDelegate.getTextAlign() == Paint.Align.RIGHT.nativeInt) { Loading tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +24 −20 Original line number Diff line number Diff line Loading @@ -569,29 +569,30 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_measureText(Paint thisPaint, char[] text, int index, int count) { int count, int bidiFlags) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { return 0; } return delegate.measureText(text, index, count); return delegate.measureText(text, index, count, bidiFlags); } @LayoutlibDelegate /*package*/ static float native_measureText(Paint thisPaint, String text, int start, int end) { return native_measureText(thisPaint, text.toCharArray(), start, end - start); /*package*/ static float native_measureText(Paint thisPaint, String text, int start, int end, int bidiFlags) { return native_measureText(thisPaint, text.toCharArray(), start, end - start, bidiFlags); } @LayoutlibDelegate /*package*/ static float native_measureText(Paint thisPaint, String text) { return native_measureText(thisPaint, text.toCharArray(), 0, text.length()); /*package*/ static float native_measureText(Paint thisPaint, String text, int bidiFlags) { return native_measureText(thisPaint, text.toCharArray(), 0, text.length(), bidiFlags); } @LayoutlibDelegate /*package*/ static int native_breakText(Paint thisPaint, char[] text, int index, int count, float maxWidth, float[] measuredWidth) { float maxWidth, int bidiFlags, float[] measuredWidth) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); Loading @@ -614,7 +615,7 @@ public class Paint_Delegate { } // measure from start to end float res = delegate.measureText(text, start, end - start + 1); float res = delegate.measureText(text, start, end - start + 1, bidiFlags); if (measuredWidth != null) { measuredWidth[measureIndex] = res; Loading @@ -634,9 +635,9 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static int native_breakText(Paint thisPaint, String text, boolean measureForwards, float maxWidth, float[] measuredWidth) { float maxWidth, int bidiFlags, float[] measuredWidth) { return native_breakText(thisPaint, text.toCharArray(), 0, text.length(), maxWidth, measuredWidth); bidiFlags, measuredWidth); } @LayoutlibDelegate Loading Loading @@ -921,7 +922,7 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static int native_getTextWidths(int native_object, char[] text, int index, int count, float[] widths) { int count, int bidiFlags, float[] widths) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { Loading Loading @@ -963,8 +964,9 @@ public class Paint_Delegate { @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); int end, int bidiFlags, float[] widths) { return native_getTextWidths(native_object, text.toCharArray(), start, end - start, bidiFlags, widths); } @LayoutlibDelegate Loading @@ -977,7 +979,7 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_getTextRunAdvances(int native_object, char[] text, int index, int count, int contextIndex, int contextCount, int flags, float[] advances, int advancesIndex, int reserved) { int flags, float[] advances, int advancesIndex) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { Loading Loading @@ -1021,14 +1023,14 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_getTextRunAdvances(int native_object, String text, int start, int end, int contextStart, int contextEnd, int flags, float[] advances, int advancesIndex, int reserved) { int flags, float[] advances, int advancesIndex) { // FIXME: support contextStart, contextEnd and direction flag int count = end - start; char[] buffer = TemporaryBuffer.obtain(count); TextUtils.getChars(text, start, end, buffer, 0); return native_getTextRunAdvances(native_object, buffer, 0, count, contextStart, contextEnd - contextStart, flags, advances, advancesIndex, reserved); contextEnd - contextStart, flags, advances, advancesIndex); } @LayoutlibDelegate Loading Loading @@ -1067,13 +1069,14 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static void nativeGetStringBounds(int nativePaint, String text, int start, int end, Rect bounds) { nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, bounds); int end, int bidiFlags, Rect bounds) { nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, bidiFlags, bounds); } @LayoutlibDelegate /*package*/ static void nativeGetCharArrayBounds(int nativePaint, char[] text, int index, int count, Rect bounds) { int count, int bidiFlags, Rect bounds) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(nativePaint); Loading Loading @@ -1182,7 +1185,8 @@ public class Paint_Delegate { } } /*package*/ float measureText(char[] text, int index, int count) { /*package*/ float measureText(char[] text, int index, int count, int bidiFlags) { // TODO: find out what bidiFlags actually does. // WARNING: the logic in this method is similar to Canvas_Delegate.native_drawText // Any change to this method should be reflected there as well Loading tools/layoutlib/bridge/src/android/os/Looper_Accessor.java +20 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package android.os; import java.lang.reflect.Field; /** * Class allowing access to package-protected methods/fields. */ Loading @@ -23,5 +25,23 @@ public class Looper_Accessor { 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); } } tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +1 −1 Original line number Diff line number Diff line Loading @@ -428,7 +428,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { // 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(); } } Loading Loading
tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +28 −1 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ public final class Bitmap_Delegate { private final Config mConfig; private BufferedImage mImage; private boolean mHasAlpha = true; private boolean mHasMipMap = false; // TODO: check the default. private int mGenerationId = 0; Loading Loading @@ -185,6 +186,10 @@ public final class Bitmap_Delegate { return mHasAlpha && mConfig != Config.RGB_565; } public boolean hasMipMap() { // TODO: check if more checks are required as in hasAlpha. return mHasMipMap; } /** * Update the generationId. * Loading Loading @@ -335,6 +340,17 @@ public final class Bitmap_Delegate { return delegate.mHasAlpha; } @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. Loading Loading @@ -468,6 +484,17 @@ public final class Bitmap_Delegate { delegate.mHasAlpha = hasAlpha; } @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); Loading
tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +11 −14 Original line number Diff line number Diff line Loading @@ -330,20 +330,19 @@ public final class Canvas_Delegate { } @LayoutlibDelegate /*package*/ static void native_setBitmap(int nativeCanvas, int bitmap) { /*package*/ static void copyNativeCanvasState(int srcCanvas, int dstCanvas) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { Canvas_Delegate srcCanvasDelegate = sManager.getDelegate(srcCanvas); if (srcCanvasDelegate == null) { return; } // get the delegate from the native int. Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap); if (bitmapDelegate == null) { Canvas_Delegate dstCanvasDelegate = sManager.getDelegate(dstCanvas); if (dstCanvasDelegate == null) { return; } canvasDelegate.setBitmap(bitmapDelegate); // TODO: actually copy the canvas state. } @LayoutlibDelegate Loading Loading @@ -572,16 +571,14 @@ public final class Canvas_Delegate { @LayoutlibDelegate /*package*/ static boolean native_quickReject(int nativeCanvas, RectF rect, int native_edgeType) { RectF rect) { // FIXME properly implement quickReject return false; } @LayoutlibDelegate /*package*/ static boolean native_quickReject(int nativeCanvas, int path, int native_edgeType) { int path) { // FIXME properly implement quickReject return false; } Loading @@ -589,8 +586,7 @@ public final class Canvas_Delegate { @LayoutlibDelegate /*package*/ static boolean native_quickReject(int nativeCanvas, float left, float top, float right, float bottom, int native_edgeType) { float right, float bottom) { // FIXME properly implement quickReject return false; } Loading Loading @@ -994,7 +990,8 @@ public final class Canvas_Delegate { float x = startX; float y = startY; if (paintDelegate.getTextAlign() != Paint.Align.LEFT.nativeInt) { float m = paintDelegate.measureText(text, index, count); // TODO: check the value of bidiFlags. float m = paintDelegate.measureText(text, index, count, 0); if (paintDelegate.getTextAlign() == Paint.Align.CENTER.nativeInt) { x -= m / 2; } else if (paintDelegate.getTextAlign() == Paint.Align.RIGHT.nativeInt) { Loading
tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +24 −20 Original line number Diff line number Diff line Loading @@ -569,29 +569,30 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_measureText(Paint thisPaint, char[] text, int index, int count) { int count, int bidiFlags) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { return 0; } return delegate.measureText(text, index, count); return delegate.measureText(text, index, count, bidiFlags); } @LayoutlibDelegate /*package*/ static float native_measureText(Paint thisPaint, String text, int start, int end) { return native_measureText(thisPaint, text.toCharArray(), start, end - start); /*package*/ static float native_measureText(Paint thisPaint, String text, int start, int end, int bidiFlags) { return native_measureText(thisPaint, text.toCharArray(), start, end - start, bidiFlags); } @LayoutlibDelegate /*package*/ static float native_measureText(Paint thisPaint, String text) { return native_measureText(thisPaint, text.toCharArray(), 0, text.length()); /*package*/ static float native_measureText(Paint thisPaint, String text, int bidiFlags) { return native_measureText(thisPaint, text.toCharArray(), 0, text.length(), bidiFlags); } @LayoutlibDelegate /*package*/ static int native_breakText(Paint thisPaint, char[] text, int index, int count, float maxWidth, float[] measuredWidth) { float maxWidth, int bidiFlags, float[] measuredWidth) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); Loading @@ -614,7 +615,7 @@ public class Paint_Delegate { } // measure from start to end float res = delegate.measureText(text, start, end - start + 1); float res = delegate.measureText(text, start, end - start + 1, bidiFlags); if (measuredWidth != null) { measuredWidth[measureIndex] = res; Loading @@ -634,9 +635,9 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static int native_breakText(Paint thisPaint, String text, boolean measureForwards, float maxWidth, float[] measuredWidth) { float maxWidth, int bidiFlags, float[] measuredWidth) { return native_breakText(thisPaint, text.toCharArray(), 0, text.length(), maxWidth, measuredWidth); bidiFlags, measuredWidth); } @LayoutlibDelegate Loading Loading @@ -921,7 +922,7 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static int native_getTextWidths(int native_object, char[] text, int index, int count, float[] widths) { int count, int bidiFlags, float[] widths) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { Loading Loading @@ -963,8 +964,9 @@ public class Paint_Delegate { @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); int end, int bidiFlags, float[] widths) { return native_getTextWidths(native_object, text.toCharArray(), start, end - start, bidiFlags, widths); } @LayoutlibDelegate Loading @@ -977,7 +979,7 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_getTextRunAdvances(int native_object, char[] text, int index, int count, int contextIndex, int contextCount, int flags, float[] advances, int advancesIndex, int reserved) { int flags, float[] advances, int advancesIndex) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { Loading Loading @@ -1021,14 +1023,14 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static float native_getTextRunAdvances(int native_object, String text, int start, int end, int contextStart, int contextEnd, int flags, float[] advances, int advancesIndex, int reserved) { int flags, float[] advances, int advancesIndex) { // FIXME: support contextStart, contextEnd and direction flag int count = end - start; char[] buffer = TemporaryBuffer.obtain(count); TextUtils.getChars(text, start, end, buffer, 0); return native_getTextRunAdvances(native_object, buffer, 0, count, contextStart, contextEnd - contextStart, flags, advances, advancesIndex, reserved); contextEnd - contextStart, flags, advances, advancesIndex); } @LayoutlibDelegate Loading Loading @@ -1067,13 +1069,14 @@ public class Paint_Delegate { @LayoutlibDelegate /*package*/ static void nativeGetStringBounds(int nativePaint, String text, int start, int end, Rect bounds) { nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, bounds); int end, int bidiFlags, Rect bounds) { nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, bidiFlags, bounds); } @LayoutlibDelegate /*package*/ static void nativeGetCharArrayBounds(int nativePaint, char[] text, int index, int count, Rect bounds) { int count, int bidiFlags, Rect bounds) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(nativePaint); Loading Loading @@ -1182,7 +1185,8 @@ public class Paint_Delegate { } } /*package*/ float measureText(char[] text, int index, int count) { /*package*/ float measureText(char[] text, int index, int count, int bidiFlags) { // TODO: find out what bidiFlags actually does. // WARNING: the logic in this method is similar to Canvas_Delegate.native_drawText // Any change to this method should be reflected there as well Loading
tools/layoutlib/bridge/src/android/os/Looper_Accessor.java +20 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package android.os; import java.lang.reflect.Field; /** * Class allowing access to package-protected methods/fields. */ Loading @@ -23,5 +25,23 @@ public class Looper_Accessor { 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); } }
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +1 −1 Original line number Diff line number Diff line Loading @@ -428,7 +428,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { // 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(); } } Loading