From a88f6334a0eae3468d51ea2ebbe4037a9616745b Mon Sep 17 00:00:00 2001 From: Benjamin Ragheb Date: Tue, 18 Jun 2013 14:00:50 -0400 Subject: [PATCH] Added code to schedule the countdown timer for per-minute updates, rather than per-second. Note that this only changes the timer, not the display, which still includes seconds. --- DCM/src/main/java/com/ucb/dcm/NowActivity.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/DCM/src/main/java/com/ucb/dcm/NowActivity.java b/DCM/src/main/java/com/ucb/dcm/NowActivity.java index 27307d5..7c9c24f 100644 --- a/DCM/src/main/java/com/ucb/dcm/NowActivity.java +++ b/DCM/src/main/java/com/ucb/dcm/NowActivity.java @@ -31,15 +31,23 @@ public class NowActivity extends SherlockFragment { - //Remember, months are 0 indexed for some reason. - public static final Date MARATHON_START_DATE = new Date(2013 - 1900, 5, 28, 16, 30, 0); + // TODO: Get start date from schedule data; show message before initial download. + // Remember, months are 0 indexed for some reason. + public static final Date MARATHON_START_DATE = new Date(2013 - 1900, 6 - 1, 28, 16, 30, 0); private Handler clock; private Runnable updateClockRunnable = new Runnable() { @Override public void run() { updateClock(); - clock.postDelayed(this, 1000); + clock.postDelayed(this, timeIntervalUntilNextMinuteChange()); + } + private long timeIntervalUntilNextMinuteChange() { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.MILLISECOND, 0); + cal.set(Calendar.SECOND, 0); + cal.add(Calendar.MINUTE, 1); + return cal.getTimeInMillis() - System.currentTimeMillis(); } }; @@ -120,6 +128,7 @@ private void updateClock(){ int minutesVal = (secondsBetween - daysVal * 60 * 60 * 24 - hoursVal * 60 * 60) / 60; minutes.setText(Integer.toString(minutesVal)); + // TODO: Remove this since we are now only updating once a minute. TextView seconds = (TextView) getView().findViewById(R.id.countdown_seconds); int secondsVal = (secondsBetween - daysVal * 60 * 60 * 24 - hoursVal * 60 * 60 - minutesVal * 60); seconds.setText(Integer.toString(secondsVal));