Android Preferences
(and Library Projects)

I’ve been battling with preferences in Android, on and off, since November 2013.

I wrote an app, Pit Board, and at the time split the preferences into two dialog boxes. A simple one for the message text and colour and an more complex one for animation styles and timings. I just created these in dialogs and thought nothing of it.

The animation styles I stored the style as an integer and the animation speed as a long value. I can then use ‘switch’ for the animation style and directly use the long value for the animation. Android preferences allow the storage of these types of variable.

With further development/reading I then wanted to replace my dialog box with a standard PreferenceFragment, which should reduce the work that I do as it automatically stores the values. A change listener can then be used in the activity.

BUT! The standard preference classes don’t have anything for an integer backed list or a way to store long values. Not only that, when setting default values in XML there is no support for long values. As a result I have had to write classes to handle those, and the long values one is a kludge as it stores the defaults as integers.

Library Projects

Obviously, having taken the time to write these I want to be able to share them across apps. At first I tried to put them in a different package (a parent to those that I was for my apps) but this causes problems when compiling. Lots of errors about not finding resources (the R class).

Reading more it seems that projects can be defined as libraries and these can be incorporated at compile time. I set about moving the preferences (and another useful class) to “utils” this morning on the train. Poor internet access can be very frustrating! I studied the examples in the TicTacToe app, but got nowhere. When I tried to compile the project it failed to find the classes that I’d moved to the utility library.

I worked on it on the way home and made the same amount of progress. Once home I googled further and found a useful post which held the secret line that fixed it!

I’d already updated the project, but I hadn’t included the “--library relative/path/to/library/project” bit. When I look at the files I can’t just see what it altered, but it compiles now. (I’d already added the library reference to and even fixed the capitalisation!)


I thought it would be useful to do a short post about Creative Commons, what it is and why I use it.

Creative Commons (CC) allows others to use the photos that I’ve taken without the need to ask permission. It also allows me to place restrictions on how the photos are used, should I wish to do so. The only requirement that applies to all of the variations of the CC licence is that attribution is given. That is, if you use my photos then you must credit me.

By default I share my photos under the “Attribution-ShareAlike” variation. This means that not only can you reuse my photos as they are, but that you are free to use them as a basis for other works – so long as you then share that work under the same licence.

I have considered the use of more restrictive licences (and occasionally need to use such) but this version has been pretty much problem free since February 2009 when I started using it.


Why do you even bother sharing your photos? It’s effort right?

To my mind there is little/no point in taking photos if they don’t get seen. I’m old enough to remember when photographs were printed on paper. I have a large collection of them. They’re in the Boots cardboard folders, in a box, under the stairs. Sad!

Why don’t you charge for them and become rich?!

Because as soon as you get paid for something it becomes a job. You have to deliver something of value in exchange for the money that you get paid. I enjoy photography as a hobby.

What are the rewards for the effort involved?

First, I get into places for free! I used to attend ThinkVisibility for free because I took photos at the first one. I now get to watch loads of roller derby for free, and stand in the middle of the track whilst doing so. It’s great! (When I say ‘free’ here I mean that there is no exchange of money in either direction. I don’t buy a ticket to get in, but I don’t get paid for the hours of work sorting through, tagging and titling photos.)

Second, if people are happy with the photos I’ve taken then they use them. People generally don’t like having their photo taken. It’s such a compliment when someone chooses to use one of my photos as their profile picture on Facebook.

Third, as people like/share my photos then I get a reputation and a portfolio and so I get to take more photos.

Do you have a preference for attribution?

The best way that people can give credit is to link back to the photo on Flickr. When people follow that link they will discover other photos. Flickr provides statistics on the number of views. It’s satisfying to see a peak following an event:

Flickr stats, April 2014This peak, of over 8,600 views in a day, was from the B-HARD vs SOFT game :-)

Firefox Offline broken

For some time now it seems that Firefox offline mode is broken or borked in some way.

I notice this on the train when I need to refer to Android documentation. Documentation can be downloaded as part of the Android developer kit. This used to work just fine in Firefox on my netbook when offline. Recently though, perhaps two releases of Firefox ago, it utterly fails.

Firefox displays nothing other than a blank white page whilst trying to connect to or Yesterday/today it has been particularly frustrating as I’ve been trying to work on stuff that I’ve not done before. Documentation was essential.

A search of the internet suggests that it might be add-on related. Some suggest restarting Firefox in safe mode. Disabling add-ons, safe mode make no difference. It is core Firefox that is at fault.

I have now installed Epiphany. It can open the local files, though the search function doesn’t seem to work. Better than nothing.

It looks like Mozilla broke something in Firefox 27?

Handy Layouts

When developing Android applications the interface layout is usually defined in XML files. Commonly the file main.xml is the definition for the first interface that the application presents to the user.

Android also allows for different layouts to be defined in XML files in different folders. The names of the folders define when the layout should be used. So, for instance, the layout-land folder holds the layouts for the application when running on a device in landscape mode. This method allows design and function to be neatly separated.

It occurred to me on the train this evening, whilst working on an app, that it might be handy to have folders for left and right handedness. This would allow for asymmetric designs, especially in portrait mode, where the device – typically a phone – is being held in one hand. So if an application has multiple buttons on the display for instance, then the more important buttons could be sized/positioned to make them easier to reach.

I don’t know if this already exists, but I wanted to get it out there so that there is prior art, hopefully preventing the likes of Apple, Microsoft and RIM from claiming it as a novel invention and patenting it.