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 Boolean isNullOrWhitespace(String string) {
    if (string == null)
        return true;

    if (string.equalsIgnoreCase("null"))
        return true;

    String trimed = string.trim();
    return TextUtils.isEmpty(trimed);
}

From source file:Main.java

/**
 * showToast//from w w w  .  j av  a2  s  .co m
 * @param context
 * @param message
 * @param duration    LENGTH_SHORT,LENGTH_LONG
 */
public static void showToastTips(Context context, String message, int duration) {
    if (!TextUtils.isEmpty(message)) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

public static boolean hasDefaultViewer(Context context, String mimeType) {
    if (!TextUtils.isEmpty(mimeType)) {
        return PreferenceManager.getDefaultSharedPreferences(context)
                .contains(DEFAULT_VIEWER_PREFIX + mimeType);
    }/*from   w ww . j a  v  a 2s.c o m*/
    return false;
}

From source file:Main.java

public static String convertUtc2LocalPro(String utcTime) {
    if (TextUtils.isEmpty(utcTime)) {
        return "";
    }//from w w  w  .  ja va2 s.  c  om
    // 2014-10-24T02:58:05.932Z
    SimpleDateFormat utcFormatter, localFormatter;
    utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
    Date date;
    Calendar cal = Calendar.getInstance();
    try {
        date = utcFormatter.parse(utcTime);
        cal.setTime(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    cal.add(Calendar.HOUR_OF_DAY, +8);
    date = cal.getTime();
    localFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
    return localFormatter.format(date);
}

From source file:Main.java

public static Bitmap rotateBitmapInNeeded(String path, Bitmap srcBitmap) {
    if (TextUtils.isEmpty(path) || srcBitmap == null) {
        return null;
    }//from   w  w  w  .j  a  v  a2  s.com

    ExifInterface localExifInterface;
    try {
        localExifInterface = new ExifInterface(path);
        int rotateInt = localExifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        float rotate = getImageRotate(rotateInt);
        if (rotate != 0) {
            Matrix matrix = new Matrix();
            matrix.postRotate(rotate);
            Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(),
                    matrix, false);
            if (dstBitmap == null) {
                return srcBitmap;
            } else {
                if (srcBitmap != null && !srcBitmap.isRecycled()) {
                    srcBitmap.recycle();
                }
                return dstBitmap;
            }
        } else {
            return srcBitmap;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return srcBitmap;
    }
}

From source file:Main.java

public static String getSubscriberId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String tel = tm.getSubscriberId();
    return TextUtils.isEmpty(tel) ? "" : tel;
}

From source file:Main.java

/** Returns the tone type that the string character represents. If input is
 * empty, then returns -1. *///from   w  w w  .  ja v  a 2  s. co m
public static int getToneTypeFromString(String toneString) {
    if (TextUtils.isEmpty(toneString)) {
        return -1;
    }

    if (toneString.equalsIgnoreCase("0")) {
        return ToneGenerator.TONE_DTMF_0;
    } else if (toneString.equalsIgnoreCase("1")) {
        return ToneGenerator.TONE_DTMF_1;
    } else if (toneString.equalsIgnoreCase("2")) {
        return ToneGenerator.TONE_DTMF_2;
    } else if (toneString.equalsIgnoreCase("3")) {
        return ToneGenerator.TONE_DTMF_3;
    } else if (toneString.equalsIgnoreCase("4")) {
        return ToneGenerator.TONE_DTMF_4;
    } else if (toneString.equalsIgnoreCase("5")) {
        return ToneGenerator.TONE_DTMF_5;
    } else if (toneString.equalsIgnoreCase("6")) {
        return ToneGenerator.TONE_DTMF_6;
    } else if (toneString.equalsIgnoreCase("7")) {
        return ToneGenerator.TONE_DTMF_7;
    } else if (toneString.equalsIgnoreCase("8")) {
        return ToneGenerator.TONE_DTMF_8;
    } else if (toneString.equalsIgnoreCase("9")) {
        return ToneGenerator.TONE_DTMF_9;
    } else if (toneString.equalsIgnoreCase("A")) {
        return ToneGenerator.TONE_DTMF_A;
    } else if (toneString.equalsIgnoreCase("B")) {
        return ToneGenerator.TONE_DTMF_B;
    } else if (toneString.equalsIgnoreCase("C")) {
        return ToneGenerator.TONE_DTMF_C;
    } else if (toneString.equalsIgnoreCase("D")) {
        return ToneGenerator.TONE_DTMF_D;
    } else if (toneString.equalsIgnoreCase("#")) {
        return ToneGenerator.TONE_DTMF_P;
    } else if (toneString.equalsIgnoreCase("*")) {
        return ToneGenerator.TONE_DTMF_S;
    }
    return ToneGenerator.TONE_DTMF_0; // Error if code reaches here.
}

From source file:Main.java

/**
 * check if is miui ROM//  w  w  w  . ja v  a2s .c  om
 */
public static boolean checkIsMiuiRom() {
    return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"));
}

From source file:Main.java

public static int compareDateStr(String dateStr1, String dateStr2, String format) {
    int result = 0;
    if (TextUtils.isEmpty(dateStr1) && !TextUtils.isEmpty(dateStr2)) {
        return 1;
    }//from w  ww .j a  va2 s  .  com
    if (!TextUtils.isEmpty(dateStr1) && TextUtils.isEmpty(dateStr2)) {
        return -1;
    }
    if ((TextUtils.isEmpty(dateStr1) && TextUtils.isEmpty(dateStr2)) || TextUtils.isEmpty(format)) {
        return 0;
    }
    Date d1 = getDate(dateStr1, format);
    Date d2 = getDate(dateStr2, format);
    if (d1 == null || d2 == null) {
        return result;
    }
    result = d2.compareTo(d1);
    return result;
}

From source file:Main.java

public static String getIMEI(Context context) {
    TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = telManager.getDeviceId();
    return TextUtils.isEmpty(deviceId) ? "" : deviceId;
}