Created
November 9, 2016 01:47
-
-
Save daolq3012/c3ab28f4e82309392b44dc3f99cd5c85 to your computer and use it in GitHub Desktop.
Author
daolq3012
commented
Nov 9, 2016
public class StringUtils {
private StringUtils() {
// No-op
}
public static boolean isBlank(String str) {
return str == null || TextUtils.isEmpty(str.trim()) || str.equalsIgnoreCase("null");
}
public static boolean isNotBlank(String str) {
return !isBlank(str);
}
public static String getString(Context context, @StringRes int stringId) {
return context.getResources().getString(stringId);
}
public static String trim(String input) {
if (TextUtils.isEmpty(input)) {
return input;
}
String output = input.trim();
while (output.startsWith("\u3000")) {
output = output.substring(1, output.length());
}
while (output.endsWith("\u3000")) {
output = output.substring(0, output.length() - 1);
}
return output;
}
}
/**
* Transform color to darker or lighter
*
* @param color input color
* @param factor < 1: darker, > 1: lighter
*/
public static int addColor(int color, float factor) {
int a = Color.alpha(color);
int r = Math.round(Color.red(color) * factor);
int g = Math.round(Color.green(color) * factor);
int b = Math.round(Color.blue(color) * factor);
return Color.argb(a, Math.min(r, 255), Math.min(g, 255), Math.min(b, 255));
}
/**
* Transform color to darker or lighter (alpha)
*
* @param color input color
* @param factor < 1: opacity, > 1: transparent
*/
public static int addAlpha(int color, float factor) {
int a = Math.round(Color.alpha(color) * factor);
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
return Color.argb(Math.min(a, 255), r, g, b);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment