[ Content | Sidebar ]

Android – UK Highways Agency Traffic App

February 10th, 2015

I have been getting back into Android programming again. To easy myself back into it and also force myself to use Android Studio I have put together a nice road traffic application. This kind of app covers a lot of the Android API so it’s a great way to update myself on the changes to the API.

The code is up on github here.

Let’s cover some of the interesting stuff.

Recycler List View

So this uses the new Android list component, the RecyclerView. In my previous post you can see my prototyping of the list as I wanted to get it right. I think it turned out okay and it’s a better example than most of the ones kicking around the net. Any dummy can built a list with one text item. It’s when you want to have icons and multiple text lines that the noddy demos than people post all fall down. So here is a decent example of something you might actually want to build.


I am using a image cache to cache the severity icons. You will see that the icons are categorised by type too. I just need to get around to generating some images.

Data Loader

The data is loaded using an RSS parser library I built a while back and have been meaning to use for some time. Data is pulled by a background task using Androids Loader API. This is the recommended component to do this now. In the past I had to roll my own threaded component.

Navigation Drawer

I want to do a bit more with this but in the meantime this is the drawer generater from the standard demo provided with Android Studio. I have tweaked it to load a list of traffic regions defined my an OPML file read locally to the application.


This is a nice way to this do this. The regions are not hard coded into the code.

Easy CP

My content provider library really shines here. It was so easy to define the domain object and write the code to read and write to persistence. If you haven’t already seen it check out EasyCP on github.

Android Studio

Finally, my take on Android Studio. Meh..it’s okay. Is Eclipse a better IDE? Yes. Can I understand why Google might want to have their own IDE? Yes, I think I can see why. I guess it’s about control and they don’t have any control over Eclipse. Now they’ve got control of the IDE and the build system. Despite the fact that 1998 called and wants it’s UI back. Also, just remember IntelliJ are not going to hand the over their core business to Google so don’t expect to be able to load in any old java project to AS any time soon. Google are always going to have to cripple this IDE in some fashion to avoid stepping on IntelliJ toes. Writing this application I had to switch back and forth between Eclipse and AS which was a bit of a pain in the arse. Anyway, we’ll see where they go with this.

Android – Recycler View Sample

February 2nd, 2015

There are quite a few samples of the new Recycler list component kicking around on the net. The problem is most of them are a bit too simple. Anyway, I have written a nice example which has most of the features you might want.

  • Icon which changes according to the data.
  • Material-design styling.
  • Multiple items on a row.
  • Dark outline around rows.
  • Short and long click handling.


The code is up on github here.


LibGDX – Demos Updated for LibGDX 1.2.0

July 28th, 2014

After some prompting I have finally got around to updating my LibGDX extenstion library and associated demos. The core library has been modified to pull the LibGDX library from the default maven repository at version 1.2.0. The demos have been updated accordingly to match the adjusted API. You can find all it in the usual place here.


The poms for the Android targets were not correct. I have updated them. To install type:

mvn -Pandroid install

Web: Spring 4 & Thymeleaf Hot Cache

July 21st, 2014

You might have run into a problem with using Thymeleaf and Spring 4 configuration where your changes to a Thymeleaf template are not immediately reflected on the page after refreshing it. Quite annoying especially as it worked ok with JSP’s right? To fix it adopt the following

 * Web configuration.
// Marks this class as configuration
// Specifies which package to scan
// Enables Spring's annotations
public class WebConfiguration extends WebMvcConfigurerAdapter
	public static final String DEFAULT_PREFIX = "/WEB-INF/templates/";
	public static final String DEFAULT_SUFFIX = ".html";
	public static final String DEFAULT_MODE = "HTML5";
	public static final String[] DEFAULT_VIEW_NAMES =

	// Hot re-load, false=will reload changes.
	public static final boolean DEFAULT_CACHE = false;

	public ServletContextTemplateResolver templateResolver()
		ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();

		return resolver;

	public SpringTemplateEngine templateEngine()
		SpringTemplateEngine engine = new SpringTemplateEngine();

		// Need this for hot re-load

		return engine;

	public ViewResolver viewResolver()
		ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();

		return viewResolver;

	@Description("Spring message resolver")
	public ResourceBundleMessageSource messageSource()
		ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();

		return messageSource;

	 * Add our static resources folder mapping.
	public void addResourceHandlers(ResourceHandlerRegistry registry)

