Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.

Commit bf2d102

Browse files
committed
VerticalStepView: Separate into two parts
Signed-off-by: Fung <fython@163.com>
1 parent 93d3bc6 commit bf2d102

4 files changed

Lines changed: 146 additions & 58 deletions

File tree

mobile/src/main/java/info/papdt/express/helper/ui/items/DetailsStatusItemBinder.java

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@
77
import android.support.v7.widget.CardView;
88
import android.support.v7.widget.RecyclerView;
99
import android.text.TextUtils;
10+
import android.util.SparseArray;
11+
import android.util.SparseBooleanArray;
1012
import android.view.LayoutInflater;
1113
import android.view.View;
1214
import android.view.ViewGroup;
15+
import android.view.animation.OvershootInterpolator;
1316
import info.papdt.express.helper.R;
1417
import info.papdt.express.helper.model.Package;
15-
import info.papdt.express.helper.view.VerticalStepView;
18+
import info.papdt.express.helper.view.VerticalStepIconView;
19+
import info.papdt.express.helper.view.VerticalStepLineView;
1620
import me.drakeet.multitype.ItemViewBinder;
1721

1822
public class DetailsStatusItemBinder extends ItemViewBinder<Package.Status, DetailsStatusItemBinder.ItemHolder> {
1923

2024
private Package mPackage;
25+
private boolean isShowed[] = new boolean[1000];
2126

2227
public void setData(Package src) {
2328
mPackage = src;
@@ -39,7 +44,8 @@ class ItemHolder extends RecyclerView.ViewHolder {
3944
private Package.Status data;
4045

4146
AppCompatTextView title, time;
42-
VerticalStepView stepView;
47+
VerticalStepIconView stepIcon;
48+
VerticalStepLineView stepLine;
4349

4450
CardView contactCard;
4551
AppCompatTextView phoneView;
@@ -49,7 +55,8 @@ class ItemHolder extends RecyclerView.ViewHolder {
4955

5056
title = itemView.findViewById(R.id.tv_title);
5157
time = itemView.findViewById(R.id.tv_time);
52-
stepView = itemView.findViewById(R.id.step_view);
58+
stepIcon = itemView.findViewById(R.id.step_icon_view);
59+
stepLine = itemView.findViewById(R.id.step_line_view);
5360
contactCard = itemView.findViewById(R.id.contact_card);
5461
phoneView = itemView.findViewById(R.id.contact_number);
5562

@@ -89,10 +96,11 @@ void setData(Package.Status newData) {
8996
/** Set up step view style */
9097
int indexInStatus = getAdapterPosition() - 3;
9198
if (indexInStatus == 0) {
92-
stepView.setIsMini(false);
93-
stepView.setLineShouldDraw(false, mPackage.data.size() > 1);
99+
stepIcon.setIsMini(false);
100+
stepLine.setLineShouldDraw(false, mPackage.data.size() > 1);
94101
if (mPackage.data.size() > 1) {
95-
stepView.setPointOffsetY(-time.getTextSize());
102+
stepIcon.setPointOffsetY(-time.getTextSize());
103+
stepLine.setPointOffsetY(-time.getTextSize());
96104
}
97105
int pointColorResId, pointIconResId;
98106
switch (mPackage.getState()) {
@@ -119,19 +127,34 @@ void setData(Package.Status newData) {
119127
pointIconResId = R.drawable.ic_flight_white_24dp;
120128
break;
121129
}
122-
stepView.setPointColorResource(pointColorResId);
123-
stepView.setCenterIcon(pointIconResId);
130+
stepIcon.setPointColorResource(pointColorResId);
131+
stepIcon.setCenterIcon(pointIconResId);
124132
} else {
125-
stepView.setIsMini(true);
126-
stepView.setPointColorResource(R.color.blue_grey_500);
127-
stepView.setPointOffsetY(-time.getTextSize());
128-
stepView.setCenterIcon(null);
129-
stepView.setLineShouldDraw(true, true);
133+
stepIcon.setIsMini(true);
134+
stepIcon.setPointColorResource(R.color.blue_grey_500);
135+
stepLine.setPointOffsetY(-time.getTextSize());
136+
stepIcon.setPointOffsetY(-time.getTextSize());
137+
stepIcon.setCenterIcon(null);
138+
stepLine.setLineShouldDraw(true, true);
130139
}
131140
if (indexInStatus == mPackage.data.size() - 1 && mPackage.data.size() > 1) {
132-
stepView.setLineShouldDraw(true, false);
133-
stepView.setPointOffsetY(0);
134-
stepView.setCenterIcon(null);
141+
stepLine.setLineShouldDraw(true, false);
142+
stepLine.setPointOffsetY(0);
143+
stepIcon.setPointOffsetY(0);
144+
stepIcon.setCenterIcon(null);
145+
}
146+
synchronized (this) {
147+
if (!isShowed[indexInStatus]) {
148+
synchronized (this) {
149+
isShowed[indexInStatus] = true;
150+
}
151+
stepIcon.setScaleX(0f);
152+
stepIcon.setScaleY(0f);
153+
stepIcon.animate().scaleX(1f).scaleY(1f)
154+
.setStartDelay(150 * (indexInStatus + 1))
155+
.setDuration(500).setInterpolator(new OvershootInterpolator()).start();
156+
157+
}
135158
}
136159
}
137160

mobile/src/main/java/info/papdt/express/helper/view/VerticalStepView.java renamed to mobile/src/main/java/info/papdt/express/helper/view/VerticalStepIconView.java

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package info.papdt.express.helper.view;
22

33
import android.content.Context;
4-
import android.graphics.Bitmap;
5-
import android.graphics.Canvas;
6-
import android.graphics.Color;
7-
import android.graphics.Paint;
8-
import android.graphics.PorterDuff;
9-
import android.graphics.RectF;
4+
import android.graphics.*;
105
import android.graphics.drawable.BitmapDrawable;
116
import android.graphics.drawable.ColorDrawable;
127
import android.graphics.drawable.Drawable;
@@ -15,39 +10,36 @@
1510
import android.support.annotation.DrawableRes;
1611
import android.util.AttributeSet;
1712
import android.view.View;
18-
1913
import info.papdt.express.helper.R;
2014
import info.papdt.express.helper.support.ScreenUtils;
2115

22-
public class VerticalStepView extends View {
16+
public class VerticalStepIconView extends View {
2317

2418
private Paint mPaint, mCirclePaint;
2519
private RectF mBounds, mIconBounds;
2620
private float radius, lineWidth, pointOffsetY = 0, iconSize;
2721

28-
@ColorInt private int pointColor = Color.BLUE, lineColor = Color.GRAY, iconColor = Color.WHITE;
29-
private boolean shouldDrawTopLine = true, shouldDrawBottomLine = true;
22+
@ColorInt private int pointColor = Color.BLUE, iconColor = Color.WHITE;
3023
private boolean isMini = false;
3124
private Drawable centerIcon;
3225
private Bitmap centerIconBitmap;
3326

34-
public VerticalStepView(Context context) {
27+
public VerticalStepIconView(Context context) {
3528
this(context, null);
3629
}
3730

38-
public VerticalStepView(Context context, AttributeSet attrs) {
31+
public VerticalStepIconView(Context context, AttributeSet attrs) {
3932
this(context, attrs, 0);
4033
}
4134

42-
public VerticalStepView(Context context, AttributeSet attrs, int defStyleAttr) {
35+
public VerticalStepIconView(Context context, AttributeSet attrs, int defStyleAttr) {
4336
super(context, attrs, defStyleAttr);
4437
lineWidth = ScreenUtils.dpToPx(context, 2);
4538
iconSize = ScreenUtils.dpToPx(context, 16);
4639

4740
init();
4841

4942
pointColor = context.getResources().getColor(R.color.blue_500);
50-
lineColor = context.getResources().getColor(R.color.blue_grey_500);
5143
}
5244

5345
void init() {
@@ -61,23 +53,10 @@ void init() {
6153
mCirclePaint.setColor(pointColor);
6254
}
6355

64-
public void setLineShouldDraw(boolean top, boolean bottom) {
65-
shouldDrawTopLine = top;
66-
shouldDrawBottomLine = bottom;
67-
}
68-
69-
public void setLineColor(@ColorInt int color) {
70-
lineColor = color;
71-
}
72-
7356
public void setPointColor(@ColorInt int color) {
7457
pointColor = color;
7558
}
7659

77-
public void setLineColorResource(@ColorRes int resId) {
78-
lineColor = getResources().getColor(resId);
79-
}
80-
8160
public void setPointColorResource(@ColorRes int resId) {
8261
pointColor = getResources().getColor(resId);
8362
}
@@ -114,17 +93,6 @@ protected void onDraw(Canvas canvas) {
11493

11594
super.onDraw(canvas);
11695

117-
118-
if (shouldDrawTopLine) {
119-
mPaint.setColor(lineColor);
120-
canvas.drawLine(mBounds.centerX(), mBounds.centerY() + pointOffsetY, mBounds.centerX(), mBounds.top, mPaint);
121-
}
122-
123-
if (shouldDrawBottomLine) {
124-
mPaint.setColor(lineColor);
125-
canvas.drawLine(mBounds.centerX(), mBounds.centerY() + pointOffsetY, mBounds.centerX(), mBounds.bottom, mPaint);
126-
}
127-
12896
mCirclePaint.setColor(pointColor);
12997
canvas.drawCircle(mBounds.centerX(), mBounds.centerY() + pointOffsetY, r, mCirclePaint);
13098

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package info.papdt.express.helper.view;
2+
3+
import android.content.Context;
4+
import android.graphics.Canvas;
5+
import android.graphics.Color;
6+
import android.graphics.Paint;
7+
import android.graphics.RectF;
8+
import android.support.annotation.ColorInt;
9+
import android.support.annotation.ColorRes;
10+
import android.util.AttributeSet;
11+
import android.view.View;
12+
13+
import info.papdt.express.helper.R;
14+
import info.papdt.express.helper.support.ScreenUtils;
15+
16+
public class VerticalStepLineView extends View {
17+
18+
private Paint mPaint;
19+
private RectF mBounds;
20+
private float lineWidth, pointOffsetY = 0;
21+
22+
@ColorInt private int lineColor = Color.GRAY;
23+
private boolean shouldDrawTopLine = true, shouldDrawBottomLine = true;
24+
25+
public VerticalStepLineView(Context context) {
26+
this(context, null);
27+
}
28+
29+
public VerticalStepLineView(Context context, AttributeSet attrs) {
30+
this(context, attrs, 0);
31+
}
32+
33+
public VerticalStepLineView(Context context, AttributeSet attrs, int defStyleAttr) {
34+
super(context, attrs, defStyleAttr);
35+
lineWidth = ScreenUtils.dpToPx(context, 2);
36+
37+
init();
38+
39+
lineColor = context.getResources().getColor(R.color.blue_grey_500);
40+
}
41+
42+
private void init() {
43+
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
44+
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
45+
mPaint.setStrokeWidth(lineWidth);
46+
}
47+
48+
public void setLineShouldDraw(boolean top, boolean bottom) {
49+
shouldDrawTopLine = top;
50+
shouldDrawBottomLine = bottom;
51+
}
52+
53+
public void setLineColor(@ColorInt int color) {
54+
lineColor = color;
55+
}
56+
57+
public void setLineColorResource(@ColorRes int resId) {
58+
lineColor = getResources().getColor(resId);
59+
}
60+
61+
public void setPointOffsetY(float pointOffsetY) {
62+
this.pointOffsetY = pointOffsetY;
63+
}
64+
65+
@Override
66+
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
67+
super.onSizeChanged(w, h, oldW, oldH);
68+
mBounds = new RectF(getLeft(), getTop(), getRight(), getBottom());
69+
}
70+
71+
@Override
72+
protected void onDraw(Canvas canvas) {
73+
super.onDraw(canvas);
74+
75+
if (shouldDrawTopLine) {
76+
mPaint.setColor(lineColor);
77+
canvas.drawLine(mBounds.centerX(), mBounds.centerY() + pointOffsetY, mBounds.centerX(), mBounds.top, mPaint);
78+
}
79+
80+
if (shouldDrawBottomLine) {
81+
mPaint.setColor(lineColor);
82+
canvas.drawLine(mBounds.centerX(), mBounds.centerY() + pointOffsetY, mBounds.centerX(), mBounds.bottom, mPaint);
83+
}
84+
}
85+
86+
}

mobile/src/main/res/layout/item_list_details_info_status.xml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88
android:layout_height="wrap_content"
99
android:layout_marginStart="8dp">
1010

11-
<info.papdt.express.helper.view.VerticalStepView
12-
android:layout_width="48dp"
13-
android:layout_height="match_parent"
14-
android:id="@+id/step_view"/>
11+
<FrameLayout
12+
android:layout_width="wrap_content"
13+
android:layout_height="match_parent">
14+
15+
<info.papdt.express.helper.view.VerticalStepLineView
16+
android:layout_width="48dp"
17+
android:layout_height="match_parent"
18+
android:id="@+id/step_line_view"/>
19+
20+
<info.papdt.express.helper.view.VerticalStepIconView
21+
android:layout_width="48dp"
22+
android:layout_height="match_parent"
23+
android:id="@+id/step_icon_view"/>
24+
25+
</FrameLayout>
1526

1627
<Space android:layout_width="8dp" android:layout_height="wrap_content"/>
1728

0 commit comments

Comments
 (0)