Search in sources :

Example 76 with LayoutlibDelegate

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

the class Canvas_Delegate method nativeDrawBitmapMatrix.

@LayoutlibDelegate
public static void nativeDrawBitmapMatrix(long nCanvas, Bitmap bitmap, long nMatrix, long nPaint) {
    // get the delegate from the native int.
    Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
    if (canvasDelegate == null) {
        return;
    }
    // get the delegate from the native int, which can be null
    Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nPaint);
    // get the delegate from the native int.
    Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
    if (bitmapDelegate == null) {
        return;
    }
    final BufferedImage image = getImageToDraw(bitmapDelegate, paintDelegate, sBoolOut);
    Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix);
    if (matrixDelegate == null) {
        return;
    }
    final AffineTransform mtx = matrixDelegate.getAffineTransform();
    canvasDelegate.getSnapshot().draw(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);
            }
            //FIXME add support for canvas, screen and bitmap densities.
            graphics.drawImage(image, mtx, null);
        }
    }, paintDelegate, true, /*compositeOnly*/
    false);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 77 with LayoutlibDelegate

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

the class Region_Delegate method nativeOp.

@LayoutlibDelegate
static /*package*/
boolean nativeOp(long native_dst, int left, int top, int right, int bottom, int op) {
    Region_Delegate region = sManager.getDelegate(native_dst);
    if (region == null) {
        return false;
    }
    region.mArea = combineShapes(region.mArea, new Rectangle2D.Float(left, top, right - left, bottom - top), 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 78 with LayoutlibDelegate

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

the class Region_Delegate method nativeGetBounds.

@LayoutlibDelegate
static /*package*/
boolean nativeGetBounds(long native_region, Rect rect) {
    Region_Delegate region = sManager.getDelegate(native_region);
    if (region == null) {
        return true;
    }
    Rectangle bounds = region.mArea.getBounds();
    if (bounds.isEmpty()) {
        rect.left = rect.top = rect.right = rect.bottom = 0;
        return false;
    }
    rect.left = bounds.x;
    rect.top = bounds.y;
    rect.right = bounds.x + bounds.width;
    rect.bottom = bounds.y + bounds.height;
    return true;
}
Also used : Rectangle(java.awt.Rectangle) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 79 with LayoutlibDelegate

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

the class StaticLayout_Delegate method nComputeLineBreaks.

@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
    Builder builder = sBuilderManager.getDelegate(nativeBuilder);
    if (builder == null) {
        return 0;
    }
    // compute all possible breakpoints.
    int length = builder.mWidths.length;
    BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
    it.setText(new Segment(builder.mText, 0, length));
    // average word length in english is 5. So, initialize the possible breaks with a guess.
    List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
    int loc;
    it.first();
    while ((loc = it.next()) != BreakIterator.DONE) {
        breaks.add(loc);
    }
    List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
    switch(builder.mBreakStrategy) {
        case Layout.BREAK_STRATEGY_SIMPLE:
            builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        case Layout.BREAK_STRATEGY_HIGH_QUALITY:
        //                break;
        case Layout.BREAK_STRATEGY_BALANCED:
            builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        default:
            throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
    }
    builder.mLineBreaker.computeBreaks(recycle);
    return recycle.breaks.length;
}
Also used : ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Segment(javax.swing.text.Segment) BreakIterator(android.icu.text.BreakIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 80 with LayoutlibDelegate

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

the class PathParser_Delegate method nCreatePathFromPathData.

@LayoutlibDelegate
static /*package*/
void nCreatePathFromPathData(long outPathPtr, long pathData) {
    Path_Delegate path_delegate = Path_Delegate.getDelegate(outPathPtr);
    PathParser_Delegate source = sManager.getDelegate(outPathPtr);
    if (source == null || path_delegate == null) {
        return;
    }
    PathDataNode.nodesToPath(source.mPathDataNodes, path_delegate);
}
Also used : Path_Delegate(android.graphics.Path_Delegate) 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