See the bits concerned with DEFAULT_CACHE. Copy these and you will find your changes reflected right away just like good old JSP!

Java – Ticket Checker Bot

May 20th, 2014

Recently I was out-gunned in my ability to mash the keyboard fast enough and get past the capchas quick enough to nab myself some sought after tickets to Kate Bush in concert. There are rumours that there might be a second round of tickets released at some point. I’m not sure that’s going to turn out to be true but just in case it is I thought I would turn my failure into action and write an application which  will check for me and send me an email should tickets suddenly become available. It’s also an good excuse to learn some new things with Guice , the Java email API and velocity  (a template engine for Java).

In the end I created a wee application which has a whole load of interesting stuff in it. I can see it might come in useful for me and maybe others.

I wanted something I could set to run periodically and which would notify me by email.

I initially started using selenium but soon realised that I didn’t need a browser to navigate and scan a target site so settled on htmlunit instead.

The email component is setup to use gmail as a smtp gateway so you will need an gmail account with two-step validation switched off.

It’s totally over-engineered of course (you could probably do it in about 10 lines of perl no doubt) but that’s not the point is it?

  • Uses Guice to implement services and singletons and load properties.
  • Unit tests with their own test Guice module.
  • Uses htmlunit to load and process webpage content without a browser.
  • Uses velocity to define any number of email templates and loads their definitions. You can technically extend the application to have different emails for different scenarios.
  • Concept of modules which return a list of links (the condition under which the links are selected is custom to the module).
  • Mavenized.
  • Builds to a command line application for Windows or Linux which can be set to run periodically.
  • Shows how to bundle configuration for a Maven project such that the config lives outside the JAR file.


The application has the concept of module (separate from the Guice module). These are custom classes which implement an operation of some kind which returns a list of URL links.

A module subclasses from the ModuleBot class and implements the interface:

public interface BotModule
   * Run module.
   public void run();

   * Return list of valid links.
   * @return links.
   public List<String> getLinkStatus();

In my sample I navigate to the gigsandtours website and look for the presence of a ‘buy ticket’ button. You could make it anything your were watching for.

A module is added to run by the application by adding it to the loadModules method in the TicketBot class i.e.

* Load site modules.
* @param modules
* @param client
private void loadModules(List<BotModule> modules, WebClient client)
   modules.add(new ModuleGigsAndTours(client));

This is the current definition which takes the custom module I wrote for checking the gigsandtours website.

You will need to fill in your gmail credentials in the application-live.properties file. I have put dummy placemarkers in for the moment. Since this will be running on your own machine noone is going to be able to access it. If they can access your machine to look at your gmail password in this file you are already stuffed!

The application uses velocity as a template engine to build a notification email. The advantage of this is that the email layout is defined in the template and not hard-coded into the application. Take a look at the sample.

Build And Run

The component uses Maven.

To build issue the command line:

**mvn install**

This will create a zip file of the component distribution. Unzip this file to your target machine and modify the properties to match your email etc.
For Windows there is a batch file for Linux a shell file. For Windows create a periodic task to run the batch file and for Linux setup a cron job.

The project and code is up in github under the Apache 2.0 license.



LibGDX – Simple Shooter Demo Broken (update – fixed)

February 13th, 2014

I seem to have somehow cocked up a commit to the LibGDX demos and deleted some asset files for the Simple Shooter demo. My apologies to anyone trying to build this. The really bad thing is that I thought I had backups in my own subversion repository and to my horror it isn’t there at all so I am going to have to put the missing fonts and stuff together again which isn’t going to be quick. I’ll put a notice up when it’s fixed. Sorry about this.


Okay, I  have fixed it. As noted in the comments I did look at the version history but it seems I may not have committed the files properly in the first place. Pretty lax of me not to check a fresh build out on my most popular github repo but I hopefully have learned my lesson. I am going to make sure I have a back up to my local SVN as well in future. 

One last note is that the Android maven build seems to be broken still so I am going to look at that next.

Dart: Pub Get not working – Solution

