forked from upstream-mirrors/OpenTracks
Use a dialog fragment to select the import all type
This commit is contained in:
@@ -30,14 +30,6 @@ limitations under the License.
|
|||||||
android:icon="@drawable/menu_import"
|
android:icon="@drawable/menu_import"
|
||||||
android:id="@+id/track_list_import_all"
|
android:id="@+id/track_list_import_all"
|
||||||
android:title="@string/menu_import_all">
|
android:title="@string/menu_import_all">
|
||||||
<menu>
|
|
||||||
<item
|
|
||||||
android:id="@+id/track_list_import_all_gpx"
|
|
||||||
android:title=""/>
|
|
||||||
<item
|
|
||||||
android:id="@+id/track_list_import_all_kml"
|
|
||||||
android:title=""/>
|
|
||||||
</menu>
|
|
||||||
</item>
|
</item>
|
||||||
<item
|
<item
|
||||||
android:icon="@drawable/menu_save"
|
android:icon="@drawable/menu_save"
|
||||||
|
|||||||
@@ -844,6 +844,17 @@ limitations under the License.
|
|||||||
%1$s: the directory. E.g., '/storage/sdcard0/MyTracks/gpx/'.">
|
%1$s: the directory. E.g., '/storage/sdcard0/MyTracks/gpx/'.">
|
||||||
Importing from %1$s…
|
Importing from %1$s…
|
||||||
</string>
|
</string>
|
||||||
|
<string name="import_selection_option"
|
||||||
|
translation_description="When importing from external storage, the option to import all
|
||||||
|
files of a certain file format.
|
||||||
|
|
||||||
|
%1$s: file format. E.g., 'GPX'.">
|
||||||
|
Import all %1$s
|
||||||
|
</string>
|
||||||
|
<string name="import_selection_title"
|
||||||
|
translation_description="The dialog title when importing from external storage.">
|
||||||
|
Import from external storage
|
||||||
|
</string>
|
||||||
<string name="import_success"
|
<string name="import_success"
|
||||||
translation_description="When importing from the external storage, the success message.
|
translation_description="When importing from the external storage, the success message.
|
||||||
|
|
||||||
@@ -1016,15 +1027,7 @@ limitations under the License.
|
|||||||
translation_description="In the menu, to import all tracks from the external storage.
|
translation_description="In the menu, to import all tracks from the external storage.
|
||||||
|
|
||||||
Character limit: ~20 (1 line)">
|
Character limit: ~20 (1 line)">
|
||||||
Import all from external storage
|
Import all
|
||||||
</string>
|
|
||||||
<string name="menu_import_all_format"
|
|
||||||
translation_description="Under the import all menu option, the submenu option to import all
|
|
||||||
files of a certain file format.
|
|
||||||
|
|
||||||
%1$s: file format. E.g., 'GPX'.
|
|
||||||
Character limit: ~20 (1 line)">
|
|
||||||
Import %1$s
|
|
||||||
</string>
|
</string>
|
||||||
<string name="menu_insert_marker"
|
<string name="menu_insert_marker"
|
||||||
translation_description="In the menu, to insert a marker.
|
translation_description="In the menu, to insert a marker.
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment;
|
|||||||
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment.EnableSyncCaller;
|
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment.EnableSyncCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
|
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller;
|
import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller;
|
||||||
|
import com.google.android.apps.mytracks.fragments.ImportSelectionDialogFragment;
|
||||||
|
import com.google.android.apps.mytracks.fragments.ImportSelectionDialogFragment.ImportSelectionCaller;
|
||||||
import com.google.android.apps.mytracks.io.file.ImportActivity;
|
import com.google.android.apps.mytracks.io.file.ImportActivity;
|
||||||
import com.google.android.apps.mytracks.io.file.SaveActivity;
|
import com.google.android.apps.mytracks.io.file.SaveActivity;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
||||||
@@ -93,7 +95,7 @@ import java.util.Locale;
|
|||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public class TrackListActivity extends AbstractSendToGoogleActivity
|
public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||||
implements EulaCaller, EnableSyncCaller, DeleteTrackCaller {
|
implements EulaCaller, EnableSyncCaller, DeleteTrackCaller, ImportSelectionCaller {
|
||||||
|
|
||||||
private static final String TAG = TrackListActivity.class.getSimpleName();
|
private static final String TAG = TrackListActivity.class.getSimpleName();
|
||||||
private static final String START_GPS_KEY = "start_gps_key";
|
private static final String START_GPS_KEY = "start_gps_key";
|
||||||
@@ -536,11 +538,6 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.track_list, menu);
|
getMenuInflater().inflate(R.menu.track_list, menu);
|
||||||
String fileTypes[] = getResources().getStringArray(R.array.file_types);
|
String fileTypes[] = getResources().getStringArray(R.array.file_types);
|
||||||
// Import all submenu titles
|
|
||||||
menu.findItem(R.id.track_list_import_all_gpx)
|
|
||||||
.setTitle(getString(R.string.menu_import_all_format, fileTypes[0]));
|
|
||||||
menu.findItem(R.id.track_list_import_all_kml)
|
|
||||||
.setTitle(getString(R.string.menu_import_all_format, fileTypes[1]));
|
|
||||||
// Save all submenu titles
|
// Save all submenu titles
|
||||||
menu.findItem(R.id.track_list_save_all_gpx)
|
menu.findItem(R.id.track_list_save_all_gpx)
|
||||||
.setTitle(getString(R.string.menu_save_format, fileTypes[0]));
|
.setTitle(getString(R.string.menu_save_format, fileTypes[0]));
|
||||||
@@ -588,12 +585,10 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
handleStartGps();
|
handleStartGps();
|
||||||
updateMenuItems(recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
updateMenuItems(recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_list_import_all_gpx:
|
case R.id.track_list_import_all:
|
||||||
startImportActivity(TrackFileFormat.GPX);
|
new ImportSelectionDialogFragment().show(
|
||||||
return true;
|
getSupportFragmentManager(), ImportSelectionDialogFragment.IMPORT_SELECTION_DIALOG_TAG);
|
||||||
case R.id.track_list_import_all_kml:
|
return true;
|
||||||
startImportActivity(TrackFileFormat.KML);
|
|
||||||
return true;
|
|
||||||
case R.id.track_list_save_all_gpx:
|
case R.id.track_list_save_all_gpx:
|
||||||
startSaveActivity(TrackFileFormat.GPX);
|
startSaveActivity(TrackFileFormat.GPX);
|
||||||
return true;
|
return true;
|
||||||
@@ -672,6 +667,16 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onImportSelectionDone(TrackFileFormat trackFileFormat) {
|
||||||
|
AnalyticsUtils.sendPageViews(
|
||||||
|
this, "/action/import_all_" + trackFileFormat.name().toLowerCase(Locale.US));
|
||||||
|
Intent intent = IntentUtils.newIntent(this, ImportActivity.class)
|
||||||
|
.putExtra(ImportActivity.EXTRA_IMPORT_ALL, true)
|
||||||
|
.putExtra(ImportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows start up dialogs.
|
* Shows start up dialogs.
|
||||||
*/
|
*/
|
||||||
@@ -785,20 +790,6 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
bindChangedCallback.run();
|
bindChangedCallback.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the {@link ImportActivity} to import all tracks.
|
|
||||||
*
|
|
||||||
* @param trackFileFormat the track file format
|
|
||||||
*/
|
|
||||||
private void startImportActivity(TrackFileFormat trackFileFormat) {
|
|
||||||
AnalyticsUtils.sendPageViews(
|
|
||||||
this, "/action/import_all_" + trackFileFormat.name().toLowerCase(Locale.US));
|
|
||||||
Intent intent = IntentUtils.newIntent(this, ImportActivity.class)
|
|
||||||
.putExtra(ImportActivity.EXTRA_IMPORT_ALL, true)
|
|
||||||
.putExtra(ImportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the {@link SaveActivity} to save all tracks.
|
* Starts the {@link SaveActivity} to save all tracks.
|
||||||
*
|
*
|
||||||
|
|||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 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.fragments;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A DialogFragment to select an import type, gpx, kml, etc.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public class ImportSelectionDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for caller of this dialog fragment.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public interface ImportSelectionCaller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when import selection is done.
|
||||||
|
*/
|
||||||
|
public void onImportSelectionDone(TrackFileFormat trackFileFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String IMPORT_SELECTION_DIALOG_TAG = "importSelection";
|
||||||
|
|
||||||
|
private ImportSelectionCaller caller;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Activity activity) {
|
||||||
|
super.onAttach(activity);
|
||||||
|
try {
|
||||||
|
caller = (ImportSelectionCaller) activity;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
throw new ClassCastException(
|
||||||
|
activity.toString() + " must implement " + ImportSelectionCaller.class.getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
String[] choices = new String[2];
|
||||||
|
String fileTypes[] = getResources().getStringArray(R.array.file_types);
|
||||||
|
choices[0] = getString(R.string.import_selection_option, fileTypes[0]);
|
||||||
|
choices[1] = getString(R.string.import_selection_option, fileTypes[1]);
|
||||||
|
|
||||||
|
return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
|
||||||
|
.setPositiveButton(R.string.generic_ok, new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||||
|
caller.onImportSelectionDone(position == 0 ? TrackFileFormat.GPX : TrackFileFormat.KML);
|
||||||
|
}
|
||||||
|
}).setSingleChoiceItems(choices, 0, null).setTitle(R.string.import_selection_title)
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user