Example usage for android.app AlertDialog.Builder create

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

Introduction

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

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:ws.crandell.newspaperpuzzles.wordsearch.view.WordSearchActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//w w  w.  j ava 2s . c  o m
    switch (id) {
    case DIALOG_ID_NO_WORDS: {
        final DialogNoWordsListener DIALOG_LISTENER_NO_WORDS = new DialogNoWordsListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_no_words);
        builder.setNegativeButton(R.string.ws_category, DIALOG_LISTENER_NO_WORDS);
        builder.setPositiveButton(R.string.ws_new_game, DIALOG_LISTENER_NO_WORDS);
        builder.setNeutralButton(R.string.ws_size, DIALOG_LISTENER_NO_WORDS);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_NO_WORDS_CUSTOM: {
        final DialogNoWordsCustomListener DIALOG_LISTENER_NO_WORDS_CUSTOM = new DialogNoWordsCustomListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_no_words_custom);
        builder.setNegativeButton(R.string.ws_category, DIALOG_LISTENER_NO_WORDS_CUSTOM);
        builder.setPositiveButton(R.string.ws_custom_editor, DIALOG_LISTENER_NO_WORDS_CUSTOM);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_GAME_OVER: {
        final DialogGameOverListener DIALOG_LISTENER_GAME_OVER = new DialogGameOverListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("blank");
        EditText text = new EditText(this);
        text.setSingleLine();
        text.setId(android.R.id.input);
        builder.setView(text);
        builder.setPositiveButton(R.string.ws_SAVE_SUBMIT, DIALOG_LISTENER_GAME_OVER);
        builder.setNeutralButton(R.string.ws_SAVE, DIALOG_LISTENER_GAME_OVER);
        builder.setOnCancelListener(DIALOG_LISTENER_GAME_OVER);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_HIGH_SCORES_LOCAL_SHOW: {
        final DialogHighScoresLocalShowListener DIALOG_LISTENER_HIGH_SCORES_SHOW = new DialogHighScoresLocalShowListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("blank");
        builder.setTitle(R.string.ws_LOCAL_HIGH_SCORES);
        builder.setNegativeButton(R.string.ws_reset, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        builder.setNeutralButton(android.R.string.ok, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        builder.setPositiveButton(R.string.ws_GLOBAL, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_GAME_NEW: {
        final DialogGameNewListener DIALOG_LISTENER_GAME_NEW = new DialogGameNewListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(this.getString(R.string.ws_game_over));
        builder.setPositiveButton(R.string.ws_new_game, DIALOG_LISTENER_GAME_NEW);
        builder.setNeutralButton(R.string.ws_REPLAY, DIALOG_LISTENER_GAME_NEW);
        builder.setNegativeButton(android.R.string.cancel, DIALOG_LISTENER_GAME_NEW);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_INTRO_INPUT_TYPE: {
        final DialogIntroListener DIALOG_LISTENER_INTRO = new DialogIntroListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_INTRO);
        builder.setPositiveButton(R.string.ws_tap, DIALOG_LISTENER_INTRO);
        builder.setNeutralButton(android.R.string.cancel, DIALOG_LISTENER_INTRO);
        builder.setNegativeButton(R.string.ws_drag, DIALOG_LISTENER_INTRO);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_INTRO_DONATE: {
        final DialogInterface.OnClickListener LISTENER = new DialogIntroDonateListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_INTRO_DONATE_MSG);
        builder.setPositiveButton(R.string.ws_DONATE, LISTENER);
        builder.setNegativeButton(R.string.ws_DONATE_NO, LISTENER);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_DONATE: {
        final DialogInterface.OnClickListener LISTENER = new DialogDonateListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_DONATE_MSG);
        builder.setPositiveButton(R.string.ws_DONATE_MARKET, LISTENER);
        builder.setNeutralButton(R.string.ws_DONATE_WEB, LISTENER);
        builder.setNegativeButton(R.string.ws_DONATE_NO, LISTENER);
        dialog = builder.create();
        break;
    }
    default:
        dialog = super.onCreateDialog(id);
        break;
    }
    return dialog;
}

From source file:com.honeycomb.cocos2dx.Soccer.java

public void askForRate(JSONObject prms) {
    AlertDialog.Builder exitbuilder = new AlertDialog.Builder(this);
    exitbuilder.setTitle("Rate 2 Planes").setMessage(com.honeycomb.cocos2dx.R.string.Rate).setCancelable(false)
            .setPositiveButton("Rate It Now", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    rateButtonClicked(getDict());
                }/*from   w  w  w. j  a v  a 2 s. co m*/
            }).setNegativeButton("No,Thanks", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    AndroidNDKHelper.SendMessageWithParameters("rated", getDict());
                }
            });
    AlertDialog stopalert = exitbuilder.create();
    stopalert.show();
}

