the map now requests updated track recording from the background service as soon as it becomes visible.
This commit is contained in:
parent
6f7f58fa23
commit
34125d7184
3 changed files with 34 additions and 8 deletions
|
@ -232,9 +232,11 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
|||
// load state of tracker service - see if anything changed
|
||||
loadTrackerServiceState(mActivity);
|
||||
|
||||
// center map on current position - if TrackerService is running
|
||||
// request an updated track recording from service - if TrackerService is running
|
||||
if (mTrackerServiceRunning) {
|
||||
mController.setCenter(convertToGeoPoint(mCurrentBestLocation));
|
||||
Intent i = new Intent();
|
||||
i.setAction(ACTION_TRACK_REQUEST);
|
||||
LocalBroadcastManager.getInstance(mActivity).sendBroadcast(i);
|
||||
}
|
||||
|
||||
// draw track on map - if available
|
||||
|
|
|
@ -17,8 +17,10 @@
|
|||
package org.y20k.trackbook;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.Sensor;
|
||||
|
@ -68,6 +70,7 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
private LocationListener mNetworkListener = null;
|
||||
private SettingsContentObserver mSettingsContentObserver;
|
||||
private Location mCurrentBestLocation;
|
||||
private BroadcastReceiver mTrackRequestReceiver;
|
||||
private boolean mTrackerServiceRunning;
|
||||
private boolean mLocationSystemSetting;
|
||||
|
||||
|
@ -75,6 +78,16 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
// listen for finished save operation
|
||||
mTrackRequestReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
sendTrackUpdate();
|
||||
}
|
||||
};
|
||||
IntentFilter trackRequestReceiverIntentFilter = new IntentFilter(ACTION_TRACK_REQUEST);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mTrackRequestReceiver, trackRequestReceiverIntentFilter);
|
||||
|
||||
// acquire reference to Location Manager
|
||||
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
|
||||
|
||||
|
@ -133,9 +146,10 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
public void onDestroy() {
|
||||
LogHelper.v(LOG_TAG, "onDestroy called.");
|
||||
|
||||
// remove listeners
|
||||
// remove receivers and listeners
|
||||
stopFindingLocation();
|
||||
mSensorManager.unregisterListener(this);
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mTrackRequestReceiver);
|
||||
|
||||
// cancel notification
|
||||
stopForeground(true);
|
||||
|
@ -288,16 +302,22 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
|
||||
// send local broadcast if new WayPoint added
|
||||
if (newWayPoint != null) {
|
||||
Intent i = new Intent();
|
||||
i.setAction(ACTION_TRACK_UPDATED);
|
||||
i.putExtra(EXTRA_TRACK, mTrack);
|
||||
i.putExtra(EXTRA_LAST_LOCATION, mCurrentBestLocation);
|
||||
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(i);
|
||||
sendTrackUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Broadcasts a track update */
|
||||
private void sendTrackUpdate() {
|
||||
Intent i = new Intent();
|
||||
i.setAction(ACTION_TRACK_UPDATED);
|
||||
i.putExtra(EXTRA_TRACK, mTrack);
|
||||
i.putExtra(EXTRA_LAST_LOCATION, mCurrentBestLocation);
|
||||
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(i);
|
||||
}
|
||||
|
||||
|
||||
/* Creates a location listener */
|
||||
private LocationListener createLocationListener() {
|
||||
return new LocationListener() {
|
||||
|
@ -411,6 +431,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
|||
LogHelper.v(LOG_TAG, "Saving finished.");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* End of inner class
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ public interface TrackbookKeys {
|
|||
String ACTION_DEFAULT = "DEFAULT";
|
||||
String ACTION_SHOW_MAP = "SHOW_MAP";
|
||||
String ACTION_TRACK_UPDATED = "TRACK_UPDATED";
|
||||
String ACTION_TRACK_REQUEST = "TRACK_REQUEST";
|
||||
String ACTION_TRACKING_STOPPED = "TRACKING_STOPPED";
|
||||
String ACTION_TRACK_SAVE = "TRACK_SAVE";
|
||||
|
||||
|
|
Loading…
Reference in a new issue