List of usage examples for android.graphics Path moveTo
public void moveTo(float x, float y)
From source file:android.support.transition.ArcMotion.java
@Override public Path getPath(float startX, float startY, float endX, float endY) { // Here's a little ascii art to show how this is calculated: // c---------- b // \ / | // \ d | // \ / e // a----f // This diagram assumes that the horizontal distance is less than the vertical // distance between The start point (a) and end point (b). // d is the midpoint between a and b. c is the center point of the circle with // This path is formed by assuming that start and end points are in // an arc on a circle. The end point is centered in the circle vertically // and start is a point on the circle. // Triangles bfa and bde form similar right triangles. The control points // for the cubic Bezier arc path are the midpoints between a and e and e and b. Path path = new Path(); path.moveTo(startX, startY); float ex;/*w ww .j a v a 2 s . c o m*/ float ey; float deltaX = endX - startX; float deltaY = endY - startY; // hypotenuse squared. float h2 = deltaX * deltaX + deltaY * deltaY; // Midpoint between start and end float dx = (startX + endX) / 2; float dy = (startY + endY) / 2; // Distance squared between end point and mid point is (1/2 hypotenuse)^2 float midDist2 = h2 * 0.25f; float minimumArcDist2; boolean isMovingUpwards = startY > endY; if ((Math.abs(deltaX) < Math.abs(deltaY))) { // Similar triangles bfa and bde mean that (ab/fb = eb/bd) // Therefore, eb = ab * bd / fb // ab = hypotenuse // bd = hypotenuse/2 // fb = deltaY float eDistY = Math.abs(h2 / (2 * deltaY)); if (isMovingUpwards) { ey = endY + eDistY; ex = endX; } else { ey = startY + eDistY; ex = startX; } minimumArcDist2 = midDist2 * mMinimumVerticalTangent * mMinimumVerticalTangent; } else { // Same as above, but flip X & Y and account for negative eDist float eDistX = h2 / (2 * deltaX); if (isMovingUpwards) { ex = startX + eDistX; ey = startY; } else { ex = endX - eDistX; ey = endY; } minimumArcDist2 = midDist2 * mMinimumHorizontalTangent * mMinimumHorizontalTangent; } float arcDistX = dx - ex; float arcDistY = dy - ey; float arcDist2 = arcDistX * arcDistX + arcDistY * arcDistY; float maximumArcDist2 = midDist2 * mMaximumTangent * mMaximumTangent; float newArcDistance2 = 0; if (arcDist2 < minimumArcDist2) { newArcDistance2 = minimumArcDist2; } else if (arcDist2 > maximumArcDist2) { newArcDistance2 = maximumArcDist2; } if (newArcDistance2 != 0) { float ratio2 = newArcDistance2 / arcDist2; float ratio = (float) Math.sqrt(ratio2); ex = dx + (ratio * (ex - dx)); ey = dy + (ratio * (ey - dy)); } float control1X = (startX + ex) / 2; float control1Y = (startY + ey) / 2; float control2X = (ex + endX) / 2; float control2Y = (ey + endY) / 2; path.cubicTo(control1X, control1Y, control2X, control2Y, endX, endY); return path; }
From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java
private void makePathWhite() { if (mPathWhite == null) { mPathWhite = new Path(); }//from w w w . j av a 2s. c o m Path p = new Path(); p.moveTo(getPaddingLeft(), mHeight / 2); p.lineTo(Math.max(getPaddingLeft(), mProgress * mWidth / 100), mHeight / 2 + calculateDeltaY()); mPathWhite.set(p); }
From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java
/** * MARK: Update drawings/*from w w w.j ava 2 s . c om*/ */ private void makePathBlack() { if (mPathBlack == null) { mPathBlack = new Path(); } Path p = new Path(); p.moveTo(Math.max(getPaddingLeft(), mProgress * mWidth / 100), mHeight / 2 + calculateDeltaY()); p.lineTo(mWidth, mHeight / 2); mPathBlack.set(p); }
From source file:com.frapim.windwatch.Notifier.java
private Path getArrowPath(float degrees) { Path path = new Path(); int leftX = (mBigIconSize / 2) - (mArrowWidth / 2); int leftHeadX = leftX - mArrowWidth; int rightX = (mBigIconSize / 2) + (mArrowWidth / 2); int rightHeadX = rightX + mArrowWidth; path.moveTo(leftX, mArrowHeight); // bottom left path.lineTo(leftX, mArrowHeadHeight); // left, arrow head start path.lineTo(leftHeadX, mArrowHeadHeight); // left, arrow head end path.lineTo(mBigIconSize / 2, 0); // top path.lineTo(rightHeadX, mArrowHeadHeight); // right, arrow head end path.lineTo(rightX, mArrowHeadHeight); // right, arrow head start path.lineTo(rightX, mArrowHeight); // bottom right path.lineTo(leftX, mArrowHeight); // bottom left path.close();// www . ja v a 2 s.com Matrix translateMatrix = new Matrix(); translateMatrix.postTranslate(0, 30); path.transform(translateMatrix); RectF bounds = new RectF(); path.computeBounds(bounds, true); Matrix rotateMatrix = new Matrix(); rotateMatrix.postRotate(degrees, (bounds.right + bounds.left) / 2, (bounds.bottom + bounds.top) / 2); path.transform(rotateMatrix); return path; }
From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java
private void makePathBubble() { if (mPathBubble == null) { mPathBubble = new Path(); }/* ww w . ja v a 2 s . c o m*/ int width = mBubbleWidth; int height = mBubbleHeight; int arrowWidth = width / 3; //Rect r = new Rect(Math.max(getPaddingLeft()-width/2-arrowWidth/4, mProgress*mWidth/100-width/2-arrowWidth/4), mHeight/2-height + calculatedeltaY(), Math.max(getPaddingLeft()+width/2-arrowWidth/4, mProgress*mWidth/100+width/2-arrowWidth/4), mHeight/2+height-height + calculatedeltaY()); Rect r = new Rect((int) (Math.max(getPaddingLeft() - width / 2, mProgress * mWidth / 100 - width / 2)), (int) (mHeight / 2 - height + calculateDeltaY()), (int) (Math.max(getPaddingLeft() + width / 2, mProgress * mWidth / 100 + width / 2)), (int) (mHeight / 2 + height - height + calculateDeltaY())); int arrowHeight = (int) (arrowWidth / 1.5f); int radius = 8; Path path = new Path(); // Down arrow path.moveTo(r.left + r.width() / 2 - arrowWidth / 2, r.top + r.height() - arrowHeight); bubbleAnchorX = r.left + r.width() / 2; bubbleAnchorY = r.top + r.height(); path.lineTo(bubbleAnchorX, bubbleAnchorY); path.lineTo(r.left + r.width() / 2 + arrowWidth / 2, r.top + r.height() - arrowHeight); // Go to bottom-right path.lineTo(r.left + r.width() - radius, r.top + r.height() - arrowHeight); // Bottom-right arc path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top + r.height() - arrowHeight - 2 * radius, r.left + r.width(), r.top + r.height() - arrowHeight), 90, -90); // Go to upper-right path.lineTo(r.left + r.width(), r.top + arrowHeight); // Upper-right arc path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top, r.right, r.top + 2 * radius), 0, -90); // Go to upper-left path.lineTo(r.left + radius, r.top); // Upper-left arc path.arcTo(new RectF(r.left, r.top, r.left + 2 * radius, r.top + 2 * radius), 270, -90); // Go to bottom-left path.lineTo(r.left, r.top + r.height() - arrowHeight - radius); // Bottom-left arc path.arcTo(new RectF(r.left, r.top + r.height() - arrowHeight - 2 * radius, r.left + 2 * radius, r.top + r.height() - arrowHeight), 180, -90); path.close(); mPathBubble.set(path); }
From source file:chrisrenke.drawerarrowdrawable.DrawerArrowDrawable.java
public DrawerArrowDrawable(Resources resources, boolean rounded) { this.rounded = rounded; float density = resources.getDisplayMetrics().density; float strokeWidthPixel = STROKE_WIDTH_DP * density; halfStrokeWidthPixel = strokeWidthPixel / 2; linePaint = new Paint(SUBPIXEL_TEXT_FLAG | ANTI_ALIAS_FLAG); linePaint.setStrokeCap(rounded ? ROUND : BUTT); linePaint.setColor(BLACK);/*from w w w . j a v a 2 s . com*/ linePaint.setStyle(STROKE); linePaint.setStrokeWidth(strokeWidthPixel); int dimen = (int) (DIMEN_DP * density); bounds = new Rect(0, 0, dimen, dimen); Path first, second; JoinedPath joinedA, joinedB; // Top first = new Path(); first.moveTo(5.042f, 20f); first.rCubicTo(8.125f, -16.317f, 39.753f, -27.851f, 55.49f, -2.765f); second = new Path(); second.moveTo(60.531f, 17.235f); second.rCubicTo(11.301f, 18.015f, -3.699f, 46.083f, -23.725f, 43.456f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 20f); first.rCubicTo(4.457f, 16.75f, 1.512f, 37.982f, -22.557f, 42.699f); second = new Path(); second.moveTo(42.402f, 62.699f); second.cubicTo(18.333f, 67.418f, 8.807f, 45.646f, 8.807f, 32.823f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); topLine = new BridgingLine(joinedA, joinedB); // Middle first = new Path(); first.moveTo(5.042f, 35f); first.cubicTo(5.042f, 20.333f, 18.625f, 6.791f, 35f, 6.791f); second = new Path(); second.moveTo(35f, 6.791f); second.rCubicTo(16.083f, 0f, 26.853f, 16.702f, 26.853f, 28.209f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 35f); first.rCubicTo(0f, 10.926f, -8.709f, 26.416f, -29.958f, 26.416f); second = new Path(); second.moveTo(35f, 61.416f); second.rCubicTo(-7.5f, 0f, -23.946f, -8.211f, -23.946f, -26.416f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); middleLine = new BridgingLine(joinedA, joinedB); // Bottom first = new Path(); first.moveTo(5.042f, 50f); first.cubicTo(2.5f, 43.312f, 0.013f, 26.546f, 9.475f, 17.346f); second = new Path(); second.moveTo(9.475f, 17.346f); second.rCubicTo(9.462f, -9.2f, 24.188f, -10.353f, 27.326f, -8.245f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 50f); first.rCubicTo(-7.021f, 10.08f, -20.584f, 19.699f, -37.361f, 12.74f); second = new Path(); second.moveTo(27.598f, 62.699f); second.rCubicTo(-15.723f, -6.521f, -18.8f, -23.543f, -18.8f, -25.642f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); bottomLine = new BridgingLine(joinedA, joinedB); }
From source file:com.xueyu.view.DrawerArrowDrawable.java
@SuppressLint("ResourceAsColor") public DrawerArrowDrawable(Resources resources, boolean rounded) { this.rounded = rounded; float density = resources.getDisplayMetrics().density; float strokeWidthPixel = STROKE_WIDTH_DP * density; halfStrokeWidthPixel = strokeWidthPixel / 2; linePaint = new Paint(SUBPIXEL_TEXT_FLAG | ANTI_ALIAS_FLAG); linePaint.setStrokeCap(rounded ? ROUND : BUTT); linePaint.setColor(R.color.white);// www . j a va 2 s . co m linePaint.setStyle(STROKE); linePaint.setStrokeWidth(strokeWidthPixel); int dimen = (int) (DIMEN_DP * density); bounds = new Rect(0, 0, dimen, dimen); Path first, second; JoinedPath joinedA, joinedB; // Top first = new Path(); first.moveTo(5.042f, 20f); first.rCubicTo(8.125f, -16.317f, 39.753f, -27.851f, 55.49f, -2.765f); second = new Path(); second.moveTo(60.531f, 17.235f); second.rCubicTo(11.301f, 18.015f, -3.699f, 46.083f, -23.725f, 43.456f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 20f); first.rCubicTo(4.457f, 16.75f, 1.512f, 37.982f, -22.557f, 42.699f); second = new Path(); second.moveTo(42.402f, 62.699f); second.cubicTo(18.333f, 67.418f, 8.807f, 45.646f, 8.807f, 32.823f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); topLine = new BridgingLine(joinedA, joinedB); // Middle first = new Path(); first.moveTo(5.042f, 35f); first.cubicTo(5.042f, 20.333f, 18.625f, 6.791f, 35f, 6.791f); second = new Path(); second.moveTo(35f, 6.791f); second.rCubicTo(16.083f, 0f, 26.853f, 16.702f, 26.853f, 28.209f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 35f); first.rCubicTo(0f, 10.926f, -8.709f, 26.416f, -29.958f, 26.416f); second = new Path(); second.moveTo(35f, 61.416f); second.rCubicTo(-7.5f, 0f, -23.946f, -8.211f, -23.946f, -26.416f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); middleLine = new BridgingLine(joinedA, joinedB); // Bottom first = new Path(); first.moveTo(5.042f, 50f); first.cubicTo(2.5f, 43.312f, 0.013f, 26.546f, 9.475f, 17.346f); second = new Path(); second.moveTo(9.475f, 17.346f); second.rCubicTo(9.462f, -9.2f, 24.188f, -10.353f, 27.326f, -8.245f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 50f); first.rCubicTo(-7.021f, 10.08f, -20.584f, 19.699f, -37.361f, 12.74f); second = new Path(); second.moveTo(27.598f, 62.699f); second.rCubicTo(-15.723f, -6.521f, -18.8f, -23.543f, -18.8f, -25.642f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); bottomLine = new BridgingLine(joinedA, joinedB); }
From source file:com.example.nouri.playground.drawable.ArrowDrawable.java
public ArrowDrawable(Resources resources, boolean rounded) { this.rounded = rounded; float density = resources.getDisplayMetrics().density; float strokeWidthPixel = STROKE_WIDTH_DP * density; halfStrokeWidthPixel = strokeWidthPixel / 2; linePaint = new Paint(SUBPIXEL_TEXT_FLAG | ANTI_ALIAS_FLAG); linePaint.setStrokeCap(rounded ? ROUND : BUTT); linePaint.setColor(BLACK);/*w w w . j a va 2 s. c o m*/ linePaint.setStyle(STROKE); linePaint.setStrokeWidth(strokeWidthPixel); int dimen = (int) (DIMEN_DP * density); bounds = new Rect(0, 0, dimen, dimen); Path first, second; JoinedPath joinedA, joinedB; // Top first = new Path(); first.moveTo(5.042f, 20f); first.rCubicTo(8.125f, -16.317f, 39.753f, -27.851f, 55.49f, -2.765f); second = new Path(); second.moveTo(60.531f, 17.235f); second.rCubicTo(11.301f, 18.015f, -3.699f, 46.083f, -23.725f, 43.456f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 20f); first.rCubicTo(4.457f, 16.75f, 1.512f, 37.982f, -22.557f, 42.699f); second = new Path(); second.moveTo(42.402f, 62.699f); second.cubicTo(18.333f, 67.418f, 8.807f, 45.646f, 8.807f, 32.823f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); topLine = new BridgingLine(joinedA, joinedB); // Middle first = new Path(); first.moveTo(5.042f, 35f); first.cubicTo(5.042f, 20.333f, 18.625f, 6.791f, 35f, 6.791f); second = new Path(); second.moveTo(35f, 6.791f); second.rCubicTo(16.083f, 0f, 26.853f, 16.702f, 26.853f, 28.209f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 35f); first.rCubicTo(0f, 10.926f, -8.709f, 26.416f, -29.958f, 26.416f); second = new Path(); second.moveTo(35f, 61.416f); second.rCubicTo(-7.5f, 0f, -23.946f, -8.211f, -23.946f, -26.416f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); middleLine = new BridgingLine(joinedA, joinedB); // Bottom first = new Path(); first.moveTo(5.042f, 50f); first.cubicTo(2.5f, 43.312f, 0.013f, 26.546f, 9.475f, 17.346f); second = new Path(); second.moveTo(9.475f, 17.346f); second.rCubicTo(9.462f, -9.2f, 24.188f, -10.353f, 27.326f, -8.245f); scalePath(first, density); scalePath(second, density); joinedA = new JoinedPath(first, second); first = new Path(); first.moveTo(64.959f, 50f); first.rCubicTo(-7.021f, 10.08f, -20.584f, 19.699f, -37.361f, 12.74f); second = new Path(); second.moveTo(27.598f, 62.699f); second.rCubicTo(-15.723f, -6.521f, -18.8f, -23.543f, -18.8f, -25.642f); scalePath(first, density); scalePath(second, density); joinedB = new JoinedPath(first, second); bottomLine = new BridgingLine(joinedA, joinedB); }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawGaugeNeedle(Canvas canvas, int count, int Scale) { canvas.save(Canvas.MATRIX_SAVE_FLAG); float divisor = 360.0f / Scale; canvas.rotate((float) (divisor * count), 100, 100); //Inside/*ww w .j a va 2 s. c o m*/ Paint needleInsidePaint = new Paint(); needleInsidePaint.setStyle(Paint.Style.FILL_AND_STROKE); needleInsidePaint.setColor(Color.WHITE); needleInsidePaint.setStrokeWidth(4); needleInsidePaint.setAntiAlias(true); Paint needleEdgePaint = new Paint(); needleEdgePaint.setStyle(Paint.Style.STROKE); needleEdgePaint.setColor(Color.DKGRAY); needleEdgePaint.setStrokeWidth(0.5f); needleEdgePaint.setAntiAlias(true); canvas.drawOval(new RectF(95, 95, 105, 105), needleInsidePaint); canvas.drawOval(new RectF(95, 96, 105, 105), needleEdgePaint); Path needleInside = new Path(); needleInside.moveTo(98, 98); needleInside.lineTo(100, 20); needleInside.lineTo(102, 102); canvas.drawPath(needleInside, needleInsidePaint); Path needleEdge = new Path(); needleInside.moveTo(99, 99); needleInside.lineTo(99, 19); needleInside.lineTo(103, 103); canvas.drawPath(needleEdge, needleEdgePaint); canvas.restore(); }
From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java
/** * Draw checkbox/*from w w w. ja va 2 s.co m*/ * @param xLoc left location * @param yLoc top location * @param paint Paint object */ private void drawCheck(float xLoc, float yLoc, Paint paint) { float x1[] = { 2.3f, 6f, 11.5f }; float y1[] = { 8f, 11f, 2.2f }; Path path = new Path(); path.moveTo(xLoc + x1[0], yLoc + y1[0]); path.lineTo(xLoc + x1[1], yLoc + y1[1]); path.lineTo(xLoc + x1[2], yLoc + y1[2]); paint.setStrokeWidth(3); can.drawPath(path, paint); }