Skip to content

Commit

Permalink
新增cpvTurn属性(是否旋转)、fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed May 23, 2019
1 parent bc33812 commit bb0f933
Show file tree
Hide file tree
Showing 10 changed files with 611 additions and 29 deletions.
48 changes: 48 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

456 changes: 456 additions & 0 deletions .idea/dbnavigator.xml

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CircleProgressView for Android 是一个圆形的进度动画控件,动画效
| cpvCirclePadding | dimension | 10dp | 外圆环刻度与内圆环间距 |
| cpvTickSplitAngle | integer | 5 | 刻度间隔的角度大小 |
| cpvBlockAngle | integer | 1 | 刻度的角度大小 |
| cpvTurn | boolean | false | 是否旋转 |


## 引入
Expand All @@ -42,18 +43,18 @@ CircleProgressView for Android 是一个圆形的进度动画控件,动画效
<dependency>
<groupId>com.king.view</groupId>
<artifactId>circleprogressview</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<type>pom</type>
</dependency>
```
### Gradle:
```gradle
implementation 'com.king.view:circleprogressview:1.0.0'
implementation 'com.king.view:circleprogressview:1.0.1'
```

### Lvy:
```lvy
<dependency org='com.king.view' name='circleprogressview' rev='1.0.0'>
<dependency org='com.king.view' name='circleprogressview' rev='1.0.1'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
```
Expand Down Expand Up @@ -93,6 +94,11 @@ compileOnly 'com.android.support:appcompat-v7:28.0.0'

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

## 版本记录

#### v1.0.1:2019-5-23
* 新增cpvTurn属性(是否旋转)

#### v1.0.0:2019-2-17
* CircleProgressView初始版本

Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -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":{}}]
[{"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":{}}]
16 changes: 13 additions & 3 deletions app/src/main/java/com/king/circleprogressview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class MainActivity extends AppCompatActivity {

private CircleProgressView cpv;

private CheckBox cb;
private CheckBox cbTick;
private CheckBox cbTurn;

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

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

cpv = findViewById(R.id.cpv);
cb = findViewById(R.id.cb);
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
cbTick = findViewById(R.id.cbTick);
cbTurn = findViewById(R.id.cbTurn);
cbTick.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cpv.setShowTick(isChecked);
}
});

cbTurn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cpv.setTurn(isChecked);
}
});


}


Expand Down
28 changes: 22 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -12,13 +13,28 @@
<com.king.view.circleprogressview.CircleProgressView
android:id="@+id/cpv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/cb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="是否显示外环刻度"/>
app:cpvLabelTextColor="@color/colorPrimary"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/cbTick"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="是否显示外环刻度"/>
<CheckBox
android:id="@+id/cbTurn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:text="是否旋转"/>
</LinearLayout>

<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ public class CircleProgressView extends View {
*/
private boolean isShowTick = true;

/**
* 是否旋转
*/
private boolean isTurn = false;


private OnChangeListener mOnChangeListener;


Expand Down Expand Up @@ -220,6 +226,8 @@ private void init(Context context,AttributeSet attrs){
mTickSplitAngle = a.getInt(attr,5);
}else if(attr == R.styleable.CircleProgressView_cpvBlockAngle){
mBlockAngle = a.getInt(attr,1);
}else if(attr == R.styleable.CircleProgressView_cpvTurn){
isTurn = a.getBoolean(attr,false);
}
}

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

final int currentBlockIndex = (int)(mProgressPercent / 100f * mTotalTickCount);
for (int i = 0; i < mTotalTickCount; i++) {
if( i < currentBlockIndex){
if(isTurn){
for (int i = 0; i < mTotalTickCount; i++) {
//底层未选中刻度
mPaint.setShader(null);
mPaint.setColor(mNormalColor);
//绘制外边框刻度
canvas.drawArc(rectF, i * (mBlockAngle + mTickSplitAngle) + mStartAngle, mBlockAngle, false, mPaint);
}

for (int i = currentBlockIndex; i < currentBlockIndex + currentBlockIndex; i++) {
//已选中的刻度
if(isShader && mShader!=null){
if (isShader && mShader != null) {
mPaint.setShader(mShader);
}else{
} else {
mPaint.setColor(mProgressColor);
}
} else {
//未选中的刻度
mPaint.setShader(null);
mPaint.setColor(mNormalColor);
//绘制外边框刻度
canvas.drawArc(rectF, i * (mBlockAngle + mTickSplitAngle) + mStartAngle, mBlockAngle, false, mPaint);
}
}else{
for (int i = 0; i < mTotalTickCount; i++) {
if (i < currentBlockIndex) {
//已选中的刻度
if (isShader && mShader != null) {
mPaint.setShader(mShader);
} else {
mPaint.setColor(mProgressColor);
}
} else {
//未选中的刻度
mPaint.setShader(null);
mPaint.setColor(mNormalColor);
}
//绘制外边框刻度
canvas.drawArc(rectF, i * (mBlockAngle + mTickSplitAngle) + mStartAngle, mBlockAngle, false, mPaint);
}
//绘制外边框刻度
canvas.drawArc(rectF, i * (mBlockAngle + mTickSplitAngle) + mStartAngle, mBlockAngle, false, mPaint);
}

}


mPaint.setShader(null);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setColor(mNormalColor);

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

//绘制当前进度弧形
canvas.drawArc(rectF1,mStartAngle,mSweepAngle * getRatio(),false,mPaint);

if(isTurn){
//绘制当前进度弧形
canvas.drawArc(rectF1,mStartAngle + mSweepAngle * getRatio(),mSweepAngle * getRatio(),false,mPaint);
}else{
//绘制当前进度弧形
canvas.drawArc(rectF1,mStartAngle,mSweepAngle * getRatio(),false,mPaint);
}

}

Expand All @@ -364,7 +400,7 @@ private void drawText(Canvas canvas){
}
mTextPaint.reset();
mTextPaint.setAntiAlias(true);
mTextPaint.setStyle(Paint.Style.STROKE);
mTextPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mTextPaint.setTextSize(mLabelTextSize);
mTextPaint.setColor(mLabelTextColor);
mTextPaint.setTextAlign(Paint.Align.CENTER);
Expand Down Expand Up @@ -517,6 +553,15 @@ public void setShowTick(boolean isShowTick){
invalidate();
}

/**
* 设置是否旋转
* @param isTurn
*/
public void setTurn(boolean isTurn){
this.isTurn = isTurn;
invalidate();
}

public int getStartAngle() {
return mStartAngle;
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<attr name="cpvCirclePadding" format="dimension"/>
<attr name="cpvTickSplitAngle" format="integer"/>
<attr name="cpvBlockAngle" format="integer"/>
<attr name="cpvTurn" format="boolean"/>

</declare-styleable>
</resources>
4 changes: 2 additions & 2 deletions versions.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//App
def app_version = [:]
app_version.versionCode = 1
app_version.versionName = "1.0.0"
app_version.versionCode = 2
app_version.versionName = "1.0.1"
ext.app_version = app_version

//build version
Expand Down

0 comments on commit bb0f933

Please sign in to comment.