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:org.apache.cordova.engine.crosswalk.XWalkCordovaChromeClient.java

/**
 * Tell the client to display a confirm dialog to the user.
 *
 * @param view/*w  ww.  ja v a2  s .  co m*/
 * @param url
 * @param message
 * @param result
 */
private boolean onJsConfirm(XWalkView view, String url, String message, final XWalkJavascriptResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Confirm");
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.cancel();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.cancel();
                return false;
            } else
                return true;
        }
    });
    dlg.create();
    dlg.show();
    return true;
}

From source file:org.apache.cordova.CordovaChromeClient.java

/**
 * Tell the client to display a confirm dialog to the user.
 *
 * @param view/*from w  w w .j  av  a2 s.c om*/
 * @param url
 * @param message
 * @param result
 */
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Confirm");
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.cancel();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.cancel();
                return false;
            } else
                return true;
        }
    });
    dlg.show();
    return true;
}

From source file:de.baumann.browser.helper.helper_main.java

public static void openFilePicker(final Activity activity, final View view, final String startDir) {

    new ChooserDialog().with(activity).withStartFile(startDir).withChosenListener(new ChooserDialog.Result() {
        @Override//from w w  w. j a  v  a  2s  . c o  m
        public void onChoosePath(final File pathFile) {

            final String fileExtension = pathFile.getAbsolutePath()
                    .substring(pathFile.getAbsolutePath().lastIndexOf("."));
            final String fileName = pathFile.getAbsolutePath()
                    .substring(pathFile.getAbsolutePath().lastIndexOf("/") + 1);
            final String fileNameWE = fileName.substring(0, fileName.lastIndexOf("."));

            final CharSequence[] options = { activity.getString(R.string.choose_menu_1),
                    activity.getString(R.string.choose_menu_2), activity.getString(R.string.choose_menu_3),
                    activity.getString(R.string.choose_menu_4) };

            final AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
            dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });
            dialog.setItems(options, new DialogInterface.OnClickListener() {
                @SuppressWarnings("ResultOfMethodCallIgnored")
                @Override
                public void onClick(DialogInterface dialog, int item) {
                    if (options[item].equals(activity.getString(R.string.choose_menu_1))) {

                        String text = (activity.getString(R.string.toast_extension) + ": " + fileExtension);

                        switch (fileExtension) {
                        case ".gif":
                        case ".bmp":
                        case ".tiff":
                        case ".svg":
                        case ".png":
                        case ".jpg":
                        case ".jpeg":
                            helper_main.openFile(activity, pathFile, "image/*", view);
                            break;
                        case ".m3u8":
                        case ".mp3":
                        case ".wma":
                        case ".midi":
                        case ".wav":
                        case ".aac":
                        case ".aif":
                        case ".amp3":
                        case ".weba":
                            helper_main.openFile(activity, pathFile, "audio/*", view);
                            break;
                        case ".mpeg":
                        case ".mp4":
                        case ".ogg":
                        case ".webm":
                        case ".qt":
                        case ".3gp":
                        case ".3g2":
                        case ".avi":
                        case ".f4v":
                        case ".flv":
                        case ".h261":
                        case ".h263":
                        case ".h264":
                        case ".asf":
                        case ".wmv":
                            helper_main.openFile(activity, pathFile, "video/*", view);
                            break;
                        case ".rtx":
                        case ".csv":
                        case ".txt":
                        case ".vcs":
                        case ".vcf":
                        case ".css":
                        case ".ics":
                        case ".conf":
                        case ".config":
                        case ".java":
                            helper_main.openFile(activity, pathFile, "text/*", view);
                            break;
                        case ".html":
                            helper_main.openFile(activity, pathFile, "text/html", view);
                            break;
                        case ".apk":
                            helper_main.openFile(activity, pathFile, "application/vnd.android.package-archive",
                                    view);
                            break;
                        case ".pdf":
                            helper_main.openFile(activity, pathFile, "application/pdf", view);
                            break;
                        case ".doc":
                            helper_main.openFile(activity, pathFile, "application/msword", view);
                            break;
                        case ".xls":
                            helper_main.openFile(activity, pathFile, "application/vnd.ms-excel", view);
                            break;
                        case ".ppt":
                            helper_main.openFile(activity, pathFile, "application/vnd.ms-powerpoint", view);
                            break;
                        case ".docx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                                    view);
                            break;
                        case ".pptx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.presentationml.presentation",
                                    view);
                            break;
                        case ".xlsx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", view);
                            break;
                        case ".odt":
                            helper_main.openFile(activity, pathFile, "application/vnd.oasis.opendocument.text",
                                    view);
                            break;
                        case ".ods":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.oasis.opendocument.spreadsheet", view);
                            break;
                        case ".odp":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.oasis.opendocument.presentation", view);
                            break;
                        case ".zip":
                            helper_main.openFile(activity, pathFile, "application/zip", view);
                            break;
                        case ".rar":
                            helper_main.openFile(activity, pathFile, "application/x-rar-compressed", view);
                            break;
                        case ".epub":
                            helper_main.openFile(activity, pathFile, "application/epub+zip", view);
                            break;
                        case ".cbz":
                            helper_main.openFile(activity, pathFile, "application/x-cbz", view);
                            break;
                        case ".cbr":
                            helper_main.openFile(activity, pathFile, "application/x-cbr", view);
                            break;
                        case ".fb2":
                            helper_main.openFile(activity, pathFile, "application/x-fb2", view);
                            break;
                        case ".rtf":
                            helper_main.openFile(activity, pathFile, "application/rtf", view);
                            break;
                        case ".opml":
                            helper_main.openFile(activity, pathFile, "application/opml", view);
                            break;

                        default:
                            Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
                            break;
                        }

                        String dir = pathFile.getParentFile().getAbsolutePath();
                        helper_main.openFilePicker(activity, view, dir);
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_2))) {

                        if (pathFile.exists()) {
                            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                            sharingIntent.setType("image/png");
                            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, fileName);
                            sharingIntent.putExtra(Intent.EXTRA_TEXT, fileName);
                            Uri bmpUri = Uri.fromFile(pathFile);
                            sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                            activity.startActivity(Intent.createChooser(sharingIntent,
                                    (activity.getString(R.string.app_share_file))));
                        }
                        String dir = pathFile.getParentFile().getAbsolutePath();
                        helper_main.openFilePicker(activity, view, dir);
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_4))) {
                        final AlertDialog.Builder dialog2 = new AlertDialog.Builder(activity);

                        dialog2.setMessage(activity.getString(R.string.choose_delete));
                        dialog2.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                pathFile.delete();
                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        String dir = pathFile.getParentFile().getAbsolutePath();
                                        helper_main.openFilePicker(activity, view, dir);
                                    }
                                }, 500);
                            }
                        });
                        dialog2.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.cancel();
                            }
                        });
                        dialog2.setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                // dialog dismiss without button press
                                String dir = pathFile.getParentFile().getAbsolutePath();
                                helper_main.openFilePicker(activity, view, dir);
                            }
                        });
                        dialog2.show();
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_3))) {

                        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                        View dialogView = View.inflate(activity, R.layout.dialog_edit_file, null);

                        final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);

                        builder.setView(dialogView);
                        builder.setTitle(R.string.choose_title);
                        builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {

                                String inputTag = edit_title.getText().toString().trim();

                                File dir = pathFile.getParentFile();
                                File to = new File(dir, inputTag + fileExtension);

                                pathFile.renameTo(to);
                                pathFile.delete();

                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        String dir = pathFile.getParentFile().getAbsolutePath();
                                        helper_main.openFilePicker(activity, view, dir);
                                    }
                                }, 500);
                            }
                        });
                        builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.cancel();
                            }
                        });
                        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                // dialog dismiss without button press
                                String dir = pathFile.getParentFile().getAbsolutePath();
                                helper_main.openFilePicker(activity, view, dir);
                            }
                        });

                        final AlertDialog dialog2 = builder.create();
                        // Display the custom alert dialog on interface
                        dialog2.show();
                        helper_editText.showKeyboard(activity, edit_title, 0, fileNameWE,
                                activity.getString(R.string.choose_hint));
                    }
                }
            });
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    // dialog dismiss without button press
                    String dir = pathFile.getParentFile().getAbsolutePath();
                    helper_main.openFilePicker(activity, view, dir);
                }
            });
            dialog.show();
        }
    }).build().show();
}

