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.example.administrator.myapplication.fragment.CordovaFragment2.java

/**
 * Display an error dialog and optionally exit application.
 *///w  ww. j  a  v  a 2s.c om
public void displayError(final String title, final String message, final String button, final boolean exit) {
    final CordovaFragment2 me = this;
    me.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            try {
                AlertDialog.Builder dlg = new AlertDialog.Builder(me.getActivity());
                dlg.setMessage(message);
                dlg.setTitle(title);
                dlg.setCancelable(false);
                dlg.setPositiveButton(button, new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (exit) {
                            getActivity().finish();
                        }
                    }
                });
                dlg.create();
                dlg.show();
            } catch (Exception e) {
                getActivity().finish();
            }
        }
    });
}

From source file:fr.mdk.kisspush.KISSPush.java

protected void openAdd() {
    final Activity act = this;
    // get prompts.xml view
    LayoutInflater layoutInflater = getLayoutInflater();
    View promptView = layoutInflater.inflate(R.layout.prompts, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(act);
    // set prompts.xml to be the layout file of the alertdialog
    // builder/*from w  ww.  ja  v a 2 s  .c om*/
    alertDialogBuilder.setView(promptView);
    final EditText input = (EditText) promptView.findViewById(R.id.userInput);
    // setup a dialog window
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // get user input and set it to
            // result
            if (input.getText().toString().length() > 0) {
                kiss_push_cli.add_alias(input.getText().toString(), new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
                        getAliases();
                    }
                });
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    // create an alert dialog
    AlertDialog alertD = alertDialogBuilder.create();
    alertD.show();

}

From source file:com.q335.r49.squaredays.MainActivity.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    final String extStorPath = Environment.getExternalStorageDirectory() + File.separator + fEXTSTOR
            + File.separator;//from  www  . j  a  va 2 s.  c  o  m
    final File cmdFile = new File(extStorPath, fTASKS);
    final File logFile = new File(extStorPath, fLOGS);
    switch (item.getItemId()) {
    case R.id.menuItemExport: {
        if (ContextCompat.checkSelfPermission(this,
                android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    1);
        final File directory = new File(extStorPath);
        directory.mkdirs();
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
        alertBuilder.setCancelable(true).setMessage("Selected files will be exported to " + extStorPath)
                .setNeutralButton("Commands", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Files.write(prefs.getString(TasksFrag.prefsTasksKey, ""), cmdFile, Charsets.UTF_8);
                            Toast.makeText(context, "Commands exported to " + extStorPath + fTASKS,
                                    Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            Log.d("SquareDays", e.toString());
                            Toast.makeText(context,
                                    "Export failed. Does this app have storage permission? (Settings > Apps > tracker > Permissions)",
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                }).setNegativeButton("Log entries", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            writeLogFile();
                            Files.copy(new File(getFilesDir(), fLOGS), logFile);
                            Toast.makeText(context, "Log entries exported to " + extStorPath + fLOGS,
                                    Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            Log.d("SquareDays", e.toString());
                            Toast.makeText(context,
                                    "Export failed. Does this app have storage permission? (Settings > Apps > tracker > Permissions)",
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                }).setPositiveButton("BOTH", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            writeLogFile();
                            Files.copy(new File(getFilesDir(), fLOGS), logFile);
                            Files.write(prefs.getString(TasksFrag.prefsTasksKey, ""), cmdFile, Charsets.UTF_8);
                            Toast.makeText(context,
                                    "Commands exported to " + extStorPath + fTASKS
                                            + System.getProperty("line.separator") + "Log entries exported to "
                                            + extStorPath + fLOGS,
                                    Toast.LENGTH_LONG).show();
                        } catch (Exception e) {
                            Log.d("SquareDays", e.toString());
                            Toast.makeText(context,
                                    "Export failed. Does this app have storage permission? (Settings > Apps > tracker > Permissions)",
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                }).show();
        return true;
    }
    case R.id.menuItemImport: {
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    1);
        final File directory = new File(extStorPath);
        if (!directory.isDirectory())
            Toast.makeText(context, "Import failed. " + extStorPath + "not found.", Toast.LENGTH_LONG).show();
        else {
            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
            alertBuilder.setCancelable(true).setMessage("Importing from " + extStorPath)
                    .setNeutralButton("commands.json", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                String jsonText = Files.toString(cmdFile, Charsets.UTF_8);
                                if (jsonText == null)
                                    Toast.makeText(context, "Import failed: empty file", Toast.LENGTH_SHORT)
                                            .show();
                                else {
                                    BF.loadCommands(jsonText);
                                    Toast.makeText(context, fTASKS + " import successful", Toast.LENGTH_SHORT)
                                            .show();
                                }
                            } catch (Exception e) {
                                Log.d("SquareDays", e.toString());
                                Toast.makeText(context,
                                        "Import failed. Does this app have storage access? (Settings > Apps > tracker > Permissions)",
                                        Toast.LENGTH_LONG).show();
                            }
                        }
                    }).setNegativeButton("log.txt", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (!logFile.exists())
                                Toast.makeText(context, "Import failed: log file not found", Toast.LENGTH_LONG)
                                        .show();
                            else {
                                try {
                                    Files.copy(logFile, new File(getFilesDir(), "log.txt"));
                                    pushOnly(Interval.newClearTimeMsg());
                                    pushOnly(Interval.newClearExpMess());
                                    readLogFile();
                                    popAll();
                                    Toast.makeText(context, fLOGS + " import successful", Toast.LENGTH_SHORT)
                                            .show();
                                } catch (Exception e) {
                                    Log.d("SquareDays", e.toString());
                                    Toast.makeText(context,
                                            "Import failed. Does this app have storage access? (Settings > Apps > tracker > Permissions)",
                                            Toast.LENGTH_LONG).show();
                                }
                            }
                        }
                    }).setPositiveButton("Both", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                String jsonText = Files.toString(cmdFile, Charsets.UTF_8);
                                if (jsonText == null) {
                                    Toast.makeText(context, "Import failed: empty file", Toast.LENGTH_SHORT)
                                            .show();
                                } else {
                                    BF.loadCommands(jsonText);
                                    Toast.makeText(context, fTASKS + " import successful", Toast.LENGTH_SHORT)
                                            .show();
                                }
                            } catch (Exception e) {
                                Log.d("SquareDays", e.toString());
                                Toast.makeText(context,
                                        "Import failed. Does this app have storage access? (Settings > Apps > tracker > Permissions)",
                                        Toast.LENGTH_LONG).show();
                            }
                            if (!logFile.exists())
                                Toast.makeText(context, fLOGS + " failed: no file", Toast.LENGTH_SHORT).show();
                            else {
                                try {
                                    Files.copy(logFile, new File(getFilesDir(), "log.txt"));
                                    pushOnly(Interval.newClearTimeMsg());
                                    pushOnly(Interval.newClearExpMess());
                                    readLogFile();
                                    popAll();
                                    Toast.makeText(context, fLOGS + " import successful", Toast.LENGTH_SHORT)
                                            .show();
                                } catch (Exception e) {
                                    Log.d("SquareDays", e.toString());
                                    Toast.makeText(context,
                                            "Import failed. Does this app have storage access? (Settings > Apps > tracker > Permissions)",
                                            Toast.LENGTH_LONG).show();
                                }
                            }
                        }
                    }).show();
        }
        return true;
    }
    case R.id.menuItemClear: {
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
        alertBuilder.setCancelable(true).setMessage("Really clear log?")
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        File logFile = new File(getFilesDir(), fLOGS);
                        if (logFile.exists()) {
                            if (logFile.delete()) {
                                pushOnly(Interval.newClearTimeMsg());
                                pushOnly(Interval.newClearExpMess());
                            } else
                                Log.d("SquareDays", "Log clear failed!");
                        } else {
                            pushOnly(Interval.newClearTimeMsg());
                            pushOnly(Interval.newClearExpMess());
                        }
                        popAll();
                    }
                }).show();
        return true;
    }
    case R.id.menuItemHelp: {
        FragmentManager fm = getSupportFragmentManager();
        HelpFrag helpV = HelpFrag.newInstance();
        helpV.show(fm, "fragment_edit_name");
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.github.kanata3249.ffxieq.android.AugmentSelectorActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case R.string.QueryDeleteAugment: {
        Dialog dialog;/* w w w.  j  a v a 2s . com*/
        AlertDialog.Builder builder;

        builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setMessage(getString(R.string.QueryDeleteAugment));
        builder.setTitle(getString(R.string.app_name));
        builder.setPositiveButton(R.string.DeleteOK, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                ((FFXIDatabase) getDAO()).deleteAugment(mLongClickingItemId);

                AugmentListView lv = (AugmentListView) findViewById(R.id.ListView);
                if (lv != null)
                    lv.setParam(getDAO(), mPart, mRace, mJob, mLevel);
                dismissDialog(R.string.QueryDeleteAugment);
            }
        });
        builder.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dismissDialog(R.string.QueryDeleteAugment);
            }
        });
        dialog = builder.create();
        return dialog;
    }
    default: {
        FilterSelectorDialog dialog = new FilterSelectorDialog(this);

        dialog.setOnDismissListener(new OnDismissListener() {
            public void onDismiss(DialogInterface dialog) {
                FilterSelectorDialog fsd = (FilterSelectorDialog) dialog;
                String filter = fsd.getFilterString();
                mFilterID = fsd.getFilterID();

                if (filter.length() > 0) {
                    AugmentListView lv = (AugmentListView) findViewById(R.id.ListView);
                    if (lv != null) {
                        lv.setFilter(filter);
                    }
                }

            }

        });
        return dialog;
    }
    }
}

From source file:ca.ualberta.cmput301.t03.user.FriendsListFragment.java

/**
 * Creates a new AlertDialog which can be
 * used to add friends.//from  www.ja v a2 s  . c o  m
 * <p>
 * The alertDialog contains a single EditText
 * where the user can enter the username to be
 * added.
 *
 * @return the configured AlertDialog
 */
private AlertDialog createAddFriendDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    View dialogContent = View.inflate(getContext(), R.layout.content_add_friend_dialog, null);
    final EditText e = (EditText) dialogContent.findViewById(R.id.addFriendEditText);

    builder.setView(dialogContent); //todo replace with layout
    builder.setCancelable(false);
    builder.setNegativeButton("Cancel", null);
    builder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String usr = e.getText().toString().trim();

            AsyncTask t = new AsyncTask() {
                @Override
                protected Object doInBackground(Object[] params) {

                    if (usr.equals(""))
                        return null;
                    try {
                        mController.addFriend(usr);
                    } catch (IOException e1) {
                        Snackbar.make(getView(), "There was a problem with the network", Snackbar.LENGTH_SHORT);
                    } catch (UserNotFoundException e2) {
                        Snackbar.make(getView(), String.format("User %s does not exist", usr),
                                Snackbar.LENGTH_SHORT).show();
                    } catch (UserAlreadyAddedException e1) {
                        Snackbar.make(getView(), String.format("User %s is already added!", usr),
                                Snackbar.LENGTH_SHORT).show();
                    } catch (ServiceNotAvailableException e1) {
                        Snackbar.make(getView(), "You must be online to add friends!", Snackbar.LENGTH_SHORT)
                                .show();
                    }
                    return null;
                }
            };
            t.execute();
        }
    });
    builder.setTitle("Add a Friend");
    AlertDialog d = builder.create();
    return d;
}

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

private Dialog removeDialog(Context context) {

    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.remove_id, null);
    final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local);
    rm_check.setText(R.string.remove_local);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setView(textEntryView);//www.j a  v  a2 s .c  om
    builder.setCancelable(false);
    builder.setTitle(R.string.assign_remove_title);
    builder.setMessage(R.string.remove_msg);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub  

            cleanUp(ctx);//replace following

            //                    editor.putString(Utilities.SP_KEY_LOGIN_USERID, "");                       
            //                 editor.putString(Utilities.SP_KEY_LOGIN_USERPWD, "");
            //                 editor.putString(Utilities.SP_KEY_LOGIN_STUDY_STARTTIME, "");
            //                 editor.commit();

            // remove local file, if checked
            Log.d(TAG, "is checked " + rm_check.isChecked());
            if (rm_check.isChecked()) {
                deleteDirectory(Utilities.PHONE_BASE_PATH);
            }

            setHints();
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub  

        }
    });

    return builder.create();

}

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

private Dialog removeDialog(Context context) {

    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.remove_id, null);
    final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local);
    rm_check.setText(R.string.remove_local);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setView(textEntryView);/* w  ww .ja v  a  2  s. c  om*/
    builder.setCancelable(false);
    builder.setTitle(R.string.assign_remove_title);
    builder.setMessage(R.string.remove_msg);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

            cleanUp(ctx);

            cancelAlarms(ctx);

            // remove local file, if checked
            Log.d(TAG, "is checked " + rm_check.isChecked());
            if (rm_check.isChecked()) {
                deleteDirectory(Util.PHONE_BASE_PATH);
            }

            setHints();
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

        }
    });

    return builder.create();

}

From source file:com.mobicage.rogerthat.plugins.friends.RecommendServiceActivity.java

private void showFacebookErrorPopup() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(true);
    builder.setMessage(R.string.error_recommend_on_fb);
    builder.setPositiveButton(R.string.rogerthat, null);
    builder.create().show();//from   w w w .ja  v  a 2s . c om
}

From source file:com.sakisds.icymonitor.activities.AddNotificationActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button_cancel:
        finish();/* w  w  w .  j av a  2  s. c o m*/
        break;
    case R.id.button_add:
        addNotification();
        break;
    case R.id.button_notification_help:
        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);

        dlgAlert.setMessage(getString(R.string.notif_ring_once_help));
        dlgAlert.setPositiveButton("OK", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }
}

From source file:de.da_sense.moses.client.service.MosesService.java

/**
 * This function will be executed on first run and shows some welcome
 * dialog.// w w  w.  j a v  a 2 s  .co  m
 * 
 * @param context
 *            The context under which the dialog is shown.
 */
private void showWelcomeDialog(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    builder.setIcon(R.drawable.ic_launcher);
    builder.setCancelable(false); // This blocks the 'BACK' button
    builder.setMessage(getString(R.string.welcome_to_moses_string));
    builder.setTitle(getString(R.string.welcome_to_moses_title_string));
    builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
    Log.d("MoSeS.SERVICE", "First login.");
    PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("first_start", false).commit();
}