From b985a935b0a52d462031e20acbdff2719b0e9c87 Mon Sep 17 00:00:00 2001 From: Sandor Dornbush Date: Thu, 7 Jul 2011 22:25:41 -0700 Subject: [PATCH] Address comments. --- .../services/TrackRecordingService.java | 32 +++++++++++-------- .../mytracks/widgets/TrackWidgetProvider.java | 31 ++++++++++-------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java index d12aacad5..4984ce340 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -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"); diff --git a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java index 5477ee128..587cf2203 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java +++ b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java @@ -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);