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;

    String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";

    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(email);

    return matcher.matches();

}

From source file:Main.java

public static String getDeviceId(TelephonyManager tm) {
    String id = tm.getSubscriberId();
    if (TextUtils.isEmpty(id)) {
        id = tm.getDeviceId();//from   w w  w.j  a  v a2 s .c om
    }
    if (TextUtils.isEmpty(id)) {
        id = UUID.randomUUID().toString();
    }
    return id;
}

From source file:Main.java

static void assertUriSafe(@Nullable Uri uri) {
    if (uri == null || TextUtils.isEmpty(uri.getScheme()) || TextUtils.isEmpty(uri.getHost())) {
        throw new RuntimeException("Unsafe uri provided");
    }//from   w w w  . j  a  v a 2  s. c  o  m
}

From source file:Main.java

public static boolean checkPhoneNumber(String phoneNumber) {
    if (TextUtils.isEmpty(phoneNumber)) {
        return false;
    }//ww w.  j a  v a 2  s.c  o  m
    String reg = "^[0-9]{11}$";
    Pattern pattern = Pattern.compile(reg);
    Matcher matcher = pattern.matcher(phoneNumber);
    return matcher.matches();
}

From source file:Main.java

public static Object jsonToBean(String jsonStr, Class<?> cl) {
    Object obj = null;/*from  w ww.j  ava 2  s  .com*/
    if (gson != null && !TextUtils.isEmpty(jsonStr)) {
        obj = gson.fromJson(jsonStr, cl);
    }
    return obj;
}

From source file:Main.java

public static double getAmount(String amountStr) {
    if (TextUtils.isEmpty(amountStr))
        return 0;
    else {/*from w  ww .j  a va 2 s. co m*/
        if (amountStr.startsWith("+"))
            amountStr = amountStr.substring(1);
        try {
            return NumberFormat.getInstance().parse(amountStr).doubleValue();
        } catch (ParseException e) {
            return 0;
        }
    }
}

From source file:Main.java

public static int isValidate(String... fields) {
    if (fields == null) {
        return 0;
    }/*  ww w. j  a va  2  s.c  o m*/

    for (int i = 0; i < fields.length; i++) {
        if (TextUtils.isEmpty(fields[i])) {
            return i;
        }

    }
    return -1;
}

From source file:Main.java

public static boolean checkUserPassword(String password) {
    if (TextUtils.isEmpty(password) || password.length() < USER_PASSWORD_LEN_MIN
            || password.length() > USER_PASSWORD_LEN_MAX) {
        return false;
    }//from   w w w .j  a v  a2  s  .c  o m

    return true;
}

From source file:Main.java

public static String getTopicUrl(String topicId, String urlArgs) {
    return "http://4pda.ru/forum/index.php?showtopic=" + topicId
            + (TextUtils.isEmpty(urlArgs) ? "" : ("&" + urlArgs));
}

From source file:Main.java

public static String byte2Common(Context context, String fsize) {
    if (TextUtils.isEmpty(fsize)) {
        return "";
    }/*from w  w w .j  a v a2s .c  om*/
    Long sizeLong = Long.parseLong(fsize);
    return Formatter.formatFileSize(context, sizeLong);
}