public class AppUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ERROR_ACTIVITY |
private static java.lang.String |
PACKAGE_NAME |
private static java.lang.String |
PLAY_STORE |
private static java.lang.String |
PLAY_STORE_WEB |
private static java.lang.String |
TAG |
private static int |
VERSION_CODE |
Modifier | Constructor and Description |
---|---|
private |
AppUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
capitalize(java.lang.String s)
Capitalize a String
|
static int |
dp2px(android.content.Context ctxt,
float dipValue)
Convert device density to pixels
|
static java.lang.String |
getAppName(android.content.Context ctxt)
Get the app name
|
static java.lang.String |
getRandomString()
Get a pseudo-random string of a fixed length
|
static java.lang.String |
getRandomString(int length)
Get a pseudo-random string of the given length
|
static java.lang.CharSequence |
getRelativeDisplayTime(android.content.Context ctxt,
long time)
Get a time string relative to now
|
static boolean |
isDualPane(android.content.Context context)
Check if the MainActivity is in dual pane mode
|
static boolean |
isEmpty(java.util.Collection coll)
Null-safe check if the specified collection is empty.
|
static boolean |
isJellyBeanOrLater()
Check if we are running on a jellybean or newer device
|
static boolean |
isLollipopOrLater()
Check if we are running on a lollipop or newer device
|
static boolean |
isMyServiceRunning(android.content.Context ctxt,
java.lang.Class<?> serviceClass)
Check if one of my services is running
|
static boolean |
isOreoOrLater()
Check if we are running on an oreo or newer device
|
static boolean |
isWhitespace(java.lang.CharSequence s)
Is String null or all whitespace
|
static void |
performWebSearch(android.content.Context ctxt,
java.lang.String text)
Launch an
Intent to search the web |
static int |
px2dp(android.content.Context ctxt,
float pxValue)
Convert pixels to device density
|
static void |
showInPlayStore(android.content.Context ctxt)
Show the
App in the play store |
static void |
showMessage(android.content.Context ctxt,
android.view.View view,
java.lang.String msg)
Display a toast or snackbar message
|
static void |
showWebUrl(android.content.Context ctxt,
java.lang.String uri)
Launch an
Intent to show a Uri |
static int |
size(java.util.Collection coll)
Null-safe size of Collection
|
static void |
startActivity(android.content.Context ctxt,
android.content.Intent intent)
Try to start an activity
|
static boolean |
startNewTaskActivity(android.content.Context ctxt,
android.content.Intent intent)
Try to start an activity as a new task
|
private static final java.lang.String TAG
private static final java.lang.String PACKAGE_NAME
private static final java.lang.String PLAY_STORE
private static final java.lang.String PLAY_STORE_WEB
private static final int VERSION_CODE
private static final java.lang.String ERROR_ACTIVITY
public static java.lang.String getAppName(android.content.Context ctxt)
public static boolean isOreoOrLater()
public static boolean isLollipopOrLater()
public static boolean isJellyBeanOrLater()
public static boolean isDualPane(android.content.Context context)
public static boolean isMyServiceRunning(android.content.Context ctxt, java.lang.Class<?> serviceClass)
ctxt
- A ContextserviceClass
- Class name of Servicepublic static void startActivity(android.content.Context ctxt, android.content.Intent intent)
ctxt
- A Contextintent
- Activity intentpublic static boolean startNewTaskActivity(android.content.Context ctxt, android.content.Intent intent)
ctxt
- A Contextintent
- Activity intentpublic static void showMessage(android.content.Context ctxt, android.view.View view, java.lang.String msg)
ctxt
- A Contextview
- a view to use for snackbarmsg
- message to displaypublic static void showInPlayStore(android.content.Context ctxt)
App
in the play storectxt
- A Contextpublic static void showWebUrl(android.content.Context ctxt, java.lang.String uri)
Intent
to show a Uri
ctxt
- A Contexturi
- A String that is a valid Web Urlpublic static void performWebSearch(android.content.Context ctxt, java.lang.String text)
Intent
to search the webctxt
- A Contexttext
- A String to search forpublic static java.lang.CharSequence getRelativeDisplayTime(android.content.Context ctxt, long time)
ctxt
- A Contexttime
- epoch timepublic static boolean isEmpty(java.util.Collection coll)
Null returns true. from: Commons Collections 3.2
coll
- the collection to check, may be nullpublic static int size(java.util.Collection coll)
Null returns 0.
coll
- the collection to check, may be nullpublic static boolean isWhitespace(@Nullable java.lang.CharSequence s)
s
- string to checkpublic static java.lang.String capitalize(java.lang.String s)
s
- String to captializepublic static java.lang.String getRandomString(int length)
length
- length of string to generatepublic static java.lang.String getRandomString()
public static int dp2px(android.content.Context ctxt, float dipValue)
ctxt
- A ContextdipValue
- Value to convertpublic static int px2dp(android.content.Context ctxt, float pxValue)
ctxt
- A ContextpxValue
- Value to convert