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;

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.


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


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:


and this using reminders


and this using compass data