Search in sources :

Example 86 with LayoutlibDelegate

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

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)

Example 87 with LayoutlibDelegate

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

the class VectorDrawable_Delegate method nGetFullPathProperties.

@LayoutlibDelegate
static boolean nGetFullPathProperties(long pathPtr, byte[] propertiesData, int length) {
    VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
    ByteBuffer properties = ByteBuffer.wrap(propertiesData);
    properties.order(ByteOrder.nativeOrder());
    properties.putFloat(VFullPath_Delegate.STROKE_WIDTH_INDEX * 4, path.getStrokeWidth());
    properties.putInt(VFullPath_Delegate.STROKE_COLOR_INDEX * 4, path.getStrokeColor());
    properties.putFloat(VFullPath_Delegate.STROKE_ALPHA_INDEX * 4, path.getStrokeAlpha());
    properties.putInt(VFullPath_Delegate.FILL_COLOR_INDEX * 4, path.getFillColor());
    properties.putFloat(VFullPath_Delegate.FILL_ALPHA_INDEX * 4, path.getStrokeAlpha());
    properties.putFloat(VFullPath_Delegate.TRIM_PATH_START_INDEX * 4, path.getTrimPathStart());
    properties.putFloat(VFullPath_Delegate.TRIM_PATH_END_INDEX * 4, path.getTrimPathEnd());
    properties.putFloat(VFullPath_Delegate.TRIM_PATH_OFFSET_INDEX * 4, path.getTrimPathOffset());
    properties.putInt(VFullPath_Delegate.STROKE_LINE_CAP_INDEX * 4, path.getStrokeLineCap());
    properties.putInt(VFullPath_Delegate.STROKE_LINE_JOIN_INDEX * 4, path.getStrokeLineJoin());
    properties.putFloat(VFullPath_Delegate.STROKE_MITER_LIMIT_INDEX * 4, path.getStrokeMiterlimit());
    properties.putInt(VFullPath_Delegate.FILL_TYPE_INDEX * 4, path.getFillType());
    return true;
}
Also used : ByteBuffer(java.nio.ByteBuffer) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 88 with LayoutlibDelegate

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

the class VectorDrawable_Delegate method nGetGroupProperties.

@LayoutlibDelegate
static boolean nGetGroupProperties(long groupPtr, float[] propertiesData, int length) {
    VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
    FloatBuffer properties = FloatBuffer.wrap(propertiesData);
    properties.put(VGroup_Delegate.ROTATE_INDEX, group.getRotation());
    properties.put(VGroup_Delegate.PIVOT_X_INDEX, group.getPivotX());
    properties.put(VGroup_Delegate.PIVOT_Y_INDEX, group.getPivotY());
    properties.put(VGroup_Delegate.SCALE_X_INDEX, group.getScaleX());
    properties.put(VGroup_Delegate.SCALE_Y_INDEX, group.getScaleY());
    properties.put(VGroup_Delegate.TRANSLATE_X_INDEX, group.getTranslateX());
    properties.put(VGroup_Delegate.TRANSLATE_Y_INDEX, group.getTranslateY());
    return true;
}
Also used : FloatBuffer(java.nio.FloatBuffer) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 89 with LayoutlibDelegate

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

the class Matrix_Delegate method native_invert.

@LayoutlibDelegate
static /*package*/
boolean native_invert(long native_object, long inverse) {
    Matrix_Delegate d = sManager.getDelegate(native_object);
    if (d == null) {
        return false;
    }
    Matrix_Delegate inv_mtx = sManager.getDelegate(inverse);
    if (inv_mtx == null) {
        return false;
    }
    try {
        AffineTransform affineTransform = d.getAffineTransform();
        AffineTransform inverseTransform = affineTransform.createInverse();
        inv_mtx.mValues[0] = (float) inverseTransform.getScaleX();
        inv_mtx.mValues[1] = (float) inverseTransform.getShearX();
        inv_mtx.mValues[2] = (float) inverseTransform.getTranslateX();
        inv_mtx.mValues[3] = (float) inverseTransform.getScaleX();
        inv_mtx.mValues[4] = (float) inverseTransform.getShearY();
        inv_mtx.mValues[5] = (float) inverseTransform.getTranslateY();
        return true;
    } catch (NoninvertibleTransformException e) {
        return false;
    }
}
Also used : NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 90 with LayoutlibDelegate

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

the class Paint_Delegate method nGetFillPath.

@LayoutlibDelegate
static /*package*/
boolean nGetFillPath(long native_object, long src, long dst) {
    Paint_Delegate paint = sManager.getDelegate(native_object);
    if (paint == null) {
        return false;
    }
    Path_Delegate srcPath = Path_Delegate.getDelegate(src);
    if (srcPath == null) {
        return true;
    }
    Path_Delegate dstPath = Path_Delegate.getDelegate(dst);
    if (dstPath == null) {
        return true;
    }
    Stroke stroke = paint.getJavaStroke();
    Shape strokeShape = stroke.createStrokedShape(srcPath.getJavaShape());
    dstPath.setJavaShape(strokeShape);
    // FIXME figure out the return value?
    return true;
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) 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