Use FileTypeDialogFragment to select a file type for import all, save all, and save

This commit is contained in:
Jimmy Shih
2013-04-30 16:14:24 -07:00
parent b880b731b4
commit 8c26cb2aa3
6 changed files with 127 additions and 153 deletions
-14
View File
@@ -51,20 +51,6 @@ limitations under the License.
android:id="@+id/track_detail_save"
android:orderInCategory="7"
android:title="@string/menu_save">
<menu>
<item
android:id="@+id/track_detail_save_gpx"
android:title=""/>
<item
android:id="@+id/track_detail_save_kml"
android:title=""/>
<item
android:id="@+id/track_detail_save_csv"
android:title=""/>
<item
android:id="@+id/track_detail_save_tcx"
android:title=""/>
</menu>
</item>
<item
android:icon="@drawable/menu_edit"
-14
View File
@@ -35,20 +35,6 @@ limitations under the License.
android:icon="@drawable/menu_save"
android:id="@+id/track_list_save_all"
android:title="@string/menu_save_all">
<menu>
<item
android:id="@+id/track_list_save_all_gpx"
android:title=""/>
<item
android:id="@+id/track_list_save_all_kml"
android:title=""/>
<item
android:id="@+id/track_list_save_all_csv"
android:title=""/>
<item
android:id="@+id/track_list_save_all_tcx"
android:title=""/>
</menu>
</item>
<item
android:icon="@drawable/menu_delete"
+35 -25
View File
@@ -710,7 +710,7 @@ limitations under the License.
</string>
<string name="generic_no"
translation_description="The text on a button to say no.">
No
No
</string>
<string name="generic_ok"
translation_description="The text on a button to say ok.">
@@ -738,9 +738,9 @@ limitations under the License.
</string>
<string name="generic_yes"
translation_description="The text on a button to say yes.">
Yes
Yes
</string>
<!-- Gps -->
<string name="gps_google_location_settings"
translation_description="In Android, the Google location settings to modify location settings
@@ -845,14 +845,14 @@ limitations under the License.
Importing from %1$s&#8230;
</string>
<string name="import_selection_option"
translation_description="When importing from external storage, the option to import all
translation_description="When importing from external storage, the option to import all the
files of a certain file format.
%1$s: file format. E.g., 'GPX'.">
%1$s: file format. 'GPX', 'KML', 'CSV', or 'TCX'.">
Import all %1$s
</string>
<string name="import_selection_title"
translation_description="The dialog title when importing from external storage.">
translation_description="The dialog title to import from external storage.">
Import from external storage
</string>
<string name="import_success"
@@ -877,7 +877,7 @@ limitations under the License.
translation_description="Option to select all the items in a list.">
Select all
</string>
<!-- Maps List -->
<string name="maps_list_error"
translation_description="When sending a track to an existing Google Map, the text on the Maps'
@@ -1024,7 +1024,7 @@ limitations under the License.
Help
</string>
<string name="menu_import_all"
translation_description="In the menu, to import all tracks from the external storage.
translation_description="In the menu, to import all the tracks from the external storage.
Character limit: ~20 (1 line)">
Import all
@@ -1078,21 +1078,13 @@ limitations under the License.
translation_description="In the menu, to save a track to the external storage.
Character limit: ~20 (1 line)">
Save to external storage
Save
</string>
<string name="menu_save_all"
translation_description="In the menu, to save all the tracks to the external storage.
Character limit: ~20 (1 line)">
Save all to external storage
</string>
<string name="menu_save_format"
translation_description="Under the save to external storage menu option, the option to save a
track as a certain file format.
%1$s: file format. 'GPX', 'KML', 'CSV', or 'TCX'.
Character limit: ~20 (1 line)">
Save as %1$s
Save all
</string>
<string name="menu_search"
translation_description="In the menu, to start a textual search for tracks or markers.
@@ -1242,6 +1234,13 @@ limitations under the License.
</string>
<!-- Save -->
<string name="save_all_selection_option"
translation_description="When saving to external storage, the option to save all the tracks as a
certain file format.
%1$s: file format. 'GPX', 'KML', 'CSV', or 'TCX'.">
Save all as %1$s
</string>
<string name="save_error"
translation_description="When saving to the external storage, the error message indicating that
only some of the tracks are saved.
@@ -1257,6 +1256,17 @@ limitations under the License.
%1$s: the directory. E.g., '/storage/sdcard0/MyTracks/gpx/'.">
Saving to %1$s&#8230;
</string>
<string name="save_selection_option"
translation_description="When saving to external storage, the option to save a track as a
certain file format.
%1$s: file format. 'GPX', 'KML', 'CSV', or 'TCX'.">
Save as %1$s
</string>
<string name="save_selection_title"
translation_description="The dialog title to save to external storage.">
Save to external storage
</string>
<string name="save_success"
translation_description="When saving to the external storage, the success message.
@@ -2050,7 +2060,7 @@ limitations under the License.
<string name="settings_sharing_share_track"
translation_description="In the 'Sharing' settings, the option to configure how to share a
track.
Character limit: ~23 (1 line)">
Share track
</string>
@@ -2062,7 +2072,7 @@ limitations under the License.
<string name="settings_sharing_share_track_file"
translation_description="In the 'Sharing' settings, the option in the 'Share track' setting to
share as a file.
%1$s: file format. E.g., 'GPX'.">
As %1$s file
</string>
@@ -2070,8 +2080,8 @@ limitations under the License.
translation_description="In the 'Sharing' settings, the option in the 'Share track' setting to
share via Google Maps url.">
Via Google Maps url
</string>
</string>
<!-- Settings Stats -->
<string name="settings_stats_coordinate"
translation_description="In the 'Stats settings, the option to show latitude and longitude.
@@ -2129,7 +2139,7 @@ limitations under the License.
</string>
<string name="share_track_file_confirm_message"
translation_description="The confirmation message when sharing a track as a file.">
This will save your track to external storage so you can share the file.
This will save your track to external storage so you can share the file.
</string>
<string name="share_track_maps_confirm_message"
translation_description="The confirmation message when sharing a track via Google Maps with
@@ -2288,8 +2298,8 @@ limitations under the License.
translation_description="When deleting multiple tracks, the confirmation message.">
The tracks and their markers will be permanently deleted from the device. If Google Drive sync
is enabled, this will also delete the tracks on Google Drive.
</string>
</string>
<!-- Track Detail -->
<string name="track_detail_chart_tab"
translation_description="In the track detail page, the title of the tab showing the chart.">
@@ -27,6 +27,8 @@ import com.google.android.apps.mytracks.fragments.ChooseUploadServiceDialogFragm
import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment;
import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment.FileTypeCaller;
import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment;
import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
import com.google.android.apps.mytracks.fragments.MyTracksMapFragment;
@@ -72,7 +74,7 @@ import java.util.Locale;
* @author Rodrigo Damazio
*/
public class TrackDetailActivity extends AbstractSendToGoogleActivity
implements ChooseUploadServiceCaller, DeleteTrackCaller {
implements ChooseUploadServiceCaller, DeleteTrackCaller, FileTypeCaller {
public static final String EXTRA_TRACK_ID = "track_id";
public static final String EXTRA_MARKER_ID = "marker_id";
@@ -301,15 +303,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.track_detail, menu);
String fileTypes[] = getResources().getStringArray(R.array.file_types);
menu.findItem(R.id.track_detail_save_gpx)
.setTitle(getString(R.string.menu_save_format, fileTypes[0]));
menu.findItem(R.id.track_detail_save_kml)
.setTitle(getString(R.string.menu_save_format, fileTypes[1]));
menu.findItem(R.id.track_detail_save_csv)
.setTitle(getString(R.string.menu_save_format, fileTypes[2]));
menu.findItem(R.id.track_detail_save_tcx)
.setTitle(getString(R.string.menu_save_format, fileTypes[3]));
Track track = myTracksProviderUtils.getTrack(trackId);
boolean sharedWithMe = track != null ? track.isSharedWithMe() : true;
@@ -387,18 +380,11 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
getSupportFragmentManager(),
ChooseUploadServiceDialogFragment.CHOOSE_UPLOAD_SERVICE_DIALOG_TAG);
return true;
case R.id.track_detail_save_gpx:
startSaveActivity(TrackFileFormat.GPX);
return true;
case R.id.track_detail_save_kml:
startSaveActivity(TrackFileFormat.KML);
return true;
case R.id.track_detail_save_csv:
startSaveActivity(TrackFileFormat.CSV);
return true;
case R.id.track_detail_save_tcx:
startSaveActivity(TrackFileFormat.TCX);
return true;
case R.id.track_detail_save:
FileTypeDialogFragment.newInstance(R.id.track_detail_save, R.string.save_selection_title,
R.string.save_selection_option, 4)
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
return true;
case R.id.track_detail_edit:
intent = IntentUtils.newIntent(this, TrackEditActivity.class)
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId);
@@ -494,6 +480,21 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
}
});
}
@Override
public void onFileTypeDone(int menuId, TrackFileFormat trackFileFormat) {
switch (menuId) {
case R.id.track_detail_save:
AnalyticsUtils.sendPageViews(
this, "/action/save_" + trackFileFormat.name().toLowerCase(Locale.US));
Intent intent = IntentUtils.newIntent(this, SaveActivity.class)
.putExtra(SaveActivity.EXTRA_TRACK_ID, trackId)
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
startActivity(intent);
break;
default:
}
}
/**
* Gets the {@link TrackDataHub}.
@@ -590,20 +591,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
setTitle(title);
}
/**
* Starts the {@link SaveActivity} to save a track.
*
* @param trackFileFormat the track file format
*/
private void startSaveActivity(TrackFileFormat trackFileFormat) {
AnalyticsUtils.sendPageViews(
this, "/action/save_" + trackFileFormat.name().toLowerCase(Locale.US));
Intent intent = IntentUtils.newIntent(this, SaveActivity.class)
.putExtra(SaveActivity.EXTRA_TRACK_ID, trackId)
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
startActivity(intent);
}
/**
* Returns true if Google Earth app is installed.
*/
@@ -29,8 +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.EulaDialogFragment;
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.fragments.FileTypeDialogFragment;
import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment.FileTypeCaller;
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.TrackFileFormat;
@@ -95,7 +95,7 @@ import java.util.Locale;
* @author Leif Hendrik Wilden
*/
public class TrackListActivity extends AbstractSendToGoogleActivity
implements EulaCaller, EnableSyncCaller, DeleteTrackCaller, ImportSelectionCaller {
implements EulaCaller, EnableSyncCaller, DeleteTrackCaller, FileTypeCaller {
private static final String TAG = TrackListActivity.class.getSimpleName();
private static final String START_GPS_KEY = "start_gps_key";
@@ -537,17 +537,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.track_list, menu);
String fileTypes[] = getResources().getStringArray(R.array.file_types);
// Save all submenu titles
menu.findItem(R.id.track_list_save_all_gpx)
.setTitle(getString(R.string.menu_save_format, fileTypes[0]));
menu.findItem(R.id.track_list_save_all_kml)
.setTitle(getString(R.string.menu_save_format, fileTypes[1]));
menu.findItem(R.id.track_list_save_all_csv)
.setTitle(getString(R.string.menu_save_format, fileTypes[2]));
menu.findItem(R.id.track_list_save_all_tcx)
.setTitle(getString(R.string.menu_save_format, fileTypes[3]));
searchMenuItem = menu.findItem(R.id.track_list_search);
startGpsMenuItem = menu.findItem(R.id.track_list_start_gps);
importAllMenuItem = menu.findItem(R.id.track_list_import_all);
@@ -586,20 +576,14 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
updateMenuItems(recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
return true;
case R.id.track_list_import_all:
new ImportSelectionDialogFragment().show(
getSupportFragmentManager(), ImportSelectionDialogFragment.IMPORT_SELECTION_DIALOG_TAG);
return true;
case R.id.track_list_save_all_gpx:
startSaveActivity(TrackFileFormat.GPX);
FileTypeDialogFragment.newInstance(R.id.track_list_import_all,
R.string.import_selection_title, R.string.import_selection_option, 2)
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
return true;
case R.id.track_list_save_all_kml:
startSaveActivity(TrackFileFormat.KML);
return true;
case R.id.track_list_save_all_csv:
startSaveActivity(TrackFileFormat.CSV);
return true;
case R.id.track_list_save_all_tcx:
startSaveActivity(TrackFileFormat.TCX);
case R.id.track_list_save_all:
FileTypeDialogFragment.newInstance(R.id.track_list_save_all, R.string.save_selection_title,
R.string.save_all_selection_option, 4)
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
return true;
case R.id.track_list_delete_all:
DeleteTrackDialogFragment.newInstance(true, new long[] {})
@@ -666,15 +650,28 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
public void onDeleteTrackDone() {
// 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);
public void onFileTypeDone(int menuId, TrackFileFormat trackFileFormat) {
Intent intent;
switch (menuId) {
case R.id.track_list_save_all:
AnalyticsUtils.sendPageViews(
this, "/action/save_all_" + trackFileFormat.name().toLowerCase(Locale.US));
intent = IntentUtils.newIntent(this, SaveActivity.class)
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
startActivity(intent);
break;
case R.id.track_list_import_all:
AnalyticsUtils.sendPageViews(
this, "/action/import_all_" + trackFileFormat.name().toLowerCase(Locale.US));
intent = IntentUtils.newIntent(this, ImportActivity.class)
.putExtra(ImportActivity.EXTRA_IMPORT_ALL, true)
.putExtra(ImportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
startActivity(intent);
break;
default:
}
}
/**
@@ -790,19 +787,6 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
bindChangedCallback.run();
}
/**
* Starts the {@link SaveActivity} to save all tracks.
*
* @param trackFileFormat the track file format
*/
private void startSaveActivity(TrackFileFormat trackFileFormat) {
AnalyticsUtils.sendPageViews(
this, "/action/save_all_" + trackFileFormat.name().toLowerCase(Locale.US));
Intent intent = IntentUtils.newIntent(this, SaveActivity.class)
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
startActivity(intent);
}
/**
* Handles a context item selection.
*
@@ -28,55 +28,76 @@ import android.os.Bundle;
import android.support.v4.app.DialogFragment;
/**
* A DialogFragment to select an import type, gpx, kml, etc.
* A DialogFragment to select a file type, gpx, kml, etc.
*
* @author Jimmy Shih
*/
public class ImportSelectionDialogFragment extends DialogFragment {
public class FileTypeDialogFragment extends DialogFragment {
/**
* Interface for caller of this dialog fragment.
*
* @author Jimmy Shih
*/
public interface ImportSelectionCaller {
public interface FileTypeCaller {
/**
* Called when import selection is done.
* Called when file type selection is done.
*/
public void onImportSelectionDone(TrackFileFormat trackFileFormat);
public void onFileTypeDone(int menuId, TrackFileFormat trackFileFormat);
}
public static final String IMPORT_SELECTION_DIALOG_TAG = "importSelection";
public static final String FILE_TYPE_DIALOG_TAG = "fileType";
private ImportSelectionCaller caller;
private static final String KEY_MENU_ID = "menuId";
private static final String KEY_TITLE_ID = "titleId";
private static final String KEY_OPTION_ID = "optionId";
private static final String KEY_SIZE = "size";
public static FileTypeDialogFragment newInstance(
int menuId, int titleId, int optionId, int size) {
Bundle bundle = new Bundle();
bundle.putInt(KEY_MENU_ID, menuId);
bundle.putInt(KEY_TITLE_ID, titleId);
bundle.putInt(KEY_OPTION_ID, optionId);
bundle.putInt(KEY_SIZE, size);
FileTypeDialogFragment fileTypeDialogFragment = new FileTypeDialogFragment();
fileTypeDialogFragment.setArguments(bundle);
return fileTypeDialogFragment;
}
private FileTypeCaller caller;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
caller = (ImportSelectionCaller) activity;
caller = (FileTypeCaller) activity;
} catch (ClassCastException e) {
throw new ClassCastException(
activity.toString() + " must implement " + ImportSelectionCaller.class.getSimpleName());
activity.toString() + " must implement " + FileTypeCaller.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]);
int size = getArguments().getInt(KEY_SIZE);
int optionId = getArguments().getInt(KEY_OPTION_ID);
final int titleId = getArguments().getInt(KEY_TITLE_ID);
final int menuId = getArguments().getInt(KEY_MENU_ID);
String[] choices = new String[size];
for (int i = 0; i < choices.length; i++) {
choices[i] = getString(optionId, fileTypes[i]);
}
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);
caller.onFileTypeDone(menuId, TrackFileFormat.values()[position]);
}
}).setSingleChoiceItems(choices, 0, null).setTitle(R.string.import_selection_title)
.create();
}).setSingleChoiceItems(choices, 0, null).setTitle(titleId).create();
}
}