Example usage for android.app AlertDialog setButton

List of usage examples for android.app AlertDialog setButton

Introduction

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

Prototype

@Deprecated
public void setButton(CharSequence text, final OnClickListener listener) 

Source Link

Document

Set a listener to be invoked when button 1 of the dialog is pressed.

Usage

From source file:sssemil.com.hostsaway.ui.HostsSourcesFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info/*from   ww w  .j a  va 2s  .c  o m*/
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView urlTextView = (TextView) v.findViewWithTag("url_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_url_dialog, null);
    final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_url);
    // set text from list
    inputEditText.setText(urlTextView.getText());
    inputEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    // move cursor to end of EditText
    Editable inputEditContent = inputEditText.getText();
    inputEditText.setSelection(inputEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String input = inputEditText.getText().toString();

                    if (RegexUtils.isValidUrl(input)) {
                        // update in db
                        ProviderHelper.updateHostsSourceUrl(mActivity, mCurrentRowId, input);
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_url_title);
                        alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_url));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:sssemil.com.hostsaway.ui.WhitelistFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info/*from ww w .  j a  v  a 2  s. c o m*/
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    CheckBox cBox = (CheckBox) v.findViewWithTag(position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_whitelist_hostname_dialog, null);
    final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    inputEditText.setText(cBox.getText());

    // move cursor to end of EditText
    Editable inputEditContent = inputEditText.getText();
    inputEditText.setSelection(inputEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String input = inputEditText.getText().toString();

                    if (RegexUtils.isValidWhitelistHostname(input)) {
                        ProviderHelper.updateWhitelistItemHostname(mActivity, mCurrentRowId, input);
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

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

private void downloadServ(String srv) {
    try {//from  ww  w  .  ja  v  a 2s  .  c o m
        keepScreenOn.acquire();

        BufferedInputStream getit = new BufferedInputStream(new URL(srv).openStream());

        File file_teste = new File(TMP_SRV_FILE);
        if (file_teste.exists())
            file_teste.delete();

        FileOutputStream saveit = new FileOutputStream(TMP_SRV_FILE);
        BufferedOutputStream bout = new BufferedOutputStream(saveit, 1024);
        byte data[] = new byte[1024];

        int readed = getit.read(data, 0, 1024);
        while (readed != -1) {
            bout.write(data, 0, readed);
            readed = getit.read(data, 0, 1024);
        }

        keepScreenOn.release();

        bout.close();
        getit.close();
        saveit.close();
    } catch (Exception e) {
        AlertDialog p = new AlertDialog.Builder(this).create();
        p.setTitle(getText(R.string.top_error));
        p.setMessage(getText(R.string.aptoide_error));
        p.setButton(getText(R.string.btn_ok), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        p.show();
    }
}

From source file:no.ntnu.idi.socialhitchhiking.Main.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {//from  w  ww. java 2s. co  m
        initLoadingScreen();
        new Thread() {
            public void run() {
                setConnection(Main.this);
                user = getApp().getUser();
                if (user == null) {
                    loginButtonClicked();
                } else {
                    initMainScreen();
                    if (!isSession()) {
                        resetSession();
                    }
                }
            }
        }.start();
    } catch (Exception e) {
        AlertDialog ad = new AlertDialog.Builder(Main.this).create();
        ad.setTitle("Server error");
        ad.setMessage(
                "The server is not responding.. Please try again later or contact the system administrator.");
        ad.setButton("Ok", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
                System.exit(0);
            }
        });
        ad.show();
    }

}

From source file:fm.smart.r1.activity.CreateExampleActivity.java

public void onWindowFocusChanged(boolean bool) {
    super.onWindowFocusChanged(bool);
    Log.d("DEBUG", "onWindowFocusChanged");
    if (CreateExampleActivity.create_example_result != null) {
        synchronized (CreateExampleActivity.create_example_result) {
            final AlertDialog dialog = new AlertDialog.Builder(this).create();
            final boolean success = CreateExampleActivity.create_example_result.success();
            dialog.setTitle(CreateExampleActivity.create_example_result.getTitle());
            dialog.setMessage(CreateExampleActivity.create_example_result.getMessage());
            CreateExampleActivity.create_example_result = null;
            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // TODO avoid moving to item view if previous thread was
                    // interrupted? create_example.isInterrupted() but need
                    // user to be aware if we
                    // have created example already - progress dialog is set
                    // cancelable, so back button will work? maybe should
                    // avoid encouraging cancel
                    // on POST operations ... not sure what to do if no
                    // response from server - guess we will time out
                    // eventually ...
                    if (success) {
                        // want to go back to individual item screen now ...
                        ItemListActivity.loadItem(CreateExampleActivity.this, item_id);
                    }//from w  w w  .  ja va2 s. c  o  m
                }
            });
            dialog.show();

        }
    }
}

From source file:com.example.SimpleTestClient.Activities.TestMainActivity.java

private void showInformationBox() {
    if (this.showingQuestion != null) {
        String msg = "";
        String title = "";
        if (this.showingQuestion.getQuestionModel().Type == QuestionBase.QuestionType.SingleChoice) {
            msg = getResources().getString(R.string.info_question_singleChoice);
            title = "? ?  ";
        }//ww  w .  j a v a 2 s .  c  o  m
        if (this.showingQuestion.getQuestionModel().Type == QuestionBase.QuestionType.MultiChoice) {
            msg = getResources().getString(R.string.info_question_multiChoice);
            title = "? ? ? ";
        }
        if (this.showingQuestion.getQuestionModel().Type == QuestionBase.QuestionType.TextQuestion) {
            msg = getResources().getString(R.string.info_question_textChoice);
            title = "? ?     ?";
        }

        AlertDialog ad = new AlertDialog.Builder(this).create();
        ad.setIcon(R.drawable.ic_action_about);
        ad.setTitle(title);
        //  ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage(msg);
        ad.setButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        ad.show();

    }
}

