Example usage for android.text TextUtils isEmpty

List of usage examples for android.text TextUtils isEmpty

Introduction

In this page you can find the example usage for android.text TextUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable CharSequence str) 

Source Link

Document

Returns true if the string is null or 0-length.

Usage

From source file:Main.java

public static boolean isEmail(String email) {
    if (TextUtils.isEmpty(email)) {
        return false;
    }//from w w w  .j  av  a  2s .c  om
    String reg = "^[0-9a-z_-][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}\\.){1,4}[a-z]{2,4}$";
    Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

From source file:Main.java

/**
 * Convert String into int ,return 0 if blank string or 
 * @str string to convert/*from   w  w  w  . j  av  a 2s  .  c o m*/
 * */
public static int getInt(String str) {
    if (TextUtils.isEmpty(str)) {
        return 0;
    } else {
        try {
            return Integer.valueOf(str);
        } catch (Exception e) {
        }
        return 0;
    }
}

From source file:Main.java

/**
 *
 * @param mobile//from  ww  w .j ava2  s .c o m
 * @return
 */
public static String formatMobileNumber(String mobile) {
    if (TextUtils.isEmpty(mobile)) {
        return "";
    }
    return mobile.replaceAll("[\\.\\-\\ ]", "").trim();
}

From source file:Main.java

public static String trimNewLine(String str) {
    if (TextUtils.isEmpty(str))
        return "";

    str = str.trim();/*from ww  w.  ja va 2s  .c  o m*/
    Pattern p = Pattern.compile("\t|\r|\n");
    Matcher m = p.matcher(str);
    String dest = m.replaceAll("");
    return dest;
}

From source file:Main.java

private static boolean isExistDataCache(Context context, String cacheFile) {
    if (context == null || TextUtils.isEmpty(cacheFile)) {
        return false;
    }/*from  w w w .  jav a2s.co m*/

    boolean exist = false;
    File data = context.getFileStreamPath(cacheFile);
    if (data.exists())
        exist = true;
    return exist;
}

From source file:Main.java

public static String getCountry() {
    Locale locale = Locale.getDefault();
    String countryCode = locale.getCountry();
    if (TextUtils.isEmpty(countryCode)) {
        countryCode = "";
    }//from  w  w w.  j  av a 2 s.c om
    return countryCode;
}

From source file:Main.java

public static String hideName(String string) {

    if (!TextUtils.isEmpty(string)) {
        int length = string.length();
        if (length > 1) {
            string = string.substring(0, 1);
            string = string + (length > 2 ? "**" : "*");
        }/*from  ww w  .  j av  a2 s .co  m*/
    }
    return string;
}

From source file:Main.java

public static <T> T jsonToObject(String json, Class<T> c) {
    T t = null;//w w  w .  j  a v  a  2 s.c o  m
    if (!TextUtils.isEmpty(json)) {
        try {
            t = new Gson().fromJson(json, c);
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
    }
    return t;
}

From source file:Main.java

public static String replaceAllBlank(String str) {
    if (TextUtils.isEmpty(str))
        return "";

    Pattern p = Pattern.compile("\\s*|\t|\r|\n");
    Matcher m = p.matcher(str);/* w w w  .j a  va 2s. c om*/
    String dest = m.replaceAll("");
    return dest;
}

From source file:Main.java

public static boolean isEmpty(final String... names) {
    if (names == null) {
        return true;
    }/*from w w w  .ja v  a2s. c om*/
    for (String name : names) {
        if (TextUtils.isEmpty(name)) {
            return true;
        }
    }
    return false;
}