Java Code Examples for android.graphics.Canvas#drawTextOnPath()
The following examples show how to use
android.graphics.Canvas#drawTextOnPath() .
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: ArrowDownloadButton.java From react-native-download-button with MIT License | 6 votes |
/** * under loading * * @param canvas Target Canvas */ private void loading(Canvas canvas) { Point currentPoint = triPoints.get(0); Point nextPoint; for (int i = 0; i < TRI_POINT_NUMBER; i++) { Point p = triPoints.get(i); p.x = (x - 3 * radius / 4) + triStep * i; p.y = y + calculateTri(TIME_STEP * i, currentTime); } for (int i = 1; i < TRI_POINT_NUMBER; i++) { nextPoint = triPoints.get(i); triPath.reset(); triPath.moveTo(currentPoint.x, currentPoint.y); triPath.lineTo(nextPoint.x, nextPoint.y); canvas.drawCircle(nextPoint.x, nextPoint.y, smallRadius, smallPaint); canvas.drawPath(triPath, triPaint); currentPoint = nextPoint; } textPath.moveTo(x - textSize, y + textY); textPath.lineTo(x + textSize, y + textY); canvas.drawTextOnPath((int) progress + "%", textPath, 0, 0, textPaint); currentTime = (int) (currentTime + TIME_STEP); float sweepAngle = (progress / PROGRESS * ANGLE); canvas.drawArc(oval, 270, 0 - sweepAngle, false, loadingPaint); postInvalidateDelayed(DURATION); }
Example 2
Source File: WaveTextView.java From WanAndroid with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { //让字体在中间 canvas.translate((float) (getWidth() - mTextWidth) / 2, (float) getHeight() / 2 + mTextCenter); mTextPath.reset(); LogUtil.d(TAG, "onDraw(), width = " + canvas.getWidth() + ", mTextWidth = " + mTextWidth); for(int i = 0; i <= SAMPLING_SIZE; i++){ float y = calculateY(mMapX[i]); float x = mSamplingX[i]; LogUtil.d(TAG, "onDraw() " + ", samplingX = " + mSamplingX[i] + ", mapX = " + mMapX[i] + ", x = " + x + ", y = " + y); if(i == 0){ mTextPath.moveTo(x, y); }else { mTextPath.lineTo(x, y); } } canvas.drawTextOnPath(mText, mTextPath, 0, 0, mTextPaint); }
Example 3
Source File: RxRotateBarBasic.java From RxTools-master with Apache License 2.0 | 6 votes |
protected void drawTitle(Canvas canvas, int alpha) { if (alpha > 0 && isShowTitle) { Path path = new Path(); float circumference = (float) (Math.PI * (outlineOval.right - outlineOval.left)); float textAngle = (360 / circumference) * titlePaint.measureText(getTitle()); float startAngle = mStartAngle + mSweepAngle / 2 - textAngle / 2; if (isSingle) { // when single, draw 360 the path will be a circle path.addArc(outlineOval, startAngle - mSweepAngle / 2, mSweepAngle / 2); } else { path.addArc(outlineOval, startAngle, mSweepAngle); } titlePaint.setAlpha(alpha); canvas.drawTextOnPath(mTitle, path, 0, textWidth / 3, titlePaint); } }
Example 4
Source File: CircleIndicator.java From android with MIT License | 6 votes |
private void drawCircleContent(Canvas canvas, IndicatorItem item, RectF oval, float perAngle, float textRadius, Path path, Paint textPaint, Paint circlePaint) { circlePaint.setColor(item.color); float startAngle = CIRCLE_START_ANGLE; startAngle += perAngle * (item.start - mStartIndicator); float endAngle = perAngle * (item.end - item.start); canvas.drawArc(oval, startAngle, endAngle, false, circlePaint); float circlePathLength = ViewUtils.getCirclePathLength(textRadius, (startAngle + endAngle / 2)); circlePathLength -= ViewUtils.getTextWidth(textPaint, item.value) / 2; canvas.drawTextOnPath(String.valueOf(item.value), path, circlePathLength, 0, textPaint); }
Example 5
Source File: LabelViewHelper.java From TLint with Apache License 2.0 | 6 votes |
public void onDraw(Canvas canvas, int measuredWidth, int measuredHeight) { if (!visual) { return; } float actualDistance = distance + height / 2; calcOffset(actualDistance, measuredWidth, measuredHeight); rectPaint.setColor(backgroundColor); rectPaint.setStrokeWidth(height); rectPath.reset(); rectPath.moveTo(startPosX, startPosY); rectPath.lineTo(endPosX, endPosY); canvas.drawPath(rectPath, rectPaint); textPaint.setTextSize(textSize); textPaint.setColor(textColor); textPaint.getTextBounds(text, 0, text.length(), textBound); canvas.drawTextOnPath(text, rectPath, (1.4142135f * actualDistance) / 2 - textBound.width() / 2, textBound.height() / 2, textPaint); }
Example 6
Source File: RotateTextImageView.java From Social with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if(bitmap==null) return; paint.reset(); // 消除锯齿 paint.setAntiAlias(true); paint.setFlags(Paint.ANTI_ALIAS_FLAG); canvas.setDrawFilter(pfdf); canvas.drawBitmap(bitmap, 0, 0, paint); newHeight = bitmap.getHeight(); newWidth = bitmap.getWidth(); calculatePoints(); // 添加阴影 path.reset(); path.moveTo(f[0], f[1]); path.lineTo(f[2], f[3]); path.lineTo(f[4], f[5]); path.lineTo(f[6], f[7]); path.close(); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setColor(Color.parseColor("#96ffffff")); canvas.drawPath(path, paint); // 添加字符 if (text != null && !text.equals("")) { path.reset(); paint.setTextSize(18); float width = paint.measureText(text); path.moveTo((f[0] + f[2]) / 2, (f[1] + f[3]) / 2); path.lineTo((f[4] + f[6]) / 2, (f[5] + f[7]) / 2); paint.setColor(Color.parseColor("#2b2b2b")); canvas.drawTextOnPath(text, path, (oriWidth - width) / 2, 3, paint); } layout(0, 0, newWidth, newHeight); }
Example 7
Source File: VerticalTextView.java From android-project-wo2b with Apache License 2.0 | 5 votes |
private void drawText(Canvas canvas, String text) { this.mHeight = getHeight(); this.mPath.moveTo(getWidth() - (2.0F * getResources().getDisplayMetrics().density), this.mHeight); this.mPath.lineTo(getWidth() - (2.0F * getResources().getDisplayMetrics().density), 0.0F); canvas.drawTextOnPath(text, this.mPath, 0.0F, 0.0F, this.mPaint); }
Example 8
Source File: PathTextView.java From MyBlogDemo with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { float dX = (left ? radioCenterX * fraction : radioCenterX * fraction * -1.0f);//相对于中心点 0 的水平偏移量 path.reset(); float defaultX = 0; path.moveTo(defaultX, defaultY); radioCenterX = (defaultX + textWidth) / 2.0f; if (currentOffset != -1) { path.quadTo(dXXX == 0 ? radioCenterX : radioCenterX + dXXX, currentOffset, textWidth, defaultY); } else { path.lineTo(textWidth, defaultY); } canvas.drawTextOnPath(TEST, path, 0, 0, textPaint); if (currentBitmap != null) { if (!isUp) { canvas.rotate(360 * fraction, radioCenterX, radioCenterY); canvas.drawBitmap(currentBitmap, radioCenterX - currentBitmap.getWidth() / 2.0f, radioCenterY - currentBitmap.getHeight() / 2.0f, null); return; } switch (Mode) { case Default: canvas.rotate(360 * fraction, radioCenterX, radioCenterY); canvas.drawBitmap(currentBitmap, radioCenterX - currentBitmap.getWidth() / 2.0f, radioCenterY - currentBitmap.getHeight() / 2.0f, null); break; case Bounce: case Oblique: canvas.rotate(360 * fraction, radioCenterX + dX, radioCenterY); canvas.translate(dX, 0); int i1 = blendColors(Color.WHITE, Color.TRANSPARENT, fraction); bitmapPaint.setColor(i1); canvas.drawBitmap(currentBitmap, radioCenterX - currentBitmap.getWidth() / 2.0f, radioCenterY - currentBitmap.getHeight() / 2.0f, bitmapPaint); break; } } }
Example 9
Source File: TextDrawable.java From iview-android-tv with MIT License | 5 votes |
@Override public void draw(Canvas canvas) { final Rect bounds = getBounds(); final int count = canvas.save(); canvas.translate(bounds.left, bounds.top); if (mTextPath == null) { //Allow the layout to draw the text mTextLayout.draw(canvas); } else { //Draw directly on the canvas using the supplied path canvas.drawTextOnPath(mText.toString(), mTextPath, 0, 0, mTextPaint); } canvas.restoreToCount(count); }
Example 10
Source File: CurvedTextView.java From Android-CircleProgressIndicator with MIT License | 5 votes |
@Override protected void onDraw(Canvas canvas) { int centerXOnView = getWidth() / 2; int centerYOnView = getHeight() / 2; int viewXCenterOnScreen = getLeft() + centerXOnView; int viewYCenterOnScreen = getTop() + centerYOnView; float threeDpPad = getResources().getDimension(R.dimen.curvedTextPadding); float rad = getResources().getDimension(R.dimen.curvedTextRadius); int leftOffset = (int) (viewXCenterOnScreen - (rad + (threeDpPad * 4))); int topOffset = (int) (viewYCenterOnScreen - (rad + (threeDpPad * 3))); int rightOffset = (int) (viewXCenterOnScreen + (rad + (threeDpPad * 4))); int bottomOffset = (int) (viewYCenterOnScreen + (rad + threeDpPad)); RectF oval = new RectF(leftOffset, topOffset, rightOffset, bottomOffset); int textLength = getText().length(); if ((textLength % 2) != 0) { textLength = textLength + 1; } this.myArc.addArc(oval, -90 - (textLength * 2), 90 + textLength + 10); canvas.drawTextOnPath((String) getText(), this.myArc, 0, 10, this.mPaintText); }
Example 11
Source File: TextDrawable.java From CryptoBuddy with GNU Affero General Public License v3.0 | 5 votes |
@Override public void draw(Canvas canvas) { final Rect bounds = getBounds(); final int count = canvas.save(); canvas.translate(bounds.left, bounds.top); if (mTextPath == null) { //Allow the layout to draw the text mTextLayout.draw(canvas); } else { //Draw directly on the canvas using the supplied path canvas.drawTextOnPath(mText.toString(), mTextPath, 0, 0, mTextPaint); } canvas.restoreToCount(count); }
Example 12
Source File: LabelImageView.java From android-open-source-project-analysis with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //计算路径 calculatePath(getMeasuredWidth(), getMeasuredHeight()); canvas.drawPath(pathBackground, backgroundPaint); canvas.drawTextOnPath("Hot", pathText, 100, -20, textPaint); }
Example 13
Source File: LabelViewHelper.java From labelview with Apache License 2.0 | 5 votes |
public void onDraw(Canvas canvas, int measuredWidth, int measuredHeight) { if (!visual || text == null) { return; } float actualDistance = distance + height / 2; calcOffset(measuredWidth, measuredHeight); rectPaint.setColor(backgroundColor); if (alpha != 0) { rectPaint.setAlpha(alpha); } rectStrokePaint.setColor(strokeColor); rectStrokePaint.setStrokeWidth(strokeWidth); canvas.drawPath(rectPath, rectPaint); canvas.drawPath(rectPath, rectStrokePaint); textPaint.setTextSize(textSize); textPaint.setColor(textColor); textPaint.getTextBounds(text, 0, text.length(), textBound); textPaint.setTypeface(Typeface.defaultFromStyle(textStyle)); float begin_w_offset = (1.4142135f * actualDistance) / 2 - textBound.width() / 2; if (begin_w_offset < 0) begin_w_offset = 0; canvas.drawTextOnPath(text, textPath, begin_w_offset, textBound.height() / 2, textPaint); }
Example 14
Source File: GpsStatusView.java From satstat with GNU General Public License v3.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { int cx = mW / 2; int cy = mH / 2; //Log.d("GpsStatusView", String.format("Drawing on a %dx%d canvas", w, h)); canvas.translate(cx, cy); canvas.rotate(-mRotation); canvas.drawCircle(0, 0, mW * 0.37125f, gridBorderPaint); canvas.drawLine(-mW * 0.405f, 0, mW * 0.405f, 0, gridPaint); canvas.drawLine(0, -mH * 0.405f, 0, mH * 0.405f, gridPaint); canvas.drawCircle(0, 0, mW * 0.405f, gridPaint); canvas.drawCircle(0, 0, mW * 0.27f, gridPaint); canvas.drawCircle(0, 0, mW * 0.135f, gridPaint); canvas.drawPath(northArrow, northPaint); canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_N), labelPathN, 0, -labelPaint.descent(), labelPaint); canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_S), labelPathS, 0, -labelPaint.descent(), labelPaint); canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_E), labelPathE, 0, -labelPaint.descent(), labelPaint); canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_W), labelPathW, 0, -labelPaint.descent(), labelPaint); if (mSats != null) { for (GpsSatellite sat : mSats) { drawSat(canvas, sat.getPrn(), sat.getAzimuth(), sat.getElevation(), sat.getSnr(), sat.usedInFix()); } } }
Example 15
Source File: WheelView.java From LuckyWheel_Android with MIT License | 5 votes |
/** * Function to draw text below image * * @param canvas Canvas to draw * @param tempAngle Temporary angle * @param sweepAngle current index angle * @param text string to show */ private void drawText(Canvas canvas, float tempAngle, float sweepAngle, String text) { Path path = new Path(); path.addArc(range, tempAngle, sweepAngle); float textWidth = textPaint.measureText(text); int hOffset = (int) (radius * Math.PI / mWheelItems.size() / 2 - textWidth / 2); int vOffset = (radius / 2 / 3) - 3; canvas.drawTextOnPath(text, path, hOffset, vOffset, textPaint); }
Example 16
Source File: SimpleTagImageView.java From MousePaint with MIT License | 5 votes |
@Override protected void onDraw(@SuppressWarnings("NullableProblems") Canvas mCanvas) { if (mRoundRadius == 0) { super.onDraw(mCanvas); } else { Drawable d = getDrawable(); if (d == null) return; if (d.getIntrinsicWidth() == 0 || d.getIntrinsicHeight() == 0) return; setupBitmapPaint(); mRoundRect.set(getPaddingLeft(), getPaddingTop(), getMeasuredWidth() - getPaddingRight(), getMeasuredHeight() - getPaddingBottom()); mCanvas.drawRoundRect(mRoundRect, mRoundRadius, mRoundRadius, mBitmapPaint); } if (mTagWidth > 0 && mTagEnable) { float rDistance = mCornerDistance + mTagWidth / 2; chooseTagOrientation(rDistance); mTextPaint.setTextSize(mTagTextSize); mTextPaint.getTextBounds(mTagText, 0, mTagText.length(), mTagTextBound); mPaint.setDither(true); mPaint.setAntiAlias(true); mPaint.setColor(mTagBackgroundColor); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.SQUARE); mPaint.setStrokeWidth(mTagWidth); mPath.reset(); mPath.moveTo(startPoint.x, startPoint.y); mPath.lineTo(endPoint.x, endPoint.y); mCanvas.drawPath(mPath, mPaint); mTextPaint.setColor(mTagTextColor); mTextPaint.setTextSize(mTagTextSize); mTextPaint.setAntiAlias(true); // 斜边长度 float hypotenuse = THE_SQUARE_ROOT_OF_2 * rDistance; mCanvas.drawTextOnPath(mTagText, mPath, hypotenuse / 2 - mTagTextBound.width() / 2, mTagTextBound.height() / 2, mTextPaint); } }
Example 17
Source File: GpsSnrView.java From satstat with GNU General Public License v3.0 | 5 votes |
/** * Draws the label for a satellite range. * * @param canvas The {@code Canvas} on which the SNR view will appear. * @param label The text to be displayed (the description of the satellite range, such as "GPS", "GLONASS" or "Beidou") * @param startBar The NMEA ID of the first satellite in the range * @param rangeBars The number of NMEA IDs in the range (ranges must be contiguous) * @param numBars Total number of SNR bars being displayed, as returned by getNumBars() */ private void drawLabel(Canvas canvas, String label, int startBar, int rangeBars, int numBars) { int offsetBars = getGridPos(startBar) - 1; int w = getWidth(); int h = getHeight(); Path labelPath = new Path(); labelPath.reset(); labelPath.moveTo(gridStrokeWidth + offsetBars * (w - gridStrokeWidth) / numBars, h); labelPath.rLineTo(rangeBars * (w - gridStrokeWidth) / numBars - gridStrokeWidth, 0); canvas.drawTextOnPath(label, labelPath, 0, -labelPaint.descent(), labelPaint); }
Example 18
Source File: RadialMenuView.java From talkback with Apache License 2.0 | 4 votes |
private void drawCorner(Canvas canvas, int width, int height, float center, int i) { final RadialMenuItem wedge = rootMenu.getCorner(i); if (wedge == null || !wedge.isVisible()) { return; } final float rotation = RadialMenu.getCornerRotation(i); final PointF cornerLocation = RadialMenu.getCornerLocation(i); if (cornerLocation == null) { return; } final float cornerX = (cornerLocation.x * width); final float cornerY = (cornerLocation.y * height); final String title = wedge.getTitle().toString(); final boolean selected = wedge.equals(focusedItem); // Apply the appropriate color filters. if (wedge.hasSubMenu()) { paint.setColorFilter(subMenuFilter); } else { paint.setColorFilter(null); } wedge.offset = rotation; tempMatrix.reset(); tempMatrix.setRotate(rotation, center, center); tempMatrix.postTranslate((cornerX - center), (cornerY - center)); canvas.setMatrix(tempMatrix); paint.setStyle(Style.FILL); paint.setColor(selected ? selectionColor : cornerFillColor); paint.setShadowLayer(shadowRadius, 0, 0, (selected ? selectionShadowColor : textShadowColor)); canvas.drawPath(cachedCornerPath, paint); paint.setShadowLayer(0, 0, 0, 0); paint.setStyle(Style.FILL); paint.setColor(selected ? selectionTextFillColor : cornerTextFillColor); paint.setTextAlign(Align.CENTER); paint.setTextSize(textSize); paint.setShadowLayer(textShadowRadius, 0, 0, textShadowColor); final String renderText = getEllipsizedText(paint, title, cachedCornerPathWidth); // Orient text differently depending on the angle. if (((rotation < 90) && (rotation > -90)) || (rotation > 270)) { canvas.drawTextOnPath(renderText, cachedCornerPathReverse, 0, (2 * textSize), paint); } else { canvas.drawTextOnPath(renderText, cachedCornerPath, 0, -textSize, paint); } paint.setShadowLayer(0, 0, 0, 0); paint.setColorFilter(null); }
Example 19
Source File: RulerDrawable.java From spline with Apache License 2.0 | 4 votes |
@Override public void draw(@NonNull Canvas canvas) { Rect bounds = getBounds(); boolean isVertical = bounds.height() > bounds.width(); int borderX1, borderX2, borderY1, borderY2; int segmentSpacing = 50; int numSegments; boolean validHighlight = mHighlightStart < Float.MAX_VALUE && mHighlightSize > -Float.MAX_VALUE; if (isVertical) { borderX1 = borderX2 = (int) (bounds.width() - mDensity / 2); borderY1 = 0; borderY2 = bounds.height(); numSegments = bounds.height() / segmentSpacing; if (validHighlight) { canvas.drawRect( 0, mHighlightStart + mViewportStart, bounds.width(), mHighlightStart + mHighlightSize + mViewportStart, mHighlightPaint ); } } else { borderX1 = 0; borderX2 = bounds.width(); borderY1 = borderY2 = (int) (bounds.height() - mDensity / 2); numSegments = bounds.width() / segmentSpacing; if (validHighlight) { canvas.drawRect( mHighlightStart + mViewportStart, 0, mHighlightStart + mHighlightSize + mViewportStart, bounds.height(), mHighlightPaint ); } } int offset = Math.round(mViewportStart % segmentSpacing); int segmentOffset = (int) (mViewportStart / segmentSpacing); for (int i = -1; i < numSegments + 2; i++) { int h = 4; int idx = i - segmentOffset; if (idx % 2 == 0) { h = 9; } if (idx % 4 == 0) { if (isVertical) { mVerticalTextPath.reset(); mVerticalTextPath.moveTo( bounds.width() / 2, i * segmentSpacing + offset + 25 * mDensity); mVerticalTextPath.lineTo( bounds.width() / 2, (i - 1) * segmentSpacing + offset); canvas.drawTextOnPath(Integer.toString(idx * segmentSpacing), mVerticalTextPath, 0, 0, mTextPaint); } else { canvas.drawText(Integer.toString(idx * segmentSpacing), i * segmentSpacing + offset, bounds.height() / 2, mTextPaint); } } if (isVertical) { canvas.drawLine( bounds.width() - (h + 4) * mDensity, i * segmentSpacing + offset, bounds.width() - 4 * mDensity, i * segmentSpacing + offset, mLinePaint); } else { canvas.drawLine( i * segmentSpacing + offset, bounds.height() - (h + 4) * mDensity, i * segmentSpacing + offset, bounds.height() - 4 * mDensity, mLinePaint); } } canvas.drawLine(borderX1, borderY1, borderX2, borderY2, mLinePaint); }
Example 20
Source File: RadialMenuView.java From talkback with Apache License 2.0 | 4 votes |
private void drawWedge(Canvas canvas, float center, int i, RadialMenu menu, float degrees) { final float offset = subMenu != null ? subMenuOffset : rootMenuOffset; final RadialMenuItem wedge = menu.getItem(i); final String title = wedge.getTitle().toString(); final float rotation = ((degrees * i) + offset); final boolean selected = wedge.equals(focusedItem); // Apply the appropriate color filters. if (wedge.hasSubMenu()) { paint.setColorFilter(subMenuFilter); } else { paint.setColorFilter(null); } wedge.offset = rotation; tempMatrix.reset(); tempMatrix.setRotate(rotation, center, center); tempMatrix.postTranslate((this.center.x - center), (this.center.y - center)); canvas.setMatrix(tempMatrix); paint.setStyle(Style.FILL); paint.setColor(selected ? selectionColor : outerFillColor); paint.setShadowLayer(shadowRadius, 0, 0, (selected ? selectionShadowColor : textShadowColor)); canvas.drawPath(cachedOuterPath, paint); paint.setShadowLayer(0, 0, 0, 0); paint.setStyle(Style.FILL); paint.setColor(selected ? selectionTextFillColor : textFillColor); paint.setTextAlign(Align.CENTER); paint.setTextSize(textSize); paint.setShadowLayer(textShadowRadius, 0, 0, textShadowColor); final String renderText = getEllipsizedText(paint, title, cachedOuterPathWidth); // Orient text differently depending on the angle. if ((rotation < 90) || (rotation > 270)) { canvas.drawTextOnPath(renderText, cachedOuterPathReverse, 0, (2 * textSize), paint); } else { canvas.drawTextOnPath(renderText, cachedOuterPath, 0, -textSize, paint); } paint.setShadowLayer(0, 0, 0, 0); paint.setColorFilter(null); }