Example usage for java.lang CharSequence toString

List of usage examples for java.lang CharSequence toString

Introduction

In this page you can find the example usage for java.lang CharSequence toString.

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:Main.java

/**
 * Returns true if the string is null or 0-length.
 * // ww w  .  ja v a 2s  .  c  o  m
 * @param str
 *            the string to be examined
 * @return true if str is null or zero length
 */
public static boolean isEmpty(CharSequence str) {
    if (str == null || str.length() == 0 || "null".equals(str.toString().trim()))
        return true;
    else
        return false;
}

From source file:Main.java

public static List<String> getRawBssidListByMacs(String macs, int macNum) {
    List<CharSequence> bssids = new ArrayList<CharSequence>();
    for (int i = 0; i < macNum; i++) {
        StringBuilder sb = new StringBuilder();
        bssids.add(sb);/*w  ww . j a v  a  2 s .c  om*/
    }
    int offset = macs.length() / macNum;
    for (int i = 0; i < macs.length(); i++) {
        char c = macs.charAt(i);
        StringBuilder sb = (StringBuilder) bssids.get(i / offset);
        sb.append(c);
    }

    List<String> result = new ArrayList<String>();
    for (CharSequence cs : bssids) {
        result.add(getRawMacAddress(cs.toString()));
    }

    return result;
}

From source file:Main.java

private static String getPermissionLabel(Context context, String permission, String defValue) {
    try {/*from  w  w  w . ja va  2 s  .  com*/
        final PackageManager pm = context.getPackageManager();
        final PermissionInfo pi = pm.getPermissionInfo(permission, 0);

        final CharSequence label = pi.loadLabel(pm);
        if (label != null && !label.toString().equals(permission))
            return label.toString();
    } catch (NameNotFoundException e) {
        // om nom nom
    }

    return defValue;
}

From source file:Main.java

public static String pickFirstNotNull(CharSequence... options) {
    if (isEmpty(options)) {
        return null;
    }/*from  w  w  w.j  a v a2s .  c  o  m*/
    String result = null;
    for (CharSequence cs : options) {
        if (null != cs) {
            result = cs.toString();
            break;
        }
    }
    return result;
}

From source file:Main.java

/** Strips all rich text except spans used to provide compositional hints. */
public static CharSequence stripRichText(CharSequence str, int start, int end) {
    String plainText = str.toString();
    SpannableString ret = new SpannableString(plainText);
    if (str instanceof Spanned) {
        List<Object> keyboardHintSpans = getComposingSpans((Spanned) str, start, end);
        copySpans((Spanned) str, ret, keyboardHintSpans);
    }// w  w  w.j a va  2s. co  m
    return ret;
}

From source file:Main.java

/**
 * Used by the indexOf(CharSequence methods) as a green implementation of indexOf.
 *
 * @param cs the {@code CharSequence} to be processed
 * @param searchChar the {@code CharSequence} to be searched for
 * @param start the start index//from  w w w.  j  ava 2 s  .c  o  m
 * @return the index where the search sequence was found
 */
static int indexOf(CharSequence cs, CharSequence searchChar, int start) {
    return cs.toString().indexOf(searchChar.toString(), start);
    //        if (cs instanceof String && searchChar instanceof String) {
    //            // TODO: Do we assume searchChar is usually relatively small;
    //            //       If so then calling toString() on it is better than reverting to
    //            //       the green implementation in the else block
    //            return ((String) cs).indexOf((String) searchChar, start);
    //        } else {
    //            // TODO: Implement rather than convert to String
    //            return cs.toString().indexOf(searchChar.toString(), start);
    //        }
}

From source file:Main.java

/**
 * @param str/*w ww.j a va  2  s.  c om*/
 * @return
 */
private static CharSequence replaceLinebreak(CharSequence str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }

    if (str.toString().contains("\n")) {
        return str.toString().replace("\n", " ");
    }

    return str;
}

From source file:Main.java

/**
 * Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf
 *
 * @param cs the {@code CharSequence} to be processed
 * @param searchChar the {@code CharSequence} to be searched for
 * @param start the start index// w w w .  j a  v  a  2 s .c o  m
 * @return the index where the search sequence was found
 */
static int lastIndexOf(CharSequence cs, CharSequence searchChar, int start) {
    return cs.toString().lastIndexOf(searchChar.toString(), start);
    //        if (cs instanceof String && searchChar instanceof String) {
    //            // TODO: Do we assume searchChar is usually relatively small;
    //            //       If so then calling toString() on it is better than reverting to
    //            //       the green implementation in the else block
    //            return ((String) cs).lastIndexOf((String) searchChar, start);
    //        } else {
    //            // TODO: Implement rather than convert to String
    //            return cs.toString().lastIndexOf(searchChar.toString(), start);
    //        }
}

From source file:Main.java

public static String getTextOmit(TextPaint paint, String str, int width) {
    String des = null;//from  w  w  w. java2 s .  c  om
    CharSequence sequence = TextUtils.ellipsize(str, paint, width, TruncateAt.END);
    if (sequence != null) {
        des = sequence.toString();
    }
    return des;
}

From source file:Main.java

public static void toast(Context context, CharSequence message, Object... args) {
    if (message != null) {
        String messageString = message.toString();
        if (args != null) {
            messageString = String.format(messageString, args);
        }/*w  w w .j  a v  a  2s.c om*/
        Toast.makeText(context, messageString, Toast.LENGTH_LONG).show();
    }
}