Search in sources :

Example 36 with LayoutlibDelegate

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

the class Bitmap_Delegate method nativeCopy.

@LayoutlibDelegate
static /*package*/
Bitmap nativeCopy(int 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(nativeConfig);
    // 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, isMutable, Bitmap.getDefaultDensity());
}
Also used : BufferedImage(java.awt.image.BufferedImage) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 37 with LayoutlibDelegate

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

the class Paint_Delegate method nativeGetCharArrayBounds.

@LayoutlibDelegate
static /*package*/
void nativeGetCharArrayBounds(int nativePaint, char[] text, int index, int count, int bidiFlags, Rect bounds) {
    // get the delegate from the native int.
    Paint_Delegate delegate = sManager.getDelegate(nativePaint);
    if (delegate == null) {
        return;
    }
    // See MeasureText
    if (delegate.mFonts.size() > 0) {
        FontInfo mainInfo = delegate.mFonts.get(0);
        Rectangle2D rect = mainInfo.mFont.getStringBounds(text, index, index + count, delegate.mFontContext);
        bounds.set(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 38 with LayoutlibDelegate

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

the class Region_Delegate method nativeOp.

@LayoutlibDelegate
static /*package*/
boolean nativeOp(int native_dst, Rect rect, int native_region, int op) {
    Region_Delegate region = sManager.getDelegate(native_dst);
    if (region == null) {
        return false;
    }
    region.mArea = combineShapes(region.mArea, new Rectangle2D.Float(rect.left, rect.top, rect.width(), rect.height()), op);
    assert region.mArea != null;
    if (region.mArea != null) {
        region.mArea = new Area();
    }
    return region.mArea.getBounds().isEmpty() == false;
}
Also used : Area(java.awt.geom.Area) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 39 with LayoutlibDelegate

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

the class Region_Delegate method scale.

@LayoutlibDelegate
static /*package*/
void scale(Region thisRegion, float scale, Region dst) {
    Region_Delegate regionDelegate = sManager.getDelegate(thisRegion.mNativeRegion);
    if (regionDelegate == null) {
        return;
    }
    Region_Delegate targetRegionDelegate = sManager.getDelegate(dst.mNativeRegion);
    if (targetRegionDelegate == null) {
        return;
    }
    if (regionDelegate.mArea.isEmpty()) {
        targetRegionDelegate.mArea = new Area();
    } else {
        targetRegionDelegate.mArea = new Area(regionDelegate.mArea);
        AffineTransform mtx = new AffineTransform();
        mtx.scale(scale, scale);
        targetRegionDelegate.mArea.transform(mtx);
    }
}
Also used : Area(java.awt.geom.Area) AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 40 with LayoutlibDelegate

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

the class Region_Delegate method nativeSetPath.

@LayoutlibDelegate
static /*package*/
boolean nativeSetPath(int native_dst, int native_path, int native_clip) {
    Region_Delegate dstRegion = sManager.getDelegate(native_dst);
    if (dstRegion == null) {
        return true;
    }
    Path_Delegate path = Path_Delegate.getDelegate(native_path);
    if (path == null) {
        return true;
    }
    dstRegion.mArea = new Area(path.getJavaShape());
    Region_Delegate clip = sManager.getDelegate(native_clip);
    if (clip != null) {
        dstRegion.mArea.subtract(clip.getJavaArea());
    }
    return dstRegion.mArea.getBounds().isEmpty() == false;
}
Also used : Area(java.awt.geom.Area) 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