diff --git a/.idea/misc.xml b/.idea/misc.xml index fbb6828..5d19981 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/java/jp/shts/android/library/sample/clockanimationview/MainActivity.java b/app/src/main/java/jp/shts/android/library/sample/clockanimationview/MainActivity.java index 32190e6..d307479 100644 --- a/app/src/main/java/jp/shts/android/library/sample/clockanimationview/MainActivity.java +++ b/app/src/main/java/jp/shts/android/library/sample/clockanimationview/MainActivity.java @@ -27,7 +27,7 @@ public void onClick(View v) { b.setText("to 7:10"); break; case 1: - clockAnimationView.animateToTime(7, 10); + clockAnimationView.setTime(7, 10); b.setText("to 9:50"); break; case 2: diff --git a/clockanimation/src/main/java/jp/shts/android/library/clockanimationview/ClockAnimationView.java b/clockanimation/src/main/java/jp/shts/android/library/clockanimationview/ClockAnimationView.java index b12050f..0c02205 100644 --- a/clockanimation/src/main/java/jp/shts/android/library/clockanimationview/ClockAnimationView.java +++ b/clockanimation/src/main/java/jp/shts/android/library/clockanimationview/ClockAnimationView.java @@ -90,7 +90,7 @@ public void setTime(int hours, int minutes) { */ public void animateToTime(int hours, int minutes) { checkParams(hours, minutes); - clockDrawable.animate(new ClockTime(hours, minutes)); + clockDrawable.animateToTime(new ClockTime(hours, minutes)); } private void checkParams(int hours, int minutes) { diff --git a/clockanimation/src/main/java/jp/shts/android/library/clockanimationview/ClockDrawable.java b/clockanimation/src/main/java/jp/shts/android/library/clockanimationview/ClockDrawable.java index af2d83e..886904b 100644 --- a/clockanimation/src/main/java/jp/shts/android/library/clockanimationview/ClockDrawable.java +++ b/clockanimation/src/main/java/jp/shts/android/library/clockanimationview/ClockDrawable.java @@ -151,13 +151,18 @@ public void start() { } void setTime(ClockTime newTime) { - duration = 0L; + setUpMinuteAnimator(0L); + setUpHourAnimator(0L); + calcAndExecute(newTime); + } + + void animateToTime(ClockTime newTime) { setUpMinuteAnimator(); setUpHourAnimator(); - animate(newTime); + calcAndExecute(newTime); } - void animate(ClockTime newTime) { + private void calcAndExecute(ClockTime newTime) { long minutesDifference = getMinutesDifference(previousTime, newTime); // 60min ... 360grade // minDif .. minDelta @@ -226,6 +231,10 @@ void setRimPaint(Paint rimPaint) { } private void setUpMinuteAnimator() { + setUpMinuteAnimator(this.duration); + } + + private void setUpMinuteAnimator(long duration) { minuteAnimator = ValueAnimator.ofFloat(0, 0); minuteAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); minuteAnimator.setDuration(duration); @@ -252,6 +261,10 @@ public void onAnimationEnd(Animator animation) { } private void setUpHourAnimator() { + setUpHourAnimator(this.duration); + } + + private void setUpHourAnimator(long duration) { hourAnimator = ValueAnimator.ofFloat(0, 0); hourAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); hourAnimator.setDuration(duration);