January 23rd, 2014

I haven’t posted anything in ages. I have been working away on various projects some of which were dead ends some of which might lead to something, we’ll see.

Also, I have been playing around with Dart, Maven and Tomcat which I will post about later. One problem I came across which I couldn’t find a straight answer to anywhere on the web was an issue I had with ‘pub get‘ for Dart. This command downloads your dart application dependencies to a folder local to your Dart project. For some reason is just stopped working properly for me. It would create the folder structure but not fetch any (or not the majority of) files. I tried

  • Deleting the pubspec.lock file and redo ‘pub get‘.
  • Deleting my package folders and redo ‘pub get‘.
  • Trying ‘pub upgrade‘ in case that had some effect. 

None of these actions had any effect.

I knew it had to be something to do with a local cache but I couldn’t find the folder as stated in the documentation. It does mention you can define a system variable PUB_CACHE to redirect the cache to where you want. So I created a system variable (windows) and set it to a folder under my user setting  and then retried pub get‘. This time it worked perfectly.

It is not clear to me what I did to break the ‘get’ mechanism. I wish I knew so I could raise an issue but in the meantime I hope this helps someone else with the same problem.

LibGDX: Noiz2-gdx Vector Shoot Em Up

September 1st, 2013

I have been noticing that there are quite a few instances of my original port of Kento Chos esoteric shooter – Noiz2 available. It has made it’s way across the internet on various app stores mostly unchanged which is fine by me. A few people have added adverts. Good luck to them.


Anyway, just to keep ahead of the game a bit I thought it was time to lavish some love on the noiz2 codebase and see if I couldn’t bring something new to the party. With this in mind I have mavenized it, ported it over to use LibGDX and put it up on Github. This took most of this weekend but I think I have almost got there.


The main new additions are:

  • Mavenized (hurray)
  • Moving star background
  • Minor tweaks to the GFX.
  • Much nicer menu with a lot borrowed from the Simple Shooter demo.

It is not finished. I have not wired the preferences or the persistence of what levels the player has completed. Also the Android platform hasn’t been added yet.

The most interesting thing about the porting procedure was that it was pretty painless. I had abstracted the graphics and control elements previously as I had OpenGL and Canvas renderers available for the Android version. Wiring in the GDX elements was a complete doddle.

Future improvements

  • Rewrite the ScreenGDX primitive renderer to be more efficient (I have yet to try this on Android).
  • Proper glowing vector lines.
  • Saving game state.
  • Saving preferences.

Code is here.

Update #1

I have got persistence of the game state and some of the original setting like sound and volume working with the LibGDX ‘Preferences’ class. Not so hard after all. The settings screen is a little flaky though. I have also started to tidy up a lot of the game text which was a bit wonky looking. One thing to note is I have ditched the original bitmap logo as I just don’t think it looked very good. I am trying to improve the look and feel overall rather than go for a ‘classic’ port of the game. I have, after all, already done that.

Update ‘#2

Added a nice menu. Can’t get it to run on Android yet.

Update #3

Working on Android. Looks good. Persistence of settings not working properly. I plan to fix this and then publish as an update.

GWT: TrafficMap – GWT & Leaflet Map Example

July 2nd, 2013

Here is a nice GWT and Leaflet map application I wrote to ease myself back into GWT again after not having written a line of GWT code since 2009. It is a classic map and list type site which displays some sample data I downloaded from the UK Highways Agency traffic RSS feed.


Not content to knock something together just to get it working I have as usual done it the hard way by embarking on learning about GWT UIBinder and the MVP design pattern which Google are promoting in the latest version of GWT. My intention is to eventually write something bigger after getting up to speed on GWT again. The result is a simple MVP application which utilises composite binder xml views and the GWT Leaflet map component. All mavenized for an easy(ish) build and deploy process.

You can download the project from here.



The data comes from the Highways Agency RSS feed here. This was downloaded and processed by my RSS parser which you can find here.

I used the Google JSON library to convert one of the feeds to a JSON file which was my sample data.


