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 getMacAddress(Context context) {
    if (TextUtils.isEmpty(macAddress)) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        if (wifiInfo != null) {
            macAddress = wifiInfo.getMacAddress();
            return macAddress;
        }//from  www  .  ja v a  2s. c  om
    }
    return macAddress;
}

From source file:Main.java

public static boolean createFile(String fileName) throws IOException {
    if (TextUtils.isEmpty(fileName)) {
        return false;
    }//www.  ja  v  a 2  s . c  o m
    return createFile(fileName, false);
}

From source file:Main.java

public static AccessibilityNodeInfo findParentNodeInfoByClass(AccessibilityNodeInfo nodeInfo,
        String parentClass) {/*from ww w  .  j  av a  2 s.  c  om*/
    if (nodeInfo == null || TextUtils.isEmpty(parentClass)) {
        return null;
    }
    if (parentClass.equals(nodeInfo.getClassName())) {
        return nodeInfo;
    }
    return findParentNodeInfoByClass(nodeInfo.getParent(), parentClass);
}

From source file:Main.java

public static String getFormatDate(final Date date, String type) {
    if (null == date || TextUtils.isEmpty(type)) {
        return null;
    }/*  w ww.  jav  a2  s  .  c  o m*/

    SimpleDateFormat sdf;
    try {
        sdf = new SimpleDateFormat(type, Locale.SIMPLIFIED_CHINESE);
    } catch (Exception e) {
        sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
    }
    TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
    sdf.setTimeZone(timeZone);
    return sdf.format(date);
}

From source file:Main.java

public static SpannableString setTextSuper(String content, int startIndex, int endIndex) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }/*w  w  w  .j  av a  2s . co m*/

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

    return spannableString;
}

From source file:Main.java

public static SpannableString setTextBoldItalic(String content, int startIndex, int endIndex) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }/* w w  w  .j  a va2 s. co  m*/

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), startIndex, endIndex,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
}

From source file:Main.java

public static String getDeviceId(Context context) {
    if (TextUtils.isEmpty(DEVICE_ID)) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        DEVICE_ID = tm.getDeviceId();// w  w w  .j a v a 2  s .  c  om
    }
    return DEVICE_ID;
}

From source file:Main.java

public static void callPhone(Context context, String number) {
    Intent intent2 = new Intent(Intent.ACTION_DIAL);
    if (TextUtils.isEmpty(number))
        return;//from w  ww.  j  a  v a  2 s  .  c om
    Uri data2 = Uri.parse("tel:" + number);
    intent2.setData(data2);
    context.startActivity(intent2);
}

From source file:Main.java

public static SpannableString setTextURL(String content, int startIndex, int endIndex, String url) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }//from  w ww . j  a  v a2s .c  om

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new URLSpan(url), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableString;
}

From source file:Main.java

/**
 * show Toast/*from ww w .  ja v a 2  s .c o  m*/
 *
 * @param context
 * @param message
 */
public static void showToast(Context context, String message) {
    if (TextUtils.isEmpty(message)) {
        return;
    }
    Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}