List of usage examples for android.text TextUtils join
public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens)
From source file:com.android.mail.ui.ConversationViewFragment.java
private boolean processInPlaceUpdates(MessageCursor newCursor, MessageCursor oldCursor) { final Set<String> idsOfChangedBodies = Sets.newHashSet(); final List<Integer> changedOverlayPositions = Lists.newArrayList(); boolean changed = false; int pos = 0;/*from w ww . j a v a 2 s. c om*/ while (true) { if (!newCursor.moveToPosition(pos) || !oldCursor.moveToPosition(pos)) { break; } final ConversationMessage newMsg = newCursor.getMessage(); final ConversationMessage oldMsg = oldCursor.getMessage(); // We are going to update the data in the adapter whenever any input fields change. // This ensures that the Message object that ComposeActivity uses will be correctly // aligned with the most up-to-date data. if (!newMsg.isEqual(oldMsg)) { mAdapter.updateItemsForMessage(newMsg, changedOverlayPositions); LogUtils.i(LOG_TAG, "msg #%d (%d): detected field(s) change. sendingState=%s", pos, newMsg.id, newMsg.sendingState); } // update changed message bodies in-place if (!TextUtils.equals(newMsg.bodyHtml, oldMsg.bodyHtml) || !TextUtils.equals(newMsg.bodyText, oldMsg.bodyText)) { // maybe just set a flag to notify JS to re-request changed bodies idsOfChangedBodies.add('"' + mTemplates.getMessageDomId(newMsg) + '"'); LogUtils.i(LOG_TAG, "msg #%d (%d): detected body change", pos, newMsg.id); } pos++; } if (!changedOverlayPositions.isEmpty()) { // notify once after the entire adapter is updated mConversationContainer.onOverlayModelUpdate(changedOverlayPositions); changed = true; } final ConversationFooterItem footerItem = mAdapter.getFooterItem(); if (footerItem != null) { footerItem.invalidateMeasurement(); } if (!idsOfChangedBodies.isEmpty()) { mWebView.loadUrl(String.format("javascript:replaceMessageBodies([%s]);", TextUtils.join(",", idsOfChangedBodies))); changed = true; } return changed; }
From source file:com.yek.keyboard.keyboards.views.AnyKeyboardViewBase.java
/** * Called when a key is long pressed. By default this will open any popup * keyboard associated with this key through the attributes popupLayout and * popupCharacters./*from www. ja va 2 s . co m*/ * * @param keyboardAddOn the owning keyboard that starts this long-press operation * @param key the key that was long pressed * @return true if the long press is handled, false otherwise. Subclasses * should call the method on the base class if the subclass doesn't * wish to handle the call. */ public boolean onLongPress(AddOn keyboardAddOn, Keyboard.Key key, boolean isSticky, @NonNull PointerTracker tracker) { if (key instanceof AnyKeyboard.AnyKey) { AnyKeyboard.AnyKey anyKey = (AnyKeyboard.AnyKey) key; if (anyKey.getKeyTags().size() > 0) { Object[] tags = anyKey.getKeyTags().toArray(); for (int tagIndex = 0; tagIndex < tags.length; tagIndex++) { tags[tagIndex] = ":" + tags[tagIndex]; } String joinedTags = TextUtils.join(", ", tags); Toast.makeText(getContext().getApplicationContext(), joinedTags, Toast.LENGTH_SHORT).show(); } if (anyKey.longPressCode != 0) { getOnKeyboardActionListener().onKey(anyKey.longPressCode, key, 0/*not multi-tap*/, null, true); tracker.onCancelEvent(); return true; } } return false; }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java
/** * Called when a key is long pressed. By default this will open any popup * keyboard associated with this key through the attributes popupLayout and * popupCharacters.//from w w w . jav a 2 s. com * * @param keyboardAddOn the owning keyboard that starts this long-press operation * @param key the key that was long pressed * @return true if the long press is handled, false otherwise. Subclasses * should call the method on the base class if the subclass doesn't * wish to handle the call. */ protected boolean onLongPress(AddOn keyboardAddOn, Key key, boolean isSticky, @NonNull PointerTracker tracker) { if (key instanceof AnyKey) { AnyKey anyKey = (AnyKey) key; if (anyKey.getKeyTags().size() > 0) { Object[] tags = anyKey.getKeyTags().toArray(); for (int tagIndex = 0; tagIndex < tags.length; tagIndex++) { tags[tagIndex] = ":" + tags[tagIndex]; } String joinedTags = TextUtils.join(", ", tags); Toast.makeText(getContext().getApplicationContext(), joinedTags, Toast.LENGTH_SHORT).show(); } if (anyKey.longPressCode != 0) { getOnKeyboardActionListener().onKey(anyKey.longPressCode, key, 0/*not multi-tap*/, null, true); tracker.onCancelEvent(); return true; } } return false; }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void backupPreferences() { if (isOnline()) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); builder.setTitle(R.string.action_backup_preferences_save); builder.setMessage(R.string.backup_preferences_save_text); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override/*from w w w .j a v a 2s . co m*/ public void onClick(DialogInterface dialog, int which) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Map<String, ?> preferences = pref.getAll(); StringBuilder backup = new StringBuilder(); Set<String> keys = preferences.keySet(); for (String key : keys) { Object value = preferences.get(key); if (value instanceof Boolean) { if (!getString(R.string.PREF_RATING_DONATION_INFO_SHOWN).equals(key) || ((Boolean) value).booleanValue()) { backup.append("boolean:").append(key).append("=").append(value).append("\n"); } } else if (value instanceof Integer) { if (!getString(R.string.OLD_VERSION).equals(key)) { backup.append("int:").append(key).append("=").append(value).append("\n"); } } else if (value instanceof Float) { backup.append("float:").append(key).append("=").append(value).append("\n"); } else if (value instanceof Long) { backup.append("long:").append(key).append("=").append(value).append("\n"); } else if (value instanceof String && value != null && ((String) value).trim().length() > 0) { backup.append("string:").append(key).append("=").append(value).append("\n"); } else if (value instanceof Set<?>) { if (!key.equals(getString(R.string.I_DONT_WANT_TO_SEE_ENTRIES))) { Set<String> valueSet = (Set<String>) value; backup.append("set:").append(key).append("="); backup.append(TextUtils.join("#,#", valueSet)); backup.append("\n"); } } } Favorite[] favorites = Favorite.getAllFavorites(getApplicationContext()); for (Favorite favorite : favorites) { backup.append("favorite:"); backup.append(favorite.getFavoriteId()); backup.append("="); backup.append(favorite.getSaveString(TvBrowser.this)); backup.append("\n"); } startSynchronizeUp(true, backup.toString(), "http://android.tvbrowser.org/data/scripts/syncUp.php?type=preferencesBackup", SettingConstants.SYNCHRONIZE_UP_DONE, getString(R.string.backup_preferences_success)); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } else { showNoInternetConnection(getString(R.string.no_network_info_data_pref_backup), null); } }
From source file:cgeo.geocaching.CacheListActivity.java
private void prepareFilterBar() { final List<String> filterNames = getFilterNames(); if (filterNames.isEmpty()) { findViewById(R.id.filter_bar).setVisibility(View.GONE); } else {/* w w w . j a va 2 s . co m*/ final TextView filterTextView = ButterKnife.findById(this, R.id.filter_text); filterTextView.setText(TextUtils.join(", ", filterNames)); findViewById(R.id.filter_bar).setVisibility(View.VISIBLE); } }
From source file:illab.nabal.proxy.FacebookProxy.java
/** * Get Facebook objects that are liked by given owner identifier. * /*from w w w.jav a 2 s. c o m*/ * @param ownerIdentifier * @param limit * @param offset * @param locale * @return list of FacebookLikableObject objects * @throws Exception */ private List<FacebookLikableObject> getLikedObjects(String ownerIdentifier, int limit, int offset, Locale locale) throws Exception { String apiUri = "/" + ownerIdentifier + "/likes"; // fields parameters String[] fields = { "id", "category", "name", "description", "link", "can_post", "talking_about_count", "website", "cover", "created_time" }; // set system locale if none given Locale localeParam = locale; if (localeParam == null) localeParam = Util.getSystemLocale(); // check locale and set to system default if null List<NameValuePair> params = ParameterHelper.addAllParams( new BasicNameValuePair("access_token", mFacebookContext.getAccessToken()), new BasicNameValuePair("fields", TextUtils.join(",", fields)), new BasicNameValuePair("locale", localeParam.toString())); // set page parameters setPageOffsetParams(params, limit, offset); return populateLikableList(localeParam, getResponseJson(getHttpGet(apiUri, params))); }
From source file:com.scoreflex.Scoreflex.java
/** * Sends a facebook app request inviting a user (or a list of users) to * install the game/*w w w .j av a 2s .com*/ * * @param activity * the current activity * @param text * the message that will be prefilled in the invitation * @param friendIds * a list of friend you want to invite * @param suggestedFriendIds * the suggested friend (appears in the invitation dialog) * @param data * any data you want to attach to the invitation (deeplink) */ public static void sendFacebookInvitation(Activity activity, String text, List<String> friendIds, List<String> suggestedFriendIds, String data) { try { ScoreflexFacebookWrapper.sendInvitation(activity, text, friendIds, suggestedFriendIds, data, new SocialShareCallback() { @Override public void OnSuccessShare(List<String> invitedFriends) { String concatenatedFriends = "Facebook%3A" + TextUtils.join(",Facebook%3A", invitedFriends); Scoreflex.postEventually("/social/invitations/" + concatenatedFriends, null, null); } }); } catch (FacebookException e) { e.printStackTrace(); } }
From source file:com.tct.mail.browse.MessageHeaderView.java
/** * Render an email list for the expanded message details view. *//* ww w . j a va 2 s . c om*/ private void renderEmailList(Resources res, int headerId, int detailsId, String[] emails, String viaDomain, View rootView, Map<String, Address> addressCache, Account account, VeiledAddressMatcher veiledMatcher, BidiFormatter bidiFormatter) { if (emails == null || emails.length == 0) { return; } final String[] formattedEmails = new String[emails.length]; for (int i = 0; i < emails.length; i++) { final Address email = Utils.getAddress(addressCache, emails[i]); String name = email.getPersonal(); final String address = email.getAddress(); // Check if the address here is a veiled address. If it is, we need to display an // alternate layout final boolean isVeiledAddress = veiledMatcher != null && veiledMatcher.isVeiledAddress(address); final String addressShown; if (isVeiledAddress) { // Add the warning at the end of the name, and remove the address. The alternate // text cannot be put in the address part, because the address is made into a link, // and the alternate human-readable text is not a link. addressShown = ""; if (TextUtils.isEmpty(name)) { // Empty name and we will block out the address. Let's write something more // readable. name = res.getString(VeiledAddressMatcher.VEILED_ALTERNATE_TEXT_UNKNOWN_PERSON); } else { name = name + res.getString(VeiledAddressMatcher.VEILED_ALTERNATE_TEXT); } } else { addressShown = address; } if (name == null || name.length() == 0 || name.equalsIgnoreCase(addressShown)) { formattedEmails[i] = bidiFormatter.unicodeWrap(addressShown); } else { // The one downside to having the showViaDomain here is that // if the sender does not have a name, it will not show the via info if (viaDomain != null) { formattedEmails[i] = res.getString(R.string.address_display_format_with_via_domain, bidiFormatter.unicodeWrap(name), bidiFormatter.unicodeWrap(addressShown), bidiFormatter.unicodeWrap(viaDomain)); } else { formattedEmails[i] = res.getString(R.string.address_display_format, bidiFormatter.unicodeWrap(name), bidiFormatter.unicodeWrap(addressShown)); } } } rootView.findViewById(headerId).setVisibility(VISIBLE); final TextView detailsText = (TextView) rootView.findViewById(detailsId); detailsText.setText(TextUtils.join("\n", formattedEmails)); stripUnderlines(detailsText, account); detailsText.setVisibility(VISIBLE); }
From source file:com.android.mail.utils.NotificationUtils.java
private static ArrayList<Long> findContacts(Context context, Collection<String> addresses) { ArrayList<String> whereArgs = new ArrayList<String>(); StringBuilder whereBuilder = new StringBuilder(); String[] questionMarks = new String[addresses.size()]; whereArgs.addAll(addresses);//from w w w . j a v a 2s . com Arrays.fill(questionMarks, "?"); whereBuilder.append(Email.DATA1 + " IN (").append(TextUtils.join(",", questionMarks)).append(")"); ContentResolver resolver = context.getContentResolver(); Cursor c = resolver.query(Email.CONTENT_URI, new String[] { Email.CONTACT_ID }, whereBuilder.toString(), whereArgs.toArray(new String[0]), null); ArrayList<Long> contactIds = new ArrayList<Long>(); if (c == null) { return contactIds; } try { while (c.moveToNext()) { contactIds.add(c.getLong(0)); } } finally { c.close(); } return contactIds; }
From source file:com.android.mail.browse.ConversationCursor.java
public static void addFolderUpdates(ArrayList<Uri> folderUris, ArrayList<Boolean> add, ContentValues values) { ArrayList<String> folders = new ArrayList<String>(); for (int i = 0; i < folderUris.size(); i++) { folders.add(folderUris.get(i).buildUpon().appendPath(add.get(i) + "").toString()); }//from w w w.jav a 2s.co m values.put(ConversationOperations.FOLDERS_UPDATED, TextUtils.join(ConversationOperations.FOLDERS_UPDATED_SPLIT_PATTERN, folders)); }