Search in sources :

Example 91 with LayoutlibDelegate

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

the class PathMeasure_Delegate method native_isClosed.

@LayoutlibDelegate
static /*package*/
boolean native_isClosed(long native_instance) {
    PathMeasure_Delegate pathMeasure = sManager.getDelegate(native_instance);
    assert pathMeasure != null;
    Path_Delegate path = Path_Delegate.getDelegate(pathMeasure.mNativePath);
    if (path == null) {
        return false;
    }
    int type = 0;
    float[] segment = new float[6];
    for (PathIterator pi = path.getJavaShape().getPathIterator(null); !pi.isDone(); pi.next()) {
        type = pi.currentSegment(segment);
    }
    // A path is a closed path if the last element is SEG_CLOSE
    return type == PathIterator.SEG_CLOSE;
}
Also used : CachedPathIterator(com.android.layoutlib.bridge.util.CachedPathIteratorFactory.CachedPathIterator) PathIterator(java.awt.geom.PathIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 92 with LayoutlibDelegate

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

the class PathMeasure_Delegate method native_getSegment.

@LayoutlibDelegate
static /*package*/
boolean native_getSegment(long native_instance, float startD, float stopD, long native_dst_path, boolean startWithMoveTo) {
    if (startD < 0) {
        startD = 0;
    }
    if (startD >= stopD) {
        return false;
    }
    PathMeasure_Delegate pathMeasure = sManager.getDelegate(native_instance);
    assert pathMeasure != null;
    CachedPathIterator iterator = pathMeasure.mOriginalPathIterator.iterator();
    float accLength = startD;
    // Whether the output has zero length or not
    boolean isZeroLength = true;
    float[] points = new float[6];
    iterator.jumpToSegment(accLength);
    while (!iterator.isDone() && (stopD - accLength > 0.1f)) {
        int type = iterator.currentSegment(points, stopD - accLength);
        if (accLength - iterator.getCurrentSegmentLength() <= stopD) {
            if (startWithMoveTo) {
                startWithMoveTo = false;
                // a first moveto
                if (type != PathIterator.SEG_MOVETO) {
                    float[] lastPoint = new float[2];
                    iterator.getCurrentSegmentEnd(lastPoint);
                    Path_Delegate.native_moveTo(native_dst_path, lastPoint[0], lastPoint[1]);
                }
            }
            isZeroLength = isZeroLength && iterator.getCurrentSegmentLength() > 0;
            switch(type) {
                case PathIterator.SEG_MOVETO:
                    Path_Delegate.native_moveTo(native_dst_path, points[0], points[1]);
                    break;
                case PathIterator.SEG_LINETO:
                    Path_Delegate.native_lineTo(native_dst_path, points[0], points[1]);
                    break;
                case PathIterator.SEG_CLOSE:
                    Path_Delegate.native_close(native_dst_path);
                    break;
                case PathIterator.SEG_CUBICTO:
                    Path_Delegate.native_cubicTo(native_dst_path, points[0], points[1], points[2], points[3], points[4], points[5]);
                    break;
                case PathIterator.SEG_QUADTO:
                    Path_Delegate.native_quadTo(native_dst_path, points[0], points[1], points[2], points[3]);
                    break;
                default:
                    assert false;
            }
        }
        accLength += iterator.getCurrentSegmentLength();
        iterator.next();
    }
    return !isZeroLength;
}
Also used : CachedPathIterator(com.android.layoutlib.bridge.util.CachedPathIteratorFactory.CachedPathIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 93 with LayoutlibDelegate

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

the class Resources_Delegate method getTextArray.

@LayoutlibDelegate
static CharSequence[] getTextArray(Resources resources, int id) throws NotFoundException {
    ResourceValue resValue = getArrayResourceValue(resources, id);
    if (resValue == null) {
        // Error already logged by getArrayResourceValue.
        return new CharSequence[0];
    } else if (!(resValue instanceof ArrayResourceValue)) {
        return new CharSequence[] { resolveReference(resources, resValue.getValue(), resValue.isFramework()) };
    }
    ArrayResourceValue arv = ((ArrayResourceValue) resValue);
    return fillValues(resources, arv, new CharSequence[arv.getElementCount()]);
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 94 with LayoutlibDelegate

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

the class Resources_Delegate method getInteger.

@LayoutlibDelegate
static int getInteger(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
    if (value != null) {
        ResourceValue resValue = value.getSecond();
        assert resValue != null;
        if (resValue != null) {
            String v = resValue.getValue();
            if (v != null) {
                try {
                    return getInt(v);
                } catch (NumberFormatException e) {
                // return exception below
                }
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(resources, id);
    // this is not used since the method above always throws
    return 0;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 95 with LayoutlibDelegate

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

the class Resources_Delegate method getStringArray.

@LayoutlibDelegate
static String[] getStringArray(Resources resources, int id) throws NotFoundException {
    ResourceValue resValue = getArrayResourceValue(resources, id);
    if (resValue == null) {
        // Error already logged by getArrayResourceValue.
        return new String[0];
    } else if (!(resValue instanceof ArrayResourceValue)) {
        return new String[] { resolveReference(resources, resValue.getValue(), resValue.isFramework()) };
    }
    ArrayResourceValue arv = ((ArrayResourceValue) resValue);
    return fillValues(resources, arv, new String[arv.getElementCount()]);
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) 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