Example usage for android.app AlertDialog.Builder setView

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

Introduction

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

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:co.carlosjimenez.android.currencyalerts.app.AddAlertFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.dialog_add_alarm, null);
    ButterKnife.bind(this, dialogView);

    Bundle arguments = getArguments();// w  ww. j  a v  a 2s .  c o m
    if (arguments != null) {
        mCurrencyFrom = arguments.getParcelable(DetailActivityFragment.CURRENCY_FROM);
        mCurrencyTo = arguments.getParcelable(DetailActivityFragment.CURRENCY_TO);
    }

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.alarm_period_labels, R.layout.spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    mSpPeriod.setAdapter(adapter);

    alertValues = Utility.getAlertSettings(getContext(), false);

    if (alertValues.getCurrencyFrom().equals(mCurrencyFrom)
            && alertValues.getCurrencyTo().equals(mCurrencyTo)) {
        setSelectedPeriod(String.valueOf(alertValues.getPeriod()));
        mTvFluctuation.setText(String.valueOf(alertValues.getFluctuation()));
    } else {
        alertValues = Utility.getAlertSettings(getContext(), true);
        alertValues.clearAverage();
    }

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(dialogView)
            // Add action buttons
            .setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    alertValues.setEnabled(true);
                    alertValues.setCurrencyFrom(mCurrencyFrom);
                    alertValues.setCurrencyTo(mCurrencyTo);
                    alertValues.setPeriod(Integer.parseInt(mSelectedPeriod));
                    alertValues.setFluctuation(Float.parseFloat(mTvFluctuation.getText().toString()));

                    new UpdateAlarmTask(getActivity()).execute(alertValues);
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    AddAlertFragment.this.getDialog().cancel();
                }
            });

    AlertDialog alertDialog = builder.create();
    alertDialog.setCanceledOnTouchOutside(false);
    alertDialog.show();

    return alertDialog;
}

From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java

private void updateButtonOpenLink() {
    final View btnOpenLink = menu.findViewById(R.id.BtnOpenLink);
    btnOpenLink.setOnClickListener(new OnClickListener() {
        @Override/*from  w w  w  .j  av  a2 s .co m*/
        public void onClick(final View view) {
            if (listener != null) {
                final SettingBrowserChoice setting = new SettingBrowserChoice(dataMgr);
                switch (setting.getData()) {
                case SettingBrowserChoice.BROWSER_CHOICE_UNKNOWN:
                    final LayoutInflater inflater = (LayoutInflater) context
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    final AlertDialog.Builder builder = new AlertDialog.Builder(
                            new ContextThemeWrapper(context, android.R.style.Theme_DeviceDefault_Dialog));
                    final View popupView = inflater.inflate(R.layout.browser_choice_popup, null);
                    final CheckBox checkBox = (CheckBox) popupView.findViewById(R.id.CheckBoxDontShowAgain);
                    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                            popupView.findViewById(R.id.Hint).setVisibility(View.VISIBLE);
                        }
                    });
                    final String items[] = new String[3];
                    items[0] = context.getString(R.string.TxtBuiltInMobilized);
                    items[1] = context.getString(R.string.TxtBuiltInOriginal);
                    items[2] = context.getString(R.string.TxtExternalOriginal);
                    builder.setTitle(R.string.TxtChooseBrowser);
                    builder.setView(popupView);
                    builder.setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int which) {
                            switch (which) {
                            case 0:
                                if (listener != null) {
                                    listener.showWebsitePage(item.getUid(), true);
                                }
                                if (checkBox.isChecked()) {
                                    setting.setData(dataMgr, SettingBrowserChoice.BROWSER_CHOICE_MOBILIZED);
                                }
                                dialog.dismiss();
                                break;
                            case 1:
                                if (listener != null) {
                                    listener.showWebsitePage(item.getUid(), false);
                                }
                                if (checkBox.isChecked()) {
                                    setting.setData(dataMgr, SettingBrowserChoice.BROWSER_CHOICE_ORIGINAL);
                                }
                                dialog.dismiss();
                                break;
                            case 2:
                                final Intent intent = new Intent(Intent.ACTION_VIEW);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.setData(Uri.parse(item.getHref()));
                                context.startActivity(intent);
                                if (checkBox.isChecked()) {
                                    setting.setData(dataMgr, SettingBrowserChoice.BROWSER_CHOICE_EXTERNAL);
                                }
                                dialog.dismiss();
                                break;
                            default:
                                break;
                            }
                        }
                    });
                    builder.setNegativeButton(context.getString(R.string.TxtCancel),
                            new DialogInterface.OnClickListener() {
                                public void onClick(final DialogInterface dialog, final int which) {
                                    dialog.dismiss();
                                }
                            });
                    builder.show();
                    break;
                case SettingBrowserChoice.BROWSER_CHOICE_EXTERNAL:
                    final Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setData(Uri.parse(item.getHref()));
                    context.startActivity(intent);
                    break;
                case SettingBrowserChoice.BROWSER_CHOICE_MOBILIZED:
                    if (listener != null) {
                        listener.showWebsitePage(item.getUid(), true);
                    }
                    break;
                case SettingBrowserChoice.BROWSER_CHOICE_ORIGINAL:
                    if (listener != null) {
                        listener.showWebsitePage(item.getUid(), false);
                    }
                    break;
                default:
                    break;
                }
            }
        }
    });
}

