Skip to content

Commit f375fcc

Browse files
committed
update
1 parent c2d5f89 commit f375fcc

9 files changed

Lines changed: 377 additions & 16 deletions

File tree

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
2+
[![Release](https://jitpack.io/v/comtu/TCircleProgressView.svg)](https://jitpack.io/#comtu/TCircleProgressView)
3+
4+
15
# TCircleProgressView
26
一个圆型进度条 仿支付宝人脸识别进度条 progressbar
37

48
# 效果
59
![](./show.gif)
10+
![](./show2.gif)
611

712

813
## 支持属性
914
#### TCircleProgressView
1015

1116
| 属性名 | 属性说明 | 类型 |
1217
| :------------------: | :-------------------------------: |:--------------:|
13-
| tcpv_border_width | 圆弧宽度 | dimension |
14-
| tcpv_start_angle | 圆弧开始角度 | integer |
15-
| tcpv_blank_angle | 圆弧空白角度 | integer |
16-
| tcpv_animation_duration | 动画持续时间 单位秒 | integer |
17-
| tcpv_total_progress | 总进度 | integer |
18+
|tcpv_border_width | 圆弧宽度 | dimension |
19+
|tcpv_start_angle | 圆弧开始角度 | integer |
20+
|tcpv_blank_angle | 圆弧空白角度 | integer |
21+
|tcpv_animation_duration | 动画持续时间 单位秒 | integer |
22+
|tcpv_total_progress | 总进度 | integer |
1823
|tcpv_background_color| 背景色 | color |
1924
|tcpv_arc_background_color | 圆弧背景色 |color |
2025
|tcpv_arc_start_color | 进度圆弧开始色 |color |
2126
|tcpv_arc_end_color | 进度圆弧结束色 |color |
2227
|tcpv_hint_background_color | 半圆背景色 |color |
2328
|tcpv_hint_text_color | 字体颜色 |color |
2429
|tcpv_hint_text_size | 字体大小 |dimension |
30+
|tcpv_hint_text_padding | 文字距离顶部的偏移量 |dimension |
2531
|tcpv_hint_text | 文字 |string |
2632
|tcpv_hint_show | 是否显示半圆 |boolean |
2733
|tcpv_hint_semicircle_rate | 半圆覆盖比率 0.1f - 1f |float |
@@ -42,8 +48,8 @@
4248

4349
```
4450
dependencies {
45-
//compile 'com.github.comtu:TCircleProgressView:v1.0.1'
46-
implementation 'com.github.comtu:TCircleProgressView:v1.0.1'
51+
//compile 'com.github.comtu:TCircleProgressView:v1.0.2'
52+
implementation 'com.github.comtu:TCircleProgressView:v1.0.2'
4753
}
4854
```
4955

@@ -69,6 +75,7 @@
6975
app:tcpv_hint_text="1xml配置"
7076
app:tcpv_hint_text_color="#ffffff"
7177
app:tcpv_hint_text_size="10dp"
78+
app:tcpv_hint_text_padding="8dp"
7279
app:tcpv_start_angle="90"
7380
app:tcpv_total_progress="100"/>
7481

@@ -100,9 +107,16 @@ mTCPV_Demo_7.setBackgroundColor(Color.parseColor("#0000ff"));//设置背景色
100107
mTCPV_Demo_7.setArcBackgroundColor(Color.parseColor("#000000"));//设置圆弧背景色
101108
mTCPV_Demo_7.setHintBackgroundColor(Color.parseColor("#5500FF00"));//设置圆弧背景色
102109
mTCPV_Demo_7.setHintTextColor(Color.parseColor("#ff0000"));//设置文字颜色
110+
mTCPV_Demo_7.setTextPadding(8);//设置文字距离顶部的偏移量
103111
mTCPV_Demo_7.setIsShowHint(true);//显示半圆与文字
104112
mTCPV_Demo_7.setSemicircleRate(0.5f);//半圆覆盖比率
105-
113+
mTCPV_Demo_7.setOnProgressListener(new TCircleProgressView.OnProgressListener() { //动画进度
114+
@Override
115+
public void onProgressChanged(float progress) {
116+
mTCPV_Demo_7.setText("进度:" + progress);
117+
mTCPV_Demo_7.setIsShowHint(progress > 30);
118+
}
119+
});
106120
```
107121

108122
## License

TCircleProgressLibrary/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,32 @@ android {
2525
dependencies {
2626
implementation fileTree(dir: 'libs', include: ['*.jar'])
2727
}
28+
29+
// 指定编码
30+
tasks.withType(JavaCompile) {
31+
options.encoding = "UTF-8"
32+
}
33+
34+
// 打包源码
35+
task sourcesJar(type: Jar) {
36+
from android.sourceSets.main.java.srcDirs
37+
classifier = 'sources'
38+
}
39+
40+
task javadoc(type: Javadoc) {
41+
failOnError false
42+
source = android.sourceSets.main.java.sourceFiles
43+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
44+
classpath += configurations.compile
45+
}
46+
47+
// 制作文档(Javadoc)
48+
task javadocJar(type: Jar, dependsOn: javadoc) {
49+
classifier = 'javadoc'
50+
from javadoc.destinationDir
51+
}
52+
53+
artifacts {
54+
archives sourcesJar
55+
archives javadocJar
56+
}

TCircleProgressLibrary/src/main/java/com/tu/tcircleprogresslibrary/TCircleProgressView.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public class TCircleProgressView extends View {
9292
private float mHintTextSize = -1;
9393
/*** 文字 */
9494
private String mHintText = "";
95+
/*** 字距离顶部的偏移量*/
96+
private float mTextPadding = 0;
9597

9698
//全透明圆
9799
/*** 透明区域圆x轴位置 */
@@ -100,6 +102,8 @@ public class TCircleProgressView extends View {
100102
private float mTransparentCircleCY;
101103
/*** 透明区域圆半径 */
102104
private float mTransparentCircleRadius;
105+
/*** 进度监听器 */
106+
private OnProgressListener mOnProgressListener;
103107

104108
// ===========================================================
105109
// Constructors
@@ -188,7 +192,7 @@ public void setGradualColors(int[] mGradualColors) {
188192
*
189193
* @param backgroundColor 颜色值
190194
*/
191-
public void setBackgroundColor( int backgroundColor) {
195+
public void setBackgroundColor(int backgroundColor) {
192196
this.mBackgroundColor = backgroundColor;
193197
}
194198

@@ -197,7 +201,7 @@ public void setBackgroundColor( int backgroundColor) {
197201
*
198202
* @param arcBackgroundColor 颜色值
199203
*/
200-
public void setArcBackgroundColor( int arcBackgroundColor) {
204+
public void setArcBackgroundColor(int arcBackgroundColor) {
201205
this.mArcBackgroundColor = arcBackgroundColor;
202206
}
203207

@@ -232,7 +236,7 @@ public void setHintTextSize(float hintTextSize) {
232236
*
233237
* @param mHintTextColor
234238
*/
235-
public void setHintTextColor( int mHintTextColor) {
239+
public void setHintTextColor(int mHintTextColor) {
236240
this.mHintTextColor = mHintTextColor;
237241
}
238242

@@ -255,6 +259,24 @@ public void setSemicircleRate(float mSemicircleRate) {
255259
this.mHintSemicircleRate = mSemicircleRate;
256260
}
257261

262+
/**
263+
* 设置文字距离顶部的偏移量
264+
*
265+
* @param mTextPadding 偏移量
266+
*/
267+
public void setTextPadding(float mTextPadding) {
268+
this.mTextPadding = dipToPx(mTextPadding);
269+
}
270+
271+
/**
272+
* 设置进度监听器
273+
*
274+
* @param mOnProgressListener l
275+
*/
276+
public void setOnProgressListener(OnProgressListener mOnProgressListener) {
277+
this.mOnProgressListener = mOnProgressListener;
278+
}
279+
258280
// ===========================================================
259281
// Methods for/from SuperClass/Interfaces
260282
// ===========================================================
@@ -293,7 +315,7 @@ private void init(Context context, AttributeSet attrs) {
293315
blankAngle = typedArray.getInt(R.styleable.TCircleProgressView_tcpv_blank_angle, 30);// 圆弧空白角度
294316
mTotalProgress = typedArray.getInt(R.styleable.TCircleProgressView_tcpv_total_progress, 100);// 总进度
295317
mAnimationDuration = typedArray.getInt(R.styleable.TCircleProgressView_tcpv_animation_duration, 3) * 1000L;// 单位秒 动画持续时间
296-
mHintSemicircleRate = typedArray.getFloat(R.styleable.TCircleProgressView_tcpv_hint_semicircle_rate, 0.3f) ;// 半圆覆盖比率 0.1f - 1f
318+
mHintSemicircleRate = typedArray.getFloat(R.styleable.TCircleProgressView_tcpv_hint_semicircle_rate, 0.3f);// 半圆覆盖比率 0.1f - 1f
297319

298320
mBackgroundColor = typedArray.getColor(R.styleable.TCircleProgressView_tcpv_background_color, Color.WHITE);//背景颜色
299321
mArcBackgroundColor = typedArray.getColor(R.styleable.TCircleProgressView_tcpv_arc_background_color, Color.parseColor("#cccccc"));//圆弧背景颜色
@@ -309,6 +331,7 @@ private void init(Context context, AttributeSet attrs) {
309331
mGradualColors = new int[]{color, color};
310332
}
311333
mHintTextSize = typedArray.getDimension(R.styleable.TCircleProgressView_tcpv_hint_text_size, -1f);//字体大小
334+
mTextPadding = typedArray.getDimension(R.styleable.TCircleProgressView_tcpv_hint_text_padding, 0);//字体大小
312335
mHintText = typedArray.getString(R.styleable.TCircleProgressView_tcpv_hint_text);//文字
313336
mIsShowHint = typedArray.getBoolean(R.styleable.TCircleProgressView_tcpv_hint_show, false);//是否显示hint
314337

@@ -413,7 +436,7 @@ private void drawHint(Canvas canvas) {
413436
vTextPaint.setColor(mHintTextColor);
414437
Rect bounds_Number = new Rect();
415438
vTextPaint.getTextBounds(mHintText, 0, mHintText.length(), bounds_Number);
416-
canvas.drawText(mHintText, mTransparentCircleCX, (mHintRectFSemicircle.bottom * 0.05f) + bounds_Number.height() + mHintRectFSemicircle.top, vTextPaint);
439+
canvas.drawText(mHintText, mTransparentCircleCX, (mHintRectFSemicircle.bottom * 0.05f) + bounds_Number.height() + mHintRectFSemicircle.top + mTextPadding, vTextPaint);
417440
}
418441

419442
/**
@@ -530,6 +553,9 @@ private void setAnimation(float last, float current) {
530553
@Override
531554
public void onAnimationUpdate(ValueAnimator animation) {
532555
mCurrentAngleLength = (float) animation.getAnimatedValue();
556+
if (mOnProgressListener != null) {
557+
mOnProgressListener.onProgressChanged(mCurrentAngleLength / mAngleLength * mTotalProgress);
558+
}
533559
invalidate();
534560
}
535561
});
@@ -552,5 +578,15 @@ private int dipToPx(float dip) {
552578
// Inner and Anonymous Classes
553579
// ===========================================================
554580

581+
/***
582+
* 动画进度监听器
583+
*/
584+
public interface OnProgressListener {
585+
/***
586+
* 动画执行到的进度
587+
* @param progress 进度
588+
*/
589+
void onProgressChanged(float progress);
590+
}
555591

556592
}

TCircleProgressLibrary/src/main/res/values/attr.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<attr name="tcpv_hint_text_color" format="color"/>
2828
<!-- 字体大小 -->
2929
<attr name="tcpv_hint_text_size" format="dimension"/>
30+
<!-- 文字偏移量 -->
31+
<attr name="tcpv_hint_text_padding" format="dimension"/>
3032
<!-- 文字 -->
3133
<attr name="tcpv_hint_text" format="string"/>
3234
<!-- 是否显示半圆 -->

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.tu.tcircleprogressview">
33

4+
<uses-permission android:name="android.permission.CAMERA"/>
45
<application
56
android:allowBackup="true"
67
android:icon="@mipmap/ic_launcher"
@@ -15,6 +16,6 @@
1516
<category android:name="android.intent.category.LAUNCHER"/>
1617
</intent-filter>
1718
</activity>
18-
19+
<activity android:name=".CameraActivity"/>
1920
</application>
2021
</manifest>

0 commit comments

Comments
 (0)