1Transit for them All (Exclusively for WP7)

A few days ago we released 1Transit. Softly. It is an exclusive Windows Phone 7 transit application that is a bundle of simple but robust and hopefully useful features.

Features Like

The application serves data for over 20 transit agencies across North America. Yes, built for travel.

We wanted you to be able to find things fast. Thus, the searching is fast. Something we like to showoff to our friends.

No your eyes do not fool you. Those are live updates that you can receive for transit stops around you. We implemented a bookmarking (aka pinning in the Windows world) feature too, so that you can get these updates with only a touch.

Not impressed? Try it for yourself and maybe you will be. Fingers crossed.

Coming Soon

We have put much weight behind this application and we’ll be building on the current version. In the coming updates we are looking to,

  • Utilize location to enrich the experience,
  • Provide schedules and maps of routes,
  • Implement live updates of vehicle locations,
  • Add support for more agencies.

Coming Sooner

Yes, 1Transit is exclusive for WP7 but we have been working on a version for our fellow smartphone users on Android and iOS. Stay tuned for that.


Improve Performance on Your Windows Phone 7 Apps. Totally.

Let’s get straight to it.

It’s all about the threads.

There are two main threads on WP7: UI thread, composition thread.

The UI thread handles user input, XAML parsing, drawing visuals and callbacks. A lot of work. So, don’t use it, it’s already got a lot on its plate.
The composition thread mainly aides the UI thread in handling graphics and animation, improving UI thread’s performance. In many cases the composition thread doesn’t kick in, so that’s no use either.

Enter, background threads.

These babies are amazing and the best way to enhance applications. And oh boy, it’s an enhancement. How does it work? Asynchronously. (Love that word.)

You can have the background threads can do all the dirty work using BackgroundWorker and then when the dirty work is all ready to be presented, use either shared variables or my favourite, Dispatcher.BeingInvoke to update the UI thread.

WebClient no more.

The web is everything and WP7′s way to the web is WebClient. Unfortunately, it runs on the UI thread. You don’t want that, especially if the data you’re working with is large. MSDN recommends using HttpWebRequest. But why build a house from scratch when there’s Nuget? The package you’re looking for is Hammock. It’s what you want if you’re working with RESTful services. And once you have all the data call on to Dispacther.BeginInvoke to send the data off to the UI. Beautiful stuff.

Let there be Opacity.

I’ll be truthful. I love UIElement.Visibility. It’s just great hide stuff and unhide them whenever. Magic style. But, UIElement.Opacity is just as amazing only faster. Black magic style. We all know black magic is better than magic. Here’s why.

When UIElement.Opacity is set to zero, Silverlight will save the bitmap to memory but when UIElement.Visibility changes, Silverlight redraws everything. Very tiresome. But to get this awesome boost you have to set UIElement.CacheMode to Media.BitmapCache, otherwise, it really is no magic and a lot of black-hole of performance hogs.

There’s another aspect to this though, if you’re in/visibling a lot of elements (by a lot I mean a lot), it’s best to measure the performance of both first and see which suits your needs. Also, you may consider selective in/visibling depending, again, on your needs.

Guess that’s all for now. I’ll wonder around to see if I can find other neat ways of enhancing performance for WP7 applications. Till then.


Objective Scrutiny: inTO

Okay, this may not be completely objective because I am really excited that a recent update… actually, overhaul of inTO is up on the Windows Phone 7 Marketplace: http://bit.ly/GetInTO.

What’s this inTO you ask? Well, the idea is to aggregate events from all over Toronto, yes GTA, in a way that it’s easy to get on top of the kazillion things happening in the city. Windows Phone style.

I’ll allow this video to demonstrate:

So, what’s the scrutiny? Well, you really should have seen Version 1.0. Hey, I was just learning Silverlight… But with the help of the team at Fersh, we cleaned up my act and the app. Redesigned the UI a bit, made it more consistent, got rid of a bunch of bugs that tend to creep in when you’re up at 5 am coding your brains out.

The good in it:

  • “in and out” of the application in no time,
  • huge amount of data at your service, searchable too,
  • the data is locally saved, so your data usage is not so huge,
  • easy sharing via email, sms and of course Facebook,
  • a completely feature-complete trial* version.

And not-so-good (hey, I said it won’t be that objective):

  • lengthy loading time; don’t blame me, it’s not my fault Toronto is a happening city,
  • no categorization of the events; I am working on that next,
  • searching isn’t the most accurate; not really noticeable but I know because I wrote it.

Well, I hope, all in all, the experience won’t be too obvious… in keeping with the Windows Phone 7 spirit. Again, the trial* version is feature complete, so give it a shot for sure: http://bit.ly/GetInTO!

*trial: a free version of a Windows Phone application, available for most applications.


Serialization and Isolated Storage in WP7

Reading XML in and out from the provided Isolated Storage is important and quite simple, as the following code snippets illustrate. I have the methods constrained to a generic so that I can use this across all the WP7 applications that I am writing.

To write, the Isolated Storage allocated is called on by IsolatedStorageFile.GetUserStoreForApplication() where objects, XMLized by XmlSerializer serializer are written by the XmlWriter writer. The code is pretty telling, I think, so I’ll spare you the explanation.

public static void Write<T>(T obj, string fileName)
{
    XmlWriterSettings writerSettings =
            new XmlWriterSettings
            {
                Indent = true,
                IndentChars = "\t"
            };

    try
    {
        var store = IsolatedStorageFile.GetUserStoreForApplication();
        IsolatedStorageFileStream stream = store.OpenFile(fileName, FileMode.Create);

        XmlSerializer serializer = new XmlSerializer(typeof(T));

        using (XmlWriter xmlWriter = XmlWriter.Create(stream, writerSettings))
        {
            serializer.Serialize(xmlWriter, obj);
        }

        stream.Close();
    }
    catch (Exception emAll)
    {
        throw emAll;
    }
}

To read XMLized objects from storage, the following function is sufficient and pretty self explanatory. Again, the function is constrained to generic objects so that you can go crazy on what types you want to use it with.

public static T Read<T>(string fileName)
 {
     try
     {
         var store = IsolatedStorageFile.GetUserStoreForApplication();
         IsolatedStorageFileStream stream = store.OpenFile(fileName, FileMode.Open);

         XmlSerializer serializer = new XmlSerializer(typeof(T));
         return (T)serializer.Deserialize(stream);
    }
    catch (Exception emAll)
    {
        throw emAll;
    }
} 

Of course, you will have to modify Exception handling to suit your needs, these are only generalized samples. Also, the code can be improved, so write back with improvements that you might have come up with.


Windows Phone 7 Obsession

I’ve been working on a several Windows Phone 7 (WP7) applications. The development tools are a delight and amazing to use. The tools are available here. And when development and testing is so easy with Visual Studio 2010 and Windows Phone Emulator, you can tell why I am obsessed with it.

Among the applications I am working on is a game called Sudoku3D. The team is great fun to work with and I’ve had a lot of learning opportunities and adventures there. We are mostly using XNA Game Studio 4 there, it’s an amazing framework, together with the power of C# 3.0 and Kit Kat (I like Kit Kat, quite a bit), it’s one hell of a ride!

Here’s a short video of the game running on a WP7 device:

In the coming weeks, I’ll post code snippets and thoughts on developing for Windows Phone 7.


Follow

Get every new post delivered to your Inbox.

Join 256 other followers