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:no.ntnu.idi.socialhitchhiking.myAccount.MyAccountPreferences.java

/**
 * Called when the button "Set Facebook privacy" is clicked. Opens an AlertDialog where the user selects a privacy setting.
 * @param view//  w ww .j av a  2  s .  co m
 */
public void btnFacebookClicked(View view) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Set Privacy");
    builder.setSingleChoiceItems(R.array.privacy_setting, selectedPrivacy,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    selectedPrivacy = item;
                }
            });
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            switch (selectedPrivacy) {
            case 0:
                privacyPreference = Visibility.FRIENDS;
                facebookPrivacy = "Friends";
                break;
            case 1:
                privacyPreference = Visibility.FRIENDS_OF_FRIENDS;
                facebookPrivacy = "Friends of friends";
                break;
            case 2:
                privacyPreference = Visibility.PUBLIC;
                facebookPrivacy = "Public";
                break;
            default:
                break;
            }
            // Setting button text
            btnFacebook.setText(Html.fromHtml("<b align = left><big>" + "Set Facebook privacy" + "</big></b>"
                    + "<br />" + facebookPrivacy + "<br />"));

            // Writing data to SharedPreferences
            getApp().getSettings().setFacebookPrivacy(privacyPreference);
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();

}

From source file:com.vuze.android.remote.AppPreferences.java

public void showRateDialog(final Activity mContext) {

    if (!shouldShowRatingReminder()) {
        return;//  w  w  w  .ja va 2  s  .c  om
    }

    // skip showing if they are adding a torrent (or anything else)
    Intent intent = mContext.getIntent();
    if (intent != null) {
        Uri data = intent.getData();
        if (data != null) {
            return;
        }
    }

    // even if something goes wrong, we want to set that we asked, so
    // it doesn't continue to pop up
    setAskedRating();

    Dialog dialog = new Dialog(mContext);

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setMessage(R.string.ask_rating_message).setCancelable(false)
            .setPositiveButton(R.string.rate_now, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String appPackageName = mContext.getPackageName();
                    try {
                        mContext.startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("market://details?id=" + appPackageName)));
                    } catch (android.content.ActivityNotFoundException anfe) {
                        mContext.startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
                    }
                    VuzeEasyTracker.getInstance(mContext).sendEvent("uiAction", "Rating", "AskStoreClick",
                            null);
                }
            }).setNeutralButton(R.string.later, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(R.string.no_thanks, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    setNeverAskRatingAgain();
                }
            });
    dialog = builder.create();

    VuzeEasyTracker.getInstance(mContext).sendEvent("uiAction", "Rating", "AskShown", null);
    dialog.show();
}

From source file:pl.bcichecki.rms.client.android.dialogs.InboxMessageDetailsDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (message == null) {
        throw new IllegalStateException("Message has not been set!");
    }//w w w  . j a v a  2 s  .co m
    if (messagesRestClient == null) {
        throw new IllegalStateException("MessagesRestClient has not been set!");
    }
    if (inboxMessagesListAdapter == null) {
        throw new IllegalStateException("InboxMessagesListAdapter has not been set!");
    }

    context = getActivity();

    markRead();

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
    dialogBuilder.setTitle(R.string.dialog_inbox_message_details_title);
    dialogBuilder
            .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog_inbox_message_details, null));
    dialogBuilder.setNeutralButton(R.string.dialog_inbox_message_details_reply,
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    MessageRecipent messageRecipent = new MessageRecipent();
                    messageRecipent.setRecipent(message.getSender());
                    HashSet<MessageRecipent> messageRecipents = new HashSet<MessageRecipent>();
                    messageRecipents.add(messageRecipent);
                    Message replyMessage = new Message();
                    replyMessage.setSubject(
                            getString(R.string.dialog_inbox_message_details_re) + ": " + message.getSubject());
                    replyMessage.setRecipents(messageRecipents);

                    Log.d(getTag(), "Starting reply message activity...");
                    Intent newMessageIntent = new Intent(context, NewMessageActivity.class);
                    newMessageIntent.putExtra(MESSAGE_EXTRA, replyMessage);
                    startActivityForResult(newMessageIntent, REQUEST_CODE_SEND_MESSAGE);
                }
            });
    dialogBuilder.setPositiveButton(R.string.general_close, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Nothing to do...
        }
    });

    AlertDialog dialog = dialogBuilder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            TextView subjectTextView = (TextView) ((AlertDialog) dialog)
                    .findViewById(R.id.dialog_inbox_message_details_subject_text);
            subjectTextView.setText(message.getSubject());

            StringBuilder sender = new StringBuilder();
            if (message.getSender().getAddress() != null
                    && message.getSender().getAddress().getFirstName() != null
                    && message.getSender().getAddress().getLastName() != null) {
                sender.append(message.getSender().getAddress().getFirstName()).append(" ")
                        .append(message.getSender().getAddress().getLastName());
            } else {
                sender.append(message.getSender().getUsername());
            }

            TextView senderTextView = (TextView) ((AlertDialog) dialog)
                    .findViewById(R.id.dialog_inbox_message_details_sender_text);
            senderTextView.setText(sender.toString());

            TextView receivedDataTextView = (TextView) ((AlertDialog) dialog)
                    .findViewById(R.id.dialog_inbox_message_details_received_date_text);
            receivedDataTextView
                    .setText(AppUtils.getFormattedDateAsString(message.getDate(), Locale.getDefault()));

            TextView contentTextView = (TextView) ((AlertDialog) dialog)
                    .findViewById(R.id.dialog_inbox_message_details_content_text);
            contentTextView.setText(message.getContent());
        }
    });

    return dialog;
}

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

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    TextView selectedView = (TextView) ((View) (info.targetView)).findViewById(R.id.uri);
    final String repo_selected = selectedView.getText().toString();
    popupOptions popupOption = popupOptions.values()[item.getItemId()];
    switch (popupOption) {
    case EDIT_REPO:
        validateRepo(repo_selected, true);
        refreshReposList();/* w  w w. j  a  va  2s. co m*/
        break;

    case REMOVE_REPO:
        AlertDialog.Builder builder = new AlertDialog.Builder(theme);
        builder.setTitle(getString(R.string.remove_repo));
        builder.setIcon(R.drawable.ic_menu_close_clear_cancel);
        builder.setMessage(getString(R.string.remove_repo_confirm) + " " + repo_selected + " ?");
        builder.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                removeDisplayRepo(repo_selected.hashCode());
                alert3.dismiss();
                refreshReposList();
            }
        });
        builder.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                alert3.dismiss();
                return;
            }
        });
        alert3 = builder.create();
        alert3.show();

        break;

    default:
        break;
    }

    return super.onContextItemSelected(item);
}

From source file:org.csp.everyaware.offline.Map.java

/************************ ALERT DIALOG NO INTERNET AVAILABLE *************************************/

public void noConnectivityDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(R.string.alert_dialog_no_internet).setIcon(android.R.drawable.ic_dialog_info)
            .setTitle(R.string.app_name).setCancelable(false)
            .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }/*ww  w .j  a  v  a  2 s  . com*/
            });

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

From source file:com.saulcintero.moveon.fragments.History.java

public static void sendAction(final Activity act, int[] idList, String[] nameList, String[] activityList,
        String[] shortDescriptionList, String[] longDescriptionList) {
    ArrayList<Integer> positions = new ArrayList<Integer>();
    for (int p = 0; p < idList.length; p++) {
        String nameToSearch = osmFilesNameFromUploadPosition.get(p).substring(0,
                osmFilesNameFromUploadPosition.get(p).length() - 4);
        positions.add(ArrayUtils.indexOf(listOfFiles, nameToSearch));
    }// w  w  w . jav  a  2 s  .c om

    for (int j = 0; j < idList.length; j++) {
        final String name = nameList[j];
        final String activity = activityList[j];
        final String shortDescription = shortDescriptionList[j];
        final String longDescription = longDescriptionList[j];
        final String url = osmUrlsToShare.get(positions.get(j));
        Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        List<ResolveInfo> activities = act.getPackageManager().queryIntentActivities(sendIntent, 0);
        AlertDialog.Builder builder = new AlertDialog.Builder(act);
        builder.setTitle(act.getText(R.string.send_to) + " " + name + " " + act.getText(R.string.share_with));
        final ShareIntentListAdapter adapter = new ShareIntentListAdapter(act, R.layout.social_share,
                activities.toArray());
        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ResolveInfo info = (ResolveInfo) adapter.getItem(which);
                if (info.activityInfo.packageName.contains("facebook")) {
                    Intent i = new Intent("android.intent.action.PUBLISH_TO_FB_WALL");
                    i.putExtra("name", activity + " " + name);
                    i.putExtra("msg", String.format("%s", shortDescription));
                    i.putExtra("link", String.format("%s", url));
                    act.sendBroadcast(i);
                } else {
                    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                    intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                    intent.setType("text/plain");
                    if ((info.activityInfo.packageName.contains("twitter"))
                            || (info.activityInfo.packageName.contains("sms"))
                            || (info.activityInfo.packageName.contains("mms"))) {
                        intent.putExtra(Intent.EXTRA_TEXT, shortDescription + url);
                    } else {
                        intent.putExtra(Intent.EXTRA_TEXT, longDescription + url);
                    }
                    act.startActivity(intent);
                }
            }
        });
        builder.create().show();
    }
}

