Example usage for android.app AlertDialog.Builder setCancelable

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

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.emuneee.nctrafficcams.ui.activities.MainActivity.java

/**
 * Displays the end user license agreement at startup
 *//*  ww w .j av a 2 s  .c  o m*/
private void showEula() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.eula_dialog, null);
    final Dialog dialog;
    builder.setCancelable(false);
    builder.setView(view);
    builder.setTitle(R.string.eula_title);

    builder.setPositiveButton(R.string.agree, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
            Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
            editor.putBoolean(Constants.PREF_EULA_ACCEPTED, true);
            editor.commit();

            editor = getPreferences(Context.MODE_PRIVATE).edit();
            editor.putBoolean(Constants.PREF_TRAFFIC_CAMS_INIT, true);
            editor.commit();
            mGetLatestCamerasTask.execute();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
            Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
            editor.putBoolean(Constants.PREF_EULA_ACCEPTED, false);
            editor.commit();
            MainActivity.this.finish();
        }
    });

    dialog = builder.create();
    // load the eula from assets
    WebView wv = (WebView) view.findViewById(R.id.web_view_eula);
    wv.loadUrl("file:///android_asset/eula.htm");
    dialog.show();
}

From source file:com.remdo.app.MainActivity.java

private void showAlertGPSDisabled() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.error));
    builder.setMessage(getString(R.string.gps_not_enabled));
    builder.setCancelable(false);
    builder.setIcon(R.drawable.ic_alerts_and_warnings);
    builder.setNegativeButton(getString(R.string.close), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();/*from  w w  w . ja  v a2  s.c  o m*/
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.miuidev.themebrowser.MainActivity.java

private void displayAbout() {
    AlertDialog.Builder builder;
    AlertDialog alertDialog;/*from ww  w  .  j a  v a2s.c om*/

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.dialog_about,
            (ViewGroup) findViewById(R.id.DialogAboutRelativeLayout));

    TextView text = (TextView) layout.findViewById(R.id.AboutVersionValue);
    text.setText(getVersionName());

    builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    builder.setCancelable(false).setPositiveButton(getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
    alertDialog = builder.create();
    alertDialog.show();

}

From source file:edu.missouri.niaaa.ema.activity.AdminManageActivity.java

private Dialog AdminPinSetDialog(Context context) {
    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.pin_input, null);
    TextView pinText = (TextView) textEntryView.findViewById(R.id.pin_text);
    pinText.setText(R.string.admin_set_msg);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    builder.setTitle(R.string.admin_set_title);
    builder.setView(textEntryView);//from w w  w  . j a  v  a2s  . c  o  m
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {

            EditText pinEdite = (EditText) textEntryView.findViewById(R.id.pin_edit);
            String pinStr = pinEdite.getText().toString();
            Utilities.Log("Pin Dialog", "pin String is " + pinStr);

            String data = null;
            try {
                data = Utilities.encryption("0000" + "," + "1" + "," + pinStr);
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            /*            check network*/

            /*            prepare params for server*/
            HttpPost request = new HttpPost(Utilities.VALIDATE_ADDRESS);

            List<NameValuePair> params = new ArrayList<NameValuePair>();

            params.add(new BasicNameValuePair("data", data));

            //               //file_name
            //               params.add(new BasicNameValuePair("userID","0000"));
            //               //function
            //               params.add(new BasicNameValuePair("pre","1"));
            //               //data
            //               params.add(new BasicNameValuePair("password",pinStr));

            /*            check identity*/

            try {
                request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

                HttpResponse response = new DefaultHttpClient().execute(request);
                if (response.getStatusLine().getStatusCode() == 200) {
                    String result = EntityUtils.toString(response.getEntity());
                    Log.d("~~~~~~~~~~http post result", result);

                    if (result.equals("AdminIsChecked")) {
                        //do nothing

                    } else if (result.equals("AdminPinIsInvalid")) {

                        imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                        Toast.makeText(getApplicationContext(), R.string.input_apin_failed, Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    } else {

                        imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                        Toast.makeText(getApplicationContext(), R.string.input_apin_error, Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    }
                } else {
                    Toast.makeText(getApplicationContext(), R.string.input_apin_return, Toast.LENGTH_SHORT)
                            .show();
                    finish();
                }

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

                imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                Toast.makeText(getApplicationContext(), R.string.input_apin_net_error, Toast.LENGTH_SHORT)
                        .show();
                ;
                finish();
            }

        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {

            imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

            finish();
        }
    });

    return builder.create();
}

From source file:org.deviceconnect.android.uiapp.DConnectActivity.java

@Override
protected void onResumeFragments() {
    super.onResumeFragments();

    // ?????????/* w w  w.  j  ava  2s . c o  m*/
    if (mError != null) {
        clearFragmentList();
        mLoadingFragment = new DialogFragment() {
            @Override
            public Dialog onCreateDialog(final Bundle savedInstanceState) {
                final AlertDialog.Builder builder = new AlertDialog.Builder(DConnectActivity.this);
                builder.setTitle(R.string.activity_failed_to_get_accesstoken);
                builder.setMessage(mError.toString());
                builder.setCancelable(true);
                mError = null;
                return builder.create();
            }
        };
        mLoadingFragment.show(getSupportFragmentManager(), "test");
    }
}

From source file:edu.missouri.niaaa.pain.activity.AdminManageActivity.java

private Dialog AdminPinSetDialog(final Context context) {
    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.pin_input, null);
    TextView pinText = (TextView) textEntryView.findViewById(R.id.pin_text);
    pinText.setText(R.string.admin_set_msg);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    builder.setTitle(R.string.admin_set_title);
    builder.setView(textEntryView);/*w w w.  j  a va  2s  .  co  m*/
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {

            EditText pinEdite = (EditText) textEntryView.findViewById(R.id.pin_edit);
            String pinStr = pinEdite.getText().toString();
            Util.Log_debug("Pin Dialog", "pin String is " + pinStr);

            String data = null;
            try {
                data = Util.encryption(context, Util.ADMIN_UID + "," + "1" + "," + pinStr);
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            /*              check network*/

            /*              prepare params for server*/
            HttpPost request = new HttpPost(Util.VALIDATE_ADDRESS);

            List<NameValuePair> params = new ArrayList<NameValuePair>();

            params.add(new BasicNameValuePair("data", data));

            //              //file_name
            //              params.add(new BasicNameValuePair("userID","0000"));
            //              //function
            //              params.add(new BasicNameValuePair("pre","1"));
            //              //data
            //              params.add(new BasicNameValuePair("password",pinStr));

            /*              check identity*/

            try {
                request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

                HttpResponse response = new DefaultHttpClient().execute(request);
                if (response.getStatusLine().getStatusCode() == 200) {
                    String result = EntityUtils.toString(response.getEntity());
                    Log.d("~~~~~~~~~~http post result", result);

                    if (result.equals("AdminIsChecked")) {
                        //do nothing

                    } else if (result.equals("AdminPinIsInvalid")) {

                        imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                        Toast.makeText(getApplicationContext(), R.string.input_apin_failed, Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    } else {

                        imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                        Toast.makeText(getApplicationContext(), R.string.input_apin_error, Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    }
                } else {
                    Toast.makeText(getApplicationContext(), R.string.input_apin_return, Toast.LENGTH_SHORT)
                            .show();
                    finish();
                }

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

                imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                Toast.makeText(getApplicationContext(), R.string.input_apin_net_error, Toast.LENGTH_SHORT)
                        .show();
                ;
                finish();
            }

        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {

            imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

            finish();
        }
    });

    return builder.create();
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.TLCDocument.PartnershipApplicant.java

public void dataSent() {
    android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(this);
    dialog.setCancelable(false);
    dialog.setTitle("Alert");
    dialog.setMessage("Data Sent Successfully");
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override//from www .j  a  v a2s  . c o m
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(PartnershipApplicant.this, ThankYouScreen.class);
            startActivity(intent);
        }
    }).setNegativeButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Action for "Cancel".
        }
    });

    final android.app.AlertDialog alert = dialog.create();
    alert.show();
}

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

