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 int |
dipToPx(android.content.Context ctx,
float dpSize)
Convert Density-Independent Pixels to actual pixels
|
static float |
distance(android.graphics.PointF p1,
android.graphics.PointF p2)
Compute the distance between two points
|
static float |
dpToPx(android.content.Context ctx,
float dpSize)
Convert Density-Independent Pixels to actual pixels
|
static java.lang.String |
generateUniqueDeviceId(android.content.Context ctx)
Generate a unique device identifier that can be replicated
on the device
|
static java.lang.String |
generateUniqueDeviceId(StringPreference uuidPref)
Generate a new UUID if one is not stored.
|
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 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 float |
spToPx(android.content.Context ctx,
float spSize)
Convert Scale-Dependent Pixels to actual pixels
|
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 java.lang.String generateUniqueDeviceId(android.content.Context ctx)
CAVEAT This method requires the android.Manifest.permission#READ_PHONE_STATE permission
ctx - the application contextpublic static java.lang.String generateUniqueDeviceId(StringPreference uuidPref)
uuidPref - the uuid preferencepublic 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 float dpToPx(android.content.Context ctx,
float dpSize)
ctx - the application contextdpSize - the size in DP unitspublic static int dipToPx(android.content.Context ctx,
float dpSize)
ctx - the application context to convert the value withdpSize - the size in DP unitspublic static float spToPx(android.content.Context ctx,
float spSize)
ctx - the application contextspSize - the size in SP unitspublic 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