Merge "Add fill type support to vector drawable" into nyc-dev
This commit is contained in:
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 ----
|
|
||||||
}
|
|
||||||
@@ -167,13 +167,13 @@ public final class Path_Delegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@LayoutlibDelegate
|
@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);
|
Path_Delegate pathDelegate = sManager.getDelegate(nPath);
|
||||||
if (pathDelegate == null) {
|
if (pathDelegate == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pathDelegate.mFillType = Path.sFillTypeArray[ft];
|
pathDelegate.setFillType(Path.sFillTypeArray[ft]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutlibDelegate
|
@LayoutlibDelegate
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 ----
|
|
||||||
}
|
|
||||||
@@ -178,6 +178,7 @@ public class VectorDrawable_Delegate {
|
|||||||
properties.putInt(VFullPath_Delegate.STROKE_LINE_JOIN_INDEX * 4, path.getStrokeLineJoin());
|
properties.putInt(VFullPath_Delegate.STROKE_LINE_JOIN_INDEX * 4, path.getStrokeLineJoin());
|
||||||
properties.putFloat(VFullPath_Delegate.STROKE_MITER_LIMIT_INDEX * 4,
|
properties.putFloat(VFullPath_Delegate.STROKE_MITER_LIMIT_INDEX * 4,
|
||||||
path.getStrokeMiterlimit());
|
path.getStrokeMiterlimit());
|
||||||
|
properties.putInt(VFullPath_Delegate.FILL_TYPE_INDEX * 4, path.getFillType());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -186,7 +187,7 @@ public class VectorDrawable_Delegate {
|
|||||||
static void nUpdateFullPathProperties(long pathPtr, float strokeWidth,
|
static void nUpdateFullPathProperties(long pathPtr, float strokeWidth,
|
||||||
int strokeColor, float strokeAlpha, int fillColor, float fillAlpha, float trimPathStart,
|
int strokeColor, float strokeAlpha, int fillColor, float fillAlpha, float trimPathStart,
|
||||||
float trimPathEnd, float trimPathOffset, float strokeMiterLimit, int strokeLineCap,
|
float trimPathEnd, float trimPathOffset, float strokeMiterLimit, int strokeLineCap,
|
||||||
int strokeLineJoin) {
|
int strokeLineJoin, int fillType) {
|
||||||
VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
|
VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
|
||||||
|
|
||||||
path.setStrokeWidth(strokeWidth);
|
path.setStrokeWidth(strokeWidth);
|
||||||
@@ -200,6 +201,7 @@ public class VectorDrawable_Delegate {
|
|||||||
path.setStrokeMiterlimit(strokeMiterLimit);
|
path.setStrokeMiterlimit(strokeMiterLimit);
|
||||||
path.setStrokeLineCap(strokeLineCap);
|
path.setStrokeLineCap(strokeLineCap);
|
||||||
path.setStrokeLineJoin(strokeLineJoin);
|
path.setStrokeLineJoin(strokeLineJoin);
|
||||||
|
path.setFillType(fillType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutlibDelegate
|
@LayoutlibDelegate
|
||||||
@@ -530,6 +532,7 @@ public class VectorDrawable_Delegate {
|
|||||||
private static final int STROKE_LINE_CAP_INDEX = 8;
|
private static final int STROKE_LINE_CAP_INDEX = 8;
|
||||||
private static final int STROKE_LINE_JOIN_INDEX = 9;
|
private static final int STROKE_LINE_JOIN_INDEX = 9;
|
||||||
private static final int STROKE_MITER_LIMIT_INDEX = 10;
|
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_BUTT = 0;
|
||||||
private static final int LINECAP_ROUND = 1;
|
private static final int LINECAP_ROUND = 1;
|
||||||
@@ -590,6 +593,8 @@ public class VectorDrawable_Delegate {
|
|||||||
Join mStrokeLineJoin = MITER;
|
Join mStrokeLineJoin = MITER;
|
||||||
float mStrokeMiterlimit = 4;
|
float mStrokeMiterlimit = 4;
|
||||||
|
|
||||||
|
int mFillType = 0; // WINDING(0) is the default value. See Path.FillType
|
||||||
|
|
||||||
private VFullPath_Delegate() {
|
private VFullPath_Delegate() {
|
||||||
// Empty constructor.
|
// Empty constructor.
|
||||||
}
|
}
|
||||||
@@ -612,6 +617,7 @@ public class VectorDrawable_Delegate {
|
|||||||
|
|
||||||
mStrokeGradient = copy.mStrokeGradient;
|
mStrokeGradient = copy.mStrokeGradient;
|
||||||
mFillGradient = copy.mFillGradient;
|
mFillGradient = copy.mFillGradient;
|
||||||
|
mFillType = copy.mFillType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStrokeLineCap() {
|
private int getStrokeLineCap() {
|
||||||
@@ -755,6 +761,14 @@ public class VectorDrawable_Delegate {
|
|||||||
private void setFillGradient(long gradientPtr) {
|
private void setFillGradient(long gradientPtr) {
|
||||||
mFillGradient = gradientPtr;
|
mFillGradient = gradientPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setFillType(int fillType) {
|
||||||
|
mFillType = fillType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getFillType() {
|
||||||
|
return mFillType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class VGroup_Delegate implements VNativeObject {
|
static class VGroup_Delegate implements VNativeObject {
|
||||||
@@ -1124,6 +1138,7 @@ public class VectorDrawable_Delegate {
|
|||||||
assert fillPaintDelegate != null;
|
assert fillPaintDelegate != null;
|
||||||
fillPaintDelegate.setColorFilter(filterPtr);
|
fillPaintDelegate.setColorFilter(filterPtr);
|
||||||
fillPaintDelegate.setShader(fullPath.mFillGradient);
|
fillPaintDelegate.setShader(fullPath.mFillGradient);
|
||||||
|
Path_Delegate.native_setFillType(mRenderPath.mNativePath, fullPath.mFillType);
|
||||||
Canvas_Delegate.native_drawPath(canvasPtr, mRenderPath.mNativePath, fillPaint
|
Canvas_Delegate.native_drawPath(canvasPtr, mRenderPath.mNativePath, fillPaint
|
||||||
.getNativeInstance());
|
.getNativeInstance());
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.8 KiB |
@@ -63,6 +63,25 @@
|
|||||||
android:fillColor="@color/gradient"
|
android:fillColor="@color/gradient"
|
||||||
android:pathData="M-20,-20 l0, 10 l10, 0 l0, -10 l-10,0 "
|
android:pathData="M-20,-20 l0, 10 l10, 0 l0, -10 l-10,0 "
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Draw squares with different fill types
|
||||||
|
-->
|
||||||
|
<path
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#AABBCC"
|
||||||
|
android:fillColor="#AAEFCC"
|
||||||
|
android:pathData="M-20,-40 l0, 10 l10, 0 l0, -10 l-10,0 m5,0 l0, 10 l10, 0 l0, -10 l-10,0"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<path
|
||||||
|
android:fillType="nonZero"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#AABBCC"
|
||||||
|
android:fillColor="#AAEFCC"
|
||||||
|
android:pathData="M0,-40 l0, 10 l10, 0 l0, -10 l-10,0 m5,0 l0, 10 l10, 0 l0, -10 l-10,0"
|
||||||
|
/>
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
</vector>
|
</vector>
|
||||||
@@ -256,7 +256,6 @@ public final class CreateInfo implements ICreateInfo {
|
|||||||
*/
|
*/
|
||||||
public final static String[] DELEGATE_CLASS_NATIVES = new String[] {
|
public final static String[] DELEGATE_CLASS_NATIVES = new String[] {
|
||||||
"android.animation.PropertyValuesHolder",
|
"android.animation.PropertyValuesHolder",
|
||||||
"android.graphics.AvoidXfermode",
|
|
||||||
"android.graphics.Bitmap",
|
"android.graphics.Bitmap",
|
||||||
"android.graphics.BitmapFactory",
|
"android.graphics.BitmapFactory",
|
||||||
"android.graphics.BitmapShader",
|
"android.graphics.BitmapShader",
|
||||||
@@ -284,7 +283,6 @@ public final class CreateInfo implements ICreateInfo {
|
|||||||
"android.graphics.PathDashPathEffect",
|
"android.graphics.PathDashPathEffect",
|
||||||
"android.graphics.PathEffect",
|
"android.graphics.PathEffect",
|
||||||
"android.graphics.PathMeasure",
|
"android.graphics.PathMeasure",
|
||||||
"android.graphics.PixelXorXfermode",
|
|
||||||
"android.graphics.PorterDuffColorFilter",
|
"android.graphics.PorterDuffColorFilter",
|
||||||
"android.graphics.PorterDuffXfermode",
|
"android.graphics.PorterDuffXfermode",
|
||||||
"android.graphics.RadialGradient",
|
"android.graphics.RadialGradient",
|
||||||
|
|||||||
Reference in New Issue
Block a user