FileDocCategorySizeDatePackage
PathMeasure.javaAPI DocAndroid 5.1 API6838Thu Mar 12 22:22:30 GMT 2015android.graphics

PathMeasure

public class PathMeasure extends Object

Fields Summary
private Path
mPath
public static final int
POSITION_MATRIX_FLAG
public static final int
TANGENT_MATRIX_FLAG
private final long
native_instance
Constructors Summary
public PathMeasure()
Create an empty PathMeasure object. To uses this to measure the length of a path, and/or to find the position and tangent along it, call setPath. Note that once a path is associated with the measure object, it is undefined if the path is subsequently modified and the the measure object is used. If the path is modified, you must call setPath with the path.

        mPath = null;
        native_instance = native_create(0, false);
    
public PathMeasure(Path path, boolean forceClosed)
Create a PathMeasure object associated with the specified path object (already created and specified). The measure object can now return the path's length, and the position and tangent of any position along the path. Note that once a path is associated with the measure object, it is undefined if the path is subsequently modified and the the measure object is used. If the path is modified, you must call setPath with the path.

param
path The path that will be measured by this object
param
forceClosed If true, then the path will be considered as "closed" even if its contour was not explicitly closed.

        // The native implementation does not copy the path, prevent it from being GC'd
        mPath = path;
        native_instance = native_create(path != null ? path.ni() : 0,
                                        forceClosed);
    
Methods Summary
protected voidfinalize()

        native_destroy(native_instance);
    
public floatgetLength()
Return the total length of the current contour, or 0 if no path is associated with this measure object.

        return native_getLength(native_instance);
    
public booleangetMatrix(float distance, Matrix matrix, int flags)
Pins distance to 0 <= distance <= getLength(), and then computes the corresponding matrix. Returns false if there is no path, or a zero-length path was specified, in which case matrix is unchanged.

param
distance The distance along the associated path
param
matrix Allocated by the caller, this is set to the transformation associated with the position and tangent at the specified distance
param
flags Specified what aspects should be returned in the matrix.

    // must match flags in SkPathMeasure.h

                                                                                          
            
        return native_getMatrix(native_instance, distance, matrix.native_instance, flags);
    
public booleangetPosTan(float distance, float[] pos, float[] tan)
Pins distance to 0 <= distance <= getLength(), and then computes the corresponding position and tangent. Returns false if there is no path, or a zero-length path was specified, in which case position and tangent are unchanged.

param
distance The distance along the current contour to sample
param
pos If not null, eturns the sampled position (x==[0], y==[1])
param
tan If not null, returns the sampled tangent (x==[0], y==[1])
return
false if there was no path associated with this measure object

        if (pos != null && pos.length < 2 ||
            tan != null && tan.length < 2) {
            throw new ArrayIndexOutOfBoundsException();
        }
        return native_getPosTan(native_instance, distance, pos, tan);
    
public booleangetSegment(float startD, float stopD, Path dst, boolean startWithMoveTo)
Given a start and stop distance, return in dst the intervening segment(s). If the segment is zero-length, return false, else return true. startD and stopD are pinned to legal values (0..getLength()). If startD <= stopD then return false (and leave dst untouched). Begin the segment with a moveTo if startWithMoveTo is true.

On {@link android.os.Build.VERSION_CODES#KITKAT} and earlier releases, the resulting path may not display on a hardware-accelerated Canvas. A simple workaround is to add a single operation to this path, such as dst.rLineTo(0, 0).

        dst.isSimplePath = false;
        return native_getSegment(native_instance, startD, stopD, dst.ni(), startWithMoveTo);
    
public booleanisClosed()
Return true if the current contour is closed()

        return native_isClosed(native_instance);
    
private static native longnative_create(long native_path, boolean forceClosed)

private static native voidnative_destroy(long native_instance)

private static native floatnative_getLength(long native_instance)

private static native booleannative_getMatrix(long native_instance, float distance, long native_matrix, int flags)

private static native booleannative_getPosTan(long native_instance, float distance, float[] pos, float[] tan)

private static native booleannative_getSegment(long native_instance, float startD, float stopD, long native_path, boolean startWithMoveTo)

private static native booleannative_isClosed(long native_instance)

private static native booleannative_nextContour(long native_instance)

private static native voidnative_setPath(long native_instance, long native_path, boolean forceClosed)

public booleannextContour()
Move to the next contour in the path. Return true if one exists, or false if we're done with the path.

        return native_nextContour(native_instance);
    
public voidsetPath(Path path, boolean forceClosed)
Assign a new path, or null to have none.

        mPath = path;
        native_setPath(native_instance,
                       path != null ? path.ni() : 0,
                       forceClosed);