Skip to content

msasikanth/android-resource-poet

Repository files navigation

Android Resource Poet

Maven Central CI Checks

Kotlin DSL to create Android resource XML

Adding to your project

implementation("dev.sasikanth:android-resource-poet:<latest-version>")

Basic usage

val xml: String = resourceXml {
    string(name = "app_name") {
        value = "Twine"
        translatable = false
    }

    dimen(name = "ball_radius") {
        value = "30dp"
    }
}

// Write XML to file
val fileWriter: OutputStreamWriter = // configure file output stream
fileWriter.write(xml)

Supported resource types (WIP)

String
resourceXml {
    string(name = "") {
        value = "" // Required
        translatable = false // Optional - Default true
    }
}
String Array
resourceXml {
    stringArray(name = "") {
        items = arrayOf("") // Required
        translatable = false // Optional - Default true
    }
}
Plurals
resourceXml {
    stringPlurals(name = "") {
        translatable = false // Optional - Default true
        item {
            quantity = "" // Required
            value = "" // Required
        }
    }
}
Boolean
resourceXml {
    boolean(name = "") {
        value = true // Optional - Default false
    }
}
Color
resourceXml {
    color(name = "") {
        value = "" // Required
    }
}
Dimen
resourceXml {
    dimen(name = "") {
        value = "" // Required
    }
}
Integer
resourceXml {
    integer(name = "") {
        value = "" // Required
    }
}
Integer Array
resourceXml {
    integerArray(name = "") {
        values = intArrayOf() // Required
    }
}
Style
resourceXml {
    style(name = "") {
        parent = "" // Optional - Default empty

        item {
            name = "" // Required
            value = "" // Required
        }
    }
}

License

Copyright 2023 Sasikanth Miriyampalli

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.