From source file:org.adawaycn.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info/*from   w ww  . j  a v  a  2 s .  c  o  m*/
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (org.adawaycn.util.RegexUtils.isValidHostname(hostname)) {
                        if (org.adawaycn.util.RegexUtils.isValidIP(ip)) {
                            org.adawaycn.provider.ProviderHelper.updateRedirectionListItemHostnameAndIp(
                                    mActivity, mCurrentRowId, hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.loadsensing.app.LoginActivity.java

public void onClick(View v) {

    // this gets the resources in the xml file
    // and assigns it to a local variable of type EditText
    EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
    EditText passwordEditText = (EditText) findViewById(R.id.txt_password);

    // the getText() gets the current value of the text box
    // the toString() converts the value to String data type
    // then assigns it to a variable of type String
    String sUserName = usernameEditText.getText().toString();
    String sPassword = passwordEditText.getText().toString();

    // Definimos constructor de alerta para los avisos posteriores
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog = new AlertDialog.Builder(this).create();

    // call the backend using Get parameters
    String address = SERVER_HOST + "?user=" + sUserName + "&pass=" + sPassword + "";

    if (sUserName.equals("") || sPassword.equals("")) {
        // error alert
        alertDialog.setTitle(getResources().getString(R.string.error));
        alertDialog.setMessage(getResources().getString(R.string.empty_fields));
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }/*from   w  w  w  .  j av a 2s  .c  o  m*/
        });
        alertDialog.show();
    } else if (!checkConnection(this.getApplicationContext())) {
        alertDialog.setTitle(getResources().getString(R.string.error));
        alertDialog.setMessage(getResources().getString(R.string.error_no_internet));
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        alertDialog.show();
    } else {
        try {
            showBusyCursor(true);
            progress = ProgressDialog.show(this, getResources().getString(R.string.pantalla_espera_title),
                    getResources().getString(R.string.iniciando_sesion), true);

            Log.d(DEB_TAG, "Requesting to " + address);

            JSONObject json = JsonClient.connectJSONObject(address);

            CheckBox rememberUserPassword = (CheckBox) findViewById(R.id.remember_user_password);
            if (rememberUserPassword.isChecked()) {
                setSharedPreference("login", sUserName);
                setSharedPreference("password", sPassword);
            } else {
                setSharedPreference("login", "");
                setSharedPreference("password", "");
            }

            if (json.getString("session") != "0") {
                progress.dismiss();
                // Guardamos la session en SharedPreferences para utilizarla
                // posteriormente
                setSharedPreference("session", json.getString("session"));
                // Sessin correcta. StartActivity de la home
                Intent intent = new Intent();
                intent.setClass(this.getApplicationContext(), HomeActivity.class);
                startActivity(intent);

            } else {
                progress.dismiss();
                alertDialog.setTitle(getResources().getString(R.string.error));
                alertDialog.setMessage(getResources().getString(R.string.error_login));
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
                alertDialog.show();
            }

        } catch (JSONException e) {
            progress.dismiss();
            Log.d(DEB_TAG, "Error parsing data " + e.toString());
        }

        showBusyCursor(false);
    }
}

From source file:org.adaway.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info/*from www  .j av a 2s  .  c o m*/
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (RegexUtils.isValidHostname(hostname)) {
                        if (RegexUtils.isValidIP(ip)) {
                            ProviderHelper.updateRedirectionListItemHostnameAndIp(mActivity, mCurrentRowId,
                                    hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(org.adaway.R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(org.adaway.R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.repolist);//w w w .  ja va2s  .c  o  m

    db = new DbHandler(this);

    Intent i = getIntent();
    if (i.hasExtra("empty")) {
        final String uri = i.getStringExtra("uri");
        AlertDialog alrt = new AlertDialog.Builder(this).create();
        alrt.setTitle(getString(R.string.title_repo_alrt));
        alrt.setIcon(android.R.drawable.ic_dialog_alert);
        alrt.setMessage(getString(R.string.myrepo_alrt) + uri);
        alrt.setButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                db.addServer(uri);
                change = true;
                redraw();
                return;
            }
        });
        alrt.setButton2("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        alrt.show();
    } else if (i.hasExtra("uri")) {
        String uri = i.getStringExtra("uri");
        Vector<String> new_serv_lst = getRemoteServLst(uri);
        for (final String srv : new_serv_lst) {
            AlertDialog alrt = new AlertDialog.Builder(this).create();
            alrt.setTitle(getString(R.string.title_repo_alrt));
            alrt.setIcon(android.R.drawable.ic_dialog_alert);
            alrt.setMessage(getString(R.string.newrepo_alrt) + srv);
            alrt.setButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    db.addServer(srv);
                    change = true;
                    redraw();
                    return;
                }
            });
            alrt.setButton2("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    return;
                }
            });
            alrt.show();
        }
    } else if (i.hasExtra("newrepo")) {
        final String repo = i.getStringExtra("newrepo");
        AlertDialog alrt = new AlertDialog.Builder(this).create();
        alrt.setTitle(getString(R.string.title_repo_alrt));
        alrt.setIcon(android.R.drawable.ic_dialog_alert);
        alrt.setMessage(getString(R.string.newrepo_alrt) + repo);
        alrt.setButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                db.addServer(repo);
                change = true;
                redraw();
                return;
            }
        });
        alrt.setButton2("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //exit
            }
        });
        alrt.show();
    }
}