use of android.graphics.PathMeasure in project muzei by romannurik.
the class AnimatedMuzeiLoadingSpinnerView method rebuildGlyphData.
private void rebuildGlyphData() {
SvgPathParser parser = new SvgPathParser() {
@Override
protected float transformX(float x) {
return x * mWidth / VIEWPORT.width();
}
@Override
protected float transformY(float y) {
return y * mHeight / VIEWPORT.height();
}
};
mGlyphData = new GlyphData();
try {
mGlyphData.path = parser.parsePath(LogoPaths.GLYPHS[0]);
} catch (ParseException e) {
mGlyphData.path = new Path();
Log.e(TAG, "Couldn't parse path", e);
}
PathMeasure pm = new PathMeasure(mGlyphData.path, true);
while (true) {
mGlyphData.length = Math.max(mGlyphData.length, pm.getLength());
if (!pm.nextContour()) {
break;
}
}
mGlyphData.paint = new Paint();
mGlyphData.paint.setStyle(Paint.Style.STROKE);
mGlyphData.paint.setAntiAlias(true);
mGlyphData.paint.setColor(Color.WHITE);
mGlyphData.paint.setStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
}
use of android.graphics.PathMeasure in project platform_frameworks_base by android.
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 ZLoading by zyao89.
the class StairsPathBuilder method initPathMeasure.
private void initPathMeasure() {
mDrawPath = new Path();
mPathMeasure = new PathMeasure();
}
use of android.graphics.PathMeasure in project android_packages_apps_Gallery2 by LineageOS.
the class FilterDrawRepresentation method serializeRepresentation.
@Override
public void serializeRepresentation(JsonWriter writer) throws IOException {
writer.beginObject();
int len = mDrawing.size();
int count = 0;
float[] mPosition = new float[2];
float[] mTan = new float[2];
PathMeasure mPathMeasure = new PathMeasure();
for (int i = 0; i < len; i++) {
writer.name(SERIAL_PATH + i);
writer.beginObject();
StrokeData mark = mDrawing.get(i);
writer.name(SERIAL_COLOR).value(mark.mColor);
writer.name(SERIAL_RADIUS).value(mark.mRadius);
writer.name(SERIAL_TYPE).value(mark.mType);
writer.name(SERIAL_POINTS_COUNT).value(mark.noPoints);
writer.name(SERIAL_POINTS);
writer.beginArray();
int npoints = mark.noPoints * 2;
for (int j = 0; j < npoints; j++) {
writer.value(mark.mPoints[j]);
}
writer.endArray();
writer.endObject();
}
writer.endObject();
}
use of android.graphics.PathMeasure in project Osmand by osmandapp.
the class MapMarkersLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
Location myLoc;
if (useFingerLocation && fingerLocation != null) {
myLoc = new Location("");
myLoc.setLatitude(fingerLocation.getLatitude());
myLoc.setLongitude(fingerLocation.getLongitude());
} else {
myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
}
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
int displayedWidgets = map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get();
if (route != null && route.points.size() > 0) {
planRouteAttrs.updatePaints(view, nightMode, tileBox);
route.renders.clear();
route.renders.add(new Renderable.StandardTrack(new ArrayList<>(route.points), 17.2));
route.drawRenderers(view.getZoom(), defaultAppMode ? planRouteAttrs.paint : planRouteAttrs.paint2, canvas, tileBox);
}
if (map.getMyApplication().getSettings().SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) {
textAttrs.paint.setTextSize(textSize);
textAttrs.paint2.setTextSize(textSize);
lineAttrs.updatePaints(view, nightMode, tileBox);
textAttrs.updatePaints(view, nightMode, tileBox);
textAttrs.paint.setStyle(Paint.Style.FILL);
boolean drawMarkerName = map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1;
int locX;
int locY;
if (map.getMapViewTrackingUtilities().isMapLinkedToLocation() && !MapViewTrackingUtilities.isSmallSpeedForAnimation(myLoc) && !map.getMapViewTrackingUtilities().isMovingToMyLocation()) {
locX = (int) tileBox.getPixXFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
locY = (int) tileBox.getPixYFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
} else {
locX = (int) tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
locY = (int) tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
}
int[] colors = MapMarker.getColors(map);
for (int i = 0; i < activeMapMarkers.size() && i < displayedWidgets; i++) {
MapMarker marker = activeMapMarkers.get(i);
int markerX = (int) tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude());
int markerY = (int) tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude());
linePath.reset();
tx.clear();
ty.clear();
tx.add(locX);
ty.add(locY);
tx.add(markerX);
ty.add(markerY);
calculatePath(tileBox, tx, ty, linePath);
PathMeasure pm = new PathMeasure(linePath, false);
float[] pos = new float[2];
pm.getPosTan(pm.getLength() / 2, pos, null);
float dist = (float) MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(), marker.getLatitude(), marker.getLongitude());
String distSt = OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
String text = distSt + (drawMarkerName ? " • " + marker.getName(map) : "");
Rect bounds = new Rect();
textAttrs.paint.getTextBounds(text, 0, text.length(), bounds);
float hOffset = pm.getLength() / 2 - bounds.width() / 2;
lineAttrs.paint.setColor(colors[marker.colorIndex]);
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
canvas.drawPath(linePath, lineAttrs.paint);
if (locX >= markerX) {
canvas.rotate(180, pos[0], pos[1]);
canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + verticalOffset, textAttrs.paint2);
canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + verticalOffset, textAttrs.paint);
canvas.rotate(-180, pos[0], pos[1]);
} else {
canvas.drawTextOnPath(text, linePath, hOffset, -verticalOffset, textAttrs.paint2);
canvas.drawTextOnPath(text, linePath, hOffset, -verticalOffset, textAttrs.paint);
}
canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
}
}
}
Aggregations