forked from upstream-mirrors/OpenTracks
GPS Status: TrackListActivity uses the value of gps status from the service to select appropiate icon.
This commit is contained in:
@@ -83,6 +83,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
private TrackController trackController;
|
private TrackController trackController;
|
||||||
private ListView listView;
|
private ListView listView;
|
||||||
private ResourceCursorAdapter resourceCursorAdapter;
|
private ResourceCursorAdapter resourceCursorAdapter;
|
||||||
|
private GpsStatusValue gpsStatusValue;
|
||||||
|
|
||||||
private final LoaderCallbacks<Cursor> loaderCallbacks = new LoaderCallbacks<Cursor>() {
|
private final LoaderCallbacks<Cursor> loaderCallbacks = new LoaderCallbacks<Cursor>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -175,25 +176,28 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
// After binding changes (e.g., becomes available), update the total time in trackController.
|
// After binding changes (e.g., becomes available), update the total time in trackController.
|
||||||
runOnUiThread(() -> trackController.update(isRecording, recordingTrackPaused));
|
runOnUiThread(() -> trackController.update(isRecording, recordingTrackPaused));
|
||||||
|
|
||||||
if (!startGps) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TrackRecordingServiceInterface service = trackRecordingServiceConnection.getServiceIfBound();
|
TrackRecordingServiceInterface service = trackRecordingServiceConnection.getServiceIfBound();
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
Log.d(TAG, "service not available to start gps or a new recording");
|
Log.d(TAG, "service not available to start gps or a new recording");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (startGps) {
|
|
||||||
service.startGps();
|
// Get GPS status and listen GPS status changes.
|
||||||
startGps = false;
|
gpsStatusValue = service.getGpsStatus();
|
||||||
}
|
updateGpsMenuItem(true, isRecording);
|
||||||
service.setListener(new BoundServiceListener() {
|
service.setListener(newStatus -> {
|
||||||
@Override
|
gpsStatusValue = newStatus;
|
||||||
public void onGpsStatusChange(GpsStatusValue newStatus) {
|
updateGpsMenuItem(true, isRecording);
|
||||||
updateGpsMenuItem(true, isRecording, newStatus.icon);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!startGps) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
service.startGps();
|
||||||
|
startGps = false;
|
||||||
|
gpsStatusValue = GpsStatusValue.GPS_ENABLED;
|
||||||
|
updateGpsMenuItem(true, isRecording);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -222,6 +226,8 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
gpsStatusValue = GpsStatusValue.GPS_NONE;
|
||||||
|
|
||||||
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||||
|
|
||||||
contentProviderUtils = new ContentProviderUtils(this);
|
contentProviderUtils = new ContentProviderUtils(this);
|
||||||
@@ -448,22 +454,21 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
* @param isRecording true if recording
|
* @param isRecording true if recording
|
||||||
*/
|
*/
|
||||||
private void updateMenuItems(boolean isGpsStarted, boolean isRecording) {
|
private void updateMenuItems(boolean isGpsStarted, boolean isRecording) {
|
||||||
updateGpsMenuItem(isGpsStarted, isRecording, R.drawable.ic_gps_not_fixed_24dp);
|
updateGpsMenuItem(isGpsStarted, isRecording);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the menu items with the icon specified.
|
* Updates the menu items with the icon specified.
|
||||||
*
|
*
|
||||||
* @param isGpsStarted true if gps is started
|
* @param isGpsStarted true if gps is started
|
||||||
* @param isRecording true if recording
|
* @param isRecording true if recording
|
||||||
* @param icon the icon drawable value
|
|
||||||
*/
|
*/
|
||||||
private void updateGpsMenuItem(boolean isGpsStarted, boolean isRecording, int icon) {
|
private void updateGpsMenuItem(boolean isGpsStarted, boolean isRecording) {
|
||||||
if (startGpsMenuItem != null) {
|
if (startGpsMenuItem != null) {
|
||||||
startGpsMenuItem.setVisible(!isRecording);
|
startGpsMenuItem.setVisible(!isRecording);
|
||||||
if (!isRecording) {
|
if (!isRecording) {
|
||||||
startGpsMenuItem.setTitle(isGpsStarted ? R.string.menu_stop_gps : R.string.menu_start_gps);
|
startGpsMenuItem.setTitle(isGpsStarted ? R.string.menu_stop_gps : R.string.menu_start_gps);
|
||||||
startGpsMenuItem.setIcon(isGpsStarted ? icon : R.drawable.ic_gps_off_24dp);
|
startGpsMenuItem.setIcon(isGpsStarted ? gpsStatusValue.icon : R.drawable.ic_gps_off_24dp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -698,4 +698,8 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
|||||||
public void setRemoteSensorManager(BluetoothRemoteSensorManager remoteSensorManager) {
|
public void setRemoteSensorManager(BluetoothRemoteSensorManager remoteSensorManager) {
|
||||||
this.remoteSensorManager = remoteSensorManager;
|
this.remoteSensorManager = remoteSensorManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GpsStatusValue getGpsStatus() {
|
||||||
|
return handlerServer.getGpsStatus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
|
import de.dennisguse.opentracks.services.handlers.GpsStatusValue;
|
||||||
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
|
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,6 +28,11 @@ class TrackRecordingServiceBinder extends android.os.Binder implements TrackReco
|
|||||||
trackRecordingService.addListener(listener);
|
trackRecordingService.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GpsStatusValue getGpsStatus() {
|
||||||
|
return trackRecordingService.getGpsStatus();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startGps() {
|
public void startGps() {
|
||||||
trackRecordingService.tryStartGps();
|
trackRecordingService.tryStartGps();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
|
import de.dennisguse.opentracks.services.handlers.GpsStatusValue;
|
||||||
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
|
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,4 +113,6 @@ public interface TrackRecordingServiceInterface {
|
|||||||
void newTrackPoint(TrackPoint trackPoint, int recordingGpsAccuracy);
|
void newTrackPoint(TrackPoint trackPoint, int recordingGpsAccuracy);
|
||||||
|
|
||||||
void setListener(BoundServiceListener listener);
|
void setListener(BoundServiceListener listener);
|
||||||
|
|
||||||
|
GpsStatusValue getGpsStatus();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ public class HandlerServer {
|
|||||||
service.newGpsStatus(gpsStatusValue);
|
service.newGpsStatus(gpsStatusValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GpsStatusValue getGpsStatus() {
|
||||||
|
return locationHandler.getGpsStatus();
|
||||||
|
}
|
||||||
|
|
||||||
public interface HandlerServerInterface {
|
public interface HandlerServerInterface {
|
||||||
void newTrackPoint(TrackPoint trackPoint, int gpsAccuracy);
|
void newTrackPoint(TrackPoint trackPoint, int gpsAccuracy);
|
||||||
void newGpsStatus(GpsStatusValue gpsStatusValue);
|
void newGpsStatus(GpsStatusValue gpsStatusValue);
|
||||||
|
|||||||
@@ -90,6 +90,10 @@ class LocationHandler implements HandlerServer.Handler, LocationListener, GpsSta
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(@NonNull Location location) {
|
public void onLocationChanged(@NonNull Location location) {
|
||||||
|
if (gpsStatus != null) {
|
||||||
|
gpsStatus.onLocationChanged(location);
|
||||||
|
}
|
||||||
|
|
||||||
if (!LocationUtils.isValidLocation(location)) {
|
if (!LocationUtils.isValidLocation(location)) {
|
||||||
Log.w(TAG, "Ignore newTrackPoint. location is invalid.");
|
Log.w(TAG, "Ignore newTrackPoint. location is invalid.");
|
||||||
return;
|
return;
|
||||||
@@ -122,10 +126,16 @@ class LocationHandler implements HandlerServer.Handler, LocationListener, GpsSta
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(@NonNull String provider) {
|
public void onProviderEnabled(@NonNull String provider) {
|
||||||
|
if (gpsStatus != null) {
|
||||||
|
gpsStatus.onGpsEnabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(@NonNull String provider) {
|
public void onProviderDisabled(@NonNull String provider) {
|
||||||
|
if (gpsStatus != null) {
|
||||||
|
gpsStatus.onGpsDisabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerLocationListener() {
|
private void registerLocationListener() {
|
||||||
@@ -161,4 +171,8 @@ class LocationHandler implements HandlerServer.Handler, LocationListener, GpsSta
|
|||||||
public void onGpsStatusChanged(GpsStatusValue prevStatus, GpsStatusValue currentStatus) {
|
public void onGpsStatusChanged(GpsStatusValue prevStatus, GpsStatusValue currentStatus) {
|
||||||
handlerServer.sendGpsStatus(currentStatus);
|
handlerServer.sendGpsStatus(currentStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GpsStatusValue getGpsStatus() {
|
||||||
|
return gpsStatus != null ? gpsStatus.getGpsStatus() : GpsStatusValue.GPS_NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user