diff --git a/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java index f36cf6549..8f329b967 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/AggregatedStatsActivity.java @@ -4,6 +4,7 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.util.ApiAdapterFactory; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import android.app.Activity; @@ -93,8 +94,8 @@ public class AggregatedStatsActivity extends Activity implements if (item.getItemId() != android.R.id.home) { return false; } - startActivity(new Intent(this, TrackListActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); + Intent intent = IntentUtils.newIntent(this, TrackListActivity.class); + startActivity(intent); return true; } diff --git a/MyTracks/src/com/google/android/apps/mytracks/BootReceiver.java b/MyTracks/src/com/google/android/apps/mytracks/BootReceiver.java index 47fd14d78..248735b7f 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/BootReceiver.java +++ b/MyTracks/src/com/google/android/apps/mytracks/BootReceiver.java @@ -48,8 +48,8 @@ public class BootReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Log.d(TAG, "BootReceiver.onReceive: " + intent.getAction()); if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) { - Intent startIntent = new Intent(context, TrackRecordingService.class); - startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true); + Intent startIntent = new Intent(context, TrackRecordingService.class) + .putExtra(RESUME_TRACK_EXTRA_NAME, true); context.startService(startIntent); Intent removeTempFilesIntent = new Intent(context, RemoveTempFilesService.class); diff --git a/MyTracks/src/com/google/android/apps/mytracks/ChartView.java b/MyTracks/src/com/google/android/apps/mytracks/ChartView.java index eb636bdc3..1fe435965 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/ChartView.java +++ b/MyTracks/src/com/google/android/apps/mytracks/ChartView.java @@ -18,6 +18,7 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.ChartValueSeries.ZoomSettings; import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.stats.ExtremityMonitor; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.maps.mytracks.R; @@ -485,8 +486,7 @@ public class ChartView extends View { } } if (nearestWaypoint != null && dmin < 100) { - Intent intent = new Intent(getContext(), MarkerDetailActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) + Intent intent = IntentUtils.newIntent(getContext(), MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, nearestWaypoint.getId()); getContext().startActivity(intent); return true; diff --git a/MyTracks/src/com/google/android/apps/mytracks/HelpActivity.java b/MyTracks/src/com/google/android/apps/mytracks/HelpActivity.java index 4e692c270..979af433a 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/HelpActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/HelpActivity.java @@ -18,6 +18,7 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.fragments.AboutDialogFragment; import com.google.android.apps.mytracks.util.ApiAdapterFactory; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import android.content.Intent; @@ -60,8 +61,8 @@ public class HelpActivity extends FragmentActivity { if (item.getItemId() != android.R.id.home) { return false; } - startActivity(new Intent(this, TrackListActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); + Intent intent = IntentUtils.newIntent(this, TrackListActivity.class); + startActivity(intent); return true; } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/ImportActivity.java b/MyTracks/src/com/google/android/apps/mytracks/ImportActivity.java index 56557bcfb..48a886fd9 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/ImportActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/ImportActivity.java @@ -18,6 +18,7 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.util.DialogUtils; import com.google.android.apps.mytracks.util.FileUtils; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.UriUtils; import com.google.android.maps.mytracks.R; @@ -140,8 +141,8 @@ public class ImportActivity extends Activity { @Override public void onClick(DialogInterface dialog, int which) { if (!importAll && trackId != -1L) { - Intent intent = new Intent(ImportActivity.this, TrackDetailActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) + Intent intent = IntentUtils.newIntent( + ImportActivity.this, TrackDetailActivity.class) .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId); startActivity(intent); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java index 5564cc696..6c21e298b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java @@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.maps.TrackPathPainter; import com.google.android.apps.mytracks.maps.TrackPathPainterFactory; import com.google.android.apps.mytracks.maps.TrackPathUtilities; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.maps.GeoPoint; @@ -442,10 +443,8 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe } } - if (waypoint != null && - dmin < 15000000 / Math.pow(2, mapView.getZoomLevel())) { - Intent intent = new Intent(context, MarkerDetailActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) + if (waypoint != null && dmin < 15000000 / Math.pow(2, mapView.getZoomLevel())) { + Intent intent = IntentUtils.newIntent(context, MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, waypoint.getId()); context.startActivity(intent); return true; diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java index ac3497c53..1459bc8db 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java @@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.util.ApiAdapterFactory; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.maps.mytracks.R; @@ -142,24 +143,26 @@ public class MarkerDetailActivity extends FragmentActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { + Intent intent; switch (item.getItemId()) { case android.R.id.home: - startActivity(new Intent(this, MarkerListActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(MarkerListActivity.EXTRA_TRACK_ID, waypoint.getTrackId())); + intent = IntentUtils.newIntent(this, MarkerListActivity.class) + .putExtra(MarkerListActivity.EXTRA_TRACK_ID, waypoint.getTrackId()); + startActivity(intent); return true; case R.id.marker_detail_show_on_map: - startActivity(new Intent(this, TrackDetailActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId)); - return true; + intent = IntentUtils.newIntent(this, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId); + startActivity(intent); + return true; case R.id.marker_detail_edit: - startActivity(new Intent(this, MarkerEditActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId)); + intent = IntentUtils.newIntent(this, MarkerEditActivity.class) + .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId); + startActivity(intent); return true; case R.id.marker_detail_delete: - DeleteOneMarkerDialogFragment.newInstance(markerId).show(getSupportFragmentManager(), + DeleteOneMarkerDialogFragment.newInstance(markerId, waypoint.getTrackId()).show( + getSupportFragmentManager(), DeleteOneMarkerDialogFragment.DELETE_ONE_MARKER_DIALOG_TAG); return true; default: diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerListActivity.java index a173d0e9e..c56605259 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MarkerListActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerListActivity.java @@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.WaypointsColumns; import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment; import com.google.android.apps.mytracks.util.ApiAdapterFactory; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.ListItemUtil; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.StringUtils; @@ -124,9 +125,9 @@ public class MarkerListActivity extends FragmentActivity { listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - startActivity(new Intent(MarkerListActivity.this, MarkerDetailActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id)); + Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerDetailActivity.class) + .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id); + startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @@ -201,8 +202,8 @@ public class MarkerListActivity extends FragmentActivity { finish(); return true; case R.id.marker_list_insert_marker: - startActivity(new Intent(this, MarkerEditActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); + Intent intent = IntentUtils.newIntent(this, MarkerEditActivity.class); + startActivity(intent); return true; case R.id.marker_list_search: return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this); @@ -234,19 +235,21 @@ public class MarkerListActivity extends FragmentActivity { * @return true if handled. */ private boolean handleContextItem(int itemId, long markerId) { + Intent intent; switch (itemId) { case R.id.list_context_menu_show_on_map: - startActivity(new Intent(this, TrackDetailActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId)); + intent = IntentUtils.newIntent(this, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId); + startActivity(intent); return true; case R.id.list_context_menu_edit: - startActivity(new Intent(this, MarkerEditActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId)); + intent = IntentUtils.newIntent(this, MarkerEditActivity.class) + .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId); + startActivity(intent); return true; case R.id.list_context_menu_delete: - DeleteOneMarkerDialogFragment.newInstance(markerId).show(getSupportFragmentManager(), + DeleteOneMarkerDialogFragment.newInstance(markerId, trackId).show( + getSupportFragmentManager(), DeleteOneMarkerDialogFragment.DELETE_ONE_MARKER_DIALOG_TAG); return true; default: diff --git a/MyTracks/src/com/google/android/apps/mytracks/MyTracksApplication.java b/MyTracks/src/com/google/android/apps/mytracks/MyTracksApplication.java index d2a50f03c..f5bab7acb 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MyTracksApplication.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MyTracksApplication.java @@ -39,7 +39,8 @@ public class MyTracksApplication extends Application { ApiAdapterFactory.getApiAdapter().enableStrictMode(); } AnalyticsUtils.sendPageViews(this, "/appstart"); - startService(new Intent(this, RemoveTempFilesService.class)); + Intent intent = new Intent(this, RemoveTempFilesService.class); + startService(intent); } /** diff --git a/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java index bdcc95137..362a0b59b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java @@ -27,6 +27,7 @@ import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment; import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.util.ApiAdapterFactory; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.ListItemUtil; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.StringUtils; @@ -138,16 +139,14 @@ public class SearchListActivity extends FragmentActivity { public void onItemClick(AdapterView parent, View view, int position, long id) { Map item = arrayAdapter.getItem(position); Long trackId = (Long) item.get(TRACK_ID_FIELD); + Long markerId = (Long) item.get(MARKER_ID_FIELD); Intent intent; - if (trackId != null) { - intent = new Intent(SearchListActivity.this, TrackDetailActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId); - + if (markerId != null) { + intent = IntentUtils.newIntent(SearchListActivity.this, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId); } else { - intent = new Intent(SearchListActivity.this, MarkerDetailActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, (Long) item.get(MARKER_ID_FIELD)); + intent = IntentUtils.newIntent(SearchListActivity.this, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId); } startActivity(intent); } @@ -256,40 +255,37 @@ public class SearchListActivity extends FragmentActivity { private boolean handleContextItem(int itemId, int position) { Map item = arrayAdapter.getItem(position); Long trackId = (Long) item.get(TRACK_ID_FIELD); + Long markerId = (Long) item.get(MARKER_ID_FIELD); Intent intent; switch (itemId) { case R.id.list_context_menu_show_on_map: - if (trackId != null) { - intent = new Intent(this, TrackDetailActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, (Long) item.get(TRACK_ID_FIELD)); + if (markerId != null) { + intent = IntentUtils.newIntent(this, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId); } else { - intent = new Intent(this, TrackDetailActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, (Long) item.get(MARKER_ID_FIELD)); + intent = IntentUtils.newIntent(this, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId); } startActivity(intent); return true; case R.id.list_context_menu_edit: - if (trackId != null) { - intent = new Intent(this, TrackEditActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId); + if (markerId != null) { + intent = IntentUtils.newIntent(this, MarkerEditActivity.class) + .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId); } else { - intent = new Intent(this, MarkerEditActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, (Long) item.get(MARKER_ID_FIELD)); + intent = IntentUtils.newIntent(this, TrackEditActivity.class) + .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId); } startActivity(intent); return true; case R.id.list_context_menu_delete: - if (trackId != null) { - DeleteOneTrackDialogFragment.newInstance(trackId).show(getSupportFragmentManager(), - DeleteOneTrackDialogFragment.DELETE_ONE_TRACK_DIALOG_TAG); - } else { - DeleteOneMarkerDialogFragment.newInstance((Long) item.get(MARKER_ID_FIELD)).show( + if (markerId != null) { + DeleteOneMarkerDialogFragment.newInstance(markerId, trackId).show( getSupportFragmentManager(), DeleteOneMarkerDialogFragment.DELETE_ONE_MARKER_DIALOG_TAG); + } else { + DeleteOneTrackDialogFragment.newInstance(trackId).show(getSupportFragmentManager(), + DeleteOneTrackDialogFragment.DELETE_ONE_TRACK_DIALOG_TAG); } return true; default: @@ -401,7 +397,7 @@ public class SearchListActivity extends FragmentActivity { : getString(R.string.search_list_marker_track_location, trackName)); resultMap.put(TOTAL_DISTANCE_FIELD, null); resultMap.put(DESCRIPTION_FIELD, statistics ? null : waypoint.getDescription()); - resultMap.put(TRACK_ID_FIELD, null); + resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId()); resultMap.put(MARKER_ID_FIELD, waypoint.getId()); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/SettingsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/SettingsActivity.java index e45475ede..185a1faae 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/SettingsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/SettingsActivity.java @@ -24,6 +24,7 @@ import com.google.android.apps.mytracks.services.sensors.ant.AntUtils; import com.google.android.apps.mytracks.util.ApiAdapterFactory; import com.google.android.apps.mytracks.util.BluetoothDeviceUtils; import com.google.android.apps.mytracks.util.DialogUtils; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.maps.mytracks.R; @@ -201,7 +202,9 @@ public class SettingsActivity extends PreferenceActivity { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - startActivity(new Intent(SettingsActivity.this, RestoreChooserActivity.class)); + Intent intent = IntentUtils.newIntent( + SettingsActivity.this, RestoreChooserActivity.class); + startActivity(intent); } }); default: @@ -361,22 +364,21 @@ public class SettingsActivity extends PreferenceActivity { : R.string.settings_reset_summary); // Add actions to the backup preferences - backupNowPreference.setOnPreferenceClickListener( - new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivity(new Intent(SettingsActivity.this, BackupActivity.class)); - return true; - } - }); - restoreNowPreference.setOnPreferenceClickListener( - new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - showDialog(DIALOG_CONFIRM_RESTORE_ID); - return true; - } - }); + backupNowPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent intent = IntentUtils.newIntent(SettingsActivity.this, BackupActivity.class); + startActivity(intent); + return true; + } + }); + restoreNowPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + showDialog(DIALOG_CONFIRM_RESTORE_ID); + return true; + } + }); } @Override @@ -627,8 +629,8 @@ public class SettingsActivity extends PreferenceActivity { Toast.LENGTH_SHORT).show(); // Restart the settings activity so all changes are loaded. - Intent intent = getIntent(); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + Intent intent = getIntent() + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java index bd069d5a8..c44e12fe2 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java @@ -38,6 +38,7 @@ import com.google.android.apps.mytracks.services.ITrackRecordingService; import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection; import com.google.android.apps.mytracks.util.AnalyticsUtils; import com.google.android.apps.mytracks.util.ApiAdapterFactory; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils; import com.google.android.maps.mytracks.R; @@ -101,15 +102,15 @@ public class TrackDetailActivity extends FragmentActivity { * class. Anonymous inner class will get garbage collected. */ private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener = - new OnSharedPreferenceChangeListener() { - @Override - public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { - // Note that key can be null - if (PreferencesUtils.getRecordingTrackIdKey(TrackDetailActivity.this).equals(key)) { - updateMenu(); - } - } - }; + new OnSharedPreferenceChangeListener() { + @Override + public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { + // Note that key can be null + if (PreferencesUtils.getRecordingTrackIdKey(TrackDetailActivity.this).equals(key)) { + updateMenu(); + } + } + }; /** * We are not displaying driving directions. Just an arbitrary track that is @@ -260,20 +261,21 @@ public class TrackDetailActivity extends FragmentActivity { Intent intent; switch (item.getItemId()) { case android.R.id.home: - startTrackListActivity(); + intent = IntentUtils.newIntent(this, TrackListActivity.class); + startActivity(intent); return true; case R.id.track_detail_stop_recording: updateMenuItems(false); TrackRecordingServiceConnectionUtils.stop(this, trackRecordingServiceConnection); return true; case R.id.track_detail_insert_marker: - startActivity(new Intent(this, MarkerEditActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); + intent = IntentUtils.newIntent(this, MarkerEditActivity.class); + startActivity(intent); return true; case R.id.track_detail_play: if (isEarthInstalled()) { AnalyticsUtils.sendPageViews(this, "/action/play"); - intent = new Intent(this, SaveActivity.class) + intent = IntentUtils.newIntent(this, SaveActivity.class) .putExtra(SaveActivity.EXTRA_TRACK_ID, trackId) .putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML) .putExtra(SaveActivity.EXTRA_PLAY_TRACK, true); @@ -284,12 +286,12 @@ public class TrackDetailActivity extends FragmentActivity { } return true; case R.id.track_detail_share_map: - intent = new Intent(this, UploadServiceChooserActivity.class) + intent = IntentUtils.newIntent(this, UploadServiceChooserActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, true, false, false)); startActivity(intent); return true; case R.id.track_detail_share_fusion_table: - intent = new Intent(this, UploadServiceChooserActivity.class) + intent = IntentUtils.newIntent(this, UploadServiceChooserActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, false, true, false)); startActivity(intent); return true; @@ -306,13 +308,12 @@ public class TrackDetailActivity extends FragmentActivity { startSaveActivity(TrackFileFormat.TCX, true); return true; case R.id.track_detail_markers: - intent = new Intent(this, MarkerListActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) + intent = IntentUtils.newIntent(this, MarkerListActivity.class) .putExtra(MarkerListActivity.EXTRA_TRACK_ID, trackId); startActivity(intent); return true; case R.id.track_detail_send_google: - intent = new Intent(this, UploadServiceChooserActivity.class) + intent = IntentUtils.newIntent(this, UploadServiceChooserActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, true, true, true)); startActivity(intent); return true; @@ -329,8 +330,9 @@ public class TrackDetailActivity extends FragmentActivity { startSaveActivity(TrackFileFormat.TCX, false); return true; case R.id.track_detail_edit: - startActivity(new Intent(this, TrackEditActivity.class) - .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId)); + intent = IntentUtils.newIntent(this, TrackEditActivity.class) + .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId); + startActivity(intent); return true; case R.id.track_detail_delete: DeleteOneTrackDialogFragment.newInstance(trackId).show( @@ -353,13 +355,16 @@ public class TrackDetailActivity extends FragmentActivity { getSupportFragmentManager(), ChartSettingsDialogFragment.CHART_SETTINGS_DIALOG_TAG); return true; case R.id.track_detail_sensor_state: - startActivity(new Intent(this, SensorStateActivity.class)); + intent = IntentUtils.newIntent(this, SensorStateActivity.class); + startActivity(intent); return true; case R.id.track_detail_settings: - startActivity(new Intent(this, SettingsActivity.class)); + intent = IntentUtils.newIntent(this, SettingsActivity.class); + startActivity(intent); return true; case R.id.track_detail_help: - startActivity(new Intent(this, HelpActivity.class)); + intent = IntentUtils.newIntent(this, HelpActivity.class); + startActivity(intent); return true; default: return false; @@ -411,14 +416,16 @@ public class TrackDetailActivity extends FragmentActivity { if (markerId != -1L) { Waypoint waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(markerId); if (waypoint == null) { - startTrackListActivity(); + Intent newIntent = IntentUtils.newIntent(this, TrackListActivity.class); + startActivity(newIntent); finish(); return; } trackId = waypoint.getTrackId(); } if (trackId == -1L) { - startTrackListActivity(); + Intent newIntent = IntentUtils.newIntent(this, TrackListActivity.class); + startActivity(newIntent); finish(); return; } @@ -475,14 +482,6 @@ public class TrackDetailActivity extends FragmentActivity { } } - /** - * Starts the {@link TrackListActivity}. - */ - private void startTrackListActivity() { - startActivity(new Intent(this, TrackListActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); - } - /** * Starts the {@link SaveActivity} to save a track. * @@ -490,7 +489,7 @@ public class TrackDetailActivity extends FragmentActivity { * @param shareTrack true to share the track after saving */ private void startSaveActivity(TrackFileFormat trackFileFormat, boolean shareTrack) { - Intent intent = new Intent(this, SaveActivity.class) + Intent intent = IntentUtils.newIntent(this, SaveActivity.class) .putExtra(SaveActivity.EXTRA_TRACK_ID, trackId) .putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat) .putExtra(SaveActivity.EXTRA_SHARE_TRACK, shareTrack); diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java index 735fe705d..23858d7c2 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java @@ -42,7 +42,7 @@ import android.widget.EditText; public class TrackEditActivity extends Activity implements OnClickListener { public static final String EXTRA_TRACK_ID = "track_id"; - public static final String EXTRA_SHOW_CANCEL = "show_cancel"; + public static final String EXTRA_NEW_TRACK = "new_track"; private static final String TAG = TrackEditActivity.class.getSimpleName(); @@ -92,13 +92,13 @@ public class TrackEditActivity extends Activity implements OnClickListener { save.setOnClickListener(this); Button cancel = (Button) findViewById(R.id.track_edit_cancel); - if (getIntent().getBooleanExtra(EXTRA_SHOW_CANCEL, true)) { + if (getIntent().getBooleanExtra(EXTRA_NEW_TRACK, false)) { + setTitle(R.string.track_edit_new_track_title); + cancel.setVisibility(View.GONE); + } else { setTitle(R.string.menu_edit); cancel.setOnClickListener(this); cancel.setVisibility(View.VISIBLE); - } else { - setTitle(R.string.track_edit_new_track_title); - cancel.setVisibility(View.GONE); } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java index f0752ad79..8c4e46e36 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java @@ -25,6 +25,7 @@ import com.google.android.apps.mytracks.services.ITrackRecordingService; import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection; import com.google.android.apps.mytracks.util.ApiAdapterFactory; import com.google.android.apps.mytracks.util.EulaUtils; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.ListItemUtil; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.StringUtils; @@ -93,7 +94,9 @@ public class TrackListActivity extends FragmentActivity { try { recordingTrackId = service.startNewTrack(); startNewRecording = false; - startTrackDetailActivity(recordingTrackId); + Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId); + startActivity(intent); Toast.makeText( TrackListActivity.this, R.string.track_list_record_success, Toast.LENGTH_SHORT).show(); Log.d(TAG, "Started a new recording"); @@ -184,7 +187,9 @@ public class TrackListActivity extends FragmentActivity { listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - startTrackDetailActivity(id); + Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id); + startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @@ -329,6 +334,7 @@ public class TrackListActivity extends FragmentActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { + Intent intent; switch (item.getItemId()) { case R.id.track_list_record_track: updateMenuItems(true); @@ -341,37 +347,45 @@ public class TrackListActivity extends FragmentActivity { case R.id.track_list_search: return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this); case R.id.track_list_import_all: - startActivity( - new Intent(this, ImportActivity.class).putExtra(ImportActivity.EXTRA_IMPORT_ALL, true)); + intent = IntentUtils.newIntent(this, ImportActivity.class) + .putExtra(ImportActivity.EXTRA_IMPORT_ALL, true); + startActivity(intent); return true; case R.id.track_list_export_gpx: - startActivity(new Intent(this, ExportActivity.class).putExtra( - ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.GPX)); + intent = IntentUtils.newIntent(this, ExportActivity.class) + .putExtra(ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.GPX); + startActivity(intent); return true; case R.id.track_list_export_kml: - startActivity(new Intent(this, ExportActivity.class).putExtra( - ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML)); + intent = IntentUtils.newIntent(this, ExportActivity.class) + .putExtra(ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML); + startActivity(intent); return true; case R.id.track_list_export_csv: - startActivity(new Intent(this, ExportActivity.class).putExtra( - ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.CSV)); + intent = IntentUtils.newIntent(this, ExportActivity.class) + .putExtra(ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.CSV); + startActivity(intent); return true; case R.id.track_list_export_tcx: - startActivity(new Intent(this, ExportActivity.class).putExtra( - ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.TCX)); + intent = IntentUtils.newIntent(this, ExportActivity.class) + .putExtra(ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.TCX); + startActivity(intent); return true; case R.id.track_list_delete_all: new DeleteAllTrackDialogFragment().show( getSupportFragmentManager(), DeleteAllTrackDialogFragment.DELETE_ALL_TRACK_DIALOG_TAG); return true; case R.id.track_list_aggregated_statistics: - startActivity(new Intent(this, AggregatedStatsActivity.class)); + intent = IntentUtils.newIntent(this, AggregatedStatsActivity.class); + startActivity(intent); return true; case R.id.track_list_settings: - startActivity(new Intent(this, SettingsActivity.class)); + intent = IntentUtils.newIntent(this, SettingsActivity.class); + startActivity(intent); return true; case R.id.track_list_help: - startActivity(new Intent(this, HelpActivity.class)); + intent = IntentUtils.newIntent(this, HelpActivity.class); + startActivity(intent); return true; default: return super.onOptionsItemSelected(item); @@ -403,14 +417,12 @@ public class TrackListActivity extends FragmentActivity { Intent intent; switch (itemId) { case R.id.list_context_menu_show_on_map: - intent = new Intent(this, TrackDetailActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) + intent = IntentUtils.newIntent(this, TrackDetailActivity.class) .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId); startActivity(intent); return true; case R.id.list_context_menu_edit: - intent = new Intent(this, TrackEditActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) + intent = IntentUtils.newIntent(this, TrackEditActivity.class) .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId); startActivity(intent); return true; @@ -423,18 +435,6 @@ public class TrackListActivity extends FragmentActivity { } } - /** - * Starts {@link TrackDetailActivity}. - * - * @param trackId the track id. - */ - private void startTrackDetailActivity(long trackId) { - Intent intent = new Intent(TrackListActivity.this, TrackDetailActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId); - startActivity(intent); - } - /** * Starts a new recording. */ diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteOneMarkerDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteOneMarkerDialogFragment.java index 723852203..d1f503b62 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteOneMarkerDialogFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteOneMarkerDialogFragment.java @@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.MarkerListActivity; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.util.DialogUtils; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import android.app.Dialog; @@ -37,10 +38,12 @@ public class DeleteOneMarkerDialogFragment extends DialogFragment { public static final String DELETE_ONE_MARKER_DIALOG_TAG = "deleteOneMarkerDialog"; private static final String KEY_MARKER_ID = "markerId"; + private static final String KEY_TRACK_ID = "trackId"; - public static DeleteOneMarkerDialogFragment newInstance(long markerId) { + public static DeleteOneMarkerDialogFragment newInstance(long markerId, long trackId) { Bundle bundle = new Bundle(); bundle.putLong(KEY_MARKER_ID, markerId); + bundle.putLong(KEY_TRACK_ID, trackId); DeleteOneMarkerDialogFragment deleteOneMarkerDialogFragment = new DeleteOneMarkerDialogFragment(); deleteOneMarkerDialogFragment.setArguments(bundle); @@ -55,8 +58,9 @@ public class DeleteOneMarkerDialogFragment extends DialogFragment { public void onClick(DialogInterface dialog, int which) { MyTracksProviderUtils.Factory.get(getActivity()).deleteWaypoint( getArguments().getLong(KEY_MARKER_ID), new DescriptionGeneratorImpl(getActivity())); - startActivity(new Intent(getActivity(), MarkerListActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); + Intent intent = IntentUtils.newIntent(getActivity(), MarkerListActivity.class) + .putExtra(MarkerListActivity.EXTRA_TRACK_ID, getArguments().getLong(KEY_TRACK_ID)); + startActivity(intent); } }); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteOneTrackDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteOneTrackDialogFragment.java index 7824ee8ee..58630656e 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteOneTrackDialogFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteOneTrackDialogFragment.java @@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.fragments; import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.util.DialogUtils; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import android.app.Dialog; @@ -54,8 +55,8 @@ public class DeleteOneTrackDialogFragment extends DialogFragment { public void onClick(DialogInterface dialog, int which) { MyTracksProviderUtils.Factory.get(getActivity()) .deleteTrack(getArguments().getLong(KEY_TRACK_ID)); - startActivity(new Intent(getActivity(), TrackListActivity.class).addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); + Intent intent = IntentUtils.newIntent(getActivity(), TrackListActivity.class); + startActivity(intent); } }); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/InstallEarthDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/InstallEarthDialogFragment.java index cb6127602..a957db4fc 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/InstallEarthDialogFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/InstallEarthDialogFragment.java @@ -45,7 +45,8 @@ public class InstallEarthDialogFragment extends DialogFragment { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - startActivity(new Intent().setData(Uri.parse(SaveActivity.GOOGLE_EARTH_MARKET_URL))); + Intent intent = new Intent().setData(Uri.parse(SaveActivity.GOOGLE_EARTH_MARKET_URL)); + startActivity(intent); } }) .create(); diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/MapFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/MapFragment.java index 3ca1e90da..f1e6d1b01 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/MapFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/MapFragment.java @@ -239,7 +239,8 @@ public class MapFragment extends Fragment @Override public void onClick(View v) { if (v == messagePane) { - startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); + Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); + startActivity(intent); } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/backup/RestoreActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/backup/RestoreActivity.java index 79d33dc9f..83bf7d02a 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/backup/RestoreActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/backup/RestoreActivity.java @@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.io.backup; import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.util.DialogUtils; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import android.app.Activity; @@ -93,8 +94,8 @@ public class RestoreActivity extends Activity { public void onAsyncTaskCompleted(boolean success, int messageId) { removeDialog(DIALOG_PROGRESS_ID); Toast.makeText(this, messageId, success ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG).show(); - startActivity(new Intent(this, TrackListActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); + Intent intent = IntentUtils.newIntent(this, TrackListActivity.class); + startActivity(intent); } /** diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/backup/RestoreChooserActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/backup/RestoreChooserActivity.java index fc1ba9bce..df63911bf 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/backup/RestoreChooserActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/backup/RestoreChooserActivity.java @@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.io.backup; import com.google.android.apps.mytracks.util.FileUtils; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.maps.mytracks.R; @@ -76,8 +77,9 @@ public class RestoreChooserActivity extends Activity { } if (backupDates.length == 1) { - startActivity(new Intent(this, RestoreActivity.class) - .putExtra(RestoreActivity.EXTRA_DATE, backupDates[0].getTime())); + Intent intent = IntentUtils.newIntent(this, RestoreActivity.class) + .putExtra(RestoreActivity.EXTRA_DATE, backupDates[0].getTime()); + startActivity(intent); finish(); return; } @@ -100,8 +102,10 @@ public class RestoreChooserActivity extends Activity { .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - startActivity(new Intent(RestoreChooserActivity.this, RestoreActivity.class).putExtra( - RestoreActivity.EXTRA_DATE, backupDates[which].getTime())); + Intent intent = IntentUtils.newIntent( + RestoreChooserActivity.this, RestoreActivity.class) + .putExtra(RestoreActivity.EXTRA_DATE, backupDates[which].getTime()); + startActivity(intent); finish(); } }) diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/docs/SendDocsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/docs/SendDocsActivity.java index 5c00f8874..688a185b1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/docs/SendDocsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/docs/SendDocsActivity.java @@ -19,6 +19,7 @@ import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendActivity; import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask; import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest; import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import android.content.Intent; @@ -43,7 +44,7 @@ public class SendDocsActivity extends AbstractSendActivity { @Override protected void startNextActivity(boolean success, boolean isCancel) { sendRequest.setDocsSuccess(success); - Intent intent = new Intent(this, UploadResultActivity.class) + Intent intent = IntentUtils.newIntent(this, UploadResultActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); startActivity(intent); finish(); diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesActivity.java index 92bac1af4..f1aab6aad 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesActivity.java @@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendActivity; import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask; import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest; import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import com.google.common.annotations.VisibleForTesting; @@ -45,10 +46,9 @@ public class SendFusionTablesActivity extends AbstractSendActivity { @Override protected void startNextActivity(boolean success, boolean isCancel) { sendRequest.setFusionTablesSuccess(success); - Class next = getNextClass(sendRequest, isCancel); - - Intent intent = new Intent(this, next).putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); + Intent intent = IntentUtils.newIntent(this, next) + .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); startActivity(intent); finish(); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/ChooseMapActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/ChooseMapActivity.java index 62112474c..9b5d5a23b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/ChooseMapActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/ChooseMapActivity.java @@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.io.maps; import com.google.android.apps.mytracks.io.gdata.maps.MapsMapMetadata; import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest; import com.google.android.apps.mytracks.util.DialogUtils; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import com.google.common.annotations.VisibleForTesting; @@ -209,7 +210,7 @@ public class ChooseMapActivity extends Activity { */ private void startNextActivity(String mapId) { sendRequest.setMapId(mapId); - Intent intent = new Intent(this, SendMapsActivity.class) + Intent intent = IntentUtils.newIntent(this, SendMapsActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); startActivity(intent); finish(); diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsActivity.java index c500c96f6..338687f17 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsActivity.java @@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendActivity; import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask; import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest; import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import com.google.common.annotations.VisibleForTesting; @@ -47,10 +48,9 @@ public class SendMapsActivity extends AbstractSendActivity { @Override protected void startNextActivity(boolean success, boolean isCancel) { sendRequest.setMapsSuccess(success); - Class next = getNextClass(sendRequest, isCancel); - - Intent intent = new Intent(this, next).putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); + Intent intent = IntentUtils.newIntent(this, next) + .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); startActivity(intent); finish(); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/AccountChooserActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/AccountChooserActivity.java index 9b769ef1a..6e8cbffbc 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/AccountChooserActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/AccountChooserActivity.java @@ -25,6 +25,7 @@ import com.google.android.apps.mytracks.io.gdata.maps.MapsConstants; import com.google.android.apps.mytracks.io.maps.ChooseMapActivity; import com.google.android.apps.mytracks.io.maps.SendMapsActivity; import com.google.android.apps.mytracks.util.ApiAdapterFactory; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import android.accounts.Account; @@ -294,7 +295,7 @@ public class AccountChooserActivity extends Activity { } else { next = UploadResultActivity.class; } - Intent intent = new Intent(this, next) + Intent intent = IntentUtils.newIntent(this, next) .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); startActivity(intent); finish(); diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivity.java index 2da21c826..259c8c69f 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivity.java @@ -182,11 +182,11 @@ public class UploadResultActivity extends Activity { SharedPreferences prefs = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); boolean shareUrlOnly = prefs.getBoolean(getString(R.string.share_url_only_key), false); - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType(TEXT_PLAIN_TYPE); - intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_track_subject)); - intent.putExtra(Intent.EXTRA_TEXT, - shareUrlOnly ? url : getString(R.string.share_track_url_body_format, url)); + Intent intent = new Intent(Intent.ACTION_SEND) + .setType(TEXT_PLAIN_TYPE) + .putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_track_subject)) + .putExtra(Intent.EXTRA_TEXT, + shareUrlOnly ? url : getString(R.string.share_track_url_body_format, url)); startActivity(Intent.createChooser(intent, getString(R.string.share_track_picker_title))); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivity.java index c2703b016..63b646f23 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivity.java @@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.io.sendtogoogle; import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.util.AnalyticsUtils; import com.google.android.apps.mytracks.util.ApiAdapterFactory; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; import com.google.common.annotations.VisibleForTesting; @@ -237,7 +238,7 @@ public class UploadServiceChooserActivity extends Activity { sendRequest.setSendFusionTables(sendFusionTables()); sendRequest.setSendDocs(sendDocs()); sendRequest.setNewMap(!existingMapRadioButton.isChecked()); - Intent intent = new Intent(this, AccountChooserActivity.class) + Intent intent = IntentUtils.newIntent(this, AccountChooserActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); startActivity(intent); finish(); 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 e5e317215..6e130c8ea 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -38,6 +38,7 @@ import com.google.android.apps.mytracks.services.tasks.SplitTask; import com.google.android.apps.mytracks.services.tasks.StatusAnnouncerFactory; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatisticsBuilder; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.maps.mytracks.R; @@ -487,11 +488,9 @@ public class TrackRecordingService extends Service { Notification notification = new Notification( R.drawable.arrow_320, null /* tickerText */, System.currentTimeMillis()); - Intent intent = new Intent(this, TrackDetailActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) + Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class) .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId); - PendingIntent contentIntent = PendingIntent.getActivity( - this, 0 /* requestCode */, intent, 0 /* flags */); + PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); notification.setLatestEventInfo(this, getString(R.string.my_tracks_app_name), getString(R.string.track_record_notification), contentIntent); notification.flags += Notification.FLAG_NO_CLEAR; diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/IntentUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/IntentUtils.java new file mode 100644 index 000000000..e38b55cff --- /dev/null +++ b/MyTracks/src/com/google/android/apps/mytracks/util/IntentUtils.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.android.apps.mytracks.util; + +import android.content.Context; +import android.content.Intent; + +/** + * Utilities for creating intents. + * + * @author Jimmy Shih + */ +public class IntentUtils { + + private IntentUtils() {} + + /** + * Creates an intent with {@link Intent#FLAG_ACTIVITY_CLEAR_TOP} and + * {@link Intent#FLAG_ACTIVITY_NEW_TASK}. + * + * @param context the context + * @param cls the class + */ + public static final Intent newIntent(Context context, Class cls) { + return new Intent(context, cls).addFlags( + Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + } +} diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java index bbb9056cc..94db8b923 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java @@ -106,9 +106,9 @@ public class TrackRecordingServiceConnectionUtils { long recordingTrackId = PreferencesUtils.getRecordingTrackId(context); trackRecordingService.endCurrentTrack(); if (recordingTrackId != -1L) { - Intent intent = new Intent(context, TrackEditActivity.class) - .putExtra(TrackEditActivity.EXTRA_SHOW_CANCEL, false) - .putExtra(TrackEditActivity.EXTRA_TRACK_ID, recordingTrackId); + Intent intent = IntentUtils.newIntent(context, TrackEditActivity.class) + .putExtra(TrackEditActivity.EXTRA_TRACK_ID, recordingTrackId) + .putExtra(TrackEditActivity.EXTRA_NEW_TRACK, true); context.startActivity(intent); } } catch (Exception e) { 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 864ab4e60..3c76166c8 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java +++ b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java @@ -20,11 +20,13 @@ import static com.google.android.apps.mytracks.Constants.SETTINGS_NAME; import static com.google.android.apps.mytracks.Constants.TAG; import com.google.android.apps.mytracks.TrackDetailActivity; +import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.services.ControlRecordingService; import com.google.android.apps.mytracks.stats.TripStatistics; +import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.maps.mytracks.R; @@ -146,10 +148,12 @@ public class TrackWidgetProvider RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.track_widget); // Make all of the stats open the mytracks activity. - Intent intent = new Intent(context, TrackDetailActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + Intent intent; if (track != null) { - intent.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId()); + intent = IntentUtils.newIntent(context, TrackDetailActivity.class) + .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId()); + } else { + intent = IntentUtils.newIntent(context, TrackListActivity.class); } PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.appwidget_track_statistics, pendingIntent); @@ -190,8 +194,8 @@ public class TrackWidgetProvider * @param icon The resource id of the icon to show for the button */ private void setButtonIntent(RemoteViews views, int action, int icon) { - Intent intent = new Intent(context, ControlRecordingService.class); - intent.setAction(context.getString(action)); + Intent intent = new Intent(context, ControlRecordingService.class) + .setAction(context.getString(action)); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.appwidget_button, pendingIntent);