66import android .annotation .SuppressLint ;
77import android .content .Context ;
88import android .content .res .TypedArray ;
9+ import android .graphics .PorterDuff ;
910import android .graphics .drawable .Drawable ;
11+ import android .os .Build ;
1012import android .os .Bundle ;
1113import android .os .Parcelable ;
1214import android .support .annotation .*;
@@ -51,7 +53,7 @@ public class VerticalStepperItemView extends FrameLayout {
5153 * View attributes
5254 */
5355 private int mAnimationDuration ;
54- private int mNormalColor , mActivatedColor ;
56+ private int mNormalColor , mActivatedColor , mLineColor , mErrorColor ;
5557 private Drawable mDoneIcon ;
5658 private boolean mAnimationEnabled = true ;
5759
@@ -77,14 +79,11 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
7779
7880 prepareViews (context );
7981
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 );
8482 DP = getResources ().getDimensionPixelSize (R .dimen .dp1 );
8583
8684 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 );
8887
8988 mTitle = a .getString (R .styleable .VerticalStepperItemView_step_title );
9089 mSummary = a .getString (R .styleable .VerticalStepperItemView_step_summary );
@@ -95,6 +94,8 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
9594 mActivatedColor = a .getColor (R .styleable .VerticalStepperItemView_step_activated_color , mActivatedColor );
9695 mAnimationDuration = a .getInt (R .styleable .VerticalStepperItemView_step_animation_duration , mAnimationDuration );
9796 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 );
9899
99100 if (a .hasValue (R .styleable .VerticalStepperItemView_step_done_icon )) {
100101 mDoneIcon = a .getDrawable (R .styleable .VerticalStepperItemView_step_done_icon );
@@ -110,6 +111,8 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
110111 setIsLastStep (isLastStep );
111112 setDoneIcon (mDoneIcon );
112113 setAnimationEnabled (mAnimationEnabled );
114+ setLineColor (mLineColor );
115+ setErrorColor (mErrorColor );
113116 }
114117
115118 @ Override
@@ -216,13 +219,13 @@ public synchronized void setState(@State int state) {
216219 if (mErrorText != null ) {
217220 mTitleColorAnimator = ObjectAnimator
218221 .ofArgb (mTitleText , "textColor" ,
219- lastTitleTextColor , getResources (). getColor ( R . color . material_red_500 ) );
222+ lastTitleTextColor , mErrorColor );
220223 mTitleColorAnimator .setDuration (mAnimationDuration );
221224 mTitleColorAnimator .start ();
222225 if (mSummaryColorAnimator != null ) mSummaryColorAnimator .cancel ();
223226 mSummaryColorAnimator = ObjectAnimator
224227 .ofArgb (mSummaryText , "textColor" ,
225- mSummaryText .getCurrentTextColor (), getResources (). getColor ( R . color . material_red_500 ) );
228+ mSummaryText .getCurrentTextColor (), mErrorColor );
226229 mSummaryColorAnimator .setDuration (mAnimationDuration );
227230 mSummaryColorAnimator .start ();
228231
@@ -241,7 +244,7 @@ public synchronized void setState(@State int state) {
241244 if (mSummaryColorAnimator != null ) mSummaryColorAnimator .cancel ();
242245 mSummaryColorAnimator = ObjectAnimator
243246 .ofArgb (mSummaryText , "textColor" ,
244- mSummaryText .getCurrentTextColor (), getResources (). getColor ( R . color . material_grey_500 ) );
247+ mSummaryText .getCurrentTextColor (), mLineColor );
245248 mSummaryColorAnimator .setDuration (mAnimationDuration );
246249 mSummaryColorAnimator .start ();
247250
@@ -606,6 +609,72 @@ public void setActivatedColorResource(@ColorRes int colorRes) {
606609 setActivatedColor (getResources ().getColor (colorRes ));
607610 }
608611
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+
609678 /**
610679 * Get activated point color
611680 *
@@ -634,6 +703,8 @@ public Parcelable onSaveInstanceState() {
634703 state .activatedColor = mActivatedColor ;
635704 state .doneIcon = mDoneIcon ;
636705 state .errorText = mErrorText ;
706+ state .lineColor = mLineColor ;
707+ state .errorColor = mErrorColor ;
637708 bundle .putParcelable (ItemViewState .STATE , state );
638709 return bundle ;
639710 }
@@ -654,6 +725,8 @@ public void onRestoreInstanceState(Parcelable state) {
654725 setActivatedColor (viewState .activatedColor );
655726 setDoneIcon (viewState .doneIcon );
656727 setErrorText (viewState .errorText );
728+ setLineColor (viewState .lineColor );
729+ setErrorColor (viewState .errorColor );
657730 return ;
658731 }
659732 super .onRestoreInstanceState (BaseSavedState .EMPTY_STATE );
@@ -670,7 +743,7 @@ protected static class ItemViewState extends BaseSavedState {
670743 String errorText ;
671744
672745 int animationDuration ;
673- int normalColor , activatedColor ;
746+ int normalColor , activatedColor , lineColor , errorColor ;
674747 Drawable doneIcon ;
675748
676749 ItemViewState (Parcelable superState ) {
@@ -679,4 +752,8 @@ protected static class ItemViewState extends BaseSavedState {
679752
680753 }
681754
755+ private static boolean isPreLollipop () {
756+ return Build .VERSION .SDK_INT < Build .VERSION_CODES .LOLLIPOP ;
757+ }
758+
682759}
0 commit comments