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.openerp.orm.ORM.java

/**
 * Execute sql query as per user requirement.
 * /*from  w  w w.  j  ava 2  s  .c  o m*/
 * @param model
 *            the model
 * @param columns
 *            the columns
 * @param where
 *            the where
 * @param args
 *            the args query arguments
 * @return the cursor of results
 */
public List<HashMap<String, Object>> executeSQL(String model, String[] columns, String[] where, String[] args) {
    SQLiteDatabase db = getWritableDatabase();
    StringBuffer sqlQuery = new StringBuffer();
    sqlQuery.append("SELECT ");
    sqlQuery.append(TextUtils.join(",", columns));
    sqlQuery.append(" FROM ");
    sqlQuery.append(modelToTable(model));
    sqlQuery.append(" WHERE ");
    sqlQuery.append(TextUtils.join(" ", where));

    List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();

    Cursor cursor = db.rawQuery(sqlQuery.toString(), args);
    if (cursor.moveToFirst()) {
        do {
            HashMap<String, Object> row = new HashMap<String, Object>();
            for (String key : columns) {
                row.put(key, cursor.getString(cursor.getColumnIndex(key)));
            }
            data.add(row);
        } while (cursor.moveToNext());
    }
    db.close();
    cursor.close();
    return data;

}

From source file:li.barter.http.HttpResponseParser.java

/**
 * Reads the book details from the Book response json into a content values
 * object/*  w w  w. ja va2 s .  c  om*/
 *
 * @param bookObject     The Json representation of a book search result
 * @param values         The values instance to read into
 * @param clearBeforeAdd Whether the values should be emptied before adding
 * @param autoNotify     <code>true</code> to automatically notify any connected
 *                       loaders
 * @return The book Id that was parsed
 * @throws JSONException If the Json is invalid
 */
private String readBookDetailsIntoContentValues(final JSONObject bookObject, final ContentValues values,
        final boolean clearBeforeAdd, final boolean autoNotify) throws JSONException {

    if (clearBeforeAdd) {
        values.clear();
    }

    final String bookId = JsonUtils.readString(bookObject, HttpConstants.ID_BOOK, false, false);

    final int id = JsonUtils.readInt(bookObject, HttpConstants.ID, true, true);
    Logger.d(TAG, "ID : " + id);
    values.put(DatabaseColumns.ID, id + "");
    values.put(DatabaseColumns.ISBN_10, JsonUtils.readString(bookObject, HttpConstants.ISBN_10, false, false));
    values.put(DatabaseColumns.ISBN_13, JsonUtils.readString(bookObject, HttpConstants.ISBN_13, false, false));
    values.put(DatabaseColumns.AUTHOR, JsonUtils.readString(bookObject, HttpConstants.AUTHOR, false, false));
    values.put(DatabaseColumns.USER_ID, JsonUtils.readString(bookObject, HttpConstants.ID_USER, false, false));
    values.put(DatabaseColumns.TITLE, JsonUtils.readString(bookObject, HttpConstants.TITLE, false, false));
    values.put(DatabaseColumns.DESCRIPTION,
            JsonUtils.readString(bookObject, HttpConstants.DESCRIPTION, false, false));

    final String imagePresent = JsonUtils.readString(bookObject, HttpConstants.IMAGE_PRESENT, false, false);
    if (imagePresent != null && imagePresent.equals("false")) {
        values.put(DatabaseColumns.IMAGE_URL,
                JsonUtils.readString(bookObject, HttpConstants.IMAGE_PRESENT, false, false));
    } else {
        values.put(DatabaseColumns.IMAGE_URL,
                JsonUtils.readString(bookObject, HttpConstants.IMAGE_URL, false, false));
    }
    values.put(DatabaseColumns.PUBLICATION_YEAR,
            JsonUtils.readString(bookObject, HttpConstants.PUBLICATION_YEAR, false, false));
    values.put(DatabaseColumns.PUBLICATION_MONTH,
            JsonUtils.readString(bookObject, HttpConstants.PUBLICATION_MONTH, false, false));
    values.put(DatabaseColumns.VALUE, JsonUtils.readString(bookObject, HttpConstants.VALUE, false, false));
    values.put(DatabaseColumns.BOOK_OWNER,
            JsonUtils.readString(bookObject, HttpConstants.OWNER_NAME, false, false));
    values.put(DatabaseColumns.BOOK_OWNER_IMAGE_URL,
            JsonUtils.readString(bookObject, HttpConstants.OWNER_IMAGE_URL, false, false));

    final JSONObject locationObject = JsonUtils.readJSONObject(bookObject, HttpConstants.LOCATION, false,
            false);

    if (locationObject != null) {
        values.put(DatabaseColumns.LOCATION_ID, parseAndStoreLocation(locationObject, autoNotify));
    }

    final JSONArray tagsArray = JsonUtils.readJSONArray(bookObject, HttpConstants.TAGS, true, true);

    if (tagsArray.length() > 0) {
        final String[] tags = new String[tagsArray.length()];

        for (int i = 0; i < tagsArray.length(); i++) {
            tags[i] = JsonUtils.readString(tagsArray, i, true, true);
        }

        values.put(DatabaseColumns.BARTER_TYPE, TextUtils.join(AppConstants.BARTER_TYPE_SEPARATOR, tags));
    }
    return id + "";
}

