Skip to content

Commit bb0f933

Browse files
author
jenly1314
committedMay 23, 2019
新增cpvTurn属性(是否旋转)、fix #1
1 parent bc33812 commit bb0f933

File tree

10 files changed

+611
-29
lines changed

10 files changed

+611
-29
lines changed
 

‎.idea/codeStyles/Project.xml

+48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/dbnavigator.xml

+456
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CircleProgressView for Android 是一个圆形的进度动画控件,动画效
3333
| cpvCirclePadding | dimension | 10dp | 外圆环刻度与内圆环间距 |
3434
| cpvTickSplitAngle | integer | 5 | 刻度间隔的角度大小 |
3535
| cpvBlockAngle | integer | 1 | 刻度的角度大小 |
36+
| cpvTurn | boolean | false | 是否旋转 |
3637

3738

3839
## 引入
@@ -42,18 +43,18 @@ CircleProgressView for Android 是一个圆形的进度动画控件,动画效
4243
<dependency>
4344
<groupId>com.king.view</groupId>
4445
<artifactId>circleprogressview</artifactId>
45-
<version>1.0.0</version>
46+
<version>1.0.1</version>
4647
<type>pom</type>
4748
</dependency>
4849
```
4950
### Gradle:
5051
```gradle
51-
implementation 'com.king.view:circleprogressview:1.0.0'
52+
implementation 'com.king.view:circleprogressview:1.0.1'
5253
```
5354

5455
### Lvy:
5556
```lvy
56-
<dependency org='com.king.view' name='circleprogressview' rev='1.0.0'>
57+
<dependency org='com.king.view' name='circleprogressview' rev='1.0.1'>
5758
<artifact name='$AID' ext='pom'></artifact>
5859
</dependency>
5960
```
@@ -93,6 +94,11 @@ compileOnly 'com.android.support:appcompat-v7:28.0.0'
9394

9495
更多使用详情,请查看[app](app)中的源码使用示例
9596

97+
## 版本记录
98+
99+
#### v1.0.1:2019-5-23
100+
* 新增cpvTurn属性(是否旋转)
101+
96102
#### v1.0.0:2019-2-17
97103
* CircleProgressView初始版本
98104

‎app/release/app-release.apk

740 Bytes
Binary file not shown.

‎app/release/output.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
1+
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

‎app/src/main/java/com/king/circleprogressview/MainActivity.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class MainActivity extends AppCompatActivity {
1212

1313
private CircleProgressView cpv;
1414

15-
private CheckBox cb;
15+
private CheckBox cbTick;
16+
private CheckBox cbTurn;
1617

1718
private int[] mShaderColors = new int[]{0xFF4FEAAC,0xFFA8DD51,0xFFE8D30F,0xFFA8DD51,0xFF4FEAAC};
1819

@@ -22,14 +23,23 @@ protected void onCreate(Bundle savedInstanceState) {
2223
setContentView(R.layout.activity_main);
2324

2425
cpv = findViewById(R.id.cpv);
25-
cb = findViewById(R.id.cb);
26-
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
26+
cbTick = findViewById(R.id.cbTick);
27+
cbTurn = findViewById(R.id.cbTurn);
28+
cbTick.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
2729
@Override
2830
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
2931
cpv.setShowTick(isChecked);
3032
}
3133
});
3234

35+
cbTurn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
36+
@Override
37+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
38+
cpv.setTurn(isChecked);
39+
}
40+
});
41+
42+
3343
}
3444

3545

‎app/src/main/res/layout/activity_main.xml

+22-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<LinearLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:tools="http://schemas.android.com/tools"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
56
android:orientation="vertical"
67
android:layout_width="match_parent"
78
android:layout_height="match_parent"
@@ -12,13 +13,28 @@
1213
<com.king.view.circleprogressview.CircleProgressView
1314
android:id="@+id/cpv"
1415
android:layout_width="wrap_content"
15-
android:layout_height="wrap_content"/>
16-
<CheckBox
17-
android:id="@+id/cb"
18-
android:layout_width="match_parent"
1916
android:layout_height="wrap_content"
20-
android:checked="true"
21-
android:text="是否显示外环刻度"/>
17+
app:cpvLabelTextColor="@color/colorPrimary"/>
18+
<LinearLayout
19+
android:orientation="horizontal"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content">
22+
<CheckBox
23+
android:id="@+id/cbTick"
24+
android:layout_width="0dp"
25+
android:layout_height="wrap_content"
26+
android:layout_weight="1"
27+
android:checked="true"
28+
android:text="是否显示外环刻度"/>
29+
<CheckBox
30+
android:id="@+id/cbTurn"
31+
android:layout_width="0dp"
32+
android:layout_height="wrap_content"
33+
android:layout_weight="1"
34+
android:singleLine="true"
35+
android:text="是否旋转"/>
36+
</LinearLayout>
37+
2238
<Button
2339
android:id="@+id/btn1"
2440
android:layout_width="match_parent"

‎lib/src/main/java/com/king/view/circleprogressview/CircleProgressView.java

+59-14
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ public class CircleProgressView extends View {
153153
*/
154154
private boolean isShowTick = true;
155155

156+
/**
157+
* 是否旋转
158+
*/
159+
private boolean isTurn = false;
160+
161+
156162
private OnChangeListener mOnChangeListener;
157163

158164

@@ -220,6 +226,8 @@ private void init(Context context,AttributeSet attrs){
220226
mTickSplitAngle = a.getInt(attr,5);
221227
}else if(attr == R.styleable.CircleProgressView_cpvBlockAngle){
222228
mBlockAngle = a.getInt(attr,1);
229+
}else if(attr == R.styleable.CircleProgressView_cpvTurn){
230+
isTurn = a.getBoolean(attr,false);
223231
}
224232
}
225233

@@ -310,24 +318,48 @@ private void drawArc(Canvas canvas){
310318
RectF rectF = new RectF(tickStartX,tickStartY,tickStartX + tickDiameter,tickStartY + tickDiameter);
311319

312320
final int currentBlockIndex = (int)(mProgressPercent / 100f * mTotalTickCount);
313-
for (int i = 0; i < mTotalTickCount; i++) {
314-
if( i < currentBlockIndex){
321+
if(isTurn){
322+
for (int i = 0; i < mTotalTickCount; i++) {
323+
//底层未选中刻度
324+
mPaint.setShader(null);
325+
mPaint.setColor(mNormalColor);
326+
//绘制外边框刻度
327+
canvas.drawArc(rectF, i * (mBlockAngle + mTickSplitAngle) + mStartAngle, mBlockAngle, false, mPaint);
328+
}
329+
330+
for (int i = currentBlockIndex; i < currentBlockIndex + currentBlockIndex; i++) {
315331
//已选中的刻度
316-
if(isShader && mShader!=null){
332+
if (isShader && mShader != null) {
317333
mPaint.setShader(mShader);
318-
}else{
334+
} else {
319335
mPaint.setColor(mProgressColor);
320336
}
321-
} else {
322-
//未选中的刻度
323-
mPaint.setShader(null);
324-
mPaint.setColor(mNormalColor);
337+
//绘制外边框刻度
338+
canvas.drawArc(rectF, i * (mBlockAngle + mTickSplitAngle) + mStartAngle, mBlockAngle, false, mPaint);
339+
}
340+
}else{
341+
for (int i = 0; i < mTotalTickCount; i++) {
342+
if (i < currentBlockIndex) {
343+
//已选中的刻度
344+
if (isShader && mShader != null) {
345+
mPaint.setShader(mShader);
346+
} else {
347+
mPaint.setColor(mProgressColor);
348+
}
349+
} else {
350+
//未选中的刻度
351+
mPaint.setShader(null);
352+
mPaint.setColor(mNormalColor);
353+
}
354+
//绘制外边框刻度
355+
canvas.drawArc(rectF, i * (mBlockAngle + mTickSplitAngle) + mStartAngle, mBlockAngle, false, mPaint);
325356
}
326-
//绘制外边框刻度
327-
canvas.drawArc(rectF, i * (mBlockAngle + mTickSplitAngle) + mStartAngle, mBlockAngle, false, mPaint);
328357
}
358+
329359
}
330360

361+
362+
mPaint.setShader(null);
331363
mPaint.setStrokeCap(Paint.Cap.ROUND);
332364
mPaint.setColor(mNormalColor);
333365

@@ -348,9 +380,13 @@ private void drawArc(Canvas canvas){
348380
mPaint.setColor(mProgressColor);
349381
}
350382

351-
//绘制当前进度弧形
352-
canvas.drawArc(rectF1,mStartAngle,mSweepAngle * getRatio(),false,mPaint);
353-
383+
if(isTurn){
384+
//绘制当前进度弧形
385+
canvas.drawArc(rectF1,mStartAngle + mSweepAngle * getRatio(),mSweepAngle * getRatio(),false,mPaint);
386+
}else{
387+
//绘制当前进度弧形
388+
canvas.drawArc(rectF1,mStartAngle,mSweepAngle * getRatio(),false,mPaint);
389+
}
354390

355391
}
356392

@@ -364,7 +400,7 @@ private void drawText(Canvas canvas){
364400
}
365401
mTextPaint.reset();
366402
mTextPaint.setAntiAlias(true);
367-
mTextPaint.setStyle(Paint.Style.STROKE);
403+
mTextPaint.setStyle(Paint.Style.FILL_AND_STROKE);
368404
mTextPaint.setTextSize(mLabelTextSize);
369405
mTextPaint.setColor(mLabelTextColor);
370406
mTextPaint.setTextAlign(Paint.Align.CENTER);
@@ -517,6 +553,15 @@ public void setShowTick(boolean isShowTick){
517553
invalidate();
518554
}
519555

556+
/**
557+
* 设置是否旋转
558+
* @param isTurn
559+
*/
560+
public void setTurn(boolean isTurn){
561+
this.isTurn = isTurn;
562+
invalidate();
563+
}
564+
520565
public int getStartAngle() {
521566
return mStartAngle;
522567
}

‎lib/src/main/res/values/attrs.xml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<attr name="cpvCirclePadding" format="dimension"/>
1818
<attr name="cpvTickSplitAngle" format="integer"/>
1919
<attr name="cpvBlockAngle" format="integer"/>
20+
<attr name="cpvTurn" format="boolean"/>
2021

2122
</declare-styleable>
2223
</resources>

‎versions.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//App
22
def app_version = [:]
3-
app_version.versionCode = 1
4-
app_version.versionName = "1.0.0"
3+
app_version.versionCode = 2
4+
app_version.versionName = "1.0.1"
55
ext.app_version = app_version
66

77
//build version

0 commit comments

Comments
 (0)
Please sign in to comment.