FileDocCategorySizeDatePackage
PatternPathMotion.javaAPI DocAndroid 5.1 API5551Thu Mar 12 22:22:10 GMT 2015android.transition

PatternPathMotion

public class PatternPathMotion extends PathMotion
A PathMotion that takes a Path pattern and applies it to the separation between two points. The starting point of the Path will be moved to the origin and the end point will be scaled and rotated so that it matches with the target end point.

This may be used in XML as an element inside a transition.

{@code
<changeBounds>
<patternPathMotion android:patternPathData="M0 0 L0 100 L100 100"/>
</changeBounds>}

Fields Summary
private android.graphics.Path
mOriginalPatternPath
private final android.graphics.Path
mPatternPath
private final android.graphics.Matrix
mTempMatrix
Constructors Summary
public PatternPathMotion()
Constructs a PatternPathMotion with a straight-line pattern.


                
      
        mPatternPath.lineTo(1, 0);
        mOriginalPatternPath = mPatternPath;
    
public PatternPathMotion(android.content.Context context, android.util.AttributeSet attrs)

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternPathMotion);
        try {
            String pathData = a.getString(R.styleable.PatternPathMotion_patternPathData);
            if (pathData == null) {
                throw new RuntimeException("pathData must be supplied for patternPathMotion");
            }
            Path pattern = PathParser.createPathFromPathData(pathData);
            setPatternPath(pattern);
        } finally {
            a.recycle();
        }

    
public PatternPathMotion(android.graphics.Path patternPath)
Creates a PatternPathMotion with the Path defining a pattern of motion between two coordinates. The pattern will be translated, rotated, and scaled to fit between the start and end points. The pattern must not be empty and must have the end point differ from the start point.

param
patternPath A Path to be used as a pattern for two-dimensional motion.

        setPatternPath(patternPath);
    
Methods Summary
private static floatdistance(float x, float y)

        return FloatMath.sqrt((x * x) + (y * y));
    
public android.graphics.PathgetPath(float startX, float startY, float endX, float endY)

        float dx = endX - startX;
        float dy = endY - startY;
        float length = distance(dx, dy);
        double angle = Math.atan2(dy, dx);

        mTempMatrix.setScale(length, length);
        mTempMatrix.postRotate((float) Math.toDegrees(angle));
        mTempMatrix.postTranslate(startX, startY);
        Path path = new Path();
        mPatternPath.transform(mTempMatrix, path);
        return path;
    
public android.graphics.PathgetPatternPath()
Returns the Path defining a pattern of motion between two coordinates. The pattern will be translated, rotated, and scaled to fit between the start and end points. The pattern must not be empty and must have the end point differ from the start point.

return
the Path defining a pattern of motion between two coordinates.
attr
ref android.R.styleable#PatternPathMotion_patternPathData

        return mOriginalPatternPath;
    
public voidsetPatternPath(android.graphics.Path patternPath)
Sets the Path defining a pattern of motion between two coordinates. The pattern will be translated, rotated, and scaled to fit between the start and end points. The pattern must not be empty and must have the end point differ from the start point.

param
patternPath A Path to be used as a pattern for two-dimensional motion.
attr
ref android.R.styleable#PatternPathMotion_patternPathData

        PathMeasure pathMeasure = new PathMeasure(patternPath, false);
        float length = pathMeasure.getLength();
        float[] pos = new float[2];
        pathMeasure.getPosTan(length, pos, null);
        float endX = pos[0];
        float endY = pos[1];
        pathMeasure.getPosTan(0, pos, null);
        float startX = pos[0];
        float startY = pos[1];

        if (startX == endX && startY == endY) {
            throw new IllegalArgumentException("pattern must not end at the starting point");
        }

        mTempMatrix.setTranslate(-startX, -startY);
        float dx = endX - startX;
        float dy = endY - startY;
        float distance = distance(dx, dy);
        float scale = 1 / distance;
        mTempMatrix.postScale(scale, scale);
        double angle = Math.atan2(dy, dx);
        mTempMatrix.postRotate((float) Math.toDegrees(-angle));
        patternPath.transform(mTempMatrix, mPatternPath);
        mOriginalPatternPath = patternPath;