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