Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1084cc0 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Add missing native methods. [DO NOT MERGE]

Also contains fixes for native methods specific to the branch.

Change-Id: I7b34e2ec0164520efc658053a80f307791a992b1
(cherry-picked from commit: 279c00e8)
parent 02bc4b04
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -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;


@@ -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.
     *
@@ -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.
@@ -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);
+10 −19
Original line number Diff line number Diff line
@@ -330,21 +330,13 @@ public final class Canvas_Delegate {
    }

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

        // get the delegate from the native int.
        Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
        if (bitmapDelegate == 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);
        }
    }

    @LayoutlibDelegate
    /*package*/ static int native_saveLayer(int nativeCanvas, RectF bounds,
@@ -571,16 +563,14 @@ public final class Canvas_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static boolean native_quickReject(int nativeCanvas,
                                                     RectF rect,
    /*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,
    /*package*/ static boolean native_quickReject(int nativeCanvas, int path,
            int native_edgeType) {
        // FIXME properly implement quickReject
        return false;
@@ -994,6 +984,7 @@ public final class Canvas_Delegate {
                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;
+4 −2
Original line number Diff line number Diff line
@@ -964,7 +964,8 @@ 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);
        return native_getTextWidths(native_object, text.toCharArray(), start, end - start,
                widths);
    }

    @LayoutlibDelegate
@@ -1068,7 +1069,8 @@ 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);
        nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start,
                bounds);
    }

    @LayoutlibDelegate
+20 −0
Original line number Diff line number Diff line
@@ -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 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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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();
        }
    }