Code cleanup: improve readability in TrackController

This commit is contained in:
Jimmy Shih
2013-06-14 09:57:01 -07:00
parent 001537863a
commit 33b4b62ad0
@@ -48,17 +48,17 @@ public class TrackController {
private final TextView totalTimeTextView; private final TextView totalTimeTextView;
private final ImageButton recordImageButton; private final ImageButton recordImageButton;
private final ImageButton stopImageButton; private final ImageButton stopImageButton;
private final boolean alwaysShow; private final boolean alwaysShow;
private boolean isRecording; private boolean isRecording;
private boolean isPaused; private boolean isPaused;
private long totalTime = 0; private long totalTime = 0;
// the timestamp for the toal time // the timestamp for the toal time
private long totalTimeTimestamp = 0; private long totalTimeTimestamp = 0;
private boolean isResumed = false; private boolean isResumed = false;
// A runnable to update the total time. // A runnable to update the total time.
private final Runnable updateTotalTimeRunnable = new Runnable() { private final Runnable updateTotalTimeRunnable = new Runnable() {
public void run() { public void run() {
@@ -92,10 +92,11 @@ public class TrackController {
} }
isRecording = recording; isRecording = recording;
isPaused = paused; isPaused = paused;
containerView.setVisibility(alwaysShow || isRecording ? View.VISIBLE : View.GONE); boolean visible = alwaysShow || isRecording;
containerView.setVisibility(visible ? View.VISIBLE : View.GONE);
if (!alwaysShow && !isRecording) { if (!visible) {
stopTimer(); handler.removeCallbacks(updateTotalTimeRunnable);
return; return;
} }
@@ -109,12 +110,12 @@ public class TrackController {
statusTextView.setVisibility(isRecording ? View.VISIBLE : View.INVISIBLE); statusTextView.setVisibility(isRecording ? View.VISIBLE : View.INVISIBLE);
if (isRecording) { if (isRecording) {
statusTextView.setTextColor( statusTextView.setTextColor(activity.getResources()
activity.getResources().getColor(isPaused ? android.R.color.white : R.color.recording_text)); .getColor(isPaused ? android.R.color.white : R.color.recording_text));
statusTextView.setText(isPaused ? R.string.generic_paused : R.string.generic_recording); statusTextView.setText(isPaused ? R.string.generic_paused : R.string.generic_recording);
} }
stopTimer(); handler.removeCallbacks(updateTotalTimeRunnable);
totalTime = isRecording ? getTotalTime() : 0L; totalTime = isRecording ? getTotalTime() : 0L;
totalTimeTextView.setText(StringUtils.formatElapsedTimeWithHour(totalTime)); totalTimeTextView.setText(StringUtils.formatElapsedTimeWithHour(totalTime));
if (isRecording && !isPaused) { if (isRecording && !isPaused) {
@@ -127,26 +128,19 @@ public class TrackController {
isResumed = true; isResumed = true;
update(recording, paused); update(recording, paused);
} }
public void onPause() { public void onPause() {
isResumed = false; isResumed = false;
stopTimer(); handler.removeCallbacks(updateTotalTimeRunnable);
} }
public void hide() { public void hide() {
containerView.setVisibility(View.GONE); containerView.setVisibility(View.GONE);
} }
public void show() { public void show() {
containerView.setVisibility(View.VISIBLE); containerView.setVisibility(View.VISIBLE);
} }
/**
* Stops the timer.
*/
private void stopTimer() {
handler.removeCallbacks(updateTotalTimeRunnable);
}
/** /**
* Gets the total time for the current recording track. * Gets the total time for the current recording track.