Posts

Showing posts from October, 2011

Getting your Android App to speak German (or any other language)

Image
I have localized a couple of apps to German now from the original English. It is a pretty painless experience, but I will just go over the main things that I did to help you on your way. Some Korean Firstly I am using Google translate for all of my translations. I speak some German, so this is not a huge leap, but I would be a bit worried about trusting it completely for a language with which I did not have any familiarity. Korean anybody? Next you create an alternative strings.xml file which will contain your translations. Any that you leave out of this will just revert to the default ones - English in my case. Not a disaster - your app won't crash for example, but certainly not ideal for customer retention, never mind delight. Next any assets that need to be different for the new locale need to be created. Images obviously spring to mind and are simple, but there are other assets which you will need to take care of. More on those later. English version So where yo

Preserving space at the end of a strings.xml string

Any trailing space in an xml string in Android will be stripped out prior to display. This can lead to bunched up displays like this: You have scored:40 points. When what you really wanted was: You have scored: 40 points. To get around this you have to use the unicode character for a space  \u0020. The details are here . This saved me a lot of time, so I decided to repost.

Javadoc for the Android Support Package

As noted at the bottom of this page . The java docs for the Android Support Package has not been provided. You have to generate them yourself. I have done this and put them on my website for reference. You can get to them here .

Using case in an update statement on sqlite

I was upgrading a database on one of my apps recently when I came across a use for a 'case' statement. I had never used this on any sql database, but had seen a colleague use it on Oracle. I had a column containing string constants. I wanted to substitute this for integers. The integers in question would be the string variables assigned by android and stored in the R class. This would allow me to localize the data returned from the database very easily. In fact the Android system will do this automatically. Here is the case statement: update res set result = (case when  result = 'Flow' then 1 when result='Bored' then 2 when result = 'Neither' then 3 end); I did not end up using the statement in the end as it would have involved finding out the generated values for the strings from R and then putting these in the update statement. I was not wild about this approach and so I just deleted the table and started the inserts afresh with the id data subst

Configuring single shot help messages

A feature I have seen on other applications that I liked was one shot help messages. These are just shown to you the first time you use a feature, access a page, view a chart etc. They don't show up again for the same user. They don't therefore annoy the user, but they don't leave them to flounder either. This is how I do this. In the onResume of the Activity that you want to nudge the user you put this code: SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(Dashboard.this); boolean oneTimeHelpShown = mPrefs .getBoolean(ONE_TIME_HELP_SHOWN, false); if (!oneTimeHelpShown) { Toast.makeText(Dashboard.this, R.string.one_time_help, Toast.LENGTH_LONG).show(); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean(ONE_TIME_HELP_SHOWN, true); editor.commit(); } It grabs a boolean from the default shared preferences to determine whether or not to show the guide toast. If the help has not been show before

Disabling logs and their associated views for production

One of the things I have added to my box of tools for app development is a some code to allow application logs to be placed in a database (instead of a normal file) for viewing from within the app on a phone. This is obviously not something I would release to production, but is very handy for troubleshooting directly on my development release on the phone. In fact there are a number of development features that a person would not want to get out into the wild. I configure these in this way. First I created file called config.xml and placed it in my values folder. I put entries like this in there: <?xml version="1.0" encoding="utf-8"?> <resources> <bool name="db_logging_on">false</bool> <bool name="db_log_viewer_on">false</bool> </resources> Then I created a Java class called Log . This contains methods which mirror those in the android.util.Log class. Stuff like Log.d(TAG, "log string&

First release of Flow Meter

Image
I have released my first Android app to the market. Its called Flow Meter and provides a way to track how often you are in a state of Flow during the day. Flow is when you are performing at your best. The task at hand is neither too easy, nor too difficult. The more time you spend in a state of flow the better. The initial researcher on Flow w as  Mihály Csíkszentmihályi. In his experiments he gave pagers to a number of participants. At random points during the day he would page them and then ask them how they were feeling. He analysed their responses to find out what activities were most positive towards a persons wellbeing. This app is just an attempt to bring this experimental method up to date. You choose how often you want to be asked 'How are you?' - I reckon about 5 times is a good place to start. Then you tell the app when you get out of bed and when you go to bed - no point in looking to see if someone is at their best when they are asleep and the phone is off. Your p

Some dashboard layouts

Image
This is a fairly common requirement in an Android app, so I decided to publish a couple of simple dashboard layouts. One for portrait and one for landscape. The portrait has 4 icons in a 2 X 2 grid. The landscape is all 4 on a horizontal line. Here are some screenshots of the 2 layouts on an Android 3.1 emulator. You can find the layout code for the landscape one here and the portrait one here .

List of required Android skills

There's not much information on the web about what skills are required for Android development. A lot of people just give very high level skills like Java and XML. Others just point to the google documentation  as say something like 'learn it all'. I think there is too much there to take on in its entirety, especially if there are areas that you are just not going to work on for the next while such as NFC . Then again I don't want to short change myself either by leaving too much stuff out. To that end I have made a list of skills that I want to master. Once I get to the bottom of this I will feel able to call myself an Android developer. I will flesh the items out as I go along and will repost the list as it changes. Build arbitrarly complex layouts Services Bound service Started service Broadcast receivers Create own (with custom broadcast) Respond to a system one Database Shared preferences Intents Create an intent filter Content providers

Handy utility to log timings

TimingLogger is a handy class provided by Google. It is built into Android, so you don't need to do anything to set it up. It acts like a stopwatch within a method, in that it allows you to 'hit the split button' a number of times (attaching a message each time) and the dump this whole lot out to the log in one go. This avoids any messing with trying to filter the log to just return your times of interest. For example here is an onClick method I wrote: public void onClick(View v) {                                TimingLogger timings = new TimingLogger("TAG", "onClick"); longThing(); timings.addSplit("long thing done"); longThing(); timings.addSplit("long thing done again"); longThing(); timings.dumpToLog(); Log.d(TAG, "finished"); } The output in the log once dumpToLog is called is this: D/TAG     ( 4434): onClick: begin D/TAG     ( 4434): o

Android mind map

Here's a mind map that I put together to track what I am doing on Android. Its in flash, so you can navigate around it. The presentation here is not perfect, but it works ok I suppose. Just a first draft, so hopefully it will improve over the next while.

Steve Jobs and the wider impact

I read Seth Godin's blog posting about Steve Jobs death. He says Jobs was the driving force behind what you are reading this on now. Initially I thought 'but this is Android, not an iPhone'. But of course there would be no Android if the iPhone had not invented the market.

Quickly extract a literal string from an xml file

As you are building an app it is fiddly to have to constantly open strings.xml to add new strings as you name the parts of the app. The latest version of the eclipse tools support automatic extraction of literal strings. Say you enter something like this in an xml editor: android:title="An interesting page" Really this should be pulled out to the strings.xml file where it is easier to localise and change. So, hit ctrl+1 to carry out a quick-fix. One of the quick fixes suggested will be 'Extract Android String'. Pick this. This opens the strings editor form and populates it with your string and an underscore separated version of it as a key. Edit what you want and then hit return to save. All done. Constantly going to string.xml was a pain and I was often not bothering. This quick fix takes away that excuse :)