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.anysoftkeyboard.quicktextkeys.QuickTextKeyFactory.java

public static List<QuickTextKey> getOrderedEnabledQuickKeys(Context applicationContext) {
    List<QuickTextKey> quickTextKeys = new ArrayList<>(getAllAvailableQuickKeys(applicationContext));

    //now, reading the ordered array of active keys
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext);
    String settingKey = applicationContext.getString(R.string.settings_key_ordered_active_quick_text_keys);

    List<String> quickKeyIdDefaultOrder = new ArrayList<>(quickTextKeys.size());
    for (QuickTextKey key : quickTextKeys) {
        quickKeyIdDefaultOrder.add(key.getId());
    }//from   ww w .jav  a2s .co  m
    String quickKeyIdsOrderValue = sharedPreferences.getString(settingKey,
            TextUtils.join(",", quickKeyIdDefaultOrder));
    String[] quickKeyIdsOrder = TextUtils.split(quickKeyIdsOrderValue, ",");

    ArrayList<QuickTextKey> orderedQuickTextKeys = new ArrayList<>(quickKeyIdsOrder.length);
    for (String keyId : quickKeyIdsOrder) {
        QuickTextKey addOn = msInstance.getAddOnById(keyId, applicationContext);
        if (addOn != null)
            orderedQuickTextKeys.add(addOn);
    }

    //forcing at least one key
    if (orderedQuickTextKeys.size() == 0)
        orderedQuickTextKeys.add(quickTextKeys.get(0));

    return orderedQuickTextKeys;
}

From source file:com.scv.slackgo.services.GeofenceTransitionsIntentService.java

private static String getGeofenceTransitionDetails(GeofencingEvent event) {
    String transitionString = GeofenceStatusCodes.getStatusCodeString(event.getGeofenceTransition());
    List triggeringIDs = new ArrayList();
    for (Geofence geofence : event.getTriggeringGeofences()) {
        triggeringIDs.add(geofence.getRequestId());
    }//from  w w w . ja v  a 2  s .c  om
    return String.format("%s: %s", transitionString, TextUtils.join(", ", triggeringIDs));
}

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

public static void TruncateOldBundles(ArrayList<String> accounts, Context context) {

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

    for (String s : accounts) {
        selectionList.add(Bundle.Account + " <> '" + s + "'");
    }//w  ww .  j  a v  a  2  s  . c o m

    String selection = TextUtils.join(" AND ", selectionList);

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

From source file:com.aoeng.degu.utils.net.asyncthhpclient.PersistentCookieStore.java

public void addCookie(Cookie cookie) {
    String name = cookie.getName() + cookie.getDomain();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
        cookies.put(name, cookie);//from  w  w  w. j a  v  a  2  s .c  om
    } else {
        cookies.remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();
}

From source file:net.iamyellow.tiws.WSProxy.java

@Kroll.method
public void open(Object[] args) {
    final KrollProxy self = this;

    if (args.length == 0) {
        throw new IllegalArgumentException("URI argument expected");
    }/* w ww.  ja  v a2 s .co  m*/

    Object uri = args[0];
    if (!(uri instanceof String)) {
        throw new IllegalArgumentException("URI argument must be a string");
    }
    String wsUri = (String) uri;
    List<BasicNameValuePair> extraHeaders = new ArrayList<BasicNameValuePair>();
    if (args.length > 1) {
        Object proto = args[1];
        if (!(proto instanceof Object[])) {
            throw new IllegalArgumentException("protocols argument must be an array of strings");
        }
        Object[] protocols = (Object[]) proto;
        for (int i = 0; i < protocols.length; i++) {
            if (!(protocols[i] instanceof String)) {
                throw new IllegalArgumentException("protocol at index " + i + " is not a string");
            }
        }
        BasicNameValuePair protocolHeader = new BasicNameValuePair("Sec-WebSocket-Protocol",
                TextUtils.join(", ", protocols));
        extraHeaders.add(protocolHeader);
    }
    try {
        if (TiwsModule.DBG) {
            Log.d(TiwsModule.LCAT, "* creating websocket");
        }

        URI wsURI = new URI(wsUri);
        Log.d(TiwsModule.LCAT, "* URI: " + wsURI);
        client = new WebSocketClient(wsURI, new WebSocketClient.Listener() {
            @Override
            public void onMessage(byte[] data) {
                if (client == null) {
                    return;
                }

                KrollDict event = new KrollDict();
                event.put("data", TiBlob.blobFromData(data));
                self.fireEvent("message", event);
            }

            @Override
            public void onMessage(String message) {
                if (client == null) {
                    return;
                }

                KrollDict event = new KrollDict();
                event.put("data", message);
                self.fireEvent("message", event);
            }

            @Override
            public void onError(Exception error) {
                if (client == null) {
                    return;
                }

                if (TiwsModule.DBG) {
                    Log.d(TiwsModule.LCAT, "* websocket error", error);
                }

                KrollDict event = new KrollDict();
                event.put("advice", "reconnect");
                event.put("error", error.toString());
                self.fireEvent("error", event);

                cleanup();
            }

            @Override
            public void onDisconnect(int code, String reason) {
                if (client == null) {
                    return;
                }

                if (TiwsModule.DBG) {
                    Log.d(TiwsModule.LCAT,
                            "* creating disconnected; reason = " + reason + "; code = " + String.valueOf(code));
                }
                KrollDict event = new KrollDict();
                event.put("code", code);
                event.put("reason", reason);
                self.fireEvent("close", event);

                cleanup();
            }

            @Override
            public void onConnect() {
                connected = true;

                KrollDict event = new KrollDict();
                self.fireEvent("open", event);
            }
        }, extraHeaders);

        client.connect();
    } catch (URISyntaxException ex) {
        if (TiwsModule.DBG) {
            Log.d(TiwsModule.LCAT, "* creating exception", ex);
        }
        cleanup();
    }
}

From source file:net.mceoin.cominghome.ReceiveTransitionsIntentService.java

/**
 * Handles incoming intents/*from   w ww .  j  a va2 s  . c o  m*/
 *
 * @param intent The Intent sent by Location Services. This Intent is provided
 *               to Location Services (inside a PendingIntent) when you call addGeofences()
 */
@Override
protected void onHandleIntent(Intent intent) {

    // Create a local broadcast Intent
    Intent broadcastIntent = new Intent();

    // Give it the category for all intents sent by the Intent Service
    broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES);

    // First check for errors
    if (LocationClient.hasError(intent)) {

        // Get the error code
        int errorCode = LocationClient.getErrorCode(intent);

        // Get the error message
        String errorMessage = LocationServiceErrorMessages.getErrorString(this, errorCode);

        // Log the error
        Log.e(TAG, getString(R.string.geofence_transition_error_detail, errorMessage));

        // Set the action and error message for the broadcast intent
        broadcastIntent.setAction(GeofenceUtils.ACTION_GEOFENCE_ERROR)
                .putExtra(GeofenceUtils.EXTRA_GEOFENCE_STATUS, errorMessage);

        // Broadcast the error *locally* to other components in this app
        LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);

        // If there's no error, get the transition type and create a notification
    } else {

        // Get the type of transition (entry or exit)
        int transition = LocationClient.getGeofenceTransition(intent);

        // Test that a valid transition was reported
        if ((transition == Geofence.GEOFENCE_TRANSITION_ENTER)
                || (transition == Geofence.GEOFENCE_TRANSITION_EXIT)) {

            // Post a notification
            List<Geofence> geofences = LocationClient.getTriggeringGeofences(intent);
            String[] geofenceIds = new String[geofences.size()];
            for (int index = 0; index < geofences.size(); index++) {
                geofenceIds[index] = geofences.get(index).getRequestId();
            }
            String ids = TextUtils.join(GeofenceUtils.GEOFENCE_ID_DELIMITER, geofenceIds);
            String transitionType = getTransitionString(transition);

            //                sendNotification(transitionType, ids);

            // Log the transition type and a message
            Log.d(TAG, getString(R.string.geofence_transition_notification_title, transitionType, ids));

            FenceHandling.process(transition, geofences, getApplicationContext());
            // An invalid transition was reported
        } else {
            // Always log as an error
            Log.e(TAG, getString(R.string.geofence_transition_invalid_type, transition));
        }
    }
}

