opt
This commit is contained in:
@@ -3,10 +3,13 @@ package com.mogo.module.media.widget;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.SweepGradient;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
@@ -78,7 +81,7 @@ public class CircleNumberProgress extends View {
|
||||
//中间圆的背景颜色 默认为浅紫色
|
||||
paintUndoneColor = typedArray.getColor(R.styleable.PercentageRing_circleBackground, 0xffafb4db);
|
||||
//外圆环的颜色 默认为深紫色
|
||||
paintDoneColor = typedArray.getColor(R.styleable.PercentageRing_ringColor, 0xff6950a1);
|
||||
// paintDoneColor = typedArray.getColor(R.styleable.PercentageRing_ringColor, Color.parseColor("#e6fffff"));
|
||||
|
||||
// 构造器中初始化数据
|
||||
initData();
|
||||
@@ -100,17 +103,20 @@ public class CircleNumberProgress extends View {
|
||||
paintUndone.setStyle(Paint.Style.STROKE);
|
||||
|
||||
// 已经完成进度条的画笔的属性
|
||||
paintDone.setColor(paintDoneColor);
|
||||
// paintDone.setColor(paintDoneColor);
|
||||
paintDone.setStrokeWidth(paintProgressWidthPx);
|
||||
paintDone.setAntiAlias(true);
|
||||
paintDone.setStyle(Paint.Style.STROKE);
|
||||
|
||||
// 文字的画笔的属性
|
||||
// paintText.setColor(paintTextColor);
|
||||
// paintText.setTextSize(paintTextSizePx);
|
||||
// paintText.setAntiAlias(true);
|
||||
// paintText.setStyle(Paint.Style.STROKE);
|
||||
// paintText.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
SweepGradient linearGradient = new SweepGradient((getMeasuredWidth() - 40)/2,(getMeasuredHeight() - 40)/2,
|
||||
new int[]{(Color.parseColor("#B3ffffff")), Color.parseColor("#F2ffffff")}, null);
|
||||
|
||||
// SweepGradient linearGradient = new SweepGradient((getMeasuredWidth())/2,(getMeasuredHeight())/2,new int[]{Color.GREEN, Color.WHITE}, null);
|
||||
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.setRotate(180, getMeasuredWidth()/2, getMeasuredHeight()/2);
|
||||
linearGradient.setLocalMatrix(matrix);
|
||||
paintDone.setShader(linearGradient);
|
||||
|
||||
}
|
||||
|
||||
@@ -147,7 +153,6 @@ public class CircleNumberProgress extends View {
|
||||
|
||||
// 比较文字高度和圆环宽度,如果文字高度较大,那么文字将突破圆环,否则,圆环会把文字包裹在内部
|
||||
Rect rect = new Rect();
|
||||
// paintText.getTextBounds("100%", 0, "100%".length(), rect);
|
||||
int textHeight = rect.height();
|
||||
|
||||
// 得到圆环的中间半径(外径和内径平均值)
|
||||
@@ -156,14 +161,6 @@ public class CircleNumberProgress extends View {
|
||||
rectF.top = viewCenterY - radiusArc;
|
||||
rectF.right = viewCenterX + radiusArc;
|
||||
rectF.bottom = viewCenterY + radiusArc;
|
||||
|
||||
// 文字所依赖路径圆弧的半径
|
||||
radiusText = radiusArc - textHeight / 2;
|
||||
rectF2.left = viewCenterX - radiusText;
|
||||
rectF2.top = viewCenterY - radiusText;
|
||||
rectF2.right = viewCenterX + radiusText;
|
||||
rectF2.bottom = viewCenterY + radiusText;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,37 +173,6 @@ public class CircleNumberProgress extends View {
|
||||
// 画已经完成进度的圆弧 从-90度开始,即从圆环顶部开始
|
||||
canvas.drawArc(rectF, -90, progress / 100.0f * 360, false, paintDone);
|
||||
|
||||
// 为文字所在路径添加一段圆弧轨迹,进度为0%-9%时应该最短,进度为10%-99%时应该边长,进度为100%时应该最长
|
||||
// 这样才能保证文字和圆弧的进度一致,不会出现超前或者滞后的情况
|
||||
|
||||
// 要画的文字
|
||||
String text = progress + "%";
|
||||
|
||||
// 存储字符所有字符所占宽度的数组
|
||||
float[] widths = new float[text.length()];
|
||||
|
||||
// 得到所有字符所占的宽度
|
||||
// paintText.getTextWidths(text, 0, text.length(), widths);
|
||||
|
||||
// 所有字符所占宽度之和
|
||||
float textWidth = 0;
|
||||
for (float f : widths) {
|
||||
textWidth += f;
|
||||
}
|
||||
|
||||
// 根据长度得到路径对应的扫过的角度
|
||||
// width = sweepAngle * 2 * π * R / 360 ; sweepAngle = width * 360 / 2 /
|
||||
// π / R
|
||||
float sweepAngle = (float) (textWidth * 360 / 2 / Math.PI / radiusText);
|
||||
|
||||
// 添加路径
|
||||
path.addArc(rectF2, progress * 3.6f - 90.0f - sweepAngle / 2.0f, sweepAngle);
|
||||
|
||||
// 绘制进度的文字
|
||||
// canvas.drawTextOnPath(text, path, 0, 0, paintText);
|
||||
|
||||
// 重置路径
|
||||
path.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:circleBackground="@color/modules_media_music_bg_color"
|
||||
app:ringColor="@color/modules_media_music_circle_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
<!-- app:ringColor="@color/modules_media_music_circle_color"-->
|
||||
|
||||
<!-- <com.mogo.module.media.widget.PercentageRingView-->
|
||||
<!-- android:id="@+id/window_circle_bg"-->
|
||||
|
||||
Reference in New Issue
Block a user