Sunday, July 24, 2016

Applying Colors at Runtime - part 1

Applying Colors at Runtime - part 1

Note: I've started the series from the latest things I encountered and required more time. On the next parts I'll try to cover the basics for ui customization.

From time to time you'll need to adjust your ui colors on runtime. It can be all the ui, or just several views. In here I collected some of the things that needs to be configure in less common way.

Window

Setting the window background instead each view background reduce the overdrawing. after setting the window background you can skip setting the activity root color

StatusBar

Status bar color can be set only on lollipop and later clients.

Tool Bar

Setting tool bar color is very common. if you can't set the color using style xml, you'll probably set it during run time.

Tab layout

Sunday, August 10, 2014

SVG support

When trying to add SVG support to our project, we encounter an issue.
We used svg-android project and it worked great, but we had a problem. Some of our images don't have a "width" & "height" attribute set on the "svg" element. when trying to load those images we got NullPointerException. After picking around, we found that the SVGParser doesn't support such images. So... we modified it: on SVGParser.java on class SVGHandler method "startElement()" modify the lines to the follow: It works great!

Monday, July 22, 2013

Modifiable Image Span

Did you ever needed to use TextView features for buttons? and you needed the buttons to be images?
I had that a lot! I needed to have a dynamic layout of icons, that will act as GridView (so they may appear in more than one line), but the Text view needed to be inside a scroll view to enable scrolling for all of the layout.
The common approach for that is using ImageSpan with ClickableSpan on it. But this also has some issues:

  1. You need the TextView to enable clicks on the ClickableSpans.
  2. You can't really modify images when you're using ImageSpan. I needed to add padding between the images.
For the first problem I found this great subclass for TextView that enable ClickableSpans without messing with the touch hierarchy. meaning you can insert it inside ListView or GridView, and still using the "normal" OnItemClickListener for the rest of the clicks.

For the second Problem I've created a sub-class for image span that can also be set with padding (in pixel) to apply padding on the image.


Color to RGB

I lately needed to get the RGB color back from the int it was saved in. The problem is that it's not really supported. The supported format for restoring the color is only HSV which isn't supported by CSS...
When trying to solve that, I came across this link which did the job.
I wrapped the important method with the necessary method to transform the color (saved as int) to HSV so the base method could do its' thing.