From c2b6ffa22de67d5cca9d861424f12ca33e1be04e Mon Sep 17 00:00:00 2001 From: Paul Cochrane Date: Wed, 25 Mar 2015 20:56:46 +0100 Subject: [PATCH] Pad single digit numbers with zeros to a width of two This change gives the time display a more standardised/common look. When using the app, I was surprised to see the seconds display go down to a single digit and the display not to be padded by a zero, as this is not the behaviour a standard digital clock has. This is the reasoning behind this commit: to reduce surprise to users. --- src/com/hlidskialf/android/pomodoro/Pomodoro.java | 2 +- src/com/hlidskialf/android/widget/CountDownView.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/hlidskialf/android/pomodoro/Pomodoro.java b/src/com/hlidskialf/android/pomodoro/Pomodoro.java index 188428b..bbff8c7 100644 --- a/src/com/hlidskialf/android/pomodoro/Pomodoro.java +++ b/src/com/hlidskialf/android/pomodoro/Pomodoro.java @@ -136,7 +136,7 @@ public static String format_time(long when) long left = when - System.currentTimeMillis(); long min = Math.abs((long)(left / 60000)); long sec = Math.abs((long)((left - min) / 1000) % 60); - return ((left < 0 ? "-" : "" )+ min+":"+sec); + return ((left < 0 ? "-" : "" ) + String.format("%02d", min) + ":" + String.format("%02d", sec)); } diff --git a/src/com/hlidskialf/android/widget/CountDownView.java b/src/com/hlidskialf/android/widget/CountDownView.java index 2d8a033..bf8686e 100644 --- a/src/com/hlidskialf/android/widget/CountDownView.java +++ b/src/com/hlidskialf/android/widget/CountDownView.java @@ -43,7 +43,7 @@ public void start(long durationMillis, long startTime) public void stop() { - setText("0:0"); + setText("00:00"); mRunning = false; } public void pause() @@ -61,6 +61,6 @@ protected void tick() long left = mUntil - System.currentTimeMillis(); long min = Math.abs((long)(left / 60000)); long sec = Math.abs((long)((left - min) / 1000) % 60); - setText((left < 0 ? "-" : "" )+ min+":"+sec); + setText((left < 0 ? "-" : "" ) + String.format("%02d", min) + ":" + String.format("%02d", sec)); } }