https://github.com/jakob-grabner/Circle-Progress-View
来源:互联网 发布:中建七局网络教育 编辑:程序博客网 时间:2024/06/04 20:09
这个库里 Sweep 渐变和 Cap.ROUND 的冲突也没解决掉.
drawArc 的 bug 也没解决掉。
1800 行的代码,慢慢看。
public void setBarColor(@ColorInt int... barColors) {用可变参数作为参数,单一颜色或渐变颜色,用一个接口就搞定了。
public void setBlockCount(int blockCount) { if (blockCount > 1) { mShowBlock = true; mBlockCount = blockCount; mBlockDegree = 360.0f / blockCount; mBlockScaleDegree = mBlockDegree * mBlockScale; } else { mShowBlock = false; } } private void drawBlocks(Canvas _canvas, RectF circleBounds, float startAngle, float _degrees, boolean userCenter, Paint paint) { float tmpDegree = 0.0f; while (tmpDegree < _degrees) { _canvas.drawArc(circleBounds, startAngle + tmpDegree, Math.min(mBlockScaleDegree, _degrees - tmpDegree), userCenter, paint); tmpDegree += mBlockDegree; } }类似 DashEffect 的东西。
private void drawBar(Canvas _canvas, float _degrees) { float startAngle = mDirection == Direction.CW ? mStartAngle : mStartAngle - _degrees; _canvas.drawArc(mCircleBounds, startAngle, _degrees, false, mBarPaint); }让进度条逆时针增加,反正我是没看懂,好神奇。
public class CircleProgress extends View { // ====================== CircleProgress ====================== public CircleProgress(Context context, AttributeSet attrs) { super(context, attrs); initPaint(); } // ====================== paints ====================== private final Paint mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint mProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private int bgColor = Color.LTGRAY; private int progressColor = Color.BLUE; // ====================== stroke ====================== private final RectF mStrokeBounds = new RectF(); private int mStrokeWidth = 30; // ====================== angles ====================== private float mProgress = 80f; private float mStartAngle = 0f; private float mArcAngle = 360f; // ====================== direction ====================== public static final int CW = 0; public static final int CCW = 1; private int mDirection = CW; // ====================== initPaint ====================== private void initPaint() { mBgPaint.setColor(bgColor); mBgPaint.setStyle(Paint.Style.STROKE); mBgPaint.setStrokeWidth(mStrokeWidth); mBgPaint.setStrokeCap(Paint.Cap.ROUND); mProgressPaint.setColor(progressColor); mProgressPaint.setStyle(Paint.Style.STROKE); mProgressPaint.setStrokeWidth(mStrokeWidth); mProgressPaint.setStrokeCap(Paint.Cap.ROUND); } // ====================== onSizeChanged ====================== @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { updateStrokeBounds(); } private void updateStrokeBounds() { final int delta = mStrokeWidth / 2; mStrokeBounds.set(delta, delta, getWidth() - delta, getHeight() - delta); } // ====================== onDraw ====================== @Override protected void onDraw(Canvas canvas) { drawBg(canvas); drawProgress(canvas); } private void drawBg(Canvas canvas) { final float sweepAngle = mArcAngle; float startAngle = getStartAngle(sweepAngle); drawArcPath(canvas, startAngle, mArcAngle, mBgPaint); } private void drawProgress(Canvas canvas) { float sweepAngle = mArcAngle * (mProgress / 100); float startAngle = getStartAngle(sweepAngle); drawArcPath(canvas, startAngle, sweepAngle, mProgressPaint); } private void drawArcPath(Canvas canvas, final float startAngle, final float sweepAngle, Paint paint) { Path path = new Path(); path.addArc(mStrokeBounds, startAngle, sweepAngle); canvas.drawPath(path, paint); } // 反向画圆 private float getStartAngle(final float sweepAngle) { return mDirection == CW ? mStartAngle : mStartAngle - sweepAngle; } // ====================== setter ====================== public void setStartAngle(final float startAngle) { mStartAngle = startAngle; invalidate(); } public void setArcAngle(final float arcAngle) { mArcAngle = arcAngle; invalidate(); } public void setProgress(final float progress) { mProgress = progress; invalidate(); } public void setDirection(final int direction) { mDirection = direction; invalidate(); } public void setStrokeWidth(final int strokeWidth) { mStrokeWidth = strokeWidth; onStrokeWidthChange(); } private void onStrokeWidthChange() { updateStrokeBounds(); mBgPaint.setStrokeWidth(mStrokeWidth); mProgressPaint.setStrokeWidth(mStrokeWidth); invalidate(); } }把代码又重构了下,看 issue 去。
0 0
- https://github.com/jakob-grabner/Circle-Progress-View
- [!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress Cloning into 'master
- https://github.com/sd6352051/NiftyNotification view顶部通知
- https://github.com/search
- https://github.com/mogutt
- https://github.com/droolsjbpm/jbpm
- https://github.com/pwnall/chromeview
- https://github.com/aspnet/开源
- https://github.com/AvinashP/VoiceRecorder
- https://github.com/stuntrally/stuntrally
- https://github.com/rickytan/RTImageAssets
- https://github.com/cnodejs/nodeclub
- https://github.com/Bilibili/ijkplayer
- https://github.com/espressif/esp8266_mp3_decoder
- https://github.com/pkelsey/libuinet
- https://github.com/getlantern/lantern/
- https://github.com/lzyzsd/CircleProgress
- https://github.com/ldoublem/RingProgress
- SpringMVC返回JSON
- hadoop2.7.2集群运行HQL时,异常Job Submission failed with exception 'org.apache.hadoop.ipc.RemoteException
- 修改tomcat内存
- 返回数据到前一个Activity StartActivityForResult方法
- Android Studio 环境Robotium网页相关测试异常java.lang.NullPointerException: lock == null
- https://github.com/jakob-grabner/Circle-Progress-View
- Android WebView 的回退方法(goback) 遭遇重定向
- 花生壳内网穿透功能设置
- Python图像处理库PIL中快速傅里叶变换FFT的实现(一)
- 【Android】Android防止过快点击造成多次事件执行(防止按钮重复点击)
- (16)数组
- Java代码中如何交换两个对象
- struts2常用标签详解
- Linux网络性能分析命令