Support special Android layout XML tags: fragment, include, merge

This commit is contained in:
Yan Zhulanow
2015-03-20 19:16:59 +03:00
parent 37af12c4bf
commit 2061e390b4
8 changed files with 122 additions and 16 deletions
@@ -47,3 +47,8 @@ public fun isResourceIdDeclaration(str: String?): Boolean = str?.startsWith(Andr
public fun isResourceIdUsage(str: String?): Boolean = str?.startsWith(AndroidConst.ID_USAGE_PREFIX) ?: false
public fun isResourceDeclarationOrUsage(id: String?): Boolean = isResourceIdDeclaration(id) || isResourceIdUsage(id)
public fun getRealWidgetType(xmlType: String): String = when (xmlType) {
"fragment", "include", "merge" -> "View"
else -> xmlType
}
@@ -32,11 +32,11 @@ class AndroidXmlHandler(private val elementCallback: (String, String) -> Unit) :
override fun startElement(uri: String, localName: String, qName: String, attributes: Attributes) {
val attributesMap = attributes.toMap()
val idAttr = attributesMap[AndroidConst.ID_ATTRIBUTE_NO_NAMESPACE]
val classNameAttr = attributesMap[AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE] ?: localName
if (isResourceDeclarationOrUsage(idAttr)) {
val name = idToName(idAttr)
if (name != null) elementCallback(name, classNameAttr)
val idAttribute = attributesMap[AndroidConst.ID_ATTRIBUTE_NO_NAMESPACE]
val widgetType = getRealWidgetType(attributesMap[AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE] ?: localName)
if (isResourceDeclarationOrUsage(idAttribute)) {
val name = idToName(idAttribute)
if (name != null) elementCallback(name, widgetType)
}
}