From source file:com.brq.wallet.activity.modern.AccountsFragment.java

private void setCoinapultMail() {

    AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
    b.setTitle(getString(R.string.coinapult_mail_question));
    View diaView = getActivity().getLayoutInflater().inflate(R.layout.ext_coinapult_mail, null);
    final EditText mailField = (EditText) diaView.findViewById(R.id.mail);
    mailField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    String email = _mbwManager.getMetadataStorage().getCoinapultMail();
    if (!email.isEmpty()) {
        mailField.setText(email);/*from  w ww. j  a  v  a  2s  .  c  o  m*/
    }
    b.setView(diaView);
    b.setPositiveButton(getString(R.string.button_done), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String mailText = mailField.getText().toString();
            if (Utils.isValidEmailAddress(mailText)) {
                Optional<String> mail;
                if (mailText.isEmpty()) {
                    mail = Optional.absent();
                } else {
                    mail = Optional.of(mailText);
                }
                _progress.setCancelable(false);
                _progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                _progress.setMessage(getString(R.string.coinapult_setting_email));
                _progress.show();
                _mbwManager.getMetadataStorage().setCoinapultMail(mailText);
                new SetCoinapultMailAsyncTask(mail).execute();
                dialog.dismiss();
            } else {
                new Toaster(AccountsFragment.this).toast("Email address not valid", false);
            }
        }
    });
    b.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    AlertDialog dialog = b.create();
    dialog.show();
}

From source file:com.zertinteractive.wallpaper.MainActivity.java

public void reminderDialog() {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    View dialogView = this.getLayoutInflater().inflate(R.layout.alert_label_editor, null);
    dialogBuilder.setView(dialogView);
    final AlertDialog alertDialog = dialogBuilder.create();

    ImageView rate_app_dialog_button = (ImageView) dialogView.findViewById(R.id.rate_app_dialog_button);
    ImageView no_thanks_dialog_button = (ImageView) dialogView.findViewById(R.id.no_thanks_dialog_button);
    ImageView edidremind_dialog_button = (ImageView) dialogView.findViewById(R.id.remind_dialog_button);

    rate_app_dialog_button.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w  .  j  a  v a2 s.c o m*/
        public void onClick(View v) {
            openUri(PLAY_STORE_URL);
        }
    });
    no_thanks_dialog_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
    edidremind_dialog_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
    alertDialog.show();
}

From source file:com.hackensack.umc.activity.RegistrationDetailsActivity.java

