List of usage examples for android.text TextUtils isEmpty
public static boolean isEmpty(@Nullable CharSequence str)
From source file:Main.java
public static boolean isApplicationInstalled(final Context context, final String pkgName) { if (TextUtils.isEmpty(pkgName)) { return false; }// w w w . j a v a2 s . c o m if (null == context) { throw new IllegalArgumentException("context may not be null."); } try { context.getPackageManager().getPackageInfo(pkgName, 0); return true; } catch (final NameNotFoundException e) { // Application not installed. } return false; }
From source file:Main.java
public static void toastMessage(Context context, String text) { if (TextUtils.isEmpty(text)) { return;//from ww w . j av a2s .c o m } Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); }
From source file:Main.java
public static String getDeviceId(Context context) { String deviceId = ""; if (context != null) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (!TextUtils.isEmpty(tm.getDeviceId())) { deviceId = tm.getDeviceId(); }/* w w w .j a v a 2s . c o m*/ } return deviceId; }
From source file:Main.java
@Nullable @SuppressWarnings("unchecked") public static <T> Class<? extends T> classForName(@NonNull String className, boolean allowEmptyName) { if (allowEmptyName && TextUtils.isEmpty(className)) { return null; }/*from w w w. j a va 2 s.c o m*/ try { return (Class<? extends T>) Class.forName(className); } catch (Exception e) { throw new RuntimeException( "An exception occurred while finding class for name " + className + ". " + e.getMessage()); } }
From source file:Main.java
public static Date getDateTime(String date) { Date originalReleaseDate = null; try {/* w w w .ja v a2 s . c o m*/ if (!TextUtils.isEmpty(date)) { originalReleaseDate = dateTimeFormat.parse(date); } } catch (ParseException e) { e.printStackTrace(); } return originalReleaseDate; }
From source file:Main.java
public static final String getRawQueryParameter(Uri uri, String queryParameterName) { String ret = null;/*from w ww .ja v a 2s. co m*/ if ((uri != null) && (!TextUtils.isEmpty(queryParameterName))) { final String query = uri.getEncodedQuery(); if (query == null) { return null; } final String encodedKey = Uri.encode(queryParameterName, null); final int length = query.length(); int start = 0; do { int nextAmpersand = query.indexOf('&', start); int end = nextAmpersand != -1 ? nextAmpersand : length; int separator = query.indexOf('=', start); if (separator > end || separator == -1) { separator = end; } if (separator - start == encodedKey.length() && query.regionMatches(start, encodedKey, 0, encodedKey.length())) { if (separator == end) { ret = ""; } else { ret = query.substring(separator + 1, end); } break; } // Move start to end of name. if (nextAmpersand != -1) { start = nextAmpersand + 1; } else { break; } } while (true); } return ret; }
From source file:Main.java
static String getCallingPackageName(Activity activity) { // getCallingPackage() was unstable until android-18, use this String packageName = activity.getCallingActivity().getPackageName(); if (TextUtils.isEmpty(packageName)) { packageName = activity.getIntent().getPackage(); }/*from w w w . j av a 2s .c om*/ if (TextUtils.isEmpty(packageName)) { Log.e(activity.getPackageName(), "Received blank Panic.ACTION_DISCONNECT Intent, it must be sent using startActivityForResult()!"); } return packageName; }
From source file:Main.java
public static String getParam(Uri uri, String key, String defaultValue) { if (uri == null) { return defaultValue; }//from w w w. jav a2s .c o m String value = null; try { value = uri.getQueryParameter(key); } catch (Exception e) { } if (TextUtils.isEmpty(value)) { value = defaultValue; } return value; }
From source file:Main.java
public static String getRandom(String source, int length) { return TextUtils.isEmpty(source) ? null : getRandom(source.toCharArray(), length); }