88import android .content .res .TypedArray ;
99import android .graphics .*;
1010import android .os .Build ;
11+ import android .os .Handler ;
1112import android .os .Parcel ;
1213import android .os .Parcelable ;
1314import android .support .annotation .ArrayRes ;
1718import android .support .v4 .content .ContextCompat ;
1819import android .support .v4 .view .PagerAdapter ;
1920import android .support .v4 .view .ViewPager ;
21+ import android .support .v7 .widget .ViewUtils ;
22+ import android .view .animation .AlphaAnimation ;
23+ import android .view .animation .Animation ;
24+ import android .view .animation .LinearInterpolator ;
25+ import android .view .animation .RotateAnimation ;
2026import android .widget .LinearLayout ;
2127import android .util .AttributeSet ;
2228import android .util .DisplayMetrics ;
2329import android .view .MotionEvent ;
2430import android .view .View ;
31+ import android .widget .TextView ;
2532import com .devmike .pagestepindicator .R ;
2633
2734import java .util .ArrayList ;
@@ -35,6 +42,7 @@ public class PageStepIndicator extends View {
3542 private static final int DEFAULT_BACKGROUND_COLOR = R .color .background_default ;
3643 private static final int DEFAULT_STEP_COLOR = R .color .step_default ;
3744 private static final int DEFAULT_CURRENT_STEP_COLOR = R .color .current_step_default ;
45+ private static final int DEFAULT_INACTIVE_TITLE = R .color .lighter_gray ;
3846 private static final int DEFAULT_TEXT_COLOR = R .color .text_default ;
3947 private static final int DEFAULT_SECONDARY_TEXT_COLOR = R .color .secondary_text_default ;
4048 public static final float DEFAULT_LINE_HEIGHT =6.0f ;
@@ -154,7 +162,8 @@ private void init(Context context, AttributeSet attributeSet) {
154162 Color .colorToHSV (currentColor , hsvCurrent );
155163 Color .colorToHSV (backgroundColor , hsvBG );
156164 Color .colorToHSV (stepColor , hsvProgress );
157- animateView (paint , currentColor , currentColor );
165+ //animateView(tText, currentColor, currentColor);
166+ initAnimation ();
158167 invalidate ();
159168 }
160169
@@ -176,8 +185,8 @@ private void initAttributes(Context context, AttributeSet attributeSet) {
176185 backgroundColor = attr .getColor (R .styleable .PageStepIndicator_pgBackgroundColor , ContextCompat .getColor (context , DEFAULT_BACKGROUND_COLOR ));
177186 textColor = attr .getColor (R .styleable .PageStepIndicator_pgTextColor , ContextCompat .getColor (context , DEFAULT_TEXT_COLOR ));
178187 secondaryTextColor = attr .getColor (R .styleable .PageStepIndicator_pgSecondaryTextColor , ContextCompat .getColor (context , DEFAULT_SECONDARY_TEXT_COLOR ));
179- pageInActiveTitleColor = attr .getColor (R .styleable .PageStepIndicator_pgInActiveTitleColor , ContextCompat .getColor (context , DEFAULT_SECONDARY_TEXT_COLOR ));
180- pageActiveTitleColor = attr .getColor (R .styleable .PageStepIndicator_pgActiveTitleColor , ContextCompat .getColor (context , DEFAULT_CURRENT_STEP_COLOR ));
188+ pageInActiveTitleColor = attr .getColor (R .styleable .PageStepIndicator_pgInActiveTitleColor , ContextCompat .getColor (context , DEFAULT_INACTIVE_TITLE ));
189+ pageActiveTitleColor = attr .getColor (R .styleable .PageStepIndicator_pgActiveTitleColor , ContextCompat .getColor (context , DEFAULT_TEXT_COLOR ));
181190 pageTitleId = attr .getResourceId (R .styleable .PageStepIndicator_pgTitles , View .NO_ID );
182191 pageStrokeAlpha = attr .getInt (R .styleable .PageStepIndicator_pgStrokeAlpha , DEFAULT_STROKE_ALPHA );
183192
@@ -361,7 +370,7 @@ protected void onDraw(Canvas canvas) {
361370 pText .setColor (secondaryTextColor );
362371
363372 tText .setColor (pageInActiveTitleColor );
364- animateView (tText , pageActiveTitleColor , pageInActiveTitleColor );
373+ animateView (tText , pageActiveTitleColor , pageInActiveTitleColor , canvas );
365374
366375 } else if (i == currentStepPosition ) {
367376 //draw current step
@@ -385,7 +394,7 @@ protected void onDraw(Canvas canvas) {
385394 pText .setColor (textColor );
386395
387396 tText .setColor (pageActiveTitleColor );
388- animateView (tText , pageInActiveTitleColor , pageActiveTitleColor );
397+ animateView (tText , pageInActiveTitleColor , pageActiveTitleColor , canvas );
389398
390399 } else {
391400 //draw next step
@@ -394,7 +403,7 @@ protected void onDraw(Canvas canvas) {
394403 pText .setColor (secondaryTextColor );
395404
396405 tText .setColor (pageInActiveTitleColor );
397- animateView (tText , pageActiveTitleColor , pageInActiveTitleColor );
406+ animateView (tText , pageActiveTitleColor , pageInActiveTitleColor , canvas );
398407
399408 //draw transition
400409 if (i == currentStepPosition + 1 && offsetPixel > 0 && pagerScrollState == 1 ) {
@@ -419,8 +428,30 @@ protected void onDraw(Canvas canvas) {
419428
420429 }
421430
422- private void animateView (Paint target , @ ColorInt int defaultColor , @ ColorInt int toColor ){
431+ private void initAnimation () {
432+ AlphaAnimation animation = new AlphaAnimation (0 , 1 );
433+ animation .setDuration (7500L );
434+ animation .setInterpolator (new LinearInterpolator ());
435+ //startAnimation(animation);
436+ }
437+
438+ private void animateView (Paint target , @ ColorInt int defaultColor , @ ColorInt int toColor , Canvas canvas ){
439+ //new ArgbEvaluator(),
423440 //TODO: Do animation works here
441+ ObjectAnimator animator = ObjectAnimator .ofObject (target ,
442+ "color" , new ArgbEvaluator (), toColor , defaultColor );
443+ animator .setDuration (2000 );
444+
445+ animator .addUpdateListener (new ValueAnimator .AnimatorUpdateListener () {
446+ @ Override
447+ public void onAnimationUpdate (ValueAnimator animation ) {
448+ float animFrac =animation .getAnimatedFraction ();
449+ tText .setColor (Color .BLACK );
450+ invalidate ();
451+ // canvas.translate(0, 50);
452+ }
453+ });
454+ animator .start ();
424455
425456 }
426457
@@ -431,6 +462,8 @@ private void drawTextCentred(Canvas canvas, Paint paint, String text, float cx,
431462
432463 private void drawTextBottom (Canvas canvas , Paint paint , String text , float cx , float cy ) {
433464 paint .getTextBounds (text , 0 , text .length (), textBounds );
465+ Path path = new Path ();
466+
434467 canvas .drawText (text , cx , cy - textBounds .exactCenterY (), paint );
435468 }
436469
0 commit comments