From source file:loon.LGame.java

/**
 * /*  www .  j  av  a  2 s. c o  m*/
 * 
 * @param listener
 * @param title
 * @param text
 */
public void showAndroidSelect(final SelectEvent listener, final String title, final String text[]) {
    if (listener == null) {
        return;
    }
    final AndroidViewTools.ClickAndroid ITEM = new AndroidViewTools.ClickAndroid(listener, 0);
    final AndroidViewTools.ClickAndroid CANCEL = new AndroidViewTools.ClickAndroid(listener, 1);
    final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(LGame.this);
    builder.setTitle(title);
    builder.setItems(text, ITEM);
    builder.setOnCancelListener(CANCEL);
    android.app.AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME);

    PackageManager pm = getPackageManager();

    ApplicationInfo appInfo;//w  w w  .  jav  a  2  s  .c o  m
    try {
        //noinspection WrongConstant (lint is actually wrong here!)
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("Failed to get ApplicationInfo for uninstalling");
    }

    final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;

    if (isSystem && !isUpdate) {
        // Cannot remove system apps unless we're uninstalling updates
        throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates");
    }

    int messageId;
    if (isUpdate) {
        messageId = R.string.uninstall_update_confirm;
    } else {
        messageId = R.string.uninstall_confirm;
    }

    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final AlertDialog.Builder builder = new AlertDialog.Builder(theme);
    builder.setTitle(appInfo.loadLabel(pm));
    builder.setIcon(appInfo.loadIcon(pm));
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent data = new Intent();
            data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName);
            setResult(Activity.RESULT_OK, intent);
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setMessage(messageId);
    builder.create().show();
}

