Package org.robolectric.shadows
Class ShadowResources
java.lang.Object
org.robolectric.shadows.ShadowResources
@Implements(android.content.res.Resources.class) public class ShadowResources extends Object
Shadow of
Resources
.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ShadowResources.OnConfigurationChangeListener
Listener callback that's called when the configuration is updated for a resources.static class
ShadowResources.ShadowLegacyTheme
Shadow forResources.Theme
.static class
ShadowResources.ShadowNotFoundException
Shadow forResources.NotFoundException
.static class
ShadowResources.ShadowTheme
Base class for shadows ofResources.Theme
. -
Constructor Summary
Constructors Constructor Description ShadowResources()
-
Method Summary
Modifier and Type Method Description void
addConfigurationChangeListener(ShadowResources.OnConfigurationChangeListener listener)
Add a listener to observe resource configuration changes.static int
getAttributeSetSourceResId(AttributeSet attrs)
Returns the layout resource id the attribute set was inflated from.protected String
getQuantityString(int resId, int quantity)
protected String
getQuantityString(int id, int quantity, Object... formatArgs)
protected static Resources
getSystem()
protected Drawable
loadDrawable(TypedValue value, int id)
protected Drawable
loadDrawable(TypedValue value, int id, Resources.Theme theme)
protected XmlResourceParser
loadXmlResourceParser(int resId, String type)
protected XmlResourceParser
loadXmlResourceParser(String file, int id, int assetCookie, String type)
protected TypedArray
obtainAttributes(AttributeSet set, int[] attrs)
protected TypedArray
obtainTypedArray(int id)
protected InputStream
openRawResource(int id)
protected AssetFileDescriptor
openRawResourceFd(int id)
SinceAssetFileDescriptor
s are not yet supported by Robolectric,null
will be returned if the resource is found.void
removeConfigurationChangeListener(ShadowResources.OnConfigurationChangeListener listener)
Remove a listener to observe resource configuration changes.static void
reset()
protected void
updateConfiguration(Configuration config, DisplayMetrics metrics, CompatibilityInfo compat)
-
Constructor Details
-
ShadowResources
public ShadowResources()
-
-
Method Details
-
reset
-
getSystem
-
obtainAttributes
-
getQuantityString
@Implementation protected String getQuantityString(int id, int quantity, Object... formatArgs) throws Resources.NotFoundException- Throws:
Resources.NotFoundException
-
getQuantityString
@Implementation protected String getQuantityString(int resId, int quantity) throws Resources.NotFoundException- Throws:
Resources.NotFoundException
-
openRawResource
- Throws:
Resources.NotFoundException
-
openRawResourceFd
@Implementation protected AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundExceptionSinceAssetFileDescriptor
s are not yet supported by Robolectric,null
will be returned if the resource is found. If the resource cannot be found,Resources.NotFoundException
will be thrown.- Throws:
Resources.NotFoundException
-
obtainTypedArray
- Throws:
Resources.NotFoundException
-
loadXmlResourceParser
@HiddenApi @Implementation protected XmlResourceParser loadXmlResourceParser(int resId, String type) throws Resources.NotFoundException- Throws:
Resources.NotFoundException
-
loadXmlResourceParser
@HiddenApi @Implementation protected XmlResourceParser loadXmlResourceParser(String file, int id, int assetCookie, String type) throws Resources.NotFoundException- Throws:
Resources.NotFoundException
-
loadDrawable
-
loadDrawable
@Implementation(minSdk=21, maxSdk=25) protected Drawable loadDrawable(TypedValue value, int id, Resources.Theme theme) throws Resources.NotFoundException- Throws:
Resources.NotFoundException
-
getAttributeSetSourceResId
Returns the layout resource id the attribute set was inflated from. Backwards compatible version ofResources.getAttributeSetSourceResId(AttributeSet)
, passes through to the underlying implementation on API levels where it is supported. -
addConfigurationChangeListener
Add a listener to observe resource configuration changes. SeeShadowResources.OnConfigurationChangeListener
. -
removeConfigurationChangeListener
public void removeConfigurationChangeListener(ShadowResources.OnConfigurationChangeListener listener)Remove a listener to observe resource configuration changes. SeeShadowResources.OnConfigurationChangeListener
. -
updateConfiguration
@Implementation protected void updateConfiguration(Configuration config, DisplayMetrics metrics, CompatibilityInfo compat)
-