public class AppUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APP_VERSION_NOT_FOUND
Replacement text to be used if the app's version name can't be found.
|
static java.lang.String |
LOG_TAG
A logging tag.
|
Constructor and Description |
---|
AppUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getAppNameAndVersion(android.content.Context ctx)
Returns a string containing the app's name and version (if found).
|
static java.lang.String |
getAppNameAndVersion(android.content.Context ctx,
int resFormat)
Returns a string containing the app's name and version (if found).
|
static java.lang.String |
getAppVersion(android.content.Context ctx)
Returns the string containing the app's current version.
|
static void |
initBackButtonForActivity(android.app.Activity act)
Initializes a back button for the activity.
|
static void |
initBackButtonForActivity(android.support.v7.app.AppCompatActivity act)
Initializes a back button for the activity.
|
static boolean |
isTextCompatRTL(android.content.Context ctx)
(in AppCompat context) Determines whether the current text layout is
right-to-left.
|
static boolean |
isTextRTL(android.content.Context ctx)
(in non-compat context) Determines whether the current text layout is
right-to-left.
|
protected static boolean |
legacyIsTextRTL(android.content.res.Configuration cfg)
(prior to API 17) Determines whether the current text layout is
right-to-left.
|
public static final java.lang.String LOG_TAG
public static final java.lang.String APP_VERSION_NOT_FOUND
"(unknown)"
.public static java.lang.String getAppVersion(android.content.Context ctx)
ctx
- a context in which to fetch a package managerpublic static java.lang.String getAppNameAndVersion(android.content.Context ctx)
ctx
- a context in which to fetch resourcesR.string#app_name_and_version_format
public static java.lang.String getAppNameAndVersion(android.content.Context ctx, int resFormat)
ctx
- a context in which to fetch resourcesresFormat
- a custom string resource specifying the format in which
the string should be rendered; must contain two string
variables (one for the name, one for the version)public static void initBackButtonForActivity(android.app.Activity act)
onCreate
method. Then, in the activity's
onOptionsItemSelected
method,
remember to set a handler for this button.
public boolean onOptionsItemSelected( MenuItem item ) { switch( item.getItemId() ) { case android.R.id.home: this.onBackPressed() ; break ; // (other items...) } }
act
- an activity.public static void initBackButtonForActivity(android.support.v7.app.AppCompatActivity act)
onCreate
method. Then, in the activity's
onOptionsItemSelected
method, remember to set a handler for this button.
public boolean onOptionsItemSelected( MenuItem item ) { switch( item.getItemId() ) { case android.R.id.home: this.onBackPressed() ; break ; // (other items...) } }
act
- an activity.public static boolean isTextCompatRTL(android.content.Context ctx)
ctx
- the context in which to evaluate text directionalitytrue
if text layout is right-to-leftTextUtilsCompat.getLayoutDirectionFromLocale(java.util.Locale)
,
Stack Overflow answer #14389640,
Stack Overflow answer #23203698public static boolean isTextRTL(android.content.Context ctx)
ctx
- the context in which to evaluate text directionalitytrue
if text layout is right-to-leftTextUtils.getLayoutDirectionFromLocale(java.util.Locale)
,
Stack Overflow answer #14389640,
Stack Overflow answer #23203698protected static boolean legacyIsTextRTL(android.content.res.Configuration cfg)
isTextRTL(android.content.Context)
and isTextCompatRTL(android.content.Context)
.cfg
- the current context's configurationtrue
if text layout is right-to-left