private void showDilaog(String message) {

    //        DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
    //            @Override
    //            public void onClick(DialogInterface dialog, int which) {
    //                switch (which) {
    //                    case DialogInterface.BUTTON_POSITIVE:
    //                        new SubmitInfoCall().execute();
    //                        dialog.dismiss();
    //                        break;
    ////www . j  a va2 s. c om
    //                    case DialogInterface.BUTTON_NEGATIVE:
    //                        dialog.dismiss();
    //                        break;
    //                }
    //            }
    //        };
    //
    //        android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(RegistrationDetailsActivity.this);
    //        builder.setTitle("Alert");
    //        builder.setMessage(message + " .Try again.").setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener).show();

    if (!isFinishing()) {

        AlertDialog.Builder builder = new AlertDialog.Builder((getSupportActionBar().getThemedContext()));

        LayoutInflater inflater = getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.dialog_network_offline, null);
        builder.setView(dialogView);

        ((TextView) dialogView.findViewById(R.id.dialog_title)).setText("Alert");
        ((TextView) dialogView.findViewById(R.id.text_message)).setText(message);

        Button btnCancel = (Button) dialogView.findViewById(R.id.button_dialog_cancel);
        btnCancel.setVisibility(View.VISIBLE);
        btnCancel.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                alert.dismiss();
            }
        });

        Button btnOk = (Button) dialogView.findViewById(R.id.button_dialog_ok);
        btnOk.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {

                new SubmitInfoCall().execute();
                alert.dismiss();

            }
        });

        alert = builder.show();
    }

}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false);

    advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type);
    advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id);
    status = (TextView) rootView.findViewById(R.id.status);
    placeId = (TextView) rootView.findViewById(R.id.placeId);
    placeId.setOnClickListener(new View.OnClickListener() {
        @Override//www  .  ja v a2s .c o m
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    latLng = (TextView) rootView.findViewById(R.id.latLng);
    latLng.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    mapView = (ImageView) rootView.findViewById(R.id.mapView);
    mapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });

    expectedStability = (TextView) rootView.findViewById(R.id.expectedStability);
    expectedStability.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability");
            final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
                    R.array.stability_enums, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            final Spinner spinner = new Spinner(getActivity());
            spinner.setAdapter(adapter);
            // Set the position of the spinner to the current value.
            if (beacon.expectedStability != null
                    && !beacon.expectedStability.equals(Beacon.STABILITY_UNSPECIFIED)) {
                for (int i = 0; i < spinner.getCount(); i++) {
                    if (beacon.expectedStability.equals(spinner.getItemAtPosition(i))) {
                        spinner.setSelection(i);
                    }
                }
            }
            builder.setView(spinner);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beacon.expectedStability = (String) spinner.getSelectedItem();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    description = (TextView) rootView.findViewById(R.id.description);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description");
            final EditText editText = new EditText(getActivity());
            editText.setText(description.getText());
            builder.setView(editText);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beacon.description = editText.getText().toString();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    actionButton = (Button) rootView.findViewById(R.id.actionButton);

    decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton);
    decommissionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon")
                    .setMessage("Are you sure you want to decommission this beacon? This operation is "
                            + "irreversible and the beacon cannot be registered again")
                    .setPositiveButton("Decommission", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            Callback decommissionCallback = new Callback() {
                                @Override
                                public void onFailure(Request request, IOException e) {
                                    logErrorAndToast("Failed request: " + request, e);
                                }

                                @Override
                                public void onResponse(Response response) throws IOException {
                                    if (response.isSuccessful()) {
                                        beacon.status = Beacon.STATUS_DECOMMISSIONED;
                                        updateBeacon();
                                    } else {
                                        String body = response.body().string();
                                        logErrorAndToast("Unsuccessful decommissionBeacon request: " + body);
                                    }
                                }
                            };
                            client.decommissionBeacon(decommissionCallback, beacon.getBeaconName());
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).show();
        }
    });

    attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider);
    attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel);
    attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout);

    // Fetch the namespace for the developer console project ID. We redraw the UI once that
    // request completes.
    // TODO: cache this.
    Callback listNamespacesCallback = new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            logErrorAndToast("Failed request: " + request, e);
        }

        @Override
        public void onResponse(Response response) throws IOException {
            String body = response.body().string();
            if (response.isSuccessful()) {
                try {
                    JSONObject json = new JSONObject(body);
                    JSONArray namespaces = json.getJSONArray("namespaces");
                    // At present there can be only one namespace.
                    String tmp = namespaces.getJSONObject(0).getString("namespaceName");
                    if (tmp.startsWith("namespaces/")) {
                        namespace = tmp.substring("namespaces/".length());
                    } else {
                        namespace = tmp;
                    }
                    redraw();
                } catch (JSONException e) {
                    Log.e(TAG, "JSONException", e);
                }
            } else {
                logErrorAndToast("Unsuccessful listNamespaces request: " + body);
            }
        }
    };
    client.listNamespaces(listNamespacesCallback);
    return rootView;
}

