onsdag 28 oktober 2009

Using Map and List in the same activity

One of Javas problems (not correct to call it a problem maybe) is the lack of support for multiple inheritance. This means that you cannot extend both for instance MapActivity and ListActivity from the same class. So how do you implement a map with a list then? It's easy!

The ListActivity is nothing more than a wrapper around the ListView. What it does is only making it slightly easier to use a listView but it doesn't give you any extra value.

Instead of using the getListView() of ListActivity you simply fetch your own declared ListView exactly the same way as you fetch any other view

ListView lv = (ListView) findViewById(R.id.my_list_view);

You can then use this in any way you prefer. Put an adapter to it by using setAdapter() instead for ListActivity.setListAdapter() (it does the same thing).

This actually took me a while to figure out since almost all tutorials and the examples always extends the ListActivity instead of using the raw view.

fredag 2 oktober 2009

Localhost settings for Android emulator

Recently I stumbled upon a problem when trying to connect to a local webservice through the Android emulator. Everytime I tried to connect it ended up with a "Connect refused" exception.

The answer to the problem and the solution is simple. What I was trying to do was to connect to "http://localhost:7001/myWebservice". The emulator interprets this as a connect to itself because it sees itself as localhost (of course :) ).

The solution? As Google states in their Android documenatation, http://developer.android.com/guide/developing/tools/emulator.html#emulatornetworking , the emulator runs behind a virtual router/firewall and you can reach the host loopback interface (127.0.0.1) by using the adress 10.0.2.2.

torsdag 1 oktober 2009

SOAP webservices on Android

To be able to consume SOAP ws on your Android phone please follow the simple steps in this blog http://android.amberfog.com/?p=45 .

You also may need to rename HttpConnectionSE to HttpConnection or update the code using your *HttpConnectionSE class instead.

fredag 11 september 2009

New version of Fordonjägaren coming up

I just got some time over to continue on the project Fordonsjägaren.

Next update will primary fix some bugs and it will also switch over to use a much more reliable data source instead of the old "less good" one :)

The stolen vehicle data is updated once every 24h from police and insurance compaines and there will be a possibility to search not for only registered vehicles but also for boats!

I expect the new version to be launched by mid october. Hopefully there will also be some more features added like geotaging of locations, search history and maybe maybe maybe a first sample of number plate recognition via taken photos.

tisdag 25 augusti 2009

Fordonsjägaren beta released on android market


Yesterday I released the very first version of Fordonsjägaren. This application is meant to assist people in the hunt for stolen vehicles and with the help of the easy to use gui one can enter a registration number from a car or motorcycle and easily get hold of information wheter it was stolen or not. In the case of a theft you will also see details about the vehicle such as date it was stolen, location, brand, color etc.

This first version is of very simple nature just to show the concept. Later versions will have support for reporting geographical locations, fast dial to the police and so on, there are many cool features to add! However it turned out to have a couple of bugs, making it hard to use on some phones :( Will look in to that next week.

You can find the program via Android Market under the name "Fordonsjägaren".

Hooked on Android!

Recently I understood the power of Googles new Android so now I am proud to announce my self to the family of android developers. Yesterday I realeased my first application, more of that in the post!

To all of you who haven't tried Android out yet, please do, it's possible to do all sorts of crazy stuff like using the GPS and map support for creating new mind bending applications!

måndag 19 januari 2009

Nice util to copy properties!

Have you ever used for instance JPA over EJB and got frustrated when you manually need to set your getters and setters of the DTO manually? I certainly have and in my current project we developed our own tool to handle these kind of problems.

Database (entity obejct) <-> DTO (transfer object) <-> EJB cloud <-> UI that uses DTO.

This is probably a common way to implement an application that takes advantage of Javas EJB but it also means A LOT of set and get between the DTO and the database entitys when you need to transfer data from backend to frontend.

Our first solution was a simple one, we used reflections to find getters and setter and then just transferred the values. However problem arised when we had lists with complex types i.e. DTO's in DTO's. Our copy properties class util just grow bigger and the performance was terrible!

One day we found this lovely tool on sourceforge called Dozer, Dozer homepage. Out of the box it handles all of these problems without any problem and it perform great! I made a quick benchmark with 10000 entitys and found it 8.6 times faster than our own implentation :)

It works like this. Lets say we have our entity object DogEO and our transfer object DogDTO:



DogDTO dto = new DogDTO();
dto.setHeight = 2;
dto.setWeigth = 23;

DogEO dogEo = new DogEO();

MapperIF mapper = new DozerBeanMapper();
dogEo = (DogEO) mapper.map(dto, DogEO.class);



This maybe seems like a small problem but trust me when you have 30+ DTO's with complex structure and content that are subject to constant change, then this is the shit!

onsdag 7 januari 2009

JPA Query cache

Ok i'll take this one in english since it doesn't touch any motorcycle stuff :)

I've recently had some cacheing problem with JPA when working with detached entities that we later on had to re-attache due to the fact that we are using EJB and hence have 2 separated domains.

In our case we actually don't want any cacheing under many circumstances since this put alot of old information into the entitymanager that is later fetched by other threads and hence they get old information. However it seems like many entitymanger providers have cacheing turned on by default.

I found an interesting blog article java.net which explains this problem pretty well, http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t.html . This one is for those of you who are using toplink essentials, if you insted are using Kodo (BEA/ORACLE) as we do, please take a peek at http://edocs.bea.com/kodo/docs40/full/html/ref_guide_caching.html for more info on how to turn of the cache.

This seems to work very well but unfortunely you turn of ALL cacheing using this one, maybe not a wanted behaviour.

JPA XML Style:

>property name="kodo.QueryCache" value="false"/<