Skip to content

Commit

Permalink
修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Haozi0456 committed Mar 26, 2018
1 parent 56c8cae commit 89fb289
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 114 deletions.
13 changes: 7 additions & 6 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<manifest package="com.zwh.stepView"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zwh.stepView">

<application android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>

</application>

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/zwh/stepView/HorizontalStepView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import java.util.List;

/**
* 日期:16/6/22 15:47
* <p/>
* 描述:StepView
*
* @author Zhaohao
* @Date 2017/04/18 17:00
* @Description: 水平指示器
*/
public class HorizontalStepView extends LinearLayout implements HorizontalStepsViewIndicator.OnDrawIndicatorListener
{
Expand Down
101 changes: 34 additions & 67 deletions src/main/java/com/zwh/stepView/HorizontalStepsViewIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import java.util.List;

/**
*
* @author Zhaohao
* @Date 2017/04/18 17:00
* @Description: 水平指示器
*/
public class HorizontalStepsViewIndicator extends View
{
public class HorizontalStepsViewIndicator extends View {
//定义默认的高度 definition default height
private int defaultStepIndicatorNum = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());

Expand All @@ -41,7 +39,7 @@ public class HorizontalStepsViewIndicator extends View
private float mLeftY;//左上方的Y位置 definition rectangle LeftY position
private float mRightY;//右下方的位置 definition rectangle RightY position

private List<StepBean> mStepBeanList ;//当前有几部流程 there are currently few step
private List<StepBean> mStepBeanList;//当前有几部流程 there are currently few step
private int mStepNum = 0;
private float mLinePadding;//两条连线之间的间距 definition the spacing between the two circles

Expand All @@ -64,8 +62,7 @@ public class HorizontalStepsViewIndicator extends View
*
* @param onDrawListener
*/
public void setOnDrawListener(OnDrawIndicatorListener onDrawListener)
{
public void setOnDrawListener(OnDrawIndicatorListener onDrawListener) {
mOnDrawListener = onDrawListener;
}

Expand All @@ -74,33 +71,28 @@ public void setOnDrawListener(OnDrawIndicatorListener onDrawListener)
*
* @return
*/
public float getCircleRadius()
{
public float getCircleRadius() {
return mCircleRadius;
}


public HorizontalStepsViewIndicator(Context context)
{
public HorizontalStepsViewIndicator(Context context) {
this(context, null);
}

public HorizontalStepsViewIndicator(Context context, AttributeSet attrs)
{
public HorizontalStepsViewIndicator(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public HorizontalStepsViewIndicator(Context context, AttributeSet attrs, int defStyle)
{
public HorizontalStepsViewIndicator(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

/**
* init
*/
private void init()
{
private void init() {
mStepBeanList = new ArrayList<>();
mPath = new Path();
mEffects = new DashPathEffect(new float[]{8, 8, 8, 8}, 1);
Expand Down Expand Up @@ -135,25 +127,21 @@ private void init()
}

@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = defaultStepIndicatorNum * 2;
if(MeasureSpec.UNSPECIFIED != MeasureSpec.getMode(widthMeasureSpec))
{
if (MeasureSpec.UNSPECIFIED != MeasureSpec.getMode(widthMeasureSpec)) {
screenWidth = MeasureSpec.getSize(widthMeasureSpec);
}
int height = defaultStepIndicatorNum;
if(MeasureSpec.UNSPECIFIED != MeasureSpec.getMode(heightMeasureSpec))
{
if (MeasureSpec.UNSPECIFIED != MeasureSpec.getMode(heightMeasureSpec)) {
height = Math.min(height, MeasureSpec.getSize(heightMeasureSpec));
}
width = (int) (mStepNum * mCircleRadius * 2 - (mStepNum - 1) * mLinePadding);
setMeasuredDimension(width, height);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
//获取中间的高度,目的是为了让该view绘制的线和圆在该view垂直居中 get view centerY,keep current stepview center vertical
mCenterY = 0.5f * getHeight();
Expand All @@ -163,8 +151,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh)
mRightY = mCenterY + mCompletedLineHeight / 2;

mCircleCenterPointPositionList.clear();
for(int i = 0; i < mStepNum; i++)
{
for (int i = 0; i < mStepNum; i++) {
//先计算全部最左边的padding值(getWidth()-(圆形直径+两圆之间距离)*2)
float paddingLeft = (screenWidth - mStepNum * mCircleRadius * 2 - (mStepNum - 1) * mLinePadding) / 2;
//add to list
Expand All @@ -174,37 +161,32 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh)
/**
* set listener
*/
if(mOnDrawListener!=null)
{
if (mOnDrawListener != null) {
mOnDrawListener.ondrawIndicator();
}
}

@Override
protected synchronized void onDraw(Canvas canvas)
{
protected synchronized void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(mOnDrawListener!=null)
{
if (mOnDrawListener != null) {
mOnDrawListener.ondrawIndicator();
}
mUnCompletedPaint.setColor(mUnCompletedLineColor);
mCompletedPaint.setColor(mCompletedLineColor);

//-----------------------画线-------draw line-----------------------------------------------
for(int i = 0; i < mCircleCenterPointPositionList.size() -1; i++)
{
for (int i = 0; i < mCircleCenterPointPositionList.size() - 1; i++) {
//前一个ComplectedXPosition
final float preComplectedXPosition = mCircleCenterPointPositionList.get(i);
//后一个ComplectedXPosition
final float afterComplectedXPosition = mCircleCenterPointPositionList.get(i + 1);

if(i <= mComplectingPosition&&mStepBeanList.get(0).getState()!=StepBean.STEP_UNDO)//判断在完成之前的所有点
if (i <= mComplectingPosition && mStepBeanList.get(0).getState() != StepBean.STEP_UNDO)//判断在完成之前的所有点
{
//判断在完成之前的所有点,画完成的线,这里是矩形,很细的矩形,类似线,为了做区分,好看些
canvas.drawRect(preComplectedXPosition + mCircleRadius - 10, mLeftY, afterComplectedXPosition - mCircleRadius + 10, mRightY, mCompletedPaint);
} else
{
} else {
mPath.moveTo(preComplectedXPosition + mCircleRadius, mCenterY);
mPath.lineTo(afterComplectedXPosition - mCircleRadius, mCenterY);
canvas.drawPath(mPath, mUnCompletedPaint);
Expand All @@ -214,25 +196,21 @@ protected synchronized void onDraw(Canvas canvas)


//-----------------------画图标-----draw icon-----------------------------------------------
for(int i = 0; i < mCircleCenterPointPositionList.size(); i++)
{
for (int i = 0; i < mCircleCenterPointPositionList.size(); i++) {
final float currentComplectedXPosition = mCircleCenterPointPositionList.get(i);
Rect rect = new Rect((int) (currentComplectedXPosition - mCircleRadius), (int) (mCenterY - mCircleRadius), (int) (currentComplectedXPosition + mCircleRadius), (int) (mCenterY + mCircleRadius));

StepBean stepsBean = mStepBeanList.get(i);

if(stepsBean.getState()==StepBean.STEP_UNDO)
{
if (stepsBean.getState() == StepBean.STEP_UNDO) {
mDefaultIcon.setBounds(rect);
mDefaultIcon.draw(canvas);
}else if(stepsBean.getState()==StepBean.STEP_CURRENT)
{
} else if (stepsBean.getState() == StepBean.STEP_CURRENT) {
mCompletedPaint.setColor(Color.WHITE);
canvas.drawCircle(currentComplectedXPosition, mCenterY, mCircleRadius * 1.1f, mCompletedPaint);
mAttentionIcon.setBounds(rect);
mAttentionIcon.draw(canvas);
}else if(stepsBean.getState()==StepBean.STEP_COMPLETED)
{
} else if (stepsBean.getState() == StepBean.STEP_COMPLETED) {
mCompleteIcon.setBounds(rect);
mCompleteIcon.draw(canvas);
}
Expand All @@ -245,8 +223,7 @@ protected synchronized void onDraw(Canvas canvas)
*
* @return
*/
public List<Float> getCircleCenterPointPositionList()
{
public List<Float> getCircleCenterPointPositionList() {
return mCircleCenterPointPositionList;
}

Expand All @@ -255,19 +232,15 @@ public List<Float> getCircleCenterPointPositionList()
*
* @param stepsBeanList 流程步数
*/
public void setStepNum(List<StepBean> stepsBeanList)
{
public void setStepNum(List<StepBean> stepsBeanList) {
this.mStepBeanList = stepsBeanList;
mStepNum = mStepBeanList.size();

if(mStepBeanList!=null&&mStepBeanList.size()>0)
{
for(int i = 0;i<mStepNum;i++)
{
if (mStepBeanList != null && mStepBeanList.size() > 0) {
for (int i = 0; i < mStepNum; i++) {
StepBean stepsBean = mStepBeanList.get(i);
{
if(stepsBean.getState()==StepBean.STEP_COMPLETED)
{
if (stepsBean.getState() == StepBean.STEP_COMPLETED) {
mComplectingPosition = i;
}
}
Expand All @@ -282,8 +255,7 @@ public void setStepNum(List<StepBean> stepsBeanList)
*
* @param unCompletedLineColor
*/
public void setUnCompletedLineColor(int unCompletedLineColor)
{
public void setUnCompletedLineColor(int unCompletedLineColor) {
this.mUnCompletedLineColor = unCompletedLineColor;
}

Expand All @@ -292,8 +264,7 @@ public void setUnCompletedLineColor(int unCompletedLineColor)
*
* @param completedLineColor
*/
public void setCompletedLineColor(int completedLineColor)
{
public void setCompletedLineColor(int completedLineColor) {
this.mCompletedLineColor = completedLineColor;
}

Expand All @@ -302,8 +273,7 @@ public void setCompletedLineColor(int completedLineColor)
*
* @param defaultIcon
*/
public void setDefaultIcon(Drawable defaultIcon)
{
public void setDefaultIcon(Drawable defaultIcon) {
this.mDefaultIcon = defaultIcon;
}

Expand All @@ -312,8 +282,7 @@ public void setDefaultIcon(Drawable defaultIcon)
*
* @param completeIcon
*/
public void setCompleteIcon(Drawable completeIcon)
{
public void setCompleteIcon(Drawable completeIcon) {
this.mCompleteIcon = completeIcon;
}

Expand All @@ -322,17 +291,15 @@ public void setCompleteIcon(Drawable completeIcon)
*
* @param attentionIcon
*/
public void setAttentionIcon(Drawable attentionIcon)
{
public void setAttentionIcon(Drawable attentionIcon) {
this.mAttentionIcon = attentionIcon;
}


/**
* 设置对view监听
*/
public interface OnDrawIndicatorListener
{
public interface OnDrawIndicatorListener {
void ondrawIndicator();
}
}
7 changes: 4 additions & 3 deletions src/main/java/com/zwh/stepView/VerticalStepView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import static android.content.ContentValues.TAG;

/**
* 日期:16/6/24 11:48
* <p/>
* 描述:
*
* @author Zhaohao
* @Date 2017/04/18 17:00
* @Description: 垂直指示器
*/
public class VerticalStepView extends LinearLayout {
private LinearLayout mTextContainer;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/zwh/stepView/VerticalStepViewIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


/**
*
* @author Zhaohao
* @Date 2017/04/18 16:59
* @Description: 垂直流程指示器
Expand Down Expand Up @@ -141,12 +140,12 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mRightY = mCenterX + (mCompletedLineHeight / 2);
if (positionCircleList != null) {

if(mIsReverseDraw){
if (mIsReverseDraw) {
for (int i = mStepNum - 1; i >= 0; i--) {
float pos = positionCircleList.get(i) + mCircleRadius + 20;
mCircleCenterPointPositionList.add(pos);
}
}else{
} else {
for (int i = 0; i < mStepNum; i++) {
float pos = positionCircleList.get(i) + mCircleRadius + 20;
mCircleCenterPointPositionList.add(pos);
Expand Down Expand Up @@ -226,7 +225,6 @@ protected void onDraw(Canvas canvas) {
}



/**
* 设置流程步数
*
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/zwh/stepView/bean/StepBean.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.zwh.stepView.bean;

/**
* 日期:16/9/3 00:36
* <p/>
* 描述:
*
* @author Zhaohao
* @Date 2017/04/26 13:45
* @Description: StepBean
*/
public class StepBean
{
Expand Down
Loading

0 comments on commit 89fb289

Please sign in to comment.