Skip to content

Commit

Permalink
Make call alternately 'setTime' and 'animateToTime'
Browse files Browse the repository at this point in the history
  • Loading branch information
shota-saito committed Aug 17, 2017
1 parent ca1ce09 commit b3a0ba0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit b3a0ba0

Please sign in to comment.