public abstract int getBackgroundColor();
+ // forAngle should be on [0.0,1.0) but 1.0 must be tolerated
public abstract int getSecondColor(float forAngle);
public abstract int getMinuteColor(float forAngle);
@Override
public int getSecondColor(float forAngle) {
+ if (forAngle >= 1.0f || forAngle < 0.0f) forAngle = 0.0f;
return mColors[((int) (forAngle * COLORS_CACHE_COUNT))];
}
@Override
public int getMinuteColor(float forAngle) {
+ if (forAngle >= 1.0f || forAngle < 0.0f) forAngle = 0.0f;
return mColors[((int) (forAngle * COLORS_CACHE_COUNT))];
}
@Override
public int getHourColor(float forAngle) {
+ if (forAngle >= 1.0f || forAngle < 0.0f) forAngle = 0.0f;
return mColors[((int) (forAngle * COLORS_CACHE_COUNT))];
}
@Override
public int getDayColor(float forAngle) {
+ if (forAngle >= 1.0f || forAngle < 0.0f) forAngle = 0.0f;
return mColors[((int) (forAngle * COLORS_CACHE_COUNT))];
}
@Override
public int getMonthColor(float forAngle) {
+ if (forAngle >= 1.0f || forAngle < 0.0f) forAngle = 0.0f;
return mColors[((int) (forAngle * COLORS_CACHE_COUNT))];
}
private boolean mVariableLineWidth;
private boolean mWatcherRegistered;
- private float mStartTime;
private Time mCalendar;
private final Paint mPaint = new Paint();
mCalendar = new Time();
mCalendar.setToNow();
- mStartTime = mCalendar.second * 1000.0f;
final Paint paint = mPaint;
paint.setAntiAlias(true);
}
mCalendar = new Time();
mCalendar.setToNow();
- mStartTime = mCalendar.second * 1000.0f;
} else {
if (mWatcherRegistered) {
mWatcherRegistered = false;
final Time calendar = mCalendar;
final Paint paint = mPaint;
- calendar.setToNow();
+ final long millis = System.currentTimeMillis();
+ calendar.set(millis);
calendar.normalize(false);
int s = width / 2;
if (mShowSeconds) {
// Draw seconds
- angle = ((mStartTime + SystemClock.elapsedRealtime()) % 60000) / 60000.0f;
- if (angle < 0) angle = -angle;
-
+ angle = (float) (millis % 60000) / 60000.0f;
+ //Log.d("PolarClock", "millis=" + millis + ", angle=" + angle);
paint.setColor(mPalette.getSecondColor(angle));
if (mVariableLineWidth) {
size -= (SMALL_GAP + lastRingThickness);
rect.set(-size, -size, size, size);
- angle = (calendar.month - 1) / 11.0f;
+ angle = (calendar.month) / 11.0f; // NB: month is already on [0..11]
paint.setColor(mPalette.getMonthColor(angle));