From 28428f7249599cd59669c7950932a6c84f416712 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Thu, 26 Oct 2023 15:18:26 +0300 Subject: [PATCH 01/20] 7 new icons --- app/assets/appfilter.xml | 7 + .../lawnchair/lawnicons/helper/Application.kt | 16 ++ .../lawnicons/helper/ConfigProcessor.kt | 102 ++++++++++++ .../lawnicons/helper/SvgFilesProcessor.kt | 150 ++++++++++++++++++ .../app/lawnchair/lawnicons/helper/XmlUtil.kt | 45 ++++++ svgs/24pay.svg | 1 + svgs/android_12_widget_pack.svg | 1 + svgs/info_tb.svg | 1 + svgs/musiccast.svg | 1 + svgs/myedenred.svg | 1 + svgs/stay_fit_gym.svg | 1 + svgs/youth_tb.svg | 1 + 12 files changed, 327 insertions(+) create mode 100644 svg-processor/bin/main/app/lawnchair/lawnicons/helper/Application.kt create mode 100644 svg-processor/bin/main/app/lawnchair/lawnicons/helper/ConfigProcessor.kt create mode 100644 svg-processor/bin/main/app/lawnchair/lawnicons/helper/SvgFilesProcessor.kt create mode 100644 svg-processor/bin/main/app/lawnchair/lawnicons/helper/XmlUtil.kt create mode 100644 svgs/24pay.svg create mode 100644 svgs/android_12_widget_pack.svg create mode 100644 svgs/info_tb.svg create mode 100644 svgs/musiccast.svg create mode 100644 svgs/myedenred.svg create mode 100644 svgs/stay_fit_gym.svg create mode 100644 svgs/youth_tb.svg diff --git a/app/assets/appfilter.xml b/app/assets/appfilter.xml index 834577c9ad5..e50490c1f25 100644 --- a/app/assets/appfilter.xml +++ b/app/assets/appfilter.xml @@ -51,6 +51,7 @@ + @@ -215,6 +216,7 @@ + @@ -2183,6 +2185,7 @@ + @@ -3071,6 +3074,7 @@ + @@ -3100,6 +3104,7 @@ + @@ -4918,6 +4923,7 @@ + @@ -5996,6 +6002,7 @@ + diff --git a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/Application.kt b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/Application.kt new file mode 100644 index 00000000000..a016e388349 --- /dev/null +++ b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/Application.kt @@ -0,0 +1,16 @@ +package app.lawnchair.lawnicons.helper + +fun main() { + val rootDir = ".." + val sourceDir = "$rootDir/svgs/" + val resDir = "$rootDir/app/src/runtime/res" + val appFilterFile = "$rootDir/app/assets/appfilter.xml" + + // Convert svg to drawable in runtime + SvgFilesProcessor.process(sourceDir, "$resDir/drawable") + + // Read appfilter xml and create icon, drawable xml file. + ConfigProcessor.loadAndCreateConfigs(appFilterFile, resDir) + + println("SvgToVector task completed") +} diff --git a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/ConfigProcessor.kt b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/ConfigProcessor.kt new file mode 100644 index 00000000000..33b16af250e --- /dev/null +++ b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/ConfigProcessor.kt @@ -0,0 +1,102 @@ +package app.lawnchair.lawnicons.helper + +import java.util.Locale +import org.dom4j.Document +import org.dom4j.tree.DefaultDocument + +object ConfigProcessor { + private const val ITEM = "item" + private const val CATEGORY = "category" + private const val COMPONENT = "component" + private const val PACKAGE = "package" + private const val DRAWABLE = "drawable" + private const val DRAWABLEIGNORE = "drawableIgnore" + private const val ICONS = "icons" + private const val ICON = "icon" + private const val RESOURCES = "resources" + private const val TITLE = "title" + private const val NAME = "name" + private const val VERSION = "version" + + fun loadAndCreateConfigs(appFilterFile: String, vararg resDirs: String) { + val (appFilterDocument, drawableMap, iconMap) = loadConfigFromXml(appFilterFile) + val sortedDrawableMap = drawableMap.toList().sortedBy { (_, value) -> value }.toMap() + + resDirs.forEach { + // Create Drawable files + writeDrawableToFile(sortedDrawableMap, "$it/xml/drawable.xml") + // Create Icon Map files + writeIconMapToFile(sortedDrawableMap, iconMap, "$it/xml/grayscale_icon_map.xml") + // Write AppFilter to resource directory + XmlUtil.writeDocumentToFile(appFilterDocument, "$it/xml/appfilter.xml") + } + } + + private fun loadConfigFromXml(appFilterFile: String): Triple, Map> { + val drawableMap = mutableMapOf() + val iconMap = mutableMapOf() + val componentStart = "ComponentInfo{" + val componentEnd = "}" + val appFilterDocument = XmlUtil.getDocument(appFilterFile) + val appFilterElements = XmlUtil.getElements(appFilterDocument, ITEM) + for (element in appFilterElements) { + val componentInfo = element.attribute(COMPONENT).value + val drawable = element.attribute(DRAWABLE).value + val name = element.attribute(NAME).value + val shouldIgnore: String? = element.attributeValue(DRAWABLEIGNORE) + if (shouldIgnore != null) continue + + if (componentInfo.startsWith(componentStart) && componentInfo.endsWith(componentEnd)) { + val component = componentInfo.substring( + componentStart.length, + componentInfo.length - componentEnd.length, + ) + drawableMap[component] = drawable + iconMap[component] = name + } + } + return Triple(appFilterDocument, drawableMap.toMap(), iconMap.toMap()) + } + + private fun writeIconMapToFile( + drawableMap: Map, + iconMap: Map, + filename: String, + ) { + val iconsDocument = DefaultDocument().apply { addElement(ICONS) } + drawableMap.forEach { (componentInfo, drawable) -> + val component = componentInfo.split("/").toTypedArray() + val name = iconMap.getOrDefault( + componentInfo, + drawable.replace("_".toRegex(), " ").capitalize(), + ) + iconsDocument.rootElement.addElement(ICON) + .addAttribute(DRAWABLE, "@drawable/${drawable}_foreground") + .addAttribute(PACKAGE, component[0]) + .addAttribute(NAME, name) + } + XmlUtil.writeDocumentToFile(iconsDocument, filename) + } + + private fun writeDrawableToFile(drawableMap: Map, filename: String) { + val resourceDocument = DefaultDocument().apply { + addElement(RESOURCES) + rootElement.addElement(VERSION).addText("1") + } + val groupNames = mutableListOf() + drawableMap.values.distinct().forEach { drawable: String -> + val groupName = drawable[0].uppercaseChar() + if (groupName !in groupNames) { + resourceDocument.rootElement.addElement(CATEGORY) + .addAttribute(TITLE, groupName.toString()) + groupNames.add(groupName) + } + resourceDocument.rootElement.addElement(ITEM).addAttribute(DRAWABLE, drawable) + } + XmlUtil.writeDocumentToFile(resourceDocument, filename) + } + + private fun String.capitalize(): String = replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() + } +} diff --git a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/SvgFilesProcessor.kt b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/SvgFilesProcessor.kt new file mode 100644 index 00000000000..a0b8c3099f8 --- /dev/null +++ b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/SvgFilesProcessor.kt @@ -0,0 +1,150 @@ +package app.lawnchair.lawnicons.helper + +import com.android.ide.common.vectordrawable.Svg2Vector +import java.io.FileOutputStream +import java.io.IOException +import java.nio.file.FileVisitOption +import java.nio.file.FileVisitResult +import java.nio.file.FileVisitor +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths +import java.nio.file.attribute.BasicFileAttributes +import java.util.EnumSet +import org.apache.commons.io.FileUtils +import org.apache.commons.io.FilenameUtils +import org.dom4j.Document +import org.dom4j.DocumentException +import org.dom4j.DocumentHelper + +object SvgFilesProcessor { + private lateinit var sourceSvgPath: Path + private lateinit var destinationVectorPath: Path + fun process(sourceDirectory: String, destDirectory: String) { + this.sourceSvgPath = Paths.get(sourceDirectory) + this.destinationVectorPath = Paths.get(destDirectory) + try { + val options = EnumSet.of(FileVisitOption.FOLLOW_LINKS) + // check first if source is a directory + if (Files.isDirectory(sourceSvgPath)) { + Files.walkFileTree(sourceSvgPath, options, Int.MAX_VALUE, fileVisitor) + } else { + println("source not a directory") + } + } catch (e: IOException) { + e.printStackTrace() + } + } + + private val fileVisitor = object : FileVisitor { + override fun postVisitDirectory(dir: Path, exc: IOException?): FileVisitResult = + FileVisitResult.CONTINUE + + override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes?): FileVisitResult { + // Skip folder which is processing svgs to xml + if (dir == destinationVectorPath) { + return FileVisitResult.SKIP_SUBTREE + } + val newDirectory = destinationVectorPath.resolve(sourceSvgPath.relativize(dir)) + try { + Files.createDirectories(newDirectory) + } catch (e: FileAlreadyExistsException) { + e.printStackTrace() + } catch (e: IOException) { + e.printStackTrace() + return FileVisitResult.SKIP_SUBTREE + } + return FileVisitResult.CONTINUE + } + + override fun visitFile(file: Path, attrs: BasicFileAttributes?): FileVisitResult { + convertToVector(file, destinationVectorPath.resolve(sourceSvgPath.relativize(file))) + return FileVisitResult.CONTINUE + } + + override fun visitFileFailed(file: Path, exc: IOException?): FileVisitResult = + FileVisitResult.CONTINUE + } + + private fun convertToVector(svgSource: Path, vectorTargetPath: Path) { + // convert only if it is .svg + if (svgSource.fileName.toString().endsWith(".svg")) { + val targetFile = XmlUtil.getFileWithExtension(vectorTargetPath) + val fileOutputStream = FileOutputStream(targetFile) + Svg2Vector.parseSvgToXml(svgSource, fileOutputStream) + val fg = "@color/primaryForeground" + val bg = "@color/primaryBackground" + try { + updateXmlPath(targetFile, "android:strokeColor", fg) + updateXmlPath(targetFile, "android:fillColor", fg) + updateRootElement(targetFile, "android:tint", fg) + } catch (e: DocumentException) { + throw RuntimeException(e) + } + createAdaptive(targetFile, bg) + } else { + println("Skipping file as its not svg " + svgSource.fileName) + } + } + + @Throws(IOException::class) + private fun createAdaptive(xmlPath: String, bgColor: String) { + val foregroundXml = xmlPath.replace(".xml", "_foreground.xml") + val foregroundFile = FileUtils.getFile(foregroundXml) + foregroundFile.delete() + FileUtils.moveFile( + FileUtils.getFile(xmlPath), + foregroundFile, + ) + val drawableName: String = FilenameUtils.getBaseName(xmlPath) + val resPath: String = FilenameUtils.getFullPath(xmlPath) + val document = DocumentHelper.createDocument() + val root = document.addElement("adaptive-icon") + .addAttribute("xmlns:android", "http://schemas.android.com/apk/res/android") + root.addElement("background") + .addAttribute("android:drawable", bgColor) + root.addElement("foreground").addElement("inset") + .addAttribute("android:inset", "32%") + .addAttribute( + "android:drawable", + "@drawable/" + FilenameUtils.getBaseName(foregroundXml), + ) + root.addElement("monochrome").addElement("inset") + .addAttribute("android:inset", "28%") + .addAttribute( + "android:drawable", + "@drawable/" + FilenameUtils.getBaseName(foregroundXml), + ) + XmlUtil.writeDocumentToFile(document, "$resPath$drawableName.xml") + } + + private fun updateRootElement(xmlPath: String, key: String, value: String) { + val aDocument: Document = XmlUtil.getDocument(xmlPath) + val keyWithoutNameSpace = key.substring(key.indexOf(":") + 1) + val attr = aDocument.rootElement.attribute(keyWithoutNameSpace) + if (attr != null) { + if (attr.value != "#00000000") { + attr.value = value + } + } else { + aDocument.rootElement.addAttribute(key, value) + } + XmlUtil.writeDocumentToFile(aDocument, xmlPath) + } + + private fun updateXmlPath(xmlPath: String, searchKey: String, attributeValue: String) { + val xmlDocument = XmlUtil.getDocument(xmlPath) + val keyWithoutNameSpace = searchKey.substring(searchKey.indexOf(":") + 1) + if (xmlDocument.rootElement != null) { + for (e in xmlDocument.rootElement.elements("path")) { + val attr = e.attribute(keyWithoutNameSpace) + if (attr != null) { + if (attr.value != "#00000000") { + attr.value = attributeValue + } + } + } + XmlUtil.writeDocumentToFile(xmlDocument, xmlPath) + } + } +} diff --git a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/XmlUtil.kt b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/XmlUtil.kt new file mode 100644 index 00000000000..bfe417d87f8 --- /dev/null +++ b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/XmlUtil.kt @@ -0,0 +1,45 @@ +package app.lawnchair.lawnicons.helper + +import java.io.File +import java.io.FileWriter +import java.nio.file.Path +import org.dom4j.Document +import org.dom4j.Element +import org.dom4j.io.OutputFormat +import org.dom4j.io.SAXReader +import org.dom4j.io.XMLWriter + +object XmlUtil { + private val UTF_8 = Charsets.UTF_8.name() + + fun getElements(document: Document, path: String): List { + return document.rootElement.elements(path) + } + + fun getDocument(xmlPath: String): Document { + return SAXReader().apply { encoding = UTF_8 }.read(xmlPath) + } + + fun getFileWithExtension(target: Path, extension: String = "xml"): String { + val svgFilePath = target.toFile().absolutePath + val index = svgFilePath.lastIndexOf(".") + return buildString { + if (index != -1) { + append(svgFilePath.substring(0, index)) + } + append(".$extension") + } + } + + fun writeDocumentToFile(outDocument: Document, outputConfigPath: String) { + File(outputConfigPath).parentFile.mkdirs() + // Delete existing file If any + File(outputConfigPath).delete() + FileWriter(outputConfigPath).use { fw -> + XMLWriter(fw, OutputFormat.createPrettyPrint()).apply { + write(outDocument) + close() + } + } + } +} diff --git a/svgs/24pay.svg b/svgs/24pay.svg new file mode 100644 index 00000000000..bc81593089f --- /dev/null +++ b/svgs/24pay.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/svgs/android_12_widget_pack.svg b/svgs/android_12_widget_pack.svg new file mode 100644 index 00000000000..8bac8fb79e5 --- /dev/null +++ b/svgs/android_12_widget_pack.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/svgs/info_tb.svg b/svgs/info_tb.svg new file mode 100644 index 00000000000..376aac35546 --- /dev/null +++ b/svgs/info_tb.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/svgs/musiccast.svg b/svgs/musiccast.svg new file mode 100644 index 00000000000..9f1b5dc9dc2 --- /dev/null +++ b/svgs/musiccast.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/svgs/myedenred.svg b/svgs/myedenred.svg new file mode 100644 index 00000000000..f7d2087a950 --- /dev/null +++ b/svgs/myedenred.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/svgs/stay_fit_gym.svg b/svgs/stay_fit_gym.svg new file mode 100644 index 00000000000..42933ca0ddf --- /dev/null +++ b/svgs/stay_fit_gym.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/svgs/youth_tb.svg b/svgs/youth_tb.svg new file mode 100644 index 00000000000..500de504946 --- /dev/null +++ b/svgs/youth_tb.svg @@ -0,0 +1 @@ + \ No newline at end of file From 22c344b637105b0338f10eed71ba8caa86c64314 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Thu, 26 Oct 2023 15:25:38 +0300 Subject: [PATCH 02/20] Remove files I have no idea where they came from --- .../lawnchair/lawnicons/helper/Application.kt | 16 -- .../lawnicons/helper/ConfigProcessor.kt | 102 ------------ .../lawnicons/helper/SvgFilesProcessor.kt | 150 ------------------ .../app/lawnchair/lawnicons/helper/XmlUtil.kt | 45 ------ 4 files changed, 313 deletions(-) delete mode 100644 svg-processor/bin/main/app/lawnchair/lawnicons/helper/Application.kt delete mode 100644 svg-processor/bin/main/app/lawnchair/lawnicons/helper/ConfigProcessor.kt delete mode 100644 svg-processor/bin/main/app/lawnchair/lawnicons/helper/SvgFilesProcessor.kt delete mode 100644 svg-processor/bin/main/app/lawnchair/lawnicons/helper/XmlUtil.kt diff --git a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/Application.kt b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/Application.kt deleted file mode 100644 index a016e388349..00000000000 --- a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/Application.kt +++ /dev/null @@ -1,16 +0,0 @@ -package app.lawnchair.lawnicons.helper - -fun main() { - val rootDir = ".." - val sourceDir = "$rootDir/svgs/" - val resDir = "$rootDir/app/src/runtime/res" - val appFilterFile = "$rootDir/app/assets/appfilter.xml" - - // Convert svg to drawable in runtime - SvgFilesProcessor.process(sourceDir, "$resDir/drawable") - - // Read appfilter xml and create icon, drawable xml file. - ConfigProcessor.loadAndCreateConfigs(appFilterFile, resDir) - - println("SvgToVector task completed") -} diff --git a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/ConfigProcessor.kt b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/ConfigProcessor.kt deleted file mode 100644 index 33b16af250e..00000000000 --- a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/ConfigProcessor.kt +++ /dev/null @@ -1,102 +0,0 @@ -package app.lawnchair.lawnicons.helper - -import java.util.Locale -import org.dom4j.Document -import org.dom4j.tree.DefaultDocument - -object ConfigProcessor { - private const val ITEM = "item" - private const val CATEGORY = "category" - private const val COMPONENT = "component" - private const val PACKAGE = "package" - private const val DRAWABLE = "drawable" - private const val DRAWABLEIGNORE = "drawableIgnore" - private const val ICONS = "icons" - private const val ICON = "icon" - private const val RESOURCES = "resources" - private const val TITLE = "title" - private const val NAME = "name" - private const val VERSION = "version" - - fun loadAndCreateConfigs(appFilterFile: String, vararg resDirs: String) { - val (appFilterDocument, drawableMap, iconMap) = loadConfigFromXml(appFilterFile) - val sortedDrawableMap = drawableMap.toList().sortedBy { (_, value) -> value }.toMap() - - resDirs.forEach { - // Create Drawable files - writeDrawableToFile(sortedDrawableMap, "$it/xml/drawable.xml") - // Create Icon Map files - writeIconMapToFile(sortedDrawableMap, iconMap, "$it/xml/grayscale_icon_map.xml") - // Write AppFilter to resource directory - XmlUtil.writeDocumentToFile(appFilterDocument, "$it/xml/appfilter.xml") - } - } - - private fun loadConfigFromXml(appFilterFile: String): Triple, Map> { - val drawableMap = mutableMapOf() - val iconMap = mutableMapOf() - val componentStart = "ComponentInfo{" - val componentEnd = "}" - val appFilterDocument = XmlUtil.getDocument(appFilterFile) - val appFilterElements = XmlUtil.getElements(appFilterDocument, ITEM) - for (element in appFilterElements) { - val componentInfo = element.attribute(COMPONENT).value - val drawable = element.attribute(DRAWABLE).value - val name = element.attribute(NAME).value - val shouldIgnore: String? = element.attributeValue(DRAWABLEIGNORE) - if (shouldIgnore != null) continue - - if (componentInfo.startsWith(componentStart) && componentInfo.endsWith(componentEnd)) { - val component = componentInfo.substring( - componentStart.length, - componentInfo.length - componentEnd.length, - ) - drawableMap[component] = drawable - iconMap[component] = name - } - } - return Triple(appFilterDocument, drawableMap.toMap(), iconMap.toMap()) - } - - private fun writeIconMapToFile( - drawableMap: Map, - iconMap: Map, - filename: String, - ) { - val iconsDocument = DefaultDocument().apply { addElement(ICONS) } - drawableMap.forEach { (componentInfo, drawable) -> - val component = componentInfo.split("/").toTypedArray() - val name = iconMap.getOrDefault( - componentInfo, - drawable.replace("_".toRegex(), " ").capitalize(), - ) - iconsDocument.rootElement.addElement(ICON) - .addAttribute(DRAWABLE, "@drawable/${drawable}_foreground") - .addAttribute(PACKAGE, component[0]) - .addAttribute(NAME, name) - } - XmlUtil.writeDocumentToFile(iconsDocument, filename) - } - - private fun writeDrawableToFile(drawableMap: Map, filename: String) { - val resourceDocument = DefaultDocument().apply { - addElement(RESOURCES) - rootElement.addElement(VERSION).addText("1") - } - val groupNames = mutableListOf() - drawableMap.values.distinct().forEach { drawable: String -> - val groupName = drawable[0].uppercaseChar() - if (groupName !in groupNames) { - resourceDocument.rootElement.addElement(CATEGORY) - .addAttribute(TITLE, groupName.toString()) - groupNames.add(groupName) - } - resourceDocument.rootElement.addElement(ITEM).addAttribute(DRAWABLE, drawable) - } - XmlUtil.writeDocumentToFile(resourceDocument, filename) - } - - private fun String.capitalize(): String = replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() - } -} diff --git a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/SvgFilesProcessor.kt b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/SvgFilesProcessor.kt deleted file mode 100644 index a0b8c3099f8..00000000000 --- a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/SvgFilesProcessor.kt +++ /dev/null @@ -1,150 +0,0 @@ -package app.lawnchair.lawnicons.helper - -import com.android.ide.common.vectordrawable.Svg2Vector -import java.io.FileOutputStream -import java.io.IOException -import java.nio.file.FileVisitOption -import java.nio.file.FileVisitResult -import java.nio.file.FileVisitor -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths -import java.nio.file.attribute.BasicFileAttributes -import java.util.EnumSet -import org.apache.commons.io.FileUtils -import org.apache.commons.io.FilenameUtils -import org.dom4j.Document -import org.dom4j.DocumentException -import org.dom4j.DocumentHelper - -object SvgFilesProcessor { - private lateinit var sourceSvgPath: Path - private lateinit var destinationVectorPath: Path - fun process(sourceDirectory: String, destDirectory: String) { - this.sourceSvgPath = Paths.get(sourceDirectory) - this.destinationVectorPath = Paths.get(destDirectory) - try { - val options = EnumSet.of(FileVisitOption.FOLLOW_LINKS) - // check first if source is a directory - if (Files.isDirectory(sourceSvgPath)) { - Files.walkFileTree(sourceSvgPath, options, Int.MAX_VALUE, fileVisitor) - } else { - println("source not a directory") - } - } catch (e: IOException) { - e.printStackTrace() - } - } - - private val fileVisitor = object : FileVisitor { - override fun postVisitDirectory(dir: Path, exc: IOException?): FileVisitResult = - FileVisitResult.CONTINUE - - override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes?): FileVisitResult { - // Skip folder which is processing svgs to xml - if (dir == destinationVectorPath) { - return FileVisitResult.SKIP_SUBTREE - } - val newDirectory = destinationVectorPath.resolve(sourceSvgPath.relativize(dir)) - try { - Files.createDirectories(newDirectory) - } catch (e: FileAlreadyExistsException) { - e.printStackTrace() - } catch (e: IOException) { - e.printStackTrace() - return FileVisitResult.SKIP_SUBTREE - } - return FileVisitResult.CONTINUE - } - - override fun visitFile(file: Path, attrs: BasicFileAttributes?): FileVisitResult { - convertToVector(file, destinationVectorPath.resolve(sourceSvgPath.relativize(file))) - return FileVisitResult.CONTINUE - } - - override fun visitFileFailed(file: Path, exc: IOException?): FileVisitResult = - FileVisitResult.CONTINUE - } - - private fun convertToVector(svgSource: Path, vectorTargetPath: Path) { - // convert only if it is .svg - if (svgSource.fileName.toString().endsWith(".svg")) { - val targetFile = XmlUtil.getFileWithExtension(vectorTargetPath) - val fileOutputStream = FileOutputStream(targetFile) - Svg2Vector.parseSvgToXml(svgSource, fileOutputStream) - val fg = "@color/primaryForeground" - val bg = "@color/primaryBackground" - try { - updateXmlPath(targetFile, "android:strokeColor", fg) - updateXmlPath(targetFile, "android:fillColor", fg) - updateRootElement(targetFile, "android:tint", fg) - } catch (e: DocumentException) { - throw RuntimeException(e) - } - createAdaptive(targetFile, bg) - } else { - println("Skipping file as its not svg " + svgSource.fileName) - } - } - - @Throws(IOException::class) - private fun createAdaptive(xmlPath: String, bgColor: String) { - val foregroundXml = xmlPath.replace(".xml", "_foreground.xml") - val foregroundFile = FileUtils.getFile(foregroundXml) - foregroundFile.delete() - FileUtils.moveFile( - FileUtils.getFile(xmlPath), - foregroundFile, - ) - val drawableName: String = FilenameUtils.getBaseName(xmlPath) - val resPath: String = FilenameUtils.getFullPath(xmlPath) - val document = DocumentHelper.createDocument() - val root = document.addElement("adaptive-icon") - .addAttribute("xmlns:android", "http://schemas.android.com/apk/res/android") - root.addElement("background") - .addAttribute("android:drawable", bgColor) - root.addElement("foreground").addElement("inset") - .addAttribute("android:inset", "32%") - .addAttribute( - "android:drawable", - "@drawable/" + FilenameUtils.getBaseName(foregroundXml), - ) - root.addElement("monochrome").addElement("inset") - .addAttribute("android:inset", "28%") - .addAttribute( - "android:drawable", - "@drawable/" + FilenameUtils.getBaseName(foregroundXml), - ) - XmlUtil.writeDocumentToFile(document, "$resPath$drawableName.xml") - } - - private fun updateRootElement(xmlPath: String, key: String, value: String) { - val aDocument: Document = XmlUtil.getDocument(xmlPath) - val keyWithoutNameSpace = key.substring(key.indexOf(":") + 1) - val attr = aDocument.rootElement.attribute(keyWithoutNameSpace) - if (attr != null) { - if (attr.value != "#00000000") { - attr.value = value - } - } else { - aDocument.rootElement.addAttribute(key, value) - } - XmlUtil.writeDocumentToFile(aDocument, xmlPath) - } - - private fun updateXmlPath(xmlPath: String, searchKey: String, attributeValue: String) { - val xmlDocument = XmlUtil.getDocument(xmlPath) - val keyWithoutNameSpace = searchKey.substring(searchKey.indexOf(":") + 1) - if (xmlDocument.rootElement != null) { - for (e in xmlDocument.rootElement.elements("path")) { - val attr = e.attribute(keyWithoutNameSpace) - if (attr != null) { - if (attr.value != "#00000000") { - attr.value = attributeValue - } - } - } - XmlUtil.writeDocumentToFile(xmlDocument, xmlPath) - } - } -} diff --git a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/XmlUtil.kt b/svg-processor/bin/main/app/lawnchair/lawnicons/helper/XmlUtil.kt deleted file mode 100644 index bfe417d87f8..00000000000 --- a/svg-processor/bin/main/app/lawnchair/lawnicons/helper/XmlUtil.kt +++ /dev/null @@ -1,45 +0,0 @@ -package app.lawnchair.lawnicons.helper - -import java.io.File -import java.io.FileWriter -import java.nio.file.Path -import org.dom4j.Document -import org.dom4j.Element -import org.dom4j.io.OutputFormat -import org.dom4j.io.SAXReader -import org.dom4j.io.XMLWriter - -object XmlUtil { - private val UTF_8 = Charsets.UTF_8.name() - - fun getElements(document: Document, path: String): List { - return document.rootElement.elements(path) - } - - fun getDocument(xmlPath: String): Document { - return SAXReader().apply { encoding = UTF_8 }.read(xmlPath) - } - - fun getFileWithExtension(target: Path, extension: String = "xml"): String { - val svgFilePath = target.toFile().absolutePath - val index = svgFilePath.lastIndexOf(".") - return buildString { - if (index != -1) { - append(svgFilePath.substring(0, index)) - } - append(".$extension") - } - } - - fun writeDocumentToFile(outDocument: Document, outputConfigPath: String) { - File(outputConfigPath).parentFile.mkdirs() - // Delete existing file If any - File(outputConfigPath).delete() - FileWriter(outputConfigPath).use { fw -> - XMLWriter(fw, OutputFormat.createPrettyPrint()).apply { - write(outDocument) - close() - } - } - } -} From 1e65c278a6f1a37c272d14ba51edc2bbf234ca52 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Thu, 26 Oct 2023 15:33:01 +0300 Subject: [PATCH 03/20] Fix drawable name --- app/assets/appfilter.xml | 2 +- svgs/{24pay.svg => twentyfourpay.svg} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename svgs/{24pay.svg => twentyfourpay.svg} (100%) diff --git a/app/assets/appfilter.xml b/app/assets/appfilter.xml index e50490c1f25..ba5d6659556 100644 --- a/app/assets/appfilter.xml +++ b/app/assets/appfilter.xml @@ -51,7 +51,7 @@ - + diff --git a/svgs/24pay.svg b/svgs/twentyfourpay.svg similarity index 100% rename from svgs/24pay.svg rename to svgs/twentyfourpay.svg From 505a261055f1656c40f858cdfd85919f072d54d9 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Thu, 26 Oct 2023 16:12:11 +0300 Subject: [PATCH 04/20] Update Stay Fit Gym and 24pay --- svgs/stay_fit_gym.svg | 2 +- svgs/twentyfourpay.svg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/svgs/stay_fit_gym.svg b/svgs/stay_fit_gym.svg index 42933ca0ddf..a4b4d1422e6 100644 --- a/svgs/stay_fit_gym.svg +++ b/svgs/stay_fit_gym.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/twentyfourpay.svg b/svgs/twentyfourpay.svg index bc81593089f..8cd2684ae87 100644 --- a/svgs/twentyfourpay.svg +++ b/svgs/twentyfourpay.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From fa872466e02846eee087168c2511882ff19175f9 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Thu, 26 Oct 2023 16:21:41 +0300 Subject: [PATCH 05/20] Update 24pay again --- svgs/twentyfourpay.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgs/twentyfourpay.svg b/svgs/twentyfourpay.svg index 8cd2684ae87..fb9a17c9311 100644 --- a/svgs/twentyfourpay.svg +++ b/svgs/twentyfourpay.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 527c97a711421286fd31692010a03f9be770b3d5 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Thu, 26 Oct 2023 16:38:03 +0300 Subject: [PATCH 06/20] Attempt to fix Youth Tb --- svgs/youth_tb.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgs/youth_tb.svg b/svgs/youth_tb.svg index 500de504946..796dbd1b5d0 100644 --- a/svgs/youth_tb.svg +++ b/svgs/youth_tb.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From e729f30ffe3598381c9df4797c3dad31d5c6c176 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Thu, 26 Oct 2023 16:53:00 +0300 Subject: [PATCH 07/20] Update position of "YOUth" --- svgs/youth_tb.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgs/youth_tb.svg b/svgs/youth_tb.svg index 796dbd1b5d0..d1b3e3014bc 100644 --- a/svgs/youth_tb.svg +++ b/svgs/youth_tb.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 3f02a0a021fdcc87087fbe338a5b40dbeae2feee Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Thu, 26 Oct 2023 22:32:57 +0300 Subject: [PATCH 08/20] Update Stay Fit Gym, YOUth TB and MyEdenred --- svgs/myedenred.svg | 2 +- svgs/stay_fit_gym.svg | 2 +- svgs/youth_tb.svg | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/svgs/myedenred.svg b/svgs/myedenred.svg index f7d2087a950..c08ade33ab8 100644 --- a/svgs/myedenred.svg +++ b/svgs/myedenred.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/stay_fit_gym.svg b/svgs/stay_fit_gym.svg index a4b4d1422e6..1349b2661b1 100644 --- a/svgs/stay_fit_gym.svg +++ b/svgs/stay_fit_gym.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/youth_tb.svg b/svgs/youth_tb.svg index d1b3e3014bc..02502a78f39 100644 --- a/svgs/youth_tb.svg +++ b/svgs/youth_tb.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 0ffe86a8318ddc75a62af6d77492a23da1f9c825 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Fri, 27 Oct 2023 19:44:00 +0300 Subject: [PATCH 09/20] Add AntenaPLAY and round A12 Widget Pack corners --- svgs/android_12_widget_pack.svg | 2 +- svgs/antenaplay.svg | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 svgs/antenaplay.svg diff --git a/svgs/android_12_widget_pack.svg b/svgs/android_12_widget_pack.svg index 8bac8fb79e5..d635096c391 100644 --- a/svgs/android_12_widget_pack.svg +++ b/svgs/android_12_widget_pack.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/antenaplay.svg b/svgs/antenaplay.svg new file mode 100644 index 00000000000..144ce726f56 --- /dev/null +++ b/svgs/antenaplay.svg @@ -0,0 +1 @@ + \ No newline at end of file From 520cc5fd03bcbc8960ce45742f75917a61765e15 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Fri, 27 Oct 2023 19:47:22 +0300 Subject: [PATCH 10/20] Add AntenaPLAY to appfilter --- app/assets/appfilter.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/appfilter.xml b/app/assets/appfilter.xml index ba5d6659556..9a3e0487b3a 100644 --- a/app/assets/appfilter.xml +++ b/app/assets/appfilter.xml @@ -239,6 +239,7 @@ + From 797b94de8b36a256c7df75ea5f8ebd081282bec9 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Fri, 27 Oct 2023 20:38:27 +0300 Subject: [PATCH 11/20] Update Info TB and YOUth TB --- svgs/info_tb.svg | 2 +- svgs/youth_tb.svg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/svgs/info_tb.svg b/svgs/info_tb.svg index 376aac35546..78ec9a0e2cb 100644 --- a/svgs/info_tb.svg +++ b/svgs/info_tb.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/youth_tb.svg b/svgs/youth_tb.svg index 02502a78f39..8d792323c1c 100644 --- a/svgs/youth_tb.svg +++ b/svgs/youth_tb.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 444b38ea919cd9795b0877ff5696f108ba80108b Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Sun, 29 Oct 2023 21:57:19 +0200 Subject: [PATCH 12/20] Space out top Youth TB letters --- svgs/youth_tb.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgs/youth_tb.svg b/svgs/youth_tb.svg index 8d792323c1c..8ee69e50798 100644 --- a/svgs/youth_tb.svg +++ b/svgs/youth_tb.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From a217c3008aad20dba8d41f25627c6dd2d46a197b Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Sun, 29 Oct 2023 22:44:52 +0200 Subject: [PATCH 13/20] First attempt at F1 Mobile Racing --- app/assets/appfilter.xml | 1 + svgs/f1_mobile_racing.svg | 1 + 2 files changed, 2 insertions(+) create mode 100644 svgs/f1_mobile_racing.svg diff --git a/app/assets/appfilter.xml b/app/assets/appfilter.xml index 02c034e3107..c415d680b35 100644 --- a/app/assets/appfilter.xml +++ b/app/assets/appfilter.xml @@ -1532,6 +1532,7 @@ + diff --git a/svgs/f1_mobile_racing.svg b/svgs/f1_mobile_racing.svg new file mode 100644 index 00000000000..541b823abd8 --- /dev/null +++ b/svgs/f1_mobile_racing.svg @@ -0,0 +1 @@ + \ No newline at end of file From 5460ad336979c7d27c760cd237ae4ca679de051d Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Sun, 29 Oct 2023 22:51:46 +0200 Subject: [PATCH 14/20] Add missing space --- app/assets/appfilter.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/appfilter.xml b/app/assets/appfilter.xml index c415d680b35..bf58c0c20bc 100644 --- a/app/assets/appfilter.xml +++ b/app/assets/appfilter.xml @@ -1532,7 +1532,7 @@ - + From b6ca628f2a8028e62d712a1c4f32e697c32b932b Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Mon, 30 Oct 2023 14:48:22 +0200 Subject: [PATCH 15/20] Update Youth TB and F1 Mobile Racing --- svgs/f1_mobile_racing.svg | 2 +- svgs/youth_tb.svg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/svgs/f1_mobile_racing.svg b/svgs/f1_mobile_racing.svg index 541b823abd8..199049c194c 100644 --- a/svgs/f1_mobile_racing.svg +++ b/svgs/f1_mobile_racing.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/youth_tb.svg b/svgs/youth_tb.svg index 8ee69e50798..59583fee5a0 100644 --- a/svgs/youth_tb.svg +++ b/svgs/youth_tb.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From b7d0f398af76b057708ebbe49203e4b39dddd792 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Mon, 30 Oct 2023 15:49:54 +0200 Subject: [PATCH 16/20] Update F1 MR and Info TB --- svgs/f1_mobile_racing.svg | 2 +- svgs/info_tb.svg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/svgs/f1_mobile_racing.svg b/svgs/f1_mobile_racing.svg index 199049c194c..e1c38b08063 100644 --- a/svgs/f1_mobile_racing.svg +++ b/svgs/f1_mobile_racing.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/info_tb.svg b/svgs/info_tb.svg index 78ec9a0e2cb..319bdf4786a 100644 --- a/svgs/info_tb.svg +++ b/svgs/info_tb.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 7c1a67b2de4eaaf6aec8055f5979fc8f4b7a175e Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Mon, 30 Oct 2023 16:44:58 +0200 Subject: [PATCH 17/20] Test alternative AntenaPLAY version --- svgs/antenaplay.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgs/antenaplay.svg b/svgs/antenaplay.svg index 144ce726f56..3d3a91b1ee7 100644 --- a/svgs/antenaplay.svg +++ b/svgs/antenaplay.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 26b549f310bc41b5f29b14b47bd3e01179e7c647 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Mon, 30 Oct 2023 16:57:15 +0200 Subject: [PATCH 18/20] Update F1 MR and AntenaPLAY --- svgs/antenaplay.svg | 2 +- svgs/f1_mobile_racing.svg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/svgs/antenaplay.svg b/svgs/antenaplay.svg index 3d3a91b1ee7..f9d6acf45c6 100644 --- a/svgs/antenaplay.svg +++ b/svgs/antenaplay.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/f1_mobile_racing.svg b/svgs/f1_mobile_racing.svg index e1c38b08063..7d174fc351e 100644 --- a/svgs/f1_mobile_racing.svg +++ b/svgs/f1_mobile_racing.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 63b8f50a2f7ad9ad600645a0b503f02ec2151048 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Tue, 31 Oct 2023 11:04:06 +0200 Subject: [PATCH 19/20] Improve A12 WP and move Antena to the right a bit --- svgs/android_12_widget_pack.svg | 2 +- svgs/antenaplay.svg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/svgs/android_12_widget_pack.svg b/svgs/android_12_widget_pack.svg index d635096c391..4d92be76990 100644 --- a/svgs/android_12_widget_pack.svg +++ b/svgs/android_12_widget_pack.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/svgs/antenaplay.svg b/svgs/antenaplay.svg index f9d6acf45c6..969c1801980 100644 --- a/svgs/antenaplay.svg +++ b/svgs/antenaplay.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 2880d2d108070869ba5633b3fe5d23bcf8bdacd2 Mon Sep 17 00:00:00 2001 From: Bratan Radu Date: Tue, 31 Oct 2023 11:12:05 +0200 Subject: [PATCH 20/20] Move Antena even more to the right --- svgs/antenaplay.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgs/antenaplay.svg b/svgs/antenaplay.svg index 969c1801980..df43f18d05b 100644 --- a/svgs/antenaplay.svg +++ b/svgs/antenaplay.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file