@@ -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}
0 commit comments