Example usage for android.app ProgressDialog setCancelable

List of usage examples for android.app ProgressDialog setCancelable

Introduction

In this page you can find the example usage for android.app ProgressDialog setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.andrewshu.android.reddit.reddits.PickSubredditActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;/* w  w w. jav a  2 s  .  co m*/
    ProgressDialog pdialog;

    switch (id) {
    // "Please wait"
    case Constants.DIALOG_LOADING_REDDITS_LIST:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Loading your reddits...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticatorActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_PROGRESS:

        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setMessage(getText(R.string.login_message_authenticating));
        dialog.setIndeterminate(true);/* w  ww  .j a va2 s  . c om*/
        dialog.setCancelable(true);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                if (BuildConfig.DEBUG) {
                    Log.i(TAG, "dialog cancel has been invoked");
                }
                if (mAuthenticationTask != null) {
                    mAuthenticationTask.cancel(true);
                    mAuthenticationTask = null;
                    finish();
                }
            }
        });
        return dialog;

    default:
        return null;
    }
}

From source file:com.artur.softwareproject.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.disconnect:

        if (!recording) {
            stopService(bluetoothServiceIntent);

            final ProgressDialog disconnectingDialog = new ProgressDialog(Main.this);

            disconnectingDialog.setMessage("Disconnecting...");
            disconnectingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            disconnectingDialog.setCancelable(false);
            disconnectingDialog.show();/*from w  w w.  ja  va 2s  .co  m*/

            disconDialog = disconnectingDialog;

            final DisconnectHandlerClass disconnectHandler = new DisconnectHandlerClass(this);

            disconnectThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    int stop = 0;

                    while (stop == 0) {
                        stop = getDisconnect();
                        sleep(1500);
                    }

                    disconnectHandler.sendEmptyMessage(0);
                }
            });

            disconnectThread.start();
        }

        return true;

    case R.id.record_data:

        Log.d(TAG, "Record button was Pressed. Gps status: " + gpsStatus);

        if (!recording && gpsStatus) {
            Intent resetIntent = new Intent();

            resetIntent.putExtra("reset", "");
            resetIntent.setAction("resetFilter");

            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(resetIntent);

            item.setIcon(R.drawable.ic_action_stop);

            Toast.makeText(getApplicationContext(), "Start recording data", Toast.LENGTH_LONG).show();

            currentTime = System.currentTimeMillis();
            recordClock.setVisibility(View.VISIBLE);

            Animation a = AnimationUtils.loadAnimation(this, R.anim.textslide);
            TextView tv = (TextView) findViewById(R.id.recordClock);

            tv.startAnimation(a);

            recording = true;

            if (!rBound) {
                Intent intent = new Intent(this, RecordService.class);
                bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
            }
        } else if (recording) {
            stopRecording();
        }

        return true;

    case R.id.vr_menu:

        if (!recording) {
            Intent vrIntent = new Intent(Main.this, VRmenuMap.class);
            Main.this.startActivity(vrIntent);
        }

        return true;

    default:

        return super.onOptionsItemSelected(item);
    }
}

From source file:it.scoppelletti.mobilepower.app.ProgressDialogFragment.java

