List of usage examples for android.net Uri encode
public static String encode(String s)
From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java
/** * When a particular suggestion has been selected, perform the various lookups required * to use the suggestion. This includes checking the cursor for suggestion-specific data, * and/or falling back to the XML for defaults; It also creates REST style Uri data when * the suggestion includes a data id./* w w w . ja v a 2 s . c o m*/ * * @param c The suggestions cursor, moved to the row of the user's selection * @param actionKey The key code of the action key that was pressed, * or {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg The message for the action key that was pressed, * or <code>null</code> if none. * @return An intent for the suggestion at the cursor's position. */ private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) { try { // use specific action if supplied, or default action if supplied, or fixed default String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION); if (action == null) { action = mSearchable.getSuggestIntentAction(); } if (action == null) { action = Intent.ACTION_SEARCH; } // use specific data if supplied, or default data if supplied String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA); if (data == null) { data = mSearchable.getSuggestIntentData(); } // then, if an ID was provided, append it. if (data != null) { String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID); if (id != null) { data = data + "/" + Uri.encode(id); } } Uri dataUri = (data == null) ? null : Uri.parse(data); String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY); String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA); return createIntent(action, dataUri, extraData, query, actionKey, actionMsg); } catch (RuntimeException e) { int rowNum; try { // be really paranoid now rowNum = c.getPosition(); } catch (RuntimeException e2) { rowNum = -1; } Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e); return null; } }
From source file:android.support.v7ox.widget.SearchView.java
/** * When a particular suggestion has been selected, perform the various lookups required * to use the suggestion. This includes checking the cursor for suggestion-specific data, * and/or falling back to the XML for defaults; It also creates REST style Uri data when * the suggestion includes a data id.//from w ww. j av a2 s . c o m * * @param c The suggestions cursor, moved to the row of the user's selection * @param actionKey The key code of the action key that was pressed, * or {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg The message for the action key that was pressed, * or <code>null</code> if none. * @return An intent for the suggestion at the cursor's position. */ private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) { try { // use specific action if supplied, or default action if supplied, or fixed default String action = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION); if (action == null && Build.VERSION.SDK_INT >= 8) { action = mSearchable.getSuggestIntentAction(); } if (action == null) { action = Intent.ACTION_SEARCH; } // use specific data if supplied, or default data if supplied String data = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA); if (IS_AT_LEAST_FROYO && data == null) { data = mSearchable.getSuggestIntentData(); } // then, if an ID was provided, append it. if (data != null) { String id = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID); if (id != null) { data = data + "/" + Uri.encode(id); } } Uri dataUri = (data == null) ? null : Uri.parse(data); String query = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY); String extraData = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA); return createIntent(action, dataUri, extraData, query, actionKey, actionMsg); } catch (RuntimeException e) { int rowNum; try { // be really paranoid now rowNum = c.getPosition(); } catch (RuntimeException e2) { rowNum = -1; } Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e); return null; } }
From source file:com.example.navigationsearchview.NavigationSearchView.java
/** * When a particular suggestion has been selected, perform the various * lookups required to use the suggestion. This includes checking the cursor * for suggestion-specific data, and/or falling back to the XML for * defaults; It also creates REST style Uri data when the suggestion * includes a data id.// ww w .j a v a 2s .co m * * @param c * The suggestions cursor, moved to the row of the user's * selection * @param actionKey * The key code of the action key that was pressed, or * {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg * The message for the action key that was pressed, or * <code>null</code> if none. * @return An intent for the suggestion at the cursor's position. */ private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) { try { // use specific action if supplied, or default action if supplied, // or fixed default String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION); if (action == null && Build.VERSION.SDK_INT >= 8) { action = mSearchable.getSuggestIntentAction(); } if (action == null) { action = Intent.ACTION_SEARCH; } // use specific data if supplied, or default data if supplied String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA); if (IS_AT_LEAST_FROYO && data == null) { data = mSearchable.getSuggestIntentData(); } // then, if an ID was provided, append it. if (data != null) { String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID); if (id != null) { data = data + "/" + Uri.encode(id); } } Uri dataUri = (data == null) ? null : Uri.parse(data); String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY); String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA); return createIntent(action, dataUri, extraData, query, actionKey, actionMsg); } catch (RuntimeException e) { int rowNum; try { // be really paranoid now rowNum = c.getPosition(); } catch (RuntimeException e2) { rowNum = -1; } Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e); return null; } }
From source file:com.juick.android.JuickMessagesAdapter.java
public static String setupProxyForURL(Context context, String url, DefaultHttpClient httpClient) { if (useDirectImageMode(context)) { return url; }//from w ww .ja va2 s. c o m String loadURl = url; if (imageLoadMode.contains("japroxy")) { final int HEIGHT = (int) (((Activity) context).getWindow().getWindowManager().getDefaultDisplay() .getHeight() * imageHeightPercent); final int WIDTH = (int) (((Activity) context).getWindow().getWindowManager().getDefaultDisplay() .getWidth()); String host = "ja.servebeer.com:8080"; //String host = "192.168.1.77:8080"; if (url.startsWith("https://i.juick.com")) { url = "http" + url.substring(5); } loadURl = "http://" + host + "/img?url=" + Uri.encode(url) + "&height=" + HEIGHT + "&width=" + WIDTH; } if (imageLoadMode.contains("weserv")) { final int HEIGHT = (int) (((Activity) context).getWindow().getWindowManager().getDefaultDisplay() .getHeight() * imageHeightPercent); // WESERV.NL if (url.startsWith("https://")) { loadURl = "http://images.weserv.nl/?url=ssl:" + Uri.encode(url.substring(8)) + "&h=" + HEIGHT + "&q=0.5"; } else if (url.startsWith("http://")) { loadURl = "http://images.weserv.nl/?url=" + Uri.encode(url.substring(7)) + "&h=" + HEIGHT + "&q=0.5"; } else { // keep url } } if (imageLoadMode.contains("fastun")) { if (httpClient != null) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); String proxyLogin = sp.getString("imageproxy.login", ""); String proxyPassword = sp.getString("imageproxy.password", ""); if (proxyLogin.length() > 0 && proxyPassword.length() > 0) { httpClient.getCredentialsProvider().setCredentials(new AuthScope("fastun.com", 7000), new UsernamePasswordCredentials(proxyLogin, proxyPassword)); HttpHost proxy = new HttpHost("fastun.com", 7000); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } } } return loadURl; }
From source file:com.juick.android.JuickMessagesAdapter.java
public static String urlToFileName(Context ctx, String url) { StringBuilder sb = new StringBuilder(); String curl = Uri.encode(url); int ask = url.indexOf('?'); if (ask != -1) { String suburl = url.substring(0, ask); if (isValidImageURl(ctx, suburl)) { int q = suburl.lastIndexOf('.'); // somefile.jpg?zz=true -> somefile.jpg?zz=true.jpg -> somefile.jpg_zz_true.jpg url += suburl.substring(q);/*ww w.j av a 2s . c o m*/ } } for (int i = 0; i < curl.length(); i++) { char c = curl.charAt(i); if (Character.isLetterOrDigit(c) || c == '.') { sb.append(c); } else { sb.append("_"); } } String retval = sb.toString(); if (retval.length() > 120) { String md5DigestForString = Utils.getMD5DigestForString(retval).replace("/", "_"); int q = retval.lastIndexOf('.'); return "longname_" + md5DigestForString + retval.substring(q); } return retval; }
From source file:com.xandy.calendar.EventInfoFragment.java
/** * Taken from com.google.android.gm.HtmlConversationActivity * * Send the intent that shows the Contact info corresponding to the email address. *//*from ww w . j a v a 2 s. co m*/ public void showContactInfo(CalendarEventModel.Attendee attendee, Rect rect) { // First perform lookup query to find existing contact final ContentResolver resolver = getActivity().getContentResolver(); final String address = attendee.mEmail; final Uri dataUri = Uri.withAppendedPath(CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(address)); final Uri lookupUri = ContactsContract.Data.getContactLookupUri(resolver, dataUri); if (lookupUri != null) { // Found matching contact, trigger QuickContact QuickContact.showQuickContact(getActivity(), rect, lookupUri, QuickContact.MODE_MEDIUM, null); } else { // No matching contact, ask user to create one final Uri mailUri = Uri.fromParts("mailto", address, null); final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, mailUri); // Pass along full E-mail string for possible create dialog Rfc822Token sender = new Rfc822Token(attendee.mName, attendee.mEmail, null); intent.putExtra(Intents.EXTRA_CREATE_DESCRIPTION, sender.toString()); // Only provide personal name hint if we have one final String senderPersonal = attendee.mName; if (!TextUtils.isEmpty(senderPersonal)) { intent.putExtra(Intents.Insert.NAME, senderPersonal); } startActivity(intent); } }
From source file:com.lgallardo.qbittorrentclient.RefreshListener.java
public void setLabelDialog(final String hash) { // get prompts.xml view LayoutInflater li = LayoutInflater.from(MainActivity.this); View view = li.inflate(R.layout.set_label, null); // URL input//from w w w.j a v a 2 s . c o m final EditText label = (EditText) view.findViewById(R.id.set_label); if (!isFinishing()) { // Dialog Builder builder = new Builder(MainActivity.this); // Set add_torrent.xml to AlertDialog builder builder.setView(view); // Cancel builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog } }); // Ok builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User accepted the dialog String labelEncoded = Uri.encode(label.getText().toString()); setLabel(hash, labelEncoded); } }); // Create dialog AlertDialog dialog = builder.create(); // Show dialog dialog.show(); } }
From source file:com.android.calendar.EventInfoFragment.java
/** * Taken from com.google.android.gm.HtmlConversationActivity * * Send the intent that shows the Contact info corresponding to the email address. *//*from ww w . j av a 2 s. c om*/ public void showContactInfo(Attendee attendee, Rect rect) { // First perform lookup query to find existing contact final ContentResolver resolver = getActivity().getContentResolver(); final String address = attendee.mEmail; final Uri dataUri = Uri.withAppendedPath(CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(address)); final Uri lookupUri = ContactsContract.Data.getContactLookupUri(resolver, dataUri); if (lookupUri != null) { // Found matching contact, trigger QuickContact QuickContact.showQuickContact(getActivity(), rect, lookupUri, QuickContact.MODE_MEDIUM, null); } else { // No matching contact, ask user to create one final Uri mailUri = Uri.fromParts("mailto", address, null); final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, mailUri); // Pass along full E-mail string for possible create dialog Rfc822Token sender = new Rfc822Token(attendee.mName, attendee.mEmail, null); intent.putExtra(Intents.EXTRA_CREATE_DESCRIPTION, sender.toString()); // Only provide personal name hint if we have one final String senderPersonal = attendee.mName; if (!TextUtils.isEmpty(senderPersonal)) { intent.putExtra(Intents.Insert.NAME, senderPersonal); } startActivity(intent); } }
From source file:com.tandong.sa.sherlock.widget.SearchView.java
/** * When a particular suggestion has been selected, perform the various * lookups required to use the suggestion. This includes checking the cursor * for suggestion-specific data, and/or falling back to the XML for * defaults; It also creates REST style Uri data when the suggestion * includes a data id./*w ww.ja va 2 s. c om*/ * * @param c * The suggestions cursor, moved to the row of the user's * selection * @param actionKey * The key code of the action key that was pressed, or * {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg * The message for the action key that was pressed, or * <code>null</code> if none. * @return An intent for the suggestion at the cursor's position. */ private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) { try { // use specific action if supplied, or default action if supplied, // or fixed default String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION); if (action == null) { action = mSearchable.getSuggestIntentAction(); } if (action == null) { action = Intent.ACTION_SEARCH; } // use specific data if supplied, or default data if supplied String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA); if (data == null) { data = mSearchable.getSuggestIntentData(); } // then, if an ID was provided, append it. if (data != null) { String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID); if (id != null) { data = data + "/" + Uri.encode(id); } } Uri dataUri = (data == null) ? null : Uri.parse(data); String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY); String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA); return createIntent(action, dataUri, extraData, query, actionKey, actionMsg); } catch (RuntimeException e) { int rowNum; try { // be really paranoid now rowNum = c.getPosition(); } catch (RuntimeException e2) { rowNum = -1; } Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e); return null; } }
From source file:com.android.bluetooth.map.BluetoothMapContent.java
private void setVCardFromPhoneNumber(BluetoothMapbMessage message, String phone, boolean incoming) { if (TextUtils.isEmpty(phone)) { return;/*from w w w. ja v a2 s.com*/ } String contactId = null, contactName = null; String[] phoneNumbers = null; String[] emailAddresses = null; Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)); String[] projection = { Contacts._ID, Contacts.DISPLAY_NAME }; String selection = Contacts.IN_VISIBLE_GROUP + "=1"; String orderBy = Contacts._ID + " ASC"; // Get the contact _ID and name Cursor p = mResolver.query(uri, projection, selection, null, orderBy); try { if (p != null && p.getCount() >= 1) { p.moveToFirst(); contactId = p.getString(p.getColumnIndex(Contacts._ID)); contactName = p.getString(p.getColumnIndex(Contacts.DISPLAY_NAME)); } // Bail out if we are unable to find a contact, based on the phone number if (contactId == null) { phoneNumbers = new String[1]; phoneNumbers[0] = phone; } else { // use only actual phone number phoneNumbers = new String[1]; phoneNumbers[0] = phone; // Fetch contact e-mail addresses close(p); p = mResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { contactId }, null); if (p != null) { int i = 0; emailAddresses = new String[p.getCount()]; while (p != null && p.moveToNext()) { String emailAddress = p .getString(p.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS)); emailAddresses[i++] = emailAddress; } } } } finally { close(p); } if (incoming == true) message.addOriginator(contactName, contactName, phoneNumbers, emailAddresses); // Use version 3.0 as we only have a formatted name else message.addRecipient(contactName, contactName, phoneNumbers, emailAddresses); // Use version 3.0 as we only have a formatted name }