Mobile Flares for Windows Phone 7: Setup

I’d like to give a brief overview of the project for starters. The first important thing to notice here is that in this first step, there are no Mango tools involved. We are still working with the first version of the windows phone tools (7.0) and will switch to Mango later in the project. Fairly soon, though.

So the first thing I have done was reusing the parser logic. Clearly by far not the finest piece of code I’ve ever written, but we don’t even need to cover it here. The only thing worth mentioning is that it is responsible for issuing a HTTP GET to the HeavensAbove website with the coordinates your phone detected. All this scraping and parsing lives in the projects FlareParser and HeavensAboveParser. MobileFlares.Core is responsible for defining the interfaces and BusinessObjects the parsed, raw data gets transformed into.

I nearly forgot to mention the use of Async CTP features in the code, which greatly simplify working with asynchronous calls. Visual Studio Async CTP SP1 Refresh ships with assemblies for Windows Phone 7, which are included in the solution. Although the solution is self contained, you will still need to install the CTP should you want to build it yourself.

I’ve used the databound template for this project. This sets up your project with one page for master data and one page for detail data. For this step, we don’t even need the details page, we will only bind the data to a list on the master page (called MainPage.xaml)

MobileFlares/SampleData contains MainViewModelSampleData.xaml to throw design time data at the list on the master page. This is wired up in MainPage.xaml using this line:

d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"

The DataTemplate for visualizing flare data is called FlareOverviewTemplate and resides in App.xaml.

That’s it for the project layout. A bit more interesting is how the GeoCoordinateWatcher is set up. There is an initalization method in the code behind for MainPage.xaml:

private void InitGeoWatcher()
{
  geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
  geoWatcher.MovementThreshold = 1000; // Notify about new position every 1km travelled
  geoWatcher.PositionChanged += geoWatcher_PositionChanged;
  geoWatcher.Start();
}

By specifying GeoPositionAccuracy.Default we tell the watcher that we don’t need GPS accuracy and are happy to use coordinates that have been determined through cell tower triangulation. This cuts down power consumption because the GPS sensor does not need to get activated.

Movement threshold is another option for reducing both power consumption and the number of calls to the website. As long as the app is running, the PositionChanged event will only fire if the position has changed more than 1km. This is still good enough for accurate flare predictions.

There is also a LogPage implementation that can be hooked up to attach itself to the ApplicationBar. Up to this point, it has only been used to check when the GeoCoordinateWatcher fires its PositionChanged event.

So this is what happened up to revision 3: The app will get the location from your device, use the coordinates to fire a request to the website, parse the response into business objects and bind it through MainViewModel to a list on the screen.

image

The next step will already contain the upgrade to Mango tools and using the Compass API to implement what I called guidance.

Advertisements

Mobile Flares for Windows Phone 7

  1. Introduction
  2. Setup and project overview

Some ideas are more or less useless, but also just as timeless. Some time ago, I started to implement a project called Mobile Flares for Windows Mobile 6.5. It was a small app for getting flare predictions for Iridium Flares.

After I got myself a brand new Windows Phone I thought about revisiting the project to make it work on the new platform. But it was only when the new Windows Phone Mango features were announced that I eventually got into it. Mango has interesting new APIs this small application can benefit from, which is why I’d like to shine some light on implementation details in order to turn the project into a Mango tutorial.

In the following posts, I will describe the implementation progress in steps and also point to the corresponding code revision. All the code is available on Codeplex, I am using Mercurial as version control software. I have to apologize for my random switching between german and english commit comments, I will restrict it to english from now on.

Even though the main use case of Mobile Flares is extremely simple (get predictions for the current location) there are a lot of sub-usecases revolving around this, which is why the application uses, among other APIs:

  • Location API
  • Compass API
  • Background Agents
  • Live Tiles
  • Local Database
  • Reminders

It also uses Visual Studio Async CTP (SP1 Refresh) and MVVM Light.

What I like about Windows Phone development is that it’s only a special flavor of Silverlight development, and Silverlight will look familiar to anyone who has done some WPF, which is, as it happens, exactly what I have done. I will not cover the basics of XAML, data binding etc for this is not a Silverlight tutorial.

Instead, I will show how to achieve this with LiveTiles:

image

and this using reminders

image

and this using compass data

image

Satellites in your pocket (Iridium Flares)

Okay. This one is for freaks only. Or at least for people that know what Iridium Flares are.

You don’t? Take this.

Iridium Flares are moving lights (flares) in the sky that can be observed with the naked eye and are caused by sunlight being reflected by antennas of satellites, in this case those of the Iridium system satellites. Hence the name Iridium Flares. When watched in the night, the brighter ones of these flares will cast your (or indeed anyone else’s) shadow on the ground since they are much brighter than any star in the sky. Still, many people don’t know about them because you have to know where to look and each flare can only be seen for a few seconds. Telling people about Satellite Flares is good fun since some won’t believe it.

Personally, I like to watch Iridium Flares whenever I happen to be at the right place in the right time AND I’m aware of it. If you combine these conditions, you’ll be left with "quite unlikely, eh?"

The problem is not getting predictions. Go to HeavensAbove, get your position and look at the predictions for the next 7 days. Easy.

The problem is memorizing all the stuff. I hope you know when you are where for the next 7 days, because often I don’t. At least not with the precision that is needed for a good flare forecast: You should know your position within 1km. If you happen to know that, good for you. Now go to HeavensAbove and memorize all the predictions for all the positions you will be within the next few days so you know when to look in what direction.

I often wanted a way to carry all the predictions for all my favorite locations around with me so I can view them even if I do not happen to sit in front of my PC. Maybe I even wanted to update them on the run, I’m not sure about that 😉

Enter MobileFlares 🙂

I believe that a lot of people don’t need that application. I wrote it for two reasons nevertheless:

  1. I need it
  2. This is my first Windows Mobile application and therefore a training project

A third, less ego-centric reason is: There are a lot of other Iridium Flare gazers, maybe some of them can use it too.

If you have a Windows Mobile device and want to learn about Iridium Flares ("quite unlikely, eh?"), head over to the project site on CodePlex.

If you’re wondering what this has to do with cloud computing: There is a lot of computing going on at HeavensAbove to predict all these satellites that are flying around above the clouds. He he.