Skip to content

Instantly share code, notes, and snippets.

@cbedoy
Last active May 24, 2022 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbedoy/5981fa6e7a5f32542a51ab7778d289de to your computer and use it in GitHub Desktop.
Save cbedoy/5981fa6e7a5f32542a51ab7778d289de to your computer and use it in GitHub Desktop.
Dimens and Font size generator
/**
* Made by cbedoy
*/
val dimenRatio = mapOf(
"mdp" to .8F, "hdp" to .9f, "xhdp" to 1f, "xxhdp" to 1.1f, "xxxhdp" to 1.2f
)
fun generate(n: Int) {
dimenRatio.map {
val dimensList = mutableListOf<String>()
for (dm in 1..n) {
dimensList.add("<dimen name=\"dimen_${dm}_dp\">${String.format("%.0f", dm * it.value)}dp</dimen>")
}
println("Dimens for ${it.key} are:")
println(dimensList.joinToString("\n"))
}
}
fun generateFonts() {
val fontList = mutableListOf<String>()
for (dm in 1..100) { // It's almost impossible have more than 100 sp though
fontList.add("<dimen name=\"text_size_${dm}\">${dm}sp</dimen>")
}
println("Fonts are:")
println(fontList.joinToString("\n"))
}
fun main() {
generate(100)
generateFonts()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment