Friday, August 27, 2010

Nothing really technical

In three week days I'll be working for a month in Espeo Software. So I guess some summary would be in place.

I sure have enjoyed working there and I think I have spent it well. I did learn a lot in that time, probably more than I usually learn in a month of class.

Android robot logo.Image via Wikipedia

I have been working with my collegue Kris on an app for Android. I intent to continue my adventure with Android development (waiting for new Android phone ATM). >]
I have also had a chance of diving into Groovy(augmented, dynamically typed Java-like language that runs on JVM) and Grails code (web framework on Groovy) and I intend to swim there a bit more as well.

By the way, I have been hearing some stuff about new Java version. If it's going to be even just a little more like Groovy - me likey !
By the way2, if you feel awkward with dynamically typed languages, as I am a little bit, but want the power of Groovy for yourself you might want to check out Groovy++.

There has been a poll posted on my blog for a while. An outstanding number of 10 people has voted in it (yes, including me). I'd like to thank everyone for visiting my blog and voting. =)
The poll was about programming languages you are 'mostly into' and the results are :

I have voted for Haskell, but at the moment I do not work on any piece of code in Haskell. One of the reasons is that the integration of Haskell code with Java code is a pretty tedious thing to do. My boss has recommended me Scala as a functional language that integrates with Java very well. Who knows, it might be just the thing to check out in some less eventfull times.
Currently I'm mostly into Java !
I expect 'other...' to be some .Net language (or not a programming language at all ;] ) which is quite popular with people I'm studying with.
Quite a suprise is that more votes ( 40% vs 20% ) are on C/C++ than Java.
Ofcourse that big sample is not really a sample and any reasoning based on it is pretty... lame. ;)

Monday, August 16, 2010

Android Activity.managedQuery selection and selectionArgs arguments

Most of the examples of managedQuery don't use the selection and selectionArgs arguments, others are pretty simple like :

Cursor simple(String id) {
return managedQuery(getIntent().getData(), PROJECTION,
 "id = " + id, null, DEFAULT_SORT_ORDER);


Cursor simple(String id) {
return managedQuery(getIntent().getData(), PROJECTION,
 "id = ?", new String [] ={id}, DEFAULT_SORT_ORDER);
Both of the above do exacly the same thing.
The '?'s are the elements in the array in order they are placed. [Resource]

I was working on a piece of code that stored IDs in SharedPreferences and then loaded the elements with those IDs into a ListView from a ContentProvider.

Basically I was trying to get that :
WHERE id IN ( id1, id2, id3, id4,...)

So the selection argument looked like that :
"id IN ( ? " +  [",? "] + " )"
and the selection args stored the ID of elements I wanted to load.

SharedPreferences data = getSharedPreferences("elementList",0);
Map <String, Integer> map = (Map<String, Integer>)data.getAll();
if (map.size() == 0) {
int i = 0;
Iterator it = map.entrySet().iterator();
String str [] = new String [map.size()];
while ( it.hasNext() ) {
    Map.Entry<String,Integer> pair
        = (Map.Entry<String,Integer>)
    str[i++] = pair.getKey();
    Log.i(this.getLocalClassName(), "pair key " + str[i-1]);
String whereClause = Prod._ID + " IN ( ?";
if (map.size()>1) {
    for (int j = 1 ; j < map.size(); ++j) {
        whereClause+=", ?";
Log.i(this.getLocalClassName(), whereClause);
Cursor cursor = managedQuery(getIntent().getData(), PROJECTION,
    whereClause , str, DEFAULT_SORT_ORDER);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
    this, R.layout.element_list_item,
    cursor, new String[] { NAME, DETAILS},
    new int[] {, }

Hope that not-that-trivial example make this topic more clear. If you would like to know more about ContentProviders or managedQuery I suggest you try this or the Notepad Tutorial.

Monday, August 9, 2010

Android Virtual Machine and non-ASCII characters the path

I have found a job ! =)

For a month (and hopefully more) I'll be working at Espeo Software. I've started last Wednesday and I've really enjoyed it so far. Currently I'm working on an android app. During its developement I've encountered a bug when trying to launch the AVM on Windows with a profile containing the letter 'Ł'.

This is the message I got :
ERROR: no search paths found in this AVD's configuration. Weird, the AVD's config.ini file is malformed. Try re-creating it.

It appears that while the sdk can be in a folder with such a path that contains non-ASCII character the emulator does not like it. Specifically to .android/avd which on default is stored in your windows user folder.

The solution is to add a local user/system variable ANDROID_SDK_HOME with the path to a place you want .android to be. For example ANDROID_SDK_HOME=C:\AndroidDev.

You might have to restart your Eclipse or other IDE after doing that. But that fixed it for me.

I have still got to resolve some problems with SpringSource Tool Suite and they way it sometimes breaks my xml files or considers proper xml files as buggy. Maybe switching to a standard Eclipse would be the solution.