Created
February 17, 2020 12:41
-
-
Save emmaguy/74212914eddcfdff47c46e5c277657ee to your computer and use it in GitHub Desktop.
Look at all Android layout files and collate what value is set for 'android:textColor' and count the usages of each
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val textColorsUsed = mutableMapOf<String, Int>() | |
File("../").walkTopDown().forEach { file -> | |
if (file.isFile && file.extension == "xml" && file.path.contains("res/layout")) { | |
val builder: DocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder() | |
val xmlInput = InputSource(StringReader(file.readText())) | |
val doc: Document = builder.parse(xmlInput) | |
val androidViews = XPathFactory.newInstance() | |
.newXPath() | |
.evaluate("//*", doc, XPathConstants.NODESET) as NodeList | |
androidViews.forEach { | |
it.attributes.getNamedItem("android:textColor")?.let { node -> | |
textColorsUsed[node.nodeValue] = textColorsUsed.defaultOrIncrement(node.nodeValue) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment