@Deprecated public class MockResources extends Resources
Resources
class. All methods are non-functional and throw
UnsupportedOperationException
. Override it to provide the operations that you
need.Resources.NotFoundException, Resources.Theme
Constructor and Description |
---|
MockResources()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
XmlResourceParser |
getAnimation(int id)
Deprecated.
Return an XmlResourceParser through which you can read an animation
description for the given resource ID.
|
int |
getColor(int id)
Deprecated.
Returns a color integer associated with a particular resource ID.
|
ColorStateList |
getColorStateList(int id)
Deprecated.
Returns a color state list associated with a particular resource ID.
|
Configuration |
getConfiguration()
Deprecated.
Return the current configuration that is in effect for this resource
object.
|
float |
getDimension(int id)
Deprecated.
Retrieve a dimensional for a particular resource ID.
|
int |
getDimensionPixelOffset(int id)
Deprecated.
Retrieve a dimensional for a particular resource ID for use
as an offset in raw pixels.
|
int |
getDimensionPixelSize(int id)
Deprecated.
Retrieve a dimensional for a particular resource ID for use
as a size in raw pixels.
|
DisplayMetrics |
getDisplayMetrics()
Deprecated.
Return the current display metrics that are in effect for this resource
object.
|
Drawable |
getDrawable(int id)
Deprecated.
Return a drawable object associated with a particular resource ID.
|
int |
getIdentifier(String name,
String defType,
String defPackage)
Deprecated.
Return a resource identifier for the given resource name.
|
int[] |
getIntArray(int id)
Deprecated.
Return the int array associated with a particular resource ID.
|
int |
getInteger(int id)
Deprecated.
Return an integer associated with a particular resource ID.
|
XmlResourceParser |
getLayout(int id)
Deprecated.
Return an XmlResourceParser through which you can read a view layout
description for the given resource ID.
|
Movie |
getMovie(int id)
Deprecated.
Return a movie object associated with the particular resource ID.
|
String |
getQuantityString(int id,
int quantity)
Deprecated.
Returns the string necessary for grammatically correct pluralization
of the given resource ID for the given quantity.
|
String |
getQuantityString(int id,
int quantity,
Object... formatArgs)
Deprecated.
Formats the string necessary for grammatically correct pluralization
of the given resource ID for the given quantity, using the given arguments.
|
CharSequence |
getQuantityText(int id,
int quantity)
Deprecated.
Returns the character sequence necessary for grammatically correct pluralization
of the given resource ID for the given quantity.
|
String |
getResourceEntryName(int resid)
Deprecated.
Return the entry name for a given resource identifier.
|
String |
getResourceName(int resid)
Deprecated.
Return the full name for a given resource identifier.
|
String |
getResourcePackageName(int resid)
Deprecated.
Return the package name for a given resource identifier.
|
String |
getResourceTypeName(int resid)
Deprecated.
Return the type name for a given resource identifier.
|
String |
getString(int id)
Deprecated.
Return the string value associated with a particular resource ID.
|
String |
getString(int id,
Object... formatArgs)
Deprecated.
Return the string value associated with a particular resource ID,
substituting the format arguments as defined in
Formatter
and String.format(java.lang.String, java.lang.Object...) . |
String[] |
getStringArray(int id)
Deprecated.
Return the string array associated with a particular resource ID.
|
CharSequence |
getText(int id)
Deprecated.
Return the string value associated with a particular resource ID.
|
CharSequence |
getText(int id,
CharSequence def)
Deprecated.
Return the string value associated with a particular resource ID.
|
CharSequence[] |
getTextArray(int id)
Deprecated.
Return the styled text array associated with a particular resource ID.
|
void |
getValue(int id,
TypedValue outValue,
boolean resolveRefs)
Deprecated.
Return the raw data associated with a particular resource ID.
|
void |
getValue(String name,
TypedValue outValue,
boolean resolveRefs)
Deprecated.
Return the raw data associated with a particular resource ID.
|
XmlResourceParser |
getXml(int id)
Deprecated.
Return an XmlResourceParser through which you can read a generic XML
resource for the given resource ID.
|
TypedArray |
obtainAttributes(AttributeSet set,
int[] attrs)
Deprecated.
Retrieve a set of basic attribute values from an AttributeSet, not
performing styling of them using a theme and/or style resources.
|
TypedArray |
obtainTypedArray(int id)
Deprecated.
Return an array of heterogeneous values.
|
InputStream |
openRawResource(int id)
Deprecated.
Open a data stream for reading a raw resource.
|
AssetFileDescriptor |
openRawResourceFd(int id)
Deprecated.
Open a file descriptor for reading a raw resource.
|
void |
updateConfiguration(Configuration config,
DisplayMetrics metrics)
Deprecated.
Store the newly updated configuration.
|
calcConfigChanges, finishPreloading, flushLayoutCache, getAnimatorCache, getAssets, getBoolean, getClassLoader, getColor, getColorStateList, getCompatibilityInfo, getDisplayAdjustments, getDrawable, getDrawableForDensity, getDrawableForDensity, getDrawableInflater, getFloat, getFraction, getImpl, getPreloadedDrawables, getSizeConfigurations, getStateListAnimatorCache, getSystem, getValueForDensity, loadComplexColor, newTheme, obtainAttributes, openRawResource, parseBundleExtra, parseBundleExtras, resourceHasPackage, selectDefaultTheme, selectSystemTheme, setCompatibilityInfo, setImpl, startPreloading, updateConfiguration, updateSystemConfiguration
public void updateConfiguration(Configuration config, DisplayMetrics metrics)
Resources
updateConfiguration
in class Resources
public CharSequence getText(int id) throws Resources.NotFoundException
Resources
getText
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public CharSequence getQuantityText(int id, int quantity) throws Resources.NotFoundException
Resources
getQuantityText
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.quantity
- The number used to get the correct string for the current language's
plural rules.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String getString(int id) throws Resources.NotFoundException
Resources
getString
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String getString(int id, Object... formatArgs) throws Resources.NotFoundException
Resources
Formatter
and String.format(java.lang.String, java.lang.Object...)
. It will be stripped of any styled text
information.
getString
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.formatArgs
- The format arguments that will be used for substitution.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String getQuantityString(int id, int quantity, Object... formatArgs) throws Resources.NotFoundException
Resources
Substitution of format arguments works as if using
Formatter
and String.format(java.lang.String, java.lang.Object...)
.
The resulting string will be stripped of any styled text information.
getQuantityString
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.quantity
- The number used to get the correct string for the current language's
plural rules.formatArgs
- The format arguments that will be used for substitution.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String getQuantityString(int id, int quantity) throws Resources.NotFoundException
Resources
getQuantityString
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.quantity
- The number used to get the correct string for the current language's
plural rules.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public CharSequence getText(int id, CharSequence def)
Resources
getText
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.def
- The default CharSequence to return.public CharSequence[] getTextArray(int id) throws Resources.NotFoundException
Resources
getTextArray
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String[] getStringArray(int id) throws Resources.NotFoundException
Resources
getStringArray
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public int[] getIntArray(int id) throws Resources.NotFoundException
Resources
getIntArray
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public TypedArray obtainTypedArray(int id) throws Resources.NotFoundException
Resources
obtainTypedArray
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.TypedArray.recycle()
when done with it.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public float getDimension(int id) throws Resources.NotFoundException
Resources
DisplayMetrics
associated
with the resources.getDimension
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getDimensionPixelOffset(int)
,
Resources.getDimensionPixelSize(int)
public int getDimensionPixelOffset(int id) throws Resources.NotFoundException
Resources
Resources.getDimension(int)
, except the returned value is converted to
integer pixels for you. An offset conversion involves simply
truncating the base value to an integer.getDimensionPixelOffset
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getDimension(int)
,
Resources.getDimensionPixelSize(int)
public int getDimensionPixelSize(int id) throws Resources.NotFoundException
Resources
Resources.getDimension(int)
, except the returned value is converted to
integer pixels for use as a size. A size conversion involves
rounding the base value, and ensuring that a non-zero base value
is at least one pixel in size.getDimensionPixelSize
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getDimension(int)
,
Resources.getDimensionPixelOffset(int)
public Drawable getDrawable(int id) throws Resources.NotFoundException
Resources
Note: Prior to
Build.VERSION_CODES.JELLY_BEAN
, this function
would not correctly retrieve the final configuration density when
the resource ID passed here is an alias to another Drawable resource.
This means that if the density configuration of the alias resource
is different than the actual resource, the density of the returned
Drawable would be incorrect, resulting in bad scaling. To work
around this, you can instead manually resolve the aliased reference
by using Resources.getValue(int, TypedValue, boolean)
and passing
true
for resolveRefs
. The resulting
TypedValue.resourceId
value may be passed to this method.
Note: To obtain a themed drawable, use
Context.getDrawable(int)
or Resources.getDrawable(int, Theme)
passing the desired theme.
getDrawable
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.Resources.getDrawable(int, Theme)
public Movie getMovie(int id) throws Resources.NotFoundException
Resources
getMovie
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public int getColor(int id) throws Resources.NotFoundException
Resources
ColorStateList
, then the default color
from the set is returned.getColor
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.public ColorStateList getColorStateList(int id) throws Resources.NotFoundException
Resources
ColorStateList
holding multiple possible colors.getColorStateList
in class Resources
id
- The desired resource identifier of a ColorStateList
,
as generated by the aapt tool. This integer encodes the
package, type, and resource entry. The value 0 is an invalid
identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.public int getInteger(int id) throws Resources.NotFoundException
Resources
getInteger
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public XmlResourceParser getLayout(int id) throws Resources.NotFoundException
Resources
This function is really a simple wrapper for calling
Resources.getXml(int)
with a layout resource.
getLayout
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getXml(int)
public XmlResourceParser getAnimation(int id) throws Resources.NotFoundException
Resources
This function is really a simple wrapper for calling
Resources.getXml(int)
with an animation resource.
getAnimation
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getXml(int)
public XmlResourceParser getXml(int id) throws Resources.NotFoundException
Resources
The XmlPullParser implementation returned here has some limited functionality. In particular, you can't change its input, and only high-level parsing events are available (since the document was pre-parsed for you at build time, which involved merging text and stripping comments).
getXml
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.AttributeSet
public InputStream openRawResource(int id) throws Resources.NotFoundException
Resources
openRawResource
in class Resources
id
- The resource identifier to open, as generated by the appt
tool.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException
Resources
This function only works for resources that are stored in the package as uncompressed data, which typically includes things like mp3 files and png images.
openRawResourceFd
in class Resources
id
- The resource identifier to open, as generated by the appt
tool.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public void getValue(int id, TypedValue outValue, boolean resolveRefs) throws Resources.NotFoundException
Resources
getValue
in class Resources
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.outValue
- Object in which to place the resource data.resolveRefs
- If true, a resource that is a reference to another
resource will be followed so that you receive the
actual final resource data. If false, the TypedValue
will be filled in with the reference itself.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public void getValue(String name, TypedValue outValue, boolean resolveRefs) throws Resources.NotFoundException
Resources
Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.
getValue
in class Resources
name
- The name of the desired resource. This is passed to
getIdentifier() with a default type of "string".outValue
- Object in which to place the resource data.resolveRefs
- If true, a resource that is a reference to another
resource will be followed so that you receive the
actual final resource data. If false, the TypedValue
will be filled in with the reference itself.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public TypedArray obtainAttributes(AttributeSet set, int[] attrs)
Resources
obtainAttributes
in class Resources
set
- The current attribute values to retrieve.attrs
- The specific attributes to be retrieved.TypedArray.recycle()
when done with it.Resources.Theme.obtainStyledAttributes(AttributeSet, int[], int, int)
public DisplayMetrics getDisplayMetrics()
Resources
getDisplayMetrics
in class Resources
public Configuration getConfiguration()
Resources
getConfiguration
in class Resources
public int getIdentifier(String name, String defType, String defPackage)
Resources
Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.
getIdentifier
in class Resources
name
- The name of the desired resource.defType
- Optional default resource type to find, if "type/" is
not included in the name. Can be null to require an
explicit type.defPackage
- Optional default package to find, if "package:" is
not included in the name. Can be null to require an
explicit package.public String getResourceName(int resid) throws Resources.NotFoundException
Resources
getResourceName
in class Resources
resid
- The resource identifier whose name is to be retrieved.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getResourcePackageName(int)
,
Resources.getResourceTypeName(int)
,
Resources.getResourceEntryName(int)
public String getResourcePackageName(int resid) throws Resources.NotFoundException
Resources
getResourcePackageName
in class Resources
resid
- The resource identifier whose package name is to be
retrieved.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getResourceName(int)
public String getResourceTypeName(int resid) throws Resources.NotFoundException
Resources
getResourceTypeName
in class Resources
resid
- The resource identifier whose type name is to be
retrieved.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getResourceName(int)
public String getResourceEntryName(int resid) throws Resources.NotFoundException
Resources
getResourceEntryName
in class Resources
resid
- The resource identifier whose entry name is to be
retrieved.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.getResourceName(int)