asysbang

 找回密码
 立即注册
查看: 7147|回复: 0
打印 上一主题 下一主题

解析资源文件里面的属性

[复制链接]

513

主题

2

好友

6404

积分

管理员

Rank: 80Rank: 80Rank: 80Rank: 80Rank: 80

最佳新人 活跃会员 热心会员 推广达人 宣传达人 灌水之王 突出贡献 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-4-28 10:42:46 |只看该作者 |正序浏览
转载请注明:www.asysbang.com

在写android应用的资源文件时,有时写的格式是不一样的
如:
    android:paddingLeft="@*android:dimen/preference_item_padding_side"
    android:paddingRight="?android:attr/scrollbarSize"
    android:background="?android:attr/selectableItemBackground"
不同的写法,会有不同的意思?那么android是如何解析这个写法的?

还有:
    android:background="@null"   ------  null 必须小写
    android:baselineAligned="TRUE"   ----  TRUE  大小写都可以
为什么有些必须小写,有些大小写都可以?

下面只是一个初步的探索,等有时间再具体深入
frameworks/base/libs/androidfw/ResourceTypes.cpp +4059       ---------   android不同版本文件路径有所改动,这个是4.2的,4.0的在framework/base/libs/utils/ResourceTypes.cpp
bool ResTable::stringToValue(   函数负责解析

4140     if (*s == '@') {
4141         outValue->dataType = outValue->TYPE_REFERENCE;
4142
4143         // Note: we don't check attrType here because the reference can
4144         // be to any other type; we just need to count on the client making
4145         // sure the referenced type is correct.
4146
4147         //printf("Looking up ref: %s\n", String8(s, len).string());
4148
4149         // It's a reference!
4150         if (len == 5 && s[1]=='n' && s[2]=='u' && s[3]=='l' && s[4]=='l') {
4151             outValue->data = 0;
4152             return true;
4153         } else {
4154             bool createIfNotFound = false;
4155             const char16_t* resourceRefName;
4156             int resourceNameLen;
4157             if (len > 2 && s[1] == '+') {
4158                 createIfNotFound = true;
4159                 resourceRefName = s + 2;
4160                 resourceNameLen = len - 2;
4161             } else if (len > 2 && s[1] == '*') {
4162                 enforcePrivate = false;
4163                 resourceRefName = s + 2;
4164                 resourceNameLen = len - 2;
4165             } else {
4166                 createIfNotFound = false;
4167                 resourceRefName = s + 1;
4168                 resourceNameLen = len - 1;
4169             }


4234     if (*s == '#') {
4235         // It's a color!  Convert to an integer of the form 0xaarrggbb.
4236         uint32_t color = 0;
4237         bool error = false;


4310     if (*s == '?') {
4311         outValue->dataType = outValue->TYPE_ATTRIBUTE;
4312
4313         // Note: we don't check attrType here because the reference can
4314         // be to any other type; we just need to count on the client making
4315         // sure the referenced type is correct.
4316
4317         //printf("Looking up attr: %s\n", String8(s, len).string());
4318
4319         static const String16 attr16("attr");
4320         String16 package, type, name;

4433     if (len == 4) {
4434         if ((s[0] == 't' || s[0] == 'T') &&
4435             (s[1] == 'r' || s[1] == 'R') &&
4436             (s[2] == 'u' || s[2] == 'U') &&
4437             (s[3] == 'e' || s[3] == 'E')) {
4438             if ((attrType&ResTable_map::TYPE_BOOLEAN) == 0) {
4439                 if (!canStringCoerce) {
4440                     if (accessor != NULL) {
4441                         accessor->reportError(accessorCookie, "Boolean types not allowed");
4442                     }
4443                     return false;
4444                 }
4445             } else {
4446                 outValue->dataType = outValue->TYPE_INT_BOOLEAN;
4447                 outValue->data = (uint32_t)-1;
4448                 return true;
4449             }
4450         }
4451     }
4452
4453     if (len == 5) {
4454         if ((s[0] == 'f' || s[0] == 'F') &&
4455             (s[1] == 'a' || s[1] == 'A') &&
4456             (s[2] == 'l' || s[2] == 'L') &&
4457             (s[3] == 's' || s[3] == 'S') &&
4458             (s[4] == 'e' || s[4] == 'E')) {


PS :CM(CyanogenMod)的主题切换功能呢个就是在这个文件里面添加了lookupRedirectionMap函数,来实现主题资源的重定向的

CyanogenMod  官方的代码修改review地址
review.cyanogenmod.org/  



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

Archiver|手机版|aSys-帮 ( 京ICP备13033689号 )

GMT+8, 2024-10-5 16:29 , Processed in 0.051892 second(s), 24 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部