use of android.graphics.PathMeasure in project Timber by naman14.
the class CircularSeekBar method calculatePointerXYPosition.
private void calculatePointerXYPosition() {
PathMeasure pm = new PathMeasure(mCircleProgressPath, false);
boolean returnValue = pm.getPosTan(pm.getLength(), mPointerPositionXY, null);
if (!returnValue) {
pm = new PathMeasure(mCirclePath, false);
returnValue = pm.getPosTan(0, mPointerPositionXY, null);
}
}
use of android.graphics.PathMeasure in project MaterialCalendar by Haoxiqiang.
the class WeatherTemplateView method getPoints.
protected PathPoints[] getPoints(Path path, int size) {
//Size of 100 indicates that, 100 points
// would be extracted from the path
PathPoints[] pointArray = new PathPoints[size];
PathMeasure pm = new PathMeasure(path, false);
float length = pm.getLength();
float distance = 0f;
float speed = length / size;
int counter = 0;
float[] aCoordinates = new float[2];
while ((distance < length) && (counter < size)) {
pm.getPosTan(distance, aCoordinates, null);
pointArray[counter] = new PathPoints(aCoordinates[0], aCoordinates[1]);
counter++;
distance = distance + speed;
}
return pointArray;
}
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 wire-android by wireapp.
the class CircularSeekBar method calculatePointerXYPosition.
private void calculatePointerXYPosition() {
PathMeasure pm = new PathMeasure(circleProgressPath, false);
boolean returnValue = pm.getPosTan(pm.getLength(), pointerPositionXY, null);
if (!returnValue) {
pm = new PathMeasure(circlePath, false);
returnValue = pm.getPosTan(0, pointerPositionXY, null);
}
}
use of android.graphics.PathMeasure in project UltimateAndroid by cymcsg.
the class FloatingActionMenu method calculateItemPositions.
/**
* Calculates the desired positions of all items.
*/
private void calculateItemPositions() {
// Create an arc that starts from startAngle and ends at endAngle
// in an area that is as large as 4*radius^2
Point center = getActionViewCenter();
RectF area = new RectF(center.x - radius, center.y - radius, center.x + radius, center.y + radius);
Path orbit = new Path();
orbit.addArc(area, startAngle, endAngle - startAngle);
PathMeasure measure = new PathMeasure(orbit, false);
// Prevent overlapping when it is a full circle
int divisor;
if (Math.abs(endAngle - startAngle) >= 360 || subActionItems.size() <= 1) {
divisor = subActionItems.size();
} else {
divisor = subActionItems.size() - 1;
}
// Measure this path, in order to find points that have the same distance between each other
for (int i = 0; i < subActionItems.size(); i++) {
float[] coords = new float[] { 0f, 0f };
measure.getPosTan((i) * measure.getLength() / divisor, coords, null);
// get the x and y values of these points and set them to each of sub action items.
subActionItems.get(i).x = (int) coords[0] - subActionItems.get(i).width / 2;
subActionItems.get(i).y = (int) coords[1] - subActionItems.get(i).height / 2;
}
}
Aggregations