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:com.bookkos.bircle.CaptureActivity.java

private void titleInputDialog(final String isbn, final JSONArray json_array) {
    // ?????//ww w  .ja  va2s.  c o  m
    final EditText titleEditText = new EditText(_activity);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle("???????????");
    alertDialogBuilder.setMessage("??????????!");
    alertDialogBuilder.setView(titleEditText);
    alertDialogBuilder.setPositiveButton("????",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String title = titleEditText.getText().toString();
                    // ?????manually_catalog_register???
                    if (!title.isEmpty() || title != " " || title != "") {
                        title = title.replaceAll(" ", "_");
                        title = title.replaceAll("", "_");
                        String request_url = initManuallyCatalogRegistUrl + isbn + "&title=" + title;
                        HttpConnectPostReturnFlag manuallyCatalogRegist = new HttpConnectPostReturnFlag(
                                _activity, request_url);
                        manuallyCatalogRegist.execute();

                        // ???????????, ??json_array?????????, ???
                        if (json_array != null) {
                            parseShelfData(isbn, json_array);
                        } else {
                            // ??????, ?ISBN??????
                            if (registFlag == 1) {
                                // ?????????????
                                arrayList.add("&book_code[]=" + lastResult);
                                if (bookListViewAdapter.isEmpty()) {
                                    animateTranslationY(bookRegistRelativeLayout, displayHeight,
                                            displayHeight - displayHeight / 4 - titleBarHeight);
                                    borrowReturnButton.setEnabled(false);
                                    registButton.setEnabled(false);
                                }
                                bookListViewAdapter.add(new BookListViewItem(lastResult.toString()));
                                //                        for(int i=0; i < arrayList.size(); i++){
                                //                           text += arrayList.get(i) + "\n";
                                //                        }
                                Toast.makeText(_context, "ISBN = " + lastResult + " ?????.",
                                        Toast.LENGTH_SHORT).show();
                                bircleBeepManager.playBeepSoundAndVibrate(2);
                                restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
                            }
                        }
                    } else {
                        Toast.makeText(_context, "???????!", Toast.LENGTH_LONG)
                                .show();
                    }
                }
            });
    alertDialogBuilder.setNeutralButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
        }
    });

    alertDialogBuilder.setCancelable(true);
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialogBuilder.show();
}

From source file:cl.gisred.android.PowerOnActivity.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);
    final LinearLayout llOrden = (LinearLayout) v.findViewById(R.id.llBuscarOrden);

    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);// w ww . j  a v  a2s  .com
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            SpiBusqueda = position;

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

        @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);
    final EditText eOrder = (EditText) v.findViewById(R.id.txtOrden);

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

            if (SpiBusqueda == 4) {
                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 if (SpiBusqueda == 6) {
                txtBusqueda = eOrder.getText().toString() + "-1";
            } 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

                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:
                    callQuery(txtBusqueda, "serie_medidor", LyMEDIDORES.getUrl().concat("/1"));
                    if (LyMEDIDORES.getLayers() != null && LyMEDIDORES.getLayers().length > 1)
                        iBusqScale = LyMEDIDORES.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 4:
                    iBusqScale = 5000;
                    String[] sBuscar = { eStreet.getText().toString(), eNumber.getText().toString() };
                    String[] sFields = { "nombre_calle", "numero" };
                    callQuery(sBuscar, sFields, LyDIRECCIONES.getUrl().concat("/0"));
                    break;
                case 5:
                    callQuery(txtBusqueda, new String[] { "id_equipo", "nombre" },
                            LyEQUIPOSLINEA.getUrl().concat("/0"));
                    if (LyEQUIPOSLINEA.getLayers() != null && LyEQUIPOSLINEA.getLayers().length > 0)
                        iBusqScale = LyEQUIPOSLINEA.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 6:
                    callQuery(txtBusqueda, getValueByEmp("ARCGIS.dbo.POWERON_CLIENTES.id_orden"),
                            LyPOCLIENTES.getUrl().concat("/1"));
                    if (LyPOCLIENTES.getLayers() != null && LyPOCLIENTES.getLayers().length > 0)
                        if (LyPOCLIENTES.getLayers()[1].getLayerServiceInfo().getMinScale() > 0)
                            iBusqScale = LyPOCLIENTES.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 7:
                    callQueryInt(txtBusqueda, getValueByEmp("ARCGIS.dbo.POWERON_CLIENTES.id_incidencia"),
                            LyPOCLIENTES.getUrl().concat("/1"));
                    if (LyPOCLIENTES.getLayers() != null && LyPOCLIENTES.getLayers().length > 0)
                        if (LyPOCLIENTES.getLayers()[1].getLayerServiceInfo().getMinScale() > 0)
                            iBusqScale = LyPOCLIENTES.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                }
            }
        }
    });

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

        }
    });

    dialogBusqueda.show();
}

