Smoother second hand for dynamic clock

This commit is contained in:
paphonb
2019-07-09 10:45:23 +07:00
parent a4558e8075
commit d3f594e60f
2 changed files with 3 additions and 5 deletions

View File

@@ -17,10 +17,8 @@ public class AutoUpdateClock extends FastBitmapDrawable implements Runnable {
}
private void rescheduleUpdate() {
long millisInSecond = 1000L;
unscheduleSelf(this);
long uptimeMillis = SystemClock.uptimeMillis();
scheduleSelf(this, uptimeMillis - uptimeMillis % millisInSecond + millisInSecond);
scheduleSelf(this, SystemClock.uptimeMillis() + 100);
}
void updateLayers(ClockLayers layers) {
@@ -42,7 +40,6 @@ public class AutoUpdateClock extends FastBitmapDrawable implements Runnable {
public void drawInternal(Canvas canvas, Rect bounds) {
if (mLayers != null) {
canvas.drawBitmap(mLayers.iconBitmap, null, bounds, mPaint);
mLayers.updateAngles();
canvas.scale(mLayers.scale, mLayers.scale, bounds.exactCenterX() + ((float) mLayers.offset), bounds.exactCenterY() + ((float) mLayers.offset));
mLayers.clipToMask(canvas);
mLayers.drawForeground(canvas);

View File

@@ -75,6 +75,7 @@ public class ClockLayers {
int hour = (mCurrentTime.get(Calendar.HOUR) + (12 - mDefaultHour)) % 12;
int minute = (mCurrentTime.get(Calendar.MINUTE) + (60 - mDefaultMinute)) % 60;
int second = (mCurrentTime.get(Calendar.SECOND) + (60 - mDefaultSecond)) % 60;
int millis = second * 1000 + mCurrentTime.get(Calendar.MILLISECOND);
boolean hasChanged = false;
if (mHourIndex != -1 && mLayerDrawable.getDrawable(mHourIndex).setLevel(hour * 60 + mCurrentTime.get(Calendar.MINUTE))) {
@@ -83,7 +84,7 @@ public class ClockLayers {
if (mMinuteIndex != -1 && mLayerDrawable.getDrawable(mMinuteIndex).setLevel(minute + mCurrentTime.get(Calendar.HOUR) * 60)) {
hasChanged = true;
}
if (mSecondIndex != -1 && mLayerDrawable.getDrawable(mSecondIndex).setLevel(second * 10)) {
if (mSecondIndex != -1 && mLayerDrawable.getDrawable(mSecondIndex).setLevel(millis / 100)) {
hasChanged = true;
}
return hasChanged;