From source file:com.hackensack.umc.activity.RegistrationDetailsActivity.java

public void showAlert(Context context, String message, String title, final OuterQuetions outerQuetions) {

    //        new android.app.AlertDialog.Builder(context)
    //                .setTitle(title)
    //                .setMessage(message)
    //                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
    //                    public void onClick(DialogInterface dialog, int which) {
    //                        dialog.dismiss();
    //                        /*Bundle b = new Bundle();
    //                        b.putParcelable(Constant.QUETIONS_DATA, outerQuetions);
    //                        b.putString(Constant.EMAIL_ID, mEmail.getText().toString());
    //                        b.putParcelable(Constant.PATIENT_FOR_EPIC_CALL, cretepationToSendForEpicCall());*/
    ///* w w w.j  a  v  a  2  s  .  c om*/
    //                        Intent intent = new Intent(RegistrationDetailsActivity.this, QuetionsActivity.class);
    //                        intent.putExtra(Constant.QUETIONS_DATA, outerQuetions);
    //                        if (mInsuranceInfo == null) {
    //                            mInsuranceInfo = new InsuranceInfo();
    //                        }
    //                        intent.putExtra(Constant.INSURANCE_DATA_TO_SEND, new CoverageJsonCreator(mInsuranceInfo.getPlanProvider(), mInsuranceInfo.getMemberNumber(), mInsuranceInfo.getGroupNumber(), mInsuranceInfo.getSubscriberId(), mInsuranceInfo.getReference(), mInsuranceInfo.getSubscriberName(), mInsuranceInfo.getSubscriberDateOfBirth()));
    //                        intent.putExtra(Constant.EMAIL_ID, mEmail.getText().toString());
    //                        intent.putExtra(Constant.PATIENT_FOR_EPIC_CALL, createPationToSendForEpicCall());
    //                        // intent.putExtra("bundle", b);
    //                        startActivity(intent);
    //                    }
    //                })
    //                .setCancelable(false)
    //                .show();

    if (!isFinishing()) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(false);
        LayoutInflater inflater = getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.dialog_network_offline, null);
        builder.setView(dialogView);

        ((TextView) dialogView.findViewById(R.id.dialog_title)).setText(title);
        ((TextView) dialogView.findViewById(R.id.text_message)).setText(message);

        Button btnDismiss = (Button) dialogView.findViewById(R.id.button_dialog_ok);
        btnDismiss.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                alert.dismiss();

                Intent intent = new Intent(RegistrationDetailsActivity.this, QuetionsActivity.class);
                intent.putExtra(Constant.QUETIONS_DATA, outerQuetions);
                if (mInsuranceInfo == null) {
                    mInsuranceInfo = new InsuranceInfo();
                }
                //with nwe json creator.
                intent.putExtra(Constant.INSURANCE_DATA_TO_SEND,
                        new CoverageJsonCreatorNew(mInsuranceInfo.getPlanProvider(),
                                mInsuranceInfo.getMemberNumber(), mInsuranceInfo.getGroupNumber(),
                                mInsuranceInfo.getSubscriberId(), mInsuranceInfo.getReference(),
                                mInsuranceInfo.getSubscriberName(), mInsuranceInfo.getSubscriberDateOfBirth()));
                intent.putExtra(Constant.EMAIL_ID, mEmail.getText().toString());
                intent.putExtra(Constant.PATIENT_FOR_EPIC_CALL, createPationToSendForEpicCall());
                intent.putExtra(Constant.PARENTS_BIRTHDATE, birthDate);
                intent.putExtra(Constant.PARENTS_FIRST_NAME, fName);
                intent.putExtra(Constant.PARENTS_LAST_NAME, lastName);
                intent.putExtra(Constant.PARENTS_GENDER, gender);

                // intent.putExtra("bundle", b);
                startActivity(intent);

            }
        });

        alert = builder.show();
    }

}

