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:br.com.GUI.perfil.HomePersonal.java

public boolean onOptionsItemSelected(MenuItem item) {
    // Take appropriate action for each action item click
    switch (item.getItemId()) {

    case R.id.actSolicitacoesDeAmizadePersonal:
        ArrayList<Aluno> solicitacoes = new Aluno().buscarAlunoNaoConfirmadoPorPersonalWeb("",
                pref.getString("usuario", null));
        if (!solicitacoes.isEmpty()) {
            Intent i = new Intent(this, SolicitacoesDeAmizade.class);
            startActivity(i);/*  w ww  . ja  va2 s.  c o m*/
        } else {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
            alertDialog.setTitle("Ops...");
            alertDialog.setMessage(R.string.label_voce_nao_possui_solicitacoes_de_amizade);
            alertDialog.setIcon(R.drawable.profile);
            alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            // Showing Alert Message
            alertDialog.show();
        }

        return true;
    case R.id.actLogoutPersonal:
        finish();
        Intent login = new Intent(this, Login.class);
        login.putExtra("logout", true);
        editor.clear();
        editor.commit();
        startActivity(login);
        return true;
    case R.id.actAdicionarAlunos:
        Intent adicionarAlunos = new Intent(this, BuscarUsuario.class);
        startActivity(adicionarAlunos);
        return true;
    case R.id.actAlterarDadosPessoaisPersonal:
        if (pref.getBoolean("isFacebookUser", false)) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(HomePersonal.this);
            alertDialog.setTitle("Erro");
            alertDialog.setMessage(
                    "Seu cadastro est vinculado ao Facebook, sendo assim, no  possivel alterao de informaes pessoais");
            alertDialog.setIcon(R.drawable.profile);
            alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            // Showing Alert Message
            alertDialog.show();
        } else {
            Intent alterarDados = new Intent(this, AlterarDadosPessoais.class);
            startActivity(alterarDados);
        }

        return true;
    case R.id.actPerfil:
        Intent perfilIntent = new Intent(this, PerfilPersonal.class);
        startActivity(perfilIntent);
        return true;

    case R.id.actNovaAvaliacao:
        Intent avaliacoesIntent = new Intent(this, AvaliarGorduraCorporal.class);
        startActivity(avaliacoesIntent);
        return true;
    case R.id.actNovoTreinamento:

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setTitle("Ops...");
        alertDialog.setMessage("Digite um nome para o novo treinamento");
        alertDialog.setIcon(R.drawable.critical);

        // Set an EditText view to get user input 
        final EditText input = new EditText(this);
        alertDialog.setView(input);

        alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                Treinamento t = new Treinamento(0, input.getText().toString(), null, null,
                        pref.getString("usuario", null), null);

                //Log.i("interface: treinamento", t.toString());
                try {
                    int resultado = t.salvarTreinamentoWeb(b);
                    if (resultado > 0) {
                        Log.i("interface: salvei web", "salvei web");
                        t.setCodTreinamento(resultado);
                        if (t.salvarTreinamento(b, pref.getString("usuario", null))) {
                            Log.i("interface: salvei local", "salvei local");
                            Toast.makeText(HomePersonal.this, "Salvo com sucesso!", Toast.LENGTH_SHORT).show();
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    Toast.makeText(HomePersonal.this, "Erro ao salvar!", Toast.LENGTH_SHORT).show();
                }
            }
        });
        alertDialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();

            }
        });
        // Showing Alert Message
        alertDialog.show();

    }

    return false;
}

From source file:de.baumann.hhsmoodle.activities.Activity_todo.java

private void setupListViewListener() {
    lvItems.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override/*from  w w w  .j  a v a2 s  . com*/
        public boolean onItemLongClick(AdapterView<?> adapter, View item, final int pos, long id) {

            final String text = (String) adapter.getItemAtPosition(pos);
            // Remove the item within array at position
            items.remove(pos);
            // Refresh the adapter
            itemsAdapter.notifyDataSetChanged();
            // Return true consumes the long click event (marks it handled)
            writeItems();

            Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG)
                    .setAction(R.string.todo_removed_back, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            items.add(pos, text);
                            // Refresh the adapter
                            itemsAdapter.notifyDataSetChanged();
                            // Return true consumes the long click event (marks it handled)
                            writeItems();
                        }
                    });
            snackbar.show();

            return true;
        }
    });

    lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapter, View item, final int pos, long id) {

            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_todo.this);
            View dialogView = View.inflate(Activity_todo.this, R.layout.dialog_edit_text_singleline, null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
            ImageButton ib_paste = (ImageButton) dialogView.findViewById(R.id.imageButtonPaste);

            ib_paste.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    final CharSequence[] options = { getString(R.string.paste_date),
                            getString(R.string.paste_time) };
                    new android.app.AlertDialog.Builder(Activity_todo.this)
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.dismiss();
                                }
                            }).setItems(options, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int item) {
                                    if (options[item].equals(getString(R.string.paste_date))) {
                                        Date date = new Date();
                                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                                                Locale.getDefault());
                                        String dateNow = format.format(date);
                                        edit_title.getText().insert(edit_title.getSelectionStart(), dateNow);
                                    }

                                    if (options[item].equals(getString(R.string.paste_time))) {
                                        Date date = new Date();
                                        SimpleDateFormat format = new SimpleDateFormat("HH:mm",
                                                Locale.getDefault());
                                        String timeNow = format.format(date);
                                        edit_title.getText().insert(edit_title.getSelectionStart(), timeNow);
                                    }
                                }
                            }).show();
                }
            });

            String text = (String) adapter.getItemAtPosition(pos);
            edit_title.setText(text);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTag = edit_title.getText().toString().trim();
                    // Remove the item within array at position
                    items.remove(pos);
                    items.add(pos, inputTag);
                    // Refresh the adapter
                    itemsAdapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItems();

                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(Activity_todo.this, edit_title);
        }
    });
}

From source file:cl.gisred.android.CatastroActivity.java

public void dialogBusqueda() {

    AlertDialog.Builder dialogBusqueda = new AlertDialog.Builder(this);
    dialogBusqueda.setTitle("Busqueda");
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.dialog_busqueda, null);
    dialogBusqueda.setView(v);

    Spinner spinner = (Spinner) v.findViewById(R.id.spinnerBusqueda);
    final LinearLayout llBuscar = (LinearLayout) v.findViewById(R.id.llBuscar);
    final LinearLayout llDireccion = (LinearLayout) v.findViewById(R.id.llBuscarDir);

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            R.layout.support_simple_spinner_dropdown_item, searchArray);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);//ww w .  j  a va 2s.c  o m
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            SpiBusqueda = position;

            if (position != 3) {
                if (llDireccion != null)
                    llDireccion.setVisibility(View.GONE);
                if (llBuscar != null)
                    llBuscar.setVisibility(View.VISIBLE);
            } else {
                if (llDireccion != null)
                    llDireccion.setVisibility(View.VISIBLE);
                if (llBuscar != null)
                    llBuscar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            Toast.makeText(getApplicationContext(), "Nada seleccionado", Toast.LENGTH_SHORT).show();
        }
    });

    final EditText eSearch = (EditText) v.findViewById(R.id.txtBuscar);
    final EditText eStreet = (EditText) v.findViewById(R.id.txtCalle);
    final EditText eNumber = (EditText) v.findViewById(R.id.txtNum);

    dialogBusqueda.setPositiveButton("Buscar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            if (SpiBusqueda == 3) {
                txtBusqueda = new String();
                if (!eStreet.getText().toString().isEmpty())
                    txtBusqueda = (eNumber.getText().toString().trim().isEmpty()) ? "0 "
                            : eNumber.getText().toString().trim() + " ";
                txtBusqueda = txtBusqueda + eStreet.getText().toString();
            } else {
                txtBusqueda = eSearch.getText().toString();
            }

            if (txtBusqueda.trim().isEmpty()) {
                Toast.makeText(myMapView.getContext(), "Debe ingresar un valor", Toast.LENGTH_SHORT).show();
            } else {
                // Escala de calle para busquedas por default
                // TODO Asignar a res values o strings
                iBusqScale = 4000;
                switch (SpiBusqueda) {
                case 0:
                    callQuery(txtBusqueda, getValueByEmp("CLIENTES_XY_006.nis"),
                            LyCLIENTES.getUrl().concat("/0"));
                    if (LyCLIENTES.getLayers() != null && LyCLIENTES.getLayers().length > 0)
                        iBusqScale = LyCLIENTES.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 1:
                    callQuery(txtBusqueda, "codigo", LySED.getUrl().concat("/1"));
                    if (LySED.getLayers() != null && LySED.getLayers().length > 1)
                        iBusqScale = LySED.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 2:
                    callQuery(txtBusqueda, "rotulo", LyPOSTES.getUrl().concat("/0"));
                    if (LyPOSTES.getLayers() != null && LyPOSTES.getLayers().length > 0)
                        iBusqScale = LyPOSTES.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 3:
                    iBusqScale = 5000;
                    String[] sBuscar = { eStreet.getText().toString(), eNumber.getText().toString() };
                    String[] sFields = { "nombre_calle", "numero" };
                    callQuery(sBuscar, sFields, LyDIRECCIONES.getUrl().concat("/0"));
                    break;
                }
            }
        }
    });

    dialogBusqueda.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    dialogBusqueda.show();
}