From source file:com.mono.applink.Foursquare.java

/** Called when the activity is first created. */
@Override//  ww  w  .  j  av  a 2  s  .co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final String url = getIntent().getData().toString();

    if (url.contains("user"))//user with id
    {
        new FoursquareUser().execute();
    } else if (url.contains("venue")) {
        new FoursquareVenue().execute();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Sorry, but this type of link is not currently supported");
        builder.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        builder.setPositiveButton("Open in Browser", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = new Intent();
                i.setAction("android.intent.action.VIEW");
                i.addCategory("android.intent.category.BROWSABLE");
                i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setData(Uri.parse(url));
                startActivity(i);
                finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }

}

From source file:com.jesjimher.bicipalma.MesProperesActivity.java

/**
 * /*from   w w  w . j a  va 2s . c o  m*/
 */
private void mostrarEstadisticas() {
    int bTot = 0;
    int bAver = 0;
    int aAver = 0;
    int bLib = 0;
    int aLib = 0;
    int noBicis = 0;

    for (Estacion e : estaciones) {
        bTot += e.getAnclajesAveriados() + e.getAnclajesLibres() + e.getAnclajesUsados();
        bAver += e.getBicisAveriadas();
        aAver += e.getAnclajesAveriados();
        bLib += e.getBicisLibres();
        aLib += e.getAnclajesLibres();
        if (e.getBicisLibres() == 0)
            noBicis++;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // Si el n de bicis es negativo, es q an no se han descargado los datos
    if (bLib < 0) {
        builder.setMessage(R.string.sinDescargaTodavia).setCancelable(true).setPositiveButton(R.string.cerrar,
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    } else {
        String mensBicis = String.format(getString(R.string.estadisticasBicis), bLib, bAver);
        String mensAnclajes = String.format(getString(R.string.estadisticasAnclajes), bTot,
                bTot - (aLib + aAver), 100 * (1 - aLib / (0.0 + bTot - aAver)), aLib,
                100 * aLib / (0.0 + bTot - aAver), aAver, 100 * aAver / Double.valueOf(bTot));

        String mensVacias = String.format(getString(R.string.estadisticasVacias), noBicis, estaciones.size());

        builder.setMessage(mensBicis + mensAnclajes + mensVacias).setTitle(R.string.estadoservicio)
                .setCancelable(true).setPositiveButton(R.string.cerrar, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:com.dwdesign.tweetings.fragment.BaseStatusesListFragment.java

protected void translate(final ParcelableStatus status) {
    ThreadPolicy tp = ThreadPolicy.LAX;
    StrictMode.setThreadPolicy(tp);/*from ww w. ja v  a2  s  . c  o  m*/

    String language = Locale.getDefault().getLanguage();
    String url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?contentType="
            + URLEncoder.encode("text/plain") + "&appId=" + BING_TRANSLATE_API_KEY + "&from=&to=" + language
            + "&text=";
    url = url + URLEncoder.encode(status.text_plain);
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(new HttpGet(url));

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String sResponse;
        StringBuilder s = new StringBuilder();

        while ((sResponse = reader.readLine()) != null) {
            s = s.append(sResponse);
        }
        String finalString = s.toString();
        finalString = finalString
                .replace("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", "");
        finalString = finalString.replace("</string>", "");

        AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
        builder.setTitle(getString(R.string.translate));
        builder.setMessage(finalString);
        builder.setCancelable(true);
        builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });

        AlertDialog alert = builder.create();
        alert.show();

        //Toast.makeText(getActivity(), finalString, Toast.LENGTH_LONG).show();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.bti360.hackathon.listview.HackathonActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case ADD_DIALOG:
        // We are going to create an AlertDialog with a single text input and a button
        // first we create the EditText
        final EditText edit = new EditText(this);
        // Next we create an AlertDialog.Builder which creates a styled AlertDialog based
        // on our specifications;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // set the title
        builder.setTitle("Add Person");
        // set the icon to a built-in, this one is a +
        builder.setIcon(android.R.drawable.ic_input_add);
        // set the text of the only button, and add a click listener
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            @Override//from   w ww.  j  ava  2 s .c om
            public void onClick(DialogInterface dialog, int which) {
                // on the Ok Button we grab the text from the EditText,
                // clear it and then add the Name to our list
                String name = edit.getText().toString();
                edit.setText("");
                addName(name);
            }
        });
        // finally let's create the dialog
        final AlertDialog d = builder.create();
        // and set the view to our EditText
        d.setView(edit);

        // we'll set a special InputType since we are collecting a name
        // other's exist such as email, address, phone number, etc
        // this allows the IME (keyboard) to customize itself based on
        // expected input, e.g. show @ and .com when Email
        edit.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
        // Respond to the default action on the IME (keyboard) By default it is
        // "Done" but it can be changed with setImeActionLabel to be something
        // else like a search hourglass.
        // In our case we want a click on "Done" to do the same thing as a click
        // on the Ok button in the Dialog.
        edit.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView tv, int actionId, KeyEvent arg2) {
                // same as the DialogClick Handler except we also dismiss the dialog
                String name = edit.getText().toString();
                edit.setText("");
                addName(name);
                d.dismiss();
                return true;
            }
        });
        return d;
    }
    return super.onCreateDialog(id);
}

