public class Utils
extends java.lang.Object
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static double |
clamp(double value,
double min,
double max)
Clamp Double values to a given range
|
static float |
clamp(float value,
float min,
float max)
Clamp Float values to a given range
|
static int |
clamp(int value,
int min,
int max)
Clamp Integer values to a given range
|
static long |
clamp(long value,
long min,
long max)
Clamp Long values to a given range
|
static int |
compare(int lhs,
int rhs)
Compares two
int values. |
static int |
compare(long lhs,
long rhs)
Compares two
long values. |
static float |
distance(android.graphics.PointF p1,
android.graphics.PointF p2)
Compute the distance between two points
|
static int |
getGMTOffset()
Get the Device's GMT Offset
|
static java.lang.String |
getMimeType(java.lang.String url)
Get the MIME type of a file
|
static java.lang.String |
getMimeTypeFromExt(java.lang.String ext) |
static java.util.Random |
getRandom()
Get the Random Number Generator
|
static android.net.Uri |
getUriFromResource(android.content.Context context,
int resId)
Get uri to any resource type
|
static boolean |
isEmulator()
Return whether or not the current device is an emulator
|
static boolean |
isValidEmail(java.lang.CharSequence email)
Return whether or not a given string is a valid email address according to
the
Patterns.EMAIL_ADDRESS |
static double |
parseDouble(java.lang.String val,
double defValue)
Parse a double from a String in a safe manner
|
static float |
parseFloat(java.lang.String val,
float defVal)
Parse a float from a String in a safe manner.
|
static int |
parseInt(java.lang.String val,
int defValue)
Parse a int from a String in a safe manner.
|
static long |
parseLong(java.lang.String val,
long defValue)
Parse a long from a String in a safe manner.
|
static java.lang.String |
parseMimeType(java.lang.String filename)
Parse a file's mime type from the file extension
|
static long |
time()
Get the time from epoch in seconds
|
public static java.util.Random getRandom()
public static long time()
public static boolean isValidEmail(java.lang.CharSequence email)
Patterns.EMAIL_ADDRESSemail - the string to validatepublic static boolean isEmulator()
public static android.net.Uri getUriFromResource(@NonNull
android.content.Context context,
@AnyRes
int resId)
throws android.content.res.Resources.NotFoundException
context - - contextresId - - resource idResources.NotFoundException - if the given ID does not exist.public static int getGMTOffset()
public static java.lang.String getMimeType(java.lang.String url)
url - public static java.lang.String getMimeTypeFromExt(java.lang.String ext)
public static java.lang.String parseMimeType(java.lang.String filename)
filename - public static float distance(android.graphics.PointF p1,
android.graphics.PointF p2)
p1 - the first pointp2 - the second pointpublic static int clamp(int value,
int min,
int max)
value - the value to clampmin - the minimum valuemax - the maximum valuepublic static float clamp(float value,
float min,
float max)
value - the value to clampmin - the minimum valuemax - the maximum valuepublic static long clamp(long value,
long min,
long max)
value - the value to clampmin - the minimum valuemax - the maximum valuepublic static double clamp(double value,
double min,
double max)
value - the value to clampmin - the minimum valuemax - the maximum valuepublic static int compare(long lhs,
long rhs)
long values.public static int compare(int lhs,
int rhs)
int values.public static float parseFloat(java.lang.String val,
float defVal)
val - the string to parsedefVal - the default value to return if parsing failspublic static int parseInt(java.lang.String val,
int defValue)
val - the string to parsedefValue - the default value to return if parsing failspublic static long parseLong(java.lang.String val,
long defValue)
val - the string to parsedefValue - the default value to return if parsing failspublic static double parseDouble(java.lang.String val,
double defValue)
val - the string to parsedefValue - the default value to return in parsing fails