public final class BridgeResources extends Resources
Modifier and Type | Class and Description |
---|---|
class |
BridgeResources.NinePatchInputStream
Simpler wrapper around FileInputStream.
|
Resources.NotFoundException, Resources.Theme
Modifier and Type | Method and Description |
---|---|
static void |
disposeSystem()
Disposes the static
Resources.mSystem to make sure we don't leave objects
around that would prevent us from unloading the library. |
XmlResourceParser |
getAnimation(int id)
Return an XmlResourceParser through which you can read an animation
description for the given resource ID.
|
boolean |
getBoolean(int id)
Return a boolean associated with a particular resource ID.
|
int |
getColor(int id)
Return a color integer associated with a particular resource ID.
|
ColorStateList |
getColorStateList(int id)
Return a color state list associated with a particular resource ID.
|
float |
getDimension(int id)
Retrieve a dimensional for a particular resource ID.
|
int |
getDimensionPixelOffset(int id)
Retrieve a dimensional for a particular resource ID for use
as an offset in raw pixels.
|
int |
getDimensionPixelSize(int id)
Retrieve a dimensional for a particular resource ID for use
as a size in raw pixels.
|
Drawable |
getDrawable(int id)
Return a drawable object associated with a particular resource ID.
|
int |
getInteger(int id)
Return an integer associated with a particular resource ID.
|
XmlResourceParser |
getLayout(int id)
Return an XmlResourceParser through which you can read a view layout
description for the given resource ID.
|
String |
getResourceEntryName(int resid)
Return the entry name for a given resource identifier.
|
String |
getResourceName(int resid)
Return the full name for a given resource identifier.
|
String |
getResourceTypeName(int resid)
Return the type name for a given resource identifier.
|
String |
getString(int id)
Return the string value associated with a particular resource ID.
|
String |
getString(int id,
Object... formatArgs)
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...) . |
CharSequence |
getText(int id)
Return the string value associated with a particular resource ID.
|
void |
getValue(int id,
TypedValue outValue,
boolean resolveRefs)
Return the raw data associated with a particular resource ID.
|
void |
getValue(String name,
TypedValue outValue,
boolean resolveRefs)
Return the raw data associated with a particular resource ID.
|
XmlResourceParser |
getXml(int id)
Return an XmlResourceParser through which you can read a generic XML
resource for the given resource ID.
|
static Resources |
initSystem(com.android.layoutlib.bridge.android.BridgeContext context,
AssetManager assets,
DisplayMetrics metrics,
Configuration config,
IProjectCallback projectCallback)
This initializes the static field
Resources.mSystem which is used
by methods who get global resources using Resources.getSystem() . |
XmlResourceParser |
loadXmlResourceParser(String file,
int id,
int assetCookie,
String type) |
BridgeTypedArray |
newTypeArray(int numEntries,
boolean platformFile) |
TypedArray |
obtainAttributes(AttributeSet set,
int[] attrs)
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)
Return an array of heterogeneous values.
|
InputStream |
openRawResource(int id)
Open a data stream for reading a raw resource.
|
InputStream |
openRawResource(int id,
TypedValue value)
Open a data stream for reading a raw resource.
|
AssetFileDescriptor |
openRawResourceFd(int id)
Open a file descriptor for reading a raw resource.
|
finishPreloading, flushLayoutCache, getAssets, getCompatibilityInfo, getConfiguration, getDisplayMetrics, getDrawableForDensity, getFraction, getIdentifier, getIntArray, getMovie, getQuantityString, getQuantityString, getQuantityText, getResourcePackageName, getStringArray, getSystem, getText, getTextArray, getValueForDensity, newTheme, parseBundleExtra, parseBundleExtras, selectDefaultTheme, selectSystemTheme, setCompatibilityInfo, startPreloading, updateConfiguration, updateConfiguration, updateSystemConfiguration, updateSystemConfiguration
public static Resources initSystem(com.android.layoutlib.bridge.android.BridgeContext context, AssetManager assets, DisplayMetrics metrics, Configuration config, IProjectCallback projectCallback)
Resources.mSystem
which is used
by methods who get global resources using Resources.getSystem()
.
They will end up using our bridge resources.
Bridge
calls this method after setting up a new bridge.public static void disposeSystem()
Resources.mSystem
to make sure we don't leave objects
around that would prevent us from unloading the library.public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile)
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 retrieve the Drawable through
TypedArray.getDrawable
. Use
Context.obtainStyledAttributes
with
an array containing the resource ID of interest to create the TypedArray.
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.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 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 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 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 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 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 boolean getBoolean(int id) throws Resources.NotFoundException
Resources
getBoolean
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 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)
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 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 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 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 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 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 XmlResourceParser loadXmlResourceParser(String file, int id, int assetCookie, String type) throws Resources.NotFoundException
Resources.NotFoundException
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 InputStream openRawResource(int id, TypedValue value) throws Resources.NotFoundException
Resources
openRawResource
in class Resources
id
- The resource identifier to open, as generated by the appt tool.value
- The TypedValue object to hold the resource information.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.