Example usage for android.text TextUtils join

List of usage examples for android.text TextUtils join

Introduction

In this page you can find the example usage for android.text TextUtils join.

Prototype

public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens) 

Source Link

Document

Returns a string containing the tokens joined by delimiters.

Usage

From source file:com.deliciousdroid.platform.BookmarkManager.java

public static void TruncateBookmarks(ArrayList<String> accounts, Context context, boolean inverse) {

    final ArrayList<String> selectionList = new ArrayList<String>();

    final String operator = inverse ? "<>" : "=";
    final String logicalOp = inverse ? " AND " : " OR ";

    for (String s : accounts) {
        selectionList.add(Bookmark.Account + " " + operator + " '" + s + "'");
    }/*from  w  ww .j a  v  a2  s .com*/

    String selection = TextUtils.join(logicalOp, selectionList);

    if (accounts.size() > 0)
        selection += " AND " + Bookmark.Synced + "=1";
    else
        selection += Bookmark.Synced + "=1";

    context.getContentResolver().delete(Bookmark.CONTENT_URI, selection, null);
}

From source file:org.xbmc.kore.ui.sections.audio.SongsListFragment.java

private void setDetails(TextView textView, String... elements) {
    if ((elements == null) || (elements.length < 1)) {
        return;/*from   ww  w.j  av  a  2 s.  c om*/
    }

    ArrayList<String> details = new ArrayList<>();
    for (int i = 0; i < elements.length; i++) {
        if (!TextUtils.isEmpty(elements[i]))
            details.add(elements[i]);
    }

    textView.setText(TextUtils.join(" | ", details.toArray()));
}

From source file:com.ichi2.libanki.Decks.java

/**
 * Rename deck prefix to NAME if not exists. Updates children.
 *///from   w ww . ja  v a 2s  . co  m
