Example usage for android.app AlertDialog.Builder dismiss

List of usage examples for android.app AlertDialog.Builder dismiss

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder dismiss.

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

From source file:Main.java

public static void yesNoMessage(final Activity activity, final String title, final String body,
        final String yesButtonLabel, final String noButtonLabel, final Runnable yesRunnable,
        final Runnable noRunnable) {
    activity.runOnUiThread(new Runnable() {
        @Override/*from  ww w  . j a  v a2  s .  c o m*/
        public void run() {

            AlertDialog.Builder dialog = new AlertDialog.Builder(activity);

            dialog.setTitle(title);
            dialog.setMessage(body);

            dialog.setPositiveButton(yesButtonLabel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if (yesRunnable != null)
                        yesRunnable.run();
                }
            });

            dialog.setNegativeButton(noButtonLabel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if (noRunnable != null)
                        noRunnable.run();
                }
            });

            dialog.create();
            dialog.show();
        }
    });
}

From source file:com.towerlabs.yildizyemek.MainActivity.java

public static void exitDialog() {

    AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.activity);
    dialog.setTitle(R.string.exit_dialog_title);
    dialog.setMessage(R.string.exit_message);
    dialog.setPositiveButton(R.string.dialog_yes, new OnClickListener() {

        @Override//w  ww.  ja v  a 2s  .  co  m
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();
            MainActivity.activity.finish();
        }
    }).setNegativeButton(R.string.dialog_cancel, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });
    dialog.create().show();

}

From source file:Main.java

public static void showOkDialog(String title, String msg, Activity act) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(act);
    if (title != null) {

        TextView dialogTitle = new TextView(act);
        dialogTitle.setText(title);/*from  ww  w .j  a  v  a 2s. com*/
        dialogTitle.setPadding(10, 10, 10, 10);
        dialogTitle.setGravity(Gravity.CENTER);
        dialogTitle.setTextColor(Color.WHITE);
        dialogTitle.setTextSize(20);
        dialog.setCustomTitle(dialogTitle);

    }
    if (msg != null) {
        dialog.setMessage(msg);
    }
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });
    AlertDialog dlg = dialog.show();
    TextView messageText = (TextView) dlg.findViewById(android.R.id.message);
    messageText.setGravity(Gravity.CENTER);

}

From source file:com.marcopolci.paperwalletvalidator.MainActivity.java

private static DialogFragment createCameraProblemdDialog() {
    return new DialogFragment() {
        @Override//from   w  w  w  . j av  a  2 s  .  c om
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
            dialog.setIcon(R.drawable.ic_menu_warning);
            dialog.setTitle(R.string.scan_camera_problem_dialog_title);
            dialog.setMessage(R.string.scan_camera_problem_dialog_message);
            dialog.setNeutralButton(R.string.button_dismiss, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.dismiss();
                }
            });
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(final DialogInterface dialog) {
                    dialog.dismiss();
                }
            });
            return dialog.create();
        }
    };
}

From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

/**
 * Show a dialog asking if unsaved edits should be ignored. Finish if so.
 *//* w  ww.  j a v  a  2  s.c  o m*/
public static void showConfirmUnsavedEditsDialog(final Activity a, final Runnable r) {
    AlertDialog.Builder dialog = new Builder(a);

    dialog.setTitle(R.string.details_have_changed);
    dialog.setMessage(R.string.you_have_unsaved_changes);

    dialog.setPositiveButton(R.string.exit, new AlertDialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (r != null) {
                r.run();
            } else {
                a.finish();
            }
        }
    });

    dialog.setNegativeButton(R.string.continue_editing, new AlertDialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    dialog.setCancelable(false);
    dialog.create().show();
}

From source file:com.towerlabs.yildizyemek.MainActivity.java

public static void scoreDialog() {

    AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.activity);
    dialog.setTitle(R.string.score_title);
    dialog.setMessage(R.string.score_text);
    dialog.setPositiveButton(R.string.dialog_ok, new OnClickListener() {

        @Override//from w ww.j av  a2  s .c  o m
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            startCounter = 0;
            Intent webActivity = new Intent(Intent.ACTION_VIEW);
            webActivity.setData(
                    Uri.parse("https://play.google.com/store/apps/details?id=com.towerlabs.yildizyemek"));
            //            webActivity.setData(Uri
            //                  .parse("market://details?id=com.towerlabs.yildizyemek"));

            activity.startActivity(webActivity);
            dialog.dismiss();
        }
    }).setNeutralButton(R.string.dialog_after, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            askStatus = true;
            startCounter = 0;
            dialog.dismiss();
        }
    }).setNegativeButton(R.string.dialog_never_ask, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            askStatus = false;
            dialog.dismiss();
        }
    });
    dialog.create().show();

}

From source file:br.com.anteros.android.persistence.backup.ImportDatabaseTask.java

@Override
protected void onPostExecute(final String errMsg) {
    if (dialog.isShowing()) {
        dialog.dismiss();
    }/*from  w  w  w .java2s .c  o  m*/

    AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
    dialog.setTitle("Aviso");
    if (errMsg.equals("OK")) {
        dialog.setMessage("Importao realizada com sucesso!");
        Toast.makeText(activity, "Importao realizada com sucesso!", Toast.LENGTH_SHORT).show();
    } else {
        dialog.setMessage("Importao falhou - " + errMsg);
        Toast.makeText(activity, "Importao falhou - " + errMsg, Toast.LENGTH_LONG).show();
    }
    dialog.setCancelable(false);
    dialog.setPositiveButton("Ok", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    AlertDialog dlg = dialog.create();
    dlg.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            activity.setResult(ImportDatabaseTask.TABLES_RECREATED);
            activity.finish();
        }
    });
    dlg.show();
}

From source file:com.laevatein.internal.misc.ui.ConfirmationDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int title = getArguments().getInt(ARGS_TITLE);
    int message = getArguments().getInt(ARGS_MESSAGE);
    AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override/*from   w ww. j av  a 2  s .com*/
                public void onClick(DialogInterface dialog, int which) {
                    mListener.onPositive();
                    dialog.dismiss();
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mListener.onNegative();
                    dialog.dismiss();
                }
            });
    return dialog.create();
}

From source file:at.maui.cheapcast.fragment.DonationsFragment.java

/**
 * Open dialog/* w  w  w.j  a v  a  2s  .  co  m*/
 *
 * @param icon
 * @param title
 * @param message
 */
void openDialog(int icon, int title, String message) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
    dialog.setIcon(icon);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setCancelable(true);
    dialog.setNeutralButton(R.string.donations__button_close, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:eu.vranckaert.worktime.utils.donations.DonationsFragment.java

private void displayDialog(int id) {
    int icon = -1;
    int title = -1;
    int message = -1;

    switch (id) {
    case DIALOG_BILLING_NOT_SUPPORTED_ID:
        icon = android.R.drawable.ic_dialog_alert;
        title = R.string.donations__google_android_market_not_supported_title;
        message = R.string.donations__google_android_market_not_supported;
    case DIALOG_THANKS:
        icon = android.R.drawable.ic_dialog_info;
        title = R.string.donations__thanks_dialog_title;
        message = R.string.donations__thanks_dialog;
    default:/*from  w  w w . jav a  2 s.c  o m*/
    }

    AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
    dialog.setIcon(icon);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setCancelable(true);
    dialog.setNeutralButton(R.string.donations__button_close, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    dialog.show();
}