summaryrefslogtreecommitdiffstats
path: root/src/com/android/deskclock/AnalogClock.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/deskclock/AnalogClock.java')
-rw-r--r--src/com/android/deskclock/AnalogClock.java53
1 files changed, 18 insertions, 35 deletions
diff --git a/src/com/android/deskclock/AnalogClock.java b/src/com/android/deskclock/AnalogClock.java
index 8b1bf9a57..55fff90a8 100644
--- a/src/com/android/deskclock/AnalogClock.java
+++ b/src/com/android/deskclock/AnalogClock.java
@@ -61,8 +61,8 @@ public class AnalogClock extends View {
private String mTimeZoneId;
private boolean mNoSeconds = false;
- private float mDotRadius;
- private float mDotOffset;
+ private final float mDotRadius;
+ private final float mDotOffset;
private Paint mDotPaint;
public AnalogClock(Context context) {
@@ -207,47 +207,30 @@ public class AnalogClock extends View {
canvas.drawCircle(x, y - (h / 2) + mDotOffset, mDotRadius, mDotPaint);
}
- canvas.save();
- canvas.rotate(mHour / 12.0f * 360.0f, x, y);
- final Drawable hourHand = mHourHand;
- if (changed) {
- w = hourHand.getIntrinsicWidth();
- h = hourHand.getIntrinsicHeight();
- hourHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2));
- }
- hourHand.draw(canvas);
- canvas.restore();
-
+ drawHand(canvas, mHourHand, x, y, mHour / 12.0f * 360.0f, changed);
+ drawHand(canvas, mMinuteHand, x, y, mMinutes / 60.0f * 360.0f, changed);
if (!mNoSeconds) {
- canvas.save();
- canvas.rotate(mSeconds / 60.0f * 360.0f, x, y);
-
- final Drawable secondHand = mSecondHand;
- if (changed) {
- w = secondHand.getIntrinsicWidth();
- h = secondHand.getIntrinsicHeight();
- secondHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2));
- }
- secondHand.draw(canvas);
- canvas.restore();
- }
- canvas.save();
- canvas.rotate(mMinutes / 60.0f * 360.0f, x, y);
-
- final Drawable minuteHand = mMinuteHand;
- if (changed) {
- w = minuteHand.getIntrinsicWidth();
- h = minuteHand.getIntrinsicHeight();
- minuteHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2));
+ drawHand(canvas, mSecondHand, x, y, mSeconds / 60.0f * 360.0f, changed);
}
- minuteHand.draw(canvas);
- canvas.restore();
if (scaled) {
canvas.restore();
}
}
+ private void drawHand(Canvas canvas, Drawable hand, int x, int y, float angle,
+ boolean changed) {
+ canvas.save();
+ canvas.rotate(angle, x, y);
+ if (changed) {
+ final int w = hand.getIntrinsicWidth();
+ final int h = hand.getIntrinsicHeight();
+ hand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2));
+ }
+ hand.draw(canvas);
+ canvas.restore();
+ }
+
private void onTimeChanged() {
mCalendar.setToNow();