public void rename(JSONObject g, String newName) throws DeckRenameException {
    // make sure target node doesn't already exist
    if (allNames().contains(newName)) {
        throw new DeckRenameException(DeckRenameException.ALREADY_EXISTS);
    }
    try {
        // ensure we have parents
        newName = _ensureParents(newName);
        // make sure we're not nesting under a filtered deck
        if (newName.contains("::")) {
            List<String> parts = Arrays.asList(newName.split("::", -1));
            String newParent = TextUtils.join("::", parts.subList(0, parts.size() - 1));
            if (byName(newParent).getInt("dyn") != 0) {
                throw new DeckRenameException(DeckRenameException.FILTERED_NOSUBDEKCS);
            }
        }
        // rename children
        String oldName = g.getString("name");
        for (JSONObject grp : all()) {
            if (grp.getString("name").startsWith(oldName + "::")) {
                // In Java, String.replaceFirst consumes a regex so we need to quote the pattern to be safe
                grp.put("name",
                        grp.getString("name").replaceFirst(Pattern.quote(oldName + "::"), newName + "::"));
                save(grp);
            }
        }
        // adjust name
        g.put("name", newName);
        // ensure we have parents again, as we may have renamed parent->child
        newName = _ensureParents(newName);
        save(g);
        // renaming may have altered active did order
        maybeAddToActive();
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.gorbin.asne.vk.VkSocialNetwork.java

/**
 * Request ArrayList of {@link com.github.gorbin.asne.core.persons.SocialPerson} by array of userIds
 * @param userID array of VK users id/*from   ww w  . ja v a 2s  .com*/
 * @param onRequestSocialPersonsCompleteListener listener for array of {@link com.github.gorbin.asne.core.persons.SocialPerson} request
 */
@Override
public void requestSocialPersons(String[] userID,
        OnRequestSocialPersonsCompleteListener onRequestSocialPersonsCompleteListener) {
    super.requestSocialPersons(userID, onRequestSocialPersonsCompleteListener);
    String userIds = TextUtils.join(",", userID);
    VKRequest request = VKApi.users().get(VKParameters.from(VKApiConst.USER_IDS, userIds, VKApiConst.FIELDS,
            "id,first_name,last_name,photo_max_orig"));
    request.secure = false;
    request.useSystemLanguage = true;
    request.executeWithListener(new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            SocialPerson socialPerson = new SocialPerson();
            ArrayList<SocialPerson> socialPersons = new ArrayList<SocialPerson>();
            try {

                JSONArray jsonArray = response.json.getJSONArray("response");
                int length = jsonArray.length();
                for (int i = 0; i < length; i++) {
                    getSocialPerson(socialPerson, jsonArray.getJSONObject(i));
                    socialPersons.add(socialPerson);
                    socialPerson = new SocialPerson();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            ((OnRequestSocialPersonsCompleteListener) mLocalListeners.get(REQUEST_GET_PERSONS))
                    .onRequestSocialPersonsSuccess(getID(), socialPersons);
            mLocalListeners.remove(REQUEST_GET_PERSONS);
        }

        @Override
        public void onError(VKError error) {
            mLocalListeners.get(REQUEST_GET_PERSONS).onError(getID(), REQUEST_GET_PERSONS, error.toString(),
                    null);
            mLocalListeners.remove(REQUEST_GET_PERSONS);
        }

        @Override
        public void attemptFailed(VKRequest request, int attemptNumber, int totalAttempts) {
            mLocalListeners.remove(REQUEST_GET_PERSONS);
            throw new SocialNetworkException("Fail in attempt person request!");
        }
    });
}

From source file:com.aengbee.android.leanback.ui.PlaybackOverlayFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    int state = args.getInt("state", 4);
    switch (state) {
    case RECOMMENDED_VIDEOS_LOADER: {
        return CursorLoaderNormalizer(args.getString(VideoContract.VideoEntry.COLUMN_DESC, ""));
    }/*from   ww  w.j  ava 2 s .  c om*/
    case QUEUE_VIDEOS_LOADER: {
        //Long videoId = args.getLong(VideoContract.VideoEntry._ID);
        return new CursorLoader(getActivity(), VideoContract.VideoEntry.CONTENT_URI, null, // Projection to return - null means return all fields.
                VideoContract.VideoEntry._ID + " IN ( ? ) OR " + VideoContract.VideoEntry.COLUMN_CARD_IMG
                        + " LIKE ? ", // Selection clause is id.
                // Selection clause is category.
                new String[] { TextUtils.join(",", mBook), "%add.jpg" }, // Select based on the id.
                null//"INSTR (',"+TextUtils.join(",", mBook)+",', ',' || "+ VideoContract.VideoEntry._ID + " || ',')" // Default sort order
        );
    }
    case SEARCH_VIDEOS_LOADER: {
        // Loading a specific video.
        return CursorLoaderNormalizer(mQuery);
    }
    default: {
        if (mQuery == null) {
            return new CursorLoader(getActivity(), VideoContract.VideoEntry.CONTENT_URI, null, // Projection to return - null means return all fields.
                    VideoContract.VideoEntry._ID + " IN ( ? ) OR " + VideoContract.VideoEntry.COLUMN_CARD_IMG
                            + " LIKE ? ", // Selection clause is id.
                    // Selection clause is category.
                    new String[] { TextUtils.join(",", mBook), "%add.jpg" }, // Select based on the id.
                    null//"INSTR (',"+TextUtils.join(",", mBook)+",', ',' || "+ VideoContract.VideoEntry._ID + " || ',')" // Default sort order
            );
        } else
            return CursorLoaderNormalizer(mQuery);
    }
    }
}

From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java

public void markAllAsRead() {
    if (mEntriesCursorAdapter != null) {
        Snackbar snackbar = Snackbar//from   w w  w.j  ava 2s .  co  m
                .make(getActivity().findViewById(R.id.coordinator_layout), R.string.marked_as_read,
                        Snackbar.LENGTH_LONG)
                .setActionTextColor(ContextCompat.getColor(getActivity(), R.color.light_theme_color_primary))
                .setAction(R.string.undo, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        new Thread() {
                            @Override
                            public void run() {
                                if (mJustMarkedAsReadEntries != null && !mJustMarkedAsReadEntries.isClosed()) {
                                    ArrayList<Integer> ids = new ArrayList<>();
                                    while (mJustMarkedAsReadEntries.moveToNext()) {
                                        ids.add(mJustMarkedAsReadEntries.getInt(0));
                                    }
                                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                                    String where = BaseColumns._ID + " IN (" + TextUtils.join(",", ids) + ')';
                                    cr.update(FeedData.EntryColumns.CONTENT_URI,
                                            FeedData.getUnreadContentValues(), where, null);

                                    mJustMarkedAsReadEntries.close();
                                }
                            }
                        }.start();
                    }
                });
        snackbar.getView().setBackgroundResource(R.color.material_grey_900);
        snackbar.show();

        new Thread() {
            @Override
            public void run() {
                ContentResolver cr = MainApplication.getContext().getContentResolver();
                String where = EntryColumns.WHERE_UNREAD + Constants.DB_AND + '(' + EntryColumns.FETCH_DATE
                        + Constants.DB_IS_NULL + Constants.DB_OR + EntryColumns.FETCH_DATE + "<="
                        + mListDisplayDate + ')';
                if (mJustMarkedAsReadEntries != null && !mJustMarkedAsReadEntries.isClosed()) {
                    mJustMarkedAsReadEntries.close();
                }
                mJustMarkedAsReadEntries = cr.query(mCurrentUri, new String[] { BaseColumns._ID }, where, null,
                        null);
                cr.update(mCurrentUri, FeedData.getReadContentValues(), where, null);
            }
        }.start();

        // If we are on "all items" uri, we can remove the notification here
        if (mCurrentUri != null && Constants.NOTIF_MGR != null && (EntryColumns.CONTENT_URI.equals(mCurrentUri)
                || EntryColumns.UNREAD_ENTRIES_CONTENT_URI.equals(mCurrentUri))) {
            Constants.NOTIF_MGR.cancel(0);
        }
    }
}

