Animation of height of LinearLayout container with ValueAnimator

Had some issues with animation in Android a couple of years ago and I posted the solution to StackOverflow. I thought I might post it here as well :)

Looking at chitgoks blog post I found that I shouldn’t use view.invalidate() to have the layout redrawn. I should use view.requestLayout().

Thus the code becomes something like this:

I just wanted to add a note on how to get the height of the LinearLayout as well to make the animation dynamic. To get the height all the views need to be drawn first. Therfor we have to listen for an event that tells us that the drawing is done. This can be done from the onResume() method like this (note that in my xml I have declared the container to wrap_content for height and it is also visible, since I want to hide it from the start I do that efter measuring it):

Dynamic localization of JSR 303 validation messages with wildcards

Lets say you have a class like this

And you want to localize the messages in a file, you might do something like this:

Now you have hardcoded the values in multiple places, imagine if you have multiple properties files for different languages, you would define the values everywhere!

Instead you can do this:

And this:

Now, why are we using {2} and {1}?

The attributes are ordered alphabetically! From the board:

For the first option, Spring-managed field error arguments include the actual constraint annotation attributes in alphabetical order now. So for @Size(min=1,max=5), it’ll include the field name as {0} , the max value as {1} , and the min value as {2}

Has caught me many times.

Adding Mojarra manually when Eclipse Luna JSF Download Library is empty

When I was setting up a fresh install of JavaEE on my laptop today, the JSF Download Library would not return any results to download. Some searching suggested that I had to change my proxy settings but since I was not behind a proxy, it would not help me. Lucky enough, JSF are just another bunch of jars that can be added to a user library.

You can download the JSF jars here (scroll down for newest versions):

Then simply;

  • click the “Manage Libraries” icon on the JSF capabilities page
  • click “New” and name your library
  • click “Add external jars” and browse to the jars you downloaded

Have fun!

Run tests in different packages and linked sources with JUnit TestSuite

In a project that I’m working on we’re using linked sources and we have multiple sub-packages with JUnit tests. We ran into some issues with running the test. Thankfully, although the eclipse wizards wouldn’t help us create a test suite that would run all the tests it was trivial to write the suite by hand.

It can look like this:

This will allow you to test any class that you import no matter what package it is in. To run this in eclipse you just right click the AllTests class and run it as JUnit test. It will then run all the tests you define in @SuiteClasses.

This will work with linked sources as well, I use it all the time.

Send a JSON object to server over TCP connection in Java using Socket

So the other day I was struggling with sending a JSON object to a server. The JSON service would not accept this special object over HTTP so I had do dig into some Socket handling to send it. Of course, we could use Netcat to send the object like this:
echo '{"id":1, "method":"object.deleteAll", "params":["myParam"]}' | nc x.x.x.x 3994

But since the application I was working on needed to run some tests on creating and deleting stuff from the server we really needed a Java method to do this for us.

Here’s the code:

Creating the Socket is straight forward, the most noteworthy thing here the Writer that is being used. I tried with so many different Writers that I forgot what they all where called. Also note that the PrintWriter.println() method is used rather then the PrintWrite.print() method.

Accept any certificate in Java and HTTPS (SSL) connection and get your JSON on.


There are cases though, when you are developing an application, debugging an application or just playing around, that you will need to deal with CertificateExceptions, SSLExceptions and other protection mechanisms that have been put in place for security. This most often occurs when some server admin has generated a self-signed certificate and sent you an IP-address to use for connecting. The certificate will most likely lack correct information such as subject alternative name, common name etc.

If these issues occur, of course you should contact the server admin and have him/her generate a proper certificate. Sometimes though, there is not enough time or good will from the admin side and you have to take extreme measures.

First thing you need to do is make sure you have the Apache HTTP Client library installed.

Then you can create the following class that will create a special SSLSocket that will accept any certificate:

Then in your class that will be calling the HTTPS URL you can have the following method that will create a new “special” HTTP client:

Now that you have an INSECURE HTTP client you can finally make a request. In this example a connection is made to “jsonURL” and fetches some JSON object:

Nicer looking GitStats and Graphs

Heikki Hokkanen is the author behind the awesome tool GitStats. It is widely used all over the world to bring out some readable statistics from a git repository. Of course it is possible to get some nice command line output but there is nothing like a couple of bar charts and line charts.

The CSS-design of the tool is not the most updated to suit the modern day demands from bosses and customers so if you want to show off some stats you might want to try out my modified version of the tool. I take no credit on the tool what so ever, I’ve only spent a little time re-doing som CSS. I am not completely finished with the work yet since some of the styles are being set in the script that generates the html from the git repos.

I will post again once it’s finished until then you can at least give it a try and post some feedback over on GitHub!


If you don’t like graphics with more then 8-bit color space and you love the terminal, don’t worry. I have something for you as well. Add the following codes to your ~/.gitconfig file and you will be seing colors all over the place when running the commands git lg/lg2

lg = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' --abbrev-commit

lg2 = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative

PieChart with AChartEngine in Android

In my last project I was spending a lot of time looking at charting/graphing libraries for Android. I finally found the awesome AChartEngine but found it very hard to get a simple example working. So here is now a small PieChart example which hopefully can get you started! This example shows a pie chart with income, costs and the difference in a “sub total” sum.

Here’s a quick how to:

  • Extend GraphicalView (class in AChartEngine)
  • Create a getNewInstance method that returns the current class using a custom Renderer and DataSet
  • Create a custom Renderer (defines colors and labels for the chart)
  • Create a custom DataSet (the data maps to the colors you give in the renderer)
  • Profit!

To use this awesome PieChart you’ve now created you need to create a Layout in your xml which you can add the instance to.

Adding HP Photosmart C5280 to DS209 NAS

After lots of trouble and searching for Linux drivers to get the printserver in the Synology DS209 to work properly I had given up on wireless printing at home. Being bored tonight though, I got into my hea to give it another try since I had a Diskstation Manager update for my NAS.

After the update I figured what the heck, lets see if they’ve added some more options that I can tweak and what do you know, there was!

So, to get this working I:

  1. Plugged printer USB into the DS209
  2. Open the external devices in the Diskstation Manager
  3. Mark the printer in the list and click Usb printer manager -> setup printer
  4. Use Network MFP (this wasn’t here when I last tried!)
  5. I enabled AirPrint (Haven’t seen this before either!)
  6. Setup Brand to HP and Driver to HP Photosmart 7150
  7. Add printer and install any needed drivers on computer
  8. Done!

The 5280 still isn’t officially supported it seems but now I’m printing from both my Mac, Hack and Windows machines without problems. Next fight is scanning :)