6
6
import android .annotation .SuppressLint ;
7
7
import android .content .Context ;
8
8
import android .content .res .TypedArray ;
9
+ import android .graphics .PorterDuff ;
9
10
import android .graphics .drawable .Drawable ;
11
+ import android .os .Build ;
10
12
import android .os .Bundle ;
11
13
import android .os .Parcelable ;
12
14
import android .support .annotation .*;
@@ -51,7 +53,7 @@ public class VerticalStepperItemView extends FrameLayout {
51
53
* View attributes
52
54
*/
53
55
private int mAnimationDuration ;
54
- private int mNormalColor , mActivatedColor ;
56
+ private int mNormalColor , mActivatedColor , mLineColor , mErrorColor ;
55
57
private Drawable mDoneIcon ;
56
58
private boolean mAnimationEnabled = true ;
57
59
@@ -77,14 +79,11 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
77
79
78
80
prepareViews (context );
79
81
80
- mNormalColor = ViewUtils .getColorFromAttr (context , android .R .attr .textColorSecondary );
81
- mActivatedColor = ViewUtils .getColorFromAttr (context , R .attr .colorPrimary );
82
- mDoneIcon = getResources ().getDrawable (R .drawable .ic_done_white_16dp );
83
- mAnimationDuration = getResources ().getInteger (android .R .integer .config_shortAnimTime );
84
82
DP = getResources ().getDimensionPixelSize (R .dimen .dp1 );
85
83
86
84
if (attrs != null ) {
87
- TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .VerticalStepperItemView , defStyleAttr , 0 );
85
+ TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .VerticalStepperItemView ,
86
+ defStyleAttr , R .style .Widget_Stepper );
88
87
89
88
mTitle = a .getString (R .styleable .VerticalStepperItemView_step_title );
90
89
mSummary = a .getString (R .styleable .VerticalStepperItemView_step_summary );
@@ -95,6 +94,8 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
95
94
mActivatedColor = a .getColor (R .styleable .VerticalStepperItemView_step_activated_color , mActivatedColor );
96
95
mAnimationDuration = a .getInt (R .styleable .VerticalStepperItemView_step_animation_duration , mAnimationDuration );
97
96
mAnimationEnabled = a .getBoolean (R .styleable .VerticalStepperItemView_step_enable_animation , true );
97
+ mLineColor = a .getColor (R .styleable .VerticalStepperItemView_step_line_color , mLineColor );
98
+ mErrorColor = a .getColor (R .styleable .VerticalStepperItemView_step_error_highlight_color , mErrorColor );
98
99
99
100
if (a .hasValue (R .styleable .VerticalStepperItemView_step_done_icon )) {
100
101
mDoneIcon = a .getDrawable (R .styleable .VerticalStepperItemView_step_done_icon );
@@ -110,6 +111,8 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
110
111
setIsLastStep (isLastStep );
111
112
setDoneIcon (mDoneIcon );
112
113
setAnimationEnabled (mAnimationEnabled );
114
+ setLineColor (mLineColor );
115
+ setErrorColor (mErrorColor );
113
116
}
114
117
115
118
@ Override
@@ -216,13 +219,13 @@ public synchronized void setState(@State int state) {
216
219
if (mErrorText != null ) {
217
220
mTitleColorAnimator = ObjectAnimator
218
221
.ofArgb (mTitleText , "textColor" ,
219
- lastTitleTextColor , getResources (). getColor ( R . color . material_red_500 ) );
222
+ lastTitleTextColor , mErrorColor );
220
223
mTitleColorAnimator .setDuration (mAnimationDuration );
221
224
mTitleColorAnimator .start ();
222
225
if (mSummaryColorAnimator != null ) mSummaryColorAnimator .cancel ();
223
226
mSummaryColorAnimator = ObjectAnimator
224
227
.ofArgb (mSummaryText , "textColor" ,
225
- mSummaryText .getCurrentTextColor (), getResources (). getColor ( R . color . material_red_500 ) );
228
+ mSummaryText .getCurrentTextColor (), mErrorColor );
226
229
mSummaryColorAnimator .setDuration (mAnimationDuration );
227
230
mSummaryColorAnimator .start ();
228
231
@@ -241,7 +244,7 @@ public synchronized void setState(@State int state) {
241
244
if (mSummaryColorAnimator != null ) mSummaryColorAnimator .cancel ();
242
245
mSummaryColorAnimator = ObjectAnimator
243
246
.ofArgb (mSummaryText , "textColor" ,
244
- mSummaryText .getCurrentTextColor (), getResources (). getColor ( R . color . material_grey_500 ) );
247
+ mSummaryText .getCurrentTextColor (), mLineColor );
245
248
mSummaryColorAnimator .setDuration (mAnimationDuration );
246
249
mSummaryColorAnimator .start ();
247
250
@@ -606,6 +609,72 @@ public void setActivatedColorResource(@ColorRes int colorRes) {
606
609
setActivatedColor (getResources ().getColor (colorRes ));
607
610
}
608
611
612
+ /**
613
+ * Get line color
614
+ *
615
+ * @return Line Color
616
+ */
617
+ public @ ColorInt int getLineColor () {
618
+ return mLineColor ;
619
+ }
620
+
621
+ /**
622
+ * Set line color
623
+ *
624
+ * @param color Line Color
625
+ */
626
+ public void setLineColor (@ ColorInt int color ) {
627
+ mLineColor = color ;
628
+ mLineView .setBackgroundColor (color );
629
+ }
630
+
631
+ /**
632
+ * Set line color
633
+ *
634
+ * @param colorRes Line Color resource
635
+ */
636
+ public void setLineColorResource (@ ColorRes int colorRes ) {
637
+ setLineColor (getResources ().getColor (colorRes ));
638
+ }
639
+
640
+ /**
641
+ * Get error highlight color
642
+ *
643
+ * @return Error Highlight Color
644
+ */
645
+ public @ ColorInt int getErrorColor () {
646
+ return mErrorColor ;
647
+ }
648
+
649
+ /**
650
+ * Set error highlight color
651
+ *
652
+ * @param color Error Highlight Color
653
+ */
654
+ public void setErrorColor (@ ColorInt int color ) {
655
+ if (isPreLollipop ()) {
656
+ mErrorIconView .getDrawable ().setColorFilter (color , PorterDuff .Mode .DST_IN );
657
+ } else {
658
+ mErrorIconView .getDrawable ().setTint (color );
659
+ }
660
+ if (mErrorText != null && color != mErrorColor ) {
661
+ if (mTitleColorAnimator != null && mTitleColorAnimator .isRunning ()) mTitleColorAnimator .cancel ();
662
+ if (mSummaryColorAnimator != null && mSummaryColorAnimator .isRunning ()) mSummaryColorAnimator .cancel ();
663
+ mTitleText .setTextColor (color );
664
+ mSummaryText .setTextColor (color );
665
+ }
666
+ mErrorColor = color ;
667
+ }
668
+
669
+ /**
670
+ * Set error highlight color
671
+ *
672
+ * @param colorRes Error Highlight Color resource
673
+ */
674
+ public void setErrorColorResource (@ ColorRes int colorRes ) {
675
+ setErrorColor (getResources ().getColor (colorRes ));
676
+ }
677
+
609
678
/**
610
679
* Get activated point color
611
680
*
@@ -634,6 +703,8 @@ public Parcelable onSaveInstanceState() {
634
703
state .activatedColor = mActivatedColor ;
635
704
state .doneIcon = mDoneIcon ;
636
705
state .errorText = mErrorText ;
706
+ state .lineColor = mLineColor ;
707
+ state .errorColor = mErrorColor ;
637
708
bundle .putParcelable (ItemViewState .STATE , state );
638
709
return bundle ;
639
710
}
@@ -654,6 +725,8 @@ public void onRestoreInstanceState(Parcelable state) {
654
725
setActivatedColor (viewState .activatedColor );
655
726
setDoneIcon (viewState .doneIcon );
656
727
setErrorText (viewState .errorText );
728
+ setLineColor (viewState .lineColor );
729
+ setErrorColor (viewState .errorColor );
657
730
return ;
658
731
}
659
732
super .onRestoreInstanceState (BaseSavedState .EMPTY_STATE );
@@ -670,7 +743,7 @@ protected static class ItemViewState extends BaseSavedState {
670
743
String errorText ;
671
744
672
745
int animationDuration ;
673
- int normalColor , activatedColor ;
746
+ int normalColor , activatedColor , lineColor , errorColor ;
674
747
Drawable doneIcon ;
675
748
676
749
ItemViewState (Parcelable superState ) {
@@ -679,4 +752,8 @@ protected static class ItemViewState extends BaseSavedState {
679
752
680
753
}
681
754
755
+ private static boolean isPreLollipop () {
756
+ return Build .VERSION .SDK_INT < Build .VERSION_CODES .LOLLIPOP ;
757
+ }
758
+
682
759
}
0 commit comments