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:com.findme.adapter.ImageListAdapter.java

@Override
public View getView(int position, View view, ViewGroup viewGroup) {

    // We only create the view if its needed
    if (view == null) {
        view = inflator.inflate(R.layout.image_list_child, null);
        // Set the click listener for the checkbox
        // view.findViewById(R.id.isSelectedCheckBox).setOnClickListener(this);
    } else/*from ww w  .  j  a  v  a2  s.com*/
        return view;
    final JSONObject personInfo = (JSONObject) getItem(position);
    String imgUrl = null;
    try {
        imgUrl = prefix + personInfo.getJSONArray("images").getString(0);
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    Log.d("image", imgUrl);
    count++;
    Log.d("Result", String.valueOf(count));
    final ImageButton img = (ImageButton) view.findViewById(R.id.appImageView1);
    URL url;
    Bitmap bmp = null;
    (new DownloadImageTask(img)).execute(imgUrl);

    img.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            AlertDialog.Builder builder = new AlertDialog.Builder(mainAct);
            View view = LayoutInflater.from(mainAct).inflate(R.layout.popup_layout, null);

            ImageView image = (ImageView) view.findViewById(R.id.resultDialogImg);

            /**
             * Not sure about the license of PhotoViewAttacher
             * TODO : look into the license of this and decide whether to use it or not.
             */

            image.setImageDrawable(img.getDrawable());
            PhotoViewAttacher mAttacher = new PhotoViewAttacher(image);
            mAttacher.update();
            //builder.setIcon(mainAct.getResources().getDrawable(mainAct.getResources().getIdentifier(app.getImage(), "drawable", mainAct.getPackageName())));
            builder.setView(view);
            builder.setPositiveButton(R.string.match_found, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    try {
                        (new AsyncHttpPostTask(prefix)).execute(personInfo.getString("personname"));
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });

            builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // User clicked OK. Start a new game.
                    dialog.dismiss();
                }
            });

            builder.create().show();
        }
    });
    return view;
}

From source file:com.hybris.mobile.app.commerce.adapter.CartProductListAdapter.java

/**
 * Display the delete item dialog// w w  w  .  ja  v a  2 s .c  om
 *
 * @param positionToDelete
 */
private void showDeleteItemDialog(final int positionToDelete) {

    // Creating the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(
            new ContextThemeWrapper(getContext(), R.style.AlertDialogCustom));
    builder.setMessage(R.string.cart_menu_delete_item_confirmation_title).setPositiveButton(
            R.string.cart_menu_delete_item_remove_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    QueryCartEntry queryCartEntry = new QueryCartEntry();
                    queryCartEntry.setEntryNumber(positionToDelete + "");

                    CommerceApplication.getContentServiceHelper()
                            .deleteCartEntry(new ResponseReceiver<CartModification>() {
                                @Override
                                public void onResponse(Response<CartModification> response) {
                                    updateCart();
                                }

                                @Override
                                public void onError(Response<ErrorList> response) {
                                    UIUtils.showError(response, getContext());

                                    // Update the cart
                                    SessionHelper.updateCart(getContext(), mRequestId, false);
                                }
                            }, mRequestId, queryCartEntry, null, false, null, mOnRequestListener);
                }
            }).setNegativeButton(R.string.cancel, null);

    AlertDialog alert = builder.create();

    // The dialog is cancelable by 3 ways: cancel button, click outside the dialog, click on the back button
    alert.setCancelable(true);
    alert.setCanceledOnTouchOutside(true);
    alert.setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            // We revert to the default quantity when we dismiss the dialog
            if (mSelectedQuantity != null) {
                mSelectedQuantity.getEditText().clearFocus();
                mSelectedQuantity.getEditText().setText(mSelectedQuantity.getDefaultValue() + "");
            }
        }
    });

    alert.show();
}

From source file:com.appdupe.flamer.LoginUsingFacebook.java

private void ErrorMessageLocationNotFonr(String title, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(LoginUsingFacebook.this);
    builder.setTitle(title);/*from  w w  w .  java  2 s  . c o m*/
    builder.setMessage(message);

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

    AlertDialog alert = builder.create();
    alert.setCancelable(false);
    alert.show();
}

