diff --git a/MyTracks/AndroidManifest.xml b/MyTracks/AndroidManifest.xml
index 8aeb07a88..6a074d09a 100755
--- a/MyTracks/AndroidManifest.xml
+++ b/MyTracks/AndroidManifest.xml
@@ -46,17 +46,6 @@ limitations under the License.
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
- %3$s からGPXファイル %2$d件のうち %1$d件をインポートしました
- %s ではGPXファイルがありません.SDカードを読み込めないかディレクトリにGPXファイルが無いかも知れません.
+ %3$s からGPXファイル %2$d件のうち %1$d件をインポートしました
+ %s ではGPXファイルがありません.SDカードを読み込めないかディレクトリにGPXファイルが無いかも知れません.
ファイル %s のインポートエラー
diff --git a/MyTracks/res/values-ru/strings.xml b/MyTracks/res/values-ru/strings.xml
index 5e3068b2f..0598737ce 100644
--- a/MyTracks/res/values-ru/strings.xml
+++ b/MyTracks/res/values-ru/strings.xml
@@ -162,8 +162,8 @@ limitations under the License.
$2 : Attempted imports
$3 : MyTracks gpx path
-->
- Импортировано %1$d из %2$d GPX файлов с %3$s
- GPX файлы не найденны в %s. Возможно не читается SD-карта или каталог не содержит GPX файлы.
+ Импортировано %1$d из %2$d GPX файлов с %3$s
+ GPX файлы не найденны в %s. Возможно не читается SD-карта или каталог не содержит GPX файлы.
Ошибка импорта файла %s
diff --git a/MyTracks/res/values/strings.xml b/MyTracks/res/values/strings.xml
index 694c2520d..5a5e33fba 100644
--- a/MyTracks/res/values/strings.xml
+++ b/MyTracks/res/values/strings.xml
@@ -163,9 +163,12 @@ limitations under the License.
$2 : Attempted imports
$3 : MyTracks gpx path
-->
- Imported %1$d of %2$d GPX files from %3$s
- No GPX files found in %s. SD card may be unreadable or directory may not contain GPX files.
+ Imported %1$d of %2$d GPX files from %3$s
+ No GPX files found in %s. SD card may be unreadable or directory may not contain GPX files.
Import error for file %s
+ Import into My Tracks
+ Successfully imported %1$d track(s) from file.
+ Show track
Delete all markers
diff --git a/MyTracks/src/com/google/android/apps/mytracks/DialogManager.java b/MyTracks/src/com/google/android/apps/mytracks/DialogManager.java
index 722530884..6401f7b63 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/DialogManager.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/DialogManager.java
@@ -17,16 +17,13 @@ package com.google.android.apps.mytracks;
import static com.google.android.apps.mytracks.Constants.TAG;
-import com.google.android.apps.mytracks.io.sendtogoogle.SendDialog;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
-import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
-import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager.BadTokenException;
@@ -37,74 +34,12 @@ import android.view.WindowManager.BadTokenException;
*/
public class DialogManager {
- public static final int DIALOG_IMPORT_PROGRESS = 2;
- public static final int DIALOG_PROGRESS = 3;
-
- private ProgressDialog progressDialog;
- private ProgressDialog importProgressDialog;
- private SendDialog sendToGoogleDialog;
-
private MyTracks activity;
public DialogManager(MyTracks activity) {
this.activity = activity;
}
- protected Dialog onCreateDialog(int id, Bundle args) {
- switch (id) {
- case DIALOG_IMPORT_PROGRESS:
- importProgressDialog = new ProgressDialog(activity);
- importProgressDialog.setIcon(android.R.drawable.ic_dialog_info);
- importProgressDialog.setTitle(
- activity.getString(R.string.progress_title));
- importProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- importProgressDialog.setMessage(
- activity.getString(R.string.import_progress_message));
- return importProgressDialog;
- case DIALOG_PROGRESS:
- progressDialog = new ProgressDialog(activity);
- progressDialog.setIcon(android.R.drawable.ic_dialog_info);
- progressDialog.setTitle(activity.getString(R.string.progress_title));
- progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- progressDialog.setMessage("");
- progressDialog.setMax(100);
- progressDialog.setProgress(10);
- return progressDialog;
- }
- return null;
- }
-
- public void setProgressMessage(final String message) {
- activity.runOnUiThread(new Runnable() {
- public void run() {
- synchronized (this) {
- if (progressDialog != null) {
- progressDialog.setMessage(message);
- }
- }
- }
- });
- }
-
- public void setProgressValue(final int percent) {
- activity.runOnUiThread(new Runnable() {
- public void run() {
- synchronized (this) {
- if (progressDialog != null) {
- progressDialog.setProgress(percent);
- }
- }
- }
- });
- }
-
- /**
- * @return the sendToGoogleDialog
- */
- public SendDialog getSendToGoogleDialog() {
- return sendToGoogleDialog;
- }
-
/**
* Shows a dialog with the given message.
* Does it on the UI thread.
diff --git a/MyTracks/src/com/google/android/apps/mytracks/ImportAllTracks.java b/MyTracks/src/com/google/android/apps/mytracks/ImportAllTracks.java
index 8826e40c7..0e23f3d8a 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/ImportAllTracks.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/ImportAllTracks.java
@@ -104,9 +104,9 @@ public class ImportAllTracks {
Log.i(Constants.TAG, "ImportAllTracks: Done");
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
if (gpxFileCount == 0) {
- builder.setMessage(activity.getString(R.string.import_empty, gpxPath + "/"));
+ builder.setMessage(activity.getString(R.string.import_multi_empty, gpxPath + "/"));
} else {
- builder.setMessage(activity.getString(R.string.import_done, importSuccessCount, gpxFileCount,
+ builder.setMessage(activity.getString(R.string.import_multi_done, importSuccessCount, gpxFileCount,
gpxPath + "/"));
}
builder.setPositiveButton(R.string.ok, null);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/MyTracks.java b/MyTracks/src/com/google/android/apps/mytracks/MyTracks.java
index de3fc31bb..1bddc20e4 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/MyTracks.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/MyTracks.java
@@ -16,12 +16,11 @@
package com.google.android.apps.mytracks;
import static com.google.android.apps.mytracks.Constants.TAG;
-import static com.google.android.apps.mytracks.DialogManager.DIALOG_IMPORT_PROGRESS;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.TrackDataHub;
+import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
-import com.google.android.apps.mytracks.io.file.GpxImporter;
import com.google.android.apps.mytracks.io.file.TempFileCleaner;
import com.google.android.apps.mytracks.services.ITrackRecordingService;
import com.google.android.apps.mytracks.services.TrackRecordingService;
@@ -32,9 +31,9 @@ import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.Dialog;
import android.app.TabActivity;
import android.content.ComponentName;
+import android.content.ContentUris;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
@@ -55,21 +54,12 @@ import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.Toast;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.xml.sax.SAXException;
-
/**
* The super activity that embeds our sub activities.
*
* @author Leif Hendrik Wilden
*/
-public class MyTracks extends TabActivity implements OnTouchListener,
- ProgressIndicator {
+public class MyTracks extends TabActivity implements OnTouchListener {
private TrackDataHub dataHub;
/*
@@ -230,73 +220,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
// This will show the eula until the user accepts or quits the app.
Eula.showEulaRequireAcceptance(this);
-
- // Check if we got invoked via the VIEW intent:
- Intent intent = getIntent();
- String action;
- if (intent != null && (action = intent.getAction()) != null) {
- if (action.equals(Intent.ACTION_MAIN)) {
- // Do nothing.
- } else if (action.equals(Intent.ACTION_VIEW)) {
- if (intent.getScheme() != null && intent.getScheme().equals("file")) {
- Log.w(TAG, "Received a VIEW intent with file scheme. Importing.");
- importGpxFile(intent.getData().getPath());
- } else {
- Log.w(TAG, "Received a VIEW intent with unsupported scheme " + intent.getScheme());
- }
- } else {
- Log.w(TAG, "Received an intent with unsupported action " + action);
- }
- } else {
- Log.d(TAG, "Received an intent with no action.");
- }
- }
-
- private void importGpxFile(final String fileName) {
- dialogManager.showDialogSafely(DIALOG_IMPORT_PROGRESS);
- Thread t = new Thread() {
- @Override
- public void run() {
- int message = R.string.success;
-
- long[] trackIdsImported = null;
-
- try {
- try {
- InputStream is = new FileInputStream(fileName);
- trackIdsImported = GpxImporter.importGPXFile(is, providerUtils);
- } catch (SAXException e) {
- Log.e(TAG, "Caught an unexpected exception.", e);
- message = R.string.error_generic;
- } catch (ParserConfigurationException e) {
- Log.e(TAG, "Caught an unexpected exception.", e);
- message = R.string.error_generic;
- } catch (IOException e) {
- Log.e(TAG, "Caught an unexpected exception.", e);
- message = R.string.error_unable_to_read_file;
- } catch (NullPointerException e) {
- Log.e(TAG, "Caught an unexpected exception.", e);
- message = R.string.error_invalid_gpx_format;
- } catch (OutOfMemoryError e) {
- Log.e(TAG, "Caught an unexpected exception.", e);
- message = R.string.error_out_of_memory;
- }
- if (trackIdsImported != null && trackIdsImported.length > 0) {
- // select last track from import file
- dataHub.loadTrack(trackIdsImported[trackIdsImported.length - 1]);
- } else {
- dialogManager.showMessageDialog(message, false/* success */);
- }
- } finally {
- runOnUiThread(new Runnable() {
- public void run() {
- dismissDialog(DIALOG_IMPORT_PROGRESS);
- }
- });
- }
- }
- };
- t.start();
}
@Override
@@ -349,6 +272,14 @@ public class MyTracks extends TabActivity implements OnTouchListener,
Intent startIntent = new Intent(this, TrackRecordingService.class);
startService(startIntent);
}
+
+ Intent intent = getIntent();
+ String action = intent.getAction();
+ if ((Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action))
+ && TracksColumns.CONTENT_ITEMTYPE.equals(intent.getType())) {
+ long trackId = ContentUris.parseId(intent.getData());
+ dataHub.loadTrack(trackId);
+ }
}
/*
@@ -376,21 +307,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
: super.onOptionsItemSelected(item);
}
- /*
- * Dialog events:
- * ==============
- */
-
- @Override
- protected Dialog onCreateDialog(int id, Bundle args) {
- return dialogManager.onCreateDialog(id, args);
- }
-
- @Override
- protected Dialog onCreateDialog(int id) {
- return dialogManager.onCreateDialog(id, null);
- }
-
/*
* Key events:
* ===========
@@ -487,22 +403,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
}
return false;
}
- // ProgressIndicator implementation
-
- @Override
- public void setProgressMessage(int resId) {
- dialogManager.setProgressMessage(getString(resId));
- }
-
- @Override
- public void clearProgressMessage() {
- dialogManager.setProgressMessage("");
- }
-
- @Override
- public void setProgressValue(final int percent) {
- dialogManager.setProgressValue(percent);
- }
/**
* Deletes the track with the given id.
diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/ImportActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/ImportActivity.java
new file mode 100644
index 000000000..14fe0d171
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/ImportActivity.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2011 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.io.file;
+
+import static com.google.android.apps.mytracks.Constants.TAG;
+
+import com.google.android.apps.mytracks.DialogManager;
+import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
+import com.google.android.apps.mytracks.content.TracksColumns;
+import com.google.android.maps.mytracks.R;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
+import android.app.ProgressDialog;
+import android.content.ContentUris;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Helper activity which imports tracks from a file.
+ *
+ * @author Rodrigo Damazio
+ */
+public class ImportActivity extends Activity {
+
+ private ProgressDialog progressDialog;
+ private MyTracksProviderUtils providerUtils;
+
+ @Override
+ public void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ providerUtils = MyTracksProviderUtils.Factory.get(this);
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ Intent intent = getIntent();
+ String action = intent.getAction();
+ if (!Intent.ACTION_VIEW.equals(action) &&
+ !Intent.ACTION_ATTACH_DATA.equals(action)) {
+ Log.e(TAG, "Received an intent with unsupported action: " + intent);
+ finish();
+ return;
+ }
+
+ if (!"file".equals(intent.getScheme())) {
+ Log.e(TAG, "Received a VIEW intent with unsupported scheme " + intent.getScheme());
+ finish();
+ return;
+ }
+
+ Log.i(TAG, "Received a VIEW intent with file scheme. Importing.");
+ startTrackImport(intent.getData().getPath());
+ }
+
+ private void startTrackImport(final String fileName) {
+ progressDialog = new ProgressDialog(this);
+ progressDialog.setOwnerActivity(this);
+ progressDialog.setIcon(android.R.drawable.ic_dialog_info);
+ progressDialog.setTitle(R.string.progress_title);
+ progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ progressDialog.setMessage(getString(R.string.import_progress_message));
+ progressDialog.show();
+
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ int message = R.string.success;
+
+ long[] trackIdsImported = null;
+
+ try {
+ try {
+ InputStream is = new FileInputStream(fileName);
+ trackIdsImported = GpxImporter.importGPXFile(is, providerUtils);
+ } catch (SAXException e) {
+ Log.e(TAG, "Caught an unexpected exception.", e);
+ message = R.string.error_generic;
+ } catch (ParserConfigurationException e) {
+ Log.e(TAG, "Caught an unexpected exception.", e);
+ message = R.string.error_generic;
+ } catch (IOException e) {
+ Log.e(TAG, "Caught an unexpected exception.", e);
+ message = R.string.error_unable_to_read_file;
+ } catch (NullPointerException e) {
+ Log.e(TAG, "Caught an unexpected exception.", e);
+ message = R.string.error_invalid_gpx_format;
+ } catch (OutOfMemoryError e) {
+ Log.e(TAG, "Caught an unexpected exception.", e);
+ message = R.string.error_out_of_memory;
+ }
+
+ boolean success = (trackIdsImported != null && trackIdsImported.length > 0);
+ onImportDone(success, message, trackIdsImported);
+ } finally {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ progressDialog.dismiss();
+ }
+ });
+ }
+ }
+ };
+ t.start();
+ }
+
+ private void onImportDone(boolean success, int message, final long[] trackIds) {
+ OnClickListener finishOnClick = new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+ finish();
+ }
+ };
+
+ if (!success) {
+ DialogManager.showMessageDialog(this, message, false /* success */,
+ finishOnClick);
+ return;
+ }
+
+ // Show a dialog telling the user about the import, and asking if he wishes
+ // to open the track right away.
+ final Builder dialogBuilder = new AlertDialog.Builder(this);
+ dialogBuilder.setCancelable(true);
+ dialogBuilder.setMessage(getString(R.string.import_success, trackIds.length));
+ dialogBuilder.setPositiveButton(android.R.string.ok, finishOnClick);
+ dialogBuilder.setNeutralButton(R.string.import_show_track, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+ long lastTrackId = trackIds[trackIds.length - 1];
+ Uri trackUri = ContentUris.withAppendedId(TracksColumns.CONTENT_URI, lastTrackId);
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(trackUri, TracksColumns.CONTENT_ITEMTYPE);
+ startActivity(intent);
+ finish();
+ }
+ });
+
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ dialogBuilder.show();
+ }
+ });
+ }
+}
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/DialogManagerTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/DialogManagerTest.java
index 5a50fc677..bfd5d0e08 100644
--- a/MyTracksTest/src/com/google/android/apps/mytracks/DialogManagerTest.java
+++ b/MyTracksTest/src/com/google/android/apps/mytracks/DialogManagerTest.java
@@ -15,8 +15,6 @@
*/
package com.google.android.apps.mytracks;
-import com.google.android.apps.mytracks.io.sendtogoogle.SendDialog;
-
import android.app.Dialog;
import android.app.ProgressDialog;
import android.test.ActivityInstrumentationTestCase2;
@@ -45,14 +43,4 @@ public class DialogManagerTest
assertNotNull(d);
assertTrue(d instanceof ProgressDialog);
}
-
- public void test_onCreateProgress() {
- Dialog d =
- getActivity().onCreateDialog(DialogManager.DIALOG_PROGRESS, null);
- assertNotNull(d);
- assertTrue(d instanceof ProgressDialog);
- ProgressDialog pd = (ProgressDialog) d;
- assertEquals(100, pd.getMax());
- assertEquals(10, pd.getProgress());
- }
}