From source file:com.aniruddhc.acemusic.player.Dialogs.BlacklistedElementsDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mApp = (Common) getActivity().getApplicationContext();

    final BlacklistedElementsDialog dialog = this;
    MANAGER_TYPE = getArguments().getString("MANAGER_TYPE");
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Get a cursor with a list of blacklisted elements.
    if (MANAGER_TYPE.equals("ARTISTS")) {
        builder.setTitle(R.string.blacklisted_artists);
        cursor = mApp.getDBAccessHelper().getBlacklistedArtists();

    } else if (MANAGER_TYPE.equals("ALBUMS")) {
        builder.setTitle(R.string.blacklisted_albums);
        cursor = mApp.getDBAccessHelper().getBlacklistedAlbums();

    } else if (MANAGER_TYPE.equals("SONGS")) {
        builder.setTitle(R.string.blacklisted_songs);
        cursor = mApp.getDBAccessHelper().getAllBlacklistedSongs();

    } else if (MANAGER_TYPE.equals("PLAYLISTS")) {
        builder.setTitle(R.string.blacklisted_playlists);
        /*DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity());
        cursor = playlistsDBHelper.getAllBlacklistedPlaylists();*/

    } else {/*from   w w  w  . jav a 2  s .  c o m*/
        Toast.makeText(getActivity(), R.string.error_occurred, Toast.LENGTH_LONG).show();
        return builder.create();
    }

    //Dismiss the dialog if there are no blacklisted elements.
    if (cursor.getCount() == 0) {
        Toast.makeText(getActivity(), R.string.no_blacklisted_items_found, Toast.LENGTH_LONG).show();
        return builder.create();
    }

    //Loop through checkboxStatuses and insert "TRUE" at every position by default.
    for (int i = 0; i < cursor.getCount(); i++) {
        checkboxStatuses.add(true);
    }

    View rootView = this.getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_blacklist_manager,
            null);
    TextView blacklistManagerInfoText = (TextView) rootView.findViewById(R.id.blacklist_manager_info_text);
    ListView blacklistManagerListView = (ListView) rootView.findViewById(R.id.blacklist_manager_list);

    blacklistManagerInfoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light"));
    blacklistManagerInfoText.setPaintFlags(
            blacklistManagerInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    blacklistManagerListView.setFastScrollEnabled(true);
    BlacklistedElementsAdapter adapter = new BlacklistedElementsAdapter(getActivity(), cursor);
    blacklistManagerListView.setAdapter(adapter);

    builder.setView(rootView);
    builder.setNegativeButton(R.string.cancel, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialog.dismiss();

        }

    });

    builder.setPositiveButton(R.string.done, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Loop through checkboxStatuses and unblacklist the elements that have been unchecked.
            for (int i = 0; i < checkboxStatuses.size(); i++) {

                cursor.moveToPosition(i);
                if (checkboxStatuses.get(i) == true) {
                    //The item is still blacklisted.
                    continue;
                } else {
                    //The item has been unblacklisted.
                    if (MANAGER_TYPE.equals("ARTISTS")) {
                        mApp.getDBAccessHelper().setBlacklistForArtist(
                                cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)), false);

                    } else if (MANAGER_TYPE.equals("ALBUMS")) {
                        mApp.getDBAccessHelper().setBlacklistForAlbum(
                                cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ALBUM)),
                                cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)), false);

                    } else if (MANAGER_TYPE.equals("SONGS")) {
                        mApp.getDBAccessHelper().setBlacklistForSong(
                                cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)), false);

                    } else if (MANAGER_TYPE.equals("PLAYLISTS")) {
                        /*DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity());
                        playlistsDBHelper.unBlacklistPlaylist(cursor.getString(cursor.getColumnIndex(DBAccessHelper.PLAYLIST_BLACKLIST_STATUS)));*/

                    }

                }

            }

            dialog.dismiss();

        }

    });

    return builder.create();
}

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