From source file:com.appdupe.flamer.LoginUsingFacebook.java

/**
 * Showing an alert dialog to usre in case of any error.
 * //  www . j  av a  2 s .c  om
 * @param title
 *            - title for the dialog.
 * @param message
 *            - error message.
 */
private void ErrorMessage(String title, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(LoginUsingFacebook.this);
    builder.setTitle(title);
    builder.setMessage(message);

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

                    dialog.dismiss();
                }
            });

    AlertDialog alert = builder.create();
    alert.setCancelable(false);
    alert.show();
}

From source file:it.feio.android.omninotes.async.UpdaterTask.java

private void promptUpdate() {

    // Confirm dialog creation
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivityReference.get());
    alertDialogBuilder.setCancelable(false).setMessage(R.string.new_update_available)
            .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {

                @Override//from   ww  w .j  a v a 2 s. c  o m
                public void onClick(DialogInterface dialog, int id) {
                    if (isGooglePlayAvailable()) {
                        mActivityReference.get().startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("market://details?id=" + packageName)));
                    } else {

                        // MapBuilder.createEvent().build() returns a Map of event fields and values
                        // that are set and sent with the hit.
                        OmniNotes.getGaTracker().send(MapBuilder.createEvent("ui_action", // Event category (required)
                                "button_press", // Event action (required)
                                "Google Drive Update", // Event label
                                null) // Event value
                                .build());

                        mActivityReference.get().startActivity(
                                new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.DRIVE_FOLDER_LAST_BUILD)));
                    }

                    dialog.dismiss();
                }
            }).setNegativeButton(R.string.not_now, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java

private void showDisableMessage() {

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());

    // set title/*from w  ww .ja va2s .co  m*/
    alertDialogBuilder.setTitle("Join the Inner Circle!");

    // set dialog message
    alertDialogBuilder.setMessage("This feature is not available in the Beta version.").setCancelable(false)
            .setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
}

From source file:co.dilaver.quoter.fragments.PopularFragment.java

private void showAlertDialog(final int pos) {
    CharSequence[] items = { getString(R.string.str_Save), getString(R.string.str_Share),
            getString(R.string.str_Copy) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                SharedPrefStorage sharedPrefStorage = new SharedPrefStorage(getActivity());
                Gson gson = new Gson();

                if (!MyApplication.savedQuotesList.contains(popularQuotesList.get(pos))) {
                    MyApplication.savedQuotesList.add(popularQuotesList.get(pos));
                    sharedPrefStorage.setSavedQuotes(gson.toJson(MyApplication.savedQuotesList));
                }/*from  w  w  w . j a  v  a 2s. c o  m*/

                Snackbar.make(rootLayout, getString(R.string.str_AddedToFavoriteQuotes), Snackbar.LENGTH_SHORT)
                        .show();
            } else if (item == 1) {
                Intent shareIntent = new Intent(getActivity(), ShareActivity.class);
                shareIntent.putExtra("quote", popularQuotesList.get(pos).getQuoteText());
                shareIntent.putExtra("author", popularQuotesList.get(pos).getQuoteAuthor());
                startActivity(shareIntent);
            } else if (item == 2) {
                ClipboardManager clipboard = (ClipboardManager) getActivity()
                        .getSystemService(Activity.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("Copied Text", popularQuotesList.get(pos).getQuoteText()
                        + " - " + popularQuotesList.get(pos).getQuoteAuthor());
                clipboard.setPrimaryClip(clip);

                Snackbar.make(rootLayout, getString(R.string.str_QuoteCopied), Snackbar.LENGTH_SHORT).show();
            }
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:eu.operando.proxy.filters.domain.DomainFiltersActivity.java

@OnClick(R.id.add_filter)
public void addFilter() {

    if (viewSelected == 0) { //User Filter

        View dialogView = getLayoutInflater().inflate(R.layout.user_domain_filter_dialog, null);
        final EditText input = (EditText) dialogView.findViewById(R.id.filter_content);
        final CheckBox isWildcard = (CheckBox) dialogView.findViewById(R.id.is_wildcard);

        AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("New DomainFilter")
                .setView(dialogView)//from   w  ww. jav  a2s . c om
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        DomainFilter domainFilter = new DomainFilter();
                        domainFilter.setContent(input.getText().toString().toLowerCase());
                        domainFilter.setSource(null);
                        domainFilter.setIsWildcard(isWildcard.isChecked());
                        db.createDomainFilter(domainFilter);
                        updateFiltersList();
                        userDomainFiltersAdapter.notifyItemInserted(userFilters.size() - 1);
                        recyclerView.scrollToPosition(userFilters.size() - 1);
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                });

        final AlertDialog dialog = builder.create();

        input.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable s) {
                if (Patterns.DOMAIN_NAME.matcher(s).matches()) {
                    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
                } else
                    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
        });

        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }
        });

        dialog.show();

    } else { //Imported filter list
        final EditText input = new EditText(this);
        input.setSingleLine(true);
        input.setHint("Enter URL");
        new AlertDialog.Builder(this).setTitle("Import filters from remote file (hosts file format)")
                .setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        final String importUrl = input.getText().toString();
                        importExternalFilters(importUrl);

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                }).show();
    }
}

