Just An Application

September 20, 2011

Android Internals: Resources – Part Nine: Simple Resource Entry Examples

Filed under: Android, Android Internals, Android Resources — Tags: , , — Simon Lewis @ 4:34 am

1.0 Booleans

These boolean Resource definitions

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <bool name="example_false">false</bool>
        <bool name="example_true">true</bool>
    </resources>

result in these entries

    ...    

    00000c58 08 00       // entry[0] size
    00000c5a 00 00       // entry[0] flags
    00000c5c 14 00 00 00 // entry[0] key [example_false]
    00000c60 08 00       // size
    00000c62 00          // 0
    00000c63 12          // dataType [TYPE_BOOLEAN]
    00000c64 00 00 00 00 // data
    00000c68 08 00       // entry[1] size
    00000c6a 00 00       // entry[1] flags
    00000c6c 15 00 00 00 // entry[1] key [example_true]
    00000c70 08 00       // size
    00000c72 00          // 0
    00000c73 12          // dataType [TYPE_BOOLEAN]
    00000c74 ff ff ff ff // data
	
    ...

The entry values both have a value type of TYPE_BOOLEAN as you would expect, but true is represented by the value 0xFFFFFFFF rather than 1 as specified by the comment here.

2.0 Colours

Colour resources can be specified using four different formats and each format has a corresponding value type.

These color Resource definitions

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="colour_rgb">#ABC</color>
        <color name="colour_argb">#ABCD</color>
        <color name="colour_rrggbb">#AABBCC</color>
        <color name="colour_aarrggbb">#AABBCCDD</color>
    </resources>

result in these entries

    ...

    00000cdc 08 00       // entry[0] size
    00000cde 00 00       // entry[0] flags
    00000ce0 16 00 00 00 // entry[0] key [colour_rgb]
    00000ce4 08 00       // size
    00000ce6 00          // 0
    00000ce7 1f          // dataType [TYPE_INT_COLOR_RGB4]
    00000ce8 cc bb aa ff // data
    00000cec 08 00       // entry[1] size
    00000cee 00 00       // entry[1] flags
    00000cf0 17 00 00 00 // entry[1] key [colour_argb]
    00000cf4 08 00       // size
    00000cf6 00          // 0
    00000cf7 1e          // dataType [TYPE_INT_COLOR_ARGB4]
    00000cf8 dd cc bb aa // data
    00000cfc 08 00       // entry[2] size
    00000cfe 00 00       // entry[2] flags
    00000d00 18 00 00 00 // entry[2] key [colour_rrggbb]
    00000d04 08 00       // size
    00000d06 00          // 0
    00000d07 1d          // dataType [TYPE_INT_COLOR_RGB8]
    00000d08 cc bb aa ff // data
    00000d0c 08 00       // entry[3] size
    00000d0e 00 00       // entry[3] flags
    00000d10 19 00 00 00 // entry[3] key [colour_aarrggbb]
    00000d14 08 00       // size
    00000d16 00          // 0
    00000d17 1c          // dataType [TYPE_INT_COLOR_ARGB8]
    00000d18 dd cc bb aa // data

    ...

Each entry value has a different type but all the colour values are encoded in the same way as standard 32-bit integers in ARGB format.

Other than making it possible to recover the textual representation of the Resource value as defined it is not clear why it is necessary to have four different colour value types

3.0 Dimensions

Dimensions can be specified in six different units.

These dimension Resource definitions

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <dimen name="dimension_mm">27mm</dimen>
        <dimen name="dimension_px">27px</dimen>
        <dimen name="dimension_in">27in</dimen>
        <dimen name="dimension_pt">27pt</dimen>
        <dimen name="dimension_dp">27dp</dimen>
        <dimen name="dimension_sp">27sp</dimen>
    </resources>

