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 void setLanguage(Context context, String language) {
    Locale locale;// ww w  .j  ava 2  s.c o  m
    if (TextUtils.isEmpty(language)) {
        locale = Locale.getDefault();
    } else if (language.length() == 5 && language.charAt(2) == '_') {
        // language is in the form: en_US
        locale = new Locale(language.substring(0, 2), language.substring(3));
    } else {
        locale = new Locale(language);
    }

    Configuration config = new Configuration();
    config.locale = locale;
    Resources resources = context.getResources();
    resources.updateConfiguration(config, resources.getDisplayMetrics());
}

From source file:Main.java

public static List<String> toStringList(String itemsstring) {
    List<String> resultList = new ArrayList<String>();
    if (TextUtils.isEmpty(itemsstring))
        return resultList;
    if (itemsstring.startsWith(",") && itemsstring.endsWith(",")) {
        itemsstring = itemsstring.substring(1, itemsstring.length() - 1);
    }/*from w w  w  . j  a  v  a  2 s  .co m*/
    String[] split = itemsstring.split(",");
    return Arrays.asList(split);
}

From source file:Main.java

public static boolean isContractNameValid(String name) {
    if (!TextUtils.isEmpty(name)) {
        return !Pattern.matches(CONTRACT_NAME_PATTERN, name);
    }/*from w w w. j a v a2 s  .  c  om*/
    return true;
}

From source file:Main.java

public static String getIMEI(Context mContext) {
    String str;//from  ww w . j  av  a 2s .c  o  m
    str = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
    return TextUtils.isEmpty(str) ? "" : str;
}

From source file:Main.java

public static String getConverDateString(String date, String fromFormat, String toFormat) {
    if (TextUtils.isEmpty(date))
        return "";
    SimpleDateFormat sdf = new SimpleDateFormat();
    sdf.applyPattern(fromFormat);/*from  www .  j a v  a2  s. c om*/
    Date d = null;
    try {
        d = sdf.parse(date);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    sdf.applyPattern(toFormat);
    return sdf.format(d);
}

From source file:Main.java

/**
 * Checks if it is a valid email address. IE, no.com would not pass but bob@gmail.com would.
 * @param target//w  w w  .  ja  va 2 s .c o  m
 * @return
 */
public static boolean isValidEmail(CharSequence target) {
    if (TextUtils.isEmpty(target)) {
        return false;
    } else {
        boolean booleanToReturn = android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
        return booleanToReturn;
    }
}

From source file:Main.java

public static String getWifiMac(Context mContext) {
    String str;/*from w  w w .ja  va 2s.c  o  m*/
    str = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo().getSSID();
    return TextUtils.isEmpty(str) ? "" : str;
}

From source file:Main.java

@Deprecated
public static HashMap<String, String> splitParams(String params) {
    if (TextUtils.isEmpty(params)) {
        return new HashMap<String, String>();
    }/*from   w w  w .j a va2 s  . c om*/
    String[] kvs = params.split("&");
    HashMap<String, String> map = new HashMap<String, String>(kvs.length);
    for (String string : kvs) {
        String[] kv = string.split("=");
        if (kv.length == 2) {
            try {
                kv[1] = URLDecoder.decode(kv[1], "utf-8");
            } catch (UnsupportedEncodingException e) {

            }
            map.put(kv[0], kv[1]);
        }
    }
    return map;
}

From source file:Main.java

public static float toFloat(String value) {
    if (TextUtils.isEmpty(value))
        return 0.0f;
    try {//ww  w . ja va2  s .co m
        float val = Float.parseFloat(value);
        return val;
    } catch (NumberFormatException ex) {
        return 0.0f;
    }
}

From source file:Main.java

public final static boolean isAnyStringEmpty(String[] array) {
    if (array == null || array.length <= 0)
        return false;

    for (String elem : array) {
        if (TextUtils.isEmpty(elem))
            return true;
    }//www.  j  a v a2 s . com

    return false;
}