/**
 * Crea il dialogo.//www. j a v a  2 s .c  o m
 * 
 * @param  savedInstanceState Stato dell’istanza.
 * @return                    Dialogo.
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int max, resId;
    ProgressDialog dlg;
    Bundle args = getArguments();

    dlg = new ProgressDialog(getActivity(), AppUtils.getDialogTheme());

    resId = args.getInt(ProgressDialogFragment.ARG_TITLEID);
    dlg.setTitle(getString(resId));
    max = args.getInt(ProgressDialogFragment.ARG_MAX, -1);

    if (max > 0) {
        dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dlg.setIndeterminate(false);
        dlg.setMax(max);
    } else {
        dlg.setIndeterminate(true);
        dlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }

    dlg.setCancelable(args.getBoolean(ProgressDialogFragment.ARG_CANCELABLE));
    dlg.setCanceledOnTouchOutside(false);

    return dlg;
}

From source file:nl.privacybarometer.privacyvandaag.activity.EditFeedActivity.java

public void onClickOk(View view) {
    // only in insert mode

    final String name = mNameEditText.getText().toString().trim();
    final String urlOrSearch = mUrlEditText.getText().toString().trim();
    final String cookieName = mCookieNameEditText.getText().toString();
    final String cookieValue = mCookieValueEditText.getText().toString();
    final TypedArray selectedValues = getResources().obtainTypedArray(R.array.settings_keep_time_values);
    final Integer keepTime = selectedValues.getInt(mKeepTime.getSelectedItemPosition(), 0);
    final String iconDrawable = "";

    if (urlOrSearch.isEmpty()) {
        Toast.makeText(this, R.string.error_feed_error, Toast.LENGTH_SHORT).show();
    }/*from www  . ja  v a  2 s  .c  o m*/

    if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) {
        final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
        pd.setMessage(getString(R.string.loading));
        pd.setCancelable(true);
        pd.setIndeterminate(true);
        pd.show();

        getLoaderManager().restartLoader(1, null,
                new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                    @Override
                    public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id, Bundle args) {
                        String encodedSearchText = urlOrSearch;
                        try {
                            encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8);
                        } catch (UnsupportedEncodingException ignored) {
                        }

                        return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText);
                    }

                    @Override
                    public void onLoadFinished(Loader<ArrayList<HashMap<String, String>>> loader,
                            final ArrayList<HashMap<String, String>> data) {
                        pd.cancel();

                        if (data == null) {
                            Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                        } else if (data.isEmpty()) {
                            Toast.makeText(EditFeedActivity.this, R.string.no_result, Toast.LENGTH_SHORT)
                                    .show();
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(EditFeedActivity.this);
                            builder.setTitle(R.string.feed_search);

                            // create the grid item mapping
                            String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC };
                            int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

                            // fill in the grid_item layout
                            SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this, data,
                                    R.layout.item_search_result, from, to);
                            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    FeedDataContentProvider.addFeed(EditFeedActivity.this,
                                            data.get(which).get(FEED_SEARCH_URL),
                                            name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name,
                                            mRetrieveFulltextCb.isChecked(), cookieName, cookieValue, keepTime,
                                            iconDrawable);

                                    setResult(RESULT_OK);
                                    finish();
                                }
                            });
                            builder.show();
                        }
                    }

                    @Override
                    public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) {
                    }
                });
    } else {
        FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name,
                mRetrieveFulltextCb.isChecked(), cookieName, cookieValue, keepTime, iconDrawable);

        setResult(RESULT_OK);
        finish();
    }
}

