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:eu.operando.operandoapp.util.NotificationUtil.java

public void displayExfiltratedNotification(Context context, String applicationInfo,
        Set<RequestFilterUtil.FilterType> exfiltrated, int mainNotificationId) {
    try {//from w  ww.j av  a  2  s.c  o  m
        StringBuilder sb = new StringBuilder();
        for (RequestFilterUtil.FilterType f : exfiltrated) {
            sb.append(f + ", ");
        }
        sb.delete(sb.length() - 2, sb.length() - 1);

        RemoteViews smallContentView = new RemoteViews(context.getPackageName(),
                R.layout.proxy_notification_small);
        smallContentView.setImageViewResource(R.id.image, R.drawable.logo_bevel);
        smallContentView.setTextViewText(R.id.titleTxtView, "Personal Information");
        smallContentView.setTextViewText(R.id.subtitleTxtView, "Expand for more info");

        RemoteViews bigContentView = new RemoteViews(context.getPackageName(),
                R.layout.proxy_notification_large);
        bigContentView.setImageViewResource(R.id.image, R.drawable.logo_bevel);
        bigContentView.setTextViewText(R.id.titleTxtView, "Personal Information");
        bigContentView.setTextViewText(R.id.subtitleTxtView,
                applicationInfo.replaceAll("\\s\\(.*?\\)", "") + " requires access to " + sb);
        bigContentView.setTextViewText(R.id.allowBtn, "Allow");
        bigContentView.setTextViewText(R.id.blockBtn, "Block");

        //get exfiltrated info to string array
        String[] exfiltrated_array = new String[exfiltrated.size()];
        int i = 0;
        for (RequestFilterUtil.FilterType filter_type : exfiltrated) {
            exfiltrated_array[i] = filter_type.name();
            i++;
        }

        //set listeners for notification buttons

        Intent allowIntent = new Intent(context, NotificationActivityReceiver.class);
        allowIntent.setAction("allow");
        Bundle allowBundle = new Bundle();
        allowBundle.putString("appInfo", applicationInfo);
        allowBundle.putInt("notificationId", mainNotificationId);
        allowBundle.putStringArray("exfiltrated", exfiltrated_array);
        allowIntent.putExtras(allowBundle);
        PendingIntent pendingAllowIntent = PendingIntent.getBroadcast(context, mainNotificationId + 1,
                allowIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        bigContentView.setOnClickPendingIntent(R.id.allowBtn, pendingAllowIntent);

        Intent blockIntent = new Intent(context, NotificationActivityReceiver.class);
        blockIntent.setAction("block");
        Bundle blockBundle = new Bundle();
        blockBundle.putString("appInfo", applicationInfo);
        blockBundle.putInt("notificationId", mainNotificationId);
        blockBundle.putStringArray("exfiltrated", exfiltrated_array);
        blockIntent.putExtras(blockBundle);
        PendingIntent pendingBlockIntent = PendingIntent.getBroadcast(context, mainNotificationId + 2,
                blockIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        bigContentView.setOnClickPendingIntent(R.id.blockBtn, pendingBlockIntent);

        Notification.Builder mBuilder = new Notification.Builder(context).setSmallIcon(R.drawable.logo_bevel)
                .setContent(smallContentView);
        Notification proxyNotification = mBuilder.build();
        proxyNotification.defaults |= Notification.DEFAULT_ALL;
        proxyNotification.bigContentView = bigContentView;

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(mainNotificationId, proxyNotification);
        DatabaseHelper db = new DatabaseHelper(context);
        db.addPendingNotification(new PendingNotification(applicationInfo,
                TextUtils.join(", ", exfiltrated_array), mainNotificationId));
    } catch (Exception e) {
        Log.d("ERROR", e.getMessage());
    }

}

From source file:com.google.plus.wigwamnow.social.GoogleProvider.java

/**
 * Initiate server-side authorization by sending a one time code to the server.
 *//*www. j  a  v a  2s  .  c om*/
@Override
public void hybridAuth(final Activity activity) {
    // Check that the activity has a PlusClient
    if (!(activity instanceof PlusClientHostActivity)) {
        throw new IllegalArgumentException("Activity must host a PlusClient!");
    }

    final PlusClientHostActivity clientHost = (PlusClientHostActivity) activity;

    // Create the hybrid authorization resources
    final String clientId = activity.getResources().getString(R.string.plus_client_id);
    final String[] activities = activity.getResources().getStringArray(R.array.visible_activities);
    final String[] scopes = activity.getResources().getStringArray(R.array.plus_scopes);
    final String scopeString = "oauth2:server:client_id:" + clientId + ":api_scope:"
            + TextUtils.join(" ", scopes);

    final Bundle appActivities = new Bundle();
    appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, TextUtils.join(" ", activities));

    AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {

        final Activity hostActivity = activity;

        @Override
        protected String doInBackground(Void... params) {
            try {
                return GoogleAuthUtil.getToken(hostActivity, clientHost.getPlusClient().getAccountName(),
                        scopeString, appActivities);
            } catch (IOException transientEx) {
                // Network or server error, try later
                Log.e(TAG, transientEx.toString(), transientEx);
                return null;
            } catch (UserRecoverableAuthException e) {
                // Recover (with e.getIntent())
                Log.e(TAG, e.toString(), e);
                Intent recover = e.getIntent();
                hostActivity.startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH);
            } catch (GoogleAuthException authEx) {
                // The call is not ever expected to succeed and should not be retried.
                Log.e(TAG, authEx.toString(), authEx);
                return null;
            } catch (Exception e) {
                Log.e(TAG, e.toString(), e);
                throw new RuntimeException(e);
            }

            return null;
        }

        @Override
        protected void onPostExecute(String code) {
            Log.d(TAG, "Authorization code retrieved:" + code);
            if (code != null && !mPendingCodeSend) {
                mPendingCodeSend = true;
                initGoogleHybridFlow(code, hostActivity);
            }
        }

    };
    task.execute();

}

