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.facebook.login.GetTokenLoginMethodHandler.java

void getTokenCompleted(LoginClient.Request request, Bundle result) {
    if (getTokenClient != null) {
        getTokenClient.setCompletedListener(null);
    }//  w w w .j  a v  a2  s .co  m
    getTokenClient = null;

    loginClient.notifyBackgroundProcessingStop();

    if (result != null) {
        ArrayList<String> currentPermissions = result.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
        Set<String> permissions = request.getPermissions();
        if ((currentPermissions != null)
                && ((permissions == null) || currentPermissions.containsAll(permissions))) {
            // We got all the permissions we needed, so we can complete the auth now.
            complete(request, result);
            return;
        }

        // We didn't get all the permissions we wanted, so update the request with just the
        // permissions we still need.
        Set<String> newPermissions = new HashSet<String>();
        for (String permission : permissions) {
            if (!currentPermissions.contains(permission)) {
                newPermissions.add(permission);
            }
        }
        if (!newPermissions.isEmpty()) {
            addLoggingExtra(LoginLogger.EVENT_EXTRAS_NEW_PERMISSIONS, TextUtils.join(",", newPermissions));
        }

        request.setPermissions(newPermissions);
    }

    loginClient.tryNextHandler();
}

From source file:net.vleu.par.android.rpc.PersistentCookieStore.java

@Override
public void addCookie(final Cookie cookie) {
    final String name = cookie.getName();

    // Save cookie into local store
    this.cookies.put(name, cookie);

    // Save cookie into persistent store
    final SharedPreferences.Editor prefsWriter = this.cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();/*from   w ww . j a v  a 2  s .com*/
}

From source file:tw.idv.palatis.danboorugallery.siteapi.ShimmieAPI.java

@Override
public List<Post> fetchPosts(Host host, int startFrom, String[] tags) throws SiteAPIException {
    HttpURLConnection connection = null;
    try {//  w w w .j  a v a2 s.  c  o  m
        int limit = host.getPageLimit(DanbooruGallerySettings.getBandwidthUsageType());
        int page = startFrom / limit + 1;

        String strtags = URLEncoder.encode(TextUtils.join(" ", tags), "UTF-8");
        if (TextUtils.isEmpty(strtags))
            strtags = "*";

        String url = String.format(URL_POSTS_FORMAT, host.url, page, strtags, 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());

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new InputSource(connection.getInputStream()));
        doc.getDocumentElement().normalize();

        NodeList nodes = doc.getElementsByTagName("post");

        int length = nodes.getLength();
        List<Post> posts = new ArrayList<>(length);
        for (int j = 0; j < length; ++j)
            posts.add(parseXMLElementToPost(host, (Element) nodes.item(j)));

        return posts;
    } catch (ParserConfigurationException | SAXException | IOException ex) {
        throw new SiteAPIException(this, connection, ex);
    } finally {
        if (connection != null)
            connection.disconnect();
    }
}

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

public void setChosenTags(List<String> tags) {
    chosenTags = new ArrayList<String>(tags);
    editView.setText(TextUtils.join(", ", chosenTags));
}

From source file:org.level28.android.moca.json.ScheduleDeserializer.java

