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

public static String getWifiName(Context mContext) {
    String str;//  w  ww .  j  a va 2 s  .co m
    str = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo().getBSSID();
    return TextUtils.isEmpty(str) ? "" : str;
}

From source file:Main.java

public static Bitmap getBitmapFromUrl(String imageUrl) {
    Bitmap bmp = null;/*from ww w.  jav a 2s . c om*/
    try {
        if (!TextUtils.isEmpty(imageUrl) && imageUrl.startsWith("http")) {
            URL url = new URL(imageUrl);
            bmp = BitmapFactory.decodeStream(url.openStream());
        } else {
            bmp = BitmapFactory.decodeFile(imageUrl);
        }
    } catch (Throwable ex) {

    }
    return bmp;
}

From source file:Main.java

public static SpannableString setTextBackground(String content, int startIndex, int endIndex,
        int backgroundColor) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }// w ww  .  j  a  v  a 2s  .  c  o  m

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new BackgroundColorSpan(backgroundColor), startIndex, endIndex,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
}

From source file:Main.java

/**
 * counter ASCII character as one, otherwise two
 *
 * @param str/*  ww  w  .j a va 2  s  .com*/
 * @return count
 */
public static int counterChars(String str) {
    // return
    if (TextUtils.isEmpty(str)) {
        return 0;
    }
    int count = 0;
    for (int i = 0; i < str.length(); i++) {
        int tmp = (int) str.charAt(i);
        if (tmp > 0 && tmp < 127) {
            count += 1;
        } else {
            count += 2;
        }
    }
    return count;
}

From source file:Main.java

public static void invokeMethod(String paramString, Object paramObject, Object[] paramArrayOfObject)
        throws Exception {
    if (TextUtils.isEmpty(paramString))
        throw new RuntimeException("method name can not be empty");
    if (paramObject == null)
        throw new RuntimeException("target object can not be null");
    ArrayList localArrayList = new ArrayList();
    int i = paramArrayOfObject.length;
    for (int j = 0; j < i; j++)
        localArrayList.add(paramArrayOfObject[j].getClass());
    Method localMethod = paramObject.getClass().getDeclaredMethod(paramString,
            (Class[]) localArrayList.toArray());
    if (localMethod == null)
        throw new RuntimeException(
                "target object: " + paramObject.getClass().getName() + " do not have this method: "
                        + paramString + " with parameters: " + localArrayList.toString());
    localMethod.setAccessible(true);//from ww w .  j av a  2 s. com
    localMethod.invoke(paramObject, paramArrayOfObject);
}

From source file:Main.java

public static List<String> getSubtitlePath(String videoPath) {
    List<String> sbPathList = new ArrayList<String>();
    if (TextUtils.isEmpty(videoPath))
        return sbPathList;
    if (videoPath.contains("file")) {
        videoPath = videoPath.substring(7);
    }/*w  ww  . j  ava  2  s  . c o  m*/

    int end = videoPath.lastIndexOf("/", videoPath.length());
    String path = videoPath.substring(0, end + 1);
    end = videoPath.lastIndexOf(".", videoPath.length());
    if (-1 == end || null == path)
        return sbPathList;

    String subffix = videoPath.substring(0, end);
    File files = new File(path);
    if ((files != null) && (files.exists()) && (files.isDirectory())) {
        File[] filesInDir = files.listFiles();
        long count = filesInDir.length;
        for (int num = 0; num < count; num++) {
            String filePath = filesInDir[num].getPath();
            File subTitleFile = new File(filePath);
            if ((subTitleFile != null) && (subTitleFile.isFile()) && (subTitleFile.canRead())) {
                int pos = filePath.lastIndexOf(".", filePath.length());
                String sub = filePath.substring(pos + 1, filePath.length());
                if ((filePath.startsWith(subffix)) && (sub != null)
                        && ((sub.equalsIgnoreCase("srt")) || (sub.equalsIgnoreCase("ass"))
                                || (sub.equalsIgnoreCase("smi")) || (sub.equalsIgnoreCase("ssa")))) {
                    sbPathList.add(filePath);
                }
            }
        }
        if (sbPathList.size() != 0) {
            return sbPathList;
        }
    }
    return sbPathList;
}

From source file:Main.java

public static void toast(Context context, String message) {
    if (!TextUtils.isEmpty(message)) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }/*  w  ww  .ja va  2 s .  c  om*/
}

From source file:Main.java

public static void uninstallApk(Context context, String packageName) {
    if (context == null)
        return;/*  w w  w.  j ava2 s .com*/
    if (TextUtils.isEmpty(packageName))
        return;
    Intent intent = new Intent(Intent.ACTION_DELETE);
    Uri packageURI = Uri.parse("package:" + packageName);
    intent.setData(packageURI);
    context.startActivity(intent);
}

From source file:Main.java

public static boolean isMobileNum(String mobiles) {
    Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(17[0-9])|(14[0-9])|(18[0-9]))\\d{8}$");
    Matcher m = p.matcher(mobiles);

    return !TextUtils.isEmpty(mobiles) && m.matches();
}

From source file:Main.java

public static boolean isNamedProcess(Context context, String processName) {
    if (context == null || TextUtils.isEmpty(processName)) {
        return false;
    }/*from  ww w  . ja  v a2s .com*/

    int pid = android.os.Process.myPid();
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses();
    if (processInfoList == null) {
        return true;
    }

    for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
        if (processInfo.pid == pid && processName.equalsIgnoreCase(processInfo.processName)) {
            return true;
        }
    }
    return false;
}