From source file:net.fred.feedex.activity.EditFeedActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();//  w ww.j a va2s .c o  m
        return true;
    case R.id.menu_validate: // only in insert mode
        final String name = mNameEditText.getText().toString().trim();
        final String urlOrSearch = mUrlEditText.getText().toString().trim();
        if (urlOrSearch.isEmpty()) {
            UiUtils.showMessage(EditFeedActivity.this, R.string.error_feed_error);
        }

        if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) {
            final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
            pd.setMessage(getString(R.string.loading));
            pd.setCancelable(true);
            pd.setIndeterminate(true);
            pd.show();

            getLoaderManager().restartLoader(1, null,
                    new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                        @Override
                        public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id, Bundle args) {
                            String encodedSearchText = urlOrSearch;
                            try {
                                encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8);
                            } catch (UnsupportedEncodingException ignored) {
                            }

                            return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText);
                        }

                        @Override
                        public void onLoadFinished(Loader<ArrayList<HashMap<String, String>>> loader,
                                final ArrayList<HashMap<String, String>> data) {
                            pd.cancel();

                            if (data == null) {
                                UiUtils.showMessage(EditFeedActivity.this, R.string.error);
                            } else if (data.isEmpty()) {
                                UiUtils.showMessage(EditFeedActivity.this, R.string.no_result);
                            } else {
                                AlertDialog.Builder builder = new AlertDialog.Builder(EditFeedActivity.this);
                                builder.setTitle(R.string.feed_search);

                                // create the grid item mapping
                                String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC };
                                int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

                                // fill in the grid_item layout
                                SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this, data,
                                        R.layout.item_search_result, from, to);
                                builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        FeedDataContentProvider.addFeed(EditFeedActivity.this,
                                                data.get(which).get(FEED_SEARCH_URL),
                                                name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name,
                                                mRetrieveFulltextCb.isChecked());

                                        setResult(RESULT_OK);
                                        finish();
                                    }
                                });
                                builder.show();
                            }
                        }

                        @Override
                        public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) {
                        }
                    });
        } else {
            FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name,
                    mRetrieveFulltextCb.isChecked());

            setResult(RESULT_OK);
            finish();
        }
        return true;
    case R.id.menu_add_filter: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_filter_edit, null);

        new AlertDialog.Builder(this) //
                .setTitle(R.string.filter_add_title) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText()
                                .toString();
                        if (filterText.length() != 0) {
                            String feedId = getIntent().getData().getLastPathSegment();

                            ContentValues values = new ContentValues();
                            values.put(FilterColumns.FILTER_TEXT, filterText);
                            values.put(FilterColumns.IS_REGEX,
                                    ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked());
                            values.put(FilterColumns.IS_APPLIED_TO_TITLE,
                                    ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked());
                            values.put(FilterColumns.IS_ACCEPT_RULE,
                                    ((RadioButton) dialogView.findViewById(R.id.acceptRadio)).isChecked());

                            ContentResolver cr = getContentResolver();
                            cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values);
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                    }
                }).show();
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.PhotoUploadWidget.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == Crop.REQUEST_CROP) {
        handleCrop(resultCode, data);/*from w  w  w.j  a  va  2  s.c o  m*/
    } else if (requestCode == PICK_IMAGE) {
        if (resultCode == Activity.RESULT_OK) {
            if (data != null && data.getData() != null) {
                if (mRatio == null) {
                    final Uri selectedImage = data.getData();

                    final ProgressDialog progressDialog = new ProgressDialog(mActivity);
                    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    progressDialog.setMessage(mActivity.getString(R.string.processing));
                    progressDialog.setCancelable(false);
                    progressDialog.show();

                    new SafeAsyncTask<Object, Object, Boolean>() {
                        @Override
                        protected Boolean safeDoInBackground(Object... params) {
                            L.d("Processing picture: " + selectedImage.getPath());
                            try {
                                File tmpUploadFile = getTmpUploadPhotoLocation();
                                if (tmpUploadFile.getAbsolutePath().equals(selectedImage.getPath())) {
                                    return true;
                                } else {
                                    InputStream is = mActivity.getContentResolver()
                                            .openInputStream(selectedImage);
                                    if (is != null) {
                                        try {
                                            OutputStream out = new FileOutputStream(tmpUploadFile);
                                            try {
                                                IOUtils.copy(is, out, 1024);
                                            } finally {
                                                out.close();
                                            }
                                        } finally {
                                            is.close();
                                        }
                                        return true;
                                    }
                                }
                            } catch (FileNotFoundException e) {
                                L.d(e);
                            } catch (Exception e) {
                                L.bug("Unknown exception occured while processing picture: "
                                        + selectedImage.toString(), e);
                            }

                            return false;
                        };

                        @Override
                        protected void safeOnPostExecute(Boolean result) {
                            progressDialog.dismiss();
                            if (result) {
                                handleSelection();
                            } else {
                                UIUtils.showLongToast(getContext(), R.string.crop__pick_error);
                            }
                        }

                        @Override
                        protected void safeOnCancelled(Boolean result) {
                        }

                        @Override
                        protected void safeOnProgressUpdate(Object... values) {
                        }

                        @Override
                        protected void safeOnPreExecute() {
                        };
                    }.execute();

                } else {
                    beginCrop(data.getData());
                    return;
                }
            } else {
                if (mRatio == null) {
                    handleSelection();
                } else {
                    beginCrop(mUriSavedImage);
                }
            }
        }
    } else {
        L.bug("Unexpected request code in onActivityResult: " + requestCode);
    }
}

