Like JavaPoet, but for Android XML Resources
Kotlin
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
src
.gitignore
.travis.yml
LICENSE.txt
README.md
build.gradle
gradlew
gradlew.bat
settings.gradle

README.md

ResourcePoet

Like JavaPoet, but for Android XML Resources

Build Status

Gradle

repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}
dependencies {
    compile 'com.github.Commit451:ResourcesPoet:latest.release.here'
}

Basic Usage

Write variables to the poet like:

val poet = ResourcesPoet.create()
            .addString("app_name", "Test")
            .addColor("color_primary", "#FF0000")
            .addBool("is_cool", true).addComment("This is a comment")
            .addDrawable("logo", "@drawable/logo")
            .addStyle("AppTheme.Dark", "Base.AppTheme.Dark")
            //etc

When you are ready for the XML result as a file:

val valuesFolder = File(resFolderPath + File.separator + "values")
valuesFolder.mkdirs()
val configXml = new File(valuesFolder, "config.xml")
configXml.createNewFile()
poet.build(configXml)

or if you want to write it to a string:

//indentation makes it easier to look at
poet.indent(true)
val resourcesXml = poet.build()

You can even start with and modify an existing resource file:

val file = File("some/path/to/file")
val poet = ResourcesPoet.create(file)
    .remove(Type.STRING, "app_name")
    .addString("app_name", "Even Better App Name")

Supported Types

Most resource types are supported. All look similar in usage:

val poet = ResourcesPoet.create()
            .addBool("is_cool", true)
            .addColor("color_primary", "#FF0000")
            .addComment("This is a comment")
            .addDimension("margin", "2dp")
            .addDrawable("logo", "@drawable/logo")
            .addId("some_id")
            .addInteger("number", 0)
            .addIntegerArray("numbers", numbers)
            .addPlurals("songs", plurals)
            .addString("app_name", "Test")
            .addStringArray("stuff", strings)
            .addStyle("AppTheme.Dark", "Base.AppTheme.Dark")
            .addTypedArray("some_typed_array", typedArray)

We do not allow configuration of more complicated resources like drawable and anim in the creation sense. Maybe one day.

License

Copyright 2017 Commit 451

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

   http://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.