List of usage examples for android.support.v4.graphics PathParser createPathFromPathData
public static Path createPathFromPathData(String pathData)
From source file:android.support.transition.PatternPathMotion.java
public PatternPathMotion(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, Styleable.PATTERN_PATH_MOTION); try {//from w w w .jav a 2 s.c o m String pathData = TypedArrayUtils.getNamedString(a, (XmlPullParser) attrs, "patternPathData", Styleable.PatternPathMotion.PATTERN_PATH_DATA); if (pathData == null) { throw new RuntimeException("pathData must be supplied for patternPathMotion"); } Path pattern = PathParser.createPathFromPathData(pathData); setPatternPath(pattern); } finally { a.recycle(); } }
From source file:android.support.graphics.drawable.PathInterpolatorCompat.java
private void parseInterpolatorFromTypeArray(TypedArray a, XmlPullParser parser) { // If there is pathData defined in the xml file, then the controls points // will be all coming from pathData. if (TypedArrayUtils.hasAttribute(parser, "pathData")) { String pathData = TypedArrayUtils.getNamedString(a, parser, "pathData", AndroidResources.STYLEABLE_PATH_INTERPOLATOR_PATH_DATA); Path path = PathParser.createPathFromPathData(pathData); if (path == null) { throw new InflateException("The path is null, which is created" + " from " + pathData); }//w w w . ja va 2 s.c o m initPath(path); } else { if (!TypedArrayUtils.hasAttribute(parser, "controlX1")) { throw new InflateException("pathInterpolator requires the controlX1 attribute"); } else if (!TypedArrayUtils.hasAttribute(parser, "controlY1")) { throw new InflateException("pathInterpolator requires the controlY1 attribute"); } float x1 = TypedArrayUtils.getNamedFloat(a, parser, "controlX1", AndroidResources.STYLEABLE_PATH_INTERPOLATOR_CONTROL_X_1, 0); float y1 = TypedArrayUtils.getNamedFloat(a, parser, "controlY1", AndroidResources.STYLEABLE_PATH_INTERPOLATOR_CONTROL_Y_1, 0); boolean hasX2 = TypedArrayUtils.hasAttribute(parser, "controlX2"); boolean hasY2 = TypedArrayUtils.hasAttribute(parser, "controlY2"); if (hasX2 != hasY2) { throw new InflateException( "pathInterpolator requires both controlX2 and" + " controlY2 for cubic Beziers."); } if (!hasX2) { initQuad(x1, y1); } else { float x2 = TypedArrayUtils.getNamedFloat(a, parser, "controlX2", AndroidResources.STYLEABLE_PATH_INTERPOLATOR_CONTROL_X_2, 0); float y2 = TypedArrayUtils.getNamedFloat(a, parser, "controlY2", AndroidResources.STYLEABLE_PATH_INTERPOLATOR_CONTROL_Y_2, 0); initCubic(x1, y1, x2, y2); } } }
From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java
/** * Setup ObjectAnimator's property or values from pathData. * * @param anim The target Animator which will be updated. * @param arrayObjectAnimator TypedArray for the ObjectAnimator. * @param pixelSize The relative pixel size, used to calculate the *///from w w w . ja v a 2s.c om private static void setupObjectAnimator(ValueAnimator anim, TypedArray arrayObjectAnimator, int valueType, float pixelSize, XmlPullParser parser) { ObjectAnimator oa = (ObjectAnimator) anim; String pathData = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "pathData", AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PATH_DATA); // Path can be involved in an ObjectAnimator in the following 3 ways: // 1) Path morphing: the property to be animated is pathData, and valueFrom and valueTo // are both of pathType. valueType = pathType needs to be explicitly defined. // 2) A property in X or Y dimension can be animated along a path: the property needs to be // defined in propertyXName or propertyYName attribute, the path will be defined in the // pathData attribute. valueFrom and valueTo will not be necessary for this animation. // 3) PathInterpolator can also define a path (in pathData) for its interpolation curve. // Here we are dealing with case 2: if (pathData != null) { String propertyXName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyXName", AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_X_NAME); String propertyYName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyYName", AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_Y_NAME); if (valueType == VALUE_TYPE_PATH || valueType == VALUE_TYPE_UNDEFINED) { // When pathData is defined, we are in case #2 mentioned above. ValueType can only // be float type, or int type. Otherwise we fallback to default type. valueType = VALUE_TYPE_FLOAT; } if (propertyXName == null && propertyYName == null) { throw new InflateException(arrayObjectAnimator.getPositionDescription() + " propertyXName or propertyYName is needed for PathData"); } else { Path path = PathParser.createPathFromPathData(pathData); setupPathMotion(path, oa, 0.5f * pixelSize, propertyXName, propertyYName); } } else { String propertyName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyName", AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_NAME); oa.setPropertyName(propertyName); } return; }