Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0fce3e9 authored by Diego Perez's avatar Diego Perez Committed by Android (Google) Code Review
Browse files

Merge "Add fill type support to vector drawable" into nyc-dev

parents b320eb92 5ceb30f2
Loading
Loading
Loading
Loading
+0 −70
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.graphics;

import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

import java.awt.Composite;

/**
 * Delegate implementing the native methods of android.graphics.AvoidXfermode
 *
 * Through the layoutlib_create tool, the original native methods of AvoidXfermode have been
 * replaced by calls to methods of the same name in this delegate class.
 *
 * This class behaves like the original native implementation, but in Java, keeping previously
 * native data into its own objects and mapping them to int that are sent back and forth between
 * it and the original AvoidXfermode class.
 *
 * Because this extends {@link Xfermode_Delegate}, there's no need to use a
 * {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
 * {@link Xfermode_Delegate}.
 *
 */
public class AvoidXfermode_Delegate extends Xfermode_Delegate {

    // ---- delegate data ----

    // ---- Public Helper methods ----

    @Override
    public Composite getComposite(int alpha) {
        // FIXME
        return null;
    }

    @Override
    public boolean isSupported() {
        return false;
    }

    @Override
    public String getSupportMessage() {
        return "Avoid Xfermodes are not supported in Layout Preview mode.";
    }

    // ---- native methods ----

    @LayoutlibDelegate
    /*package*/ static long nativeCreate(int opColor, int tolerance, int nativeMode) {
        AvoidXfermode_Delegate newDelegate = new AvoidXfermode_Delegate();
        return sManager.addNewDelegate(newDelegate);
    }

    // ---- Private delegate/helper methods ----
}
+2 −2
Original line number Diff line number Diff line
@@ -167,13 +167,13 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_setFillType(long nPath, int ft) {
    public static void native_setFillType(long nPath, int ft) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
        }

        pathDelegate.mFillType = Path.sFillTypeArray[ft];
        pathDelegate.setFillType(Path.sFillTypeArray[ft]);
    }

    @LayoutlibDelegate
+0 −70
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.graphics;

import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

import java.awt.Composite;

/**
 * Delegate implementing the native methods of android.graphics.PixelXorXfermode
 *
 * Through the layoutlib_create tool, the original native methods of PixelXorXfermode have been
 * replaced by calls to methods of the same name in this delegate class.
 *
 * This class behaves like the original native implementation, but in Java, keeping previously
 * native data into its own objects and mapping them to int that are sent back and forth between
 * it and the original PixelXorXfermode class.
 *
 * Because this extends {@link Xfermode_Delegate}, there's no need to use a
 * {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
 * {@link Xfermode_Delegate}.
 *
 * @see Xfermode_Delegate
 */
public class PixelXorXfermode_Delegate extends Xfermode_Delegate {
    // ---- delegate data ----

    // ---- Public Helper methods ----

    @Override
    public Composite getComposite(int alpha) {
        // FIXME
        return null;
    }

    @Override
    public boolean isSupported() {
        return false;
    }

    @Override
    public String getSupportMessage() {
        return "Pixel XOR Xfermodes are not supported in Layout Preview mode.";
    }

    // ---- native methods ----

    @LayoutlibDelegate
    /*package*/ static long nativeCreate(int opColor) {
        PixelXorXfermode_Delegate newDelegate = new PixelXorXfermode_Delegate();
        return sManager.addNewDelegate(newDelegate);
    }

    // ---- Private delegate/helper methods ----
}
+16 −1
Original line number Diff line number Diff line
@@ -178,6 +178,7 @@ public class VectorDrawable_Delegate {
        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;
    }
@@ -186,7 +187,7 @@ public class VectorDrawable_Delegate {
    static void nUpdateFullPathProperties(long pathPtr, float strokeWidth,
            int strokeColor, float strokeAlpha, int fillColor, float fillAlpha, float trimPathStart,
            float trimPathEnd, float trimPathOffset, float strokeMiterLimit, int strokeLineCap,
            int strokeLineJoin) {
            int strokeLineJoin, int fillType) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);

        path.setStrokeWidth(strokeWidth);
@@ -200,6 +201,7 @@ public class VectorDrawable_Delegate {
        path.setStrokeMiterlimit(strokeMiterLimit);
        path.setStrokeLineCap(strokeLineCap);
        path.setStrokeLineJoin(strokeLineJoin);
        path.setFillType(fillType);
    }

    @LayoutlibDelegate
@@ -530,6 +532,7 @@ public class VectorDrawable_Delegate {
        private static final int STROKE_LINE_CAP_INDEX = 8;
        private static final int STROKE_LINE_JOIN_INDEX = 9;
        private static final int STROKE_MITER_LIMIT_INDEX = 10;
        private static final int FILL_TYPE_INDEX = 11;

        private static final int LINECAP_BUTT = 0;
        private static final int LINECAP_ROUND = 1;
@@ -590,6 +593,8 @@ public class VectorDrawable_Delegate {
        Join mStrokeLineJoin = MITER;
        float mStrokeMiterlimit = 4;

        int mFillType = 0; // WINDING(0) is the default value. See Path.FillType

        private VFullPath_Delegate() {
            // Empty constructor.
        }
@@ -612,6 +617,7 @@ public class VectorDrawable_Delegate {

            mStrokeGradient = copy.mStrokeGradient;
            mFillGradient = copy.mFillGradient;
            mFillType = copy.mFillType;
        }

        private int getStrokeLineCap() {
@@ -755,6 +761,14 @@ public class VectorDrawable_Delegate {
        private void setFillGradient(long gradientPtr) {
            mFillGradient = gradientPtr;
        }

        private void setFillType(int fillType) {
            mFillType = fillType;
        }

        private int getFillType() {
            return mFillType;
        }
    }

    static class VGroup_Delegate implements VNativeObject {
@@ -1124,6 +1138,7 @@ public class VectorDrawable_Delegate {
                    assert fillPaintDelegate != null;
                    fillPaintDelegate.setColorFilter(filterPtr);
                    fillPaintDelegate.setShader(fullPath.mFillGradient);
                    Path_Delegate.native_setFillType(mRenderPath.mNativePath, fullPath.mFillType);
                    Canvas_Delegate.native_drawPath(canvasPtr, mRenderPath.mNativePath, fillPaint
                            .getNativeInstance());
                }
+311 B (5.83 KiB)
Loading image diff...
Loading