@Override
public void onCreate() {
    super.onCreate();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    if (mTitle != null) {
        builder.setTitle(mTitle);//from w  w w. j  a v  a 2 s. c  om
    }
    // 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() {
                    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() {
                    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();
}

From source file:com.app_software.chromisstock.StockChangeDialog.java

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

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout

    View v = inflater.inflate(R.layout.dialog_stock_change, null);

    // Set information given in the Intent
    m_txtProductName = (TextView) v.findViewById(R.id.txtProductName);
    m_txtField = (TextView) v.findViewById(R.id.txtField);
    m_editNewValue = (EditText) v.findViewById(R.id.editNewValue);
    m_rbIncrease = (RadioButton) v.findViewById(R.id.rbIncrease);
    m_rbDecrease = (RadioButton) v.findViewById(R.id.rbDecrease);
    m_rbSetValue = (RadioButton) v.findViewById(R.id.rbSetValue);

    m_rbIncrease.setEnabled(m_bAllowAdjust);
    m_rbDecrease.setEnabled(m_bAllowAdjust);

    DatabaseHandler db = DatabaseHandler.getInstance(getActivity());
    StockProduct product = db.getProduct(m_ProductID, true);
    if (product == null) {
        Log.e(TAG, "Product not found");
        m_txtProductName.setText("DATABASE ERROR!!");
    } else {/*from www. j  a va2 s .  c  o m*/

        m_ChromisID = product.getChromisId();
        String name;
        if (TextUtils.isEmpty(product.getValueString(StockProduct.NAME))) {
            name = getResources().getString(R.string.change_newproduct);
        } else {
            name = product.getValueString(StockProduct.NAME);
        }
        m_txtProductName.setText(name);
        m_txtField.setText(m_FieldLabel);

        if (m_ChangeType == DatabaseHandler.CHANGETYPE_ADJUSTVALUE) {
            Double d = new Double(m_Value);
            if (d < 0) {
                m_rbDecrease.setChecked(true);
                d = d * -1;
                m_Value = String.format("%.0f", d);
            } else {
                m_rbIncrease.setChecked(true);
            }
        } else {
            m_rbSetValue.setChecked(true);
        }

        if (m_bIsNumber) {
            m_editNewValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        } else {
            m_editNewValue.setInputType(InputType.TYPE_CLASS_TEXT);
            m_editNewValue.setText(m_Value);
        }
        m_editNewValue.setHint(m_Value);
    }

    // Add action buttons
    builder.setView(v).setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            // Create a new change record
            createChangeRecord();
        }
    }).setNegativeButton(R.string.label_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    return builder.create();
}

From source file:com.android.julia.todolist.ui.EditTaskDialogFragment.java