result in these entries

    ...

    00000d90 08 00       // entry[0] size
    00000d92 00 00       // entry[0] flags
    00000d94 1a 00 00 00 // entry[0] key [dimension_mm]
    00000d98 08 00       // size
    00000d9a 00          // 0
    00000d9b 05          // dataType [TYPE_DIMENSION]
    00000d9c 05 1b 00 00 // data
    00000da0 08 00       // entry[1] size
    00000da2 00 00       // entry[1] flags
    00000da4 1b 00 00 00 // entry[1] key [dimension_px]
    00000da8 08 00       // size
    00000daa 00          // 0
    00000dab 05          // dataType [TYPE_DIMENSION]
    00000dac 00 1b 00 00 // data
    00000db0 08 00       // entry[2] size
    00000db2 00 00       // entry[2] flags
    00000db4 1c 00 00 00 // entry[2] key [dimension_in]
    00000db8 08 00       // size
    00000dba 00          // 0
    00000dbb 05          // dataType [TYPE_DIMENSION]
    00000dbc 04 1b 00 00 // data
    00000dc0 08 00       // entry[3] size
    00000dc2 00 00       // entry[3] flags
    00000dc4 1d 00 00 00 // entry[3] key [dimension_pt]
    00000dc8 08 00       // size
    00000dca 00          // 0
    00000dcb 05          // dataType [TYPE_DIMENSION]
    00000dcc 03 1b 00 00 // data
    00000dd0 08 00       // entry[4] size
    00000dd2 00 00       // entry[4] flags
    00000dd4 1e 00 00 00 // entry[4] key [dimension_dp]
    00000dd8 08 00       // size
    00000dda 00          // 0
    00000ddb 05          // dataType [TYPE_DIMENSION]
    00000ddc 01 1b 00 00 // data
    00000de0 08 00       // entry[5] size
    00000de2 00 00       // entry[5] flags
    00000de4 1f 00 00 00 // entry[5] key [dimension_sp]
    00000de8 08 00       // size
    00000dea 00          // 0
    00000deb 05          // dataType [TYPE_DIMENSION]
    00000dec 02 1b 00 00 // data

    ...

Dimensions are the reverse of colours. All values have the same type (TYPE_DIMENSION) and the type of each dimension’s unit is encoded in the data.

The low-order 8 bits of the data value specify the units of the dimension as defined by the anonymous enum members

  • COMPLEX_UNIT_PX

  • COMPLEX_UNIT_DIP

  • COMPLEX_UNIT_SP

  • COMPLEX_UNIT_PT

  • COMPLEX_UNIT_IN

  • COMPLEX_UNIT_MM

The remaining 24 bits specify the value.

4.0 Fractions

Fractions can be specified using two different formats.

These resource definitions

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <fraction name="example_fraction_percent">14%</fraction>
        <fraction name="example_fraction_percent_p">28%p</fraction>
    </resources>

result in these entries

    ...

    00000e3c 00 00 00 00 // entry_index[0]
    00000e40 10 00 00 00 // entry_index[1]
    00000e44 08 00       // entry[0] size
    00000e46 00 00       // entry[0] flags
    00000e48 20 00 00 00 // entry[0] key [example_fraction_percent]
    00000e4c 08 00       // size
    00000e4e 00          // 0
    00000e4f 06          // dataType [TYPE_FRACTION]
    00000e50 30 85 eb 11 // data
    00000e54 08 00       // entry[1] size
    00000e56 00 00       // entry[1] flags
    00000e58 21 00 00 00 // entry[1] key [example_fraction_percent_p]
    00000e5c 08 00       // size
    00000e5e 00          // 0
    00000e5f 06          // dataType [TYPE_FRACTION]
    00000e60 31 0a d7 23 // data

    ...

Fractions are like dimensions. All values have the same type (TYPE_FRACTION) and the format is encoded in the data.

The low-order 4 bits of the data value specify the type of the fraction as defined by the anonymous enum members

  • COMPLEX_UNIT_FRACTION

  • COMPLEX_UNIT_FRACTION_PARENT

The remaining 28 bits specify the value as a floating point number.

5.0 Integers

Integer Resources can be specified as a decimal or hexidecimal value and there are corresponding value types.

These resource definitions

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
	    <integer name="example_decimal">1234</integer>
	    <integer name="example_hex">0x1234</integer>
    </resources>

result in these entries

    ...

    00000eb0 00 00 00 00 // entry_index[0]
    00000eb4 10 00 00 00 // entry_index[1]
    00000eb8 08 00       // entry[0] size
    00000eba 00 00       // entry[0] flags
    00000ebc 22 00 00 00 // entry[0] key [example_decimal]
    00000ec0 08 00       // size
    00000ec2 00          // 0
    00000ec3 10          // dataType [TYPE_INT_DEC]
    00000ec4 d2 04 00 00 // data
    00000ec8 08 00       // entry[1] size
    00000eca 00 00       // entry[1] flags
    00000ecc 23 00 00 00 // entry[1] key [example_hex]
    00000ed0 08 00       // size
    00000ed2 00          // 0
    00000ed3 11          // dataType [TYPE_INT_HEX]
    00000ed4 34 12 00 00 // data

    ...

The entry values have different types but unsurprisingly both integer values are encoded as standard 32-bit integers.

Other than making it possible to recover the textual representation of the Resource value as defined it is not clear why it is necessary to have two different integer value types

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: