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 int getIntByString(Bundle bundle, String key, int def) {
    if (bundle == null)
        return def;
    String str = bundle.getString(key);
    if (!TextUtils.isEmpty(str)) {
        try {// ww w  .ja  v  a2  s  .com
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

    return def;
}

From source file:Main.java

public static SpannableString setTextSub(String content, int startIndex, int endIndex) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }//from w  w  w  . j  av  a2 s. c  o  m

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

    return spannableString;
}

From source file:Main.java

public static Bitmap decodeBitmapFromFile(String pathName, BitmapFactory.Options opts) {
    if (TextUtils.isEmpty(pathName)) {
        return null;
    }/*  w  ww .  ja  va  2  s  .c o  m*/
    return BitmapFactory.decodeFile(pathName, opts);
}

From source file:Main.java

public static void dialPhone(Context context, String phoneNumber) {
    if (!TextUtils.isEmpty(phoneNumber)) {
        try {/*from   w w  w .  j  a va2s. co  m*/
            Intent callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
            context.startActivity(callIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void callPhone(Context context, String phoneNumber) {
    if (!TextUtils.isEmpty(phoneNumber)) {
        try {//from ww w  .  ja va 2 s. c  om
            Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
            context.startActivity(callIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

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

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

    return spannableString;
}

From source file:Main.java

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

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

    return spannableString;
}

From source file:Main.java

public static synchronized void deleteCalllogByPhone(Context context, String number) {
    if (TextUtils.isEmpty(number))
        return;/* w  w  w . j  a  v  a  2s  .  c  o  m*/
    try {
        Cursor cursor = context.getContentResolver().query(Calls.CONTENT_URI, null, Calls.NUMBER + "=?",
                new String[] { number }, Calls.DATE + " desc");
        if (cursor != null) {
            if (cursor.moveToNext()) {
                long _id = cursor.getLong(cursor.getColumnIndex(Calls._ID));
                context.getContentResolver().delete(Calls.CONTENT_URI, Calls._ID + "=?",
                        new String[] { String.valueOf(_id) });
            }
            cursor.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static ArrayList<String> jsonArrayStringToStringList(String jsonArrayString) {
    try {// w ww.j av  a2 s. c  om
        if (!TextUtils.isEmpty(jsonArrayString)) {
            return jsonArrayToStringList(new JSONArray(jsonArrayString));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return new ArrayList<>();
}

From source file:Main.java

public static boolean isValidCv2Number(String cv2) {
    if (TextUtils.isEmpty(cv2)) {
        return false;
    }/*  ww w. ja v  a  2  s. co  m*/

    if (cv2.length() < CV2_LENGTH_MIN || cv2.length() > CV2_LENGTH_MAX) {
        return false;
    }

    // check all numeric
    if (!TextUtils.isDigitsOnly(cv2)) {
        return false;
    }

    return true;
}