Example usage for android.net Uri encode

List of usage examples for android.net Uri encode

Introduction

In this page you can find the example usage for android.net Uri encode.

Prototype

public static String encode(String s) 

Source Link

Document

Encodes characters in the given string as '%'-escaped octets using the UTF-8 scheme.

Usage

From source file:com.android.music.AlbumBrowserActivity.java

private Cursor getAlbumCursor(AsyncQueryHandler async, String filter) {
    String[] cols = new String[] { MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ARTIST,
            MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Albums.ALBUM_ART };

    Cursor ret = null;/*from   ww  w  .java  2s.co m*/
    if (mArtistId != null) {
        Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external", Long.valueOf(mArtistId));
        if (!TextUtils.isEmpty(filter)) {
            uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
        }
        if (async != null) {
            async.startQuery(0, null, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
        } else {
            ret = MusicUtils.query(this, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
        }
    } else {
        Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
        if (!TextUtils.isEmpty(filter)) {
            uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
        }
        if (async != null) {
            async.startQuery(0, null, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
        } else {
            ret = MusicUtils.query(this, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
        }
    }
    return ret;
}

From source file:com.nit.vicky.CardBrowser.java

private String getImgURL(Card card) {
    String imgURL = "error.jpg";
    String[] img = card.getQuestion(true).split("'");
    if (img.length > 1)
        imgURL = Utils.getBaseUrl(mCol.getMedia().getDir()) + Uri.encode(img[1]);

    return imgURL;
}

From source file:org.kei.android.phone.cellhistory.fragments.GeolocationFragment.java

@Override
public void onClick(final View v) {
    if (v.equals(rbSpeedMS)) {
        if (chart.getVisibility() == View.VISIBLE)
            chart.clear();//from   w w w .  ja v a2s.  c om
        CellHistoryApp.addLog(getActivity(), "Select MS display");
        Editor e = prefs.edit();
        e.putInt(PreferencesGeolocation.PREFS_KEY_CURRENT_SPEED, PreferencesGeolocation.PREFS_SPEED_MS);
        e.commit();
        rbSpeedKMH.setChecked(false);
        rbSpeedMPH.setChecked(false);
    } else if (v.equals(rbSpeedKMH)) {
        if (chart.getVisibility() == View.VISIBLE)
            chart.clear();
        CellHistoryApp.addLog(getActivity(), "Select KMH display");
        Editor e = prefs.edit();
        e.putInt(PreferencesGeolocation.PREFS_KEY_CURRENT_SPEED, PreferencesGeolocation.PREFS_SPEED_KMH);
        e.commit();
        rbSpeedMS.setChecked(false);
        rbSpeedMPH.setChecked(false);
    } else if (v.equals(rbSpeedMPH)) {
        if (chart.getVisibility() == View.VISIBLE)
            chart.clear();
        CellHistoryApp.addLog(getActivity(), "Select MPH display");
        Editor e = prefs.edit();
        e.putInt(PreferencesGeolocation.PREFS_KEY_CURRENT_SPEED, PreferencesGeolocation.PREFS_SPEED_MPH);
        e.commit();
        rbSpeedKMH.setChecked(false);
        rbSpeedMS.setChecked(false);
    } else if (v.equals(txtGeolocation)) {
        final String geo = txtGeolocation.getText().toString();
        if (!geo.isEmpty() && app.getProviderCtx().isValid()) {
            String cid = "-1";
            String lac = "-1";
            app.getGlobalTowerInfo().lock();
            try {
                cid = String.valueOf(app.getGlobalTowerInfo().getCellId());
                lac = String.valueOf(app.getGlobalTowerInfo().getLac());
            } finally {
                app.getGlobalTowerInfo().unlock();
            }
            final String uriBegin = "geo:" + geo;
            final String query = geo + "(CellID: " + cid + ", LAC: " + lac + ")";
            final String encodedQuery = Uri.encode(query);
            final String uriString = uriBegin + "?q=" + encodedQuery + "&z=16&iwloc=A";
            final Uri uri = Uri.parse(uriString);
            final Intent mapViewIntent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(mapViewIntent);
        }
    }
}

From source file:com.google.zxing.client.android.result.ResultHandler.java

/**
 * Do a geo search using the address as the query.
 *
 * @param address The address to find//w  w  w  .  j  a  v  a  2 s . c o m
 * @param title An optional title, e.g. the name of the business at this address
 */
final void searchMap(String address, CharSequence title) {
    String query = address;
    if (title != null && title.length() > 0) {
        query += " (" + title + ')';
    }
    launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(query))));
}

From source file:org.yammp.app.MusicPlaybackActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    Intent intent;/*from   w  w  w  . j  a  v  a 2 s  . c o m*/
    switch (item.getItemId()) {
    case MENU_ADD_TO_PLAYLIST:
        intent = new Intent(INTENT_ADD_TO_PLAYLIST);
        long[] list_to_be_added = new long[1];
        list_to_be_added[0] = MusicUtils.getCurrentAudioId();
        intent.putExtra(INTENT_KEY_LIST, list_to_be_added);
        startActivity(intent);
        break;
    case EQUALIZER:
        intent = new Intent(INTENT_EQUALIZER);
        startActivity(intent);
        break;
    case MENU_SLEEP_TIMER:
        intent = new Intent(INTENT_SLEEP_TIMER);
        startActivity(intent);
        break;
    case DELETE_ITEMS:
        intent = new Intent(INTENT_DELETE_ITEMS);
        Bundle bundle = new Bundle();
        bundle.putString(INTENT_KEY_PATH, Uri.withAppendedPath(Audio.Media.EXTERNAL_CONTENT_URI,
                Uri.encode(String.valueOf(MusicUtils.getCurrentAudioId()))).toString());
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    case SETTINGS:
        intent = new Intent(INTENT_APPEARANCE_SETTINGS);
        startActivity(intent);
        break;
    case GOTO_HOME:
        intent = new Intent(INTENT_MUSIC_BROWSER);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
        break;
    case ADD_TO_FAVORITES:
        toggleFavorite();
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.visva.voicerecorder.view.fragments.FragmentContact.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // If this is the loader for finding contacts in the Contacts Provider
    // (the only one supported)
    if (id == ContactsQuery.QUERY_ID) {
        Uri contentUri;/*from www . ja  va2s .  co m*/

        // There are two types of searches, one which displays all contacts and
        // one which filters contacts by a search query. If mSearchTerm is set
        // then a search query has been entered and the latter should be used.

        if (mSearchTerm == null) {
            // Since there's no search string, use the content URI that searches the entire
            // Contacts table
            contentUri = ContactsQuery.CONTENT_URI;
        } else {
            // Since there's a search string, use the special content Uri that searches the
            // Contacts table. The URI consists of a base Uri and the search string.
            contentUri = Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(mSearchTerm));
        }

        // Returns a new CursorLoader for querying the Contacts table. No arguments are used
        // for the selection clause. The search string is either encoded onto the content URI,
        // or no contacts search string is used. The other search criteria are constants. See
        // the ContactsQuery interface.
        return new CursorLoader(getActivity(), contentUri, ContactsQuery.PROJECTION, ContactsQuery.SELECTION,
                null, ContactsQuery.SORT_ORDER);
    }
    return null;
}

