Search in sources :

Example 66 with LayoutlibDelegate

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

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 67 with LayoutlibDelegate

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

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 68 with LayoutlibDelegate

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

the class AnimatedVectorDrawable_Delegate method nCreatePathPropertyHolder.

@LayoutlibDelegate
static /*package*/
long nCreatePathPropertyHolder(long nativePtr, int propertyId, float startValue, float endValue) {
    VFullPath_Delegate path = VNativeObject.getDelegate(nativePtr);
    Consumer<Float> setter = path.getFloatPropertySetter(propertyId);
    return sHolders.addNewDelegate(FloatPropertySetter.of(setter, startValue, endValue));
}
Also used : VFullPath_Delegate(android.graphics.drawable.VectorDrawable_Delegate.VFullPath_Delegate) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 69 with LayoutlibDelegate

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

the class AnimatedVectorDrawable_Delegate method nAddAnimator.

@LayoutlibDelegate
static /*package*/
void nAddAnimator(long setPtr, long propertyValuesHolder, long nativeInterpolator, long startDelay, long duration, int repeatCount) {
    PropertySetter holder = sHolders.getDelegate(propertyValuesHolder);
    if (holder == null || holder.getValues() == null) {
        return;
    }
    ObjectAnimator animator = new ObjectAnimator();
    animator.setValues(holder.getValues());
    animator.setInterpolator(NativeInterpolatorFactoryHelper_Delegate.getDelegate(nativeInterpolator));
    animator.setStartDelay(startDelay);
    animator.setDuration(duration);
    animator.setRepeatCount(repeatCount);
    animator.setTarget(holder);
    animator.setPropertyName(holder.getValues().getPropertyName());
    AnimatorSetHolder set = sAnimatorSets.getDelegate(setPtr);
    assert set != null;
    set.addAnimator(animator);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 70 with LayoutlibDelegate

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

the class GradientDrawable_Delegate method buildRing.

/**
     * The ring can be built either by drawing full circles, or by drawing arcs in case the
     * circle isn't complete. LayoutLib cannot handle drawing full circles (requires path
     * subtraction). So, if we need to draw full circles, we switch to drawing 99% circle.
     */
@LayoutlibDelegate
static /*package*/
Path buildRing(GradientDrawable thisDrawable, GradientState st) {
    boolean useLevel = st.mUseLevelForShape;
    int level = thisDrawable.getLevel();
    // 10000 is the max level. See android.graphics.drawable.Drawable#getLevel()
    float sweep = useLevel ? (360.0f * level / 10000.0f) : 360f;
    Field mLevel = null;
    if (sweep >= 360 || sweep <= -360) {
        st.mUseLevelForShape = true;
        // dirty again.
        try {
            mLevel = Drawable.class.getDeclaredField("mLevel");
            mLevel.setAccessible(true);
            // set to one less than max.
            mLevel.setInt(thisDrawable, 9999);
        } catch (NoSuchFieldException e) {
        // The field has been removed in a recent framework change. Fall back to old
        // buggy behaviour.
        } catch (IllegalAccessException e) {
            // We've already set the field to be accessible.
            assert false;
        }
    }
    Path path = thisDrawable.buildRing_Original(st);
    st.mUseLevelForShape = useLevel;
    if (mLevel != null) {
        try {
            mLevel.setInt(thisDrawable, level);
        } catch (IllegalAccessException e) {
            assert false;
        }
    }
    return path;
}
Also used : Path(android.graphics.Path) Field(java.lang.reflect.Field) 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