Skip to content

Commit 49e293a

Browse files
committed
增加刻度盘效果
1 parent a0d4535 commit 49e293a

File tree

14 files changed

+395
-171
lines changed

14 files changed

+395
-171
lines changed

.DS_Store

0 Bytes
Binary file not shown.

MaterialProgressView-master/.DS_Store

0 Bytes
Binary file not shown.

MaterialProgressView-master/.idea/misc.xml

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

MaterialProgressView-master/.idea/workspace.xml

+205-154
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.
Loading

MaterialProgressView-master/library/build.gradle

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ dependencies {
3131
testCompile 'junit:junit:4.12'
3232
}
3333

34-
apply plugin: 'com.novoda.bintray-release'//添加
34+
apply plugin: 'com.novoda.bintray-release'
35+
3536

36-
//添加
3737
publish {
38-
userOrg = 'moosphon'//bintray.com用户名
39-
groupId = 'com.moos'//jcenter上的路径
38+
userOrg = 'moosphon'//bintray-username
39+
groupId = 'com.moos'//group name
4040
artifactId = 'Material-ProgressView'//项目名称
41-
publishVersion = '1.0.2'//版本号
41+
publishVersion = '1.0.3'//version
4242
desc = 'This is a pretty and simple used library for progress views on android'
43-
website = 'https://github.com/Moosphan/Material-ProgressView'//网站
43+
website = 'https://github.com/Moosphan/Material-ProgressView'//website
4444
}

MaterialProgressView-master/library/src/main/java/com/moos/library/CircleProgressView.java

