List of usage examples for android.text TextUtils isEmpty
public static boolean isEmpty(@Nullable CharSequence str)
From source file:Main.java
public static void showWebPage(String url, Context context) { if (TextUtils.isEmpty(url)) return;/*w w w . jav a 2 s.c om*/ Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); context.startActivity(intent); }
From source file:Main.java
public static boolean deleteFile(String path) { // If path == null will throw NullPointException. if (TextUtils.isEmpty(path)) { return false; }// w w w . ja v a2s . c o m File file = new File(path); if (!file.exists()) { return false; } boolean flag = file.delete(); File parent = file.getParentFile(); if (isEmptyDirectory(parent)) { parent.delete(); } return flag; }
From source file:Main.java
/** * Get characters' unicode in hexadecimal. *///from w w w .j a v a2 s . c o m public static String getUnicode(String text, int len_limit) { if (TextUtils.isEmpty(text) || len_limit <= 0) { return ""; } StringBuilder stringBuilder = new StringBuilder(); final char[] CHARS = text.toCharArray(); for (int len = CHARS.length, i = len - 1; i >= 0; --i) { if (len - i <= len_limit) { stringBuilder.insert(0, Integer.toHexString(CHARS[i]).toUpperCase()); stringBuilder.insert(0, " "); } else { stringBuilder.insert(0, " ..."); break; } } //Remove the first superfluous " ". return stringBuilder.substring(1); }
From source file:Main.java
/** * Toast// www .j av a2s. com * @param context * @param msg */ public static void showToast(Context context, String msg) { if (!TextUtils.isEmpty(msg)) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } }
From source file:Main.java
public static String getMimeType(String filePath) { if (TextUtils.isEmpty(filePath)) { return ""; }/*w ww. j av a 2 s . c o m*/ String type = null; String extension = getExtensionName(filePath.toLowerCase()); if (!TextUtils.isEmpty(extension)) { MimeTypeMap mime = MimeTypeMap.getSingleton(); type = mime.getMimeTypeFromExtension(extension); } Log.i(TAG, "url:" + filePath + " " + "type:" + type); // FIXME if (TextUtils.isEmpty(type) && filePath.endsWith("aac")) { type = "audio/aac"; } return type; }
From source file:Main.java
public static List<String> split(String str, char delimiter) { if (TextUtils.isEmpty(str)) { return Collections.emptyList(); }/*from ww w .ja v a 2 s.com*/ int substringsCount = 1; for (int i = 0, len = str.length(); i < len; i++) { if (str.charAt(i) == delimiter) { substringsCount++; } } if (substringsCount == 1) { return Collections.singletonList(str); } List<String> split = new ArrayList<String>(substringsCount); int index = str.indexOf(delimiter); int lastIndex = 0; while (index != -1) { split.add(str.substring(lastIndex, index)); lastIndex = index + 1; index = str.indexOf(delimiter, lastIndex); } split.add(str.substring(lastIndex, str.length())); // add the final string after the last delimiter return split; }
From source file:Main.java
public static void sendSms(Context context, String phoneNumber, String content) { Uri uri = Uri.parse("smsto:" + (TextUtils.isEmpty(phoneNumber) ? "" : phoneNumber)); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); intent.putExtra("sms_body", TextUtils.isEmpty(content) ? "" : content); context.startActivity(intent);// w w w . j a va2s. c o m }
From source file:Main.java
public static Rect getTextRect(String text, Paint paint) { Rect rect = new Rect(); if (!TextUtils.isEmpty(text)) { paint.getTextBounds(text, 0, text.length(), rect); }/* ww w .j av a 2s . com*/ return rect; }
From source file:Main.java
public static boolean copyFile(String fromFilePath, String toFilePath) { if (!TextUtils.isEmpty(fromFilePath) && !TextUtils.isEmpty(toFilePath)) { if (!(new File(fromFilePath)).exists()) { return false; } else {/*from ww w . j a v a 2s.c o m*/ try { FileInputStream e = new FileInputStream(fromFilePath); FileOutputStream fosto = new FileOutputStream(toFilePath); copyFile(e, fosto); return true; } catch (Throwable var4) { return false; } } } else { return false; } }
From source file:Main.java
public static boolean makeFolder(String filePath) { String folderName = getFolderName(filePath); if (TextUtils.isEmpty(folderName)) { return false; }// www . j av a 2 s . co m File folder = new File(folderName); return (folder.exists() && folder.isDirectory()) ? true : folder.mkdirs(); }