summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2015-04-03 14:15:22 -0700
committerGeorge Mount <mount@google.com>2015-04-07 11:02:11 -0700
commit4ec064dff1ec61211bf533ed3c381841a44df7c7 (patch)
treef983792e7b0a04e21c0dd9a1ca50baaaa1211824 /tools
parent266aa36b426eabb4a74f2ced9b45ebe55687d2c4 (diff)
downloadframeworks_base-4ec064dff1ec61211bf533ed3c381841a44df7c7.zip
frameworks_base-4ec064dff1ec61211bf533ed3c381841a44df7c7.tar.gz
frameworks_base-4ec064dff1ec61211bf533ed3c381841a44df7c7.tar.bz2
Use layout path for the tag on bound layout roots.
Change-Id: I6bda5d5716e749251b27c112865da066ba908509
Diffstat (limited to 'tools')
-rw-r--r--tools/data-binding/annotationprocessor/src/main/java/android/databinding/annotationprocessor/ProcessExpressions.java2
-rw-r--r--tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutBinder.java5
-rw-r--r--tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutXmlProcessor.java6
-rw-r--r--tools/data-binding/compiler/src/main/java/android/databinding/tool/store/LayoutFileParser.java9
-rw-r--r--tools/data-binding/compiler/src/main/java/android/databinding/tool/store/ResourceBundle.java14
-rw-r--r--tools/data-binding/compiler/src/main/kotlin/android/databinding/tool/writer/DataBinderWriter.kt5
6 files changed, 14 insertions, 27 deletions
diff --git a/tools/data-binding/annotationprocessor/src/main/java/android/databinding/annotationprocessor/ProcessExpressions.java b/tools/data-binding/annotationprocessor/src/main/java/android/databinding/annotationprocessor/ProcessExpressions.java
index 512fbdb..d62715a 100644
--- a/tools/data-binding/annotationprocessor/src/main/java/android/databinding/annotationprocessor/ProcessExpressions.java
+++ b/tools/data-binding/annotationprocessor/src/main/java/android/databinding/annotationprocessor/ProcessExpressions.java
@@ -164,7 +164,7 @@ public class ProcessExpressions extends ProcessDataBinding.ProcessingStep {
try {
final ResourceBundle.LayoutFileBundle bundle
= (ResourceBundle.LayoutFileBundle) mUnmarshaller.unmarshal(is);
- resourceBundle.addLayoutBundle(bundle, bundle.getLayoutId());
+ resourceBundle.addLayoutBundle(bundle);
L.d("loaded layout info file %s", bundle);
} finally {
IOUtils.closeQuietly(is);
diff --git a/tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutBinder.java b/tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutBinder.java
index 7139cde..e0b18d9 100644
--- a/tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutBinder.java
+++ b/tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutBinder.java
@@ -202,12 +202,11 @@ public class LayoutBinder {
return mBaseClassName;
}
- public int getId() {
- return mBundle.getLayoutId();
+ public String getTag() {
+ return mBundle.getDirectory() + "/" + mBundle.getFileName();
}
public boolean hasVariations() {
return mBundle.hasVariations();
}
-
}
diff --git a/tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutXmlProcessor.java b/tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutXmlProcessor.java
index 90619c7..8cc01d2 100644
--- a/tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutXmlProcessor.java
+++ b/tools/data-binding/compiler/src/main/java/android/databinding/tool/LayoutXmlProcessor.java
@@ -98,13 +98,11 @@ public class LayoutXmlProcessor {
return false;
}
LayoutFileParser layoutFileParser = new LayoutFileParser();
- int layoutId = 0;
for (File xmlFile : getLayoutFiles(mResources)) {
final ResourceBundle.LayoutFileBundle bindingLayout = layoutFileParser
- .parseXml(xmlFile, mResourceBundle.getAppPackage(), layoutId);
+ .parseXml(xmlFile, mResourceBundle.getAppPackage());
if (bindingLayout != null && !bindingLayout.isEmpty()) {
- mResourceBundle.addLayoutBundle(bindingLayout, layoutId);
- layoutId++;
+ mResourceBundle.addLayoutBundle(bindingLayout);
}
}
mProcessingComplete = true;
diff --git a/tools/data-binding/compiler/src/main/java/android/databinding/tool/store/LayoutFileParser.java b/tools/data-binding/compiler/src/main/java/android/databinding/tool/store/LayoutFileParser.java
index 92edfd5..5909922 100644
--- a/tools/data-binding/compiler/src/main/java/android/databinding/tool/store/LayoutFileParser.java
+++ b/tools/data-binding/compiler/src/main/java/android/databinding/tool/store/LayoutFileParser.java
@@ -55,10 +55,12 @@ public class LayoutFileParser {
private static final String XPATH_MERGE_TAG = "/merge";
final String LAYOUT_PREFIX = "@layout/";
- public ResourceBundle.LayoutFileBundle parseXml(File xml, String pkg, int layoutId)
+ public ResourceBundle.LayoutFileBundle parseXml(File xml, String pkg)
throws ParserConfigurationException, IOException, SAXException,
XPathExpressionException {
- File original = stripFileAndGetOriginal(xml, "" + layoutId);
+ final String xmlNoExtension = ParserHelper.INSTANCE$.stripExtension(xml.getName());
+ final String newTag = xml.getParentFile().getName() + '/' + xmlNoExtension;
+ File original = stripFileAndGetOriginal(xml, newTag);
if (original == null) {
L.d("assuming the file is the original for %s", xml.getAbsoluteFile());
original = xml;
@@ -66,8 +68,7 @@ public class LayoutFileParser {
L.d("parsing file %s", xml.getAbsolutePath());
ResourceBundle.LayoutFileBundle bundle = new ResourceBundle.LayoutFileBundle(
- ParserHelper.INSTANCE$.stripExtension(xml.getName()), layoutId,
- xml.getParentFile().getName(), pkg);
+ xmlNoExtension, xml.getParentFile().getName(), pkg);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
diff --git a/tools/data-binding/compiler/src/main/java/android/databinding/tool/store/ResourceBundle.java b/tools/data-binding/compiler/src/main/java/android/databinding/tool/store/ResourceBundle.java
index c115387..0cb29e7 100644
--- a/tools/data-binding/compiler/src/main/java/android/databinding/tool/store/ResourceBundle.java
+++ b/tools/data-binding/compiler/src/main/java/android/databinding/tool/store/ResourceBundle.java
@@ -53,12 +53,11 @@ public class ResourceBundle implements Serializable {
mAppPackage = appPackage;
}
- public void addLayoutBundle(LayoutFileBundle bundle, int layoutId) {
+ public void addLayoutBundle(LayoutFileBundle bundle) {
Preconditions.checkArgument(bundle.mFileName != null, "File bundle must have a name");
if (!mLayoutBundles.containsKey(bundle.mFileName)) {
mLayoutBundles.put(bundle.mFileName, new ArrayList<LayoutFileBundle>());
}
- bundle.mLayoutId = layoutId;
final List<LayoutFileBundle> bundles = mLayoutBundles.get(bundle.mFileName);
for (LayoutFileBundle existing : bundles) {
if (existing.equals(bundle)) {
@@ -211,8 +210,6 @@ public class ResourceBundle implements Serializable {
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name="Layout")
public static class LayoutFileBundle implements Serializable {
- @XmlAttribute(name="layoutId", required = true)
- public int mLayoutId;
@XmlAttribute(name="layout", required = true)
public String mFileName;
@XmlAttribute(name="modulePackage", required = true)
@@ -239,10 +236,8 @@ public class ResourceBundle implements Serializable {
public LayoutFileBundle() {
}
- public LayoutFileBundle(String fileName, int layoutId, String directory,
- String modulePackage) {
+ public LayoutFileBundle(String fileName, String directory, String modulePackage) {
mFileName = fileName;
- mLayoutId = layoutId;
mDirectory = directory;
mModulePackage = modulePackage;
}
@@ -276,10 +271,6 @@ public class ResourceBundle implements Serializable {
return null;
}
- public int getLayoutId() {
- return mLayoutId;
- }
-
public String getFileName() {
return mFileName;
}
@@ -351,7 +342,6 @@ public class ResourceBundle implements Serializable {
", mConfigName='" + mConfigName + '\'' +
", mModulePackage='" + mModulePackage + '\'' +
", mFileName='" + mFileName + '\'' +
- ", mLayoutId=" + mLayoutId +
'}';
}
diff --git a/tools/data-binding/compiler/src/main/kotlin/android/databinding/tool/writer/DataBinderWriter.kt b/tools/data-binding/compiler/src/main/kotlin/android/databinding/tool/writer/DataBinderWriter.kt
index 5fd46ec..f7afc93 100644
--- a/tools/data-binding/compiler/src/main/kotlin/android/databinding/tool/writer/DataBinderWriter.kt
+++ b/tools/data-binding/compiler/src/main/kotlin/android/databinding/tool/writer/DataBinderWriter.kt
@@ -31,11 +31,10 @@ class DataBinderWriter(val pkg: String, val projectPackage: String, val classNam
} else {
// we should check the tag to decide which layout we need to inflate
tab("{") {
- tab("final String tag = (String)view.getTag();")
+ tab("final Object tag = view.getTag();")
tab("if(tag == null) throw new java.lang.RuntimeException(\"view must have a tag\");")
it.value.forEach {
- // TODO don't use strings. not necessary
- tab("if (tag.equals(String.valueOf(${it.getId()}))) {") {
+ tab("if (\"${it.getTag()}\".equals(tag)) {") {
tab("return new ${it.getPackage()}.${it.getImplementationName()}(view);")
} tab("}")
}