From source file:com.facebook.share.internal.ShareInternalUtility.java

/**
 * Creates a new Request configured to post a status update to a user's feed.
 *
 * @param accessToken the access token to use, or null
 * @param message     the text of the status update
 * @param placeId     an optional place id to associate with the post
 * @param tagIds      an optional list of user ids to tag in the post
 * @param callback    a callback that will be called when the request is completed to handle
 *                    success or error conditions
 * @return a Request that is ready to execute
 *///from   www . java2 s.  com
private static GraphRequest newStatusUpdateRequest(AccessToken accessToken, String message, String placeId,
        List<String> tagIds, Callback callback) {

    Bundle parameters = new Bundle();
    parameters.putString("message", message);

    if (placeId != null) {
        parameters.putString("place", placeId);
    }

    if (tagIds != null && tagIds.size() > 0) {
        String tags = TextUtils.join(",", tagIds);
        parameters.putString("tags", tags);
    }

    return new GraphRequest(accessToken, MY_FEED, parameters, HttpMethod.POST, callback);
}

From source file:illab.nabal.proxy.FacebookProxy.java

@Override
public void postLink(final Operation<FacebookDelegate, FacebookPost> operation, final String message,
        final String picture, final String link, final String name, final String caption,
        final String description, final String source, final String placeId, final String[] tags,
        final Locale locale) {
    requestJob(new ProxyJob() {
        public void onFail(Exception e) {
            operation.onFail(e);// w ww. j a va  2  s . co m
        }

        public void run() {
            try {
                // check link URL
                if (StringHelper.isEmpty(link) == true) {
                    throw new SystemException("Invalid link URL.");
                }
                // generate tag CSV 
                String tagString = null;
                if (tags != null && tags.length > 0) {
                    tagString = TextUtils.join(",", tags);
                }
                operation.onResult(publishPost(ME, message, picture, link, name, caption, description, source,
                        placeId, tagString, locale));
            } catch (Exception e) {
                onFail(e);
            }
        }
    });
}

From source file:illab.nabal.proxy.FacebookProxy.java

@Override
public void postStatus(final Operation<FacebookDelegate, FacebookPost> operation, final String ownerIdentifier,
        final String message, final String placeId, final String[] tags, final Locale locale) {
    requestJob(new ProxyJob() {
        public void onFail(Exception e) {
            operation.onFail(e);//ww w  .j  a  v  a 2  s  .c o m
        }

        public void run() {
            try {
                // check message
                if (StringHelper.isEmpty(message) == true) {
                    throw new SystemException("Invalid message.");
                }
                // generate tag CSV 
                String tagString = null;
                if (tags != null && tags.length > 0) {
                    tagString = TextUtils.join(",", tags);
                }
                operation.onResult(publishPost(ownerIdentifier, message, null, null, null, null, null, null,
                        placeId, tagString, locale));
            } catch (Exception e) {
                onFail(e);
            }
        }
    });
}

From source file:illab.nabal.proxy.FacebookProxy.java

@Override
public void postLink(final Operation<FacebookDelegate, FacebookPost> operation, final String ownerIdentifier,
        final String message, final String picture, final String link, final String name, final String caption,
        final String description, final String source, final String placeId, final String[] tags,
        final Locale locale) {
    requestJob(new ProxyJob() {
        public void onFail(Exception e) {
            operation.onFail(e);//from  ww w. j a v a2s. c o m
        }

        public void run() {
            try {
                // check link URL
                if (StringHelper.isEmpty(link) == true) {
                    throw new SystemException("Invalid link URL.");
                }
                // generate tag CSV 
                String tagString = null;
                if (tags != null && tags.length > 0) {
                    tagString = TextUtils.join(",", tags);
                }
                operation.onResult(publishPost(ownerIdentifier, message, picture, link, name, caption,
                        description, source, placeId, tagString, locale));
            } catch (Exception e) {
                onFail(e);
            }
        }
    });
}

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

