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:edu.missouri.bas.activities.AdminManageActivity.java

private Dialog AdminPinDialog(Context context) {
    LayoutInflater inflater = LayoutInflater.from(this);
    final View textEntryView = inflater.inflate(R.layout.pin_login, null);
    alert_text = (TextView) textEntryView.findViewById(R.id.pin_text);
    alert_text.setText("Please input PIN for administrator");
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    builder.setTitle("Verify Admin PIN");
    builder.setView(textEntryView);/*from   ww w .  j  av a 2s .  c  om*/
    //builder.setMessage("Please input PIN for administrator");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            //check networking

            adminPin = (EditText) textEntryView.findViewById(R.id.pin_edit);
            String AdPin = adminPin.getText().toString();
            Log.d(TAG, "get from edittext is " + AdPin);

            HttpPost request = new HttpPost(
                    "http://dslsrv8.cs.missouri.edu/~rs79c/Server/Crt/validateUser.php");

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

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

            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

                        //setResult(8);
                    } else if (result.equals("AdminPinIsInvalid")) {

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

                        Toast toast = Toast.makeText(getApplicationContext(),
                                "Admin PIN is wrong, exit! Please try again.", Toast.LENGTH_SHORT);
                        toast.show();
                        //set return code
                        /*                            if(shp.getString(ASID, "").equals("")){
                                                       setResult(9);
                                                    }else{
                                                       setResult(Activity.RESULT_CANCELED);
                                                    }*/
                        //setResult(9);
                        finish();
                    } else {

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

                        Toast toast = Toast.makeText(getApplicationContext(),
                                "Verify failed. Please try again.", Toast.LENGTH_SHORT);
                        toast.show();
                        //set return code
                        /*                            if(shp.getString(ASID, "").equals("")){
                                                       setResult(9);
                                                    }else{
                                                       setResult(Activity.RESULT_CANCELED);
                                                    }*/
                        finish();
                    }

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

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

                Toast toast = Toast.makeText(getApplicationContext(),
                        "Failed. Please try again, with network connection.", Toast.LENGTH_SHORT);
                toast.show();
                //set return code
                /*                        if(shp.getString(ASID, "").equals("")){
                   setResult(9);
                }else{
                   setResult(Activity.RESULT_CANCELED);
                }*/

                finish();
                e.printStackTrace();
            }

        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

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

            //set return code
            /*                    if(shp.getString(ASID, "").equals("")){
               setResult(9);
            }else{
               setResult(Activity.RESULT_CANCELED);
            }*/
            setResult(9);
            finish();
        }
    });
    return builder.create();
}

From source file:cm.aptoide.pt.Aptoide.java

private void requestUpdateSelf() {
    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
    alertBuilder.setCancelable(false)
            .setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();// ww  w.  j a  va 2 s .  co  m
                    new DownloadSelfUpdate().execute();
                }
            }).setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    proceed();
                }
            }).setMessage(R.string.update_self_msg);

    AlertDialog alert = alertBuilder.create();

    alert.setTitle(R.string.update_self_title);
    alert.setIcon(R.drawable.icon);

    alert.show();
}

From source file:com.kawakawaplanning.rssreader.Main.MainActivity.java

public boolean check() {
    if (!netWorkCheck(this)) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
        alertDialogBuilder.setTitle("?");
        alertDialogBuilder.setMessage(/*from   w  w  w . j av a  2 s  . c o  m*/
                "???????????????????????");
        alertDialogBuilder.setPositiveButton("OK", null);
        alertDialogBuilder.setCancelable(true);
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }
    return netWorkCheck(this);
}

From source file:com.gh4a.IssueListActivity.java

private void showAssigneesDialog() {
    final String[] assignees = new String[mAssignees.size() + 1];

    assignees[0] = getResources().getString(R.string.issue_filter_by_any_assignee);

    String checkedAssignee = mFilterData.get("assignee");
    int checkedItem = 0;

    for (int i = 1; i <= mAssignees.size(); i++) {
        User u = mAssignees.get(i - 1);/*www .j a  v  a  2s  .c  o m*/
        assignees[i] = u.getLogin();
        if (u.getLogin().equalsIgnoreCase(checkedAssignee)) {
            checkedItem = i;
        }
    }

    int dialogTheme = Gh4Application.THEME == R.style.DefaultTheme ? R.style.Theme_Sherlock_Dialog
            : R.style.Theme_Sherlock_Light_Dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, dialogTheme));
    builder.setCancelable(true);
    builder.setTitle(R.string.issue_filter_by_assignee);
    builder.setSingleChoiceItems(assignees, checkedItem, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                mFilterData.remove("assignee");
            } else {
                mFilterData.put("assignee", assignees[which]);
            }
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            reloadIssueList();
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }).create();

    builder.show();
}

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

@Override
protected void onPostExecute(final String errMsg) {
    if (dialog.isShowing()) {
        dialog.dismiss();/*w  w w .j a  va2s  .com*/
    }

    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.openerp.addons.note.EditNoteFragment.java

public void openDailogview(String title, String message, String positivebtnText, String negativebtnText) {

    AlertDialog.Builder deleteDialogConfirm = new AlertDialog.Builder(scope.context());
    deleteDialogConfirm.setTitle(title);
    deleteDialogConfirm.setMessage(message);
    deleteDialogConfirm.setCancelable(true);

    deleteDialogConfirm.setPositiveButton(positivebtnText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            flag = true;//from w  ww .j  ava2s  . c o  m
            getActivity().getSupportFragmentManager().popBackStack();
        }
    });

    deleteDialogConfirm.setNegativeButton(negativebtnText, null);

    deleteDialogConfirm.show();
}

From source file:com.gh4a.IssueListActivity.java

private void showMilestonesDialog() {
    String[] milestones = new String[mMilestones.size() + 1];
    final int[] milestoneIds = new int[mMilestones.size() + 1];

    milestones[0] = getResources().getString(R.string.issue_filter_by_any_milestone);
    milestoneIds[0] = 0;/*from www . j a v a  2s . com*/

    String checkedMilestoneNumber = mFilterData.get("milestone");
    int checkedItem = checkedMilestoneNumber != null && !"".equals(checkedMilestoneNumber)
            ? Integer.parseInt(checkedMilestoneNumber)
            : 0;

    for (int i = 1; i <= mMilestones.size(); i++) {
        Milestone m = mMilestones.get(i - 1);
        milestones[i] = m.getTitle();
        milestoneIds[i] = m.getNumber();
        if (m.getNumber() == checkedItem) {
            checkedItem = i;
        }
    }

    int dialogTheme = Gh4Application.THEME == R.style.DefaultTheme ? R.style.Theme_Sherlock_Dialog
            : R.style.Theme_Sherlock_Light_Dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, dialogTheme));
    builder.setCancelable(true);
    builder.setTitle(R.string.issue_filter_by_milestone);
    builder.setSingleChoiceItems(milestones, checkedItem, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                mFilterData.remove("milestone");
            } else {
                mFilterData.put("milestone", String.valueOf(milestoneIds[which]));
            }
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            reloadIssueList();
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }).create();

    builder.show();
}

From source file:com.pgmacdesign.rsrtoolbox.InputSchedule.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.input_schedule);

    //Different Shared preferences, accessed via the preferences tab in the main grid
    getData = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    work_address_stored = getData.getString("work_address_stored_xml", "Address");

    //To let them know that they can go to preferenes and adjust the address preferences
    if (work_address_stored.equals("Address")) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setTitle("Did You Know?");
        builder.setMessage(// w w  w  .  j  a  va2s .  c  o  m
                "To change your work address and have it automatically fill it in for you. Edit the 'Address' field. "
                        + "It can be found via the main menu -> preferences -> Work Address");
        builder.setInverseBackgroundForced(true);
        builder.setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("Show Me", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
                Intent intent99 = new Intent("com.pgmacdesign.rsrtoolbox.PREFS");
                startActivity(intent99);
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }

    //Setup all variables and listeners
    Initialize();

}

From source file:com.jeremyhaberman.playgrounds.Playgrounds.java

/**
 * Display an error about failing to load playground data. Called by
 * displayErrorTask//from   w ww . ja v  a  2  s  .co m
 */
protected void displayLocationError() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // builder.setTitle("ERROR");

    builder.setMessage(getString(R.string.unable_to_get_current_location));
    builder.setCancelable(false);
    builder.setPositiveButton("Try Again", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss();
            mHandler.post(showPlaygrounds);
        }
    });
    builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss();
        }
    });
    alertDialog = builder.create();
    alertDialog.show();
    mHandler.sendEmptyMessage(0);
}

From source file:app.screen.PopupInfoDialogFragment.java

/** pull in the fragment layout {@link R.id#ttf_dialog_info} and create the dialog */
@Override/*from w  ww.  j  a v a 2s  . c o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    View rootView = getActivity().getLayoutInflater().inflate(R.layout.dialog_fragment, null);

    // set the info text field value
    TextView ttf_info = (TextView) rootView.findViewById(R.id.ttf_dialog_info);
    ttf_info.setText(item);

    builder.setView(rootView).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            getDialog().cancel();
        }
    });
    builder.setCancelable(false);
    return builder.create();
}