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.
|
||||
if (intent != null) {
|
||||
if (intent.getBooleanExtra(RESUME_TRACK_EXTRA_NAME, false)) {
|
||||
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");
|
||||
resumeTrack(startId);
|
||||
} else {
|
||||
// Process actions for controlling the service.
|
||||
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
|
||||
public IBinder onBind(Intent intent) {
|
||||
Log.d(TAG, "TrackRecordingService.onBind");
|
||||
|
||||
@@ -87,17 +87,11 @@ public class TrackWidgetProvider
|
||||
@Override
|
||||
public void onEnabled(Context context) {
|
||||
initialize(context);
|
||||
|
||||
// So long as an action is set the buttons will get set up properly.
|
||||
updateTrack("some action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
initialize(context);
|
||||
|
||||
// So long as an action is set the buttons will get set up properly.
|
||||
updateTrack("some action");
|
||||
}
|
||||
|
||||
private void initialize(Context context) {
|
||||
@@ -117,12 +111,6 @@ public class TrackWidgetProvider
|
||||
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
|
||||
public void onReceive(Context context, Intent 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) {
|
||||
Track track = null;
|
||||
if (selectedTrackId != -1) {
|
||||
@@ -158,8 +152,8 @@ public class TrackWidgetProvider
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
|
||||
|
||||
// Make all of the stats open the mytracks activity.
|
||||
Intent i = new Intent(context, MyTracks.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
|
||||
Intent intent = new Intent(context, MyTracks.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
views.setOnClickPendingIntent(R.id.appwidget_track_statistics, pendingIntent);
|
||||
|
||||
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(
|
||||
RemoteViews views, Context context, int action, int icon, int extra) {
|
||||
Intent intent = new Intent(context, TrackRecordingService.class);
|
||||
|
||||
Reference in New Issue
Block a user