From source file:com.csipsimple.ui.favorites.FavLoader.java

/**
 * Creates a cursor that contains a single row and maps the section to the
 * given value.//from ww w  . ja v a2  s .c  o m
 */
private Cursor createHeaderCursorFor(SipProfile account) {
    MatrixCursor matrixCursor = new MatrixCursor(
            new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE, SipProfile.FIELD_DISPLAY_NAME,
                    SipProfile.FIELD_WIZARD, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED,
                    SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY, SipProfile.FIELD_ACC_ID });
    String proxies = "";
    if (account.proxies != null) {
        proxies = TextUtils.join(SipProfile.PROXIES_SEPARATOR, account.proxies);
    }
    matrixCursor
            .addRow(new Object[] { account.id, ContactsWrapper.TYPE_GROUP, account.display_name, account.wizard,
                    account.android_group, account.publish_enabled, account.reg_uri, proxies, account.acc_id });
    return matrixCursor;
}

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

@Override
public List<Post> fetchPosts(Host host, int startFrom, String[] tags) throws SiteAPIException {
    HttpURLConnection connection = null;
    try {//  ww w  .  java2 s. c  om
        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 (JSONException | IOException ex) {
        throw new SiteAPIException(this, connection, ex);
    } finally {
        if (connection != null)
            connection.disconnect();
    }
}

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

/** Add any missing tags from notes to the tags list. */
public void registerNotes(long[] nids) {
    // when called with a null argument, the old list is cleared first.
    String lim;//www . j  a  v  a  2  s  .  c o m
    if (nids != null) {
        lim = " WHERE id IN " + Utils.ids2str(nids);
    } else {
        lim = "";
        mTags.clear();
        mChanged = true;
    }
    List<String> tags = new ArrayList<String>();
    Cursor cursor = null;
    try {
        cursor = mCol.getDb().getDatabase().rawQuery("SELECT DISTINCT tags FROM notes" + lim, null);
        while (cursor.moveToNext()) {
            tags.add(cursor.getString(0));
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    HashSet<String> tagSet = new HashSet<String>();
    for (String s : split(TextUtils.join(" ", tags))) {
        tagSet.add(s);
    }
    register(tagSet);
}

From source file:com.roamprocess1.roaming4world.ui.favorites.FavLoader.java

/**
 * Creates a cursor that contains a single row and maps the section to the
 * given value.// w  ww  . ja  va  2 s .c om
 */
private Cursor createHeaderCursorFor(SipProfile account) {
    MatrixCursor matrixCursor = new MatrixCursor(
            new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE, SipProfile.FIELD_DISPLAY_NAME,
                    SipProfile.FIELD_WIZARD, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED,
                    SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY, SipProfile.FIELD_ACC_ID });
    String proxies = "";
    if (account.proxies != null) {
        proxies = TextUtils.join(SipProfile.PROXIES_SEPARATOR, account.proxies);
    }
    matrixCursor
            .addRow(new Object[] { account.id, ContactsWrapper.TYPE_GROUP, account.display_name, account.wizard,
                    account.android_group, account.publish_enabled, account.reg_uri, proxies, account.acc_id });

    return matrixCursor;
}

From source file:com.slodin.transalarm.GeofenceTransitionsIntentService.java

/**
 * Gets transition details and returns them as a formatted string.
 *
 * @param context               The app context.
 * @param geofenceTransition    The ID of the geofence transition.
 * @param triggeringGeofences   The geofence(s) triggered.
 * @return                      The transition details formatted as String.
 *//*  ww  w .  j  ava  2s .c o  m*/
private String getGeofenceTransitionDetails(Context context, int geofenceTransition,
        List<Geofence> triggeringGeofences) {

    String geofenceTransitionString = getTransitionString(geofenceTransition);

    // Get the Ids of each geofence that was triggered.
    ArrayList triggeringGeofencesIdsList = new ArrayList();
    for (Geofence geofence : triggeringGeofences) {
        triggeringGeofencesIdsList.add(geofence.getRequestId());
    }
    String triggeringGeofencesIdsString = TextUtils.join(", ", triggeringGeofencesIdsList);

    return geofenceTransitionString + " " + triggeringGeofencesIdsString;
}

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

@Override
public boolean clearExpired(final Date date) {
    boolean clearedAny = false;
    final SharedPreferences.Editor prefsWriter = this.cookiePrefs.edit();

    for (final ConcurrentHashMap.Entry<String, Cookie> entry : this.cookies.entrySet()) {
        final String name = entry.getKey();
        final Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            this.cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;/*ww  w  . j av  a  2s  .co m*/
        }
    }

    // Update names in persistent store
    if (clearedAny)
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
    prefsWriter.commit();

    return clearedAny;
}

From source file:com.parse.facebook.FacebookController.java

/**
 * Get auth data from the access token./*from  w w w. java2  s  . com*/
 * Includes the following:
 * - UserId
 * - Access Token
 * - Expiration Date
 * - Last Refresh Date
 * - Permissions (Comma Delineated)
 * @param accessToken - Facebook's {@link AccessToken}
 * @return - {@link Map} of auth data used parse to create facebook {@link AccessToken} by hand.
 * See {@link FacebookController#setAuthData(Map)}
 */
public Map<String, String> getAuthData(AccessToken accessToken) {
    Map<String, String> authData = new HashMap<>();
    authData.put(KEY_USER_ID, accessToken.getUserId());
    authData.put(KEY_ACCESS_TOKEN, accessToken.getToken());
    authData.put(KEY_EXPIRATION_DATE, PRECISE_DATE_FORMAT.format(accessToken.getExpires()));
    authData.put(KEY_REFRESH_DATE, PRECISE_DATE_FORMAT.format(accessToken.getLastRefresh()));

    Set<String> permissionSet = accessToken.getPermissions();
    String valueToInsert = TextUtils.join(",", permissionSet);
    authData.put(KEY_PERMISSIONS, valueToInsert);

    return authData;
}

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

public static CursorLoader SearchTags(String query, String username, Context context) {
    final String[] projection = new String[] { Tag._ID, Tag.Name, Tag.Count };
    String selection = null;//from  www. ja v a  2 s .c  o  m

    final String sortorder = Tag.Name + " ASC";
    final ArrayList<String> selectionlist = new ArrayList<String>();

    ArrayList<String> queryList = new ArrayList<String>();

    for (String s : query.split(" ")) {
        queryList.add(Tag.Name + " LIKE ?");
        selectionlist.add("%" + s + "%");
    }

    selectionlist.add(username);

    if (query != null && query != "") {
        selection = "(" + TextUtils.join(" OR ", queryList) + ")" + " AND " + Tag.Account + "=?";
    } else {
        selection = Tag.Account + "=?";
    }

    return new CursorLoader(context, Tag.CONTENT_URI, projection, selection,
            selectionlist.toArray(new String[] {}), sortorder);
}