The map is the GWT Leaflet component. The component attaches itself to an g:HTMLPanel defined in the MapView.xml UIBinder template.

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
	.mapViewPanel {
		padding-left: 10px;
		padding-right: 10px;
	<g:HTMLPanel ui:field="mainPanel" addStyleNames="{style.mapViewPanel}" >

You cannot instantiate the map control directly in the constructor of the binder. You won’t see anything. It has to be created and attached in the onLoad method of the composite view i.e.

protected void onLoad()

	// ---------------------------------------------------------------
	// Map Widget
	// ---------------------------------------------------------------

	MapWidget mapWidget = new MapWidget(MAP_DIV);

	// ---------------------------------------------------------------
	// Map Configuration
	// ---------------------------------------------------------------

	// Create Map instance
	MapOptions loptions = new MapOptions();
	loptions.setCenter(new LatLng(55.864237000000000000, -4.251805999999988000));

	Options tileOptions = new Options();
	tileOptions.setProperty("attribution", MAP_ATTRIBUTION);
	TileLayer tileLayer = new TileLayer(MAP_URL, tileOptions);

	myMap = new Map(MAP_DIV, loptions);



A few things to point out.

  • I couldn’t get the the ‘fitBounds’ method to work which I believe should set the view bounds and zoom to the data set.
  • You must call ‘invalidateSize’ to force the map to redraw otherwise the map is kind of half-drawn.
    • Layout

    The whole view is actually a composite of the left, middle and right panels. I.e.

    <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
    <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    	xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:my="urn:import:com.netthreads.gwt.client.view">
    	<g:HTMLPanel ui:field="testLabel">
    		<my:TopView ui:field="topView" width="100%" height="100%"/>
    		<g:DockLayoutPanel width="100%" height="650px">
    			<g:west size="300.0">
    				<my:ListViewImpl ui:field="listView" width="100%" height="100%"/>
    			<g:center size="80.0">
    				<my:MapViewImpl ui:field="mapView" width="100%" height="100%" />
    			<g:east size="220.0">
    				<my:PropertiesViewImpl ui:field="propertiesView" width="100%" height="100%" />

    I had bit of trouble trying to get the data table to do a single selection when a row was clicked. After a fair bit of Googling and hunting around stackoverflow I found that you cannot define this in the binder template CSS. The only was to get this to work was to define a CSS resource and pass it into the constructor of the DataGrid.

    The css.

    .dataGridSelectedRowCell {
      border: selectionBorderWidth solid #ffffff; /*#628cd5;*/
     * The keyboard selected cell is visible over selection.
    .dataGridKeyboardSelectedCell {
      border: selectionBorderWidth solid #ffffff; /* #d7dde8;*/

    The resource.

    package com.netthreads.gwt.client.view;
    import com.google.gwt.user.cellview.client.DataGrid;
     * Override the datagrid style resources.
     * http://stackoverflow.com/questions/7394151/datagrid-celltable-styling-frustration-overriding-row-styles
    public interface DataGridResource extends DataGrid.Resources
    	        DataGrid.Style.DEFAULT_CSS, "DataGridOverride.css"
    	DataGrid.Style dataGridStyle();

    And the usage:

    	private DataGridResource resource = GWT.create(DataGridResource.class);
    	@UiField(provided = true)
    	protected DataGrid<TrafficData> dataGrid = new DataGrid<TrafficData>(50, resource);

    I am going to write more GWT stuff again as I am heartily sick of javascript, css and html.

    Apache License 2.0

    Java: Standard RSS and UK Highways Agency RSS Pull parsers on github

    May 26th, 2013

    I have been looking at GWT again recently and was considering trying to write a traffic application again. I wanted to generate some traffic incident data so I dug around into some old code which I had knocking around which parsed UK Highways Agency incident RSS.

    The parser is a pull-parser. Pull parsers are fast and can be cancelled mid operation unlike SAX and DOM parsers which will block while they do their thing. This makes pull parsers ideal for Android. I did have a bit of search but this library appears to be unique in that I haven’t seen any RSS pull parsers elsewhere which is probably because they are a bit onerous to write.

    I have separated out the RSS part into it’s own library and made a new component which just does HA RSS traffic incidents.

    So, enjoy. There are unit tests which show how to use them.

    Standard OPML and RSS parser here.

    Highways Agency RSS parser here.

    The license is Apache 2.0.