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.asburymotors.android.disneysocal.ui.DetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);//w  w  w.j  av a 2  s  .c om
    View view = inflater.inflate(R.layout.fragment_detail, container, false);
    String attractionName = getArguments().getString(EXTRA_ATTRACTION);
    mAttraction = findAttraction(attractionName);

    if (mAttraction == null) {
        getActivity().finish();
        return null;
    }

    TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView);
    TextView descTextView = (TextView) view.findViewById(R.id.descriptionTextView);
    TextView distanceTextView = (TextView) view.findViewById(R.id.distanceTextView);
    ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
    FloatingActionButton mapFab = (FloatingActionButton) view.findViewById(R.id.mapFab);

    LatLng location = Utils.getLocation(getActivity());
    String distance = Utils.formatDistanceBetween(location, mAttraction.location);
    if (TextUtils.isEmpty(distance)) {
        distanceTextView.setVisibility(View.GONE);
    }

    nameTextView.setText(attractionName);
    distanceTextView.setText(distance);
    descTextView.setText(mAttraction.longDescription);

    int imageSize = getResources().getDimensionPixelSize(R.dimen.image_size) * Constants.IMAGE_ANIM_MULTIPLIER;
    Glide.with(getActivity()).load(mAttraction.imageUrl).diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .placeholder(R.color.lighter_gray).override(imageSize, imageSize).into(imageView);

    mapFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri
                    .parse(Constants.MAPS_INTENT_URI + Uri.encode(mAttraction.name + ", " + mAttraction.city)));
            startActivity(intent);
        }
    });

    return view;
}

From source file:org.thoughtcrime.securesms.contacts.ContactAccessor.java

public Cursor getCursorForContactsWithPush(Context context) {
    final ContentResolver resolver = context.getContentResolver();
    final String[] inProjection = new String[] { PhoneLookup._ID, PhoneLookup.DISPLAY_NAME };
    final String[] outProjection = new String[] { PhoneLookup._ID, PhoneLookup.DISPLAY_NAME, PUSH_COLUMN };
    MatrixCursor cursor = new MatrixCursor(outProjection);
    List<String> pushNumbers = Directory.getInstance(context).getActiveNumbers();
    for (String pushNumber : pushNumbers) {
        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
        Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
        try {/*from  w ww . ja  v a 2 s  . c  om*/
            if (lookupCursor != null && lookupCursor.moveToFirst()) {
                cursor.addRow(new Object[] { lookupCursor.getLong(0), lookupCursor.getString(1), 1 });
            }
        } finally {
            if (lookupCursor != null)
                lookupCursor.close();
        }
    }
    return cursor;
}

From source file:ru.glesik.nostrangersms.SMSReceiver.java

public String getContactDisplayNameByNumber(Context context, String number) {
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    String name = "";
    ContentResolver contentResolver = context.getContentResolver();
    Cursor contactLookup = contentResolver.query(uri,
            new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);
    try {//from w  w  w  .  j ava2s . com
        if (contactLookup != null && contactLookup.getCount() > 0) {
            contactLookup.moveToNext();
            name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
        }
    } finally {
        if (contactLookup != null) {
            contactLookup.close();
        }
    }
    return name;
}

From source file:co.codecrunch.musicplayerlite.childfragment.ChildFragmentArtists.java

private Cursor getArtistCursor(AsyncQueryHandler async, String filter) {

    String[] cols = new String[] { MediaStore.Audio.Artists._ID, MediaStore.Audio.Artists.ARTIST,
            MediaStore.Audio.Artists.NUMBER_OF_ALBUMS, MediaStore.Audio.Artists.NUMBER_OF_TRACKS };

    Uri uri = MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI;
    if (!TextUtils.isEmpty(filter)) {
        uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
    }/*from  www.  jav  a  2  s  . c  o  m*/

    Cursor ret = null;
    if (async != null) {
        async.startQuery(0, null, uri, cols, null, null, MediaStore.Audio.Artists.ARTIST_KEY);
    } else {
        ret = MusicPlayerUtility.query(getActivity(), uri, cols, null, null,
                MediaStore.Audio.Artists.ARTIST_KEY);
    }
    return ret;
}

From source file:in.risysnetworks.shplayer.fragments.childfragment.ChildFragmentGenres.java

private Cursor getGenersCursor(AsyncQueryHandler async, String filter) {

    String[] cols = new String[] { MediaStore.Audio.Genres._ID, MediaStore.Audio.Genres.NAME };

    Uri uri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;
    if (!TextUtils.isEmpty(filter)) {
        uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
    }//from  w  ww .  j a  v a 2  s.  c  om

    Cursor ret = null;
    if (async != null) {
        async.startQuery(0, null, uri, cols, null, null, null);
    } else {
        ret = SHPlayerUtility.query(getActivity(), uri, cols, null, null, null);
    }
    return ret;
}

