JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 526 forks source link

String Resource File #26

Closed ghost closed 10 years ago

ghost commented 10 years ago

I've created a string resource file that can be included in your android project to make the icon values easy to reference reference. I know you can use the enum within the library, but I needed an easy way to be able to alias the icon names.

https://gist.github.com/keannan5390/9487918

Then you can use it like this:

TextView icon = (TextView)findViewById(R.id.icon_name);
icon.setText(R.string.icon_user);
Iconify.addIcons(icon);

or this:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="12sp"
    android:id="@+id/icon_name"
    android:text="@string/icon_user"/>
naixx commented 10 years ago

Why not to use unicode symbols directly?

JoanZapata commented 10 years ago

@keannan5390 Aliases will be supported in the next version, so I'm closing this issue. @naixx Because FontAwesome as a lot more icons than what you can find in the unicode symbols.

naixx commented 10 years ago

@JoanZapata i meant, that it would be better to use <string name="icon_glass">\uf000</string> instead of <string name="icon_glass">{fa-glass}</string>

And what are aliases?

JoanZapata commented 10 years ago

Yes it would be faster to use the unicode character directly. But anyway, this strings.xml file will be useless in the next version because i'll support aliases. An alias in FontAwesome is another name for the same icon, for example fa_ruble is an alias for fa_rub.

naixx commented 10 years ago

@JoanZapata It seems to me, that such strings/xml would be useful not because of some kind of aliases, but for compile time validation of named characters like {fa-glass}

JoanZapata commented 10 years ago

I see, you've got a point. Unfortunately it also prevent the use of surrounding text like {fa-glass} Drink, and forces the lib to be an Android Library instead of just being a simple JAR file. I'm not sure it's worth it. Maybe a gradle plugin could do the validation job… It would be interesting to dig into that!

naixx commented 10 years ago

Yep, it is rather narrow case, like Drawables or simple Image Buttons. Now, I understand, why you use resources instead of assets form fonts:) But this strings.xml could be optional and could be included as a separate file.

The other thing that I was looking for - is using custom fonts (mainly fontastic.me) as it is done in https://github.com/shamanland/fonticon. There is an additional project, that generates strings.xml based on the output of fontastic(like aliases). Of course one can use unicode characters, but using strings is rather helpful. fonticon also lacks of convenience of using strings from the code, like it is done in your project IconValue.fa_android So, if once you are to support custom fonts, it would be a great feature to have generated IconValue :)

JoanZapata commented 10 years ago

There must be a clean way to do it. I just created issue #33 for further investigation. Thanks for the feedback. ;)

nhaarman commented 10 years ago

:+1: :)