Search in sources :

Example 1 with Plural

use of org.robolectric.res.Plural in project robolectric by robolectric.

the class ShadowResourcesImpl method getQuantityString.

@Implementation
public String getQuantityString(int resId, int quantity) throws Resources.NotFoundException {
    ShadowAssetManager shadowAssetManager = shadowOf(realResourcesImpl.getAssets());
    TypedResource typedResource = shadowAssetManager.getResourceTable().getValue(resId, RuntimeEnvironment.getQualifiers());
    if (typedResource != null && typedResource instanceof PluralResourceLoader.PluralRules) {
        PluralResourceLoader.PluralRules pluralRules = (PluralResourceLoader.PluralRules) typedResource;
        Plural plural = pluralRules.find(quantity);
        if (plural == null) {
            return null;
        }
        TypedResource<?> resolvedTypedResource = shadowAssetManager.resolve(new TypedResource<>(plural.getString(), ResType.CHAR_SEQUENCE, pluralRules.getXmlContext()), RuntimeEnvironment.getQualifiers(), resId);
        return resolvedTypedResource == null ? null : resolvedTypedResource.asString();
    } else {
        return null;
    }
}
Also used : TypedResource(org.robolectric.res.TypedResource) Plural(org.robolectric.res.Plural) PluralResourceLoader(org.robolectric.res.PluralResourceLoader)

Aggregations

Plural (org.robolectric.res.Plural)1 PluralResourceLoader (org.robolectric.res.PluralResourceLoader)1 TypedResource (org.robolectric.res.TypedResource)1