ment-mx / Prism

Creates a beautiful artboard color palette with all your 'Document Colors' and their respective color label in a variety of formats.
MIT License
1.01k stars 47 forks source link

Android export not as good as needed #14

Closed DaRolla closed 7 years ago

DaRolla commented 8 years ago

Hi there,

thanks for your plugin. I am an Android developer, and I want to tell you our needs.

In Android it is very common to place the assets next to the code. So colors are defined in XML. Your export only suits the JAVA code, not the XML.

In more details we need something like this: https://developer.android.com/samples/BasicMediaRouter/res/values/colors.html

Maybe you can help us?

Greetings, DaRolla

Adrxx commented 8 years ago

You're totally right. I recently had some experience in Android development and found my color generation useless. It wouln't be hard to add that implementation by yourself as I explained on the readme, however I'll try to do it if I have some time.

DaRolla commented 8 years ago

Thanks for your response. I took a look at https://github.com/ment-mx/Prism#customization but I am missing some function giving me a hex with ARGB.

In format_HEX: your are using color.hex for RGB (alpha is missing). I wasn't able to find that function in order to modify it...

DaRolla commented 8 years ago

well, maybe we can use something like this:

format_ANDROID_XML: (color, commented) ->
    formattedColor = '#' + parseInt(color.alpha,10).toString(16)).slice(-2) + parseInt(color.red,10).toString(16)).slice(-2) + parseInt(color.green,10).toString(16)).slice(-2) + parseInt(color.blue,10).toString(16)).slice(-2);
    if commented
        "#{formattedColor} // #{color.name}"
    else
        formattedColor

source: http://jsfiddle.net/Mottie/xcqpF/1/light/

Adrxx commented 8 years ago

Yep, the method toString(16) is useful to convert decimal into hexadecimal. However if you have a decimal number that converts into a one digit hexadecimal number, for example: 0 is also 0 in hexadecimal. Then you would have a problem, as you need a leading 0 to complete the alpha component. That's the only problem you need to solve. The rest of the hexadecimal numbers you need (RGB) are easy to get by just calling color.hex. Also, parseInt() is not something you need. color.alpha gives you a 0 to 1 value that you can convert to a 0-255 value you need by just doing: color.alpha * 255

Sorry for the delay, I've been a little busy lately.

Adrxx commented 7 years ago

I have added support for Android XML in the last release ;) Hope you like it.

DaRolla commented 7 years ago

Thanks a lot, I will have a try...