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

Debranding Light for Windows Phone 7

So now you are the owner of a shiny WP7 device and even got a marketplace signup so you can code applications for this thing. And after a while you realize that Microsoft released a firmware update that contains some functionality you would like to incorporate into your apps, like copy & paste for example.

But your phone just never tells you about the update, and there is nothing to be installed, and some friends of yours already got the update while you are still unable to thoroughly test your app. Then you realize the difference: You bought the phone from a different carrier.

Some carriers hold back new updates for WP7 for quite some time, which – from a developer’s point of view – might be unacceptable.

And then someone tells you that flashing your phone with an original (unbranded) ROM might do the trick, but this means that you are losing all your messages and settings and so on – almost everything in fact, since the device will be completely reset, just like after doing a fresh reinstall of you favorite OS on your PC. But at least for a PC there are a lot of backup solutions available that will bring all your data back.

At the time of writing, this is not true for WP7 devices – the only backup solution worth mentioning I know of will do a complete backup of the phone – including the device’s current ROM which means that this is only applicable if you do NOT want do upgrade the ROM. But this is precisely what debranding is about.

If your only goal is to unlock the updates for your phone so that it uses MS updates directly instead of waiting for your carrier to release them, then there is another solution. Essentially, it will only flick a switch telling your phone not to receive the updates from your carrier but directly from MS. It will not alter your branded boot screen nor any other settings on your phone. Most importantly, it will not do anything to your precious data.

This is a short outline of what I did for my Samsung Omnia 7:

  1. (Optional) Create a complete backup of your phone so you could roll back in case of failure. This might be a good idea anyway.
    1. Install the support tool for WP7
    2. Install this wrapper for the support tool (this is the backup solution I mentioned previously)
    3. Perform a backup of the phone. For me, it was ok to remove the USB cable when the app told me to even though the phone was displaying an image at that time strongly advising me not to do so
  2. Follow the instructions on this site. For me this meant:
    1. Installing the registry editor for Samsung devices. This editor comes as an XAP file which must be deployed to the phone via the Windows Phone SDK Application Deployment tool
    2. After that I had to edit one registry value and
    3. Reboot the phone
  3. This should be it. My phone announced available updates and I installed them after Zune was finished updating itself to a new version.

Some forum members claimed that this took more than one attempt for them. While it worked for me at once, some had to try 20 times.

HTH