Package com.transifex.txnative
Class Utils
java.lang.Object
com.transifex.txnative.Utils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanstatic SpannedInvokesHtml.fromHtml(String, int)on API 24 and newer, otherwiseflagsare ignored andHtml.fromHtml(String)is used.static LocalegetCurrentLocale(Context context) Utility method to get the current locale as set in Android.static ResourcesgetDefaultLocaleResources(Context context) Returns aResourcesobject configured for the default (non localized) resources.static ResourcesgetLocalizedResources(Context context, Locale desiredLocale) Returns a Resources object, derived from the one in the provided context, which uses the desired locale.static intgetStringResourceId(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 booleanChecks ifAndroidx.appcompatclasses are available at runtime.static booleanisClassPresent(String className) Checks, using reflection, if the provided class is available at runtime.static booleanChecks ifMaterial Componentsclasses are available at runtime.static voidprintAttributeSet(Context context, AttributeSet attrs) static StringunescapeHTMLEntities(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 aResourcesobject 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, otherwiseflagsare 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.appcompatclasses are available at runtime. -
isMaterialComponentsPresent
public static boolean isMaterialComponentsPresent()Checks ifMaterial Componentsclasses are available at runtime.
-