List of usage examples for android.net Uri encode
public static String encode(String s)
From source file:com.sublimis.urgentcallfilter.Magic.java
private boolean isCallerEligible() { boolean retVal = true; if (MyPreference.isContactsOnly()) { if (!strValidAndNotEmpty(mNumber)) { retVal = false;//from w w w .ja va 2 s. c o m } else { try { Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(mNumber)); if (mContext != null) { ContentResolver contentResolver = mContext.getContentResolver(); if (contentResolver != null) { Cursor cur = contentResolver.query(uri, new String[] { PhoneLookup._ID }, null, null, null); if (cur == null || cur.getCount() <= 0) { retVal = false; } if (cur != null) { cur.close(); } } } } catch (Exception e) { } } } return retVal; }
From source file:com.siahmsoft.soundroid.sdk7.provider.tracks.SoundcloudTracksStore.java
@Override Uri buildSearchTracksQuery(String query, int offset, int limit) { // http://api.soundcloud.com/tracks.json?q=quano&offset=0&limit=1 String sOffset = offset == 0 ? VALUE_START_INDEX : String.valueOf(offset); String sLimit = limit == 0 ? VALUE_MAX_RESULTS : String.valueOf(limit); StringBuffer uri = new StringBuffer(); uri.append("http://api.soundcloud.com/tracks" + API_REQUEST_TYPE + "?"); uri.append(API_ITEM_LOOKUP + "=" + Uri.encode(query)); uri.append("&" + PARAM_START_INDEX + "=" + sOffset); uri.append("&" + PARAM_MAX_RESULTS + "=" + sLimit); return Uri.parse(uri.toString()); }
From source file:com.securecomcode.text.contacts.ContactAccessor.java
public String getNameForNumber(Context context, String number) { Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); try {/* w w w. jav a 2 s . c o m*/ if (cursor != null && cursor.moveToFirst()) return cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME)); } finally { if (cursor != null) cursor.close(); } return null; }
From source file:im.delight.android.commons.Social.java
/** * Displays an application chooser and composes the described email using the selected application * * @param recipientEmail the recipient's email address * @param subjectText the subject line of the message * @param bodyText the body text of the message * @param captionRes a string resource ID for the title of the application chooser's window * @param restrictToPackage an application's package name to restricted the selection to * @param context a context reference/* www . java2s . co m*/ * @throws Exception if there was an error trying to launch the email application */ public static void sendMail(final String recipientEmail, final String subjectText, final String bodyText, final int captionRes, final String restrictToPackage, final Context context) throws Exception { final String uriString = "mailto:" + Uri.encode(recipientEmail) + "?subject=" + Uri.encode(subjectText) + "&body=" + Uri.encode(bodyText); final Uri uri = Uri.parse(uriString); final Intent emailIntent = new Intent(Intent.ACTION_SENDTO); emailIntent.setData(uri); if (restrictToPackage != null && restrictToPackage.length() > 0) { emailIntent.setPackage(restrictToPackage); if (context != null) { // launch the target app directly context.startActivity(emailIntent); } } else { if (context != null) { // offer a selection of all applications that can handle the email Intent context.startActivity(Intent.createChooser(emailIntent, context.getString(captionRes))); } } }
From source file:fr.tvbarthel.apps.cameracolorpicker.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final int itemId = item.getItemId(); boolean handled; switch (itemId) { case R.id.menu_main_action_licenses: handled = true;/*from w w w. j a v a2s . c o m*/ final Intent intent = new Intent(this, LicenseActivity.class); startActivity(intent); break; case R.id.menu_main_action_about: handled = true; AboutDialogFragment.newInstance().show(getSupportFragmentManager(), null); break; case R.id.menu_main_action_contact_us: handled = true; final String uriString = getString(R.string.contact_us_uri, Uri.encode(getString(R.string.contact_us_email)), Uri.encode(getString(R.string.contact_us_default_subject))); final Uri mailToUri = Uri.parse(uriString); final Intent sendToIntent = new Intent(Intent.ACTION_SENDTO); sendToIntent.setData(mailToUri); startActivity(sendToIntent); break; default: handled = mMainActivityFlavor.onOptionsItemSelected(item); if (!handled) { handled = super.onOptionsItemSelected(item); } } return handled; }
From source file:com.vedant.hereami.chatfolder.MyFirebaseMessagingService.java
public String getContactDisplayNameByNumber(String number) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); String name = "?"; ContentResolver contentResolver = getContentResolver(); Cursor contactLookup = contentResolver.query(uri, new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); try {/*ww w . j av a 2 s . c o m*/ if (contactLookup != null && contactLookup.getCount() > 0) { contactLookup.moveToNext(); name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)); //String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID)); hashMap.put(name, number); } } finally { if (contactLookup != null) { contactLookup.close(); } } return name; }
From source file:com.chute.android.photopickerplus.ui.fragment.FragmentSingle.java
public void updateFragment(AccountModel account, String folderId, List<Integer> selectedItemsPositions) { this.account = account; this.selectedItemsPositions = selectedItemsPositions; this.folderId = folderId; String encodedId = Uri.encode(folderId); if (getActivity() != null) { GCAccounts.accountSingle(getActivity(), PhotoPickerPreferenceUtil.get().getAccountType().name().toLowerCase(), account.getShortcut(), encodedId, new AccountSingleCallback()).executeAsync(); }/* w w w . j a v a 2 s . com*/ }
From source file:net.giovannicapuano.galax.controller.User.java
/** * Fetch the messages sent to the given user. *//* w ww .ja v a 2s . c om*/ public static Message[] fetchMessages(User user, Context context) throws Exception { String body = Utils.get("/user/messages/" + Uri.encode(user.getUsername()), context).getBody(); ArrayList<Message> messages = new ArrayList<Message>(); try { if (body.startsWith("{")) { int status = new JSONObject(body).getInt("status"); throw new Exception("Error status: " + status); } JSONArray jsonArray = new JSONArray(body); for (int i = 0, len = jsonArray.length(); i < len; ++i) { JSONObject json = jsonArray.getJSONObject(i); messages.add(new Message(json.getInt("id"), json.getString("from"), json.getString("to"), json.getString("text"))); } } catch (JSONException e) { e.printStackTrace(); } return messages.toArray(new Message[0]); }
From source file:fr.bde_eseo.eseomega.events.EventsFragment.java
@Override public View onCreateView(LayoutInflater rootInfl, ViewGroup container, Bundle savedInstanceState) { // UI// w w w .j av a 2 s . co m View rootView = rootInfl.inflate(R.layout.fragment_event_list, container, false); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.events_refresh); swipeRefreshLayout.setColorSchemeColors(R.color.md_blue_800); progCircle = (ProgressBar) rootView.findViewById(R.id.progressEvent); tv1 = (TextView) rootView.findViewById(R.id.tvListNothing); tv2 = (TextView) rootView.findViewById(R.id.tvListNothing2); img = (ImageView) rootView.findViewById(R.id.imgNoEvent); progCircle.setVisibility(View.GONE); progCircle.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.md_grey_500), PorterDuff.Mode.SRC_IN); tv1.setVisibility(View.GONE); tv2.setVisibility(View.GONE); img.setVisibility(View.GONE); disabler = new RecyclerViewDisabler(); // I/O cache data cachePath = getActivity().getCacheDir() + "/"; cacheFileEseo = new File(cachePath + "events.json"); // Init static model TicketStore.getInstance().reset(); // Model / objects eventItems = TicketStore.getInstance().getEventItems(); mAdapter = new MyEventsAdapter(getActivity(), eventItems); recList = (RecyclerView) rootView.findViewById(R.id.recyList); recList.setAdapter(mAdapter); recList.setHasFixedSize(false); LinearLayoutManager llm = new LinearLayoutManager(getActivity()); llm.setOrientation(LinearLayoutManager.VERTICAL); recList.setLayoutManager(llm); mAdapter.setEventItems(eventItems); mAdapter.notifyDataSetChanged(); // Start download of data AsyncJSON asyncJSON = new AsyncJSON(true); // circle needed for first call asyncJSON.execute(Constants.URL_JSON_EVENTS); // On click listener recList.addOnItemTouchListener( new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { final EventItem ei = eventItems.get(position); if (!ei.isHeader()) { boolean hasUrl = ei.getUrl() != null && ei.getUrl().length() != 0; boolean hasPlace = ei.getLieu() != null && ei.getLieu().length() != 0; boolean isAllDay = false; MaterialDialog.Builder mdb = new MaterialDialog.Builder(getActivity()) .customView(R.layout.dialog_event, false).positiveText("Ajouter au calendrier"); if (hasUrl) mdb.neutralText("Consulter le site"); if (hasPlace) mdb.negativeText("Y aller"); mdb.callback(new MaterialDialog.ButtonCallback() { @Override public void onNegative(MaterialDialog dialog) { // Intent : go to address super.onNegative(dialog); try { Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + Uri.encode(ei.getLieu())); Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); mapIntent.setPackage("com.google.android.apps.maps"); startActivity(mapIntent); } catch (ActivityNotFoundException ex) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps")); startActivity(intent); } } @Override public void onPositive(MaterialDialog dialog) { // Intent : add to calendar super.onPositive(dialog); startActivity(ei.toCalendarIntent()); } @Override public void onNeutral(MaterialDialog dialog) { // Intent : go to website super.onNeutral(dialog); String url = ei.getUrl(); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); MaterialDialog md = mdb.show(); View mdView = md.getView(); ((TextView) mdView.findViewById(R.id.tvEventName)).setText(ei.getName()); (mdView.findViewById(R.id.rlBackDialogEvent)).setBackgroundColor(ei.getColor()); if (ei.getDetails() != null && ei.getDetails().length() > 0) { ((TextView) mdView.findViewById(R.id.tvEventDetails)).setText(ei.getDetails()); } else { ((TextView) mdView.findViewById(R.id.tvEventDetails)) .setText("Que souhaitez vous faire ?"); } if (ei.getLieu() != null && ei.getLieu().length() > 0) { ((TextView) mdView.findViewById(R.id.tvEventPlace)) .setText("Lieu : " + ei.getLieu()); ((TextView) mdView.findViewById(R.id.tvEventPlace)).setVisibility(View.VISIBLE); } else { ((TextView) mdView.findViewById(R.id.tvEventPlace)).setVisibility(View.GONE); } } } })); // Swipe-to-refresh implementations timestamp = 0; swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { //Toast.makeText(getActivity(), "Refreshing ...", Toast.LENGTH_SHORT).show(); long t = System.currentTimeMillis() / 1000; if (t - timestamp > LATENCY_REFRESH) { // timestamp in seconds) timestamp = t; AsyncJSON asyncJSON = new AsyncJSON(false); // no circle here (already in SwipeLayout) asyncJSON.execute(Constants.URL_JSON_EVENTS); } else { swipeRefreshLayout.setRefreshing(false); } } }); return rootView; }
From source file:fr.spaz.widget.pedia.SimpleWikipediaHelper.java
public static List<String> getRandomPages(int nbItem) throws ApiException, ParseException { // Encode page title and expand templates if requested String lang = Uri.encode("en"); // Query the API for content String queryString = String.format(WIKIPEDIA_PAGE_RANDOM, lang, nbItem); String content = getUrlContent(queryString); try {/* w w w . j a va2 s .c o m*/ List<String> res = new ArrayList<String>(); // Drill into the JSON response to find the content body JSONObject response = new JSONObject(content); JSONObject query = response.getJSONObject("query"); JSONArray random = query.getJSONArray("random"); for (int i = 0; i < random.length(); i++) { JSONObject page = random.getJSONObject(i); res.add(page.getString("title")); } return res; } catch (JSONException e) { throw new ParseException("Problem parsing API response", e); } }