[Modify]声音签名进度条
This commit is contained in:
@@ -345,6 +345,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|||||||
MAX_RECORD_VOICE_DURATION
|
MAX_RECORD_VOICE_DURATION
|
||||||
)
|
)
|
||||||
chronometer.text = showStr
|
chronometer.text = showStr
|
||||||
|
binding.roundProgress.setProgress(second)
|
||||||
if (second >= MAX_RECORD_VOICE_DURATION) {
|
if (second >= MAX_RECORD_VOICE_DURATION) {
|
||||||
soundViewModel.stopRecord() // 录制时长超过上限时,停止录制
|
soundViewModel.stopRecord() // 录制时长超过上限时,停止录制
|
||||||
}
|
}
|
||||||
@@ -381,6 +382,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|||||||
duration,
|
duration,
|
||||||
MAX_RECORD_VOICE_DURATION
|
MAX_RECORD_VOICE_DURATION
|
||||||
)
|
)
|
||||||
|
binding.roundProgress.setProgress(duration)
|
||||||
binding.tvSoundTime.text = showStr
|
binding.tvSoundTime.text = showStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,10 +54,8 @@ public class AudioPlayerHelper {
|
|||||||
endPlay();
|
endPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
private boolean preparing = false;
|
private boolean preparing = false;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private boolean pause = false;
|
private boolean pause = false;
|
||||||
|
|
||||||
public void playInThread(String filePath, OnPlayListener l) {
|
public void playInThread(String filePath, OnPlayListener l) {
|
||||||
|
@@ -0,0 +1,165 @@
|
|||||||
|
package com.yizhuan.erban.audio.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.RectF;
|
||||||
|
import android.graphics.SweepGradient;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.yizhuan.erban.R;
|
||||||
|
|
||||||
|
public class RoundProgressView extends View {
|
||||||
|
// 画实心圆的画笔
|
||||||
|
private Paint mCirclePaint;
|
||||||
|
// 画圆环的画笔
|
||||||
|
private Paint mRingPaint;
|
||||||
|
// 画圆环的画笔背景色
|
||||||
|
private Paint mRingPaintBg;
|
||||||
|
// 画字体的画笔
|
||||||
|
private Paint mTextPaint;
|
||||||
|
// 圆形颜色
|
||||||
|
private int mCircleColor;
|
||||||
|
// 圆环颜色
|
||||||
|
private int mRingColor;
|
||||||
|
// 圆环背景颜色
|
||||||
|
private int mRingBgColor;
|
||||||
|
// 半径
|
||||||
|
private float mRadius;
|
||||||
|
// 圆环半径
|
||||||
|
private float mRingRadius;
|
||||||
|
// 圆环宽度
|
||||||
|
private float mStrokeWidth;
|
||||||
|
// 圆心x坐标
|
||||||
|
private int mXCenter;
|
||||||
|
// 圆心y坐标
|
||||||
|
private int mYCenter;
|
||||||
|
// 字的长度
|
||||||
|
private float mTxtWidth;
|
||||||
|
// 字的高度
|
||||||
|
private float mTxtHeight;
|
||||||
|
// 总进度
|
||||||
|
private int mTotalProgress = 60;
|
||||||
|
// 当前进度
|
||||||
|
private int mProgress;
|
||||||
|
|
||||||
|
private String string;
|
||||||
|
|
||||||
|
public RoundProgressView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
// 获取自定义的属性
|
||||||
|
initAttrs(context, attrs);
|
||||||
|
initVariable();
|
||||||
|
}
|
||||||
|
|
||||||
|
//属性
|
||||||
|
private void initAttrs(Context context, AttributeSet attrs) {
|
||||||
|
TypedArray typeArray = context.getTheme().obtainStyledAttributes(attrs,
|
||||||
|
R.styleable.RoundProgressView, 0, 0);
|
||||||
|
mRadius = typeArray.getDimension(R.styleable.RoundProgressView_round_radius, 80);
|
||||||
|
mStrokeWidth = typeArray.getDimension(R.styleable.RoundProgressView_round_strokeWidth, 10);
|
||||||
|
mCircleColor = typeArray.getColor(R.styleable.RoundProgressView_round_circleColor, 0xFFFFFFFF);
|
||||||
|
mRingColor = typeArray.getColor(R.styleable.RoundProgressView_round_ringColor, 0xFFFFFFFF);
|
||||||
|
mRingBgColor = typeArray.getColor(R.styleable.RoundProgressView_round_ringBgColor, 0xFFFFFFFF);
|
||||||
|
|
||||||
|
mRingRadius = mRadius + mStrokeWidth / 2;
|
||||||
|
}
|
||||||
|
RectF oval;
|
||||||
|
//初始化画笔
|
||||||
|
private void initVariable() {
|
||||||
|
oval = new RectF();
|
||||||
|
//内圆
|
||||||
|
mCirclePaint = new Paint();
|
||||||
|
mCirclePaint.setAntiAlias(true);
|
||||||
|
mCirclePaint.setColor(mCircleColor);
|
||||||
|
mCirclePaint.setStyle(Paint.Style.FILL);
|
||||||
|
mCirclePaint.setStrokeCap(Paint.Cap.ROUND);
|
||||||
|
|
||||||
|
//外圆弧背景
|
||||||
|
mRingPaintBg = new Paint();
|
||||||
|
mRingPaintBg.setAntiAlias(true);
|
||||||
|
mRingPaintBg.setColor(mRingBgColor);
|
||||||
|
mRingPaintBg.setStyle(Paint.Style.STROKE);
|
||||||
|
mRingPaintBg.setStrokeWidth(mStrokeWidth);
|
||||||
|
|
||||||
|
|
||||||
|
//外圆弧
|
||||||
|
mRingPaint = new Paint();
|
||||||
|
mRingPaint.setAntiAlias(true);
|
||||||
|
//mRingPaint.setColor(mRingColor);
|
||||||
|
mRingPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
mRingPaint.setStrokeWidth(mStrokeWidth);
|
||||||
|
mRingPaint.setStrokeCap(Paint.Cap.ROUND);//设置线冒样式,有圆 有方
|
||||||
|
|
||||||
|
|
||||||
|
//中间字
|
||||||
|
mTextPaint = new Paint();
|
||||||
|
mTextPaint.setAntiAlias(true);
|
||||||
|
mTextPaint.setStyle(Paint.Style.FILL);
|
||||||
|
mTextPaint.setColor(mRingColor);
|
||||||
|
mTextPaint.setTextSize(mRadius / 2);
|
||||||
|
|
||||||
|
Paint.FontMetrics fm = mTextPaint.getFontMetrics();
|
||||||
|
mTxtHeight = (int) Math.ceil(fm.descent - fm.ascent);
|
||||||
|
}
|
||||||
|
SweepGradient sweepGradient;
|
||||||
|
//画图
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
mXCenter = getWidth() / 2;
|
||||||
|
mYCenter = getHeight() / 2;
|
||||||
|
|
||||||
|
//内圆
|
||||||
|
canvas.drawCircle(mXCenter, mYCenter, mRadius, mCirclePaint);
|
||||||
|
|
||||||
|
//外圆弧背景
|
||||||
|
RectF oval1 = new RectF();
|
||||||
|
oval1.left = (mXCenter - mRingRadius);
|
||||||
|
oval1.top = (mYCenter - mRingRadius);
|
||||||
|
oval1.right = mRingRadius * 2 + (mXCenter - mRingRadius);
|
||||||
|
oval1.bottom = mRingRadius * 2 + (mYCenter - mRingRadius);
|
||||||
|
canvas.drawArc(oval1, 0, 360, false, mRingPaintBg); //圆弧所在的椭圆对象、圆弧的起始角度、圆弧的角度、是否显示半径连线
|
||||||
|
|
||||||
|
//外圆弧
|
||||||
|
if (mProgress > 0 ) {
|
||||||
|
|
||||||
|
oval.left = (mXCenter - mRingRadius);
|
||||||
|
oval.top = (mYCenter - mRingRadius);
|
||||||
|
oval.right = mRingRadius * 2 + (mXCenter - mRingRadius);
|
||||||
|
oval.bottom = mRingRadius * 2 + (mYCenter - mRingRadius);
|
||||||
|
if (sweepGradient==null) {
|
||||||
|
int[] arcColors= new int[]{Color.parseColor("#CC67FF"),
|
||||||
|
Color.parseColor("#9DB4FF"),
|
||||||
|
Color.parseColor("#13E2F5"),
|
||||||
|
Color.parseColor("#CC67FF")};
|
||||||
|
float[] arcPostion=new float[]{0.0f,0.25f,0.75f,1f};
|
||||||
|
//sweepGradient = new SweepGradient(mXCenter, mYCenter, mRingColor,Color.parseColor("#b05e39"));
|
||||||
|
sweepGradient = new SweepGradient(mXCenter, mYCenter, arcColors,arcPostion);
|
||||||
|
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
matrix.setRotate(-90,mXCenter,mYCenter);
|
||||||
|
sweepGradient.setLocalMatrix(matrix);
|
||||||
|
mRingPaint.setShader(sweepGradient);
|
||||||
|
}
|
||||||
|
canvas.drawArc(oval, -90, ((float)mProgress / mTotalProgress) * 360, false, mRingPaint); //
|
||||||
|
|
||||||
|
//字体
|
||||||
|
String txt = mProgress + "%";
|
||||||
|
mTxtWidth = mTextPaint.measureText(txt, 0, txt.length());
|
||||||
|
canvas.drawText(txt, mXCenter - mTxtWidth / 2, mYCenter + mTxtHeight / 4, mTextPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setText(String string){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置进度
|
||||||
|
public void setProgress(int progress) {
|
||||||
|
mProgress = progress;
|
||||||
|
postInvalidate();//重绘
|
||||||
|
}
|
||||||
|
}
|
@@ -96,6 +96,20 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/title_bar" />
|
app:layout_constraintTop_toBottomOf="@+id/title_bar" />
|
||||||
|
|
||||||
|
<com.yizhuan.erban.audio.widget.RoundProgressView
|
||||||
|
android:id="@+id/roundProgress"
|
||||||
|
android:layout_width="180dp"
|
||||||
|
android:layout_height="180dp"
|
||||||
|
app:round_radius="80dp"
|
||||||
|
app:round_strokeWidth="8dp"
|
||||||
|
app:round_circleColor="@color/transparent"
|
||||||
|
app:round_ringColor="@color/transparent"
|
||||||
|
app:round_ringBgColor="@color/transparent"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/ivSoundTranscribe"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/ivSoundTranscribe"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/ivSoundTranscribe"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/ivSoundTranscribe"/>
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/ivSaveRecord"
|
android:id="@+id/ivSaveRecord"
|
||||||
android:layout_width="42dp"
|
android:layout_width="42dp"
|
||||||
|
@@ -404,4 +404,12 @@
|
|||||||
<attr name="marqueeResetLocation" format="boolean" />
|
<attr name="marqueeResetLocation" format="boolean" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
<declare-styleable name="RoundProgressView">
|
||||||
|
<attr name="round_radius" format="dimension" />
|
||||||
|
<attr name="round_strokeWidth" format="dimension" />
|
||||||
|
<attr name="round_circleColor" format="color" />
|
||||||
|
<attr name="round_ringColor" format="color" />
|
||||||
|
<attr name="round_ringBgColor" format="color" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user