MockResources
open class MockResources : Resources
A mock android.content.res.Resources
class. All methods are non-functional and throw java.lang.UnsupportedOperationException
. Override it to provide the operations that you need.
Summary
Inherited constants |
From class Resources
Int |
ID_NULL
The null resource ID. This denotes an invalid resource ID that is returned by the system when a resource is not found or the value is set to @null in XML.
|
|
Inherited functions |
From class Resources
Unit |
addLoaders(vararg loaders: ResourcesLoader!)
Adds a loader to the list of loaders. If the loader is already present in the list, the list will not be modified.
This should only be called from the UI thread to avoid lock contention when propagating loader changes.
|
Unit |
finishPreloading()
Called by zygote when it is done preloading resources, to change back to normal Resources operation.
|
Unit |
flushLayoutCache()
Call this to remove all cached loaded layout resources from the Resources object. Only intended for use with performance testing tools.
|
AssetManager! |
getAssets()
Retrieve underlying AssetManager storage for these resources.
|
Int |
getAttributeSetSourceResId(set: AttributeSet?)
Returns the resource ID of the resource that was used to create this AttributeSet.
|
Boolean |
getBoolean(id: Int)
Return a boolean associated with a particular resource ID. This can be used with any integral resource value, and will return true if it is non-zero.
|
Int |
getColor(id: Int, theme: Resources.Theme?)
Returns a themed color integer associated with a particular resource ID. If the resource holds a complex ColorStateList , then the default color from the set is returned.
|
ColorStateList |
getColorStateList(id: Int, theme: Resources.Theme?)
Returns a themed color state list associated with a particular resource ID. The resource may contain either a single raw color value or a complex ColorStateList holding multiple possible colors.
|
Drawable! |
getDrawable(id: Int, theme: Resources.Theme?)
Return a drawable object associated with a particular resource ID and styled for the specified theme. Various types of objects will be returned depending on the underlying resource -- for example, a solid color, PNG image, scalable image, etc.
|
Drawable? |
getDrawableForDensity(id: Int, density: Int)
Return a drawable object associated with a particular resource ID for the given screen density in DPI. This will set the drawable's density to be the device's density multiplied by the ratio of actual drawable density to requested density. This allows the drawable to be scaled up to the correct size if needed. Various types of objects will be returned depending on the underlying resource -- for example, a solid color, PNG image, scalable image, etc. The Drawable API hides these implementation details.
Note: To obtain a themed drawable, use Context.getDrawable(int) or getDrawableForDensity(int,int,android.content.res.Resources.Theme) passing the desired theme.
|
Drawable? |
getDrawableForDensity(id: Int, density: Int, theme: Resources.Theme?)
Return a drawable object associated with a particular resource ID for the given screen density in DPI and styled for the specified theme.
|
Float |
getFloat(id: Int)
Retrieve a floating-point value for a particular resource ID.
|
Typeface |
getFont(id: Int)
Return the Typeface value associated with a particular resource ID. {@more}
|
Float |
getFraction(id: Int, base: Int, pbase: Int)
Retrieve a fractional unit for a particular resource ID.
|
Resources! |
getSystem()
Return a global shared Resources object that provides access to only system resources (no application resources), is not configured for the current screen (can not use dimension units, does not change based on orientation, etc), and is not affected by Runtime Resource Overlay.
|
Unit |
getValueForDensity(id: Int, density: Int, outValue: TypedValue!, resolveRefs: Boolean)
Get the raw value associated with a resource with associated density.
|
Resources.Theme! |
newTheme()
Generate a new Theme object for this set of Resources. It initially starts out empty.
|
InputStream |
openRawResource(id: Int, value: TypedValue!)
Open a data stream for reading a raw resource. This can only be used with resources whose value is the name of an asset file -- that is, it can be used to open drawable, sound, and raw resources; it will fail on string and color resources.
|
Unit |
parseBundleExtra(tagName: String!, attrs: AttributeSet!, outBundle: Bundle!)
Parse a name/value pair out of an XML tag holding that data. The AttributeSet must be holding the data defined by android.R.styleable#Extra . The following value types are supported:
|
Unit |
parseBundleExtras(parser: XmlResourceParser!, outBundle: Bundle!)
Parse a series of <extra> tags from an XML file. You call this when you are at the parent tag of the extra tags, and it will return once all of the child tags have been parsed. This will call parseBundleExtra for each extra tag encountered.
|
Unit |
registerResourcePaths(uniqueId: String, appInfo: ApplicationInfo)
Register the resources paths of a package (e.g. a shared library). This will collect the package resources' paths from its ApplicationInfo and add them to all existing and future contexts while the application is running. A second call with the same uniqueId is a no-op. The paths are not persisted during application restarts. The application is responsible for calling the API again if this happens.
|
Unit |
removeLoaders(vararg loaders: ResourcesLoader!)
Removes loaders from the list of loaders. If the loader is not present in the list, the list will not be modified.
This should only be called from the UI thread to avoid lock contention when propagating loader changes.
|
|
Public constructors
MockResources
MockResources()
Public methods
getAnimation
open fun getAnimation(id: Int): XmlResourceParser
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
XmlResourceParser |
A new parser object through which you can read the XML data. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getColor
open fun getColor(id: Int): Int
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
Int |
A single color value in the form 0xAARRGGBB. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getColorStateList
open fun getColorStateList(id: Int): ColorStateList
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
ColorStateList |
A ColorStateList object containing either a single solid color or multiple colors that can be selected based on a state. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getConfiguration
open fun getConfiguration(): Configuration!
Deprecated: Deprecated in Java.
getDimension
open fun getDimension(id: Int): Float
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
Float |
Resource dimension value multiplied by the appropriate metric to convert to pixels. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getDimensionPixelOffset
open fun getDimensionPixelOffset(id: Int): Int
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
Int |
Resource dimension value multiplied by the appropriate metric and truncated to integer pixels. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getDimensionPixelSize
open fun getDimensionPixelSize(id: Int): Int
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
Int |
Resource dimension value multiplied by the appropriate metric and truncated to integer pixels. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getDisplayMetrics
open fun getDisplayMetrics(): DisplayMetrics!
Deprecated: Deprecated in Java.
getDrawable
open fun getDrawable(id: Int): Drawable!
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
Drawable! |
Drawable An object that can be used to draw this resource. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getIdentifier
open fun getIdentifier(
name: String!,
defType: String!,
defPackage: String!
): Int
Deprecated: Deprecated in Java.
Parameters |
name |
String!: The name of the desired resource. |
defType |
String!: Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type. |
defPackage |
String!: Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package. |
Return |
Int |
int The associated resource identifier. Returns 0 if no such resource was found. (0 is not a valid resource ID.) |
getIntArray
open fun getIntArray(id: Int): IntArray
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
IntArray |
The int array associated with the resource. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getInteger
open fun getInteger(id: Int): Int
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
Int |
Returns the integer value contained in the resource. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getLayout
open fun getLayout(id: Int): XmlResourceParser
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
XmlResourceParser |
A new parser object through which you can read the XML data. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getMovie
open fun getMovie(id: Int): Movie!
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getQuantityString
open fun getQuantityString(
id: Int,
quantity: Int,
vararg formatArgs: Any!
): String
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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 |
Int: The number used to get the correct string for the current language's plural rules. |
formatArgs |
Any!: The format arguments that will be used for substitution. |
Return |
String |
String The string data associated with the resource, stripped of styled text information. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getQuantityString
open fun getQuantityString(
id: Int,
quantity: Int
): String
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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 |
Int: The number used to get the correct string for the current language's plural rules. |
Return |
String |
String The string data associated with the resource, stripped of styled text information. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getQuantityText
open fun getQuantityText(
id: Int,
quantity: Int
): CharSequence
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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 |
Int: The number used to get the correct string for the current language's plural rules. |
Return |
CharSequence |
CharSequence The string data associated with the resource, plus possibly styled text information. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getResourceEntryName
open fun getResourceEntryName(resid: Int): String!
Deprecated: Deprecated in Java.
Parameters |
resid |
Int: The resource identifier whose entry name is to be retrieved. |
Return |
String! |
A string holding the entry name of the resource. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getResourceName
open fun getResourceName(resid: Int): String!
Deprecated: Deprecated in Java.
Parameters |
resid |
Int: The resource identifier whose name is to be retrieved. |
Return |
String! |
A string holding the name of the resource. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getResourcePackageName
open fun getResourcePackageName(resid: Int): String!
Deprecated: Deprecated in Java.
Parameters |
resid |
Int: The resource identifier whose package name is to be retrieved. |
Return |
String! |
A string holding the package name of the resource. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getResourceTypeName
open fun getResourceTypeName(resid: Int): String!
Deprecated: Deprecated in Java.
Parameters |
resid |
Int: The resource identifier whose type name is to be retrieved. |
Return |
String! |
A string holding the type name of the resource. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getString
open fun getString(id: Int): String
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
String |
String The string data associated with the resource, stripped of styled text information. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getString
open fun getString(
id: Int,
vararg formatArgs: Any!
): String
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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 |
Any!: The format arguments that will be used for substitution. |
Return |
String |
String The string data associated with the resource, stripped of styled text information. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getStringArray
open fun getStringArray(id: Int): Array<String!>
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
Array<String!> |
The string array associated with the resource. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getText
open fun getText(id: Int): CharSequence
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
CharSequence |
CharSequence The string data associated with the resource, plus possibly styled text information. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getText
open fun getText(
id: Int,
def: CharSequence!
): CharSequence!
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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 |
CharSequence!: The default CharSequence to return. |
Return |
CharSequence! |
CharSequence The string data associated with the resource, plus possibly styled text information, or def if id is 0 or not found. |
getTextArray
open fun getTextArray(id: Int): Array<CharSequence!>
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
Array<CharSequence!> |
The styled text array associated with the resource. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getValue
open fun getValue(
id: Int,
outValue: TypedValue!,
resolveRefs: Boolean
): Unit
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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 |
TypedValue!: Object in which to place the resource data. |
resolveRefs |
Boolean: 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. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getValue
open fun getValue(
name: String!,
outValue: TypedValue!,
resolveRefs: Boolean
): Unit
Deprecated: Deprecated in Java.
Parameters |
name |
String!: The name of the desired resource. This is passed to getIdentifier() with a default type of "string". |
outValue |
TypedValue!: Object in which to place the resource data. |
resolveRefs |
Boolean: 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. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
getXml
open fun getXml(id: Int): XmlResourceParser
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
XmlResourceParser |
A new parser object through which you can read the XML data. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
obtainAttributes
open fun obtainAttributes(
set: AttributeSet!,
attrs: IntArray!
): TypedArray!
Deprecated: Deprecated in Java.
Parameters |
set |
AttributeSet!: The current attribute values to retrieve. |
attrs |
IntArray!: The specific attributes to be retrieved. These attribute IDs must be sorted in ascending order. |
obtainTypedArray
open fun obtainTypedArray(id: Int): TypedArray
Deprecated: Deprecated in Java.
Parameters |
id |
Int: 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. |
Return |
TypedArray |
Returns a TypedArray holding an array of the array values. Be sure to call TypedArray.recycle() when done with it. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
openRawResource
open fun openRawResource(id: Int): InputStream
Deprecated: Deprecated in Java.
Parameters |
id |
Int: The resource identifier to open, as generated by the aapt tool. |
Return |
InputStream |
InputStream Access to the resource data. This value cannot be null . |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |
openRawResourceFd
open fun openRawResourceFd(id: Int): AssetFileDescriptor!
Deprecated: Deprecated in Java.
Parameters |
id |
Int: The resource identifier to open, as generated by the aapt tool. |
Return |
AssetFileDescriptor! |
AssetFileDescriptor A new file descriptor you can use to read the resource. This includes the file descriptor itself, as well as the offset and length of data where the resource appears in the file. A null is returned if the file exists but is compressed. |
Exceptions |
android.content.res.Resources.NotFoundException |
Throws NotFoundException if the given ID does not exist. |