@NonNull
@Override//from   w w w  .j a va  2s .c om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
    alertDialogBuilder.setTitle(getString(R.string.title_edit_task_dialog));
    alertDialogBuilder.setPositiveButton(getString(R.string.action_save_edit_task_dialog),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    onClickSaveTask();
                }
            });
    alertDialogBuilder.setNegativeButton(getString(R.string.action_cancel_edit_task_dialog),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    // Fetch arguments from bundle and set position, description, and priority
    mPosition = getArguments().getInt("position", 0);
    String description = getArguments().getString("description");
    mPriority = getArguments().getInt("priority", 1);

    View v = View.inflate(getContext(), R.layout.fragment_edit_task, null);

    // Get field from view
    mTaskDescriptionEditText = (EditText) v.findViewById(R.id.editTextTaskDescription);
    // Set user's cursor in the text field at the end of the current text value
    // and focused by default
    mTaskDescriptionEditText.setText("");
    mTaskDescriptionEditText.append(description);
    // Show soft keyboard automatically and request focus to field
    mTaskDescriptionEditText.requestFocus();

    mHighRadioButton = (RadioButton) v.findViewById(R.id.radButton1);
    mMediumRadioButton = (RadioButton) v.findViewById(R.id.radButton2);
    mLowRadioButton = (RadioButton) v.findViewById(R.id.radButton3);
    mHighRadioButton.setOnClickListener(this);
    mMediumRadioButton.setOnClickListener(this);
    mLowRadioButton.setOnClickListener(this);

    if (mPriority == 1) {
        mHighRadioButton.setChecked(true);
    } else if (mPriority == 2) {
        mMediumRadioButton.setChecked(true);
    } else if (mPriority == 3) {
        mLowRadioButton.setChecked(true);
    }

    // Set to adjust screen height automatically, when soft keyboard appears on screen
    Window window = alertDialogBuilder.create().getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    }
    alertDialogBuilder.setView(v);
    return alertDialogBuilder.create();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;//w  w w . j  a  v a2  s. co  m

    // Import license file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction()))
        if (Util.importProLicense(new File(getIntent().getData().getPath())) != null)
            Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show();

    // Set layout
    setContentView(R.layout.mainlist);
    setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar));
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // Set sub title
    if (Util.hasProLicense(this) != null)
        getSupportActionBar().setSubtitle(R.string.menu_pro);

    // Annotate
    Meta.annotate(this.getResources());

    // Get localized restriction name
    List<String> listRestrictionName = new ArrayList<String>(
            PrivacyManager.getRestrictions(this).navigableKeySet());
    listRestrictionName.add(0, getString(R.string.menu_all));

    // Build spinner adapter
    SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spAdapter.addAll(listRestrictionName);

    // Handle info
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void onClick(View view) {
            int position = spRestriction.getSelectedItemPosition();
            if (position != AdapterView.INVALID_POSITION) {
                String query = (position == 0 ? "restrictions"
                        : (String) PrivacyManager.getRestrictions(ActivityMain.this).values().toArray()[position
                                - 1]);

                WebView webview = new WebView(ActivityMain.this);
                webview.getSettings().setUserAgentString("Mozilla/5.0");
                // needed for hashtag
                webview.getSettings().setJavaScriptEnabled(true);
                webview.loadUrl("https://github.com/M66B/XPrivacy#" + query);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
                alertDialogBuilder.setTitle((String) spRestriction.getSelectedItem());
                alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setView(webview);
                alertDialogBuilder.setCancelable(true);
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });

    // Setup category spinner
    spRestriction = (Spinner) findViewById(R.id.spRestriction);
    spRestriction.setAdapter(spAdapter);
    spRestriction.setOnItemSelectedListener(this);
    int pos = getSelectedCategory(userId);
    spRestriction.setSelection(pos);

    // Setup sort
    mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0"));
    mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false);

    // Start task to get app list
    AppListTask appListTask = new AppListTask();
    appListTask.executeOnExecutor(mExecutor, (Object) null);

    // Check environment
    Requirements.check(this);

    // Licensing
    checkLicense();

    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_ADDED);
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;

    boolean showChangelog = true;

    // First run
    if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) {
        showChangelog = false;
        optionAbout();
    }

    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialMain, false)) {
        showChangelog = false;
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

    // Legacy
    if (!PrivacyManager.cVersion3) {
        long now = new Date().getTime();
        String legacy = PrivacyManager.getSetting(userId, PrivacyManager.cSettingLegacy, null);
        if (legacy == null || now > Long.parseLong(legacy) + 7 * 24 * 60 * 60 * 1000L) {
            showChangelog = false;
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingLegacy, Long.toString(now));

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
            alertDialogBuilder.setTitle(R.string.app_name);
            alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
            alertDialogBuilder.setMessage(R.string.title_update_legacy);
            alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Util.viewUri(ActivityMain.this,
                            Uri.parse("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md#xprivacy3"));
                }
            });
            alertDialogBuilder.setNegativeButton(android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    });

            // Show dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    }

    // Show changelog
    if (showChangelog) {
        String sVersion = PrivacyManager.getSetting(userId, PrivacyManager.cSettingChangelog, null);
        Version changelogVersion = new Version(sVersion == null ? "0.0" : sVersion);
        Version currentVersion = new Version(Util.getSelfVersionName(this));
        if (sVersion == null || changelogVersion.compareTo(currentVersion) < 0)
            optionChangelog();
    }
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    // Set up variables for a dialog and a dialog builder. Only need one of each.
    Dialog dialog = null;/*from  w  w  w  .ja v a 2s. co m*/
    AlertDialog.Builder builder = null;

    // Determine the type of dialog based on the integer passed. These are defined in constants
    // at the top of the class.
    switch (id) {
    case DIALOG_SHOW_HOVER_TEXT:
        //Build and show the Hover Text dialog
        builder = new AlertDialog.Builder(ComicViewerActivity.this);
        builder.setMessage(comicInfo.getAlt());
        builder.setPositiveButton("Open Link...", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                openComicLink();
            }
        });
        builder.setNegativeButton("Close", null);
        dialog = builder.create();
        builder = null;
        break;
    case DIALOG_SHOW_ABOUT:
        //Build and show the About dialog
        builder = new AlertDialog.Builder(this);
        builder.setTitle(getStringAppName());
        builder.setIcon(android.R.drawable.ic_menu_info_details);
        builder.setNegativeButton(android.R.string.ok, null);
        builder.setNeutralButton("Donate", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                donate();
            }
        });
        builder.setPositiveButton("Developer Website", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                developerWebsite();
            }
        });
        View v = LayoutInflater.from(this).inflate(R.layout.about, null);
        TextView tv = (TextView) v.findViewById(R.id.aboutText);
        tv.setText(String.format(getStringAboutText(), getVersion()));
        builder.setView(v);
        dialog = builder.create();
        builder = null;
        v = null;
        tv = null;
        break;
    case DIALOG_SEARCH_BY_TITLE:
        //Build and show the Search By Title dialog
        builder = new AlertDialog.Builder(this);

        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.search_dlg, (ViewGroup) findViewById(R.id.search_dlg));

        final EditText input = (EditText) layout.findViewById(R.id.search_dlg_edit_box);

        builder.setTitle("Search by Title");
        builder.setIcon(android.R.drawable.ic_menu_search);
        builder.setView(layout);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String query = input.getText().toString();
                Uri uri = comicDef.getArchiveUrl();
                Intent i = new Intent(ComicViewerActivity.this, getArchiveActivityClass());
                i.setAction(Intent.ACTION_VIEW);
                i.setData(uri);
                i.putExtra(getPackageName() + "LoadType", ArchiveActivity.LoadType.SEARCH_TITLE);
                i.putExtra(getPackageName() + "query", query);
                startActivityForResult(i, PICK_ARCHIVE_ITEM);
            }
        });
        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        dialog = builder.create();
        builder = null;
        break;
    case DIALOG_FAILED:
        // Probably doesn't need its own builder, but because this is a special case
        // dialog I gave it one.
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        adb.setTitle("Error");
        adb.setIcon(android.R.drawable.ic_dialog_alert);

        adb.setNeutralButton(android.R.string.ok, null);

        //Set failedDialog to our dialog so we can dismiss
        //it manually
        failedDialog = adb.create();
        failedDialog.setMessage(errors);

        dialog = failedDialog;
        break;
    default:
        dialog = null;
    }

    return dialog;
}

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

