List of usage examples for android.text TextUtils isEmpty
public static boolean isEmpty(@Nullable CharSequence str)
From source file:Main.java
public static boolean isEmpty(String text) { if (TextUtils.isEmpty(text)) { return true; }//from w w w. j ava2 s .c om return false; }
From source file:Main.java
public static String getAppVersion(Context context) { if (TextUtils.isEmpty(VERSION_NAME)) { PackageManager manager = context.getPackageManager(); try {/*from w ww.j a v a2 s.co m*/ PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); VERSION_NAME = info.versionName; } catch (Exception e) { e.printStackTrace(); } } return VERSION_NAME; }
From source file:Main.java
public static Bitmap fix(String path, int w, int h) { if (TextUtils.isEmpty(path)) return null; BitmapFactory.Options options = new Options(); options.inJustDecodeBounds = true;//from w ww .j a v a 2 s . co m BitmapFactory.decodeFile(path, options); int imageH = options.outHeight; int imageW = options.outWidth; int scaleX = imageH / w; int scaleY = imageW / h; int scale = 1; if (scaleX >= scaleY & scaleY >= 1) { scale = scaleX; } if (scaleY >= scaleX & scaleX >= 1) { scale = scaleY; } options.inJustDecodeBounds = false; options.inSampleSize = scale; return BitmapFactory.decodeFile(path, options); }
From source file:Main.java
public static void toastLong(Context context, String message) { if (!TextUtils.isEmpty(message)) { Toast.makeText(context, message, Toast.LENGTH_LONG).show(); }/*from w ww . j a va 2s .co m*/ }
From source file:Main.java
public static SpannableString setTextImg(String content, int startIndex, int endIndex, Drawable drawable) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }//from w ww . j av a 2 s . c o m SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new ImageSpan(drawable), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static String getMetaString(ApplicationInfo appInfo, String key) { String value = ""; if (appInfo == null) return value; value = String.valueOf(appInfo.metaData.get(key)); if (TextUtils.isEmpty(value)) value = Integer.toString(appInfo.metaData.getInt(key)); return value; }
From source file:Main.java
public static void log(String owner, String message, String flag) { Log.d("LOG", "<message owner=\"" + owner + (!TextUtils.isEmpty(flag) ? " flag=\"" + flag + "\"" : "") + ">" + message + "</message>"); }
From source file:Main.java
public static boolean saveObjectToFile(String filePath, Object object) { if (!TextUtils.isEmpty(filePath)) { File cacheFile = null;/* w w w . jav a2 s . c om*/ try { cacheFile = new File(filePath); if (cacheFile.exists()) { cacheFile.delete(); } if (!cacheFile.getParentFile().exists()) { cacheFile.getParentFile().mkdirs(); } cacheFile.createNewFile(); } catch (Throwable var6) { var6.printStackTrace(); cacheFile = null; } if (cacheFile != null) { try { FileOutputStream t = new FileOutputStream(cacheFile); GZIPOutputStream gzos = new GZIPOutputStream(t); ObjectOutputStream oos = new ObjectOutputStream(gzos); oos.writeObject(object); oos.flush(); oos.close(); return true; } catch (Throwable var7) { var7.printStackTrace(); } } } return false; }
From source file:Main.java
public static void resetDefaultViewer(Context context, String mimeType) { if (!TextUtils.isEmpty(mimeType)) { PreferenceManager.getDefaultSharedPreferences(context).edit().remove(DEFAULT_VIEWER_PREFIX + mimeType) .apply();// ww w .j av a2 s .com } }
From source file:Main.java
private static void saveToFile(byte[] data, String path) { if (data == null || data.length == 0) { return;/* w w w . ja v a2s .com*/ } if (TextUtils.isEmpty(path)) { return; } FileOutputStream fos = null; try { fos = new FileOutputStream(path, true); fos.write(data); fos.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }