Compare commits

..

6 Commits

@ -0,0 +1,2 @@
1111
222

@ -1,4 +1,4 @@
package com.sbw.atrue.Order.Activity;
package practice.csy.com.customprogress.view;
import android.content.Context;
import android.content.res.TypedArray;
@ -10,7 +10,8 @@ import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ProgressBar;
import com.sbw.atrue.Order.R;
import practice.csy.com.customprogress.R;
/**
* Created by user on 2017-8-8.
*
@ -68,9 +69,6 @@ public class CustomHorizontalProgres extends ProgressBar{
HorizontalProgresTextSize = (int) typedArray.getDimension(R.styleable.CustomHorizontalProgresStyle_HorizontalProgresTextSize,sp2px(getContext(),DEAFUALT_PROGRESS_TEXT_SIZE));
HorizontalProgresTextOffset = (int) typedArray.getDimension(R.styleable.CustomHorizontalProgresStyle_HorizontalProgresTextOffset,DEAFUALT_PROGRESS_TEXT_OFFSET);
typedArray.recycle();//记得加这句
/*TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.);
int textColor = a.getColor(R.styleable._, );
https://www.jianshu.com/p/8d388894d9e9*/
}
@Override
@ -196,4 +194,3 @@ public class CustomHorizontalProgres extends ProgressBar{
}

@ -1,4 +1,4 @@
package com.sbw.atrue.Order.Activity;
package practice.csy.com.customprogress.view;
import android.content.Context;
import android.content.res.TypedArray;
@ -10,9 +10,7 @@ import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ProgressBar;
import com.sbw.atrue.Order.R;
//import practice.csy.com.customprogress.R;
import practice.csy.com.customprogress.R;
/**
* Created by user on 2017-8-8.
@ -101,7 +99,7 @@ public class CustomHorizontalProgresNoNum extends ProgressBar {
float realWidth = getWidth() - getPaddingLeft() - getPaddingRight();//实际宽度减去文字宽度
float progressX = radio * realWidth;
/*向路径中添加圆角矩形。radii数组定义圆角矩形的四个圆角的x,y半径。radii长度必须为8*/
/*向路径中添加圆角矩形。radii数组定义圆角矩形的四个圆角的x,y半径。radii长度必须为8*/
path.addRoundRect(new RectF(getPaddingLeft(),getPaddingTop()-HorizontalProgresReachHeight/2,realWidth,HorizontalProgresReachHeight/2), rids, Path.Direction.CW);
canvas.clipPath(path);
@ -206,4 +204,3 @@ public class CustomHorizontalProgresNoNum extends ProgressBar {
}

@ -1,4 +1,4 @@
package com.sbw.atrue.Order.Activity;
package practice.csy.com.customprogress.view;
import android.content.Context;
import android.content.res.TypedArray;
@ -9,9 +9,7 @@ import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ProgressBar;
import com.sbw.atrue.Order.R;
//import practice.csy.com.customprogress.R;
import practice.csy.com.customprogress.R;
/**
* Created by user on 2017-8-8.
@ -197,4 +195,3 @@ public class CustomHorizontalProgresWithNum extends ProgressBar{
}

@ -0,0 +1,2 @@
# liyuxuan_gitProject

@ -0,0 +1,191 @@
package practice.csy.com.customprogress.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ProgressBar;
import practice.csy.com.customprogress.R;
/**
* Created by user on 2017-8-8.
*
* ProgressBar
*
*
*/
public class RoundlProgresWithNum extends CustomHorizontalProgresNoNum{
private static final int DEAFUALT_PROGRESS_RADIO = 50;//圆的半径
private static final int DEAFUALT_PROGRESS_UNREACH_PAINT_STROKEN = 2;//未走完进度的宽度
private static final int DEAFUALT_PROGRESS_REACH_PAINT_STROKEN = 5;//走完进度的宽度
private static final int DEAFUALT_PROGRESS_REACH_START_DGREE = 0;//走完进度 圆弧 默认从多少度开始
private static final int DEAFUALT_PROGRESS_REACH_END_DGREE = 360;
private static final boolean DEAFUALT_PROGRESS_HAS_NUM = false;//是否带进度数字显示
private int mCustomCircleRadio ;//圆的半径
private int mCustomCircleUnReachPaintStroken ;//走完进度的
private int mCustomCircleReachPaintStroken ;//走完进度的画笔宽度
private int mCustomUnReachEnd;
private int mCustomUnReachStart;
private boolean mCustomHasNum;
private RectF mRectFOval;
public RoundlProgresWithNum(Context context) {
this(context,null);
}
public RoundlProgresWithNum(Context context, AttributeSet attrs) {
this(context,attrs,0);
}
public RoundlProgresWithNum(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mPaint.setTextSize(HorizontalProgresTextSize);//设置画笔文字大小,便于后面测量文字宽高
mPaint.setColor(HorizontalProgresTextColor);
}
@Override
protected void getStyleabletAttr(AttributeSet attrs) {
super.getStyleabletAttr(attrs);
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.CustomCircleProgresStyle);
mCustomCircleRadio = (int) typedArray.getDimension(R.styleable.CustomCircleProgresStyle_CustomCircleRadio,dp2px(getContext(),DEAFUALT_PROGRESS_RADIO));
mCustomCircleUnReachPaintStroken = (int) typedArray.getDimension(R.styleable.CustomCircleProgresStyle_CustomUnReachPaintStroken,dp2px(getContext(),DEAFUALT_PROGRESS_UNREACH_PAINT_STROKEN));
mCustomCircleReachPaintStroken = (int) typedArray.getDimension(R.styleable.CustomCircleProgresStyle_CustomReachPaintStroken,dp2px(getContext(),DEAFUALT_PROGRESS_REACH_PAINT_STROKEN));
mCustomUnReachStart = typedArray.getInteger(R.styleable.CustomCircleProgresStyle_CustomUnReachStart,DEAFUALT_PROGRESS_REACH_START_DGREE);
mCustomUnReachEnd = typedArray.getInteger(R.styleable.CustomCircleProgresStyle_CustomUnReachEnd,DEAFUALT_PROGRESS_REACH_END_DGREE);
mCustomHasNum = typedArray.getBoolean(R.styleable.CustomCircleProgresStyle_CustomHasProgressNum,DEAFUALT_PROGRESS_HAS_NUM);
typedArray.recycle();//记得加这句
}
/**
*
*/
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = measureWidth(widthMeasureSpec);//计算宽高
int height = measureHeight(heightMeasureSpec);
width = height = Math.min(width,height);//取宽高的最小值
if (mCustomCircleRadio>width/2){
mCustomCircleRadio = width/2;
}
mCustomCircleRadio = mCustomCircleRadio - mCustomCircleReachPaintStroken/2;//还要减去画笔的宽度
setMeasuredDimension(width,height);//设置宽高
}
@Override
protected synchronized void onDraw(Canvas canvas) {
//super.onDraw(canvas);//不需要父类里面的代码
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
//移动画布,减少后续画图换算
int centerX = getWidth()/2;
int centerY = getHeight()/2;
canvas.save();//save、restore 图层的保存和回滚相关的方法 详见 http://blog.csdn.net/tianjian4592/article/details/45234419
canvas.translate(centerX,centerY);//移动图层到垂直居中位置
//draw unreach circle
mPaint.setColor(HorizontalProgresUnReachColor);
mPaint.setStrokeWidth(mCustomCircleUnReachPaintStroken);
canvas.drawCircle(0,0,mCustomCircleRadio,mPaint);
//draw reach circle
mPaint.setColor(HorizontalProgresReachColor);
mPaint.setStrokeWidth(mCustomCircleReachPaintStroken);
int progress = (int) ((getProgress()*1.0f/getMax())*360);//圆弧度数
int mTotalProgress = Math.abs(mCustomUnReachStart) + Math.abs(mCustomUnReachEnd);
if (progress<=mTotalProgress){
if (mRectFOval==null){//只创建一次,减少内存的创建与回收
mRectFOval = new RectF(-mCustomCircleRadio,-mCustomCircleRadio,mCustomCircleRadio,mCustomCircleRadio);//float left, float top, float right, float bottom
}
canvas.drawArc(mRectFOval,mCustomUnReachStart,progress,false,mPaint);////false绘制圆弧不含圆心 @NonNull RectF oval, float startAngle, float sweepAngle, boolean useCenter, @NonNull Paint paint
} else{
if (mRectFOval==null){//只创建一次,减少内存的创建与回收
mRectFOval = new RectF(-mCustomCircleRadio,-mCustomCircleRadio,mCustomCircleRadio,mCustomCircleRadio);//float left, float top, float right, float bottom
}
canvas.drawArc(mRectFOval,mCustomUnReachStart,mTotalProgress,false,mPaint);////false绘制圆弧不含圆心 @NonNull RectF oval, float startAngle, float sweepAngle, boolean useCenter, @NonNull Paint paint
}
//draw Text
if (mCustomHasNum){
mPaint.setColor(HorizontalProgresTextColor);
mPaint.setTextSize(HorizontalProgresTextSize);
mPaint.setStyle(Paint.Style.FILL);
String currentProgress = getProgress()+"%";
Rect mRectF = new Rect();
mPaint.getTextBounds(currentProgress,0,currentProgress.length(),mRectF);
//canvas.drawText(currentProgress,mRectF.width(),mRectF.height(),mPaint);
canvas.drawText(currentProgress,0 - mRectF.width()/2,0+mRectF.height()/2,mPaint);
}
canvas.restore();
}
/**
* Determines the width of this view
* @param measureSpec A measureSpec packed into an int
* @return The width of the view, honoring constraints from measureSpec
*/
protected int measureWidth(int measureSpec) {
int result = 0;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
result = Math.min(specSize,mCustomCircleRadio*2);
} else {
// Measure the text
result = dp2px(getContext(),2*mCustomCircleRadio);//
if (specMode == MeasureSpec.AT_MOST) {
// Respect AT_MOST value if that was what is called for by measureSpec
result = Math.min(result, specSize);
}
}
return result;
}
/**
* Determines the height of this view
* @param measureSpec A measureSpec packed into an int
* @return The height of the view, honoring constraints from measureSpec
*/
protected int measureHeight(int measureSpec) {
int result = 0;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
result = specSize;
} else {
// Measure the text (beware: ascent is a negative number)
//此处高度为走完的进度高度和未走完的机大以及文字的高度的最大值
result = 2*mCustomCircleRadio + getPaddingTop()
+ getPaddingBottom();
if (specMode == MeasureSpec.AT_MOST) {
// Respect AT_MOST value if that was what is called for by measureSpec
result = Math.min(result, specSize);
}
}
return result;
}
}

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context="com.sbw.atrue.Order.Activity.horizonta_main">
tools:context="practice.csy.com.customprogress.MainActivity">
<LinearLayout
android:layout_width="wrap_content"
@ -19,7 +19,7 @@
android:textColor="#36513e"
android:layout_marginTop="20dp"
></TextView>
<com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum
<practice.csy.com.customprogress.view.CustomHorizontalProgresNoNum
android:layout_marginTop="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
@ -38,7 +38,7 @@
android:textColor="#36513e"
android:layout_marginTop="20dp"
></TextView>
<com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum
<practice.csy.com.customprogress.view.CustomHorizontalProgresWithNum
android:layout_marginTop="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
@ -49,7 +49,7 @@
app:HorizontalProgresTextColor="#00ffaa"
android:layout_width="300dp"
android:layout_height="30dp">
</com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum>
</practice.csy.com.customprogress.view.CustomHorizontalProgresWithNum>
<TextView
android:layout_width="100dp"
@ -58,7 +58,7 @@
android:textColor="#36513e"
android:layout_marginTop="20dp"
></TextView>
<com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum
<practice.csy.com.customprogress.view.CustomHorizontalProgresWithNum
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginTop="20dp"
@ -71,7 +71,7 @@
android:layout_width="300dp"
android:layout_height="30dp">
</com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum>
</practice.csy.com.customprogress.view.CustomHorizontalProgresWithNum>
<TextView
android:layout_width="100dp"
android:layout_height="20dp"
@ -79,7 +79,7 @@
android:textColor="#36513e"
android:layout_marginTop="20dp"
></TextView>
<com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum
<practice.csy.com.customprogress.view.CustomHorizontalProgresWithNum
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginTop="20dp"
@ -92,7 +92,7 @@
app:HorizontalProgresTextColor="#00FEA9"
android:layout_width="300dp"
android:layout_height="30dp">
</com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum>
</practice.csy.com.customprogress.view.CustomHorizontalProgresWithNum>
</LinearLayout>
</ScrollView>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

@ -1,2 +0,0 @@
#Fri Oct 21 23:04:16 GMT+08:00 2022
gradle.version=6.4.1

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save