private void rename(final DashboardListItem currentItem) {
    AlertDialog.Builder adb = new AlertDialog.Builder(boxThemeContextWrapper);
    LayoutInflater adbInflater = LayoutInflater.from(DashboardActivity.this);
    View inputFilename = adbInflater.inflate(R.layout.dialog_input_filename, null);
    userFilename = (TextView) inputFilename.findViewById(R.id.input_filename);
    userFilename.setText(currentItem.getFilename());
    adb.setView(inputFilename);
    adb.setTitle(getString(R.string.rename_dialog_title));
    //adb.setMessage(getString(R.string.rename_dialog_msg));

    adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String input = userFilename.getText().toString();
            File in = new File(currentItem.getPath(), currentItem.getFilename());
            File renamed = new File(currentItem.getPath(), input);
            if (in.renameTo(renamed)) {
                // set new name to the list item
                currentItem.setFilename(input);

                // update the JSON file entry
                Json.addEntryToJsonFile(DashboardActivity.this, currentItem.getId(), currentItem.getType(),
                        currentItem.getYtId(), currentItem.getPos(), currentItem.getStatus(),
                        currentItem.getPath(), input, Utils.getFileNameWithoutExt(input),
                        currentItem.getAudioExt(), currentItem.getSize(), false);

                // remove references for the old file
                String mediaUriString = Utils.getContentUriFromFilePath(in.getAbsolutePath(),
                        getContentResolver());
                //Utils.logger("d", "mediaString: " + mediaUriString, DEBUG_TAG);
                removeFromMediaStore(in, mediaUriString);

                // scan the new file
                Utils.scanMedia(DashboardActivity.this, new String[] { renamed.getAbsolutePath() },
                        new String[] { "video/*" });

                // refresh the dashboard
                refreshlist(DashboardActivity.this);

                Utils.logger("d", "'" + in.getName() + "' renamed to '" + input + "'", DEBUG_TAG);
            } else {
                Log.e(DEBUG_TAG, "'" + in.getName() + "' NOT renamed");
            }//from   ww w .ja  v a2 s.c  o m

            // hide keyboard
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(userFilename.getWindowToken(), 0);
        }
    });

    adb.setNegativeButton(getString(R.string.dialogs_negative), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // cancel
        }
    });

    secureShowDialog(adb);
}

