Android: Weather Focus application
“Weather Focus”is a demo application I have put together. It fetches the seven day weather forecast based on your current geographical location (latitude, longitude).
Full project source code here.
APK file here.
The source of the weather data is the XML feed from NDFD here. I am not using the SOAP service just the straight xml API. Web services under Android are possible but it’s a lot more work than I was prepared to put in.
So, a quick rundown of the application
- Uses the alarm service to spawn a periodic background thread. This thread loads the weather data, parses it and writes it to a ContentProvider.
- Uses built in GPS to fetch current location. This is tagged onto the XML request URL.
- The parser is bog standard SAX based handler. Fast and lean.
- The ContentProvider is backed by SQLLite database.
- Synced columns in database to allow implementation of a ContentObserver which listens for changes to the database and updates the textual timestamp on the front of the application.
- ManagedQuery watches the provider and updates the master list.
- Weather icons are fetched remotely from the web service and cached locally. This avoids having to get the same icon again and again.
- Data is fetched periodically as long as the application is running. This is total overkill for something like weather data but this is purely a demo to show off how to do this.
- Notifications on the top bar of the phone view.
- Toast popups to indicate the starting and stopping of service.
Basically this was the same layout as my traffic application. I just switched it to weather data as I was getting bogged down trying to implement a fancy back end to that app. I will get back to it but I figured better to learn to walk before I run.
Notes
- If you modify the database you will have to set the version number constant to a different value to force the database to rebuild.
- Sometimes the XML weather feed returns less than seven days info. Strange!
- Sometimes the odd strange characters seem to appear instead of the proper weather description.No idea why, it’s coming from the feed and not the application.
I notice that this is quite like the HandWx weather application which has a similar forecast screen. The HandWx application also has radar weather data on the google map view. I’m not sure if that data is available across the xml service but I think it would be interesting to look. Will keep you posted.
GWT: gTraffic Usage
I have Google stats activated for some of my websites including gTraffic the UK traffic Google map mashup. The site ticks over with fairly low stats of about 20 people a day (I salute you fellow traffic junkies). Occasionally when there is a bank weekend or a public holiday the stats jump to some fairly respectable figures. For example, there is a monday holiday coming up in the UK this weekend, check out the stats. Both spikes are holiday weekends:
This is interesting in all sorts of ways if you are into road traffic websites. Basically (and I can back this up from the commercial sites I have worked on), noone gives a hoot about the traffic on the road until they have to make a journey. Then they want to know if they are likely to get held up as the pack the kids into the 4×4 and make the journey down to Dover or north to the Lake District. For those of you who use gTraffic I thank you and have good holiday.
Android: Traffic App with icons
Okay it needs a bit of formatting but I’m quite chuffed I figured this out.
Android: Initial Thoughts and Traffic App
I have been meaning to get into the Andoid SDK for a while but I was having some time off from doing any development at home so I left it alone for a while. Well now I am back and I have been having a play around with the SDK and the emulator. This is a screenshot of an application I put together which uses the current GPS location to look for local traffic situations using the Yahoo traffic API.
I won’t lie and say I knocked this together really quickly because I didn’t, it was a bit of a hard slog and it still doesn’t display any icons to indicate the situation type like I had planned. I put this up just to show what I have been working on. I have to say as someone who likes to play about with frameworks that I found this pretty difficult, maybe because I wanted to do it properly and not cut corners. Highlights are:
– Uses AlarmManager like the AlarmService example in the API examples to trigger a background service which launches a thread to download Yahoo traffic reports based on the current GPS position (and a fixed radius – I haven’t got around to making any other views yet).
– Uses SAX parser handler to extract the XML values and builds a temporary list of traffic objects.
– The traffic service writes the traffic data to a custom ContentProvider. Data is stored in rows in a database.
– The view list activity listens for notifications from the ContentProvider for updates to the data and redraws the master list accordingly.
First impressions? I had no idea it would be quite as difficult to use the framework. It was simple downloading the SDK and getting the sample applications up and running (not my experience with J2ME but that was a while ago). But, actually creating something was a bit of a culture shock even for a hardened framework explorer like me. There is lots of terminology and concepts to get your head around.
My initial impetus for the application was from a different direction to just getting traffic reports. I first started by thinking about what sort of things you could do with a wireless device with a built in GPS that could be applied to traffic information. What popped into my head was a system like this. The GPS in the phone could be used to calculate a travelling speed and this along with current position could be sent to a central server which would aggregate this information for your area. Based on reports from other users a picture of real surrounding road conditions could be built up.
A quick check on the net revealed that there is already another project along these lines here Jamdroid.
Also, I reckon this does something similar was well in terms of pinning the location to a road or route.
Google are also into this stuff with their acquisition of a company called ZipDash. There is a description of the companies patent application here.
An existing hand held device here.
I will probably keep plugging away at this anyway and will keep you posted. Nothing until next week as I have a busy weekend.