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 getPicUrl(String baseProImgUrl, int size, int index) {
    if (TextUtils.isEmpty(baseProImgUrl))
        return "";

    int end = baseProImgUrl.lastIndexOf("?");
    String str_timemark = "";
    if (end > 0) {
        str_timemark = baseProImgUrl.substring(end); // /?123445
    }//from  w w w  .ja va2s .  c om

    end = baseProImgUrl.lastIndexOf("/");
    String innerUrl = baseProImgUrl.substring(0, end);

    end = innerUrl.lastIndexOf("/");
    String head = innerUrl.substring(0, end);
    String mid = innerUrl.substring(end);

    String items[] = mid.split("\\.");
    if (null == items || items.length != 3)
        return "";

    int flag = 0;
    for (int len = PIC_WIDTH.length, i = len - 1; i > -1; i--) {
        if (size >= PIC_WIDTH[i]) {
            flag = i;
            break;
        }
    }
    if (flag >= PIC_WIDTH.length)
        flag = PIC_WIDTH.length - 1;

    int resolution = PIC_WIDTH[flag] == 800 ? 0 : PIC_WIDTH[flag];

    String result = head + items[0] + "." + index + "." + items[2] + "/" + resolution + str_timemark;
    return result;
}

From source file:Main.java

/**
 * isStringEmpty//w w  w .  ja  v a2 s.c  o m
 * <p>
 * Check if the given string is empty
 * 
 * @return return true if the string is null or len-of-zero
 */
public static boolean isStringEmpty(String str) {
    return (str == null || TextUtils.isEmpty(str));
}

From source file:Main.java

public static SpannableString setTextSize(String content, int startIndex, int endIndex, int fontSize) {
    if (TextUtils.isEmpty(content) || fontSize <= 0 || startIndex >= endIndex || startIndex < 0
            || endIndex >= content.length()) {
        return null;
    }/*from  ww  w  . java2 s  .co m*/

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new AbsoluteSizeSpan(fontSize), startIndex, endIndex,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
}

From source file:Main.java

public static boolean isX86CPU() {
    String cpu = getCpuInfo();/*from  w w w .  ja v  a 2  s.co  m*/
    if (!TextUtils.isEmpty(cpu)) {
        if (cpu.contains("x86")) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static long str2Long(String obj, Long defValue) {
    try {//from w  w  w.  ja  v  a  2 s  .c om
        if (TextUtils.isEmpty(obj))
            return defValue;
        return Long.parseLong(obj);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return defValue;
}

From source file:Main.java

public static boolean isInstalled(Context context, String packageName) {
    boolean installed = false;
    if (TextUtils.isEmpty(packageName)) {
        return false;
    }/*from  w w  w.  j  a va2s .c  o m*/
    List<ApplicationInfo> installedApplications = context.getPackageManager().getInstalledApplications(0);
    for (ApplicationInfo in : installedApplications) {
        if (packageName.equals(in.packageName)) {
            installed = true;
            break;
        } else {
            installed = false;
        }
    }
    return installed;
}

From source file:Main.java

public static File getAndroidDataFile(String packageName) {
    String internalsd = Environment.getExternalStorageDirectory().getAbsolutePath(); //getInternalSdcardPath();
    return (TextUtils.isEmpty(internalsd) || TextUtils.isEmpty(packageName)) ? null
            : new File(internalsd, "Android/data/" + packageName);
}

From source file:Main.java

@Nullable
public static Uri safeUri(@NonNull String url) {
    if (TextUtils.isEmpty(url)) {
        return null;
    }//from  w  w w  . j a va 2s .  co m

    Uri uri = Uri.parse(url);

    if (TextUtils.isEmpty(uri.getScheme()) || TextUtils.isEmpty(uri.getHost())) {
        return null;
    }

    return uri;
}

From source file:Main.java

public static String getSourceApkPath(Context context, String packageName) {
    if (TextUtils.isEmpty(packageName))
        return null;

    try {/*from w  w w.j  a  va 2s.  com*/
        ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
        return appInfo.sourceDir;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static String getStoragePath() {
    if (!isCardExist())
        return null;
    File path = Environment.getExternalStorageDirectory();
    if (path != null && !TextUtils.isEmpty(path.getAbsolutePath())) {
        return path.getAbsolutePath();
    } else {/* w ww .  jav a2 s  .com*/
        return null;
    }
}