public static List<InetAddress> getDns(Context context) {
    List<InetAddress> listDns = new ArrayList<>();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    List<String> sysDns = Util.getDefaultDNS(context);
    String vpnDns = prefs.getString("dns", null);
    Log.i(TAG, "DNS system=" + TextUtils.join(",", sysDns) + " VPN=" + vpnDns);

    if (vpnDns != null)
        try {/*from  w w  w .ja v  a  2 s .c o m*/
            InetAddress dns = InetAddress.getByName(vpnDns);
            if (!(dns.isLoopbackAddress() || dns.isAnyLocalAddress()))
                listDns.add(dns);
        } catch (Throwable ignored) {
        }

    for (String def_dns : sysDns)
        try {
            InetAddress ddns = InetAddress.getByName(def_dns);
            if (!listDns.contains(ddns) && !(ddns.isLoopbackAddress() || ddns.isAnyLocalAddress()))
                listDns.add(ddns);
        } catch (Throwable ignored) {
        }

    return listDns;
}

From source file:com.annanovas.bestprice.DashBoardEditActivity.java

private void generateProductRecyclerView() {
    myDB.open();/* ww w  . j av a2s . c om*/
    productsObjectArrayList = myDB.getAllProducts();
    productsObjectArrayListForSearch.addAll(productsObjectArrayList);

    if (selectedProductIdList.size() != 0) {
        for (int i = 0; i < selectedProductIdList.size(); i++) {
            selectedProductList.add(myDB.getProductName(Integer.parseInt(selectedProductIdList.get(i))));
        }
        tvSelectedProduct.setText(TextUtils.join(", ", selectedProductList));
        for (int i = 0; i < productsObjectArrayListForSearch.size(); i++) {
            String cellId = String.valueOf(productsObjectArrayListForSearch.get(i).getId());
            if (selectedProductIdList.contains(cellId)) {
                ProductsObject loop = productsObjectArrayListForSearch.get(i);
                loop.setIsChecked(true);
                productsObjectArrayListForSearch.set(i, loop);
            }
        }
        generateBrandRecyclerView();
    }

    productAdapter = new ProductAdapter(DashBoardEditActivity.this, productsObjectArrayListForSearch);
    LinearLayoutManager linearLayoutManager4 = new LinearLayoutManager(DashBoardEditActivity.this);
    productRecyclerView.setLayoutManager(linearLayoutManager4);
    productRecyclerView.setItemAnimator(new DefaultItemAnimator());
    productRecyclerView.setAdapter(productAdapter);
    productRecyclerView.setNestedScrollingEnabled(false);
    myDB.close();

    productRecyclerView.addOnItemTouchListener(new ProductAdapter.RecyclerTouchListener(getApplicationContext(),
            productRecyclerView, new ProductAdapter.ClickListener() {
                @Override

                public void onClick(View view, int position) {
                    ProductsObject productsObject = productsObjectArrayListForSearch.get(position);
                    String cellId = String.valueOf(productsObject.getId());
                    if (selectedProductIdList.contains(cellId)) {
                        selectedProductIdList.remove(cellId);
                        selectedProductList.remove(productsObject.getName());
                        productsObject.setIsChecked(false);
                    } else {
                        int totalId = selectedProductIdList.size();
                        selectedProductIdList.add(totalId, cellId);
                        selectedProductList.add(totalId, productsObject.getName());
                        productsObject.setIsChecked(true);
                    }
                    productsObjectArrayListForSearch.set(position, productsObject);
                    productAdapter.notifyItemChanged(position);
                    tvSelectedProduct.setText(TextUtils.join(", ", selectedProductList));

                    chosenBrandIdList.clear();
                    chosenBrandList.clear();
                    tvDealerShipWith.setText("");
                    generateBrandRecyclerView();
                }

                @Override
                public void onLongClick(View view, int position) {

                }
            }));

    etProductSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String newText = s.toString();
            ArrayList<ProductsObject> newList4 = new ArrayList<>();
            for (ProductsObject productsObjectItem : productsObjectArrayList) {
                String name = productsObjectItem.getName().toLowerCase();
                if (name.contains(newText)) {
                    newList4.add(productsObjectItem);
                }
            }
            productsObjectArrayListForSearch.clear();
            productsObjectArrayListForSearch.addAll(newList4);
            productAdapter.notifyDataSetChanged();
            //productAdapter.setFilter(newList4);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
}

From source file:illab.nabal.proxy.TwitterProxy.java

/**
 * Get a Twitter profile corresponding to given user UID.
 * //from   w  w w .  j a  va  2s.  c o m
 * @param userUids
 * @return list of TwitterProfile objects
 * @throws Exception
 */
