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:id="@+id/track_detail_save"
android:orderInCategory="7" android:orderInCategory="7"
android:title="@string/menu_save"> 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>
<item <item
android:icon="@drawable/menu_edit" android:icon="@drawable/menu_edit"
-14
View File
@@ -35,20 +35,6 @@ limitations under the License.
android:icon="@drawable/menu_save" android:icon="@drawable/menu_save"
android:id="@+id/track_list_save_all" android:id="@+id/track_list_save_all"
android:title="@string/menu_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>
<item <item
android:icon="@drawable/menu_delete" android:icon="@drawable/menu_delete"
+35 -25
View File
@@ -710,7 +710,7 @@ limitations under the License.
</string> </string>
<string name="generic_no" <string name="generic_no"
translation_description="The text on a button to say no."> translation_description="The text on a button to say no.">
No No
</string> </string>
<string name="generic_ok" <string name="generic_ok"
translation_description="The text on a button to say ok."> translation_description="The text on a button to say ok.">
@@ -738,9 +738,9 @@ limitations under the License.
</string> </string>
<string name="generic_yes" <string name="generic_yes"
translation_description="The text on a button to say yes."> translation_description="The text on a button to say yes.">
Yes Yes
</string> </string>
<!-- Gps --> <!-- Gps -->
<string name="gps_google_location_settings" <string name="gps_google_location_settings"
translation_description="In Android, the Google location settings to modify 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; Importing from %1$s&#8230;
</string> </string>
<string name="import_selection_option" <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. 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 Import all %1$s
</string> </string>
<string name="import_selection_title" <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 Import from external storage
</string> </string>
<string name="import_success" <string name="import_success"
@@ -877,7 +877,7 @@ limitations under the License.
translation_description="Option to select all the items in a list."> translation_description="Option to select all the items in a list.">
Select all Select all
</string> </string>
<!-- Maps List --> <!-- Maps List -->
<string name="maps_list_error" <string name="maps_list_error"
translation_description="When sending a track to an existing Google Map, the text on the Maps' 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 Help
</string> </string>
<string name="menu_import_all" <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)"> Character limit: ~20 (1 line)">
Import all Import all
@@ -1078,21 +1078,13 @@ limitations under the License.
translation_description="In the menu, to save a track to the external storage. translation_description="In the menu, to save a track to the external storage.
Character limit: ~20 (1 line)"> Character limit: ~20 (1 line)">
Save to external storage Save
</string> </string>
<string name="menu_save_all" <string name="menu_save_all"
translation_description="In the menu, to save all the tracks to the external storage. translation_description="In the menu, to save all the tracks to the external storage.
Character limit: ~20 (1 line)"> Character limit: ~20 (1 line)">
Save all to external storage Save all
</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
</string> </string>
<string name="menu_search" <string name="menu_search"
translation_description="In the menu, to start a textual search for tracks or markers. translation_description="In the menu, to start a textual search for tracks or markers.
@@ -1242,6 +1234,13 @@ limitations under the License.
</string> </string>
<!-- Save --> <!-- 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" <string name="save_error"
translation_description="When saving to the external storage, the error message indicating that translation_description="When saving to the external storage, the error message indicating that
only some of the tracks are saved. 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/'."> %1$s: the directory. E.g., '/storage/sdcard0/MyTracks/gpx/'.">
Saving to %1$s&#8230; Saving to %1$s&#8230;
</string> </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" <string name="save_success"
translation_description="When saving to the external storage, the success message. 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" <string name="settings_sharing_share_track"
translation_description="In the 'Sharing' settings, the option to configure how to share a translation_description="In the 'Sharing' settings, the option to configure how to share a
track. track.
Character limit: ~23 (1 line)"> Character limit: ~23 (1 line)">
Share track Share track
</string> </string>
@@ -2062,7 +2072,7 @@ limitations under the License.
<string name="settings_sharing_share_track_file" <string name="settings_sharing_share_track_file"
translation_description="In the 'Sharing' settings, the option in the 'Share track' setting to translation_description="In the 'Sharing' settings, the option in the 'Share track' setting to
share as a file. share as a file.
%1$s: file format. E.g., 'GPX'."> %1$s: file format. E.g., 'GPX'.">
As %1$s file As %1$s file
</string> </string>
@@ -2070,8 +2080,8 @@ limitations under the License.
translation_description="In the 'Sharing' settings, the option in the 'Share track' setting to translation_description="In the 'Sharing' settings, the option in the 'Share track' setting to
share via Google Maps url."> share via Google Maps url.">
Via Google Maps url Via Google Maps url
</string> </string>
<!-- Settings Stats --> <!-- Settings Stats -->
<string name="settings_stats_coordinate" <string name="settings_stats_coordinate"
translation_description="In the 'Stats settings, the option to show latitude and longitude. translation_description="In the 'Stats settings, the option to show latitude and longitude.
@@ -2129,7 +2139,7 @@ limitations under the License.
</string> </string>
<string name="share_track_file_confirm_message" <string name="share_track_file_confirm_message"
translation_description="The confirmation message when sharing a track as a file."> 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>
<string name="share_track_maps_confirm_message" <string name="share_track_maps_confirm_message"
translation_description="The confirmation message when sharing a track via Google Maps with 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."> 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 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. is enabled, this will also delete the tracks on Google Drive.
</string> </string>
<!-- Track Detail --> <!-- Track Detail -->
<string name="track_detail_chart_tab" <string name="track_detail_chart_tab"
translation_description="In the track detail page, the title of the tab showing the chart."> 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.ConfirmDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment; import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller; 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.FrequencyDialogFragment;
import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment; import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
import com.google.android.apps.mytracks.fragments.MyTracksMapFragment; import com.google.android.apps.mytracks.fragments.MyTracksMapFragment;
@@ -72,7 +74,7 @@ import java.util.Locale;
* @author Rodrigo Damazio * @author Rodrigo Damazio
*/ */
public class TrackDetailActivity extends AbstractSendToGoogleActivity 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_TRACK_ID = "track_id";
public static final String EXTRA_MARKER_ID = "marker_id"; public static final String EXTRA_MARKER_ID = "marker_id";
@@ -301,15 +303,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.track_detail, 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); Track track = myTracksProviderUtils.getTrack(trackId);
boolean sharedWithMe = track != null ? track.isSharedWithMe() : true; boolean sharedWithMe = track != null ? track.isSharedWithMe() : true;
@@ -387,18 +380,11 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
getSupportFragmentManager(), getSupportFragmentManager(),
ChooseUploadServiceDialogFragment.CHOOSE_UPLOAD_SERVICE_DIALOG_TAG); ChooseUploadServiceDialogFragment.CHOOSE_UPLOAD_SERVICE_DIALOG_TAG);
return true; return true;
case R.id.track_detail_save_gpx: case R.id.track_detail_save:
startSaveActivity(TrackFileFormat.GPX); FileTypeDialogFragment.newInstance(R.id.track_detail_save, R.string.save_selection_title,
return true; R.string.save_selection_option, 4)
case R.id.track_detail_save_kml: .show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
startSaveActivity(TrackFileFormat.KML); return true;
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_edit: case R.id.track_detail_edit:
intent = IntentUtils.newIntent(this, TrackEditActivity.class) intent = IntentUtils.newIntent(this, TrackEditActivity.class)
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId); .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}. * Gets the {@link TrackDataHub}.
@@ -590,20 +591,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
setTitle(title); 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. * 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.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.FileTypeDialogFragment;
import com.google.android.apps.mytracks.fragments.ImportSelectionDialogFragment.ImportSelectionCaller; 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.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;
@@ -95,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, ImportSelectionCaller { implements EulaCaller, EnableSyncCaller, DeleteTrackCaller, FileTypeCaller {
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";
@@ -537,17 +537,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
@Override @Override
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);
// 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); searchMenuItem = menu.findItem(R.id.track_list_search);
startGpsMenuItem = menu.findItem(R.id.track_list_start_gps); startGpsMenuItem = menu.findItem(R.id.track_list_start_gps);
importAllMenuItem = menu.findItem(R.id.track_list_import_all); 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); updateMenuItems(recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
return true; return true;
case R.id.track_list_import_all: case R.id.track_list_import_all:
new ImportSelectionDialogFragment().show( FileTypeDialogFragment.newInstance(R.id.track_list_import_all,
getSupportFragmentManager(), ImportSelectionDialogFragment.IMPORT_SELECTION_DIALOG_TAG); R.string.import_selection_title, R.string.import_selection_option, 2)
return true; .show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
case R.id.track_list_save_all_gpx:
startSaveActivity(TrackFileFormat.GPX);
return true; return true;
case R.id.track_list_save_all_kml: case R.id.track_list_save_all:
startSaveActivity(TrackFileFormat.KML); FileTypeDialogFragment.newInstance(R.id.track_list_save_all, R.string.save_selection_title,
return true; R.string.save_all_selection_option, 4)
case R.id.track_list_save_all_csv: .show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
startSaveActivity(TrackFileFormat.CSV);
return true;
case R.id.track_list_save_all_tcx:
startSaveActivity(TrackFileFormat.TCX);
return true; return true;
case R.id.track_list_delete_all: case R.id.track_list_delete_all:
DeleteTrackDialogFragment.newInstance(true, new long[] {}) DeleteTrackDialogFragment.newInstance(true, new long[] {})
@@ -666,15 +650,28 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
public void onDeleteTrackDone() { public void onDeleteTrackDone() {
// Do nothing // Do nothing
} }
@Override @Override
public void onImportSelectionDone(TrackFileFormat trackFileFormat) { public void onFileTypeDone(int menuId, TrackFileFormat trackFileFormat) {
AnalyticsUtils.sendPageViews( Intent intent;
this, "/action/import_all_" + trackFileFormat.name().toLowerCase(Locale.US)); switch (menuId) {
Intent intent = IntentUtils.newIntent(this, ImportActivity.class) case R.id.track_list_save_all:
.putExtra(ImportActivity.EXTRA_IMPORT_ALL, true) AnalyticsUtils.sendPageViews(
.putExtra(ImportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat); this, "/action/save_all_" + trackFileFormat.name().toLowerCase(Locale.US));
startActivity(intent); 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(); 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. * Handles a context item selection.
* *
@@ -28,55 +28,76 @@ import android.os.Bundle;
import android.support.v4.app.DialogFragment; 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 * @author Jimmy Shih
*/ */
public class ImportSelectionDialogFragment extends DialogFragment { public class FileTypeDialogFragment extends DialogFragment {
/** /**
* Interface for caller of this dialog fragment. * Interface for caller of this dialog fragment.
* *
* @author Jimmy Shih * @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 @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
try { try {
caller = (ImportSelectionCaller) activity; caller = (FileTypeCaller) activity;
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new ClassCastException( throw new ClassCastException(
activity.toString() + " must implement " + ImportSelectionCaller.class.getSimpleName()); activity.toString() + " must implement " + FileTypeCaller.class.getSimpleName());
} }
} }
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
String[] choices = new String[2];
String fileTypes[] = getResources().getStringArray(R.array.file_types); String fileTypes[] = getResources().getStringArray(R.array.file_types);
choices[0] = getString(R.string.import_selection_option, fileTypes[0]); int size = getArguments().getInt(KEY_SIZE);
choices[1] = getString(R.string.import_selection_option, fileTypes[1]); 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) return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
.setPositiveButton(R.string.generic_ok, new OnClickListener() { .setPositiveButton(R.string.generic_ok, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); 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) }).setSingleChoiceItems(choices, 0, null).setTitle(titleId).create();
.create();
} }
} }