private static Session parseSession(final JsonNode objectRoot) throws JsonDeserializerException {
    // Basic sanity checks
    if (objectRoot == null || objectRoot.isNull()) {
        throw new JsonDeserializerException("null objectRoot");
    }//w  w w. j av  a  2  s. com
    if (!objectRoot.isObject()) {
        throw new JsonDeserializerException("objectRoot is not a JSON object");
    }

    JsonNode node;
    Session result = new Session();

    try {
        // Session id (required)
        node = objectRoot.path("id");
        if (node.isMissingNode() || !node.isTextual()) {
            throw new JsonDeserializerException("'id' is missing or invalid");
        }
        result.setId(node.textValue());

        // Session title (required)
        node = objectRoot.path("title");
        if (node.isMissingNode() || !node.isTextual()) {
            throw new JsonDeserializerException("'title' is missing or invalid");
        }
        result.setTitle(node.textValue());

        // Session day (required)
        node = objectRoot.path("day");
        if (node.isMissingNode() || !node.isInt()) {
            throw new JsonDeserializerException("'day' is missing or invalid");
        }
        result.setDay(node.asInt());

        // Session start time (required)
        node = objectRoot.path("start");
        if (node.isMissingNode() || !node.isTextual()) {
            throw new JsonDeserializerException("'start' is missing or invalid");
        }
        result.setStartTime(parseTime(node.textValue()));

        // Session end time (required)
        node = objectRoot.path("end");
        if (node.isMissingNode() || !node.isTextual()) {
            throw new JsonDeserializerException("'end' is missing or invalid");
        }
        result.setEndTime(parseTime(node.textValue()));

        // Session hosts (required)
        node = objectRoot.path("hosts");
        if (node.isMissingNode() || !node.isArray()) {
            throw new JsonDeserializerException("'hosts' is missing or invalid");
        }
        final ArrayList<String> hosts = new ArrayList<String>(node.size());
        for (JsonNode hostsSubNode : node) {
            if (!hostsSubNode.isTextual() || "".equals(hostsSubNode.textValue())) {
                throw new JsonDeserializerException("'hosts' children is not valid");
            }
            hosts.add(hostsSubNode.textValue());
        }
        result.setHosts(TextUtils.join(", ", hosts));

        // Session language (required)
        node = objectRoot.path("lang");
        if (node.isMissingNode() || !node.isTextual()) {
            throw new JsonDeserializerException("'lang' is missing or invalid");
        }
        result.setLang(node.textValue());

        // Session abstract (optional)
        node = objectRoot.path("abstract");
        if (!node.isMissingNode()) {
            result.setSessionAbstract(node.textValue());
        }

        return result;
    } catch (IllegalArgumentException e) {
        throw new JsonDeserializerException("Invalid session entry", e);
    } catch (ParseException e) {
        throw new JsonDeserializerException("Invalid session entry", e);
    }
}

From source file:eu.faircode.adblocker.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;//from   w  w  w.j av a2s .c o  m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:fr.s13d.photobackup.media.PBMediaStore.java

Cursor getAllMediasCursor() {
    String where = null;/*from  ww  w .  j a v a2s .c  om*/
    final SharedPreferences prefs = getDefaultSharedPreferences(PBApplication.getApp());
    final Set<String> bucketIds = prefs.getStringSet(PBConstants.PREF_PICTURE_FOLDER_LIST, null);
    if (bucketIds != null && !bucketIds.isEmpty()) {
        final String bucketString = TextUtils.join(", ", bucketIds);
        where = "bucket_id in (" + bucketString + ")";
    }

    final boolean backupVideos = prefs.getBoolean(PBConstants.PREF_MEDIA_BACKUP_VIDEO, false);
    final String[] projection = new String[] { "_id", "_data", "date_added" };
    final ContentResolver cr = PBApplication.getApp().getContentResolver();
    final Cursor[] cursors = new Cursor[backupVideos ? 2 : 1];
    cursors[0] = cr.query(imagesUri, projection, where, null, DATE_ADDED_DESC);
    if (backupVideos) {
        cursors[1] = cr.query(videosUri, projection, where, null, DATE_ADDED_DESC);
    }
    if (cursors[0] == null) {
        Log.d(LOG_TAG, "Media cursor is null.");
        return null;
    }

    return new MergeCursor(cursors);
}

From source file:com.zhengde163.netguard.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/*  ww  w.ja v a 2  s . c om*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        //            Util.setTheme(context);
        context.setTheme(R.style.AppThemeBlue);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:net.bither.preference.PersistentCookieStore.java

@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = this.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);/* w  w w.  ja v  a 2s .  c  om*/

            // 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;
}

From source file:com.master.metehan.filtereagle.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;// w w  w .  j  a va  2  s .c o m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}