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 project.properties and even fixed the capitalisation!)

Posted in Android | Comments Off

CC

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.

Questions

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 :-)

Posted in Communication, Photography, Publishing | Tagged , , | Comments Off

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 google.com or googleapis.com. 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?

Posted in Open source | Tagged , , , | Comments Off

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.

Posted in Android, Open source | Comments Off

Snapshot

Back in July I stumbled across some photos of jewellery on Facebook. They were, I’m afraid, not terribly good. I sent a message to the group that had posted them and offered to go and take some better ones, free of charge.

I was pleased that they didn’t take my criticism the wrong way and I ended up falling into a conversation with them. I never got to take photos for them; those taking part in the jewellery class took their items home. We did though talk about the possibility of my running a photography class for them.

Skip forward three months and that is now going to happen!

The sessions will be on Tuesday evenings, 7pm to 9pm, from 26 November to 17 December, at Cup Cakes Coffee House in Sowerby Bridge. There is a £25 one off charge for those wishing to take part. Call 07762 884 135 if you’re interested. They are being run by the Phoenix Heights Community Group. They have a website, Facebook page and Twitter account.

Posted in Photography | Comments Off

Speed

One of Imogen’s friends, who is also doing photography in sixth form, posted that she is saving for a camera. Specifically a Canon 5D. In keeping with the tradition of Canon/Nikon rivalry I considered posted that auto correct had changed ‘Nikon xxx’ to ‘Canon 5D’.

I set about researching equivalent models in the Nikon range. The nearest I found is the D800. The criteria I used to judge ‘similar’ were sensor size and price. But the more I read, the more I think that at this price point, Canon has the better camera.

The Nikon is cheaper and has a higher resolution (36Mp) sensor, so surely it’s the better camera? Well, maybe for some uses, but I feel it fails in two respects, both a direct result of going for a high pixel density.

Because the sensor elements are smaller they are less sensitive. The ISO equivalent range is therefore shorter than the Canon and at the high end noise becomes an issue. Second, because there are more pixels, the processing engine has to work with more data. This reduces the frame rate to 4 frames per second.

I then did some reading around the current Nikon DSLR range. I have a D300, the current incarnation of which is the D300S. It’s the only DX model (ACP size sensor) that Nikon have in their “professional” range. Professional seems to equate to similar electronics to the base FX model, but with a smaller sensor.

I continue to be very pleased with this camera. It’s capable of 6 frames per second, 8 with the external battery pack. Reading through the technical specifications of the current range the only camera that I’d consider replacing it with is the D4. This is unlikely to happen any time soon as it’s Nikon’s flagship model and costs around £4,300!

Posted in Photography | Tagged , , , | 1 Comment

Android Timer Fault

Android Jelly Bean suffers a weird problem when setting a timer that is not on a ten minute interval.

I first noticed it when setting a timer for frozen pizza. They take 12 minutes, but I found that the alarm didn’t sound until much later. With some experimentation it seems that asking for a timer to be set over 10 minutes, but not at a ten minute interval, breaks things. It adds 90 minutes to the time.

Timer fault on Android

Illustration of Android timer fault

In this example I said “set a timer for 12 minutes”. As you can see from the time in the top right corner it was just after 10pm. The timer should have been set for 10.14pm but has been set for 11.44pm. If a request is made to “set a timer for 20 minutes” it seems to work.

I see this fault on both my phone (HTC One S running 4.1.1) and my Nexus 7 (4.2.2).

This issue seems to be fixed by recent updates.

Posted in Android | Tagged , | Comments Off

Laptops and Linux

I’m looking for a laptop and it’s proving very difficult! This will be my main machine, used for programming and general web stuff. It must run Linux, preferably Fedora. This is what I’m after:

  • 14 or 15 inch display with better than 1366 by 768 resolution
  • Graphics card that is supported under Linux. Needs to be good enough to run Gnome 3 but it won’t be used for games, so integrated graphics are fine
  • DVD re-writer, not bothered about Blu-Ray
  • 256Gb SSD drive (128Gb would do)
  • Intel Core i5 or better
  • Decent battery life
  • Backlit keyboard
  • USB 3 port(s)