From source file:org.ohmage.authenticator.AuthenticatorActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = super.onCreateDialog(id);
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    switch (id) {

    case DIALOG_LOGIN_ERROR:
        dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_auth_error).setCancelable(true)
                .setPositiveButton(R.string.ok, null)
        /*/* www  . j  av  a 2  s .c o  m*/
         * .setNeutralButton("Help", new
         * DialogInterface.OnClickListener() {
         * @Override public void onClick(DialogInterface dialog, int
         * which) { startActivity(new Intent(LoginActivity.this,
         * HelpActivity.class)); //put extras for specific help on login
         * error } })
         */;
        // add button for contact
        dialog = dialogBuilder.create();
        break;

    case DIALOG_USER_DISABLED:
        dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_account_disabled)
                .setCancelable(true).setPositiveButton(R.string.ok, null)
        /*
         * .setNeutralButton("Help", new
         * DialogInterface.OnClickListener() {
         * @Override public void onClick(DialogInterface dialog, int
         * which) { startActivity(new Intent(LoginActivity.this,
         * HelpActivity.class)); //put extras for specific help on login
         * error } })
         */;
        // add button for contact
        dialog = dialogBuilder.create();
        break;

    case DIALOG_NETWORK_ERROR:
        dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_network_error)
                .setCancelable(true).setPositiveButton(R.string.ok, null)
        /*
         * .setNeutralButton("Help", new
         * DialogInterface.OnClickListener() {
         * @Override public void onClick(DialogInterface dialog, int
         * which) { startActivity(new Intent(LoginActivity.this,
         * HelpActivity.class)); //put extras for specific help on http
         * error } })
         */;
        // add button for contact
        dialog = dialogBuilder.create();
        break;

    case DIALOG_INTERNAL_ERROR:
        dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_server_error).setCancelable(true)
                .setPositiveButton(R.string.ok, null)
        /*
         * .setNeutralButton("Help", new
         * DialogInterface.OnClickListener() {
         * @Override public void onClick(DialogInterface dialog, int
         * which) { startActivity(new Intent(LoginActivity.this,
         * HelpActivity.class)); //put extras for specific help on http
         * error } })
         */;
        // add button for contact
        dialog = dialogBuilder.create();
        break;

    case DIALOG_LOGIN_PROGRESS: {
        pDialog = new ProgressDialog(this);
        pDialog.setMessage(getString(R.string.login_authenticating, getString(R.string.server_name)));
        pDialog.setIndeterminate(true);
        pDialog.setCancelable(false);
        dialog = pDialog;
        break;
    }
    case DIALOG_DOWNLOADING_CAMPAIGNS: {
        ProgressDialog pDialog = new ProgressDialog(this);
        pDialog.setMessage(getString(R.string.login_download_campaign));
        pDialog.setCancelable(false);
        // pDialog.setIndeterminate(true);
        dialog = pDialog;
        break;
    }
    case DIALOG_SERVER_LIST: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        ArrayList<String> servers = Lists.newArrayList(getResources().getStringArray(R.array.servers));

        if (OhmageApplication.DEBUG_BUILD) {
            servers.add("https://test.ohmage.org/");
        }

        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1,
                servers);

        builder.setTitle(R.string.login_choose_server);
        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                mServerEdit
                        .setText(((AlertDialog) dialog).getListView().getAdapter().getItem(which).toString());
            }
        });

        dialog = builder.create();
        break;
    }
    }

    return dialog;
}

From source file:cn.edu.nju.dapenti.activity.EditFeedActivity.java

public void onClickSearch(View view) {
    final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null);
    final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText);
    final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup);

    new AlertDialog.Builder(EditFeedActivity.this) //
            .setIcon(R.drawable.action_search) //
            .setTitle(R.string.feed_search) //
            .setView(dialogView) //
            .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
                @Override//from   w  ww. j  a  v  a  2 s. c  om
                public void onClick(DialogInterface dialog, int which) {

                    if (searchText.getText().length() > 0) {
                        String tmp = searchText.getText().toString();
                        try {
                            tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8);
                        } catch (UnsupportedEncodingException ignored) {
                        }
                        final String text = tmp;

                        switch (radioGroup.getCheckedRadioButtonId()) {
                        case R.id.byWebSearch:
                            final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
                            pd.setMessage(getString(R.string.loading));
                            pd.setCancelable(true);
                            pd.setIndeterminate(true);
                            pd.show();

                            getLoaderManager().restartLoader(1, null,
                                    new LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                                        @Override
                                        public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id,
                                                Bundle args) {
                                            return new GetFeedSearchResultsLoader(EditFeedActivity.this, text);
                                        }

                                        @Override
                                        public void onLoadFinished(
                                                Loader<ArrayList<HashMap<String, String>>> loader,
                                                final ArrayList<HashMap<String, String>> data) {
                                            pd.cancel();

                                            if (data == null) {
                                                Toast.makeText(EditFeedActivity.this, R.string.error,
                                                        Toast.LENGTH_SHORT).show();
                                            } else if (data.isEmpty()) {
                                                Toast.makeText(EditFeedActivity.this, R.string.no_result,
                                                        Toast.LENGTH_SHORT).show();
                                            } else {
                                                AlertDialog.Builder builder = new AlertDialog.Builder(
                                                        EditFeedActivity.this);
                                                builder.setTitle(R.string.feed_search);

                                                // create the grid item mapping
                                                String[] from = new String[] { FEED_SEARCH_TITLE,
                                                        FEED_SEARCH_DESC };
                                                int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

                                                // fill in the grid_item layout
                                                SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this,
                                                        data, R.layout.item_search_result, from, to);
                                                builder.setAdapter(adapter,
                                                        new DialogInterface.OnClickListener() {
                                                            @Override
                                                            public void onClick(DialogInterface dialog,
                                                                    int which) {
                                                                mNameEditText.setText(
                                                                        data.get(which).get(FEED_SEARCH_TITLE));
                                                                mUrlEditText.setText(
                                                                        data.get(which).get(FEED_SEARCH_URL));
                                                            }
                                                        });
                                                builder.show();
                                            }
                                        }

                                        @Override
                                        public void onLoaderReset(
                                                Loader<ArrayList<HashMap<String, String>>> loader) {
                                        }
                                    }).forceLoad();
                            break;

                        case R.id.byTopic:
                            mUrlEditText.setText("http://www.faroo.com/api?q=" + text
                                    + "&start=1&length=10&l=en&src=news&f=rss");
                            break;

                        case R.id.byYoutube:
                            mUrlEditText.setText("http://www.youtube.com/rss/user/" + text.replaceAll("\\+", "")
                                    + "/videos.rss");
                            break;
                        }
                    }
                }
            }).setNegativeButton(android.R.string.cancel, null).show();
}

