Search in sources :

Example 1 with PathMeasure

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()));
}
Also used : Path(android.graphics.Path) PathMeasure(android.graphics.PathMeasure) ParseException(java.text.ParseException) Paint(android.graphics.Paint)

Example 2 with PathMeasure

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;
}
Also used : PathMeasure(android.graphics.PathMeasure)

Example 3 with PathMeasure

use of android.graphics.PathMeasure in project ZLoading by zyao89.

the class StairsPathBuilder method initPathMeasure.

private void initPathMeasure() {
    mDrawPath = new Path();
    mPathMeasure = new PathMeasure();
}
Also used : Path(android.graphics.Path) PathMeasure(android.graphics.PathMeasure)

Example 4 with 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();
}
Also used : PathMeasure(android.graphics.PathMeasure)

Example 5 with PathMeasure

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());
        }
    }
}
Also used : Rect(android.graphics.Rect) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) PathMeasure(android.graphics.PathMeasure) Location(net.osmand.Location)

Aggregations

PathMeasure (android.graphics.PathMeasure)47 Path (android.graphics.Path)18 Paint (android.graphics.Paint)11 RectF (android.graphics.RectF)5 Point (android.graphics.Point)3 ParseException (java.text.ParseException)3 Animator (android.animation.Animator)2 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 PropertyValuesHolder (android.animation.PropertyValuesHolder)2 ValueAnimator (android.animation.ValueAnimator)2 SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 Matrix (android.graphics.Matrix)2 PointF (android.graphics.PointF)2 Rect (android.graphics.Rect)2 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)2 DashPathEffect (android.graphics.DashPathEffect)1 PathEffect (android.graphics.PathEffect)1 Nullable (android.support.annotation.Nullable)1