Search in sources :

Example 51 with LayoutlibDelegate

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

the class ViewGroup_Delegate method drawChild.

/**
     * Overrides the original drawChild call in ViewGroup to draw the shadow.
     */
@LayoutlibDelegate
static /*package*/
boolean drawChild(ViewGroup thisVG, Canvas canvas, View child, long drawingTime) {
    if (child.getZ() > thisVG.getZ()) {
        // The background's bounds are set lazily. Make sure they are set correctly so that
        // the outline obtained is correct.
        child.setBackgroundBounds();
        ViewOutlineProvider outlineProvider = child.getOutlineProvider();
        if (outlineProvider != null) {
            Outline outline = child.mAttachInfo.mTmpOutline;
            outlineProvider.getOutline(child, outline);
            if (outline.mPath != null || (outline.mRect != null && !outline.mRect.isEmpty())) {
                int restoreTo = transformCanvas(thisVG, canvas, child);
                drawShadow(thisVG, canvas, child, outline);
                canvas.restoreToCount(restoreTo);
            }
        }
    }
    return thisVG.drawChild_Original(canvas, child, drawingTime);
}
Also used : Outline(android.graphics.Outline) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 52 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 53 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)

Example 54 with LayoutlibDelegate

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

the class PathParser_Delegate method nParseStringForPath.

@LayoutlibDelegate
static /*package*/
void nParseStringForPath(long pathPtr, @NonNull String pathString, int stringLength) {
    Path_Delegate path_delegate = Path_Delegate.getDelegate(pathPtr);
    if (path_delegate == null) {
        return;
    }
    assert pathString.length() == stringLength;
    PathDataNode.nodesToPath(createNodesFromPathData(pathString), path_delegate);
}
Also used : Path_Delegate(android.graphics.Path_Delegate) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 55 with LayoutlibDelegate

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

the class Region_Delegate method nativeSetPath.

@LayoutlibDelegate
static /*package*/
boolean nativeSetPath(long native_dst, long native_path, long 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