/**
 * Creates the UI for the interactive authentication process
 * /*  w  ww  .  j  a v  a  2  s . co 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:com.chaturs.notepad.NoteEditor.java

private void showDialogForTitle() {

    View view = LayoutInflater.from(this).inflate(R.layout.dialog_title, null);
    final EditText edit = (EditText) view.findViewById(R.id.edit);
    Button okButton = (Button) view.findViewById(R.id.ok);
    Button cancelButton = (Button) view.findViewById(R.id.cancel);

    edit.setText(title);//from  ww  w  .  ja va2s  . c o m
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Enter Title");
    builder.setView(view);
    builder.setCancelable(false);

    okButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            title = edit.getText().toString();

            if (title.trim().length() == 0) {
                edit.setError("Please Enter Some Text !");
                return;
            }

            saveNote();
            setTitle(title);
            dialog.dismiss();
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            dialog.dismiss();

        }
    });

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

From source file:com.qasp.diego.arsp.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.configs:
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);// www.  j a  v a  2 s  .  com
        return true;
    case R.id.contato:
        AlertDialog.Builder bcontato = new AlertDialog.Builder(MainActivity.this);
        bcontato.setTitle("Informaes para contato");
        bcontato.setMessage("Envie um e-mail para:" + "\n\n" + "diego.buoro@usp.br" + "\n\n" + "com" + " "
                + " '[IQSP]'" + " " + "no ttulo");
        bcontato.setCancelable(true);
        bcontato.setNeutralButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        AlertDialog alerta_contato = bcontato.create();
        alerta_contato.show();
        return true;
    case R.id.about:
        AlertDialog.Builder babout = new AlertDialog.Builder(MainActivity.this);
        babout.setTitle("Sobre o programa");
        babout.setMessage(
                "O IQSP  um programa para a exibio da qualidade do ar nas estaes, e na obteno da qualidade no local do usurio."
                        + "\n\n"
                        + "- Use o cone da seta para baixo para atualizar as estaes (Necessita de Internet)."
                        + "\n" + "- Indice local  calculado assim que a aba  selecionada (Necessita GPS)."
                        + "\n\n" + "Verso 1.0");
        babout.setCancelable(true);
        babout.setNeutralButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        AlertDialog alerta_about = babout.create();
        alerta_about.show();
        return true;
    case R.id.action_update:
        if (PermissaodeEscrita(this))
            atualizarClick();
        else {
            AlertDialog.Builder bPERERR = new AlertDialog.Builder(MainActivity.this);
            bPERERR.setTitle("Sem permisso");
            bPERERR.setMessage(
                    "Sem permisso para escrita dos dados, atualizao impossvel. Deseja permitir?");
            bPERERR.setCancelable(true);
            bPERERR.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    verifyStoragePermissions(MainActivity.this);
                }
            });
            bPERERR.setNegativeButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog alerta_permissao = bPERERR.create();
            alerta_permissao.show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}