List of usage examples for android.text TextUtils join
public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens)
From source file:holidayiq.com.geofenced.geofence.GeofenceTransitionsIntentService.java
private static String Underscored(String stringExtra) { stringExtra = TextUtils.join("_", stringExtra.split(" ")); return stringExtra; }
From source file:net.kjmaster.cookiemom.settings.SettingsFragment.java
@AfterViews void afterViews() { if (TextUtils.split(iSettings.CookieList().get(), ",").length != getResources() .getStringArray(R.array.cookie_names_array).length) { fillCookieList(TextUtils.join(",", getResources().getStringArray(R.array.cookie_names_array))); iSettings.CookieList()/*from w w w. j a v a 2 s.c o m*/ .put(TextUtils.join(",", getResources().getStringArray(R.array.cookie_names_array))); } else { fillCookieList(iSettings.CookieList().get()); } setChecks(); createHooks(); setting_cookie_list.setEnabled(iSettings.useCustomCookies().get()); settings_edit_cookie.setEnabled(iSettings.useCustomCookies().get()); setting_save_cookie.setEnabled(iSettings.useCustomCookies().get()); }
From source file:net.openid.appauth.internal.UriUtil.java
public static String formUrlEncode(Map<String, String> parameters) { if (parameters == null) { return ""; }/*from ww w . jav a 2 s .c om*/ List<String> queryParts = new ArrayList<>(); for (Map.Entry<String, String> param : parameters.entrySet()) { try { queryParts.add(param.getKey() + "=" + URLEncoder.encode(param.getValue(), "utf-8")); } catch (UnsupportedEncodingException e) { // Should not end up here Logger.error("Could not utf-8 encode."); } } return TextUtils.join("&", queryParts); }
From source file:com.yolanda.nohttp.HttpHeaders.java
@Override public void addCookie(URI uri, CookieHandler cookieHandler) { try {// ww w .j av a 2 s . c om Map<String, List<String>> diskCookies = cookieHandler.get(uri, new HashMap<String, List<String>>()); for (Map.Entry<String, List<String>> entry : diskCookies.entrySet()) { String key = entry.getKey(); List<String> value = entry.getValue(); if ((HEAD_KEY_COOKIE.equalsIgnoreCase(key) || HEAD_KEY_COOKIE2.equalsIgnoreCase(key))) { add(key, TextUtils.join("; ", value)); } } } catch (IOException e) { Logger.e(e); } }
From source file:info.aamulumi.sharedshopping.network.RequestSender.java
/** * Send HTTP Request with params (x-url-encoded) * * @param requestURL - URL of the request * @param method - HTTP method (GET, POST, PUT, DELETE, ...) * @param urlParameters - parameters send in URL * @param bodyParameters - parameters send in body (encoded) * @return JSONObject returned by the server *//*from w ww. j a va 2 s . c om*/ public JSONObject makeHttpRequest(String requestURL, String method, HashMap<String, String> urlParameters, HashMap<String, String> bodyParameters) { HttpURLConnection connection = null; URL url; JSONObject jObj = null; try { // Check if we must add parameters in URL if (urlParameters != null) { String stringUrlParams = getFormattedParameters(urlParameters); url = new URL(requestURL + "?" + stringUrlParams); } else url = new URL(requestURL); // Create connection connection = (HttpURLConnection) url.openConnection(); // Add cookies to request if (mCookieManager.getCookieStore().getCookies().size() > 0) connection.setRequestProperty("Cookie", TextUtils.join(";", mCookieManager.getCookieStore().getCookies())); // Set request parameters connection.setReadTimeout(5000); connection.setConnectTimeout(5000); connection.setRequestMethod(method); connection.setDoInput(true); // Check if we must add parameters in body if (bodyParameters != null) { // Create a string with parameters String stringBodyParameters = getFormattedParameters(bodyParameters); // Set output request parameters connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", "" + Integer.toString(stringBodyParameters.getBytes().length)); connection.setRequestProperty("Content-Language", "fr-FR"); // Send body's request OutputStream os = connection.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(stringBodyParameters); writer.flush(); writer.close(); os.close(); } // Get response code int responseCode = connection.getResponseCode(); // If response is 200 (OK) if (responseCode == HttpsURLConnection.HTTP_OK) { // Keep new cookies in the manager List<String> cookiesHeader = connection.getHeaderFields().get(COOKIES_HEADER); if (cookiesHeader != null) { for (String cookie : cookiesHeader) mCookieManager.getCookieStore().add(null, HttpCookie.parse(cookie).get(0)); } // Read the response String line; BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } // Parse the response to a JSON Object try { jObj = new JSONObject(sb.toString()); } catch (JSONException e) { Log.d("JSON Parser", "Error parsing data " + e.toString()); Log.d("JSON Parser", "Setting value of jObj to null"); jObj = null; } } else { Log.w("HttpUrlConnection", "Error : server sent code : " + responseCode); } } catch (MalformedURLException e) { Log.e("Network", "Error in URL"); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { // Close connection if (connection != null) connection.disconnect(); } return jObj; }
From source file:org.piwik.sdk.dispatcher.PacketFactory.java
@Nullable private Packet buildPacketForPost(List<Event> events) { if (events.isEmpty()) return null; try {//from w w w .j a va 2s .c o m JSONObject params = new JSONObject(); JSONArray jsonArray = new JSONArray(); for (Event event : events) jsonArray.put(event.getEncodedQuery()); params.put("requests", jsonArray); return new Packet(mApiUrl, params, events.size()); } catch (JSONException e) { Timber.tag(LOGGER_TAG).w(e, "Cannot create json object:\n%s", TextUtils.join(", ", events)); } return null; }
From source file:com.example.administrator.datarequest.ningworld.HttpHeaders.java
@Override public void addCookie(URI uri, CookieHandler cookieHandler) { try {//from ww w . jav a 2 s . co m Map<String, List<String>> diskCookies = cookieHandler.get(uri, new HashMap<String, List<String>>()); for (Map.Entry<String, List<String>> entry : diskCookies.entrySet()) { String key = entry.getKey(); List<String> value = entry.getValue(); if ((Headers.HEAD_KEY_COOKIE.equalsIgnoreCase(key) || Headers.HEAD_KEY_COOKIE2.equalsIgnoreCase(key))) { add(key, TextUtils.join("; ", value)); } } } catch (IOException e) { Logger.e(e); } }
From source file:com.hp.saas.agm.core.entity.EntityQuery.java
public synchronized boolean setOrValues(String prop, List<String> values) { return setValue(prop, TextUtils.join(" OR ", values.toArray(new String[values.size()]))); }
From source file:org.piwik.sdk.TrackerBulkURLWrapper.java
/** * {/*from ww w. j a v a 2 s. co m*/ * "requests": ["?idsite=1&url=http://example.org&action_name=Test bulk log Pageview&rec=1", * "?idsite=1&url=http://example.net/test.htm&action_name=Another bul k page view&rec=1"], * "token_auth": "33dc3f2536d3025974cccb4b4d2d98f4" * } * * @return json object */ public JSONObject getEvents(Page page) { if (page == null || page.isEmpty()) { return null; } List<String> pageElements = events.subList(page.fromIndex, page.toIndex); if (pageElements.size() == 0) { Log.w(Tracker.LOGGER_TAG, "Empty page"); return null; } JSONObject params = new JSONObject(); try { params.put("requests", new JSONArray(pageElements)); if (authToken != null) { params.put(Tracker.QueryParams.AUTHENTICATION_TOKEN.toString(), authToken); } } catch (JSONException e) { Log.w(Tracker.LOGGER_TAG, "Cannot create json object", e); Log.i(Tracker.LOGGER_TAG, TextUtils.join(", ", pageElements)); return null; } return params; }
From source file:com.anysoftkeyboard.quicktextkeys.QuickTextKeyFactory.java
public static void storeOrderedEnabledQuickKeys(Context applicationContext, List<QuickTextKey> orderedKeys) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext); String settingKey = applicationContext.getString(R.string.settings_key_ordered_active_quick_text_keys); Set<String> storedKeys = new HashSet<>(); List<String> quickKeyIdOrder = new ArrayList<>(orderedKeys.size()); for (QuickTextKey key : orderedKeys) { final String id = key.getId(); if (!storedKeys.contains(id)) quickKeyIdOrder.add(id);//from w ww. j a va 2 s . com storedKeys.add(id); } SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(settingKey, TextUtils.join(",", quickKeyIdOrder)); SharedPreferencesCompat.EditorCompat.getInstance().apply(editor); }