From source file:me.piebridge.prevent.ui.PreventActivity.java

private void showTestDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.app_name) + "(" + BuildConfig.VERSION_NAME + ")");
    builder.setMessage(R.string.soak_version);
    builder.setIcon(R.drawable.ic_launcher);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override//from ww  w . ja v  a2s.  c  o  m
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            startActivity(new Intent(Intent.ACTION_DELETE,
                    Uri.fromParts("package", BuildConfig.APPLICATION_ID, null)));
            finish();
        }
    });
    builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            init();
        }
    });
    builder.create().show();
}

From source file:org.apache.cordova.AndroidChromeClient.java

/**
 * Tell the client to display a confirm dialog to the user.
 *
 * @param view/*  w w w . jav a 2  s.  c  o  m*/
 * @param url
 * @param message
 * @param result
 */
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Confirm");
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    dlg.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.cancel();
        }
    });
    dlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            result.cancel();
        }
    });
    dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
        //DO NOTHING
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                result.cancel();
                return false;
            } else
                return true;
        }
    });
    dlg.create();
    dlg.show();
    return true;
}

From source file:org.loon.framework.android.game.LGameActivity.java

/**
 * ??Select/*from w w w .j  a  v a  2 s. co  m*/
 * 
 * @param title
 * @param text
 * @return
 */
public int showAndroidSelect(final String title, final String text[]) {
    Runnable showSelect = new Runnable() {
        public void run() {
            final AlertDialog.Builder builder = new AlertDialog.Builder(LGameActivity.this);
            builder.setTitle(title);
            builder.setItems(text, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    androidSelect = item;
                }
            });
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    androidSelect = -1;
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    };
    runOnUiThread(showSelect);
    return androidSelect;
}

From source file:com.github.michalbednarski.intentslab.ReceiveBroadcastDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context context = getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    View view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.dialog_receive_broadcast, null);
    mActionTextView = (AutoCompleteTextView) view.findViewById(R.id.action);
    mMultipleCheckBox = (CheckBox) view.findViewById(R.id.receive_multiple_broadcasts);
    mActionTextView.setText(/*from  w ww .j  a v  a 2  s. c o  m*/
            PreferenceManager.getDefaultSharedPreferences(context).getString("lastcatchbroadcastaction", ""));
    mActionTextView.setAdapter(new NameAutocompleteAdapter(context, R.raw.broadcast_actions));
    builder.setView(view);
    builder.setTitle(R.string.receive_broadcast);
    builder.setPositiveButton(R.string.register_receiver, this);
    if (ReceiveBroadcastService.sIsRunning) {
        builder.setNegativeButton(R.string.unregister_receiver, this);
    }
    builder.setOnCancelListener(this);
    return builder.create();
}

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

private void displayFrameworkBugMessageAndExit() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.app_name));
    builder.setMessage(getString(R.string.msg_camera_framework_bug));
    builder.setPositiveButton(R.string.button_ok, new FinishListener(this));
    builder.setOnCancelListener(new FinishListener(this));
    builder.show();/*from w  w  w. ja  v  a 2  s  . c  om*/
}