From source file:co.nerdart.ourss.activity.EditFeedActivity.java

public void onClickSearch(View view) {
    final View dialogView = getLayoutInflater().inflate(R.layout.search_feed, null);
    final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText);
    final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup);

    new AlertDialog.Builder(EditFeedActivity.this) //
            .setIcon(R.drawable.action_search) //
            .setTitle(R.string.feed_search) //
            .setView(dialogView) //
            .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
                @Override/*from www  .ja v a  2  s .  c o m*/
                public void onClick(DialogInterface dialog, int which) {

                    if (searchText.getText().length() > 0) {
                        String tmp = searchText.getText().toString();
                        try {
                            tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8);
                        } catch (UnsupportedEncodingException ignored) {
                        }
                        final String text = tmp;

                        switch (radioGroup.getCheckedRadioButtonId()) {
                        case R.id.byWebSearch:
                            final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
                            pd.setMessage(getString(R.string.loading));
                            pd.setCancelable(true);
                            pd.setIndeterminate(true);
                            pd.show();

                            getLoaderManager().restartLoader(1, null,
                                    new LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                                        @Override
                                        public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id,
                                                Bundle args) {
                                            return new GetFeedSearchResultsLoader(EditFeedActivity.this, text);
                                        }

                                        @Override
                                        public void onLoadFinished(
                                                Loader<ArrayList<HashMap<String, String>>> loader,
                                                final ArrayList<HashMap<String, String>> data) {
                                            pd.cancel();

                                            if (data == null) {
                                                Crouton.makeText(EditFeedActivity.this, R.string.error,
                                                        Style.INFO);
                                            } else if (data.isEmpty()) {
                                                Crouton.makeText(EditFeedActivity.this, R.string.no_result,
                                                        Style.INFO);
                                            } else {
                                                AlertDialog.Builder builder = new AlertDialog.Builder(
                                                        EditFeedActivity.this);
                                                builder.setTitle(R.string.feed_search);

                                                // create the grid item mapping
                                                String[] from = new String[] { FEED_SEARCH_TITLE,
                                                        FEED_SEARCH_DESC };
                                                int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

                                                // fill in the grid_item layout
                                                SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this,
                                                        data, R.layout.search_result_item, from, to);
                                                builder.setAdapter(adapter,
                                                        new DialogInterface.OnClickListener() {
                                                            @Override
                                                            public void onClick(DialogInterface dialog,
                                                                    int which) {
                                                                mNameEditText.setText(
                                                                        data.get(which).get(FEED_SEARCH_TITLE));
                                                                mUrlEditText.setText(
                                                                        data.get(which).get(FEED_SEARCH_URL));
                                                            }
                                                        });
                                                builder.show();
                                            }
                                        }

                                        @Override
                                        public void onLoaderReset(
                                                Loader<ArrayList<HashMap<String, String>>> loader) {
                                        }
                                    }).forceLoad();
                            break;

                        case R.id.byTopic:
                            mUrlEditText.setText("http://www.faroo.com/api?q=" + text
                                    + "&start=1&length=10&l=en&src=news&f=rss");
                            break;

                        case R.id.byYoutube:
                            mUrlEditText.setText("http://www.youtube.com/rss/user/" + text.replaceAll("\\+", "")
                                    + "/videos.rss");
                            break;
                        }
                    }
                }
            }).setNegativeButton(android.R.string.cancel, null).show();
}