+113-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import android.graphics.Canvas;
99
import android.graphics.LinearGradient;
1010
import android.graphics.Paint;
11+
import android.graphics.Path;
12+
import android.graphics.PathDashPathEffect;
13+
import android.graphics.PathEffect;
1114
import android.graphics.RectF;
1215
import android.graphics.Shader;
1316
import android.support.annotation.ColorInt;
@@ -132,6 +135,37 @@ public class CircleProgressView extends View {
132135
private Interpolator mInterpolator;
133136
private CircleProgressUpdateListener updateListener;
134137

138+
/**
139+
* the path of scale zone
140+
*/
141+
private Path mScaleZonePath;
142+
/**
143+
* the width of each scale zone
144+
*/
145+
private float mScaleZoneWidth = 6;
146+
/**
147+
* the length of each scale zone
148+
*/
149+
private float mScaleZoneLength = 22;
150+
/**
151+
* the padding of scale zones
152+
*/
153+
private int mScaleZonePadding = 18;
154+
/**
155+
* the shape of scale zone
156+
*/
157+
private RectF mScaleZoneRect;
158+
/**
159+
* open draw the scale zone or not
160+
*/
161+
private boolean isGraduated = false;
162+
/**
163+
* the radius of scale zone corner
164+
*/
165+
private int mScaleZoneCornerRadius = 0;
166+
167+
PathEffect pathEffect;
168+
135169

136170
public CircleProgressView(Context context) {
137171
super(context);
@@ -171,7 +205,11 @@ private void obtainAttrs(Context context, AttributeSet attrs){
171205
mTrackColor = typedArray.getColor(R.styleable.CircleProgressView_trackColor, getResources().getColor(R.color.default_track_color));
172206
textVisibility = typedArray.getBoolean(R.styleable.CircleProgressView_progressTextVisibility, true);
173207
mProgressDuration = typedArray.getInt(R.styleable.CircleProgressView_progressDuration, 1200);
174-
208+
mScaleZoneLength = typedArray.getDimensionPixelSize(R.styleable.CircleProgressView_scaleZone_length, getResources().getDimensionPixelSize(R.dimen.default_zone_length));
209+
mScaleZoneWidth = typedArray.getDimensionPixelSize(R.styleable.CircleProgressView_scaleZone_width, getResources().getDimensionPixelSize(R.dimen.default_zone_width));
210+
mScaleZonePadding = typedArray.getDimensionPixelSize(R.styleable.CircleProgressView_scaleZone_padding, getResources().getDimensionPixelSize(R.dimen.default_zone_padding));
211+
mScaleZoneCornerRadius = typedArray.getDimensionPixelSize(R.styleable.CircleProgressView_scaleZone_corner_radius, getResources().getDimensionPixelSize(R.dimen.default_zone_corner_radius));
212+
isGraduated = typedArray.getBoolean(R.styleable.CircleProgressView_isGraduated, false);
175213
moveProgress = mStartProgress;
176214

177215
typedArray.recycle();
@@ -182,6 +220,11 @@ private void init(){
182220
progressPaint.setStyle(Paint.Style.STROKE);
183221
progressPaint.setStrokeCap(Paint.Cap.ROUND);
184222
progressPaint.setStrokeWidth(mTrackWidth);
223+
mScaleZonePath = new Path();
224+
/**
225+
* if set the scale zone mode for progress view, should not let the circle be filled
226+
*/
227+
drawScaleZones(isGraduated);
185228

186229
}
187230

@@ -192,7 +235,6 @@ protected void onDraw(Canvas canvas) {
192235

193236
drawTrack(canvas);
194237

195-
196238
//mShader = new LinearGradient(mOval.left,mOval.top,mOval.right,mOval.bottom,mStartColor,mEndColor, Shader.TileMode.CLAMP);
197239
progressPaint.setShader(mShader);
198240
updateTheTrack();
@@ -204,6 +246,7 @@ protected void onDraw(Canvas canvas) {
204246
initProgressDrawing(canvas, false);
205247

206248
}
249+
207250
drawProgressText(canvas);
208251

209252

@@ -217,6 +260,13 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
217260

218261
mShader = new LinearGradient(mOval.left-200, mOval.top-200, mOval.right+20, mOval.bottom+20,
219262
mStartColor, mEndColor, Shader.TileMode.CLAMP);
263+
/**
264+
* draw the scale zone shape
265+
*/
266+
mScaleZoneRect = new RectF(0,0, mScaleZoneWidth, mScaleZoneLength);
267+
mScaleZonePath.addRoundRect(mScaleZoneRect, mScaleZoneCornerRadius, mScaleZoneCornerRadius, Path.Direction.CW);
268+
269+
220270
}
221271

222272
/**
@@ -238,6 +288,25 @@ private void drawTrack(Canvas canvas){
238288
}
239289
}
240290

291+
/**
292+
* draw the each scale zone, you can set round corner fot it
293+
* @link
294+
*/
295+
private void drawScaleZones(boolean isGraduated){
296+
297+
Log.e(TAG, "init======isGraduated>>>>>"+isGraduated );
298+
if(isGraduated){
299+
if(pathEffect == null){
300+
301+
pathEffect = new PathDashPathEffect(mScaleZonePath, mScaleZonePadding,0,PathDashPathEffect.Style.ROTATE);
302+
}
303+
progressPaint.setPathEffect(pathEffect);
304+
}else {
305+
progressPaint.setPathEffect(null);
306+
}
307+
308+
}
309+
241310
/**
242311
* init for track view
243312
* @param canvas mCanvas
@@ -468,6 +537,48 @@ public void setCircleBroken(boolean isBroken){
468537
refreshTheView();
469538
}
470539

540+
/**
541+
* set the scale zone type for progress view
542+
* @param isGraduated have scale zone or not
543+
* todo:deal with the multi views can not works situation
544+
*/
545+
public void setGraduatedEnabled(boolean isGraduated){
546+
this.isGraduated = isGraduated;
547+
drawScaleZones(isGraduated);
548+
}
549+
550+
/**
551+
* set the scale zone width for it
552+
* @param zoneWidth each zone 's width
553+
*/
554+
public void setScaleZoneWidth(float zoneWidth){
555+
this.mScaleZoneWidth = Utils.dp2px(mContext, zoneWidth);
556+
}
557+
558+
/**
559+
* set the scale zone length for it
560+
* @param zoneLength each zone 's length
561+
*/
562+
public void setScaleZoneLength(float zoneLength){
563+
this.mScaleZoneLength = Utils.dp2px(mContext, zoneLength);
564+
}
565+
566+
/**
567+
* set each zone's distance
568+
* @param zonePadding distance
569+
*/
570+
public void setScaleZonePadding(int zonePadding){
571+
this.mScaleZonePadding = Utils.dp2px(mContext, zonePadding);
572+
}
573+
574+
/**
575+
* set corner radius for each zone
576+
* @param cornerRadius round rect zone's corner
577+
*/
578+
public void setScaleZoneCornerRadius(int cornerRadius){
579+
this.mScaleZoneCornerRadius = Utils.dp2px(mContext, cornerRadius);
580+
}
581+
471582
/**
472583
* set the visibility for progress inner text
473584
* @param visibility text visible or not

MaterialProgressView-master/library/src/main/java/com/moos/library/HorizontalProgressView.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import android.graphics.Canvas;
99
import android.graphics.LinearGradient;
1010
import android.graphics.Paint;
11+
import android.graphics.Path;
12+
import android.graphics.PathDashPathEffect;
13+
import android.graphics.PathEffect;
1114
import android.graphics.RectF;
1215
import android.graphics.Shader;
1316
import android.support.annotation.ColorInt;
@@ -22,6 +25,7 @@
2225
import android.view.animation.Interpolator;
2326
import android.view.animation.LinearInterpolator;
2427
import android.view.animation.OvershootInterpolator;
28+
import android.widget.ListView;
2529

2630
/**
2731
* Created by moos on 2018/3/19.
@@ -131,13 +135,13 @@ public class HorizontalProgressView extends View {
131135
*/
132136
private RectF mRect;
133137
private RectF mTrackRect;
134-
135138
private Paint mTextPaint;
136139
private Interpolator mInterpolator;
137140
private HorizontalProgressUpdateListener animatorUpdateListener;
138141

139142

140143

144+
141145
public HorizontalProgressView(Context context) {
142146
super(context);
143147
this.mContext = context;
@@ -187,6 +191,7 @@ private void init(){
187191
progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
188192
progressPaint.setStyle(Paint.Style.FILL);
189193

194+
190195
}
191196

192197
@Override
@@ -206,6 +211,7 @@ protected void onDraw(Canvas canvas) {
206211
drawTrack(canvas);
207212
progressPaint.setShader(mShader);
208213
canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, progressPaint);
214+
209215
drawProgressText(canvas);
210216

211217
}
@@ -216,6 +222,8 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
216222

217223
mShader = new LinearGradient(getPaddingLeft()-50, (getHeight()-getPaddingTop())-50, getWidth() - getPaddingRight(), getHeight()/2 + getPaddingTop() + mTrackWidth,
218224
mStartColor, mEndColor, Shader.TileMode.CLAMP);
225+
226+
219227
}
220228

221229
/**
@@ -263,6 +271,8 @@ private void drawProgressText(Canvas canvas){
263271

264272
}
265273

274+
275+
266276
/**
267277
* set progress animate type
268278
* @param type anim type

MaterialProgressView-master/library/src/main/res/values/attrs.xml

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
<attr name="animateType"/>
3838
<attr name="isFilled" format="boolean"/>
3939
<attr name="circleBroken" format="boolean"/>
40+
<attr name="isGraduated" format="boolean"/>
41+
<attr name="scaleZone_width" format="dimension"/>
42+
<attr name="scaleZone_length" format="dimension"/>
43+
<attr name="scaleZone_corner_radius" format="dimension"/>
44+
<attr name="scaleZone_padding" format="dimension"/>
4045

4146
</declare-styleable>
4247

@@ -64,6 +69,10 @@
6469
<dimen name="default_progress_text_size">28sp</dimen>
6570
<dimen name="default_corner_radius">5dp</dimen>
6671
<dimen name="default_horizontal_text_size">14sp</dimen>
72+
<dimen name="default_zone_length">22dp</dimen>
73+
<dimen name="default_zone_width">6dp</dimen>
74+
<dimen name="default_zone_padding">16dp</dimen>
75+
<dimen name="default_zone_corner_radius">8dp</dimen>
6776

6877

6978
</resources>

MaterialProgressView-master/sample/src/main/java/com/moos/progress/MainActivity.java

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ private void initProgressViews(){
6666
hpv_history.setProgressViewUpdateListener(this);
6767
hpv_math.setProgressViewUpdateListener(this);
6868
cpv_small.setProgressViewUpdateListener(this);
69+
70+
cpv_main.setGraduatedEnabled(true);
6971
cpv_main.setProgressViewUpdateListener(this);
7072
}
7173

@@ -139,6 +141,7 @@ public void onCircleProgressUpdate(View view, float progress) {
139141
public void onCircleProgressFinished(View view) {
140142

141143
if(view.getId() == R.id.progressView_circle_small){
144+
142145
cpv_main.startProgressAnimation();
143146
}
144147

MaterialProgressView-master/sample/src/main/java/com/moos/progress/fragment/CircleProgressFragment.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class CircleProgressFragment extends Fragment implements SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener, View.OnClickListener, CircleProgressView.CircleProgressUpdateListener {
2424

2525
private AppCompatSeekBar csb_track_width, csb_start_progress, csb_end_progress, csb_text_size;
26-
private SwitchCompat csc_trackEnabled, csc_fillEnabled, csc_circleBroken;
26+
private SwitchCompat csc_trackEnabled, csc_fillEnabled, csc_circleBroken, csc_isGraduated;
2727
private CircleProgressView circleProgressView;
2828
private Button btn_start;
2929

@@ -49,6 +49,7 @@ private void initView(View view){
4949
csc_trackEnabled = (SwitchCompat) view.findViewById(R.id.csc_isTracked);
5050
csc_fillEnabled = (SwitchCompat) view.findViewById(R.id.csc_isFilled);
5151
csc_circleBroken = (SwitchCompat) view.findViewById(R.id.csc_circleBroken);
52+
csc_isGraduated = (SwitchCompat) view.findViewById(R.id.csc_isGraduated);
5253
circleProgressView = (CircleProgressView) view.findViewById(R.id.progressView_circle);
5354
btn_start = (Button) view.findViewById(R.id.cb_start);
5455
csb_track_width.setOnSeekBarChangeListener(this);
@@ -58,6 +59,7 @@ private void initView(View view){
5859
csc_trackEnabled.setOnCheckedChangeListener(this);
5960
csc_circleBroken.setOnCheckedChangeListener(this);
6061
csc_fillEnabled.setOnCheckedChangeListener(this);
62+
csc_isGraduated.setOnCheckedChangeListener(this);
6163
btn_start.setOnClickListener(this);
6264
circleProgressView.setProgressViewUpdateListener(this);
6365
}
@@ -122,6 +124,14 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
122124
circleProgressView.setFillEnabled(false);
123125
}
124126
break;
127+
128+
case R.id.csc_isGraduated:
129+
if (isChecked){
130+
circleProgressView.setGraduatedEnabled(true);
131+
}else {
132+
circleProgressView.setGraduatedEnabled(false);
133+
}
134+
break;
125135
}
126136
}
127137

MaterialProgressView-master/sample/src/main/res/layout/fragment_circle_progress.xml

+20
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@
179179
android:layout_margin="8dp"/>
180180
</LinearLayout>
181181

182+
<LinearLayout
183+
android:layout_width="match_parent"
184+
android:layout_height="wrap_content"
185+
android:orientation="horizontal"
186+
android:gravity="center_vertical">
187+
<TextView
188+
android:layout_width="120dp"
189+
android:layout_height="wrap_content"
190+
android:textColor="#666666"
191+
android:textSize="16sp"
192+
android:layout_marginLeft="12dp"
193+
android:text="isGraduated:"/>
194+
<android.support.v7.widget.SwitchCompat
195+
android:id="@+id/csc_isGraduated"
196+
android:layout_width="wrap_content"
197+
android:layout_height="wrap_content"
198+
android:checked="false"
199+
android:layout_margin="8dp"/>
200+
</LinearLayout>
201+
182202
<Button
183203
android:id="@+id/cb_start"
184204
android:layout_width="match_parent"

0 commit comments

Comments
 (0)