It's the little things

It has been a little while since I’ve last worked on my little Android weather app, so I wanted to get back into it with a small, simple task. So, I decided to replace the text that describes the weather with little icons. Like so:

UI Screenshot

I did some StackOverflow searching to see how people map text to image resources. I found a reasonable solution here. However, instead of hardcoding the “format string” I added it to strings.xml. Furthermore, there isn’t a one-to-one mapping from condition strings and icons. Consequently, I made a new resource file to map the formatted condition string to the actual drawable resource. A snippet of it here:

 
<item name="ic_flurries" type="drawable">@drawable/ic_weather_snow</item>
<item name="ic_fog" type="drawable">@drawable/ic_weather_cloud</item>
<item name="ic_hazy" type="drawable">@drawable/ic_weather_cloud</item>

I don’t have an icon for fog or haze, so I’m just using the cloud one for both. What my code ends up looking like then is:

Integer resourceId = getResources().getIdentifier(icon_str, "drawable", getActivity().getPackageName()); iconView.setImageResource(resourceId); 

Notes from this experience:

It really was such a small change, but I definitely appreciate how much better it looks now.

Icons made by Freepik from Flaticon is licensed by CC 3.0 BY

Comments

comments powered by Disqus