private boolean isLegacyAssetManager() { return ShadowAssetManager.useLegacy(); }
private ShadowLegacyAssetManager getShadowAssetManager() { return legacyShadowOf(getResources().getAssets()); }
ResName defStyleName = getResName(defStyleAttr); defStyleFromAttr = resolveStyle(defStyleResName, themeStyleSet); ResName styleAttributeResName = getResName(set.getStyleAttribute()); while (styleAttributeResName.type.equals("attr")) { AttributeResource attrValue = themeStyleSet.getAttrValue(styleAttributeResName); styleAttrStyle = resolveStyle(styleAttributeResName, themeStyleSet); ResName resName = getResName(defStyleRes); if (resName.type.equals("attr")) { AttributeResource attributeValue = findAttributeValue(defStyleRes, set, styleAttrStyle, defStyleFromAttr, defStyleFromAttr, themeStyleSet); if (attributeValue != null) { if (attributeValue.isStyleReference()) { defStyleFromRes = resolveStyle(resName, themeStyleSet); AttributeResource attribute = findAttributeValue(resId, set, styleAttrStyle, defStyleFromAttr, defStyleFromRes, themeStyleSet); while (attribute != null && attribute.isStyleReference()) { ResName otherAttrName = attribute.getStyleReference(); strictError("no such attr %s in %s while resolving value for %s", attribute.value, themeStyleSet, resName.getFullyQualifiedName()); attribute = null; } else { } else { TypedValue typedValue = new TypedValue(); convertAndFill(attribute, typedValue, RuntimeEnvironment.getQualifiers(), true);
@HiddenApi @Implementation public int[] getArrayIntResource(int resId) { TypedResource value = getAndResolve(resId, RuntimeEnvironment.getQualifiers(), true); if (value == null) return null; List<TypedResource> items = getConverter(value).getItems(value); int[] ints = new int[items.size()]; for (int i = 0; i < items.size(); i++) { TypedResource typedResource = resolve(items.get(i), RuntimeEnvironment.getQualifiers(), resId); ints[i] = getConverter(typedResource).asInt(typedResource); } return ints; }
protected TypedArray getTypedArrayResource(Resources resources, int resId) { TypedResource value = getAndResolve(resId, RuntimeEnvironment.getQualifiers(), true); if (value == null) { return null; } List<TypedResource> items = getConverter(value).getItems(value); return getTypedArray(resources, items, resId); }
public XmlResourceParser loadXmlResourceParser(int resId, String type) throws Resources.NotFoundException { ResName resName = getResName(resId); ResName resolvedResName = resolveResName(resName, RuntimeEnvironment.getQualifiers()); if (resolvedResName == null) { throw new RuntimeException("couldn't resolve " + resName.getFullyQualifiedName()); } resName = resolvedResName; XmlBlock block = resourceTable.getXml(resName, RuntimeEnvironment.getQualifiers()); if (block == null) { throw new Resources.NotFoundException(resName.getFullyQualifiedName()); } ResourceTable resourceProvider = ResourceIds.isFrameworkResource(resId) ? RuntimeEnvironment.getSystemResourceTable() : RuntimeEnvironment.getCompileTimeResourceTable(); return getXmlResourceParser(resourceProvider, block, resName.packageName); }
int type = getResourceType(typedResource); if (type == -1) { typedValue.resourceId = resourceTable.getResourceId(refResName); typedValue.data = typedValue.resourceId; typedResource = resolve(typedResource, RuntimeEnvironment.getQualifiers(), typedValue.resourceId); type = getResourceType(typedResource); if (type == TypedValue.TYPE_ATTRIBUTE) { type = TypedValue.TYPE_REFERENCE; getConverter(typedResource).fillTypedValue(typedResource.getData(), typedValue);
@Test public void whenStyleAttrResolutionFails_attrsToTypedArray_returnsNiceErrorMessage() throws Exception { if (!useLegacy()) return; expectedException.expect(RuntimeException.class); expectedException.expectMessage( "no value for org.robolectric:attr/styleNotSpecifiedInAnyTheme " + "in theme with applied styles: [Style org.robolectric:Theme.Robolectric (and parents)]"); Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_Robolectric, false); legacyShadowOf(assetManager) .attrsToTypedArray( resources, Robolectric.buildAttributeSet() .setStyleAttribute("?attr/styleNotSpecifiedInAnyTheme") .build(), new int[] {R.attr.string1}, 0, ((ShadowLegacyTheme) Shadow.extract(theme)).getNativePtr(), 0); }
@HiddenApi @Implementation public boolean getResourceValue(int ident, int density, TypedValue outValue, boolean resolveRefs) { TypedResource value = getAndResolve(ident, RuntimeEnvironment.getQualifiers(), resolveRefs); if (value == null) return false; getConverter(value).fillTypedValue(value.getData(), outValue); return true; }
@Implementation public String getResourceEntryName(int resid) { return getResName(resid).name; } }
public TypedResource resolveResourceValue(TypedResource value, String qualifiers, int resId) { ResName resName = getResName(resId); return resolveResourceValue(value, qualifiers, resName); }
Style resolveStyle(int resId, Style themeStyleSet) { return resolveStyle(getResName(resId), themeStyleSet); }
@Implementation public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { return shadowOf(realResources.getAssets()) .attrsToTypedArray(realResources, set, attrs, 0, null, 0); }
public XmlResourceParser loadXmlResourceParser(int resId, String type) throws Resources.NotFoundException { ResName resName = getResName(resId); ResName resolvedResName = resolveResName(resName, RuntimeEnvironment.getQualifiers()); if (resolvedResName == null) { throw new RuntimeException("couldn't resolve " + resName.getFullyQualifiedName()); } resName = resolvedResName; XmlBlock block = getResourceLoader().getXml(resName, RuntimeEnvironment.getQualifiers()); if (block == null) { throw new Resources.NotFoundException(resName.getFullyQualifiedName()); } return ResourceParser.from(block, resName.packageName, getResourceLoader()); }
@HiddenApi @Implementation public XmlResourceParser loadXmlResourceParser(int resId, String type) throws Resources.NotFoundException { ShadowAssetManager shadowAssetManager = shadowOf(realResources.getAssets()); return shadowAssetManager.loadXmlResourceParser(resId, type); }
static void setCreatedFromResId(Resources resources, int id, Drawable drawable) { // todo: this kinda sucks, find some better way... if (drawable != null) { shadowOf(drawable).createdFromResId = id; if (drawable instanceof BitmapDrawable) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); if (bitmap != null) { ShadowBitmap shadowBitmap = shadowOf(bitmap); if (shadowBitmap.createdFromResId == -1) { shadowBitmap.setCreatedFromResId(id, shadowOf(resources.getAssets()).getResourceName(id)); } } } } }
@HiddenApi @Implementation public CharSequence getResourceText(int ident) { TypedResource value = getAndResolve(ident, RuntimeEnvironment.getQualifiers(), true); if (value == null) return null; return (CharSequence) value.getData(); }
@HiddenApi @Implementation public String[] getResourceStringArray(final int id) { CharSequence[] resourceTextArray = getResourceTextArray(id); if (resourceTextArray == null) return null; String[] strings = new String[resourceTextArray.length]; for (int i = 0; i < strings.length; i++) { strings[i] = resourceTextArray[i].toString(); } return strings; }
ResName defStyleName = getResName(defStyleAttr); defStyleFromAttr = resolveStyle(defStyleResName, themeStyleSet); ResName styleAttributeResName = getResName(set.getStyleAttribute()); while (styleAttributeResName.type.equals("attr")) { AttributeResource attrValue = themeStyleSet.getAttrValue(styleAttributeResName); styleAttrStyle = resolveStyle(styleAttributeResName, themeStyleSet); ResName resName = getResName(defStyleRes); if (resName.type.equals("attr")) { AttributeResource attributeValue = findAttributeValue(defStyleRes, set, styleAttrStyle, defStyleFromAttr, defStyleFromAttr, themeStyleSet); if (attributeValue != null) { if (attributeValue.isStyleReference()) { defStyleFromRes = resolveStyle(resName, themeStyleSet); AttributeResource attribute = findAttributeValue(resId, set, styleAttrStyle, defStyleFromAttr, defStyleFromRes, themeStyleSet); while (attribute != null && attribute.isStyleReference()) { ResName otherAttrName = attribute.getStyleReference(); strictError("no such attr %s in %s while resolving value for %s", attribute.value, themeStyleSet, resName.getFullyQualifiedName()); attribute = null; } else { } else { TypedValue typedValue = new TypedValue(); convertAndFill(attribute, typedValue, RuntimeEnvironment.getQualifiers(), true);
@HiddenApi @Implementation public CharSequence[] getResourceTextArray(int resId) { TypedResource value = getAndResolve(resId, RuntimeEnvironment.getQualifiers(), true); if (value == null) return null; List<TypedResource> items = getConverter(value).getItems(value); CharSequence[] charSequences = new CharSequence[items.size()]; for (int i = 0; i < items.size(); i++) { TypedResource typedResource = resolve(items.get(i), RuntimeEnvironment.getQualifiers(), resId); charSequences[i] = getConverter(typedResource).asCharSequence(typedResource); } return charSequences; }