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 showMessage(Context context, String msg) {
    if (context == null || TextUtils.isEmpty(msg)) {
        return;//from   www  . ja v a 2  s  .c om
    }
    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

public static boolean doesAccountHaveEmail(Account account) {
    if (account == null || TextUtils.isEmpty(account.name)) {
        return false;
    }//  w  w w .  j a v a 2 s . c o m
    return Patterns.EMAIL_ADDRESS.matcher(account.name).matches();
}

From source file:Main.java

public static String getDeviceModel() {
    String model = Build.MODEL;/*from  w  ww  .  j  ava  2 s . c o m*/
    if (TextUtils.isEmpty(model)) {
        return "unknown";
    }
    return model;
}

From source file:Main.java

public static String patternLoginVerificationCode(String patternContent) {
    if (TextUtils.isEmpty(patternContent)) {
        return null;
    }/*from w w w.  j  av a  2  s . c  o  m*/
    Pattern p = Pattern.compile("(?<!\\d)\\d{6}(?!\\d)");
    Matcher matcher = p.matcher(patternContent);
    if (matcher.find()) {
        return matcher.group();
    }
    return null;
}

From source file:Main.java

private static Field getField(Class<?> thisClass, String fieldName) {
    Field field = null;/*from   w w w.  j  av  a  2s  .c o m*/

    if (!TextUtils.isEmpty(fieldName)) {
        try {
            field = thisClass.getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return field;
}

From source file:Main.java

public static int getFacialIdentifier(Context context, String type) {
    if (TextUtils.isEmpty(type)) {
        return -1;
    }/*from   w  w w  . jav  a2s.c o m*/
    Resources res = context.getResources();
    int resId = res.getIdentifier(String.format("like_%s", type), "drawable", context.getPackageName());
    return resId;
}

From source file:Main.java

public static long getFileSize(Context context, String filePath) {
    if (context != null && !TextUtils.isEmpty(filePath)) {
        File f = new File(filePath);
        if (f.exists() && f.isFile()) {
            return f.length();
        }/*from w  ww  .ja v  a2  s  .  c om*/
    }
    return -1l;
}

From source file:Main.java

public static String formatMoneyYuan(String amount) {
    if (TextUtils.isEmpty(amount)) {
        return "0.00";
    }/*from  w w w.jav  a 2 s.  co m*/
    String result;
    try {
        double num = Double.parseDouble(amount);
        DecimalFormat formater = new DecimalFormat("###,##0.00");
        result = formater.format(num);
    } catch (NumberFormatException e) {
        result = amount;
    }
    return result;
}

From source file:Main.java

public static boolean isInternal(String path) {
    return TextUtils.isEmpty(path) || path.startsWith(Environment.getRootDirectory() + "/media")
            || path.startsWith(getDataSDCardRoot());
}

From source file:Main.java

public static float getFloat(JSONObject jsonObject, String key) {
    if (jsonObject == null || TextUtils.isEmpty(key)) {
        return -1F;
    }/*from ww  w.j a v a 2  s.  c  om*/
    try {
        return (float) jsonObject.getDouble(key);
    } catch (Exception e) {
    }
    return -1F;
}