List of usage examples for android.text TextUtils join
public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens)
From source file:gr.ellak.ma.emergencyroad.PersistentCookieStore.java
@Override public boolean clearExpired(Date date) { boolean clearedAny = false; SharedPreferences.Editor prefsWriter = cookiePrefs.edit(); for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) { String name = entry.getKey(); Cookie cookie = entry.getValue(); if (cookie.isExpired(date)) { //&& !cookie.getName().contains("sid_customer")) { // Clear cookies from local store cookies.remove(name);/*from w ww . j av a 2 s. c o m*/ // Clear cookies from persistent store prefsWriter.remove(COOKIE_NAME_PREFIX + name); // We've cleared at least one clearedAny = true; } } // Update names in persistent store if (clearedAny) { prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet())); } prefsWriter.apply(); return clearedAny; }
From source file:com.balch.mocktrade.finance.FinanceYQLModel.java
@Override public void getQuotes(final List<String> symbols, final RequestListener<Map<String, Quote>> listener) { final CountDownLatch latch = new CountDownLatch(2); final Map<String, Quote> yqlQuotes = new HashMap<String, Quote>(); final Map<String, Quote> googleQuotes = new HashMap<String, Quote>(); final StringBuilder errorMessages = new StringBuilder(); this.getYQLQuotes(symbols, new RequestListener<Map<String, Quote>>() { @Override//from w w w . j av a2s. c o m public void onResponse(Map<String, Quote> response) { try { yqlQuotes.putAll(response); } finally { latch.countDown(); } } @Override public void onErrorResponse(String error) { errorMessages.append(error).append("\n"); latch.countDown(); } }); this.getGoogleRealTimeQuotes(symbols, new RequestListener<Map<String, Quote>>() { @Override public void onResponse(Map<String, Quote> response) { try { googleQuotes.putAll(response); } finally { latch.countDown(); } } @Override public void onErrorResponse(String error) { errorMessages.append(error).append("\n"); latch.countDown(); } }); try { // wait for both requests to finish latch.await(); if (errorMessages.length() == 0) { // add google's realtime quotes on top of yql quotes for (Quote q : googleQuotes.values()) { Quote yqlQuote = yqlQuotes.get(q.getSymbol()); if (yqlQuote != null) { yqlQuote.setPrice(q.getPrice()); yqlQuote.setLastTradeTime(q.getLastTradeTime()); } else { Log.wtf(TAG, "GoogleQuote contains a symbol that is not in the yqlQuote map. GoogleQuote Symbol:" + q.getSymbol() + " Submitted Symbols:" + TextUtils.join(",", symbols)); } } listener.onResponse(yqlQuotes); } else { listener.onErrorResponse(errorMessages.toString()); } } catch (InterruptedException e) { } }
From source file:com.codestation.henkakuserver.HenkakuServer.java
/** * Convert the loader code to shellcode embedded in js * * @param loader loader compiled code/*from w w w . j a v a 2 s .co m*/ * @return the shellcode embedded in js * @throws Exception */ private String preprocessToJs(byte[] loader) throws Exception { Pair<ArrayList<Integer>, List<Byte>> data = preprocessRop(loader); List<Long> longList = new ArrayList<>(); for (Integer i : data.first) { longList.add(i & 0xFFFFFFFFL); } String payload = TextUtils.join(",", longList); String relocations = TextUtils.join(",", data.second); return String.format("\npayload = [%1$s];\nrelocs = [%2$s];\n", payload, relocations); }
From source file:com.yanzhenjie.nohttp.HttpHeaders.java
@Override public String getCacheControl() { // first http1.1, second http1.0 List<String> cacheControls = getValues(HEAD_KEY_CACHE_CONTROL); if (cacheControls == null) cacheControls = getValues(HEAD_KEY_PRAGMA); if (cacheControls == null) cacheControls = new ArrayList<>(); return TextUtils.join(",", cacheControls); }
From source file:tw.idv.palatis.danboorugallery.siteapi.MoebooruAPI.java
@Override public List<Post> fetchPosts(Host host, int startFrom, String[] tags) throws SiteAPIException { HttpURLConnection connection = null; try {//w w w.j ava2s.co m int limit = host.getPageLimit(DanbooruGallerySettings.getBandwidthUsageType()); int page = startFrom / limit + 1; String url = String.format(URL_POSTS_FORMAT, host.url, page, URLEncoder.encode(TextUtils.join(" ", tags), "UTF-8"), limit); Log.v(TAG, String.format("URL: %s", url)); connection = SiteAPI.openConnection(new URL(url)); if (!host.getLogin().isEmpty()) connection.setRequestProperty("Authorization", "Basic " + host.getSecret()); Reader input = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); Writer output = new StringWriter(); char buffer[] = new char[_BUFFER_SIZE]; for (int count = input.read(buffer); count > 0; count = input.read(buffer)) output.write(buffer, 0, count); JSONArray json_posts = new JSONArray(output.toString()); int len = json_posts.length(); List<Post> posts = new ArrayList<>(len); for (int j = 0; j < len; ++j) { try { posts.add(parseJSONObjectToPost(host, json_posts.getJSONObject(j))); } catch (JSONException | ParseException ex) { throw new SiteAPIException(this, connection, ex); } } return posts; } catch (IOException | JSONException ex) { throw new SiteAPIException(this, connection, ex); } finally { if (connection != null) connection.disconnect(); } }
From source file:com.example.administrator.datarequest.ningworld.HttpHeaders.java
@Override public String getCacheControl() { // first http1.1, second http1.0 List<String> cacheControls = getValues(HEAD_KEY_CACHE_CONTROL); if (cacheControls == null) cacheControls = getValues(HEAD_KEY_PRAGMA); if (cacheControls == null) cacheControls = new ArrayList<String>(); return TextUtils.join(",", cacheControls); }
From source file:de.incoherent.suseconferenceclient.app.ConferenceCacher.java
public long cacheConference(Conference conference, Database db) { //String url = conference.getUrl(); String url = "https://conference.opensuse.org/osem/api/v1/conferences/gRNyOIsTbvCfJY5ENYovBA"; String eventsUrl = url + "/events.json"; String roomsUrl = url + "/rooms.json"; String speakersUrl = url + "/speakers.json"; String tracksUrl = url + "/tracks.json"; String venueUrl = url + "/venue.json"; Long returnVal = null;//from w w w .j a va 2 s . c o m HashMap<String, Long> roomMap = new HashMap<String, Long>(); HashMap<String, Long> trackMap = new HashMap<String, Long>(); HashMap<String, Long> speakerMap = new HashMap<String, Long>(); try { Log.d("SUSEConferences", "Venues: " + venueUrl); publishProgress("venues"); JSONObject venueReply = HTTPWrapper.get(venueUrl); JSONObject venue = venueReply.getJSONObject("venue"); String infoUrl = url + "/" + venue.getString("info_text"); Log.d("Application Url", "INFO URL: " + infoUrl); String info = HTTPWrapper.getRawText(infoUrl); String venueName = venue.getString("name"); String venueAddr = venue.getString("address"); String offlineMap = ""; String offlineMapBounds = ""; if (venue.has("offline_map")) { offlineMap = venue.getString("offline_map"); offlineMapBounds = venue.getString("offline_map_bounds"); } long venueId = db.insertVenue(venue.getString("guid"), venueName, venueAddr, offlineMap, offlineMapBounds, info); JSONArray mapPoints = venue.getJSONArray("map_points"); int mapLen = mapPoints.length(); for (int i = 0; i < mapLen; i++) { JSONObject point = mapPoints.getJSONObject(i); String lat = point.getString("lat"); String lon = point.getString("lon"); String type = point.getString("type"); String name = "Unknown Point"; String addr = "Unknown Address"; String desc = ""; if (point.has("name")) { name = point.getString("name"); } if (point.has("address")) { addr = point.getString("address"); } if (point.has("description")) { desc = point.getString("description"); } db.insertVenuePoint(venueId, lat, lon, type, name, addr, desc); } if (venue.has("map_polygons")) { JSONArray polygons = venue.getJSONArray("map_polygons"); int polygonLen = polygons.length(); for (int j = 0; j < polygonLen; j++) { JSONObject polygon = polygons.getJSONObject(j); String name = polygon.getString("name"); String label = polygon.getString("label"); String lineColorStr = polygon.getString("line_color"); String fillColorStr = "#00000000"; if (polygon.has("fill_color")) fillColorStr = polygon.getString("fill_color"); List<String> stringList = new ArrayList<String>(); JSONArray points = polygon.getJSONArray("points"); int pointsLen = points.length(); for (int k = 0; k < pointsLen; k++) { String newPoint = points.getString(k); stringList.add(newPoint); } String joined = TextUtils.join(";", stringList); int lineColor = Color.parseColor(lineColorStr); int fillColor = Color.parseColor(fillColorStr); db.insertVenuePolygon(venueId, name, label, lineColor, fillColor, joined); } } db.setConferenceVenue(venueId, conference.getSqlId()); Log.d("SUSEConferences", "Rooms"); publishProgress("rooms"); JSONObject roomsReply = HTTPWrapper.get(roomsUrl); Log.d("Rooms of the event", "ROOMS URL: " + roomsUrl); JSONArray rooms = roomsReply.getJSONArray("rooms"); int roomsLen = rooms.length(); for (int i = 0; i < roomsLen; i++) { JSONObject room = rooms.getJSONObject(i); String guid = room.getString("guid"); Long roomId = db.insertRoom(guid, room.getString("name"), room.getString("description"), venueId); roomMap.put(guid, roomId); } Log.d("SUSEConferences", "Tracks"); publishProgress("tracks"); JSONObject tracksReply = HTTPWrapper.get(tracksUrl); Log.d("Event tracks", "Tracks: " + tracksUrl); JSONArray tracks = tracksReply.getJSONArray("tracks"); int tracksLen = tracks.length(); for (int i = 0; i < tracksLen; i++) { JSONObject track = tracks.getJSONObject(i); String guid = track.getString("guid"); Long trackId = db.insertTrack(guid, track.getString("name"), track.getString("color"), conference.getSqlId()); trackMap.put(guid, trackId); } Log.d("SUSEConferences", "Speakers"); publishProgress("speakers"); JSONObject speakersReply = HTTPWrapper.get(speakersUrl); JSONArray speakers = speakersReply.getJSONArray("speakers"); int speakersLen = speakers.length(); for (int i = 0; i < speakersLen; i++) { JSONObject speaker = speakers.getJSONObject(i); String guid = speaker.getString("guid"); Long speakerId = db.insertSpeaker(guid, speaker.getString("name"), speaker.getString("company"), speaker.getString("biography"), ""); speakerMap.put(guid, speakerId); } Log.d("SUSEConferences", "Events"); publishProgress("events"); JSONObject eventsReply = HTTPWrapper.get(eventsUrl); JSONArray events = eventsReply.getJSONArray("events"); int eventsLen = events.length(); for (int i = 0; i < eventsLen; i++) { JSONObject event = events.getJSONObject(i); String guid = event.getString("guid"); String track = event.getString("track"); Long trackId = trackMap.get(track); Long roomId = roomMap.get(event.getString("room")); if (track.equals("meta")) { // The "meta" track is used to insert information // into the schedule that automatically appears on "my schedule", // and also isn't clickable. db.insertEvent(guid, conference.getSqlId(), roomId.longValue(), trackId.longValue(), event.getString("date"), event.getInt("length"), "", "", event.getString("title"), "", ""); } else { Long eventId = db.insertEvent(guid, conference.getSqlId(), roomId.longValue(), trackId.longValue(), event.getString("date"), event.getInt("length"), event.getString("type"), event.getString("language"), event.getString("title"), event.getString("abstract"), ""); JSONArray eventSpeakers = event.getJSONArray("speaker_ids"); int eventSpeakersLen = eventSpeakers.length(); for (int j = 0; j < eventSpeakersLen; j++) { Long speakerId = speakerMap.get(eventSpeakers.getString(j)); if (speakerId != null) db.insertEventSpeaker(speakerId, eventId); } } } } catch (IllegalStateException e) { e.printStackTrace(); mErrorMessage = e.getLocalizedMessage(); returnVal = Long.valueOf(-1); } catch (SocketException e) { e.printStackTrace(); mErrorMessage = e.getLocalizedMessage(); returnVal = Long.valueOf(-1); } catch (UnsupportedEncodingException e) { e.printStackTrace(); mErrorMessage = e.getLocalizedMessage(); returnVal = Long.valueOf(-1); } catch (IOException e) { e.printStackTrace(); mErrorMessage = e.getLocalizedMessage(); returnVal = Long.valueOf(-1); } catch (JSONException e) { e.printStackTrace(); mErrorMessage = e.getLocalizedMessage(); returnVal = Long.valueOf(-1); } if (returnVal == null) returnVal = conference.getSqlId(); return returnVal; }
From source file:org.geometerplus.android.fbreader.network.ActivityNetworkContext.java
private boolean registerAccessToken(String clientId, String authUrl, String authToken) { String code = null;/*from w w w . ja v a 2s . c o m*/ try { code = GoogleAuthUtil.getToken(myActivity, myAccount, String.format("oauth2:server:client_id:%s:api_scope:%s", clientId, TextUtils.join(" ", new Object[] { Scopes.DRIVE_FILE, Scopes.PROFILE })), null); System.err.println("ACCESS TOKEN = " + code); final String result = runTokenAuthorization(authUrl, authToken, code); System.err.println("AUTHENTICATION RESULT 2 = " + result); return true; } catch (UserRecoverableAuthException e) { myAuthorizationConfirmed = false; startActivityAndWait(e.getIntent(), NetworkLibraryActivity.REQUEST_AUTHORISATION); return myAuthorizationConfirmed && registerAccessToken(clientId, authUrl, authToken); } catch (Exception e) { return false; } }
From source file:group5.trackerexpress.BasicMapActivity.java
protected void makeLatLngMarker(LatLng latLng, String locName, Integer zoom) { String snippet = ""; if (locName == null) { locName = ""; }//from w ww .ja va 2 s . c o m // https://developer.android.com/training/location/display-address.html 03/04/2015 List<Address> addresses = null; try { addresses = mGeocoder.getFromLocation(latLng.latitude, latLng.longitude, 1); } catch (IOException ioException) { // Catch network or other I/O problems. System.err.println("Geocoder IO EXCEPTION"); } catch (IllegalArgumentException illegalArgumentException) { // Catch invalid latitude or longitude values. System.err.println("Geocoder IllegalArgument at " + latLng.toString()); } if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); ArrayList<String> addressFragments = new ArrayList<String>(); // Fetch the address lines using getAddressLine, // join them, and send them to the thread. if (address.getMaxAddressLineIndex() > 0) { if (locName.isEmpty()) { System.out.println("Location name is empty"); locName = address.getAddressLine(0); } for (int i = 1; i <= address.getMaxAddressLineIndex(); i++) { addressFragments.add(address.getAddressLine(i)); } } snippet = TextUtils.join(" ", addressFragments); } if (!snippet.isEmpty()) { snippet += System.getProperty("line.separator"); } snippet += latLngFormat(latLng); makeMarker(latLng, locName, snippet); System.out.println("MAKING MARKER"); goToMarker(lastMarker, zoom); }
From source file:com.ab.http.PersistentCookieStore.java
/** * ??TODO/* ww w .j a va 2s . c o m*/ * @see org.apache.http.client.CookieStore#clearExpired(java.util.Date) * @author: zhaoqp * @date2013-10-22 ?4:23:15 * @version v1.0 */ @Override public boolean clearExpired(Date date) { boolean clearedAny = false; SharedPreferences.Editor prefsWriter = cookiePrefs.edit(); for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) { String name = entry.getKey(); Cookie cookie = entry.getValue(); if (cookie.isExpired(date)) { // Clear cookies from local store cookies.remove(name); // Clear cookies from persistent store prefsWriter.remove(COOKIE_NAME_PREFIX + name); // We've cleared at least one clearedAny = true; } } // Update names in persistent store if (clearedAny) { prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet())); } prefsWriter.commit(); return clearedAny; }