List of usage examples for android.text TextUtils join
public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens)
From source file:com.google.ytdl.MainActivity.java
private void loadUploadedVideos() { if (mToken == null) { return;/*from w w w . ja va2s. c o m*/ } setProgressBarIndeterminateVisibility(true); new AsyncTask<Void, Void, List<VideoData>>() { @Override protected List<VideoData> doInBackground(Void... voids) { GoogleCredential credential = new GoogleCredential(); credential.setAccessToken(mToken); HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); YouTube yt = new YouTube.Builder(httpTransport, jsonFactory, credential) .setApplicationName(Constants.APP_NAME).build(); try { ChannelListResponse clr = yt.channels().list("contentDetails").setMine(true).execute(); String uploadsPlaylistId = clr.getItems().get(0).getContentDetails().getRelatedPlaylists() .getUploads(); List<VideoData> videos = new ArrayList<VideoData>(); PlaylistItemListResponse pilr = yt.playlistItems().list("id,contentDetails") .setPlaylistId(uploadsPlaylistId).setMaxResults(20l).execute(); List<String> videoIds = new ArrayList<String>(); for (PlaylistItem item : pilr.getItems()) { videoIds.add(item.getContentDetails().getVideoId()); } VideoListResponse vlr = yt.videos().list(TextUtils.join(",", videoIds), "id,snippet,status") .execute(); for (Video video : vlr.getItems()) { if ("public".equals(video.getStatus().getPrivacyStatus())) { VideoData videoData = new VideoData(); videoData.setVideo(video); videos.add(videoData); } } Collections.sort(videos, new Comparator<VideoData>() { @Override public int compare(VideoData videoData, VideoData videoData2) { return videoData.getTitle().compareTo(videoData2.getTitle()); } }); mCurrentBackoff = 0; return videos; } catch (final GoogleJsonResponseException e) { if (401 == e.getDetails().getCode()) { Log.e(this.getClass().getSimpleName(), e.getMessage()); GoogleAuthUtil.invalidateToken(MainActivity.this, mToken); mHandler.postDelayed(new Runnable() { @Override public void run() { tryAuthenticate(); } }, mCurrentBackoff * 1000); mCurrentBackoff *= 2; if (mCurrentBackoff == 0) { mCurrentBackoff = 1; } } } catch (final IOException e) { Log.e(this.getClass().getSimpleName(), e.getMessage()); } return null; } @Override protected void onPostExecute(List<VideoData> videos) { setProgressBarIndeterminateVisibility(false); if (videos == null) { return; } mUploadsListFragment.setVideos(videos); } }.execute((Void) null); }
From source file:com.markupartist.sthlmtraveling.ViewOnMapActivity.java
/** * Update the action bar with start and end points. * @param journeyQuery the journey query *//*from w ww .j a v a2s. co m*/ protected void updateStartAndEndPointViews(final JourneyQuery journeyQuery) { ActionBar ab = getSupportActionBar(); if (journeyQuery.origin.isMyLocation()) { ab.setTitle(StringUtils.getStyledMyLocationString(this)); } else { ab.setTitle(journeyQuery.origin.getName()); } CharSequence via = null; if (journeyQuery.hasVia()) { via = journeyQuery.via.getName(); } if (journeyQuery.destination.isMyLocation()) { if (via != null) { ab.setSubtitle(TextUtils.join(" ", new CharSequence[] { via, StringUtils.getStyledMyLocationString(this) })); } else { ab.setSubtitle(StringUtils.getStyledMyLocationString(this)); } } else { if (via != null) { ab.setSubtitle( TextUtils.join(" ", new CharSequence[] { via, journeyQuery.destination.getName() })); } else { ab.setSubtitle(journeyQuery.destination.getName()); } } }
From source file:com.ichi2.libanki.Card.java
public String toString() { List<String> members = new ArrayList<String>(); for (Field f : this.getClass().getDeclaredFields()) { try {//from w w w . ja va 2 s.c o m // skip non-useful elements if (SKIP_PRINT.contains(f.getName())) { continue; } members.add(String.format("'%s': %s", f.getName(), f.get(this))); } catch (IllegalAccessException e) { members.add(String.format("'%s': %s", f.getName(), "N/A")); } catch (IllegalArgumentException e) { members.add(String.format("'%s': %s", f.getName(), "N/A")); } } return TextUtils.join(", ", members); }
From source file:com.hichinaschool.flashcards.libanki.Sched.java
/** * Returns [deckname, did, rev, lrn, new] *//*from www .j a v a 2s.co m*/ public ArrayList<Object[]> deckDueList() { _checkDay(); mCol.getDecks().recoverOrphans(); ArrayList<JSONObject> decks = mCol.getDecks().all(); Collections.sort(decks, new DeckDueListComparator()); HashMap<String, Integer[]> lims = new HashMap<String, Integer[]>(); ArrayList<Object[]> data = new ArrayList<Object[]>(); try { for (JSONObject deck : decks) { // if we've already seen the exact same deck name, remove the // invalid duplicate and reload if (lims.containsKey(deck.getString("name"))) { mCol.getDecks().rem(deck.getLong("id"), false, true); return deckDueList(); } String p; List<String> parts = Arrays.asList(deck.getString("name").split("::")); if (parts.size() < 2) { p = null; } else { parts = parts.subList(0, parts.size() - 1); p = TextUtils.join("::", parts); } // new int nlim = _deckNewLimitSingle(deck); if (!TextUtils.isEmpty(p)) { if (!lims.containsKey(p)) { // if parent was missing, this deck is invalid, and we need to reload the deck list mCol.getDecks().rem(deck.getLong("id"), false, true); return deckDueList(); } nlim = Math.min(nlim, lims.get(p)[0]); } int newC = _newForDeck(deck.getLong("id"), nlim); // learning int lrn = _lrnForDeck(deck.getLong("id")); // reviews int rlim = _deckRevLimitSingle(deck); if (!TextUtils.isEmpty(p)) { rlim = Math.min(rlim, lims.get(p)[1]); } int rev = _revForDeck(deck.getLong("id"), rlim); // save to list // LIBANKI: order differs from libanki (here: new, lrn, rev) // TODO: why? data.add(new Object[] { deck.getString("name"), deck.getLong("id"), newC, lrn, rev }); // add deck as a parent lims.put(deck.getString("name"), new Integer[] { nlim, rlim }); } } catch (JSONException e) { throw new RuntimeException(e); } return data; }
From source file:com.android.contacts.group.GroupMembersFragment.java
private void sendToGroup(long[] ids, String sendScheme, String title) { if (ids == null || ids.length == 0) return;//from w w w . j a va 2 s.com // Get emails or phone numbers // contactMap <contact_id, contact_data> final Map<String, ContactDataHelperClass> contactMap = new HashMap<>(); // itemList <item_data> final List<String> itemList = new ArrayList<>(); final String sIds = GroupUtil.convertArrayToString(ids); final String select = (ContactsUtils.SCHEME_MAILTO.equals(sendScheme) ? Query.EMAIL_SELECTION : Query.PHONE_SELECTION) + " AND " + ContactsContract.Data.CONTACT_ID + " IN (" + sIds + ")"; final ContentResolver contentResolver = getContext().getContentResolver(); final Cursor cursor = contentResolver.query(ContactsContract.Data.CONTENT_URI, ContactsUtils.SCHEME_MAILTO.equals(sendScheme) ? Query.EMAIL_PROJECTION : Query.PHONE_PROJECTION, select, null, null); if (cursor == null) { return; } try { cursor.moveToPosition(-1); while (cursor.moveToNext()) { final String contactId = cursor.getString(Query.CONTACT_ID); final String itemId = cursor.getString(Query.ITEM_ID); final boolean isPrimary = cursor.getInt(Query.PRIMARY) != 0; final int timesUsed = cursor.getInt(Query.TIMES_USED); final String data = cursor.getString(Query.DATA1); if (!TextUtils.isEmpty(data)) { final ContactDataHelperClass contact; if (!contactMap.containsKey(contactId)) { contact = new ContactDataHelperClass(); contactMap.put(contactId, contact); } else { contact = contactMap.get(contactId); } contact.addItem(itemId, timesUsed, isPrimary); itemList.add(data); } } } finally { cursor.close(); } // Start picker if a contact does not have a default for (ContactDataHelperClass i : contactMap.values()) { if (!i.hasDefaultItem()) { // Build list of default selected item ids final List<Long> defaultSelection = new ArrayList<>(); for (ContactDataHelperClass j : contactMap.values()) { final String selectionItemId = j.getDefaultSelectionItemId(); if (selectionItemId != null) { defaultSelection.add(Long.parseLong(selectionItemId)); } } final long[] defaultSelectionArray = Longs.toArray(defaultSelection); startSendToSelectionPickerActivity(ids, defaultSelectionArray, sendScheme, title); return; } } if (itemList.size() == 0 || contactMap.size() < ids.length) { Toast.makeText(getContext(), ContactsUtils.SCHEME_MAILTO.equals(sendScheme) ? getString(R.string.groupSomeContactsNoEmailsToast) : getString(R.string.groupSomeContactsNoPhonesToast), Toast.LENGTH_LONG).show(); } if (itemList.size() == 0) { return; } final String itemsString = TextUtils.join(",", itemList); GroupUtil.startSendToSelectionActivity(this, itemsString, sendScheme, title); }
From source file:com.deliciousdroid.platform.BookmarkManager.java
public static CursorLoader SearchBookmarks(String query, String tagname, String username, Context context) { final String[] projection = new String[] { Bookmark._ID, Bookmark.Url, Bookmark.Description, Bookmark.Meta, Bookmark.Tags, Bookmark.Shared, Bookmark.Synced, Bookmark.Deleted }; String selection = null;/*from www.j a v a 2s. com*/ final String sortorder = Bookmark.Description + " ASC"; final String[] queryBookmarks = query.split(" "); final ArrayList<String> queryList = new ArrayList<String>(); final ArrayList<String> selectionlist = new ArrayList<String>(); if (query != null && query != "" && (tagname == null || tagname == "")) { for (String s : queryBookmarks) { queryList.add("(" + Bookmark.Tags + " LIKE ? OR " + Bookmark.Description + " LIKE ? OR " + Bookmark.Notes + " LIKE ?)"); selectionlist.add("%" + s + "%"); selectionlist.add("%" + s + "%"); selectionlist.add("%" + s + "%"); } selectionlist.add(username); selection = TextUtils.join(" AND ", queryList) + " AND " + Bookmark.Account + "=?"; } else if (query != null && query != "") { for (String s : queryBookmarks) { queryList.add("(" + Bookmark.Description + " LIKE ? OR " + Bookmark.Notes + " LIKE ?)"); selectionlist.add("%" + s + "%"); selectionlist.add("%" + s + "%"); } selection = TextUtils.join(" AND ", queryList) + " AND " + Bookmark.Account + "=? AND " + "(" + Bookmark.Tags + " LIKE ? OR " + Bookmark.Tags + " LIKE ? OR " + Bookmark.Tags + " LIKE ? OR " + Bookmark.Tags + " = ?)"; selectionlist.add(username); selectionlist.add("% " + tagname + " %"); selectionlist.add("% " + tagname); selectionlist.add(tagname + " %"); selectionlist.add(tagname); } else { selectionlist.add(username); selection = Bookmark.Account + "=?"; } selection += " AND " + Bookmark.Deleted + "=0"; return new CursorLoader(context, Bookmark.CONTENT_URI, projection, selection, selectionlist.toArray(new String[] {}), sortorder); }
From source file:com.sickboots.ytube.MainActivity.java
private void loadUploadedVideos() { if (mChosenAccountName == null) { return;//from ww w .java 2s .c o m } setProgressBarIndeterminateVisibility(true); new AsyncTask<Void, Void, List<VideoData>>() { @Override protected List<VideoData> doInBackground(Void... voids) { YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential) .setApplicationName(Constants.APP_NAME).build(); try { /* * Now that the user is authenticated, the app makes a * channels list request to get the authenticated user's * channel. Returned with that data is the playlist id for * the uploaded videos. * https://developers.google.com/youtube * /v3/docs/channels/list */ ChannelListResponse clr = youtube.channels().list("contentDetails").setMine(true).execute(); // Get the user's uploads playlist's id from channel list // response String uploadsPlaylistId = clr.getItems().get(0).getContentDetails().getRelatedPlaylists() .getUploads(); List<VideoData> videos = new ArrayList<VideoData>(); // Get videos from user's upload playlist with a playlist // items list request PlaylistItemListResponse pilr = youtube.playlistItems().list("id,contentDetails") .setPlaylistId(uploadsPlaylistId).setMaxResults(20l).execute(); List<String> videoIds = new ArrayList<String>(); // Iterate over playlist item list response to get uploaded // videos' ids. for (PlaylistItem item : pilr.getItems()) { videoIds.add(item.getContentDetails().getVideoId()); } // Get details of uploaded videos with a videos list // request. VideoListResponse vlr = youtube.videos().list("id,snippet,status") .setId(TextUtils.join(",", videoIds)).execute(); // Add only the public videos to the local videos list. for (Video video : vlr.getItems()) { if ("public".equals(video.getStatus().getPrivacyStatus())) { VideoData videoData = new VideoData(); videoData.setVideo(video); videos.add(videoData); } } // Sort videos by title Collections.sort(videos, new Comparator<VideoData>() { @Override public int compare(VideoData videoData, VideoData videoData2) { return videoData.getTitle().compareTo(videoData2.getTitle()); } }); return videos; } catch (final GooglePlayServicesAvailabilityIOException availabilityException) { showGooglePlayServicesAvailabilityErrorDialog(availabilityException.getConnectionStatusCode()); } catch (UserRecoverableAuthIOException userRecoverableException) { startActivityForResult(userRecoverableException.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { Utils.logAndShow(MainActivity.this, Constants.APP_NAME, e); } return null; } @Override protected void onPostExecute(List<VideoData> videos) { setProgressBarIndeterminateVisibility(false); if (videos == null) { return; } mUploadsListFragment.setVideos(videos); } }.execute((Void) null); }
From source file:org.youtube.Youtube_MainActivity.java
private void loadUploadedVideos() { if (mChosenAccountName == null) { return;/* w ww . j av a 2 s . com*/ } setProgressBarIndeterminateVisibility(true); new AsyncTask<Void, Void, List<VideoData>>() { @Override protected List<VideoData> doInBackground(Void... voids) { YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential) .setApplicationName(Youtube_Constants.APP_NAME).build(); try { /* * Now that the user is authenticated, the app makes a * channels list request to get the authenticated user's * channel. Returned with that data is the playlist id for * the uploaded videos. * https://developers.google.com/youtube * /v3/docs/channels/list */ ChannelListResponse clr = youtube.channels().list("contentDetails").setMine(true).execute(); // Get the user's uploads playlist's id from channel list // response String uploadsPlaylistId = clr.getItems().get(0).getContentDetails().getRelatedPlaylists() .getUploads(); List<VideoData> videos = new ArrayList<VideoData>(); // Get videos from user's upload playlist with a playlist // items list request PlaylistItemListResponse pilr = youtube.playlistItems().list("id,contentDetails") .setPlaylistId(uploadsPlaylistId).setMaxResults(20l).execute(); List<String> videoIds = new ArrayList<String>(); // Iterate over playlist item list response to get uploaded // videos' ids. for (PlaylistItem item : pilr.getItems()) { videoIds.add(item.getContentDetails().getVideoId()); } // Get details of uploaded videos with a videos list // request. VideoListResponse vlr = youtube.videos().list("id,snippet,status") .setId(TextUtils.join(",", videoIds)).execute(); // Add only the public videos to the local videos list. for (Video video : vlr.getItems()) { if ("public".equals(video.getStatus().getPrivacyStatus())) { VideoData videoData = new VideoData(); videoData.setVideo(video); videos.add(videoData); } } // Sort videos by title Collections.sort(videos, new Comparator<VideoData>() { @Override public int compare(VideoData videoData, VideoData videoData2) { return videoData.getTitle().compareTo(videoData2.getTitle()); } }); return videos; } catch (final GooglePlayServicesAvailabilityIOException availabilityException) { showGooglePlayServicesAvailabilityErrorDialog(availabilityException.getConnectionStatusCode()); } catch (UserRecoverableAuthIOException userRecoverableException) { startActivityForResult(userRecoverableException.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { Utils.logAndShow(Youtube_MainActivity.this, Youtube_Constants.APP_NAME, e); } return null; } @Override protected void onPostExecute(List<VideoData> videos) { setProgressBarIndeterminateVisibility(false); if (videos == null) { return; } mYoutubeUploadsListFragment.setVideos(videos); } }.execute((Void) null); }
From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java
/** * Saves the value for the "approvals" restriction of AppRestrictionSchema. * * @param activity The activity//from www . j a v a2 s . co m * @param approvals The value to be set for the restriction. */ private void saveApprovals(Activity activity, String[] approvals) { mCurrentRestrictions.putStringArray(RESTRICTION_KEY_APPROVALS, approvals); saveRestrictions(activity); editPreferences(activity).putString(RESTRICTION_KEY_APPROVALS, TextUtils.join(DELIMETER, approvals)) .apply(); }
From source file:org.thoughtland.xlocation.ActivityUsage.java
private void updateTitle() { if (mUid == 0) { // Get statistics long count = 0; long restricted = 0; double persec = 0; try {/*ww w . java 2s. co m*/ @SuppressWarnings("rawtypes") Map statistics = PrivacyService.getClient().getStatistics(); count = (Long) statistics.get("restriction_count"); restricted = (Long) statistics.get("restriction_restricted"); long uptime = (Long) statistics.get("uptime_milliseconds"); persec = (double) count / (uptime / 1000); } catch (Throwable ex) { Util.bug(null, ex); } // Set sub title getActionBar().setSubtitle(String.format("%d/%d %.2f/s", restricted, count, persec)); } else getActionBar() .setSubtitle(TextUtils.join(", ", new ApplicationInfoEx(this, mUid).getApplicationName())); }