Use a dialog fragment to select the import all type

This commit is contained in:
Jimmy Shih
2013-04-30 15:01:13 -07:00
parent b593fa3550
commit b880b731b4
4 changed files with 111 additions and 43 deletions
@@ -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.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.io.file.ImportActivity;
import com.google.android.apps.mytracks.io.file.SaveActivity;
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
@@ -93,7 +95,7 @@ import java.util.Locale;
* @author Leif Hendrik Wilden
*/
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 START_GPS_KEY = "start_gps_key";
@@ -536,11 +538,6 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.track_list, menu);
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
menu.findItem(R.id.track_list_save_all_gpx)
.setTitle(getString(R.string.menu_save_format, fileTypes[0]));
@@ -588,12 +585,10 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
handleStartGps();
updateMenuItems(recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
return true;
case R.id.track_list_import_all_gpx:
startImportActivity(TrackFileFormat.GPX);
return true;
case R.id.track_list_import_all_kml:
startImportActivity(TrackFileFormat.KML);
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);
return true;
@@ -672,6 +667,16 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
// 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.
*/
@@ -785,20 +790,6 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
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.
*
@@ -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();
}
}