I’m working up a table of manufacturers/models which I’ll publish here soon. In the mean time, any pointers would be very welcome. Thanks!

Update 1: Dell Latitude are looking like the favourite at the moment. Only missing USB 3.

Update 2: After much deliberation I have gone for a Dell Vostro 3550. The other factor that I didn’t include above is now much I’m willing to pay for a laptop. The Latitude looks great, but at nearly £1,500 it’s way too expensive. (It also doesn’t have USB 3 ports.) The Vostro doesn’t match on a few of the requirements; resolution is 1366 by 768 and the hard drive is a 320Gb SATA, though spinning at 7,200 RPM. Given that my current laptop is an Asus A6000 the new machine should be a joy to use!

Posted in Open source | Tagged , , | Comments Off

Libraries, bookshops and e-readers

Recently I nipped out of the office at lunchtime to get some air. I called into WHSmith, not for any particular reason, just to browse I suppose, and saw the book to the right: The Most Human Human

The cover is delightful, the title intriguing; I picked it up and began to read. It was fascinating! I wanted it. Whilst Amazon do their best to feed me adverts for stuff I might want, bookshops offer the opportunity to easily discover books quite by accident. However, I have found that WHSmith always have higher prices than any other shop. I checked Amazon, found it on Kindle and within minutes had it on my phone at half the price.

I have also been visiting the library every week recently to get books for Wendy (my partner). She broke her ankle and was in plaster. She reads crime novels, lots of crime novels, more so whilst she was off sick. These events lead me to consider libraries, bookshops and e-readers.

I’m opposed to Kindle for a number of reasons:

  • Kindle uses a DRM format
  • Users can’t easily share or pass on content
  • The format doesn’t allow for easy navigation
  • You can’t borrow Kindle books from the library

The first of two of these are obvious, the third and forth perhaps less so. I find that because an e-book has no physical form it’s not so easy to comprehend where I am in the book. With a physical book "about half way" has a meaning, it feels like half-way. It’s also fast and easy to flip between pages, useful when reading technical matter. Page numbers are also rather meaningless. For example, a quick check of the book I’m currently reading (Bravo Two Zero) gives my position as 847 of 7340. Is that 7,340 pages? If I had a Kindle, with it’s larger display, would I have fewer pages? It doesn’t make sense.

The restrictions make it difficult to borrow books from a library, but not impossible. But it’s not how Amazon anticipate users will use the books. They want users to buy the book, even if they only read it once. This is how Wendy reads crime novels; once. I keep a list of books that I have borrowed for her, to avoid duplicates. If she had purchased these on Kindle, at an estimate of £5 each, it would have cost her over £100. That’s a lot of money for books that she won’t read again and can’t pass on to friends/charity shops.

On the other hand though I find Kindle (on my phone) useful:

  • I always have a book to hand if I’m bored
  • I can carry many books and I don’t even realise it
  • I can read at night in the dark
  • If I see a book I like I can get it immediately at a reasonable price

So as you can see, I’m torn. What are your thoughts about e-books?

Posted in Publishing | Tagged , , , , , | 2 Comments

Android Testing

The Art of Agile Development, by James Shore and Shane Warden is an excellent book. I recently read it and found it inspiring. Whilst many of the practices don’t work for a lone developer, test driven development seems like it will.

So now I’m trying to set up unit testing for when I’m developing Android appications. However, I found the guidance on the Android developer website unclear. Having spent some time getting frustrated at my apparent inability to follow simple instructions I made it past the first step. I share that first step in the hope that I can help others.

The developer notes give examples using relative paths. I found that this didn’t work. Here is the relevant folder structure for my application, which is called Aoide.

~\
  Android\
          aoide\
                AndroidManifest.xml
                build.properties
                build.xml
                default.properties
                local.properties
                proguard.cfg
                bin\
                gen\
                libs\
                res\
                src\

The Testing Fundamentals page shows that I want to create a tests folder in the aoide folder. I found this command, run from the Android directory, worked for me:

tools/android create test-project -m ~/Android/aoide \
    -n AoideTest -p ~/Android/aoide/tests

Now to figure unit tests…

Posted in Android | Tagged , , , , , , | 1 Comment