Freeing MyTracks from isRecording() calls.

This commit is contained in:
Rodrigo Damazio
2011-05-31 03:09:08 -03:00
parent 73e4af98cc
commit ed3ff01c22
8 changed files with 106 additions and 79 deletions
@@ -22,11 +22,13 @@ import com.google.android.apps.mytracks.content.TrackDataHub;
import com.google.android.apps.mytracks.content.TrackDataHub.ListenerDataType;
import com.google.android.apps.mytracks.content.TrackDataListener;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.services.ServiceStateHelper;
import com.google.android.apps.mytracks.services.tasks.StatusAnnouncerFactory;
import com.google.android.apps.mytracks.util.ApiFeatures;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.content.SharedPreferences;
import android.location.Location;
import android.os.Bundle;
import android.util.DisplayMetrics;
@@ -46,6 +48,18 @@ import java.util.EnumSet;
* @author Rodrigo Damazio
*/
public class StatsActivity extends Activity implements TrackDataListener {
/**
* A runnable for posting to the UI thread. Will update the total time field.
*/
private final Runnable updateResults = new Runnable() {
public void run() {
if (dataHub.isRecordingSelected()) {
utils.setTime(R.id.total_time_register,
System.currentTimeMillis() - startTime);
}
}
};
private StatsUtilities utils;
private UIUpdateThread thread;
@@ -61,18 +75,7 @@ public class StatsActivity extends Activity implements TrackDataListener {
private boolean showCurrentSegment = false;
private TrackDataHub dataHub;
/**
* A runnable for posting to the UI thread. Will update the total time field.
*/
private final Runnable updateResults = new Runnable() {
public void run() {
if (dataHub.isRecordingSelected()) {
utils.setTime(R.id.total_time_register,
System.currentTimeMillis() - startTime);
}
}
};
private SharedPreferences preferences;
/**
* A thread that updates the total time field every second.
@@ -87,7 +90,7 @@ public class StatsActivity extends Activity implements TrackDataListener {
@Override
public void run() {
Log.i(TAG, "Started UI update thread");
while (MyTracks.getInstance().isRecording()) {
while (ServiceStateHelper.isRecording(StatsActivity.this, preferences)) {
runOnUiThread(updateResults);
try {
Thread.sleep(1000L);
@@ -105,6 +108,7 @@ public class StatsActivity extends Activity implements TrackDataListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences = getSharedPreferences(Constants.SETTINGS_NAME, 0);
dataHub = MyTracks.getInstance().getDataHub();
utils = new StatsUtilities(this);