From 33b4b62ad03df6790005ed2e5b215ad0df0a2dce Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Fri, 14 Jun 2013 09:57:01 -0700 Subject: [PATCH] Code cleanup: improve readability in TrackController --- .../apps/mytracks/TrackController.java | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackController.java b/MyTracks/src/com/google/android/apps/mytracks/TrackController.java index 91d89a7ea..492c3ee03 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackController.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackController.java @@ -48,17 +48,17 @@ public class TrackController { private final TextView totalTimeTextView; private final ImageButton recordImageButton; private final ImageButton stopImageButton; - private final boolean alwaysShow; - + private final boolean alwaysShow; + private boolean isRecording; private boolean isPaused; private long totalTime = 0; - + // the timestamp for the toal time private long totalTimeTimestamp = 0; private boolean isResumed = false; - + // A runnable to update the total time. private final Runnable updateTotalTimeRunnable = new Runnable() { public void run() { @@ -92,10 +92,11 @@ public class TrackController { } isRecording = recording; isPaused = paused; - containerView.setVisibility(alwaysShow || isRecording ? View.VISIBLE : View.GONE); + boolean visible = alwaysShow || isRecording; + containerView.setVisibility(visible ? View.VISIBLE : View.GONE); - if (!alwaysShow && !isRecording) { - stopTimer(); + if (!visible) { + handler.removeCallbacks(updateTotalTimeRunnable); return; } @@ -109,12 +110,12 @@ public class TrackController { statusTextView.setVisibility(isRecording ? View.VISIBLE : View.INVISIBLE); if (isRecording) { - statusTextView.setTextColor( - activity.getResources().getColor(isPaused ? android.R.color.white : R.color.recording_text)); + statusTextView.setTextColor(activity.getResources() + .getColor(isPaused ? android.R.color.white : R.color.recording_text)); statusTextView.setText(isPaused ? R.string.generic_paused : R.string.generic_recording); } - stopTimer(); + handler.removeCallbacks(updateTotalTimeRunnable); totalTime = isRecording ? getTotalTime() : 0L; totalTimeTextView.setText(StringUtils.formatElapsedTimeWithHour(totalTime)); if (isRecording && !isPaused) { @@ -127,26 +128,19 @@ public class TrackController { isResumed = true; update(recording, paused); } - + public void onPause() { isResumed = false; - stopTimer(); + handler.removeCallbacks(updateTotalTimeRunnable); } - + public void hide() { containerView.setVisibility(View.GONE); } - + public void show() { containerView.setVisibility(View.VISIBLE); } - - /** - * Stops the timer. - */ - private void stopTimer() { - handler.removeCallbacks(updateTotalTimeRunnable); - } /** * Gets the total time for the current recording track.