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

private static int decodeFileLength(String filePath) {
    if (TextUtils.isEmpty(filePath)) {
        return 0;
    }//w  w w .ja va  2  s .  co  m
    File file = new File(filePath);
    if (!file.exists()) {
        return 0;
    }
    return (int) file.length();
}

From source file:Main.java

public static int hex2color(String color) {
    if (TextUtils.isEmpty(color)) {
        color = "#ffffff";
    }//from  w  ww  .  j a v  a 2 s .  c  o  m

    int result;
    if (color.charAt(0) != '#') {
        color = "#" + color;
    }
    result = Color.parseColor(color);
    return result;
}

From source file:Main.java

public static String convertPackageName(String packageName) {
    if (TextUtils.isEmpty(packageName)) {
        return "";
    }//from ww  w.  j a  va 2s  .com
    int num = packageName.indexOf(PACKAGE_STR);
    if (num != -1) {
        return packageName.substring(PACKAGE_STR.length() + num, packageName.length());
    }
    return packageName;
}

From source file:Main.java

public static boolean isPhoneNumber(String phoneNumber) {
    if (!TextUtils.isEmpty(phoneNumber)) {
        String regex = "1([\\d]{10})|((\\+[0-9]{2,4})?\\(?[0-9]+\\)?-?)?[0-9]{7,8}";
        Pattern p = Pattern.compile(regex);
        Matcher matcher = p.matcher(phoneNumber);
        return matcher.find();
    } else {/*from   ww  w  . ja v  a2s  .  co  m*/
        return false;
    }
}

From source file:Main.java

public static int getCPUOnlineCores(String online_info) {
    if (TextUtils.isEmpty(online_info)) {
        return -1;
    }/*from ww w  .j  ava  2s  . c  om*/

    int result = 0;

    String[] nums;
    for (String temp_str : online_info.split(",")) {
        nums = temp_str.split("-");
        switch (nums.length) {
        case 1:
            ++result;
            break;
        case 2:
            result += (Integer.parseInt(nums[1]) - Integer.parseInt(nums[0])) + 1;
        }
    }

    return result;
}

From source file:Main.java

public static boolean hasChinese(String str) {
    if (TextUtils.isEmpty(str))
        return false;
    else {// w w  w. java  2s. c om
        String regEx = "[\u4e00-\u9fa5]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        if (m.find())
            return true;
        else
            return false;
    }
}

From source file:Main.java

public static String getFormatTime(String format, long time) {
    if (TextUtils.isEmpty(format))
        return null;

    SimpleDateFormat dateFormat = new SimpleDateFormat(format);
    Date date = new Date(time);
    return dateFormat.format(date);
}

From source file:Main.java

public static boolean isExistFile(String fileName) {
    if (TextUtils.isEmpty(fileName)) {
        return false;
    }//from  w  w  w.  jav a2s .c  o m

    File file = new File(fileName);
    if (file.exists() && file.isFile()) {
        return true;
    }

    return false;
}

From source file:Main.java

public static void setupTextView(TextView tv, CharSequence chars) {
    if (TextUtils.isEmpty(chars)) {
        tv.setVisibility(View.GONE);
    } else {/*from   w w  w.  j a va2 s . co m*/
        tv.setVisibility(View.VISIBLE);
        tv.setText(chars);
    }
}

From source file:Main.java

public static boolean isUserNameCorrect(String userName) {
    if (!TextUtils.isEmpty(userName)) {
        Pattern pattern = Pattern.compile("^[0-9a-zA-Z_]{6,20}$");
        Matcher matcher = pattern.matcher(userName);
        return matcher.find();
    }/*from  w w  w  .j a v a2  s . c  om*/
    return false;
}