From source file:com.example.android.xyztouristattractions.ui.ToursListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);//from www .j  av  a  2s .c om
    View view = inflater.inflate(R.layout.parc_detail, container, false);
    String attractionName = getArguments().getString(EXTRA_ATTRACTION);
    mAttraction = findAttraction(attractionName);

    if (mAttraction == null) {
        getActivity().finish();
        return null;
    }

    TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView);
    TextView descTextView = (TextView) view.findViewById(R.id.descriptionTextView);
    TextView numeriUtiliTextView = (TextView) view.findViewById(R.id.numeriUtiliTextView);
    TextView distanceTextView = (TextView) view.findViewById(R.id.distanceTextView);
    ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
    FloatingActionButton mapFab = (FloatingActionButton) view.findViewById(R.id.mapFab);

    LatLng location = Utils.getLocation(getActivity());
    String distance = Utils.formatDistanceBetween(location, mAttraction.location);
    if (TextUtils.isEmpty(distance)) {
        distanceTextView.setVisibility(View.GONE);
    }

    nameTextView.setText(attractionName);
    distanceTextView.setText(distance);
    numeriUtiliTextView.setText(mAttraction.numeriUtili);
    descTextView.setText(mAttraction.longDescription);

    int imageSize = getResources().getDimensionPixelSize(R.dimen.image_size) * Constants.IMAGE_ANIM_MULTIPLIER;
    Glide.with(getActivity()).load(mAttraction.secondaryImageUrl).diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .placeholder(R.color.lighter_gray).override(imageSize, imageSize).into(imageView);

    mapFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(Constants.MAPS_INTENT_URI + Uri.encode(mAttraction.city)));
            startActivity(intent);
        }
    });

    return view;
}

From source file:org.peterbaldwin.vlcremote.fragment.PlaybackFragment.java

/** {@inheritDoc} */
public void onClick(View v) {
    if (v == mButtonPlaylistPause) {
        playlist().pause();/*from  www  .j a v  a 2  s  .  c o  m*/
    } else if (v == mButtonPlaylistStop) {
        playlist().stop();
    } else if (v == mButtonPlaylistSkipBackward) {
        playlist().previous();
    } else if (v == mButtonPlaylistSkipForward) {
        playlist().next();
    } else if (v == mButtonPlaylistSeekBackward) {
        command().seek(Uri.encode("-10"));
    } else if (v == mButtonPlaylistSeekForward) {
        command().seek(Uri.encode("+10"));
    }
}

From source file:com.nikhilnayak.games.octoshootar.ui.fragments.AboutFragment.java

private void sendUsAnEmail(int subjectResourceId) {
    final String uriString = getString(R.string.email_us_uri, Uri.encode(getString(R.string.email_us_email)),
            Uri.encode(getString(subjectResourceId)));
    final Uri mailToUri = Uri.parse(uriString);
    Intent sendToIntent = new Intent(Intent.ACTION_SENDTO);
    sendToIntent.setData(mailToUri);//from  w w w. j a  va2  s  .com
    startActivity(sendToIntent);
}

From source file:com.dmplayer.childfragment.ChildFragmentAlbum.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 . ja  va2s . com
    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 = DMPlayerUtility.query(getActivity(), uri, cols, null, null,
                MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
    }
    return ret;
}

From source file:org.thoughtcrime.SMP.contacts.ContactAccessor.java

public Collection<ContactData> getContactsWithPush(Context context) {
    final ContentResolver resolver = context.getContentResolver();
    final String[] inProjection = new String[] { PhoneLookup._ID, PhoneLookup.DISPLAY_NAME };

    List<String> pushNumbers = TextSecureDirectory.getInstance(context).getActiveNumbers();
    final Collection<ContactData> lookupData = new ArrayList<ContactData>(pushNumbers.size());

    for (String pushNumber : pushNumbers) {
        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
        Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
        try {/*ww  w .  ja v  a  2 s  . c  o  m*/
            if (lookupCursor != null && lookupCursor.moveToFirst()) {
                final ContactData contactData = new ContactData(lookupCursor.getLong(0),
                        lookupCursor.getString(1));
                contactData.numbers.add(new NumberData("TextSecure", pushNumber));
                lookupData.add(contactData);
            }
        } finally {
            if (lookupCursor != null)
                lookupCursor.close();
        }
    }
    return lookupData;
}