From source file:com.googlecode.android_scripting.facade.ui.NFCBeamTask.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override//  ww  w . j  a  v a2 s . co m
public void onCreate() {
    super.onCreate();
    if (initNFCBeam()) {

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        if (mTitle != null) {
            builder.setTitle(mTitle);
        }
        // Can't display both a message and items. We'll elect to show the items instead.
        if (mMessage != null && mItems.isEmpty()) {
            builder.setMessage(mMessage);
        }
        switch (mInputType) {
        // Add single choice menu items to dialog.
        case SINGLE_CHOICE:
            builder.setSingleChoiceItems(getItemsAsCharSequenceArray(), mSelectedItems.iterator().next(),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            mSelectedItems.clear();
                            mSelectedItems.add(item);
                        }
                    });
            break;
        // Add multiple choice items to the dialog.
        case MULTI_CHOICE:
            boolean[] selectedItems = new boolean[mItems.size()];
            for (int i : mSelectedItems) {
                selectedItems[i] = true;
            }
            builder.setMultiChoiceItems(getItemsAsCharSequenceArray(), selectedItems,
                    new DialogInterface.OnMultiChoiceClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item, boolean isChecked) {
                            if (isChecked) {
                                mSelectedItems.add(item);
                            } else {
                                mSelectedItems.remove(item);
                            }
                        }
                    });
            break;
        // Add standard, menu-like, items to dialog.
        case MENU:
            builder.setItems(getItemsAsCharSequenceArray(), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    Map<String, Integer> result = new HashMap<String, Integer>();
                    result.put("item", item);
                    dismissDialog();
                    setResult(result);
                }
            });
            break;
        case PLAIN_TEXT:
            mEditText = new EditText(getActivity());
            if (mDefaultText != null) {
                mEditText.setText(mDefaultText);
            }
            mEditText.setInputType(mEditInputType);
            builder.setView(mEditText);
            break;
        case PASSWORD:
            mEditText = new EditText(getActivity());
            mEditText.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
            mEditText.setTransformationMethod(new PasswordTransformationMethod());
            builder.setView(mEditText);
            break;
        default:
            // No input type specified.
        }
        configureButtons(builder, getActivity());
        addOnCancelListener(builder, getActivity());
        mDialog = builder.show();
        mShowLatch.countDown();
    } else {

    }
}

