infos = getPackageManager().queryIntentActivities(
+ new Intent().setType(SaveActivity.KML_MIME_TYPE), PackageManager.MATCH_DEFAULT_ONLY);
+ for (ResolveInfo info : infos) {
+ if (info.activityInfo != null && info.activityInfo.packageName != null
+ && info.activityInfo.packageName.equals(SaveActivity.GOOGLE_EARTH_PACKAGE)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Gets the map activity, can be null.
*/
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java
index bc21d80d0..39a53993b 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java
@@ -37,8 +37,8 @@ import android.widget.EditText;
*/
public class TrackEditActivity extends Activity implements OnClickListener {
- public static final String TRACK_ID = "trackId";
- public static final String SHOW_CANCEL = "showCancel";
+ public static final String EXTRA_TRACK_ID = "track_id";
+ public static final String EXTRA_SHOW_CANCEL = "show_cancel";
private static final String TAG = TrackEditActivity.class.getSimpleName();
@@ -55,7 +55,7 @@ public class TrackEditActivity extends Activity implements OnClickListener {
super.onCreate(bundle);
setContentView(R.layout.track_edit);
- trackId = getIntent().getLongExtra(TRACK_ID, -1);
+ trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1);
if (trackId < 0) {
Log.e(TAG, "invalid trackId.");
finish();
@@ -87,7 +87,7 @@ public class TrackEditActivity extends Activity implements OnClickListener {
save.setOnClickListener(this);
Button cancel = (Button) findViewById(R.id.track_edit_cancel);
- if (getIntent().getBooleanExtra(SHOW_CANCEL, true)) {
+ if (getIntent().getBooleanExtra(EXTRA_SHOW_CANCEL, true)) {
cancel.setOnClickListener(this);
cancel.setVisibility(View.VISIBLE);
} else {
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
index c515cd16b..4dcb600fb 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
@@ -41,6 +41,7 @@ import android.os.Bundle;
import android.os.Parcelable;
import android.speech.tts.TextToSpeech;
import android.support.v4.app.DialogFragment;
+import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
@@ -69,7 +70,6 @@ public class TrackListActivity extends FragmentActivity {
private static final String CHECK_UNITS_DIALOG_TAG = "checkUnitsDialog";
private static final String DELETE_ALL_DIALOG_TAG = "deleteAllDialog";
private static final String EULA_DIALOG_TAG = "eulaDialog";
- private static final String EXPORT_ALL_DIALOG_TAG = "exportAllDialog";
private static final int WELCOME_ACTIVITY_REQUEST_CODE = 0;
@@ -169,7 +169,8 @@ public class TrackListActivity extends FragmentActivity {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
Intent intent = new Intent(TrackListActivity.this, TrackDetailActivity.class)
- .putExtra(TrackDetailActivity.TRACK_ID, id);
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
+ .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
startActivity(intent);
}
});
@@ -238,15 +239,10 @@ public class TrackListActivity extends FragmentActivity {
});
if (!EulaUtils.getEulaValue(this)) {
- new EulaDialogFragment().show(getSupportFragmentManager(), EULA_DIALOG_TAG);
- }
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- if (isRecording()) {
- trackRecordingServiceConnection.startAndBind();
+ Fragment fragment = getSupportFragmentManager().findFragmentByTag(EULA_DIALOG_TAG);
+ if (fragment == null) {
+ new EulaDialogFragment().show(getSupportFragmentManager(), EULA_DIALOG_TAG);
+ }
}
}
@@ -283,13 +279,22 @@ public class TrackListActivity extends FragmentActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.track_list, menu);
-
- recordTrack = menu.findItem(R.id.menu_record_track);
- stopRecording = menu.findItem(R.id.menu_stop_recording);
- search = menu.findItem(R.id.menu_search);
- importAll = menu.findItem(R.id.menu_import_all);
- exportAll = menu.findItem(R.id.menu_export_all);
- deleteAll = menu.findItem(R.id.menu_delete_all);
+ String fileTypes[] = getResources().getStringArray(R.array.file_types);
+ menu.findItem(R.id.track_list_export_gpx)
+ .setTitle(getString(R.string.menu_export_all_format, fileTypes[0]));
+ menu.findItem(R.id.track_list_export_kml)
+ .setTitle(getString(R.string.menu_export_all_format, fileTypes[1]));
+ menu.findItem(R.id.track_list_export_csv)
+ .setTitle(getString(R.string.menu_export_all_format, fileTypes[2]));
+ menu.findItem(R.id.track_list_export_tcx)
+ .setTitle(getString(R.string.menu_export_all_format, fileTypes[3]));
+
+ recordTrack = menu.findItem(R.id.track_list_record_track);
+ stopRecording = menu.findItem(R.id.track_list_stop_recording);
+ search = menu.findItem(R.id.track_list_search);
+ importAll = menu.findItem(R.id.track_list_import_all);
+ exportAll = menu.findItem(R.id.track_list_export_all);
+ deleteAll = menu.findItem(R.id.track_list_delete_all);
ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, search);
updateMenu();
@@ -330,33 +335,46 @@ public class TrackListActivity extends FragmentActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.menu_record_track:
+ case R.id.track_list_record_track:
updateMenuItems(true);
startRecording();
return true;
- case R.id.menu_stop_recording:
+ case R.id.track_list_stop_recording:
updateMenuItems(false);
stopRecording();
return true;
- case R.id.menu_search:
+ case R.id.track_list_search:
return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this);
- case R.id.menu_import_all:
+ case R.id.track_list_import_all:
startActivity(
new Intent(this, ImportActivity.class).putExtra(ImportActivity.EXTRA_IMPORT_ALL, true));
return true;
- case R.id.menu_export_all:
- new ExportAllDialogFragment().show(getSupportFragmentManager(), EXPORT_ALL_DIALOG_TAG);
+ case R.id.track_list_export_gpx:
+ startActivity(new Intent(this, ExportActivity.class).putExtra(
+ ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.GPX));
return true;
- case R.id.menu_delete_all:
+ case R.id.track_list_export_kml:
+ startActivity(new Intent(this, ExportActivity.class).putExtra(
+ ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML));
+ return true;
+ case R.id.track_list_export_csv:
+ startActivity(new Intent(this, ExportActivity.class).putExtra(
+ ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.CSV));
+ return true;
+ case R.id.track_list_export_tcx:
+ startActivity(new Intent(this, ExportActivity.class).putExtra(
+ ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.TCX));
+ return true;
+ case R.id.track_list_delete_all:
new DeleteAllDialogFragment().show(getSupportFragmentManager(), DELETE_ALL_DIALOG_TAG);
return true;
- case R.id.menu_aggregated_statistics:
+ case R.id.track_list_aggregated_statistics:
startActivity(new Intent(this, AggregatedStatsActivity.class));
return true;
- case R.id.menu_settings:
+ case R.id.track_list_settings:
startActivity(new Intent(this, SettingsActivity.class));
return true;
- case R.id.menu_help:
+ case R.id.track_list_help:
startActivity(new Intent(this, WelcomeActivity.class));
return true;
default:
@@ -398,8 +416,8 @@ public class TrackListActivity extends FragmentActivity {
service.endCurrentTrack();
if (recordingTrackId != -1L) {
Intent intent = new Intent(this, TrackEditActivity.class)
- .putExtra(TrackEditActivity.SHOW_CANCEL, false)
- .putExtra(TrackEditActivity.TRACK_ID, recordingTrackId);
+ .putExtra(TrackEditActivity.EXTRA_SHOW_CANCEL, false)
+ .putExtra(TrackEditActivity.EXTRA_TRACK_ID, recordingTrackId);
startActivity(intent);
}
recordingTrackId = -1L;
@@ -503,33 +521,4 @@ public class TrackListActivity extends FragmentActivity {
.create();
}
}
-
- /**
- * Export All DialogFragment.
- */
- public static class ExportAllDialogFragment extends DialogFragment {
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- String fileTypes[] = getResources().getStringArray(R.array.file_types);
- String[] choices = new String[fileTypes.length];
- for (int i = 0; i < fileTypes.length; i++) {
- choices[i] = getString(R.string.menu_export_all_format, fileTypes[i]);
- }
- return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
- .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
- Intent intent = new Intent(getActivity(), ExportActivity.class).putExtra(
- ExportActivity.EXTRA_TRACK_FILE_FORMAT,
- (Parcelable) TrackFileFormat.values()[index]);
- getActivity().startActivity(intent);
- }
- })
- .setSingleChoiceItems(choices, 0, null)
- .setTitle(R.string.menu_export_all)
- .create();
- }
- }
}
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 92cd7fb58..19edaa98f 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
@@ -92,9 +92,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));
- finish();
+ startActivity(new Intent(this, TrackListActivity.class)
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
}
/**
diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
index bc31d16b5..025938e48 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
@@ -20,7 +20,6 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.FileUtils;
-import com.google.android.apps.mytracks.util.PlayTrackUtils;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
@@ -48,8 +47,13 @@ public class SaveActivity extends Activity {
public static final String EXTRA_SHARE_TRACK = "share_track";
public static final String EXTRA_PLAY_TRACK = "play_track";
+ public static final String KML_MIME_TYPE = "application/vnd.google-earth.kml+xml";
+ public static final String GOOGLE_EARTH_PACKAGE = "com.google.earth";
+
private static final String TAG = SaveActivity.class.getSimpleName();
-
+ private static final String TOUR_FEATURE_ID = "com.google.earth.EXTRA.tour_feature_id";
+ private static final String GOOGLE_EARTH_CLASS = "com.google.earth.EarthActivity";
+
private static final int DIALOG_PROGRESS_ID = 0;
private static final int DIALOG_RESULT_ID = 1;
@@ -206,11 +210,10 @@ public class SaveActivity extends Activity {
startActivity(Intent.createChooser(intent, getString(R.string.share_track_picker_title)));
} else if (playTrack) {
Intent intent = new Intent()
- .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- .putExtra(PlayTrackUtils.TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
- .setClassName(PlayTrackUtils.GOOGLE_EARTH_PACKAGE, PlayTrackUtils.GOOGLE_EARTH_CLASS)
- .setDataAndType(Uri.fromFile(new File(filePath)), PlayTrackUtils.KML_MIME_TYPE);
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
+ .putExtra(TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
+ .setClassName(GOOGLE_EARTH_PACKAGE, GOOGLE_EARTH_CLASS)
+ .setDataAndType(Uri.fromFile(new File(filePath)), KML_MIME_TYPE);
startActivity(intent);
}
}
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 c72c1a19d..f92deabfc 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java
@@ -485,7 +485,8 @@ public class TrackRecordingService extends Service {
R.drawable.arrow_320, null /* tickerText */,
System.currentTimeMillis());
Intent intent = new Intent(this, TrackDetailActivity.class)
- .putExtra(TrackDetailActivity.TRACK_ID, recordingTrackId);
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
+ .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId);
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0 /* requestCode */, intent, 0 /* flags */);
notification.setLatestEventInfo(this, getString(R.string.my_tracks_app_name),
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/Api11Adapter.java b/MyTracks/src/com/google/android/apps/mytracks/util/Api11Adapter.java
index 00396f572..638a32f84 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/Api11Adapter.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/Api11Adapter.java
@@ -17,11 +17,11 @@
package com.google.android.apps.mytracks.util;
import android.annotation.TargetApi;
+import android.app.ActionBar;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.view.MenuItem;
-import android.view.Window;
import android.widget.SearchView;
/**
@@ -33,8 +33,10 @@ import android.widget.SearchView;
public class Api11Adapter extends Api10Adapter {
@Override
- public void showActionBar(Activity activity) {
- activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
+ public void configureActionBarHomeAsUp(Activity activity) {
+ ActionBar actionBar = activity.getActionBar();
+ actionBar.setHomeButtonEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
}
@Override
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/Api7Adapter.java b/MyTracks/src/com/google/android/apps/mytracks/util/Api7Adapter.java
index 1f7e8aefe..81dea19a6 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/Api7Adapter.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/Api7Adapter.java
@@ -104,7 +104,7 @@ public class Api7Adapter implements ApiAdapter {
}
@Override
- public void showActionBar(Activity activity) {
+ public void configureActionBarHomeAsUp(Activity activity) {
// Action bar not available, just hide the title and let actions be shown
// via the regular menu.
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/ApiAdapter.java b/MyTracks/src/com/google/android/apps/mytracks/util/ApiAdapter.java
index efdb86c25..e108620f3 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/ApiAdapter.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/ApiAdapter.java
@@ -101,15 +101,15 @@ public interface ApiAdapter {
*/
public BluetoothSocket getBluetoothSocket(BluetoothDevice bluetoothDevice) throws IOException;
- /**
- * Shows the action bar, if the current system supports it.
- * If it's not supported, the title bar will be kept hidden.
- *
+ /**
+ * Configures the action bar with the Home button as an Up button. If the
+ * system doesn't support action bar, hide the title bar.
+ *
* Due to changes in API level 11.
*
* @param activity the current activity
*/
- public void showActionBar(Activity activity);
+ public void configureActionBarHomeAsUp(Activity activity);
/**
* Configures the search widget.
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/PlayTrackUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/PlayTrackUtils.java
deleted file mode 100644
index 28cdf39e3..000000000
--- a/MyTracks/src/com/google/android/apps/mytracks/util/PlayTrackUtils.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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 com.google.android.apps.mytracks.io.file.SaveActivity;
-import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
-import com.google.android.maps.mytracks.R;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.net.Uri;
-import android.os.Parcelable;
-
-import java.util.List;
-
-/**
- * Utilities for playing a track on Google Earth.
- *
- * @author Jimmy Shih
- */
-public class PlayTrackUtils {
-
- /**
- * KML mime type.
- */
- public static final String KML_MIME_TYPE = "application/vnd.google-earth.kml+xml";
- public static final String TOUR_FEATURE_ID = "com.google.earth.EXTRA.tour_feature_id";
-
- public static final String GOOGLE_EARTH_PACKAGE = "com.google.earth";
- public static final String GOOGLE_EARTH_CLASS = "com.google.earth.EarthActivity";
- private static final String EARTN_MARKET_URI = "market://details?id=" + GOOGLE_EARTH_PACKAGE;
-
- private PlayTrackUtils() {}
-
- /**
- * Returns true if a Google Earth app that can handle KML mine type is
- * installed.
- *
- * @param context the context
- */
- public static boolean isEarthInstalled(Context context) {
- List infos = context.getPackageManager().queryIntentActivities(
- new Intent().setType(KML_MIME_TYPE), PackageManager.MATCH_DEFAULT_ONLY);
- for (ResolveInfo info : infos) {
- if (info.activityInfo != null && info.activityInfo.packageName != null
- && info.activityInfo.packageName.equals(GOOGLE_EARTH_PACKAGE)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Plays a track by sending an intent to {@link SaveActivity}.
- *
- * @param context the context
- * @param trackId the track id
- */
- public static void playTrack(Context context, long trackId) {
- AnalyticsUtils.sendPageViews(context, "/action/play");
-
- Intent intent = new Intent(context, SaveActivity.class)
- .putExtra(SaveActivity.EXTRA_TRACK_ID, trackId)
- .putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML)
- .putExtra(SaveActivity.EXTRA_PLAY_TRACK, true);
- context.startActivity(intent);
- }
-
- /**
- * Creates a dialog to install Google Earth from the Android Market.
- *
- * @param context the context
- */
- public static Dialog createInstallEarthDialog(final Context context) {
- return new AlertDialog.Builder(context)
- .setCancelable(true)
- .setMessage(R.string.track_detail_install_earth_message)
- .setNegativeButton(android.R.string.cancel, null)
- .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent();
- intent.setData(Uri.parse(EARTN_MARKET_URI));
- context.startActivity(intent);
- }
- })
- .create();
- }
-}
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 40546740f..c80bd6ca3 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java
@@ -145,9 +145,10 @@ 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);
+ Intent intent = new Intent(context, TrackDetailActivity.class)
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
if (track != null) {
- intent.putExtra(TrackDetailActivity.TRACK_ID, track.getId());
+ intent.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId());
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.appwidget_track_statistics, pendingIntent);