From source file:butter.droid.base.fragments.dialog.NumberPickerDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    if (getArguments() == null || !getArguments().containsKey(MAX_VALUE)
            || !getArguments().containsKey(MIN_VALUE) || !getArguments().containsKey(TITLE)
            || mOnResultListener == null) {
        return builder.create();
    }//from  w w  w.j  a v a  2 s .  c  o  m

    final NumberPicker numberPicker = new NumberPicker(getActivity());
    numberPicker.setLayoutParams(new NumberPicker.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    numberPicker.setWrapSelectorWheel(false);

    final int minValue = getArguments().getInt(MIN_VALUE);
    final int maxValue = getArguments().getInt(MAX_VALUE);
    final int currentValue = getArguments().getInt(DEFAULT_VALUE,
            (int) Math.floor((numberPicker.getMaxValue() - numberPicker.getMinValue()) / 2));

    List<String> displayValues = new ArrayList<>();
    for (int i = minValue; i < maxValue + 1; i++) {
        displayValues.add(Integer.toString(i));
    }
    numberPicker.setDisplayedValues(displayValues.toArray(new String[displayValues.size()]));

    if (minValue < 0) {
        numberPicker.setMinValue(0);
        numberPicker.setMaxValue(maxValue + Math.abs(minValue));
        numberPicker.setValue(currentValue + Math.abs(minValue));
    } else {
        numberPicker.setMinValue(minValue);
        numberPicker.setMaxValue(maxValue);
        numberPicker.setValue(currentValue);
    }

    if (getArguments().containsKey(FOCUSABLE) && !getArguments().getBoolean(FOCUSABLE))
        numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    builder.setView(numberPicker).setTitle(getArguments().getString(TITLE))
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mOnResultListener.onNewValue(numberPicker.getValue() + (minValue < 0 ? minValue : 0));
                    dialog.dismiss();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    return builder.create();
}

From source file:com.njlabs.amrita.aid.landing.Landing.java

public void checkForUpdates() {

    OkHttpClient client = new OkHttpClient.Builder().followRedirects(true).followSslRedirects(true).build();

    Request.Builder request = new Request.Builder().url("https://api.codezero.xyz/aid/latest");

    client.newCall(request.build()).enqueue(new Callback() {
        @Override/*w ww . j  a  v  a  2 s.c o  m*/
        public void onFailure(Call call, IOException e) {
            Ln.e(e);
        }

        @Override
        public void onResponse(Call call, final Response rawResponse) throws IOException {
            final String responseString = rawResponse.body().string();
            ((Activity) baseContext).runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    JSONObject response;

                    try {
                        response = new JSONObject(responseString);

                        String status = "";
                        status = response.getString("status");

                        if (status.equals("ok")) {
                            Double Latest = 0.0;
                            String Description = null;
                            try {
                                Latest = response.getDouble("version");
                                Description = response.getString("description");
                            } catch (JSONException e) {
                                FirebaseCrash.report(e);
                            }
                            if (Latest > BuildConfig.VERSION_CODE) {

                                AlertDialog.Builder updateDialogBuilder = new AlertDialog.Builder(Landing.this);

                                LayoutInflater factory = LayoutInflater.from(Landing.this);
                                final View changelogView = factory.inflate(R.layout.webview_dialog, null);
                                LinearLayout WebViewDialogLayout = (LinearLayout) changelogView
                                        .findViewById(R.id.WebViewDialogLayout);
                                WebViewDialogLayout.setPadding(5, 5, 5, 5);
                                WebView changelogWebView = (WebView) changelogView
                                        .findViewById(R.id.LicensesView);
                                changelogWebView.loadData(String.format("%s", Description), "text/html",
                                        "utf-8");
                                changelogWebView.setPadding(5, 5, 5, 5);
                                changelogWebView.setBackgroundColor(0);
                                changelogWebView.setOnLongClickListener(new View.OnLongClickListener() {
                                    @Override
                                    public boolean onLongClick(View v) {
                                        return true;
                                    }
                                });
                                changelogWebView.setLongClickable(false);
                                updateDialogBuilder.setView(changelogView).setCancelable(true)
                                        .setCancelable(false)
                                        .setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                dialog.cancel();
                                            }
                                        })
                                        .setPositiveButton("Update Now", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                Uri uri = Uri
                                                        .parse("market://details?id=com.njlabs.amrita.aid");
                                                Intent it = new Intent(Intent.ACTION_VIEW, uri);
                                                startActivity(it);
                                            }
                                        });
                                AlertDialog alert = updateDialogBuilder.create();
                                alert.setTitle("Update Available");
                                alert.setIcon(R.mipmap.ic_launcher);
                                alert.show();
                            }
                        }

                    } catch (Exception e) {
                        Ln.e(e);
                    }
                }
            });
        }
    });
}