From source file:com.andrewshu.android.reddit.user.ProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from w w  w .  j  a  v a  2  s . c  o  m
    ProgressDialog pdialog;
    AlertDialog.Builder builder;
    LayoutInflater inflater;
    View layout; // used for inflated views for AlertDialog.Builder.setView()

    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, false) {
            @Override
            public void onLoginChosen(String user, String password) {
                removeDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    case Constants.DIALOG_COMPOSE:
        inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        layout = inflater.inflate(R.layout.compose_dialog, null);

        Common.setTextColorFromTheme(mSettings.getTheme(), getResources(),
                (TextView) layout.findViewById(R.id.compose_destination_textview),
                (TextView) layout.findViewById(R.id.compose_subject_textview),
                (TextView) layout.findViewById(R.id.compose_message_textview),
                (TextView) layout.findViewById(R.id.compose_captcha_textview),
                (TextView) layout.findViewById(R.id.compose_captcha_loading));

        final EditText composeDestination = (EditText) layout.findViewById(R.id.compose_destination_input);
        final EditText composeSubject = (EditText) layout.findViewById(R.id.compose_subject_input);
        final EditText composeText = (EditText) layout.findViewById(R.id.compose_text_input);
        final Button composeSendButton = (Button) layout.findViewById(R.id.compose_send_button);
        final Button composeCancelButton = (Button) layout.findViewById(R.id.compose_cancel_button);
        final EditText composeCaptcha = (EditText) layout.findViewById(R.id.compose_captcha_input);
        composeDestination.setText(mUsername);

        dialog = builder.setView(layout).create();
        final Dialog composeDialog = dialog;
        composeSendButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ThingInfo hi = new ThingInfo();

                if (!FormValidation.validateComposeMessageInputFields(ProfileActivity.this, composeDestination,
                        composeSubject, composeText, composeCaptcha))
                    return;

                hi.setDest(composeDestination.getText().toString().trim());
                hi.setSubject(composeSubject.getText().toString().trim());
                new MyMessageComposeTask(composeDialog, hi, composeCaptcha.getText().toString().trim())
                        .execute(composeText.getText().toString().trim());
                removeDialog(Constants.DIALOG_COMPOSE);
            }
        });
        composeCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_COMPOSE);
            }
        });
        break;

    case Constants.DIALOG_THREAD_CLICK:
        dialog = new ThreadClickDialog(this, mSettings);
        break;

    // "Please wait"
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_REPLYING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Sending reply...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_COMPOSING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Composing message...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;

    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showSendMoneyPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    final String message = "Send Money to Friend In A Flash";
    String positiveButtonText = "Send";

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    final TextView labelAmount = new TextView(getActivity());
    final EditText editAmount = new EditText(getActivity());
    final TextView labelMobileNo = new TextView(getActivity());
    final EditText editMobileNo = new EditText(getActivity());
    final TextView labelMessage = new TextView(getActivity());
    final EditText editMessage = new EditText(getActivity());
    editAmount.setSingleLine(true);//  www .j a v  a2 s  . co  m
    editMobileNo.setSingleLine(true);
    editMessage.setSingleLine(true);

    labelAmount.setText("Amount");
    labelMobileNo.setText("Enter Mobile No of Friend");
    labelMessage.setText("Enter Message (Optional)");

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    labelAmount.setLayoutParams(layoutParams);
    labelMobileNo.setLayoutParams(layoutParams);
    labelMessage.setLayoutParams(layoutParams);
    editAmount.setLayoutParams(layoutParams);
    editMobileNo.setLayoutParams(layoutParams);
    editMessage.setLayoutParams(layoutParams);

    linearLayout.addView(labelAmount);
    linearLayout.addView(editAmount);
    linearLayout.addView(labelMobileNo);
    linearLayout.addView(editMobileNo);
    linearLayout.addView(labelMessage);
    linearLayout.addView(editMessage);

    int paddingPx = Utils.getSizeInPx(getActivity(), 32);
    linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

    editAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    editMobileNo.setInputType(InputType.TYPE_CLASS_NUMBER);
    alert.setTitle("Send Money In A Flash");
    alert.setMessage(message);

    alert.setView(linearLayout);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editAmount.getText().toString();
            String mobileNo = editMobileNo.getText().toString();
            String message = editMessage.getText().toString();

            mCitrusClient.sendMoneyToMoblieNo(new Amount(amount), mobileNo, message,
                    new Callback<PaymentResponse>() {
                        @Override
                        public void success(PaymentResponse paymentResponse) {
                            //                        Utils.showToast(getActivity(), paymentResponse.getStatus() == CitrusResponse.Status.SUCCESSFUL ? "Sent Money Successfully." : "Failed To Send the Money");
                            ((UIActivity) getActivity()).showSnackBar(
                                    paymentResponse.getStatus() == CitrusResponse.Status.SUCCESSFUL
                                            ? "Sent Money Successfully."
                                            : "Failed To Send the Money");
                        }

                        @Override
                        public void error(CitrusError error) {
                            //                        Utils.showToast(getActivity(), error.getMessage());
                            ((UIActivity) getActivity()).showSnackBar(error.getMessage());
                        }
                    });
            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editAmount.getWindowToken(), 0);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    editAmount.requestFocus();
    alert.show();
}

