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

/**
 * @param val  the value to check//from   www. ja v  a  2 s  . com
 * @param tag   the tag to log
 */
public static void checkEmpty(String val, String tag) {
    if (TextUtils.isEmpty(val)) {
        throw new RuntimeException(tag + " can't be empty");
    }
}

From source file:Main.java

public static void showLong(Context context, String msg) {
    if (context != null && !TextUtils.isEmpty(msg)) {
        Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_LONG).show();
    }/*from w w w  .j  a v a 2 s  .  c  o m*/
}

From source file:Main.java

public static void openBrowser(Context context, String url) {
    if (!TextUtils.isEmpty(url)) {
        if (!url.startsWith("http://") && !url.startsWith("https://")) {
            url = "http://" + url;
        }//from  w w w. j  av a  2s.c  om
        context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    } else {
        Log.e("Helpers#openBrowser", "Something isn't right about the URL passed");
    }
}

From source file:Main.java

public static void showShort(Context context, String msg) {
    if (context != null && !TextUtils.isEmpty(msg)) {
        Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }//  ww  w.j  a  va  2  s .  co m
}

From source file:Main.java

public static boolean isServiceRunning(Context context, String serviceName) {
    if (TextUtils.isEmpty(serviceName)) {
        return false;
    }//from  w  ww.  j  a v  a 2 s  .  c om
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> mServiceList = manager.getRunningServices(100);
    for (int i = 0; i < mServiceList.size(); i++) {
        String clasString = mServiceList.get(i).service.getClassName();
        if (clasString.equals(serviceName)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static boolean chechField(EditText editText) {
    return TextUtils.isEmpty(editText.getText().toString().trim());
}

From source file:Main.java

public static void setField(String paramString, Object paramObject1, Object paramObject2) throws Exception {
    if (TextUtils.isEmpty(paramString))
        throw new RuntimeException("field name can not be empty");
    if (paramObject1 == null)
        throw new RuntimeException("target object can not be null");
    Field localField = paramObject1.getClass().getDeclaredField(paramString);
    if (localField == null)
        throw new RuntimeException("target object: " + paramObject1.getClass().getName()
                + " do not have this field: " + paramString);
    localField.setAccessible(true);//w w w  . j  a  v  a2 s  . c  om
    localField.set(paramObject1, paramObject2);
}

From source file:Main.java

public static String getResolution(Context context) {
    if (TextUtils.isEmpty(resolution)) {
        DisplayMetrics displaymetrics = context.getResources().getDisplayMetrics();
        if (displaymetrics.widthPixels == 720) {
            resolution = "hd720";
        } else if (displaymetrics.widthPixels == 1080) {
            resolution = "hd1080";
        } else if (displaymetrics.widthPixels == 1440) {
            resolution = "hd1440";
        } else if (displaymetrics.widthPixels == 2160) {
            resolution = "hd2160";
        } else {//w w w  .j a v  a2s .c o  m
            return displaymetrics.widthPixels + "x" + displaymetrics.heightPixels;
        }
    }

    return resolution;
}

From source file:Main.java

public static void sendSmsByPhoneAndContext(Context context, String phone, String content) {
    phone = TextUtils.isEmpty(phone) ? "" : phone;
    content = TextUtils.isEmpty(content) ? "" : content;

    Uri uri = Uri.parse("smsto:" + phone);
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    intent.putExtra("sms_body", content);
    context.startActivity(intent);/*from   w  ww  .  j av a 2  s .c  o  m*/
}

From source file:Main.java

public static boolean isEmptys(EditText... editTexts) {
    for (EditText ed : editTexts) {
        String str = ed.getText().toString().trim();
        if (TextUtils.isEmpty(str)) {
            return true;
        }/*from   w w w .  ja va 2  s.  co m*/
    }
    return false;
}