2011-03-31 21:17:47 -04:00
|
|
|
package com.fsck.k9.activity;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
|
|
|
public class ConfirmationDialog {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a customized confirmation dialog ({@link AlertDialog}).
|
|
|
|
*
|
|
|
|
* @param activity The activity this dialog is created for.
|
|
|
|
* @param dialogId The id that was used with {@link Activity#showDialog(int)}
|
|
|
|
* @param title The resource id of the text to display in the dialog title
|
|
|
|
* @param message The text to display in the main dialog area
|
|
|
|
* @param confirmButton The resource id of the text to display in the confirm button
|
|
|
|
* @param cancelButton The resource id of the text to display in the cancel button
|
|
|
|
* @param action The action to perform if the user presses the confirm button
|
|
|
|
* @return A confirmation dialog with the supplied arguments
|
|
|
|
*/
|
|
|
|
public static Dialog create(final Activity activity, final int dialogId, final int title,
|
2011-04-12 08:16:22 -04:00
|
|
|
final String message, final int confirmButton, final int cancelButton,
|
|
|
|
final Runnable action) {
|
2011-06-06 19:25:38 -04:00
|
|
|
return create(activity, dialogId, title, message, confirmButton, cancelButton,
|
2011-06-13 19:49:06 -04:00
|
|
|
action, null);
|
2011-06-06 19:25:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a customized confirmation dialog ({@link AlertDialog}).
|
|
|
|
*
|
|
|
|
* @param activity The activity this dialog is created for.
|
|
|
|
* @param dialogId The id that was used with {@link Activity#showDialog(int)}
|
|
|
|
* @param title The resource id of the text to display in the dialog title
|
|
|
|
* @param message The text to display in the main dialog area
|
|
|
|
* @param confirmButton The resource id of the text to display in the confirm button
|
|
|
|
* @param cancelButton The resource id of the text to display in the cancel button
|
|
|
|
* @param action The action to perform if the user presses the confirm button
|
|
|
|
* @param negativeAction The action to perform if the user presses the cancel button. Can be {@code null}.
|
|
|
|
* @return A confirmation dialog with the supplied arguments
|
|
|
|
*/
|
|
|
|
public static Dialog create(final Activity activity, final int dialogId, final int title,
|
|
|
|
final String message, final int confirmButton, final int cancelButton,
|
|
|
|
final Runnable action, final Runnable negativeAction) {
|
2011-03-31 21:17:47 -04:00
|
|
|
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
builder.setTitle(title);
|
|
|
|
builder.setMessage(message);
|
|
|
|
builder.setPositiveButton(confirmButton,
|
2011-04-12 08:16:22 -04:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
activity.dismissDialog(dialogId);
|
|
|
|
action.run();
|
|
|
|
}
|
|
|
|
});
|
2011-03-31 21:17:47 -04:00
|
|
|
builder.setNegativeButton(cancelButton,
|
2011-04-12 08:16:22 -04:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
activity.dismissDialog(dialogId);
|
2011-06-06 19:25:38 -04:00
|
|
|
if (negativeAction != null) {
|
|
|
|
negativeAction.run();
|
|
|
|
}
|
2011-04-12 08:16:22 -04:00
|
|
|
}
|
|
|
|
});
|
2011-03-31 21:17:47 -04:00
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a customized confirmation dialog ({@link AlertDialog}).
|
|
|
|
*
|
|
|
|
* @param activity The activity this dialog is created for.
|
|
|
|
* @param dialogId The id that was used with {@link Activity#showDialog(int)}
|
|
|
|
* @param title The resource id of the text to display in the dialog title
|
|
|
|
* @param message The resource id of text to display in the main dialog area
|
|
|
|
* @param confirmButton The resource id of the text to display in the confirm button
|
|
|
|
* @param cancelButton The resource id of the text to display in the cancel button
|
|
|
|
* @param action The action to perform if the user presses the confirm button
|
|
|
|
* @return A confirmation dialog with the supplied arguments
|
2011-06-06 19:25:38 -04:00
|
|
|
* @see #create(Activity,int,int,String,int,int,Runnable, Runnable)
|
2011-03-31 21:17:47 -04:00
|
|
|
*/
|
|
|
|
public static Dialog create(final Activity activity, final int dialogId, final int title,
|
2011-04-12 08:16:22 -04:00
|
|
|
final int message, final int confirmButton, final int cancelButton,
|
|
|
|
final Runnable action) {
|
2011-03-31 21:17:47 -04:00
|
|
|
|
|
|
|
return create(activity, dialogId, title, activity.getString(message), confirmButton,
|
2011-06-06 19:25:38 -04:00
|
|
|
cancelButton, action, null);
|
2011-03-31 21:17:47 -04:00
|
|
|
}
|
|
|
|
}
|