Friday, September 26, 2014

Dynamic and custom colors on a Zooper Widget Battery indicator

This past week on my Android customization series over at Android Authority, I took a quick look at a way to dynamically change the color of a battery element in a Zooper Widget.

The idea is simple, if your battery level is below a certain threshold, the icon or text turns red, if you have your device plugged in, it is all green and the rest of the time your icon and text is simply white.

Zooper Widget is great for this sort of advanced operation, and we didn't even need to tie into Tasker to get the job done. The only downside is that Zooper Widget's Advanced Parameters can be a little much to swallow the first time you dive in. That is why I not only go through the steps and the thought process, but simply give you the string that will make it all work for you.

Head on over to my Android Authority post to get all the details and see how I pulled it off.

Now, I wanted to discuss what I did over there, it was ugly code, and the results are not as smooth and crisp as they should have been. I used two IF statements and mashed them together. Don't get me wrong, my old programming mind works great with IF statements, and the logic of nesting IFs is pretty common practice for me, but Zooper Widget has some better methods that I probably should have taken for a spin.

In the article, I shared Zooper's own example for making a battery indicator that shows green above 20%, yellow between 10 and 20% and then red when below 10%. As follows:

The discerning eye can make out that this is still an IF statement of sorts, but instead of calling [c] multiple times inside of an IF, this statement is wrapped inside of the [c], and just changes the value based on the conditions.

Would anyone like to take a stab at molding my example from the Android customization series into the Zooper Widget string format here? I'll work with you and show off my results in the comments below, later.

Thanks for checking in, be sure to check out some of my other Zooper Widget and Tasker work, when it all comes together, there is not much you can't do with your Android device.