From source file:edu.cmu.hcii.hangg.beeksbeacon.Fragments.ManageBeaconFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i(TAG, "bi.id: " + beaconInstance.id + ", bi.googleType: " + beaconInstance.googleType);
    View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false);

    advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type);
    advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id);
    status = (TextView) rootView.findViewById(R.id.status);
    placeId = (TextView) rootView.findViewById(R.id.placeId);
    placeId.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w .  j a v  a 2 s.  c om*/
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    latLng = (TextView) rootView.findViewById(R.id.latLng);
    latLng.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    mapView = (ImageView) rootView.findViewById(R.id.mapView);
    mapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });

    expectedStability = (TextView) rootView.findViewById(R.id.expectedStability);
    expectedStability.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability");
            final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
                    R.array.stability_enums, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            final Spinner spinner = new Spinner(getActivity());
            spinner.setAdapter(adapter);
            // Set the position of the spinner to the current value.
            if (beaconInstance.expectedStability != null
                    && !beaconInstance.expectedStability.equals(BeaconInstance.STABILITY_UNSPECIFIED)) {
                for (int i = 0; i < spinner.getCount(); i++) {
                    if (beaconInstance.expectedStability.equals(spinner.getItemAtPosition(i))) {
                        spinner.setSelection(i);
                    }
                }
            }
            builder.setView(spinner);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beaconInstance.expectedStability = (String) spinner.getSelectedItem();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    description = (TextView) rootView.findViewById(R.id.description);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description");
            final EditText editText = new EditText(getActivity());
            editText.setText(description.getText());
            builder.setView(editText);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beaconInstance.description = editText.getText().toString();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    actionButton = (Button) rootView.findViewById(R.id.actionButton);

    decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton);
    decommissionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon")
                    .setMessage("Are you sure you want to decommission this beacon? This operation is "
                            + "irreversible and the beacon cannot be registered again")
                    .setPositiveButton("Decommission", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            Callback decommissionCallback = new Callback() {
                                @Override
                                public void onFailure(Request request, IOException e) {
                                    logErrorAndToast("Failed request: " + request, e);
                                }

                                @Override
                                public void onResponse(Response response) throws IOException {
                                    if (response.isSuccessful()) {
                                        beaconInstance.status = BeaconInstance.STATUS_DECOMMISSIONED;
                                        updateBeacon();
                                    } else {
                                        String body = response.body().string();
                                        logErrorAndToast("Unsuccessful decommissionBeacon request: " + body);
                                    }
                                }
                            };
                            client.decommissionBeacon(decommissionCallback, beaconInstance.getBeaconName());
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).show();
        }
    });

    attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider);
    attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel);
    attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout);

    // Fetch the namespace for the developer console project ID. We redraw the UI once that
    // request completes.
    // TODO: cache this.
    Callback listNamespacesCallback = new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            logErrorAndToast("Failed request: " + request, e);
        }

        @Override
        public void onResponse(Response response) throws IOException {
            String body = response.body().string();
            if (response.isSuccessful()) {
                try {
                    JSONObject json = new JSONObject(body);
                    JSONArray namespaces = json.getJSONArray("namespaces");
                    // At present there can be only one namespace.
                    String tmp = namespaces.getJSONObject(0).getString("namespaceName");
                    if (tmp.startsWith("namespaces/")) {
                        namespace = tmp.substring("namespaces/".length());
                    } else {
                        namespace = tmp;
                    }
                    redraw();
                } catch (JSONException e) {
                    Log.e(TAG, "JSONException", e);
                }
            } else {
                logErrorAndToast("Unsuccessful listNamespaces request: " + body);
            }
        }
    };
    client.listNamespaces(listNamespacesCallback);
    return rootView;
}