public final class ResourceValuesXmlParser
extends java.lang.Object
SymbolTable
from a resource XML file. Resource XML files contain
zero or multiple resources of the following types:
Type | XML Tag (*1) | Symbol Type | Java Type |
---|---|---|---|
Animation | anim | anim | int |
Animator | animator | animator | int |
Attribute | attr | attr | int |
Boolean | bool | bool | int |
Color | color | color | int |
Dimension | dimen | dimen | int |
Drawable | drawable | drawable | int |
Enumeration | enum | id | int |
Fraction | fraction | fraction | int |
ID | id | id | int |
Integer | integer | integer | int |
Integer Array | integer-array | array | int |
Menu | menu | menu | int |
MipMap | mipmap | mipmap | int |
Plural | plurals | plurals | int |
Raw | raw | raw | int |
String | string | string | int |
String Array | string-array | array | int |
Style | style | style | int |
Styleable | declare-styleable | styleable (*2) | int[] |
Transition | transition | transition | int |
Typed Array | array | array | int |
XML | xml | xml | int |
(*1) Resources can be also declared in an extended form where the XML Tag is "item"
and the attribute "type"
specifies whether the resource is an "attr"
, a string
et cetera. Therefore a construction like this:
Is equal to the following construction that uses "item"
tag:
It is also worth noting that some resources can be declared with a prefix like aapt:
or android:
. Following aapt's original behaviour, we strip the type names from those
prefixes. This behaviour is deprecated and might be the support for it might end in the near
future.
(*2)The mapping of declare-styleable
to symbols is complex. For each styleable, a
symbol of resource type styleabe
is created of java type int[]
. For each
attribute (attr
) in the declare-styleable
a symbol of resource type styleable
with java type int
is created as well as a symbol of resource type attr
with hava type int
. In case of the symbol with styleable
type, its name is
the symbol name of the declare-styleable
element joined with the name of the attr
element by an underscore character. The value of the int array in the declare-styleable
contains the IDs of all styleable
symbols. So, for example, the following XML:
Will generate the following R.java
:
class R { class attr { public static int def = 0x7f040001; public static int ghi = 0x7f040002; } class styleable { public static int[] abc = { 0x7f040001, 0x7f040002 }; public static int abc_def = 0; public static int abc_ghi = 1; } }
Modifier and Type | Method and Description |
---|---|
static com.android.builder.symbols.SymbolTable |
parse(org.w3c.dom.Document xmlDocument,
IdProvider idProvider,
com.android.builder.symbols.SymbolTable platformAttrSymbols)
Constructs a
SymbolTable from the given parsed XML document. |
@NonNull public static com.android.builder.symbols.SymbolTable parse(@NonNull org.w3c.dom.Document xmlDocument, @NonNull IdProvider idProvider, com.android.builder.symbols.SymbolTable platformAttrSymbols)
SymbolTable
from the given parsed XML document. The values for the
resource are drawn from the given provider. For testing purposes, this method guarantees that
IDs are assigned in the order the resources are provided in the XML document. However, this
guarantee is only to make testing simpler and non-test code should not rely on this
assumption as it may change, along with the required refactoring of the test code.xmlDocument
- the parsed XML documentidProvider
- the provider for IDs to assign to the resourcesplatformAttrSymbols
- the platform attr symbols