use of android.graphics.PathMeasure in project Osmand by osmandapp.
the class RulerControlLayer method drawTextOnCenterOfPath.
private void drawTextOnCenterOfPath(Canvas canvas, float x1, float x2, Path path, String text) {
PathMeasure pm = new PathMeasure(path, false);
Rect bounds = new Rect();
lineFontAttrs.paint.getTextBounds(text, 0, text.length(), bounds);
float hOffset = pm.getLength() / 2 - bounds.width() / 2;
if (x1 >= x2) {
float[] pos = new float[2];
pm.getPosTan(pm.getLength() / 2, pos, null);
canvas.rotate(180, pos[0], pos[1]);
canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, lineFontAttrs.paint2);
canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, lineFontAttrs.paint);
canvas.rotate(-180, pos[0], pos[1]);
} else {
canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, lineFontAttrs.paint2);
canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, lineFontAttrs.paint);
}
}
use of android.graphics.PathMeasure in project Bitocle by mthli.
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;
}
}
use of android.graphics.PathMeasure in project Depth-LIB-Android- by danielzeller.
the class PathBitmapMesh method matchVertsToPath.
public void matchVertsToPath(Path path, float bottomCoord, float extraOffset) {
PathMeasure pm = new PathMeasure(path, false);
for (int i = 0; i < staticVerts.length / 2; i++) {
float yIndexValue = staticVerts[i * 2 + 1];
float xIndexValue = staticVerts[i * 2];
float percentOffsetX = (0.000001f + xIndexValue) / bitmap.getWidth();
float percentOffsetX2 = (0.000001f + xIndexValue) / (bitmap.getWidth() + extraOffset);
percentOffsetX2 += pathOffsetPercent;
pm.getPosTan(pm.getLength() * (1f - percentOffsetX), coords, null);
pm.getPosTan(pm.getLength() * (1f - percentOffsetX2), coords2, null);
if (yIndexValue == 0) {
setXY(drawingVerts, i, coords[0], coords2[1]);
} else {
setXY(drawingVerts, i, coords[0], bottomCoord);
}
}
}
use of android.graphics.PathMeasure in project Depth-LIB-Android- by danielzeller.
the class RenderableTree method matchVertsToPath.
private void matchVertsToPath() {
PathMeasure pmLeft = new PathMeasure(pathLeft, false);
PathMeasure pmRight = new PathMeasure(pathRight, false);
float[] coords = new float[2];
for (int i = 0; i < staticVerts.length / 2; i++) {
float yIndexValue = staticVerts[i * 2 + 1];
float xIndexValue = staticVerts[i * 2];
if (xIndexValue == 0) {
float percentOffsetY = (0.000001f + yIndexValue) / bitmap.getHeight();
pmLeft.getPosTan(pmLeft.getLength() * (1f - percentOffsetY), coords, null);
setXY(drawingVerts, i, coords[0], coords[1]);
} else {
float percentOffsetY = (0.000001f + yIndexValue) / bitmap.getHeight();
pmRight.getPosTan(pmRight.getLength() * (1f - percentOffsetY), coords, null);
setXY(drawingVerts, i, coords[0], coords[1]);
}
}
}
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);
}
}
Aggregations