Example usage for android.app AlertDialog.Builder setOnCancelListener

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

Introduction

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

Prototype

public void setOnCancelListener(@Nullable OnCancelListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is canceled.

Usage

From source file:Main.java

public static void showConfirmDialog(Context context, String title, String message, String strPositiveButton,
        String strNegativeButton, DialogInterface.OnClickListener positiveOnclick,
        DialogInterface.OnClickListener negativeOnClick, boolean cancelAble,
        DialogInterface.OnCancelListener cancelListener) {
    if (context == null) {
        return;/*from  w w  w . java  2  s . c o  m*/
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    if (title != null) {
        builder.setTitle(title);
    }

    builder.setMessage(message);
    if (TextUtils.isEmpty(strPositiveButton)) {
        builder.setPositiveButton(strPositiveButton, positiveOnclick);
    } else {
        builder.setPositiveButton(strPositiveButton, positiveOnclick);
    }
    if (!TextUtils.isEmpty(strNegativeButton)) {
        builder.setNegativeButton(strNegativeButton, negativeOnClick);
    }
    builder.setCancelable(cancelAble);
    builder.setOnCancelListener(cancelListener);
    builder.create().show();
}

From source file:edu.cmu.cylab.starslinger.demo.MainActivity.java

protected static AlertDialog.Builder xshowMessage(Activity act, Bundle args) {
    String title = args.getString(EXTRA_TITLE);
    String msg = args.getString(EXTRA_MSG);
    AlertDialog.Builder ad = new AlertDialog.Builder(act);
    ad.setTitle(title);//from ww w.  j  av  a2 s.c o m
    ad.setMessage(msg);
    ad.setCancelable(true);
    ad.setNeutralButton(R.string.dev_btn_OK, new android.content.DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    ad.setOnCancelListener(new android.content.DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });
    return ad;
}

From source file:br.fucapi.fapeam.monitori.eula.Eula.java

/**
 * Displays the EULA if necessary. This method should be called from the
 * onCreate() method of your main Activity.
 * /*from  w w w .  j av a  2  s .  co  m*/
 * @param activity
 *            The Activity to finish if the user rejects the EULA.
 * @return Whether the user has agreed already.
 */
public static boolean show(final Activity activity, int title, int acceptLabel, int refuseLabel) {
    final SharedPreferences preferences = activity.getSharedPreferences(PREFERENCES_EULA,
            Activity.MODE_PRIVATE);
    if (!preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(title);
        builder.setCancelable(true);
        builder.setPositiveButton(acceptLabel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                accept(preferences);
                if (activity instanceof OnEulaAgreedTo) {
                    ((OnEulaAgreedTo) activity).onEulaAgreedTo();
                }
            }
        });
        builder.setNegativeButton(refuseLabel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                refuse(activity);
            }
        });
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                refuse(activity);
            }
        });
        builder.setMessage(readEula(activity));
        builder.create().show();
        return false;
    }
    return true;
}

From source file:com.marinamalynkina.android.nearbyplaces.PermissionUtils.java

public static void showNoConnectionDialog(Context ctx1) {
    final Context ctx = ctx1;
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setCancelable(true);//from  w  ww  .  j av  a2s  .c om
    builder.setMessage("Internet not available, Cross check your internet connectivity and try again");
    builder.setTitle("Network problem");
    builder.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            ctx.startActivity(new Intent(Settings.ACTION_SETTINGS));
        }
    });
    //        builder.setNegativeButton("Continue", new DialogInterface.OnClickListener() {
    //            public void onClick(DialogInterface dialog, int which) {
    //                return;
    //            }
    //        });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            return;
        }
    });

    builder.show();
}

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

private static DialogFragment createCameraProblemdDialog() {
    return new DialogFragment() {
        @Override/*from   w  w w.  j av a2s.  c o  m*/
        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:edu.cmu.cylab.starslinger.view.ComposeFragment.java

public static AlertDialog.Builder xshowChangeFileOptions(Activity act) {
    final CharSequence[] items = new CharSequence[] { act.getText(R.string.menu_Remove),
            act.getText(R.string.menu_Change) };
    AlertDialog.Builder ad = new AlertDialog.Builder(act);
    ad.setTitle(R.string.title_FileOptions);
    ad.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {

        @Override/*from   w ww.  j a va2  s  .  c o  m*/
        public void onClick(DialogInterface dialog, int item) {
            dialog.dismiss();
            switch (item) {
            case 0: // remove
                doFileRemove();
                break;
            case 1: // change
                doFileSelect();
                break;
            default:
                break;
            }
        }

    });
    ad.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });
    return ad;
}

From source file:com.googlecode.android_scripting.facade.ui.SeekBarDialogTask.java

private Builder addOnCancelListener(final AlertDialog.Builder builder, final Activity activity) {
    return builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            JSONObject result = new JSONObject();
            try {
                result.put("canceled", true);
                result.put("progress", mSeekBar.getProgress());
            } catch (JSONException e) {
                Log.e(e);//from   www .  j a va2 s  .  co m
            }
            dismissDialog();
            setResult(result);
        }
    });
}

From source file:org.iisgcp.waterwalk.utils.HelpDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(mDialogTitle);/*  w  w w . java2  s .c  o m*/
    builder.setMessage(mDialogText);
    builder.setCancelable(false);
    builder.setOnCancelListener(this);
    builder.setNeutralButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
            mListener.onHelpDialogClosed(HelpDialog.this);
        }
    });
    // Create the AlertDialog object and return it
    return builder.create();
}

From source file:com.popdeem.sdk.uikit.fragment.dialog.PDUIProgressDialogFragment.java

@NonNull
@Override//  ww  w . ja va  2  s.  co m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_pd_progress_dialog, null, false);

    AlertDialog.Builder builder = new AlertDialog.Builder(
            new ContextThemeWrapper(getActivity(), R.style.AlertDialogCustom));
    builder.setView(view);
    builder.setOnCancelListener(mOnCancelListener);

    TextView textView = (TextView) view.findViewById(R.id.pd_progress_dialog_title);
    textView.setText(args.getString(TITLE_KEY, getString(R.string.pd_common_please_wait_text)));

    textView = (TextView) view.findViewById(R.id.pd_progress_dialog_message);
    textView.setText(args.getString(MESSAGE_KEY, getString(R.string.pd_claim_claiming_reward_text)));

    return builder.create();
}

From source file:us.parshall.ezandroid.activity.EZActivity.java

protected AlertDialog.Builder buildMessageDialog(String title, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(title);/*from w  w w  .ja va 2s .c  o m*/

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {

        }
    });

    builder.setMessage(message);

    return builder;
}