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:com.securecomcode.text.ContactSelectionListFragment.java

private void addMultipleNumberContact(ContactData contactData, CheckedTextView textView) {
    String[] options = new String[contactData.numbers.size()];
    int i = 0;/*  w w  w . ja  v a 2  s  .c  om*/

    for (NumberData option : contactData.numbers) {
        options[i++] = option.type + " " + option.number;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.ContactSelectionlistFragment_select_for + " " + contactData.name);
    builder.setMultiChoiceItems(options, null, new DiscriminatorClickedListener(contactData));
    builder.setPositiveButton(android.R.string.ok, new DiscriminatorFinishedListener(contactData, textView));
    builder.setOnCancelListener(new DiscriminatorFinishedListener(contactData, textView));
    builder.show();
}

From source file:com.xys.libzxing.zxing.activity.CaptureActivity.java

private void displayFrameworkBugMessageAndExit() {
    // camera error
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.zxing_bar_name));
    builder.setMessage("Camera error");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override/*ww  w  . j  a v a  2s .  c  o  m*/
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }

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

        @Override
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    builder.show();
}

From source file:com.microsoft.windowsazure.mobileservices.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 * /*from  ww w . j  a v a  2  s .  c  om*/
 * @param provider
 *            The provider used for the authentication process
 * @param startUrl
 *            The initial URL for the authentication process
 * @param endUrl
 *            The final URL for the authentication process
 * @param context
 *            The context used to create the authentication dialog
 * @param callback
 *            Callback to invoke when the authentication process finishes
 */
private void showLoginUI(final String startUrl, final String endUrl, final Context context,
        LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });
    wv.getSettings().setJavaScriptEnabled(true);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int webViewHeight = displaymetrics.heightPixels;

    wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight));

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

From source file:com.orangelabs.rcs.ri.messaging.chat.single.SingleChatView.java

private AlertDialog popUpToClearMessageDeliveryExpiration(Context ctx, String title, String msg,
        OnClickListener onClickiLstener, OnCancelListener onCancelListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setMessage(msg);/*  www. jav a  2 s.  c o  m*/
    builder.setTitle(title);
    builder.setOnCancelListener(onCancelListener);
    builder.setPositiveButton(R.string.label_ok, onClickiLstener);
    return builder.show();
}

From source file:com.azure.webapi.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 * /*from  w w w .j  a  v  a 2 s .c  o m*/
 * @param provider
 *            The provider used for the authentication process
 * @param startUrl
 *            The initial URL for the authentication process
 * @param endUrl
 *            The final URL for the authentication process
 * @param context
 *            The context used to create the authentication dialog
 * @param callback
 *            Callback to invoke when the authentication process finishes
 */
protected void showLoginUI(MobileServiceAuthenticationProvider provider, final String startUrl,
        final String endUrl, final Context context, LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setTitle("Connecting to a service");
    builder.setCancelable(true);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });

    // Set cancel button's action
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
            wv.destroy();
        }
    });

    wv.getSettings().setJavaScriptEnabled(true);

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

From source file:org.thoughtcrime.securesms.PushContactSelectionListFragment.java

private void addMultipleNumberContact(ContactData contactData, TextView textView, CheckBox checkBox) {
    String[] options = new String[contactData.numbers.size()];
    int i = 0;/*from ww  w.  j  av a  2s. c  o m*/

    for (NumberData option : contactData.numbers) {
        options[i++] = option.type + " " + option.number;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.ContactSelectionlistFragment_select_for + " " + contactData.name);
    builder.setMultiChoiceItems(options, null, new DiscriminatorClickedListener(contactData));
    builder.setPositiveButton(android.R.string.ok,
            new DiscriminatorFinishedListener(contactData, textView, checkBox));
    builder.setOnCancelListener(new DiscriminatorFinishedListener(contactData, textView, checkBox));
    builder.show();
}

From source file:com.chiemy.zxing.activity.CaptureActivity.java

private void displayFrameworkBugMessageAndExit() {
    // camera error
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.app_name));
    builder.setMessage("Camera error");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override/*from  w  w  w  .j  a  va  2s  .com*/
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }

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

        @Override
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    builder.show();
}

From source file:org.ubicompforall.cityexplorer.CityExplorer.java

/**
  * Display a dialog that user has no Internet connection
  * Code from: http://osdir.com/ml/Android-Developers/2009-11/msg05044.html
 * @return /* ww  w.  j  av  a  2s.  co m*/
  */
public static AlertDialog showNoConnectionDialog(final Context myContext, final String msg,
        final String cancelButtonStr, final Intent cancelIntent) {
    AlertDialog.Builder builder = new AlertDialog.Builder(myContext);
    builder.setCancelable(true);
    if (msg == "") {
        builder.setMessage(R.string.no_connection);
    } else {
        builder.setMessage(msg);
    }
    builder.setTitle(R.string.no_connection_title);
    builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            myContext.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
        }
    });

    String cancelText = cancelButtonStr;
    if (cancelText == "") {
        cancelText = myContext.getResources().getString(R.string.cancel);
    }
    builder.setNegativeButton(cancelText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (cancelIntent != null) {
                if (myContext instanceof Activity) {
                    ((Activity) myContext).startActivityForResult(cancelIntent, CityExplorer.REQUEST_LOCATION);
                } else {
                    debug(-1, "This is not an Activity!!");
                }
                dialog.dismiss();
            }
            return;
        }
    });

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            if (myContext == null) {
                debug(0, "OOOPS!");
            } else {
                Toast.makeText(myContext, "CANCELLED!", Toast.LENGTH_LONG).show();
                if (cancelIntent != null) {
                    myContext.startActivity(cancelIntent);
                }
            }
            return;
        }
    });

    DATACONNECTION_NOTIFIED = true;
    return builder.show();
}

From source file:org.apache.cordova.engine.crosswalk.XWalkCordovaChromeClient.java

/**
 * Tell the client to display a javascript alert dialog.
 *
 * @param view/*from w ww.  j a  va  2  s.co  m*/
 * @param url
 * @param message
 * @param result
 */
private boolean onJsAlert(XWalkView view, String url, String message, final XWalkJavascriptResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Alert");
    //Don't let alerts break the back button
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    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.confirm();
                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 javascript alert dialog.
 *
 * @param view/*from ww  w .  j a v a  2s.  c o m*/
 * @param url
 * @param message
 * @param result
 */
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
    dlg.setMessage(message);
    dlg.setTitle("Alert");
    //Don't let alerts break the back button
    dlg.setCancelable(true);
    dlg.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            result.confirm();
        }
    });
    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.confirm();
                return false;
            } else
                return true;
        }
    });
    dlg.show();
    return true;
}