Skip to content

Commit

Permalink
Make setTime()
Browse files Browse the repository at this point in the history
  • Loading branch information
shota-saito committed Aug 14, 2017
1 parent 9c7e090 commit 0322d52
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

final ClockAnimationView clockAnimationView = (ClockAnimationView) findViewById(R.id.image);
clockAnimationView.animateToTime(0, 45);
clockAnimationView.setTime(0, 45);

final Button b = (Button) findViewById(R.id.button);
b.setText("to 2:30");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public ClockAnimationView(Context context, AttributeSet attrs, int defStyleAttr)
@ColorInt
private int rimPaintColor;
private float rimStrokeWidth;
private long duration;

private ClockDrawable clockDrawable;

private void init(Context context, AttributeSet attrs) {
long duration;
if (attrs != null) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ClockAnimationView);
duration = ta.getInt(R.styleable.ClockAnimationView_animDurations, ANIMATION_DURATION);
Expand Down Expand Up @@ -79,7 +79,7 @@ private void init(Context context, AttributeSet attrs) {
*/
public void setTime(int hours, int minutes) {
checkParams(hours, minutes);
clockDrawable.animate(new ClockTime(hours, minutes));
clockDrawable.setTime(new ClockTime(hours, minutes));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ClockDrawable extends Drawable implements Animatable {
private boolean minAnimInterrupted;

private ClockTime previousTime;
private final long duration;
private long duration;

@Nullable
private ClockAnimationListener clockAnimationListener;
Expand All @@ -59,11 +59,22 @@ public class ClockDrawable extends Drawable implements Animatable {
init();
}

ClockDrawable(Paint facePaint, Paint rimPaint, long duration, int hour, int minute) {
this.facePaint = facePaint;
this.rimPaint = rimPaint;
this.duration = duration;
init(hour, minute);
}

private void init() {
this.init(0, 0);
}

private void init(int hour, int minute) {
hourHandPath = new Path();
minuteHandPath = new Path();

previousTime = new ClockTime(0, 0);
previousTime = new ClockTime(hour, minute);

setUpMinuteAnimator();
setUpHourAnimator();
Expand Down Expand Up @@ -139,28 +150,12 @@ public void start() {
minuteAnimator.start();
}

// TODO:
// void setTime(ClockTime newTime) {
// long minutesDifference = getMinutesDifference(previousTime, newTime);
// // 60min ... 360grade
// // minDif .. minDelta
// float minDeltaRotation = ((float) minutesDifference * 360f) / 60f;
// // 720min ... 360grade = 12h ... 360grade
// // minDif ... hourDelta
// float hourDeltaRotation = ((float) minutesDifference * 360f) / 720f;
//
// remainingMinRotation += minDeltaRotation;
// remainingHourRotation += hourDeltaRotation;
//
// targetHourRotation = currentHourRotation + remainingHourRotation;
// targetMinRotation = currentMinRotation + remainingMinRotation;
//
// start();
//
// previousTime = newTime;
//
// invalidateSelf();
// }
void setTime(ClockTime newTime) {
duration = 0L;
setUpMinuteAnimator();
setUpHourAnimator();
animate(newTime);
}

void animate(ClockTime newTime) {
long minutesDifference = getMinutesDifference(previousTime, newTime);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jp.shts.android.library.clockanimationview;

class ClockTime {
int hours, minutes;
private int hours, minutes;

ClockTime(int hours, int minutes) {
this.hours = hours;
Expand Down

0 comments on commit 0322d52

Please sign in to comment.