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
|
// load state of tracker service - see if anything changed
|
||||||
loadTrackerServiceState(mActivity);
|
loadTrackerServiceState(mActivity);
|
||||||
|
|
||||||
// center map on current position - if TrackerService is running
|
// request an updated track recording from service - if TrackerService is running
|
||||||
if (mTrackerServiceRunning) {
|
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
|
// draw track on map - if available
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
package org.y20k.trackbook;
|
package org.y20k.trackbook;
|
||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
|
@ -68,6 +70,7 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
||||||
private LocationListener mNetworkListener = null;
|
private LocationListener mNetworkListener = null;
|
||||||
private SettingsContentObserver mSettingsContentObserver;
|
private SettingsContentObserver mSettingsContentObserver;
|
||||||
private Location mCurrentBestLocation;
|
private Location mCurrentBestLocation;
|
||||||
|
private BroadcastReceiver mTrackRequestReceiver;
|
||||||
private boolean mTrackerServiceRunning;
|
private boolean mTrackerServiceRunning;
|
||||||
private boolean mLocationSystemSetting;
|
private boolean mLocationSystemSetting;
|
||||||
|
|
||||||
|
@ -75,6 +78,16 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
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
|
// acquire reference to Location Manager
|
||||||
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
|
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
|
@ -133,9 +146,10 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
LogHelper.v(LOG_TAG, "onDestroy called.");
|
LogHelper.v(LOG_TAG, "onDestroy called.");
|
||||||
|
|
||||||
// remove listeners
|
// remove receivers and listeners
|
||||||
stopFindingLocation();
|
stopFindingLocation();
|
||||||
mSensorManager.unregisterListener(this);
|
mSensorManager.unregisterListener(this);
|
||||||
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mTrackRequestReceiver);
|
||||||
|
|
||||||
// cancel notification
|
// cancel notification
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
|
@ -288,16 +302,22 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
||||||
|
|
||||||
// send local broadcast if new WayPoint added
|
// send local broadcast if new WayPoint added
|
||||||
if (newWayPoint != null) {
|
if (newWayPoint != null) {
|
||||||
Intent i = new Intent();
|
sendTrackUpdate();
|
||||||
i.setAction(ACTION_TRACK_UPDATED);
|
|
||||||
i.putExtra(EXTRA_TRACK, mTrack);
|
|
||||||
i.putExtra(EXTRA_LAST_LOCATION, mCurrentBestLocation);
|
|
||||||
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 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 */
|
/* Creates a location listener */
|
||||||
private LocationListener createLocationListener() {
|
private LocationListener createLocationListener() {
|
||||||
return new LocationListener() {
|
return new LocationListener() {
|
||||||
|
@ -411,6 +431,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
||||||
LogHelper.v(LOG_TAG, "Saving finished.");
|
LogHelper.v(LOG_TAG, "Saving finished.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* End of inner class
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public interface TrackbookKeys {
|
||||||
String ACTION_DEFAULT = "DEFAULT";
|
String ACTION_DEFAULT = "DEFAULT";
|
||||||
String ACTION_SHOW_MAP = "SHOW_MAP";
|
String ACTION_SHOW_MAP = "SHOW_MAP";
|
||||||
String ACTION_TRACK_UPDATED = "TRACK_UPDATED";
|
String ACTION_TRACK_UPDATED = "TRACK_UPDATED";
|
||||||
|
String ACTION_TRACK_REQUEST = "TRACK_REQUEST";
|
||||||
String ACTION_TRACKING_STOPPED = "TRACKING_STOPPED";
|
String ACTION_TRACKING_STOPPED = "TRACKING_STOPPED";
|
||||||
String ACTION_TRACK_SAVE = "TRACK_SAVE";
|
String ACTION_TRACK_SAVE = "TRACK_SAVE";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue