Search in sources :

Example 71 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.

the class Bitmap_Delegate method nativeCopy.

@LayoutlibDelegate
static /*package*/
Bitmap nativeCopy(long srcBitmap, int nativeConfig, boolean isMutable) {
    Bitmap_Delegate srcBmpDelegate = sManager.getDelegate(srcBitmap);
    if (srcBmpDelegate == null) {
        return null;
    }
    BufferedImage srcImage = srcBmpDelegate.getImage();
    int width = srcImage.getWidth();
    int height = srcImage.getHeight();
    int imageType = getBufferedImageType();
    // create the image
    BufferedImage image = new BufferedImage(width, height, imageType);
    // copy the source image into the image.
    int[] argb = new int[width * height];
    srcImage.getRGB(0, 0, width, height, argb, 0, width);
    image.setRGB(0, 0, width, height, argb, 0, width);
    // create a delegate with the content of the stream.
    Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.nativeToConfig(nativeConfig));
    return createBitmap(delegate, getPremultipliedBitmapCreateFlags(isMutable), Bitmap.getDefaultDensity());
}
Also used : BufferedImage(java.awt.image.BufferedImage) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 72 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.

the class Bitmap_Delegate method nativeCreate.

// ---- native methods ----
@LayoutlibDelegate
static /*package*/
Bitmap nativeCreate(int[] colors, int offset, int stride, int width, int height, int nativeConfig, boolean isMutable) {
    int imageType = getBufferedImageType();
    // create the image
    BufferedImage image = new BufferedImage(width, height, imageType);
    if (colors != null) {
        image.setRGB(0, 0, width, height, colors, offset, stride);
    }
    // create a delegate with the content of the stream.
    Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.nativeToConfig(nativeConfig));
    return createBitmap(delegate, getPremultipliedBitmapCreateFlags(isMutable), Bitmap.getDefaultDensity());
}
Also used : BufferedImage(java.awt.image.BufferedImage) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 73 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.

the class Canvas_Delegate method native_setMatrix.

@LayoutlibDelegate
public static void native_setMatrix(long nCanvas, long nMatrix) {
    // get the delegate from the native int.
    Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
    if (canvasDelegate == null) {
        return;
    }
    Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix);
    if (matrixDelegate == null) {
        return;
    }
    // get the current top graphics2D object.
    GcSnapshot snapshot = canvasDelegate.getSnapshot();
    // get the AffineTransform of the given matrix
    AffineTransform matrixTx = matrixDelegate.getAffineTransform();
    // give it to the graphics2D as a new matrix replacing all previous transform
    snapshot.setTransform(matrixTx);
    if (matrixDelegate.hasPerspective()) {
        assert false;
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Canvas#setMatrix(android.graphics.Matrix) only " + "supports affine transformations.", null, null);
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 74 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.

the class Preference_Delegate method getView.

@LayoutlibDelegate
static /*package*/
View getView(Preference pref, View convertView, ViewGroup parent) {
    Context context = pref.getContext();
    BridgeContext bc = context instanceof BridgeContext ? ((BridgeContext) context) : null;
    convertView = pref.getView_Original(convertView, parent);
    if (bc != null) {
        Object cookie = bc.getCookie(pref);
        if (cookie != null) {
            bc.addViewKey(convertView, cookie);
        }
    }
    return convertView;
}
Also used : Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 75 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.

the class Canvas_Delegate method native_drawBitmap.

@LayoutlibDelegate
public static void native_drawBitmap(long nativeCanvas, int[] colors, int offset, int stride, final float x, final float y, int width, int height, boolean hasAlpha, long nativePaintOrZero) {
    // create a temp BufferedImage containing the content.
    final BufferedImage image = new BufferedImage(width, height, hasAlpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
    image.setRGB(0, 0, width, height, colors, offset, stride);
    draw(nativeCanvas, nativePaintOrZero, true, /*compositeOnly*/
    false, /*forceSrcMode*/
    new GcSnapshot.Drawable() {

        @Override
        public void draw(Graphics2D graphics, Paint_Delegate paint) {
            if (paint != null && paint.isFilterBitmap()) {
                graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            }
            graphics.drawImage(image, (int) x, (int) y, null);
        }
    });
}
Also used : GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)334 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)56 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)56 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)56 BufferedImage (java.awt.image.BufferedImage)46 AffineTransform (java.awt.geom.AffineTransform)42 Area (java.awt.geom.Area)42 File (java.io.File)30 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)29 FileNotFoundException (java.io.FileNotFoundException)24 Graphics2D (java.awt.Graphics2D)19 TypedValue (android.util.TypedValue)17 NotFoundException (android.content.res.Resources.NotFoundException)16 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)16 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)16 ArrayList (java.util.ArrayList)16 XmlPullParser (org.xmlpull.v1.XmlPullParser)16 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)16 IOException (java.io.IOException)14 NinePatchInputStream (com.android.layoutlib.bridge.util.NinePatchInputStream)12