From source file:org.totschnig.myexpenses.dialog.VersionDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle bundle = getArguments();/*  w  ww  .  j  a v a  2  s.  c  om*/
    Activity ctx = (Activity) getActivity();
    LayoutInflater li = LayoutInflater.from(ctx);
    int from = bundle.getInt("from");
    Resources res = getResources();
    int[] versionCodes = res.getIntArray(R.array.version_codes);
    String[] versionNames = res.getStringArray(R.array.version_names);
    final ArrayList<VersionInfo> versions = new ArrayList<VersionInfo>();
    for (int i = 0; i < versionCodes.length; i++) {
        int code = versionCodes[i];
        if (from >= code)
            break;
        int resId = res.getIdentifier("whats_new_" + code, "array", ctx.getPackageName());
        if (resId == 0) {
            Log.e(MyApplication.TAG, "missing change log entry for version " + code);
        } else {
            String changes[] = res
                    .getStringArray(res.getIdentifier("whats_new_" + code, "array", ctx.getPackageName()));
            versions.add(new VersionInfo(code, versionNames[i], changes));
        }
    }
    View view = li.inflate(R.layout.versiondialog, null);
    final ListView lv = (ListView) view.findViewById(R.id.list);
    ArrayAdapter<VersionInfo> adapter = new ArrayAdapter<VersionInfo>(ctx, R.layout.version_row,
            R.id.versionInfoName, versions) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LinearLayout row = (LinearLayout) super.getView(position, convertView, parent);
            VersionInfo version = versions.get(position);
            ((TextView) row.findViewById(R.id.versionInfoName)).setText(version.name);
            ((TextView) row.findViewById(R.id.versionInfoChanges))
                    .setText("- " + TextUtils.join("\n- ", version.changes));
            return row;
        }
    };
    lv.setAdapter(adapter);
    if (MyApplication.getInstance().showImportantUpgradeInfo) {
        view.findViewById(R.id.ImportantUpgradeInfoHeading).setVisibility(View.VISIBLE);
        view.findViewById(R.id.ImportantUpgradeInfoBody).setVisibility(View.VISIBLE);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(ctx)
            .setTitle(getString(R.string.help_heading_whats_new)).setIcon(R.drawable.icon).setView(view)
            .setNegativeButton(android.R.string.ok, this);
    if (!MyApplication.getInstance().isContribEnabled)
        builder.setPositiveButton(R.string.menu_contrib, this);
    return builder.create();
}

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

@Override
public List<Post> fetchPosts(Host host, int startFrom, String[] tags) throws SiteAPIException {
    HttpURLConnection connection = null;
    try {/*from   w ww .jav  a 2s  .  c  o  m*/
        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());

        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:gr.ellak.ma.emergencyroad.PersistentCookieStore.java

@Override
public void addCookie(Cookie cookie) {
    if (omitNonPersistentCookies && !cookie.isPersistent())
        return;//w  w w .  ja  v a 2 s.  c  o m
    String name = cookie.getName() + cookie.getDomain();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
        cookies.put(name, cookie);
    } else {
        cookies.remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.apply();
}

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

@Override
public void initContentAfterDataLoaded(ViewGroup container) {
    editView.setTokenizer(tokenizer);/*from   w w w . j a  va2s .co m*/
    editView.setText(TextUtils.join(", ", chosenTags));
    editView.requestFocus();
}