Java Code Examples for android.graphics.PathMeasure#getLength()
The following examples show how to use
android.graphics.PathMeasure#getLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DashboardView.java From Android_UE with Apache License 2.0 | 6 votes |
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mRect = new RectF(getWidth() / 2 - RADIUS, PADDING, getWidth() / 2 + RADIUS, getHeight() - PADDING); // 刻度的数量 Path arcPath = new Path(); arcPath.addArc(mRect, START_ANAGLE, 360 - (START_ANAGLE - 45)); PathMeasure pathMeasure = new PathMeasure(arcPath, false); float pathMeasureLength = pathMeasure.getLength(); // 短刻度 mShortEffect = new PathDashPathEffect(mShortDash, (pathMeasureLength - Utils.dp2px(2)) / 50,// 每个间距为多少 0,// 第一个从什么地方开始 PathDashPathEffect.Style.ROTATE); // 长刻度 mLongEffect = new PathDashPathEffect(mLongDash, (pathMeasureLength - Utils.dp2px(2)) / 10,// 每个间距为多少 0,// 第一个从什么地方开始 PathDashPathEffect.Style.ROTATE); }
Example 2
Source File: PathInterpolatorDonut.java From RxTools-master with Apache License 2.0 | 6 votes |
public PathInterpolatorDonut(Path path) { final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); final float pathLength = pathMeasure.getLength(); final int numPoints = (int) (pathLength / PRECISION) + 1; mX = new float[numPoints]; mY = new float[numPoints]; final float[] position = new float[2]; for (int i = 0; i < numPoints; ++i) { final float distance = (i * pathLength) / (numPoints - 1); pathMeasure.getPosTan(distance, position, null /* tangent */); mX[i] = position[0]; mY[i] = position[1]; } }
Example 3
Source File: OC_Tracer.java From GLEXP-Team-onebillion with Apache License 2.0 | 6 votes |
public OBGroup splitPath(OBPath obp) { PathMeasure pm = new PathMeasure(obp.path(),false); float splen = pm.getLength(); int noSplits = (int)(splen / (100)); List<OBPath> newOBPaths = splitInto(obp, pm, noSplits, 1.0f / (noSplits * 4)); for (OBPath newOBPath : newOBPaths) { //newOBPath.setBounds(obp.bounds); //newOBPath.setPosition(obp.position()); //newOBPath.sizeToBox(obp.bounds()); newOBPath.setStrokeColor(Color.argb((int)(255 * 0.4f),255,0,0)); newOBPath.setLineJoin(OBStroke.kCALineJoinRound); newOBPath.setFillColor(0); newOBPath.setLineWidth(swollenLineWidth); } OBGroup grp = new OBGroup((List<OBControl>)(Object)newOBPaths); return grp; }
Example 4
Source File: OC_Generic_Tracing.java From GLEXP-Team-onebillion with Apache License 2.0 | 6 votes |
public OBGroup splitPath (OBPath obp) { int lengthPerSplit = 100; PathMeasure pm = new PathMeasure(obp.path(), false); float splen = pm.getLength(); int noSplits = (int) (splen / lengthPerSplit); List<OBPath> newOBPaths = splitInto(obp, pm, noSplits, 1.0f / (noSplits * 4)); for (OBPath newOBPath : newOBPaths) { //newOBPath.setBounds(obp.bounds); //newOBPath.setPosition(obp.position()); //newOBPath.sizeToBox(obp.bounds()); newOBPath.setStrokeColor(Color.argb((int) (255 * 0.4f), 255, 0, 0)); newOBPath.setLineJoin(OBStroke.kCALineJoinRound); newOBPath.setFillColor(0); newOBPath.setLineWidth(swollenLineWidth); } MainActivity.log("Now serving " + newOBPaths.size()); OBGroup grp = new OBGroup((List<OBControl>) (Object) newOBPaths); return grp; }
Example 5
Source File: PathKeyframesSupport.java From CatchPiggy with GNU General Public License v3.0 | 6 votes |
@Override void init(MyPath path) { final PathMeasure pathMeasure = new PathMeasure(path, false); final float pathLength = pathMeasure.getLength(); numPoints = (int) (pathLength / PRECISION) + 1; mX = new float[numPoints]; mY = new float[numPoints]; final float[] position = new float[2]; for (int i = 0; i < numPoints; ++i) { final float distance = (i * pathLength) / (numPoints - 1); pathMeasure.getPosTan(distance, position, null /* tangent */); mX[i] = position[0]; mY[i] = position[1]; } mPath = path; }
Example 6
Source File: PaperPlaneView.java From SparkleMotion with MIT License | 6 votes |
@Override protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); // Scale and translate the SVG path. Matrix matrix = new Matrix(); RectF rectF = new RectF(); mPath.computeBounds(rectF, false); RectF largeRectF = new RectF(0, 0, w * SCALE_FACTOR, h * SCALE_FACTOR); matrix.setRectToRect(rectF, largeRectF, Matrix.ScaleToFit.CENTER); float pathTranslationY = getResources().getDimension(R.dimen.path_translation_y); float pathTranslationX = getResources().getDimension(R.dimen.path_translation_x); matrix.postTranslate(pathTranslationX, pathTranslationY); mPath.transform(matrix); mPathMeasure = new PathMeasure(mPath, false); mLength = mPathMeasure.getLength(); if (mProgress != 0) { // Animate the restored frame. animate(mProgress); } }
Example 7
Source File: OC_ReadingReadToMeNTx.java From GLEXP-Team-onebillion with Apache License 2.0 | 6 votes |
List<Path> pathsFromComplexPath(Path p) { List<Path>pathList = new ArrayList<>(); PathMeasure pm = new PathMeasure(p,false); Boolean fin = false; while (!fin) { float len = pm.getLength(); if (len > 0) { Path np = new Path(); pm.getSegment(0,len,np,true); pathList.add(np); } fin = !pm.nextContour(); } return pathList; }
Example 8
Source File: ObjectAnimatorCompatBase.java From MaterialProgressBar with Apache License 2.0 | 5 votes |
private static void calculateXYValues(@NonNull Path path, @NonNull @Size(NUM_POINTS) float[] xValues, @NonNull @Size(NUM_POINTS) float[] yValues) { PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); float pathLength = pathMeasure.getLength(); float[] position = new float[2]; for (int i = 0; i < NUM_POINTS; ++i) { float distance = (i * pathLength) / (NUM_POINTS - 1); pathMeasure.getPosTan(distance, position, null /* tangent */); xValues[i] = position[0]; yValues[i] = position[1]; } }
Example 9
Source File: LineSparkAnimator.java From spark with Apache License 2.0 | 5 votes |
@Nullable @Override public Animator getAnimation(final SparkView sparkView) { final Path linePath = sparkView.getSparkLinePath(); // get path length final PathMeasure pathMeasure = new PathMeasure(linePath, false); final float endLength = pathMeasure.getLength(); if (endLength <= 0) { return null; } animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float animatedValue = (float) animation.getAnimatedValue(); float animatedPathLength = animatedValue * endLength; linePath.reset(); pathMeasure.getSegment(0, animatedPathLength, linePath, true); // set the updated path for the animation sparkView.setAnimationPath(linePath); } }); return animator; }
Example 10
Source File: RxPathAnimator.java From RxTools-master with Apache License 2.0 | 5 votes |
public FloatAnimation(Path path, float rotation, View parent, View child) { mPm = new PathMeasure(path, false); mDistance = mPm.getLength(); mView = child; mRotation = rotation; parent.setLayerType(View.LAYER_TYPE_HARDWARE, null); }
Example 11
Source File: PathAnimator.java From KSYMediaPlayer_Android with Apache License 2.0 | 5 votes |
public FloatAnimation(Path path, float rotation, View parent, View child) { mPm = new PathMeasure(path,false); mDistance = mPm.getLength(); mView = child; mRotation = rotation; parent.setLayerType(View.LAYER_TYPE_HARDWARE, null); }
Example 12
Source File: PathAnimator.java From MousePaint with MIT License | 5 votes |
public FloatAnimation(Path path, float rotation, View parent, View child) { mPm = new PathMeasure(path, false); mDistance = mPm.getLength(); mView = child; mRotation = rotation; parent.setLayerType(View.LAYER_TYPE_HARDWARE, null); }
Example 13
Source File: SimpleLineStyle.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected void drawText(float scaledWidth, Path mainPath, GISDisplay display) { if (TextUtils.isEmpty(mText) || mainPath == null) return; Paint textPaint = new Paint(); textPaint.setColor(mOutColor); textPaint.setAntiAlias(true); textPaint.setStyle(Paint.Style.FILL); textPaint.setStrokeCap(Paint.Cap.ROUND); textPaint.setStrokeWidth(scaledWidth); float textSize = 12 * scaledWidth; textPaint.setTextSize(textSize); float textWidth = textPaint.measureText(mText); float vOffset = (float) (textSize / 2.7); // draw text along the main path PathMeasure pm = new PathMeasure(mainPath, false); float length = pm.getLength(); float gap = textPaint.measureText("_"); float period = textWidth + gap; float startD = gap; float stopD = startD + period; Path textPath = new Path(); while (stopD < length) { textPath.reset(); pm.getSegment(startD, stopD, textPath, true); textPath.rLineTo(0, 0); // workaround for API <= 19 display.drawTextOnPath(mText, textPath, 0, vOffset, textPaint); startD += period; stopD += period; } stopD = startD; float rest = length - stopD; if (rest > gap * 2) { stopD = length - gap; textPath.reset(); pm.getSegment(startD, stopD, textPath, true); textPath.rLineTo(0, 0); // workaround for API <= 19 display.drawTextOnPath(mText, textPath, 0, vOffset, textPaint); } }
Example 14
Source File: Animator.java From LineAnimation with MIT License | 4 votes |
@Override protected void onDraw(Canvas canvas){ super.onDraw(canvas); paint.setColor(pathColor); paint.setStrokeWidth(pathStrokeWidth); OnPathListener opl = (OnPathListener) context; line = opl.setOnPathUpdateListener(arrowX, arrowY); PathMeasure pm = new PathMeasure(line, false); float aCoordinates[] = {0f, 0f}; float aTan[] = {0f, 0f}; //if(coordinates == null){ coordinates = new ArrayList<>(); coordinatesTan = new ArrayList<>(); for(int x = (int) pm.getLength(); x > 0; x--){ pm.getPosTan(x, aCoordinates, aTan); Coordinates c = new Coordinates(); c.setX((int) aCoordinates[0]); c.setY((int) aCoordinates[1]); coordinates.add(c); Coordinates c2 = new Coordinates(); c2.setXf(aTan[0]); c2.setYf(aTan[1]); coordinatesTan.add(c2); } //} canvas.drawPath(line, paint); motionBitmap(); matrix.reset(); float degrees = (float) (Math.atan2(arrowXTan, arrowYTan) * -180.0 / Math.PI); matrix.postRotate(degrees, arrow.getWidth() / 2, arrow.getHeight() / 2); matrix.postTranslate(arrowX - (arrow.getWidth() / 2), arrowY - (arrow.getHeight() / 2)); canvas.drawBitmap(arrow, matrix, null); if(animateArrow){ invalidate(); } }
Example 15
Source File: GUIFallingOsuSliderEnd.java From Beats with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void draw(GUIDrawingArea drawarea, Canvas canvas) { if (missed) return; int timeDiff; //float timeDiffPercent; timeDiff = start_time - GUIGame.currentTime; //timeDiffPercent = (float)(timeDiff) / delay; if (lastBeat != null && !lastBeat.missed && (lastBeat.tapped || lastBeat.opa > 0)) { float beatDiffPercent = (float)(timeDiff) / (float)(start_time - lastBeat.start_time); if (beatDiffPercent > 1) beatDiffPercent = 1f; if (beatDiffPercent < 0) beatDiffPercent = 0f; if (lastBeat.tapped) { opa = Tools.MAX_OPA; } else { opa = lastBeat.opa; } curvePaint.setAlpha(opa); curvePaintOutline.setAlpha(opa); canvas.drawPath(curvePath, curvePaintOutline); canvas.drawPath(curvePath, curvePaint); fadePaint.setAlpha(opa); canvas.drawBitmap( drawarea.getBitmap( GUINoteImage.osu_beat(fraction), Tools.button_w, Tools.button_h), lastBeat.x, lastBeat.y, fadePaint ); numPaint.ARGB(opa, 255, 255, 255); // white numPaint.strokeARGB(opa, 0, 0, 0); // black //numPaint.draw(canvas, num, cx, cy + NUM_TEXT_HEIGHT/3); numPaint.draw(canvas, num, lastBeat.cx, lastBeat.cy + NUM_TEXT_HEIGHT/3); canvas.drawBitmap( drawarea.getBitmap( GUINoteImage.osu_beat(fraction), Tools.button_w, Tools.button_h), x, y, fadePaint ); if (GUIGame.currentTime > lastBeat.end_time && lastBeat.tapped) { focusPaint.setAlpha((int)(Math.abs(Math.sin(timeDiff / (BLINK_DEFAULT / BLINK_SPEED) ) * Tools.MAX_OPA))); // Fade in and out! } else { focusPaint.setAlpha(0); } /* if (timeDiffPercent < timeDiffMax && timeDiffPercent > timeDiffMin) { int radius = (int)(Tools.button_h * 0.95) / 2; if (timeDiffPercent >= 0) { radius *= (1 + timeDiffPercent); } canvas.drawCircle(cx, cy, radius, circlePaint); } */ float[] coords = new float[2]; PathMeasure measure = new PathMeasure(curvePath, false); float length = measure.getLength(); measure.getPosTan(length - beatDiffPercent * length, coords, null); canvas.drawCircle(coords[0], coords[1], focusRadius, focusPaint); } }
Example 16
Source File: CheckView.java From CheckView with Apache License 2.0 | 4 votes |
/** * Perform measurements and pre-calculations. This should be called any time * the view measurements or visuals are changed, such as with a call to {@link #setPadding(int, int, int, int)} * or an operating system callback like {@link #onLayout(boolean, int, int, int, int)}. */ private void measurePaths() { int maxSize; float middle; maxSize = Math.min(getWidth(), getHeight()); padding = Math.max( Math.max(getPaddingBottom(), getPaddingTop()), Math.max(getPaddingRight(), getPaddingLeft())); maxSize -= padding * 2; middle = maxSize / 2f; pathMeasure = new PathMeasure(); PointF p1a = new PointF(middle, 0); PointF p1b = getCheckRightPoint(maxSize); firstPath = new Path(); firstPath.moveTo(p1a.x, p1a.y); firstPath.lineTo(p1b.x, p1b.y); pathMeasure.setPath(firstPath, false); firstPathLength = pathMeasure.getLength(); PointF p2a = new PointF(middle, maxSize); PointF p2b = getCheckMiddlePoint(maxSize); secondPath = new Path(); secondPath.moveTo(p2a.x, p2a.y); secondPath.lineTo(p2b.x, p2b.y); pathMeasure.setPath(secondPath, false); secondPathLength = pathMeasure.getLength(); PointF p3a = new PointF(0, middle); PointF p3b = getCheckLeftPoint(maxSize); thirdPath = new Path(); thirdPath.moveTo(p3a.x, p3a.y); thirdPath.lineTo(p3b.x, p3b.y); pathMeasure.setPath(thirdPath, false); thirdPathLength = pathMeasure.getLength(); PointF p4a = new PointF(maxSize, middle); fourPath = new Path(); fourPath.moveTo(p4a.x, p4a.y); fourPath.lineTo(p2b.x, p2b.y); pathMeasure.setPath(fourPath, false); fourPathLength = pathMeasure.getLength(); paint = new Paint(); paint.setAntiAlias(true); paint.setColor(color); paint.setStyle(Paint.Style.STROKE); paint.setStrokeCap(Paint.Cap.SQUARE); paint.setStrokeWidth(strokeWidth); fromXY = new float[]{0f, 0f}; toXY = new float[]{0f, 0f}; }
Example 17
Source File: SimpleLineStyle.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected Path drawDashLine(float scaledWidth, GeoLineString lineString, GISDisplay display) { Paint paint = new Paint(); paint.setColor(mColor); paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE); paint.setStrokeCap(Paint.Cap.BUTT); paint.setStrokeWidth(scaledWidth); List<GeoPoint> points = lineString.getPoints(); // workaround for "DashPathEffect/drawLine not working properly when hardwareAccelerated="true"" // https://code.google.com/p/android/issues/detail?id=29944 // get all points to the main path Path mainPath = new Path(); mainPath.incReserve(points.size()); mainPath.moveTo((float) points.get(0).getX(), (float) points.get(0).getY()); for (int i = 1; i < points.size(); ++i) { mainPath.lineTo((float) points.get(i).getX(), (float) points.get(i).getY()); } // draw along the main path PathMeasure pm = new PathMeasure(mainPath, false); float[] coordinates = new float[2]; float length = pm.getLength(); float dash = (float) (10 / display.getScale()); float gap = (float) (5 / display.getScale()); float distance = dash; boolean isDash = true; Path dashPath = new Path(); dashPath.incReserve((int) (2 * length / (dash + gap))); dashPath.moveTo((float) points.get(0).getX(), (float) points.get(0).getY()); while (distance < length) { // get a point from the main path pm.getPosTan(distance, coordinates, null); if (isDash) { dashPath.lineTo(coordinates[0], coordinates[1]); distance += gap; } else { dashPath.moveTo(coordinates[0], coordinates[1]); distance += dash; } isDash = !isDash; } // add a rest from the main path if (isDash) { distance = distance - dash; float rest = length - distance; if (rest > (float) (1 / display.getScale())) { distance = length - 1; pm.getPosTan(distance, coordinates, null); dashPath.lineTo(coordinates[0], coordinates[1]); } } display.drawPath(dashPath, paint); return mainPath; }
Example 18
Source File: PathMeasureView.java From zone-sdk with MIT License | 4 votes |
private void testNextContour(Canvas canvas) { Path path = new Path(); path.addRect(-100, -100, 100, 100, Path.Direction.CW); // 添加小矩形 path.addRect(-200, -200, 200, 200, Path.Direction.CW); // 添加大矩形 canvas.drawPath(path, mDeafultPaint); // 绘制 Path PathMeasure measure = new PathMeasure(path, false); // 将Path与PathMeasure关联 float len1 = measure.getLength(); // 获得第一条路径的长度 measure.nextContour(); // 跳转到下一条路径 float len2 = measure.getLength(); // 获得第二条路径的长度 Log.i("LEN", "len1=" + len1); // 输出两条路径的长度 Log.i("LEN", "len2=" + len2); }
Example 19
Source File: MaterialContainerTransform.java From material-components-android with Apache License 2.0 | 4 votes |
private TransitionDrawable( PathMotion pathMotion, View startView, RectF startBounds, ShapeAppearanceModel startShapeAppearanceModel, float startElevation, View endView, RectF endBounds, ShapeAppearanceModel endShapeAppearanceModel, float endElevation, @ColorInt int containerColor, @ColorInt int startContainerColor, @ColorInt int endContainerColor, int scrimColor, boolean entering, boolean elevationShadowEnabled, FadeModeEvaluator fadeModeEvaluator, FitModeEvaluator fitModeEvaluator, ProgressThresholdsGroup progressThresholds, boolean drawDebugEnabled) { this.startView = startView; this.startBounds = startBounds; this.startShapeAppearanceModel = startShapeAppearanceModel; this.startElevation = startElevation; this.endView = endView; this.endBounds = endBounds; this.endShapeAppearanceModel = endShapeAppearanceModel; this.endElevation = endElevation; this.entering = entering; this.elevationShadowEnabled = elevationShadowEnabled; this.fadeModeEvaluator = fadeModeEvaluator; this.fitModeEvaluator = fitModeEvaluator; this.progressThresholds = progressThresholds; this.drawDebugEnabled = drawDebugEnabled; containerPaint.setColor(containerColor); startContainerPaint.setColor(startContainerColor); endContainerPaint.setColor(endContainerColor); compatShadowDrawable.setFillColor(ColorStateList.valueOf(Color.TRANSPARENT)); compatShadowDrawable.setShadowCompatibilityMode( MaterialShapeDrawable.SHADOW_COMPAT_MODE_ALWAYS); compatShadowDrawable.setShadowBitmapDrawingEnable(false); compatShadowDrawable.setShadowColor(COMPAT_SHADOW_COLOR); currentStartBounds = new RectF(startBounds); currentStartBoundsMasked = new RectF(currentStartBounds); currentEndBounds = new RectF(currentStartBounds); currentEndBoundsMasked = new RectF(currentEndBounds); // Calculate motion path PointF startPoint = getMotionPathPoint(startBounds); PointF endPoint = getMotionPathPoint(endBounds); Path motionPath = pathMotion.getPath(startPoint.x, startPoint.y, endPoint.x, endPoint.y); motionPathMeasure = new PathMeasure(motionPath, false); motionPathLength = motionPathMeasure.getLength(); scrimPaint.setStyle(Paint.Style.FILL); scrimPaint.setShader(createColorShader(scrimColor)); debugPaint.setStyle(Paint.Style.STROKE); debugPaint.setStrokeWidth(10); // Initializes calculations the drawable updateProgress(0); }
Example 20
Source File: CircleBroodLoadingRenderer.java From DevUtils with Apache License 2.0 | 3 votes |
private float getRestLength(Path path, float startD) { Path tempPath = new Path(); PathMeasure pathMeasure = new PathMeasure(path, false); pathMeasure.getSegment(startD, pathMeasure.getLength(), tempPath, true); pathMeasure.setPath(tempPath, false); return pathMeasure.getLength(); }