From source file:com.blueoxfords.peacecorpstinder.activities.MainActivity.java

public void getLegalInfo(View v) {
    String photoId = v.getTag() + "";
    ImageRestClient.get().getInfoFromImageId(photoId, new Callback<ImageService.ImageInfoWrapper>() {
        @Override//from  ww  w  . j av  a 2 s.com
        public void success(ImageService.ImageInfoWrapper imageInfoWrapper, Response response) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.activity);

            ScrollView wrapper = new ScrollView(MainActivity.activity);
            LinearLayout infoLayout = new LinearLayout(MainActivity.activity);
            infoLayout.setOrientation(LinearLayout.VERTICAL);
            infoLayout.setPadding(35, 35, 35, 35);

            TextView imageOwner = new TextView(MainActivity.activity);
            imageOwner.setText(Html.fromHtml("<b>Image By: </b>" + imageInfoWrapper.photo.owner.username));
            if (imageInfoWrapper.photo.owner.realname.length() > 0) {
                imageOwner.setText(imageOwner.getText() + " (" + imageInfoWrapper.photo.owner.realname + ")");
            }
            infoLayout.addView(imageOwner);

            if (getLicenseUrl(Integer.parseInt(imageInfoWrapper.photo.license)).length() > 0) {
                TextView licenseLink = new TextView(MainActivity.activity);
                licenseLink.setText(Html
                        .fromHtml("<a href=\"" + getLicenseUrl(Integer.parseInt(imageInfoWrapper.photo.license))
                                + "\"><b>Licensing</b></a>"));
                licenseLink.setMovementMethod(LinkMovementMethod.getInstance());
                infoLayout.addView(licenseLink);
            }

            if (imageInfoWrapper.photo.urls.url.size() > 0) {
                TextView imageLink = new TextView(MainActivity.activity);
                imageLink.setText(Html.fromHtml("<a href=\"" + imageInfoWrapper.photo.urls.url.get(0)._content
                        + "\"><b>Image Link</b></a>"));
                imageLink.setMovementMethod(LinkMovementMethod.getInstance());
                infoLayout.addView(imageLink);
            }

            if (imageInfoWrapper.photo.title._content.length() > 0) {
                TextView photoTitle = new TextView(MainActivity.activity);
                photoTitle
                        .setText(Html.fromHtml("<b>Image Title: </b>" + imageInfoWrapper.photo.title._content));
                infoLayout.addView(photoTitle);
            }

            if (imageInfoWrapper.photo.description._content.length() > 0) {
                TextView description = new TextView(MainActivity.activity);
                description.setText(Html
                        .fromHtml("<b>Image Description: </b>" + imageInfoWrapper.photo.description._content));
                infoLayout.addView(description);
            }

            TextView contact = new TextView(MainActivity.activity);
            contact.setText(
                    Html.fromHtml("<br><i>To remove this photo, please email pcorpsconnect@gmail.com</i>"));
            infoLayout.addView(contact);

            wrapper.addView(infoLayout);

            builder.setTitle("Photo Information");
            builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

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

        @Override
        public void failure(RetrofitError error) {
            Log.i("testing", "could not retrieve legal/attribution info");
        }
    });
}

From source file:com.example.testapplication.DialogLocation.java

@SuppressLint("InlinedApi")
@Override/*www . j ava  2  s .c  o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mProgressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mProgressBarInv = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mProgressBarInv.setVisibility(ProgressBar.GONE);

    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    mCriteria = new Criteria();
    int criteria = (mGpsPref) ? Criteria.POWER_HIGH : Criteria.POWER_MEDIUM;
    mCriteria.setPowerRequirement(criteria);

    mProvider = mLocationManager.getBestProvider(mCriteria, true);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    int telephonyInfo = tm.getNetworkType();

    boolean networkAvailable = true;

    if ((telephonyInfo == TelephonyManager.NETWORK_TYPE_UNKNOWN && !networkInfo.isConnected())
            || !mLocationManager.isProviderEnabled("network")) {
        networkAvailable = false;
    }

    int locationMode = -1;
    int locationType = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
            locationMode = Settings.Secure.getInt(getActivity().getContentResolver(),
                    Settings.Secure.LOCATION_MODE);
        } catch (SettingNotFoundException e) {
            e.printStackTrace();
        }

        if (locationMode == Settings.Secure.LOCATION_MODE_OFF
                || (!networkAvailable && (mProvider.matches("network"))))
            locationType = NO_LOCATION_SERVICES;
        else if (mGpsPref && (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY
                || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY))
            locationType = (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY || !networkAvailable)
                    ? USING_ONLY_GPS_LOCATION
                    : USING_GPS_LOCATION_NETWORK_AVAILABLE;
        else if (mProvider.matches("network") && (locationMode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING
                || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY))
            locationType = USING_NETWORK_LOCATION;

    } else {
        if (mProvider.matches("passive") || !networkAvailable
                && (mProvider.matches("network") || (!mGpsPref && mProvider.matches("gps"))))
            locationType = NO_LOCATION_SERVICES;
        else if (mProvider.matches("gps") && mGpsPref)
            locationType = ((mProvider.matches("gps")) || !networkAvailable) ? USING_ONLY_GPS_LOCATION
                    : USING_GPS_LOCATION_NETWORK_AVAILABLE;
        else if (mProvider.matches("network"))
            locationType = USING_NETWORK_LOCATION;
    }

    switch (locationType) {
    case NO_LOCATION_SERVICES:
        builder.setTitle(DIALOG_LOCATION_NO_LOCATION_SERVICES_TITLE);
        builder.setMessage(DIALOG_LOCATION_NO_LOCATION_SERVICES_MESSAGE);
        builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton);
        mAbortRequest = true;
        break;
    case USING_ONLY_GPS_LOCATION:
        builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE);
        builder.setMessage(DIALOG_LOCATION_ONLY_GPS_MESSAGE);
        builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton);
        builder.setView(mProgressBar);
        break;
    case USING_GPS_LOCATION_NETWORK_AVAILABLE:
        builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE);
        builder.setPositiveButton(DIALOG_LOCATION_USE_NETWORK, null);
        builder.setView(mProgressBar);
        break;
    case USING_NETWORK_LOCATION:
        builder.setView(mProgressBar);
        builder.setTitle(DIALOG_LOCATION_UPDATING_NETWORK_TITLE);
        break;
    }

    builder.setNegativeButton(DIALOG_LOCATION_CANCEL, cancelListener);
    builder.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                mCallback.onLocationFound(null, mFragmentId);
                mLocationManager.removeUpdates(DialogLocation.this);
                Toast.makeText(getActivity(), "Location request cancelled", Toast.LENGTH_SHORT).show();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });

    mRealDialog = builder.create();
    mRealDialog.setOnShowListener(usingNetwork);
    mRealDialog.setCanceledOnTouchOutside(false);
    return mRealDialog;
}

From source file:dentex.youtube.downloader.DashboardActivity.java

public void editId3Tags(View view) {
    BugSenseHandler.leaveBreadcrumb("editId3Tags");
    if (newClick) {
        tagArtist = "";
        tagAlbum = "";
        tagTitle = "";
        tagGenre = "";
        tagYear = "";
    }//from  ww  w .ja  va2  s. com

    AlertDialog.Builder builder = new AlertDialog.Builder(boxThemeContextWrapper);
    LayoutInflater inflater0 = getLayoutInflater();
    final View id3s = inflater0.inflate(R.layout.dialog_edit_id3, null);

    final EditText artistEt = (EditText) id3s.findViewById(R.id.id3_et_artist);
    final EditText titleEt = (EditText) id3s.findViewById(R.id.id3_et_title);
    final EditText albumEt = (EditText) id3s.findViewById(R.id.id3_et_album);
    final EditText genreEt = (EditText) id3s.findViewById(R.id.id3_et_genre);
    final EditText yearEt = (EditText) id3s.findViewById(R.id.id3_et_year);

    if (tagTitle.isEmpty()) {
        titleEt.setText(currentItem.getBasename());
    } else {
        titleEt.setText(tagTitle);
    }

    if (tagYear.isEmpty()) {
        Calendar cal = new GregorianCalendar();
        int y = cal.get(Calendar.YEAR);
        yearEt.setText(String.valueOf(y));
    } else {
        yearEt.setText(tagYear);
    }

    artistEt.setText(tagArtist);
    albumEt.setText(tagAlbum);
    genreEt.setText(tagGenre);

    builder.setView(id3s).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            tagArtist = artistEt.getText().toString();
            tagAlbum = albumEt.getText().toString();
            tagTitle = titleEt.getText().toString();
            tagGenre = genreEt.getText().toString();
            tagYear = yearEt.getText().toString();
        }
    }).setNegativeButton(R.string.dialogs_negative, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // cancel
        }
    });

    secureShowDialog(builder);
    newClick = false;
}

From source file:com.b44t.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    actionBar//from  w ww.j a v  a 2s  . com
            .setBackButtonImage(screen == SCREEN0_SETTINGS ? R.drawable.ic_ab_back : R.drawable.ic_close_white);
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (screen != SCREEN0_SETTINGS) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (screen == SCREEN1_ENTER_CODE1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView
                        .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(
                        LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView
                    .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (screen == SCREEN1_ENTER_CODE1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    return true;
                }
                return false;
            }
        });
        passwordEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

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

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (passwordEditText.length() == 4) {
                    if (screen == SCREEN2_ENTER_CODE2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });

        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });

        if (screen == SCREEN1_ENTER_CODE1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, 0);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item,
                    LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1));
                } else if (i == passcodeOnOffRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("Disabled", R.string.Disabled);
                            } else if (value == 1) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Minutes, 1, 1);
                            } else if (value == 2) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Minutes, 5, 5);
                            } else if (value == 3) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Hours, 1, 1);
                            } else if (value == 4) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Hours, 5, 5);
                            }
                            return "";
                        }
                    });
                    numberPicker.setWrapSelectorWheel(false);
                    builder.setView(numberPicker);
                    builder.setNegativeButton(LocaleController.getString("Done", R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}