Cleanup all remaining dialogs.

- Use DialogUtils to create a spinner or a horizontal progress dialog.
- Update all progress dialog messages.
This commit is contained in:
Jimmy Shih
2012-03-21 16:04:53 -07:00
parent a8002ce13e
commit d2a245194f
15 changed files with 239 additions and 235 deletions
+25 -28
View File
@@ -664,11 +664,13 @@ limitations under the License.
indicating error."> indicating error.">
Unable to export. Unable to export.
</string> </string>
<string name="export_progress_message"
translation_description="When exporting all the tracks to the SD card, the progress message.">
Exporting all tracks...
</string>
<string name="export_success" <string name="export_success"
translation_description="When exporting all the tracks to the SD card, a toast message translation_description="When exporting all the tracks to the SD card, a toast message
indicating success. indicating success.">
Screenshot: export_success">
Export finished. Export finished.
</string> </string>
@@ -786,6 +788,10 @@ limitations under the License.
No GPX file found in %1$s. The SD card may be unreadable or the directory may not contain any No GPX file found in %1$s. The SD card may be unreadable or the directory may not contain any
GPX file. GPX file.
</string> </string>
<string name="import_progress_message"
translation_description="When importing all the tracks from the SD card, the progress message.">
Importing all tracks...
</string>
<string name="import_success" <string name="import_success"
translation_description="After importing all the tracks from the SD card, the alert message translation_description="After importing all the tracks from the SD card, the alert message
indicating success. indicating success.
@@ -803,11 +809,6 @@ limitations under the License.
'Maps' list page informing the user that his maps cannot be loaded at this time."> 'Maps' list page informing the user that his maps cannot be loaded at this time.">
Your maps could not be loaded at this time. Your maps could not be loaded at this time.
</string> </string>
<string name="maps_list_loading"
translation_description="When sending a track to an existing Google Map, the progress dialog
message informing the user that his maps are being loaded.">
Loading your Google Maps.
</string>
<string name="maps_list_no_maps" <string name="maps_list_no_maps"
translation_description="When sending a track to an existing Google Map, the text on the translation_description="When sending a track to an existing Google Map, the text on the
'Maps' list page informing the user that he doesn't have any maps."> 'Maps' list page informing the user that he doesn't have any maps.">
@@ -818,6 +819,11 @@ limitations under the License.
'Maps' list page asking the user to pick one of his maps."> 'Maps' list page asking the user to pick one of his maps.">
Pick a map: Pick a map:
</string> </string>
<string name="maps_list_progress_message"
translation_description="When sending a track to an existing Google Map, the progress message
informing the user that his maps are being loaded.">
Loading your Google Maps...
</string>
<string name="maps_list_public_label" <string name="maps_list_public_label"
translation_description="When sending a track to an existing Google Map, in the 'Maps' translation_description="When sending a track to an existing Google Map, in the 'Maps'
list page, the label next to the maps that are public, as opposed to being unlisted."> list page, the label next to the maps that are public, as opposed to being unlisted.">
@@ -1182,12 +1188,9 @@ limitations under the License.
file."> file.">
Unable to write to a file. Unable to write to a file.
</string> </string>
<string name="sd_card_progress_write_file" <string name="sd_card_progress_message"
translation_description="When writing to the SD card, the progress dialog message indicating translation_description="When saving a track to the SD card, the progress message.">
that it may take a while. Saving to the SD card...
Screenshot: sd_card_progress_write_file.png">
Exporting a track to the SD card. This may take a while.
</string> </string>
<string name="sd_card_success_read_file" <string name="sd_card_success_read_file"
translation_description="When reading from the SD card, the success message when finish reading translation_description="When reading from the SD card, the success message when finish reading
@@ -1297,12 +1300,11 @@ limitations under the License.
not selected any Google service and no data is sent."> not selected any Google service and no data is sent.">
You did not select any service. No data is sent. You did not select any service. No data is sent.
</string> </string>
<string name="send_google_progress_title" <string name="send_google_progress_message"
translation_description="When sending a track to a Google service, the title on the progress translation_description="When sending a track to a Google service, the progress message.
dialog.
%1$s: service name. 'Google Maps', 'Google Fusion Tables', or 'Google Docs'."> %1$s: service name. 'Google Maps', 'Google Fusion Tables', or 'Google Docs'.">
Sending to %1$s. Please wait... Sending to %1$s...
</string> </string>
<string name="send_google_result_share_url" <string name="send_google_result_share_url"
translation_description="When sending a track to Google, in the result dialog, the button on translation_description="When sending a track to Google, in the result dialog, the button on
@@ -1456,11 +1458,8 @@ limitations under the License.
</string> </string>
<string name="settings_backup_now_progress_message" <string name="settings_backup_now_progress_message"
translation_description="In the 'Backup' settings, after pressing the 'Backup now' option, the translation_description="In the 'Backup' settings, after pressing the 'Backup now' option, the
progress dialog telling the user that it is writing all tracks and settings and that it may progress message telling the user that it is writing all tracks and settings to the SD card.">
take a while. Writing all tracks and settings...
Screenshot: settings_backup_now_progress_message.png">
Writing all tracks and settings to the SD card. This may take a while...
</string> </string>
<string name="settings_backup_now_summary" <string name="settings_backup_now_summary"
translation_description="In the 'Backup' settings, under the 'SD card' section, the translation_description="In the 'Backup' settings, under the 'SD card' section, the
@@ -1495,11 +1494,9 @@ limitations under the License.
</string> </string>
<string name="settings_backup_restore_progress_message" <string name="settings_backup_restore_progress_message"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the
message on the progress dialog indicating that My Tracks is reading all tracks and settings progress message informing that My Tracks is reading all tracks and settings from the backup
from the backup on the SD card and that it may take a while. on the SD card.">
Reading all tracks and settings...
Screenshot: settings_backup_restore_progress.png">
Reading all tracks and settings from the SD card. This may take a while...
</string> </string>
<string name="settings_backup_restore_select_title" <string name="settings_backup_restore_select_title"
translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the translation_description="In the 'Backup' settings, after pressing the 'Restore now' option, the
@@ -16,6 +16,7 @@
package com.google.android.apps.mytracks; package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat; import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.app.Activity; import android.app.Activity;
@@ -67,19 +68,14 @@ public class ExportActivity extends Activity {
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case DIALOG_PROGRESS_ID: case DIALOG_PROGRESS_ID:
progressDialog = new ProgressDialog(this); progressDialog = DialogUtils.createHorizontalProgressDialog(this,
progressDialog.setCancelable(true); getString(R.string.export_progress_message), new DialogInterface.OnCancelListener() {
progressDialog.setIcon(android.R.drawable.ic_dialog_info); @Override
progressDialog.setIndeterminate(true); public void onCancel(DialogInterface dialog) {
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { exportAsyncTask.cancel(true);
@Override finish();
public void onCancel(DialogInterface dialog) { }
exportAsyncTask.cancel(true); });
finish();
}
});
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.track_list_export_all);
return progressDialog; return progressDialog;
default: default:
return null; return null;
@@ -17,6 +17,7 @@
package com.google.android.apps.mytracks; package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.FileUtils; import com.google.android.apps.mytracks.util.FileUtils;
import com.google.android.apps.mytracks.util.UriUtils; import com.google.android.apps.mytracks.util.UriUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
@@ -110,19 +111,14 @@ public class ImportActivity extends Activity {
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case DIALOG_PROGRESS_ID: case DIALOG_PROGRESS_ID:
progressDialog = new ProgressDialog(this); progressDialog = DialogUtils.createHorizontalProgressDialog(this,
progressDialog.setCancelable(true); getString(R.string.import_progress_message), new DialogInterface.OnCancelListener() {
progressDialog.setIcon(android.R.drawable.ic_dialog_info); @Override
progressDialog.setIndeterminate(true); public void onCancel(DialogInterface dialog) {
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { importAsyncTask.cancel(true);
@Override finish();
public void onCancel(DialogInterface dialog) { }
importAsyncTask.cancel(true); });
finish();
}
});
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.track_list_import_all);
return progressDialog; return progressDialog;
case DIALOG_RESULT_ID: case DIALOG_RESULT_ID:
String message; String message;
@@ -250,7 +250,7 @@ public class MapActivity extends com.google.android.maps.MapActivity
return PlayTrackUtils.createInstallEarthDialog(this); return PlayTrackUtils.createInstallEarthDialog(this);
case DIALOG_DELETE_CURRENT_ID: case DIALOG_DELETE_CURRENT_ID:
return DialogUtils.createConfirmationDialog(this, return DialogUtils.createConfirmationDialog(this,
R.string.track_list_delete_track_confirm_message, getString(R.string.track_list_delete_track_confirm_message),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@@ -178,15 +178,16 @@ public class SettingsActivity extends PreferenceActivity {
switch (id) { switch (id) {
case DIALOG_CONFIRM_RESET_ID: case DIALOG_CONFIRM_RESET_ID:
return DialogUtils.createConfirmationDialog( return DialogUtils.createConfirmationDialog(
this, R.string.settings_reset_confirm_message, new OnClickListener() { this, getString(R.string.settings_reset_confirm_message), new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int button) { public void onClick(DialogInterface dialog, int button) {
onResetPreferencesConfirmed(); onResetPreferencesConfirmed();
} }
}); });
case DIALOG_CONFIRM_ACCESS_ID: case DIALOG_CONFIRM_ACCESS_ID:
return DialogUtils.createConfirmationDialog( return DialogUtils.createConfirmationDialog(this,
this, R.string.settings_sharing_allow_access_confirm_message, new OnClickListener() { getString(R.string.settings_sharing_allow_access_confirm_message),
new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int button) { public void onClick(DialogInterface dialog, int button) {
CheckBoxPreference pref = (CheckBoxPreference) findPreference( CheckBoxPreference pref = (CheckBoxPreference) findPreference(
@@ -196,7 +197,7 @@ public class SettingsActivity extends PreferenceActivity {
}); });
case DIALOG_CONFIRM_RESTORE_ID: case DIALOG_CONFIRM_RESTORE_ID:
return DialogUtils.createConfirmationDialog( return DialogUtils.createConfirmationDialog(
this, R.string.settings_backup_restore_confirm_message, new OnClickListener() { this, getString(R.string.settings_backup_restore_confirm_message), new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(SettingsActivity.this, RestoreChooserActivity.class)); startActivity(new Intent(SettingsActivity.this, RestoreChooserActivity.class));
@@ -354,7 +354,8 @@ public class TrackList extends ListActivity
.create(); .create();
case DIALOG_DELETE_ALL_ID: case DIALOG_DELETE_ALL_ID:
return DialogUtils.createConfirmationDialog(this, return DialogUtils.createConfirmationDialog(this,
R.string.track_list_delete_all_confirm_message, new DialogInterface.OnClickListener() { getString(R.string.track_list_delete_all_confirm_message),
new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
MyTracksProviderUtils.Factory.get(TrackList.this).deleteAllTracks(); MyTracksProviderUtils.Factory.get(TrackList.this).deleteAllTracks();
@@ -368,7 +369,8 @@ public class TrackList extends ListActivity
}); });
case DIALOG_DELETE_CURRENT_ID: case DIALOG_DELETE_CURRENT_ID:
return DialogUtils.createConfirmationDialog(this, return DialogUtils.createConfirmationDialog(this,
R.string.track_list_delete_track_confirm_message, new DialogInterface.OnClickListener() { getString(R.string.track_list_delete_track_confirm_message),
new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
MyTracksProviderUtils.Factory.get(TrackList.this).deleteTrack(trackId); MyTracksProviderUtils.Factory.get(TrackList.this).deleteTrack(trackId);
@@ -206,7 +206,7 @@ public class WaypointsList extends ListActivity implements View.OnClickListener
switch (id) { switch (id) {
case DIALOG_DELETE_CURRENT_ID: case DIALOG_DELETE_CURRENT_ID:
return DialogUtils.createConfirmationDialog(this, return DialogUtils.createConfirmationDialog(this,
R.string.marker_list_delete_marker_confirm_message, getString(R.string.marker_list_delete_marker_confirm_message),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@@ -16,11 +16,11 @@
package com.google.android.apps.mytracks.io.backup; package com.google.android.apps.mytracks.io.backup;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast; import android.widget.Toast;
@@ -35,7 +35,6 @@ public class BackupActivity extends Activity {
private static final int DIALOG_PROGRESS_ID = 0; private static final int DIALOG_PROGRESS_ID = 0;
private BackupAsyncTask backupAsyncTask; private BackupAsyncTask backupAsyncTask;
private ProgressDialog progressDialog;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -61,20 +60,14 @@ public class BackupActivity extends Activity {
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case DIALOG_PROGRESS_ID: case DIALOG_PROGRESS_ID:
progressDialog = new ProgressDialog(this); return DialogUtils.createSpinnerProgressDialog(this,
progressDialog.setCancelable(true); getString(R.string.settings_backup_now_progress_message),
progressDialog.setIcon(android.R.drawable.ic_dialog_info); new DialogInterface.OnCancelListener() {
progressDialog.setIndeterminate(true); @Override
progressDialog.setMessage(getString(R.string.settings_backup_now_progress_message)); public void onCancel(DialogInterface dialog) {
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { finish();
@Override }
public void onCancel(DialogInterface dialog) { });
finish();
}
});
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
return progressDialog;
default: default:
return null; return null;
} }
@@ -17,11 +17,11 @@
package com.google.android.apps.mytracks.io.backup; package com.google.android.apps.mytracks.io.backup;
import com.google.android.apps.mytracks.MyTracks; import com.google.android.apps.mytracks.MyTracks;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@@ -43,7 +43,6 @@ public class RestoreActivity extends Activity {
private static final int DIALOG_PROGRESS_ID = 0; private static final int DIALOG_PROGRESS_ID = 0;
private RestoreAsyncTask restoreAsyncTask; private RestoreAsyncTask restoreAsyncTask;
private ProgressDialog progressDialog;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -74,20 +73,14 @@ public class RestoreActivity extends Activity {
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case DIALOG_PROGRESS_ID: case DIALOG_PROGRESS_ID:
progressDialog = new ProgressDialog(this); return DialogUtils.createSpinnerProgressDialog(this,
progressDialog.setCancelable(true); getString(R.string.settings_backup_restore_progress_message),
progressDialog.setIcon(android.R.drawable.ic_dialog_info); new DialogInterface.OnCancelListener() {
progressDialog.setIndeterminate(true); @Override
progressDialog.setMessage(getString(R.string.settings_backup_restore_progress_message)); public void onCancel(DialogInterface dialog) {
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { finish();
@Override }
public void onCancel(DialogInterface dialog) { });
finish();
}
});
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
return progressDialog;
default: default:
return null; return null;
} }
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.io.file;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat; import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.FileUtils; import com.google.android.apps.mytracks.util.FileUtils;
import com.google.android.apps.mytracks.util.PlayTrackUtils; import com.google.android.apps.mytracks.util.PlayTrackUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
@@ -120,20 +121,15 @@ public class SaveActivity extends Activity {
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case DIALOG_PROGRESS_ID: case DIALOG_PROGRESS_ID:
progressDialog = new ProgressDialog(this); progressDialog = DialogUtils.createHorizontalProgressDialog(this,
progressDialog.setCancelable(true); getString(R.string.sd_card_progress_message),
progressDialog.setIcon(android.R.drawable.ic_dialog_info); new DialogInterface.OnCancelListener() {
progressDialog.setIndeterminate(true); @Override
progressDialog.setMessage(getString(R.string.sd_card_progress_write_file)); public void onCancel(DialogInterface dialog) {
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { saveAsyncTask.cancel(true);
@Override finish();
public void onCancel(DialogInterface dialog) { }
saveAsyncTask.cancel(true); });
finish();
}
});
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
return progressDialog; return progressDialog;
case DIALOG_RESULT_ID: case DIALOG_RESULT_ID:
return new AlertDialog.Builder(this) return new AlertDialog.Builder(this)
@@ -17,13 +17,13 @@ package com.google.android.apps.mytracks.io.maps;
import com.google.android.apps.mytracks.io.gdata.maps.MapsMapMetadata; import com.google.android.apps.mytracks.io.gdata.maps.MapsMapMetadata;
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest; import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
@@ -46,13 +46,11 @@ import java.util.ArrayList;
*/ */
public class ChooseMapActivity extends Activity { public class ChooseMapActivity extends Activity {
private static final int PROGRESS_DIALOG = 1; private static final int DIALOG_PROGRESS_ID = 0;
@VisibleForTesting private static final int DIALOG_ERROR_ID = 1;
static final int ERROR_DIALOG = 2;
private SendRequest sendRequest; private SendRequest sendRequest;
private ChooseMapAsyncTask asyncTask; private ChooseMapAsyncTask asyncTask;
private ProgressDialog progressDialog;
@VisibleForTesting @VisibleForTesting
ArrayAdapter<ListItem> arrayAdapter; ArrayAdapter<ListItem> arrayAdapter;
@@ -122,39 +120,34 @@ public class ChooseMapActivity extends Activity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case PROGRESS_DIALOG: case DIALOG_PROGRESS_ID:
progressDialog = new ProgressDialog(this); return DialogUtils.createSpinnerProgressDialog(
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); this, getString(R.string.maps_list_progress_message), new DialogInterface.OnCancelListener() {
progressDialog.setMessage(getString(R.string.maps_list_loading)); @Override
progressDialog.setCancelable(true); public void onCancel(DialogInterface dialog) {
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { asyncTask.cancel(true);
@Override finish();
public void onCancel(DialogInterface dialog) { }
asyncTask.cancel(true); });
finish(); case DIALOG_ERROR_ID:
} return new AlertDialog.Builder(this)
}); .setCancelable(true)
progressDialog.setIcon(android.R.drawable.ic_dialog_info); .setIcon(android.R.drawable.ic_dialog_alert)
progressDialog.setTitle(R.string.generic_progress_title); .setMessage(R.string.maps_list_error)
return progressDialog; .setOnCancelListener(new OnCancelListener() {
case ERROR_DIALOG: @Override
AlertDialog.Builder builder = new AlertDialog.Builder(this); public void onCancel(DialogInterface dialog) {
builder.setIcon(android.R.drawable.ic_dialog_alert); finish();
builder.setTitle(R.string.generic_error_title); }
builder.setMessage(R.string.maps_list_error); })
builder.setPositiveButton(R.string.generic_ok, new OnClickListener() { .setPositiveButton(R.string.generic_ok, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int arg1) { public void onClick(DialogInterface dialog, int arg1) {
finish(); finish();
} }
}); })
builder.setOnCancelListener(new OnCancelListener() { .setTitle(R.string.generic_error_title)
@Override .create();
public void onCancel(DialogInterface dialog) {
finish();
}
});
return builder.create();
default: default:
return null; return null;
} }
@@ -192,7 +185,7 @@ public class ChooseMapActivity extends Activity {
* Shows the progress dialog. * Shows the progress dialog.
*/ */
public void showProgressDialog() { public void showProgressDialog() {
showDialog(PROGRESS_DIALOG); showDialog(DIALOG_PROGRESS_ID);
} }
/** /**
@@ -200,7 +193,7 @@ public class ChooseMapActivity extends Activity {
*/ */
@VisibleForTesting @VisibleForTesting
void showErrorDialog() { void showErrorDialog() {
showDialog(ERROR_DIALOG); showDialog(DIALOG_ERROR_ID);
} }
/** /**
@@ -208,7 +201,7 @@ public class ChooseMapActivity extends Activity {
*/ */
@VisibleForTesting @VisibleForTesting
void removeProgressDialog() { void removeProgressDialog() {
removeDialog(PROGRESS_DIALOG); removeDialog(DIALOG_PROGRESS_ID);
} }
/** /**
@@ -16,6 +16,7 @@
package com.google.android.apps.mytracks.io.sendtogoogle; package com.google.android.apps.mytracks.io.sendtogoogle;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.app.Activity; import android.app.Activity;
@@ -41,7 +42,7 @@ import android.os.Bundle;
*/ */
public abstract class AbstractSendActivity extends Activity { public abstract class AbstractSendActivity extends Activity {
private static final int PROGRESS_DIALOG = 1; private static final int DIALOG_PROGRESS_ID = 0;
protected SendRequest sendRequest; protected SendRequest sendRequest;
private AbstractSendAsyncTask asyncTask; private AbstractSendAsyncTask asyncTask;
@@ -71,21 +72,16 @@ public abstract class AbstractSendActivity extends Activity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case PROGRESS_DIALOG: case DIALOG_PROGRESS_ID:
progressDialog = new ProgressDialog(this); progressDialog = DialogUtils.createHorizontalProgressDialog(this,
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); getString(R.string.send_google_progress_message, getServiceName()),
progressDialog.setIcon(android.R.drawable.ic_dialog_info); new DialogInterface.OnCancelListener() {
progressDialog.setTitle(getString(R.string.send_google_progress_title, getServiceName())); @Override
progressDialog.setMax(100); public void onCancel(DialogInterface dialog) {
progressDialog.setProgress(0); asyncTask.cancel(true);
progressDialog.setCancelable(true); startNextActivity(false, true);
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { }
@Override });
public void onCancel(DialogInterface dialog) {
asyncTask.cancel(true);
startNextActivity(false, true);
}
});
return progressDialog; return progressDialog;
default: default:
return null; return null;
@@ -105,7 +101,7 @@ public abstract class AbstractSendActivity extends Activity {
* Shows the progress dialog. * Shows the progress dialog.
*/ */
public void showProgressDialog() { public void showProgressDialog() {
showDialog(PROGRESS_DIALOG); showDialog(DIALOG_PROGRESS_ID);
} }
/** /**
@@ -115,7 +111,9 @@ public abstract class AbstractSendActivity extends Activity {
*/ */
public void setProgressDialogValue(int value) { public void setProgressDialogValue(int value) {
if (progressDialog != null) { if (progressDialog != null) {
progressDialog.setIndeterminate(false);
progressDialog.setProgress(value); progressDialog.setProgress(value);
progressDialog.setMax(100);
} }
} }
@@ -55,8 +55,8 @@ public class AccountChooserActivity extends Activity {
private static final String TAG = AccountChooserActivity.class.getSimpleName(); private static final String TAG = AccountChooserActivity.class.getSimpleName();
private static final int NO_ACCOUNT_DIALOG = 1; private static final int DIALOG_NO_ACCOUNT_ID = 0;
private static final int CHOOSE_ACCOUNT_DIALOG = 2; private static final int DIALOG_CHOOSER_ID = 1;
/** /**
* A callback after getting the permission to access a Google service. * A callback after getting the permission to access a Google service.
@@ -108,74 +108,72 @@ public class AccountChooserActivity extends Activity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (accounts.length == 0) { if (accounts.length == 0) {
showDialog(NO_ACCOUNT_DIALOG); showDialog(DIALOG_NO_ACCOUNT_ID);
} else if (accounts.length > 1 ) { } else if (accounts.length > 1 ) {
showDialog(CHOOSE_ACCOUNT_DIALOG); showDialog(DIALOG_CHOOSER_ID);
} }
} }
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder;
switch (id) { switch (id) {
case NO_ACCOUNT_DIALOG: case DIALOG_NO_ACCOUNT_ID:
builder = new AlertDialog.Builder(this); return new AlertDialog.Builder(this)
builder.setTitle(R.string.send_google_no_account_title); .setCancelable(true)
builder.setMessage(R.string.send_google_no_account_message); .setMessage(R.string.send_google_no_account_message)
builder.setCancelable(true); .setOnCancelListener(new DialogInterface.OnCancelListener() {
builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override
@Override public void onCancel(DialogInterface dialog) {
public void onCancel(DialogInterface dialog) { finish();
finish(); }
} })
}); .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
builder.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) { finish();
finish(); }
} })
}); .setTitle(R.string.send_google_no_account_title)
return builder.create(); .create();
case CHOOSE_ACCOUNT_DIALOG: case DIALOG_CHOOSER_ID:
builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.send_google_choose_account_title);
String[] choices = new String[accounts.length]; String[] choices = new String[accounts.length];
for (int i = 0; i < accounts.length; i++) { for (int i = 0; i < accounts.length; i++) {
choices[i] = accounts[i].name; choices[i] = accounts[i].name;
} }
builder.setSingleChoiceItems(choices, selectedAccountIndex, new DialogInterface.OnClickListener() { return new AlertDialog.Builder(this)
@Override .setCancelable(true)
public void onClick(DialogInterface dialog, int which) { .setNegativeButton(R.string.generic_cancel, new DialogInterface.OnClickListener() {
selectedAccountIndex = which; public void onClick(DialogInterface dialog, int which) {
} finish();
}); }
})
builder.setCancelable(true); .setOnCancelListener(new DialogInterface.OnCancelListener() {
builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override
@Override public void onCancel(DialogInterface dialog) {
public void onCancel(DialogInterface dialog) { finish();
finish(); }
} })
}); .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
builder.setNegativeButton(R.string.generic_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) { Account account = accounts[selectedAccountIndex];
finish(); SharedPreferences sharedPreferences = getSharedPreferences(
} Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
}); Editor editor = sharedPreferences.edit();
builder.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() { editor.putString(getString(R.string.preferred_account_key), account.name);
public void onClick(DialogInterface dialog, int which) { ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
Account account = accounts[selectedAccountIndex];
SharedPreferences prefs = getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
Editor editor = prefs.edit();
editor.putString(getString(R.string.preferred_account_key), account.name);
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
sendRequest.setAccount(account); sendRequest.setAccount(account);
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback); getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
} }
}); })
return builder.create(); .setSingleChoiceItems(
choices, selectedAccountIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selectedAccountIndex = which;
}
})
.setTitle(R.string.send_google_choose_account_title)
.create();
default: default:
return null; return null;
} }
@@ -43,7 +43,7 @@ import android.widget.TextView;
public class UploadResultActivity extends Activity { public class UploadResultActivity extends Activity {
private static final String TEXT_PLAIN_TYPE = "text/plain"; private static final String TEXT_PLAIN_TYPE = "text/plain";
private static final int RESULT_DIALOG = 1; private static final int DIALOG_RESULT_ID = 0;
private SendRequest sendRequest; private SendRequest sendRequest;
private Track track; private Track track;
@@ -75,13 +75,13 @@ public class UploadResultActivity extends Activity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
showDialog(RESULT_DIALOG); showDialog(DIALOG_RESULT_ID);
} }
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case RESULT_DIALOG: case DIALOG_RESULT_ID:
View view = getLayoutInflater().inflate(R.layout.upload_result, null); View view = getLayoutInflater().inflate(R.layout.upload_result, null);
LinearLayout mapsResult = (LinearLayout) view.findViewById(R.id.upload_result_maps_result); LinearLayout mapsResult = (LinearLayout) view.findViewById(R.id.upload_result_maps_result);
@@ -20,34 +20,75 @@ import com.google.android.maps.mytracks.R;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface;
/** /**
* Utilities for creating dialogs. * Utilities for creating dialogs.
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class DialogUtils { public class DialogUtils {
private DialogUtils() {} private DialogUtils() {}
/** /**
* Creates a confirmation dialog. * Creates a confirmation dialog.
* *
* @param context the context * @param context the context
* @param messageId the id of the confirmation message * @param message the confirmation message
* @param onClickListener the listener to invoke when the users clicks OK * @param onClickListener the listener to invoke when the user clicks OK
*/ */
public static Dialog createConfirmationDialog( public static Dialog createConfirmationDialog(
Context context, int messageId, OnClickListener onClickListener) { Context context, String message, DialogInterface.OnClickListener onClickListener) {
return new AlertDialog.Builder(context) return new AlertDialog.Builder(context)
.setCancelable(true) .setCancelable(true)
.setIcon(android.R.drawable.ic_dialog_alert) .setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(messageId) .setMessage(message)
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, onClickListener) .setPositiveButton(android.R.string.ok, onClickListener)
.setTitle(R.string.generic_confirm_title) .setTitle(R.string.generic_confirm_title)
.create(); .create();
} }
/**
* Creates a spinner progress dialog.
*
* @param context the context
* @param message the progress message
* @param onCancelListener the listener to invoke when the user cancels
*/
public static ProgressDialog createSpinnerProgressDialog(
Context context, String message, DialogInterface.OnCancelListener onCancelListener) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setCancelable(true);
progressDialog.setIcon(android.R.drawable.ic_dialog_info);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(message);
progressDialog.setOnCancelListener(onCancelListener);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setTitle(R.string.generic_progress_title);
return progressDialog;
}
/**
* Creates a horizontal progress dialog.
*
* @param context the context
* @param message the progress message
* @param onCancelListener the listener to invoke when the user cancels
*/
public static ProgressDialog createHorizontalProgressDialog(
Context context, String message, DialogInterface.OnCancelListener onCancelListener) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setCancelable(true);
progressDialog.setIcon(android.R.drawable.ic_dialog_info);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(message);
progressDialog.setOnCancelListener(onCancelListener);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
return progressDialog;
}
} }