forked from upstream-mirrors/OpenTracks
Address comments.
This commit is contained in:
@@ -283,20 +283,7 @@ public class TrackRecordingService extends Service {
|
|||||||
// Check if called on phone reboot with resume intent.
|
// Check if called on phone reboot with resume intent.
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
if (intent.getBooleanExtra(RESUME_TRACK_EXTRA_NAME, false)) {
|
if (intent.getBooleanExtra(RESUME_TRACK_EXTRA_NAME, false)) {
|
||||||
Log.d(TAG, "TrackRecordingService: requested resume");
|
resumeTrack(startId);
|
||||||
|
|
||||||
// Make sure that the current track exists and is fresh enough.
|
|
||||||
if (recordingTrack == null || !shouldResumeTrack(recordingTrack)) {
|
|
||||||
Log.i(TAG,
|
|
||||||
"TrackRecordingService: Not resuming, because the previous track ("
|
|
||||||
+ recordingTrack + ") doesn't exist or is too old");
|
|
||||||
isRecording = false;
|
|
||||||
prefManager.setRecordingTrack(recordingTrackId = -1);
|
|
||||||
stopSelfResult(startId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.i(TAG, "TrackRecordingService: resuming");
|
|
||||||
} else {
|
} else {
|
||||||
// Process actions for controlling the service.
|
// Process actions for controlling the service.
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
@@ -312,6 +299,23 @@ public class TrackRecordingService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resumeTrack(int startId) {
|
||||||
|
Log.d(TAG, "TrackRecordingService: requested resume");
|
||||||
|
|
||||||
|
// Make sure that the current track exists and is fresh enough.
|
||||||
|
if (recordingTrack == null || !shouldResumeTrack(recordingTrack)) {
|
||||||
|
Log.i(TAG,
|
||||||
|
"TrackRecordingService: Not resuming, because the previous track ("
|
||||||
|
+ recordingTrack + ") doesn't exist or is too old");
|
||||||
|
isRecording = false;
|
||||||
|
prefManager.setRecordingTrack(recordingTrackId = -1);
|
||||||
|
stopSelfResult(startId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "TrackRecordingService: resuming");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
Log.d(TAG, "TrackRecordingService.onBind");
|
Log.d(TAG, "TrackRecordingService.onBind");
|
||||||
|
|||||||
@@ -87,17 +87,11 @@ public class TrackWidgetProvider
|
|||||||
@Override
|
@Override
|
||||||
public void onEnabled(Context context) {
|
public void onEnabled(Context context) {
|
||||||
initialize(context);
|
initialize(context);
|
||||||
|
|
||||||
// So long as an action is set the buttons will get set up properly.
|
|
||||||
updateTrack("some action");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
initialize(context);
|
initialize(context);
|
||||||
|
|
||||||
// So long as an action is set the buttons will get set up properly.
|
|
||||||
updateTrack("some action");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize(Context context) {
|
private void initialize(Context context) {
|
||||||
@@ -117,12 +111,6 @@ public class TrackWidgetProvider
|
|||||||
TRACK_STOPPED_ACTION = context.getString(R.string.track_stopped_broadcast_action);
|
TRACK_STOPPED_ACTION = context.getString(R.string.track_stopped_broadcast_action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisabled(Context context) {
|
|
||||||
context.getContentResolver().unregisterContentObserver(trackObserver);
|
|
||||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
@@ -142,6 +130,12 @@ public class TrackWidgetProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisabled(Context context) {
|
||||||
|
context.getContentResolver().unregisterContentObserver(trackObserver);
|
||||||
|
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateTrack(String action) {
|
private void updateTrack(String action) {
|
||||||
Track track = null;
|
Track track = null;
|
||||||
if (selectedTrackId != -1) {
|
if (selectedTrackId != -1) {
|
||||||
@@ -158,8 +152,8 @@ public class TrackWidgetProvider
|
|||||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
|
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
|
||||||
|
|
||||||
// Make all of the stats open the mytracks activity.
|
// Make all of the stats open the mytracks activity.
|
||||||
Intent i = new Intent(context, MyTracks.class);
|
Intent intent = new Intent(context, MyTracks.class);
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.appwidget_track_statistics, pendingIntent);
|
views.setOnClickPendingIntent(R.id.appwidget_track_statistics, pendingIntent);
|
||||||
|
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
@@ -195,6 +189,15 @@ public class TrackWidgetProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the main widget button.
|
||||||
|
*
|
||||||
|
* @param views The widget views
|
||||||
|
* @param context The widget context
|
||||||
|
* @param action The resource id of the action to fire when the button is pressed
|
||||||
|
* @param icon The resource id of the icon to show for the button
|
||||||
|
* @param extra Optional resource id of a boolean extra on the intent
|
||||||
|
*/
|
||||||
private void setButtonIntent(
|
private void setButtonIntent(
|
||||||
RemoteViews views, Context context, int action, int icon, int extra) {
|
RemoteViews views, Context context, int action, int icon, int extra) {
|
||||||
Intent intent = new Intent(context, TrackRecordingService.class);
|
Intent intent = new Intent(context, TrackRecordingService.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user