From source file:com.safecell.ManageProfile_Activity.java

void displayDialog(String title, String inputText, final int position) {

    LayoutInflater li = LayoutInflater.from(this);
    View dialogView = li.inflate(R.layout.dialog_edittext_input, null);

    dialogInputEditText = (EditText) dialogView.findViewById(R.id.DialogEditTextInputEditText);
    dialogInputEditText.setText(inputText);
    dialogInputEditText.setInputType(setInputTypeKeyBoard(position));

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(title).setInverseBackgroundForced(true).setView(dialogView).setCancelable(false)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    String text = dialogInputEditText.getText().toString();
                    if (!text.equalsIgnoreCase("")) {
                        if (position == 2) {
                            if (validationForEmailAddress(text)) {
                                setDialogValuesListArrayAdapter(position);
                                dialog.cancel();
                            } else {
                                dialog.cancel();
                            }/*from  w  ww .  j  a va 2  s  .  com*/
                        } else {
                            setDialogValuesListArrayAdapter(position);
                            dialog.cancel();
                        }
                    } else {
                        Toast.makeText(context, "Blank not allowed.", Toast.LENGTH_SHORT).show();
                    }

                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
    alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}

From source file:com.pentacog.mctracker.MCServerTrackerActivity.java

/**
 * Performs request for data from the server
 * @param server Server object to populate with data
 *///from   w  ww.  j ava  2 s .c  o  m
private void getServerData(Server server) {
    final ProgressDialog dialog = ProgressDialog.show(this, "", "Requesting Server Info", true);
    GetServerDataTask task = new GetServerDataTask(server, new GetServerDataTask.ServerDataResultHandler() {

        @SuppressWarnings("unchecked")
        @Override
        public void onServerDataResult(final Server server, String result) {
            dialog.dismiss();
            if (result == null) {
                serverList.add(server);
                new SaveServerListTask(getApplicationContext()).execute(serverList.getServerList());
                updateListView();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(MCServerTrackerActivity.this);
                builder.setMessage("Failed to contact server\n" + result);
                builder.setPositiveButton("Try Again", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        getServerData(server);
                    }
                });
                builder.setNegativeButton("Cancel", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.setNeutralButton("Back", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        Intent addServer = new Intent(MCServerTrackerActivity.this, AddServerActivity.class);
                        addServer.putExtra(Server.SERVER_ID, server.id);
                        addServer.putExtra(Server.SERVER_NAME, server.name);
                        addServer.putExtra(Server.SERVER_ADDRESS, server.address);
                        addServer.putExtra(Server.SERVER_PORT, "" + server.port);

                        startActivityForResult(addServer, AddServerActivity.ADD_SERVER_ACTIVITY_ID);
                    }
                });

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

    task.execute();
}