Package com.transifex.txnative
Class Utils
java.lang.Object
com.transifex.txnative.Utils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
static Spanned
InvokesHtml.fromHtml(String, int)
on API 24 and newer, otherwiseflags
are ignored andHtml.fromHtml(String)
is used.static Locale
getCurrentLocale
(Context context) Utility method to get the current locale as set in Android.static Resources
getDefaultLocaleResources
(Context context) Returns aResources
object configured for the default (non localized) resources.static Resources
getLocalizedResources
(Context context, Locale desiredLocale) Returns a Resources object, derived from the one in the provided context, which uses the desired locale.static int
getStringResourceId
(Context context, AttributeSet attributeSet, int attributeId) Returns the string resource id that this attributeId is resolving to under the provided attribute set and the current theme.static boolean
Checks ifAndroidx.appcompat
classes are available at runtime.static boolean
isClassPresent
(String className) Checks, using reflection, if the provided class is available at runtime.static boolean
Checks ifMaterial Components
classes are available at runtime.static void
printAttributeSet
(Context context, AttributeSet attrs) static String
unescapeHTMLEntities
(String string) Converts HTML entities to the final character similarly to whatHtmlCompat.fromHTML()
or the Android XML parser would do.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
getStringResourceId
@StringRes public static int getStringResourceId(Context context, @NonNull AttributeSet attributeSet, @AttrRes int attributeId) Returns the string resource id that this attributeId is resolving to under the provided attribute set and the current theme.If the attribute does not point to a resource id, the method returns "0". This can happen if the attribute is set to a hardcoded string or to "@null" or the attribute has not beet set.
- Parameters:
context
- The context.attributeSet
- The view's attribute set.attributeId
- The desired attribute to be retrieved.- Returns:
- The attribute's resource identifier or "0" if not applicable.
-
printAttributeSet
-
getCurrentLocale
Utility method to get the current locale as set in Android. -
getLocalizedResources
@NonNull public static Resources getLocalizedResources(@NonNull Context context, @NonNull Locale desiredLocale) Returns a Resources object, derived from the one in the provided context, which uses the desired locale. -
getDefaultLocaleResources
Returns aResources
object configured for the default (non localized) resources.Getting a string from this object, will return the string found in the default
`strings.xml`
file. Note though that quantity strings will not follow any locale's plural rules. -
equals
-
fromHtml
InvokesHtml.fromHtml(String, int)
on API 24 and newer, otherwiseflags
are ignored andHtml.fromHtml(String)
is used. -
unescapeHTMLEntities
Converts HTML entities to the final character similarly to whatHtmlCompat.fromHTML()
or the Android XML parser would do.The following conversions are performed:
"&"
to"&"
"<"
to"<"
">"
to">"
Only the HTML entities supported by the Android XML parser are converted.
- Parameters:
string
- A string that may contain HTML entities.- Returns:
- The finally rendered string.
-
isClassPresent
Checks, using reflection, if the provided class is available at runtime. -
isAppcompatPresent
public static boolean isAppcompatPresent()Checks ifAndroidx.appcompat
classes are available at runtime. -
isMaterialComponentsPresent
public static boolean isMaterialComponentsPresent()Checks ifMaterial Components
classes are available at runtime.
-