From source file:com.aniruddhc.acemusic.player.LauncherActivity.LauncherActivity.java

public void showTrialDialog(final boolean expired, int numDaysRemaining) {

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setTitle(R.string.app_name);
    builder.setCancelable(false);/*  w  ww .  j  a va2s .  com*/

    View view = this.getLayoutInflater().inflate(R.layout.trial_expiry_dialog, null);
    TextView trialExpiredText = (TextView) view.findViewById(R.id.trial_message);
    TextView trialDaysRemaining = (TextView) view.findViewById(R.id.trial_days_remaining);
    TextView trialDaysCaps = (TextView) view.findViewById(R.id.days_caps);

    trialExpiredText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    trialExpiredText
            .setPaintFlags(trialExpiredText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    trialDaysRemaining.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));

    trialDaysCaps.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    trialDaysCaps
            .setPaintFlags(trialDaysCaps.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    if (expired) {
        trialDaysRemaining.setText(R.string.expired);
        trialExpiredText.setText(R.string.trial_expired);
        trialDaysRemaining.setTextColor(0xFFFF8800);
        trialDaysCaps.setVisibility(View.GONE);
        trialDaysRemaining.setTextSize(36);
        trialDaysRemaining.setPaintFlags(
                trialDaysRemaining.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    } else {
        trialExpiredText.setText(R.string.trial_running);
        trialDaysRemaining.setText("" + numDaysRemaining);
        trialDaysCaps.setVisibility(View.VISIBLE);
        trialDaysRemaining.setTextColor(0xFF0099CC);
        trialDaysRemaining.setPaintFlags(trialDaysRemaining.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
                | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    }

    builder.setView(view);
    builder.setPositiveButton(R.string.upgrade, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            showUpgradeFragmentWithPromo();

        }

    });

    builder.setNegativeButton(R.string.later, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (expired) {
                finish();
            } else {
                launchMainActivity();
            }

        }

    });

    builder.create().show();
}