private List<TwitterProfile> getProfilesByUid(String[] userUids) throws Exception {

    String apiUri = "/users/lookup.json";

    // throw an exception if user UID is invalid
    if (userUids == null || userUids.length == 0) {
        throw new SystemException("No user UID is specified.");
    }

    // check paramter length
    else if (userUids.length > 100) {
        throw new SystemException("user UIDs should be no more than 100.");
    }

    String commaSeparatedUserUids = TextUtils.join(",", userUids);

    return populateProfileList(getJsonArray(
            getResponseString(getHttpPost(apiUri, new BasicNameValuePair("user_id", commaSeparatedUserUids),
                    new BasicNameValuePair("include_entities", "true")))));
}

From source file:android_network.hetnet.vpn_service.ServiceSinkhole.java

public static List<InetAddress> getDns(Context context) {
    List<InetAddress> listDns = new ArrayList<>();
    List<String> sysDns = Util.getDefaultDNS(context);

    // Get custom DNS servers
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String vpnDns1 = prefs.getString("dns", null);
    String vpnDns2 = prefs.getString("dns2", null);
    Log.i(TAG, "DNS system=" + TextUtils.join(",", sysDns) + " VPN1=" + vpnDns1 + " VPN2=" + vpnDns2);

    if (vpnDns1 != null)
        try {/*from  w w  w .  j a va  2  s  .co m*/
            InetAddress dns = InetAddress.getByName(vpnDns1);
            if (!(dns.isLoopbackAddress() || dns.isAnyLocalAddress()))
                listDns.add(dns);
        } catch (Throwable ignored) {
        }

    if (vpnDns2 != null)
        try {
            InetAddress dns = InetAddress.getByName(vpnDns2);
            if (!(dns.isLoopbackAddress() || dns.isAnyLocalAddress()))
                listDns.add(dns);
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }

    // Use system DNS servers only when no two custom DNS servers specified
    if (listDns.size() <= 1)
        for (String def_dns : sysDns)
            try {
                InetAddress ddns = InetAddress.getByName(def_dns);
                if (!listDns.contains(ddns) && !(ddns.isLoopbackAddress() || ddns.isAnyLocalAddress()))
                    listDns.add(ddns);
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            }

    // Remove local DNS servers when not routing LAN
    boolean lan = prefs.getBoolean("lan", false);
    if (lan) {
        List<InetAddress> listLocal = new ArrayList<>();
        try {
            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
            if (nis != null)
                while (nis.hasMoreElements()) {
                    NetworkInterface ni = nis.nextElement();
                    if (ni != null && ni.isUp() && !ni.isLoopback()) {
                        List<InterfaceAddress> ias = ni.getInterfaceAddresses();
                        if (ias != null)
                            for (InterfaceAddress ia : ias) {
                                InetAddress hostAddress = ia.getAddress();
                                BigInteger host = new BigInteger(1, hostAddress.getAddress());

                                int prefix = ia.getNetworkPrefixLength();
                                BigInteger mask = BigInteger.valueOf(-1)
                                        .shiftLeft(hostAddress.getAddress().length * 8 - prefix);

                                for (InetAddress dns : listDns)
                                    if (hostAddress.getAddress().length == dns.getAddress().length) {
                                        BigInteger ip = new BigInteger(1, dns.getAddress());

                                        if (host.and(mask).equals(ip.and(mask))) {
                                            Log.i(TAG, "Local DNS server host=" + hostAddress + "/" + prefix
                                                    + " dns=" + dns);
                                            listLocal.add(dns);
                                        }
                                    }
                            }
                    }
                }
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }

        List<InetAddress> listDns4 = new ArrayList<>();
        List<InetAddress> listDns6 = new ArrayList<>();
        try {
            listDns4.add(InetAddress.getByName("8.8.8.8"));
            listDns4.add(InetAddress.getByName("8.8.4.4"));
            listDns6.add(InetAddress.getByName("2001:4860:4860::8888"));
            listDns6.add(InetAddress.getByName("2001:4860:4860::8844"));

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

        for (InetAddress dns : listLocal) {
            listDns.remove(dns);
            if (dns instanceof Inet4Address) {
                if (listDns4.size() > 0) {
                    listDns.add(listDns4.get(0));
                    listDns4.remove(0);
                }
            } else {
                if (listDns6.size() > 0) {
                    listDns.add(listDns6.get(0));
                    listDns6.remove(0);
                }
            }
        }
    }

    // Prefer IPv4 addresses
    Collections.sort(listDns, new Comparator<InetAddress>() {
        @Override
        public int compare(InetAddress a, InetAddress b) {
            boolean a4 = (a instanceof Inet4Address);
            boolean b4 = (b instanceof Inet4Address);
            if (a4 && !b4)
                return -1;
            else if (!a4 && b4)
                return 1;
            else
                return 0;
        }
    });

    return listDns;
}