From source file:com.nokia.example.capturetheflag.Controller.java

@Override
public void onError(JSONResponse error) {
    Log.w(TAG, "onError()");

    AlertDialog.Builder errordialog = new AlertDialog.Builder(getActivity());
    errordialog.setTitle("Error");

    if (error.getErrorCode() == JSONResponse.ERROR_GAME_FULL) {
        errordialog.setMessage(getString(R.string.game_full));
    } else if (error.getErrorCode() == JSONResponse.ERROR_EXCEPTION) {
        errordialog.setMessage(error.getException().getMessage());
    }/*from ww w .j  a va2 s. c  o m*/

    errordialog.setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            MainActivity m = (MainActivity) getActivity();
            m.showGameMenu(null);
        }
    });

    errordialog.create().show();
}

From source file:com.radicaldynamic.groupinform.activities.AccountFolderList.java

@Override
protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    Dialog dialog = null;//from w  w  w .ja v a 2s .  c  o  m

    switch (id) {
    case DIALOG_DENIED_NOT_OWNER:
        builder.setIcon(R.drawable.ic_dialog_info).setTitle(R.string.tf_unable_to_edit_folder_not_owner_title)
                .setMessage(R.string.tf_unable_to_edit_folder_not_owner_msg)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        dialog = builder.create();
        break;

    case DIALOG_MORE_INFO:
        String message = "Owner:\n" + mFolder.getOwnerAlias() + "\n\n";
        message = message + "Description:\n" + mFolder.getDescription();

        builder.setIcon(R.drawable.ic_dialog_info).setTitle(mFolder.getName()).setMessage(message)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        removeDialog(DIALOG_MORE_INFO);
                    }
                });

        dialog = builder.create();
        break;
    }

    return dialog;
}

From source file:com.mono.applink.Twitter.java

/** Called when the activity is first created. */
@Override/*from   w  ww  . java  2s .  com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final String url = getIntent().getData().toString();

    if (url.contains("twitter.com") && !url.contains("status") && !url.contains("direct_messages")
            && !url.contains("user_spam_reports") && !url.contains("account") && !url.contains("settings"))//Just if it is a link of a user profile
    {
        new TwitterUser().execute();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Sorry, but this type of link is not currently supported");
        builder.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        builder.setPositiveButton("Open in Browser", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = new Intent();
                i.setAction("android.intent.action.VIEW");
                i.addCategory("android.intent.category.BROWSABLE");
                i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setData(Uri.parse(url));
                startActivity(i);
                finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

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

/**
 * Display an error about failing to load playground data. Called by
 * displayErrorTask//from w w  w .  j ava 2  s  . c o m
 */
protected void displayPlaygroundLoadError() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // builder.setTitle("ERROR");

    builder.setMessage("Error loading playgrounds");
    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);
}