use of android.taobao.atlas.framework.BundleImpl in project atlas by alibaba.
the class ResourceIdFetcher method getIdentifierWithRefection.
private int getIdentifierWithRefection(String name, String defType, String defPackage) {
if (defType == null && defPackage == null) {
String rawName = name;
name = rawName.substring(name.indexOf("/") + 1);
defType = rawName.substring(rawName.indexOf(":") + 1, rawName.indexOf("/"));
}
if (TextUtils.isEmpty(name) || TextUtils.isEmpty(defType)) {
return 0;
}
List<Bundle> bundles = Framework.getBundles();
if (bundles != null && !bundles.isEmpty()) {
for (Bundle b : Framework.getBundles()) {
String pkgName = b.getLocation();
final String searchKey = pkgName + ":" + name;
if (!resIdentifierMap.isEmpty() && resIdentifierMap.containsKey(searchKey)) {
ResInfo info = resIdentifierMap.get(searchKey);
if (info != null && info.type != null && defType != null && info.type.equals(defType)) {
return info.resId;
}
}
BundleImpl bundle = (BundleImpl) b;
if (bundle.getArchive().isDexOpted()) {
ClassLoader classloader = bundle.getClassLoader();
try {
if (classloader != null) {
StringBuilder resClass = new StringBuilder(pkgName);
resClass.append(".R$");
resClass.append(defType);
Class clazz = classloader.loadClass(resClass.toString());
int tmpResID = getFieldValueOfR(clazz, name);
if (tmpResID != 0) {
resIdentifierMap.put(searchKey, new ResInfo(defType, tmpResID));
return tmpResID;
}
}
} catch (ClassNotFoundException e) {
}
}
}
}
return 0;
}
Aggregations