From source file:com.raceyourself.android.samsung.ProviderService.java

private void popupWaitingForGearDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("RaceYourself Gear Edition").setMessage(
            "Please launch RaceYourself on Gear.\n\nIf you have just installed RaceYourself, the icon may take a few moments to appear. \n\nIf you are waiting a while, make sure Gear Manager shows a connection to gear or try disabling/re-enabing bluetooth on Gear.")
            .setCancelable(false).setPositiveButton("Retry", new DialogInterface.OnClickListener() {
                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                        @SuppressWarnings("unused") final int id) {
                    new Handler().post(new Runnable() {
                        public void run() {
                            runUserInit();
                        }/*from   ww w.  j a v a 2  s .co  m*/
                    });
                }
            }).setNegativeButton("Quit", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    ProviderService.this.stopSelf();
                }
            });
    waitingAlert = builder.create();
    waitingAlert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    waitingAlert.show();
}

From source file:reportsas.com.formulapp.Formulario.java

public void HabilitarParametros(Menu menu) {
    for (int i = 0; i < encuesta.getParametros().size(); i++) {

        switch (encuesta.getParametros().get(i).getIdParametro()) {
        // Captura GPS
        case 1:/*from  w  w w.j a v a2 s  .c  o m*/

            menu.getItem(2).setVisible(true);
            parametroGPS = new ParametrosRespuesta(1);
            manejador = (LocationManager) getSystemService(LOCATION_SERVICE);
            if (!manejador.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                AlertDialog alert = null;
                final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("El sistema GPS esta desactivado, Debe activarlo!").setCancelable(false)
                        .setPositiveButton("Activar GPS", new DialogInterface.OnClickListener() {
                            public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                                    @SuppressWarnings("unused") final int id) {
                                startActivity(
                                        new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                            }
                        });
                alert = builder.create();
                alert.show();
            }
            Criteria criterio = new Criteria();
            criterio.setCostAllowed(false);
            criterio.setAltitudeRequired(false);
            criterio.setAccuracy(Criteria.ACCURACY_FINE);
            proveedor = manejador.getBestProvider(criterio, true);
            Location localizacion = manejador.getLastKnownLocation(proveedor);
            capturarLocalizacion(localizacion);
            manejador.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this);
            Toast toast1;
            if (parametroGPS.getValor().equals("Posicion Desconocida")) {
                toast1 = Toast.makeText(this, "Posicion Desconocida.", Toast.LENGTH_SHORT);

            } else {
                toast1 = Toast.makeText(this, "Localizacin obtenida exitosamente.", Toast.LENGTH_SHORT);

            }

            toast1.show();
            break;
        // Captura Imgen
        case 2:

            menu.getItem(0).setVisible(true);
            break;
        // Lectura de Codigo
        case 3:

            menu.getItem(1).setVisible(true);
            break;

        default:

            break;
        }

    }

}

From source file:com.markupartist.sthlmtraveling.PlannerFragment.java

private Dialog createDialogViaPoint() {
    AlertDialog.Builder viaPointDialogBuilder = new AlertDialog.Builder(getActivity());
    viaPointDialogBuilder.setTitle(getText(R.string.via));
    final Cursor historyViaCursor = mHistoryDbAdapter.fetchLatest();
    getActivity().startManagingCursor(historyViaCursor);
    final SelectPointAdapter viaPointAdapter = new SelectPointAdapter(getActivity(), historyViaCursor, true,
            true);//w w  w. java  2  s  .  co m
    getActivity().stopManagingCursor(historyViaCursor);
    viaPointDialogBuilder.setAdapter(viaPointAdapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            default:
                Site viaPoint = (Site) viaPointAdapter.getItem(which);
                mViaPoint = viaPoint;
                mViaPointAutoComplete.setText(mViaPoint.getName());
                mViaPointAutoComplete.clearFocus();
            }
        }
    });
    return viaPointDialogBuilder.create();
}

From source file:dev.memento.MementoBrowser.java

@Override
protected Dialog onCreateDialog(int id) {

    Dialog dialog = null;/*from  w ww.j ava 2 s  .co m*/
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    switch (id) {
    case DIALOG_DATE:
        dialog = new DatePickerDialog(this, mDateSetListener, mDateChosen.getYear(), mDateChosen.getMonth() - 1,
                mDateChosen.getDay());
        break;

    case DIALOG_ERROR:
        builder = new AlertDialog.Builder(this);
        builder.setMessage("error message").setCancelable(false).setPositiveButton("OK", null);
        dialog = builder.create();
        break;

    case DIALOG_MEMENTO_YEARS:
        builder = new AlertDialog.Builder(this);
        final CharSequence[] years = mMementos.getAllYears();

        // Select the year of the Memento currently displayed
        int selectedYear = -1;

        for (int i = 0; i < years.length; i++) {
            if (mDateDisplayed.getYear() == Integer.parseInt(years[i].toString())) {
                selectedYear = i;
                break;
            }
        }

        builder.setSingleChoiceItems(years, selectedYear, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                dialog.dismiss();

                mSelectedYear = Integer.parseInt(years[item].toString());
                showDialog(DIALOG_MEMENTO_DATES);
            }
        });

        dialog = builder.create();

        // Cause the dialog to be freed whenever it is dismissed.
        // This is necessary because the items are dynamic.  
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface arg0) {
                removeDialog(DIALOG_MEMENTO_YEARS);
            }
        });

        break;

    case DIALOG_MEMENTO_DATES:
        builder = new AlertDialog.Builder(this);

        final CharSequence[] dates;

        if (mSelectedYear == 0)
            dates = mMementos.getAllDates();
        else
            dates = mMementos.getDatesForYear(mSelectedYear);

        Log.d(LOG_TAG, "Number of dates = " + dates.length);

        // This shouldn't happen, but just in case.
        if (dates.length == 0) {
            showToast("No Mementos to select from.");
            return null;
        }

        int selected = -1;

        // Select the radio button for the current Memento if it's in the selected year.
        if (mSelectedYear == 0 || mSelectedYear == mDateDisplayed.getYear()) {

            int index = mMementos.getIndex(mDateDisplayed);
            if (index < 0)
                Log.d(LOG_TAG, "Could not find Memento in the list with date " + mDateDisplayed);
            else
                mMementos.setCurrentIndex(index);

            Memento m = mMementos.getCurrent();
            if (m != null) {
                for (int i = 0; i < dates.length; i++) {
                    if (m.getDateTime().dateAndTimeFormatted().equals(dates[i])) {
                        selected = i;
                        break;
                    }
                }
            } else
                Log.d(LOG_TAG, "There is no current Memento");
        }

        Log.d(LOG_TAG, "Selected index = " + selected);

        builder.setSingleChoiceItems(dates, selected, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                dialog.dismiss();

                int index = mMementos.getIndex(dates[item].toString());
                Memento m = mMementos.get(index);
                if (m == null) {
                    Log.e(LOG_TAG, "Could not find Memento with date " + mDateChosen + ".");
                    displayError("The date selected could not be accessed. Please select another.");
                } else {
                    // Display this Memento

                    Log.d(LOG_TAG, "index for [" + dates[item] + "] is " + index);

                    SimpleDateTime d = m.getDateTime();
                    setChosenDate(d);

                    if (index == mMementos.getCurrentIndex()) {
                        showToast("Memento is already displayed.");
                    } else {
                        mMementos.setCurrentIndex(index);
                        showToast("Time travelling to " + mDateChosen.dateFormatted());

                        // Find the Memento URL for the selected date                      

                        mDateDisplayed = new SimpleDateTime(mDateChosen);
                        String redirectUrl = m.getUrl();
                        Log.d(LOG_TAG, "Sending browser to " + redirectUrl);
                        mWebview.loadUrl(redirectUrl);

                        setEnableForNextPrevButtons();
                    }
                }
            }
        });

        dialog = builder.create();

        // Cause the dialog to be freed whenever it is dismissed.
        // This is necessary because the items are dynamic.  I couldn't find
        // a better way to solve this problem.
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface arg0) {
                removeDialog(DIALOG_MEMENTO_DATES);
            }
        });

        break;

    case DIALOG_HELP:

        Context context = getApplicationContext();
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.about_dialog, null);
        builder.setView(layout);
        builder.setPositiveButton("OK", null);
        dialog = builder.create();
        break;
    }

    return dialog;
}