From source file:justforcommunity.radiocom.activities.Home.java

public void loadMap() {
    try {// w w  w.jav  a2s  .  co  m
        // Uri with a marker at the target, in google maps
        String uriBegin = "geo:" + station.getLatitude() + "," + station.getLongitude();
        String encodedQuery = Uri.encode(station.getStation_name());
        Uri uri = Uri.parse(uriBegin + "?q=" + encodedQuery + "&z=16");

        Intent mapIntent = new Intent(android.content.Intent.ACTION_VIEW, uri);
        startActivity(mapIntent);

    } catch (Exception e) {
        processBuilder(mContext, this, GlobalValues.baseURLWEB);
    }
}

From source file:org.musicmod.android.app.MusicPlaybackActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    Intent intent;/*  w  ww. j  av  a  2 s. co  m*/
    switch (item.getItemId()) {
    case ADD_TO_PLAYLIST:
        intent = new Intent(INTENT_ADD_TO_PLAYLIST);
        long[] list_to_be_added = new long[1];
        list_to_be_added[0] = MusicUtils.getCurrentAudioId();
        intent.putExtra(INTENT_KEY_LIST, list_to_be_added);
        startActivity(intent);
        break;
    case EQUALIZER:
        intent = new Intent(INTENT_EQUALIZER);
        startActivity(intent);
        break;
    case SLEEP_TIMER:
        intent = new Intent(INTENT_SLEEP_TIMER);
        startActivity(intent);
        break;
    case DELETE_ITEMS:
        intent = new Intent(INTENT_DELETE_ITEMS);
        Bundle bundle = new Bundle();
        bundle.putString(INTENT_KEY_PATH, Uri.withAppendedPath(Audio.Media.EXTERNAL_CONTENT_URI,
                Uri.encode(String.valueOf(MusicUtils.getCurrentAudioId()))).toString());
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    case SETTINGS:
        intent = new Intent(INTENT_APPEARANCE_SETTINGS);
        startActivity(intent);
        break;
    case GOTO_HOME:
        intent = new Intent(INTENT_MUSIC_BROWSER);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
        break;
    case ADD_TO_FAVORITES:
        toggleFavorite();
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:android.com.example.contactslist.ui.ContactsListFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    // If this is the loader for finding contacts in the Contacts Provider
    // (the only one supported)
    if (id == ContactsQuery.QUERY_ID) {
        Uri contentUri;/*w w  w  .  j a v a 2  s  .  c o m*/

        // There are two types of searches, one which displays all contacts and
        // one which filters contacts by a search query. If mSearchTerm is set
        // then a search query has been entered and the latter should be used.

        if (mSearchTerm == null) {
            // Since there's no search string, use the content URI that searches the entire
            // Contacts table
            contentUri = ContactsQuery.CONTENT_URI;
        } else {
            // Since there's a search string, use the special content Uri that searches the
            // Contacts table. The URI consists of a base Uri and the search string.
            contentUri = Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(mSearchTerm));
        }

        // Returns a new CursorLoader for querying the Contacts table. No arguments are used
        // for the selection clause. The search string is either encoded onto the content URI,
        // or no contacts search string is used. The other search criteria are constants. See
        // the ContactsQuery interface.
        return new CursorLoader(getActivity(), contentUri, ContactsQuery.PROJECTION, ContactsQuery.SELECTION,
                null, ContactsQuery.SORT_ORDER);
    }

    Log.e(TAG, "onCreateLoader - incorrect ID provided (" + id + ")");
    return null;
}