List of usage examples for android.text TextUtils isEmpty
public static boolean isEmpty(@Nullable CharSequence str)
From source file:Main.java
private static boolean hasAction(String actionText, View.OnClickListener onClickListener) { return !TextUtils.isEmpty(actionText) && onClickListener != null; }
From source file:Main.java
public static boolean isValidEmail(String s) { if (TextUtils.isEmpty(s)) { return false; }//ww w . jav a 2 s . co m String strPattern = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"; Pattern p = Pattern.compile(strPattern); Matcher m = p.matcher(s); return m.matches(); }
From source file:Main.java
public static boolean isFixedPhoneNumber(String telNum) { if (TextUtils.isEmpty(telNum)) { return false; }//from w w w . j av a 2 s. c o m telNum = telNum.replaceAll("^\\+{0,1}86", ""); boolean flag = false; if (telNum.matches("^0[1|2]\\d[1-9]\\d{4,6}$")) { flag = true; } else if (telNum.matches("^0[3-9]\\d{2}[1-9]\\d{4,5}$")) { flag = true; } return flag; }
From source file:Main.java
public static boolean isEmail(String email) { if (TextUtils.isEmpty(email)) return false; Pattern pattern = Pattern .compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"); Matcher matcher = pattern.matcher(email); return matcher.matches(); }
From source file:Main.java
public static int getStringUTF8Length(final String str) { if (TextUtils.isEmpty(str)) { return 0; }/*from ww w . ja va 2s . c o m*/ try { return str.getBytes("UTF-8").length; } catch (final UnsupportedEncodingException e) { return 0; } }
From source file:Main.java
public static float getTextWidth(Paint paint, String text, float textSize) { if (TextUtils.isEmpty(text)) { return 0; }/*from w ww .j a v a 2 s . com*/ paint.setTextSize(textSize); float[] widths = new float[text.length()]; paint.getTextWidths(text, widths); float totalWidth = 0; for (int i = 0; i < widths.length; i++) { totalWidth += widths[i]; } return totalWidth; }
From source file:Main.java
public static boolean isIDNumber(String id) { if (!TextUtils.isEmpty(id)) { Pattern pattern = Pattern .compile("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$"); Matcher matcher = pattern.matcher(id); return matcher.find(); }//ww w .j a va 2 s .co m return false; }
From source file:Main.java
public static String getLocation(String city, String country) { if (!TextUtils.isEmpty(city) && !TextUtils.isEmpty(country)) { return city + ", " + country; } else if (!TextUtils.isEmpty(city)) { return city; } else if (!TextUtils.isEmpty(country)) { return country; } else {/*from w w w. jav a 2 s. co m*/ return ""; } }
From source file:Main.java
public static boolean isFileExist(String filePath) { if (TextUtils.isEmpty(filePath)) { return false; }// w w w . j ava 2s . c om File file = new File(filePath); return (file.exists() && file.isFile()); }
From source file:Main.java
private static String getFileName(String fileName) { if (!TextUtils.isEmpty(fileName)) { int fragment = fileName.lastIndexOf('#'); if (fragment > 0) { fileName = fileName.substring(0, fragment); }//from ww w . j a v a2 s . c o m int query = fileName.lastIndexOf('?'); if (query > 0) { fileName = fileName.substring(0, query); } return fileName; } else { return ""; } }