use of android.graphics.PathMeasure in project android_frameworks_base by AOSPA.
the class PatternPathMotion method setPatternPath.
/**
* 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
*/
public void setPatternPath(Path patternPath) {
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 = (float) Math.hypot(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;
}
use of android.graphics.PathMeasure in project android_frameworks_base by ResurrectionRemix.
the class PatternPathMotion method setPatternPath.
/**
* 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
*/
public void setPatternPath(Path patternPath) {
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 = (float) Math.hypot(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;
}
use of android.graphics.PathMeasure in project android_frameworks_base by crdroidandroid.
the class PatternPathMotion method setPatternPath.
/**
* 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
*/
public void setPatternPath(Path patternPath) {
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 = (float) Math.hypot(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;
}
Aggregations