From source file:dev.drsoran.moloko.fragments.AbstractTaskEditFragment.java

public void setTags(List<String> tags) {
    final String joinedTags = TextUtils.join(Tasks.TAGS_SEPARATOR, tags);

    if (SyncUtils.hasChanged(getCurrentValue(Tasks.TAGS, String.class), joinedTags)) {
        putChange(Tasks.TAGS, joinedTags, String.class);
        initializeTagsSection();//from   ww  w  .  ja  v  a  2  s  .c o  m
    }
}

From source file:paulscode.android.mupen64plusae.profile.TouchscreenProfileActivity.java

private void setHoldable(int n64Index, boolean holdable) {
    String index = String.valueOf(n64Index);

    // Get the serialized list from the profile
    String serialized = mProfile.get(TOUCHSCREEN_AUTOHOLDABLES, "");
    String[] holdables = serialized.split(AUTOHOLDABLES_DELIMITER);

    // Modify the list as necessary
    if (!holdable) {
        holdables = (String[]) ArrayUtils.removeElement(holdables, index);
    } else if (!ArrayUtils.contains(holdables, index)) {
        holdables = (String[]) ArrayUtils.add(holdables, index);
    }/*from  ww w.j  a v  a 2  s  . co  m*/

    // Put the serialized list back into the profile
    serialized = TextUtils.join(AUTOHOLDABLES_DELIMITER, holdables);
    mProfile.put(TOUCHSCREEN_AUTOHOLDABLES, serialized);
}

From source file:com.google.android.gm.ay.java

private static Bundle g(final Context context, final Account account) {
    final Bundle bundle = new Bundle();
    final Account[] ax = com.android.mail.utils.a.ax(context);
    final HashSet<String> set = new HashSet<String>();
    for (int length = ax.length, i = 0; i < length; ++i) {
        set.add(com.google.android.gm.c.c.i(context, ax[i]));
    }/*from   w  w  w  .j  a va 2 s.c  o  m*/
    if (set.size() > 0) {
        bundle.putString("all-account-domains", TextUtils.join((CharSequence) "/", (Iterable) set));
    }
    if (account != null) {
        bundle.putString("current-account-domain", com.google.android.gm.c.c.i(context, account));
    }
    return bundle;
}

From source file:com.eutectoid.dosomething.picker.PlacePickerFragment.java

private GraphRequest createRequest(Location location, int radiusInMeters, int resultsLimit, String searchText,
        Set<String> extraFields) {
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    GraphRequest request = GraphRequest.newPlacesSearchRequest(accessToken, location, radiusInMeters,
            resultsLimit, searchText, null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[] { ID, NAME, LOCATION, CATEGORY, WERE_HERE_COUNT };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);//from w w w .  j  a v a 2 s. c  om
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}