Bye Nokia... Hello Microsoft!

The deal to transfer substantially all of the Nokia Devices & Services business to Microsoft has now officially been closed.

With it, I proudly become a Microsoft employee! :)

I will always cherish the moment I decided in moving to the UK to work for Nokia (even if that stopped any chance of receiving the Microsoft MVP award, but that’s another story!).

Nokia made me feel that I could actually make a difference with my work, and I truly appreciate the company for the opportunity!

I’ve been working with Microsoft technologies for more time than I can remember, both as a user and also as an IT professional, and I consider getting the “blue badge” as a giant career step for me!

In the present moment this doesn’t bring any significant changes: I’ll carry on working in the MixRadio apps here in Bristol, as I did until today!

Thank you Nokia, it’s been really fun… Hello Microsoft! :)

Cimbalino Windows Phone Toolkit Updated to v3.2.3

Version 3.2.3 of Cimbalino Windows Phone Toolkit is now available!

As previously indicated, this will probably be the last version still supporting Windows Phone 7…

Here’s the change log starting from version 3.2.0 to the current 3.2.3:

  • v3.2.1
    • New WebRequestExtensions
    • Ensured that MarketplaceInformationService doesn’t cache the results
  • v3.2.2
    • New EventHandlerExtensions
    • Improved the MultiBindingBehavior by adding the missing Mode property
    • Improved the ShellTileServiceTile to enable tiles update with XML data
    • Fixed a couple of issues on MarketplaceInformationService related to “beta apps”
  • v3.2.3
    • New SaveRingtoneService
    • New ScreenCaptureBehavior
    • New FrameworkElementExtensions
    • DeviceInfo, Location, and UserInfo components can now be used inside Background Agents
    • Improved ShellToastService to add the custom sound support

There are other improvements and bug fixes not stated here, but also quite important too! :)

WrapPanel is great, so please, stop using it!

The WrapPanel control (part of the Windows Phone Toolkit) is a really useful control container.

Having said that, you should definitely avoid using it in your apps if you are planing to use in ListBox.ItemsPanel for large lists items presented with fixed size!!

To demonstrate my point, let’s say we have a list of 10 items:

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

Now say we want to list 3 items per row and them wrap to the next row, we can use a WrapPanel container control, like so:

<ListBox x:Name="ItemsListBox"
ItemTemplate="{StaticResource ItemDataTemplate}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

The resulting items layout will look something like the following picture:

WrapPanel layout

This will work fine with 10 items, but what about 100? Or 1.000? Or even 10.000?

Using a WrapPanel with a large number of items will cause the control loading time and memory usage to increase, and if you make it large enough, you’ll probably start seeing your app crash with “out of memory” errors…

Now lets say we first group the items in groups of 3, making the source list look like this:

{ {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {9} }

All we now need is another ItemsControl inside our main ListBox to iterate the each group, something like this:

<ListBox x:Name="ItemsListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<ItemsControl ItemTemplate="{StaticResource ItemDataTemplate}" ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

Here’s the resulting layout schematic:

Smart Wrapping layout

Major advantages with this approach is the obvious performance improvement and memory consumption reduction. Why? Because we maintained the VirtualizingStackPanel in our main ListBox.ItemsPanel!

To prove my point, I’ve created a small demonstration app showing the result of using these two approaches with a list of 400 items.

Download the code, deploy it on a phone or emulator, then run each approach separately and exit the app after each run in order to check the peak memory usage.

You’ll notice a huge difference in loading times, but I can tell you that memory wise, it’s the difference between using 120MB or just 20MB! :)

Poll: What are your plans for #wp7dev

As I am about to start adding Windows Phone “Blue” support to Cimbalino Windows Phone Toolkit, I’m planning to stopping the WP7 support on the 3.x!

The upcoming 4.x would have WP8 and WP Blue support, allowing for a more future prune implementation and dropping the NuGet packages from 9 to just 2 (the Background package as it stands today and a main one with all the rest).

To actually understand the position of the Windows Phone developers about WP7 development, I started a poll that I now invite you to answer! :)

Want to meet the Cimbalino Windows Phone Toolkit?

The next W&W WAG (Wales and West Windows Application Group) meeting will be help tomorrow, February 26th, at Nokia Bristol office, and will feature me talking about the Cimbalino Windows Phone Toolkit, and the Mike Hole, talking about Bluetooth and NFC based communication.

The meeting will start at 18h30, you can find more details and register here!

Hope to see you there! :)

Disabling screenshot functionality in a Windows Phone app

Update: Kudos to Murat and Rudy Huyn for pointing me out on a missing return; that would cause the NotSupportedException to be raised all the time… I’ve fixed the code by inverting the if condition.

Update 2: Just noticed that GDR2 is also supported, as the code below will also work in devices with it! :)

Windows Phone 8 made it possible to take a screenshot of your screen at any time, just by pressing the Windows and Power button at the same time.

Sure, this is a really cool feature and can be quite handy from time to time, but it can become a security concern for some specific scenarios, not to mention a way to copy someone else’s graphical designs!

Since Windows Phone 8 update 3 (GDR2) there is now a hidden feature that allows you to disable the Screenshot functionality on a page by page basis: the PhoneApplicationPage.IsScreenCaptureEnabled!

This is a hidden property that requires Reflection in order to access and modify it’s state. The following extension methods will help you with that:

public static class PhoneApplicationPageExtensionMethods
{
public static bool CanSetScreenCaptureEnabled(this PhoneApplicationPage page)
{
return Environment.OSVersion.Version >= new Version(8, 0, 10322);
}
public static void SetScreenCaptureEnabled(this PhoneApplicationPage page, bool enabled)
{
var propertyInfo = typeof(PhoneApplicationPage).GetProperty("IsScreenCaptureEnabled");
if (propertyInfo == null)
{
throw new NotSupportedException("Not supported in this Windows Phone version!");
}
propertyInfo.SetValue(page, enabled);
}
public static bool GetScreenCaptureEnabled(this PhoneApplicationPage page)
{
var propertyInfo = typeof(PhoneApplicationPage).GetProperty("IsScreenCaptureEnabled");
if (propertyInfo == null)
{
throw new NotSupportedException("Not supported in this Windows Phone version!");
}
return (bool)propertyInfo.GetValue(page);
}
}

The first step is to call CanSetScreenCaptureEnabled() from inside your PhoneApplicationPage to check if the Windows Phone version is at least Windows Phone 8 update 3 (version 8.0.10322) as that is the minimum required version for this to work!

If it is, we can then use the GetScreenCaptureEnabled() and SetScreenCaptureEnabled() extension methods to change the property value!

Here is a sample usage code to disable screenshot functionality:

public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
if (this.CanSetScreenCaptureEnabled())
{
this.SetScreenCaptureEnabled(false);
}
}
}

If you do try to take a screenshot after that code, this is what will happen:

Application screenshot functionality disabled

The same result will happen from the application switcher screen:

Task switcher screenshot functionality disabled

Nowadays, privacy has become the #1 concern in everything we do, and I’m sure this is a really useful information for a bunch of apps out there (looking at you 6snap and all other Snapchat apps ;) )

The Windows Phone apps on my phone!

So you got a brand new Windows Phone device for Christmas and still don’t know what to install on it?

Then look no further: here is the list of the best apps I have installed on my own phone! :)

Social

  • Twitter - The fully featured Twitter app with multiple account support and push notifications that actually do work!
  • Facebook Beta - There is also a non-beta Facebook official app, but I prefer the beta one as it gives me the latest features sooner! ;)
  • 4th & Mayor - I know that there is an official Foursquare app and that it’s a lot better than the first version, but I still prefer 4th & Mayor from Jeff Wilcox as it is quite simpler and uses a more direct approach!
  • WhatsApp - free messaging that works on pretty much any phone? Yes, thank you very much! :)
  • Skype - The official Skype app, really good when it actually works… this is the one app I really need and sometimes fails me miserably :\
  • 6tag - developed by Rudy Huyn, probably the best Instagram app for Windows Phone. There is an official Instagram BETA app, but it’s still lacking some features…
  • Disqus - It’s probably the most used network for commenting on forums and blogs everywhere!
  • LinkedIn - LinkedIn official app, to keep in eye on your professional connections.
  • Viber - Another VOIP app, quite known out there

Tools + Productivity

  • Authenticator - In a time where security and privacy are lacking more and more, using two-factor sign-in whenever possible does help a bit (Microsoft, Google, and other websites use this approach)
  • Google - not that different than accessing www.google.com with the browser, but nevertheless it’s the only app that Google has on Windows Phone…
  • Adobe Reader - Official Adobe Reader app to open PDF files on the phone. There is also a PDF Reader from Microsoft as a really good alternative.
  • BoxFiles for Dropbox - There are quite a few Dropbox apps right now for Windows Phone (none is official) and I personally like this one.
  • SkyDrive - full featured official SkyDrive app from Microsoft.
  • GDrive - Using Google Drive? Then this is what you need! It’s not a fully featured client, but at least it is better than nothing!
  • TeamViewer - Access your machine remotely using TeamViewer.

News + Weather

  • Nextgen Reader - this is the #1 app in my phone!!! I just couldn’t go by without reading my RSS feeds, and given it uses Feedly as source, all my feeds are synchronized; just perfect!!
  • Amazing Weather HD - A really good weather app with nice look and quite a few features. A free alternative is Bing Weather, also quite nice!

Lifestyle / Shopping

  • Amazon Mobile - Search Amazon, purchase stuff, check your order status…
  • eBay - The app is quite simple and could use a better look, but it works well and does a proper job alerting when auctions are about to end.

Travel + Navigation

  • Geosense - quite useful to convert from different GPS coordinates types, to get my location, open KML files from Google Earth… and yes, I wrote it and that’s also another reason why it’s here, so sue me! :P
  • TripAdvisor - I always like to read the reviews on hotels and restaurants on TripAdvisor before I actually go to the place.
  • Currency - Currency exchange, provided by XE

Entertainment

  • IMDb - The official IMDb app for Windows Phone, probably the best showcase for a WP app and the best IMDb client you’ll find in any mobile device!
  • Helium Voice Free - Because it’s fun and I like to show kids! :)

Business

  • Office Remote - do you do PowerPoint presentations? Then do yourself a favor and install this in your Windows Phone!

Personal Finance

  • PayPal - I like to keep a close eye on my PayPal transactions!

Photo

  • Pictures Lab - Nice, clean, and fast, picture effects app, developed by René Schulte.
  • Tile Me! - Create a Windows Phone tile picture with this app, and use it everywhere! :D

Music + Video

  • YouTube - a couple a months ago there was an official YouTube app (and it was really good, I might add), but Google pulled the plug on it and so we are stuck with just this miserable plugin and YouTube mobile website…
  • Shazam - You know when you’re in a party, listening to a music that you actually like and don’t know who the artist is? That’s when Shazam comes quite handy!
  • Sax - A simple fun way of playing saxophone without one!

Books + Reference

  • Wikipedia - it’s Wikipedia, and that is all anyone needs for reference…

So go on now, install some apps in your phone and have fun!

And by the way: Happy New Year!!! :)

Creating PNG image files in Windows Phone

Windows Phone image processing and format support has always been lacking a bit, especially when compared with all the GDI+ capabilities one has available in the full .NET Framework.

For instance, you can read JPEG and PNG files, but you can only save to JPEG, as there is no support to save to PNG directly on the platform.

Saving to PNG has been quite easy since the beginning of Windows Phone 7 by using 3rd party libraries, and on this chapter, .NET Image Tools is the most used one!

But personally, using Image Tools always presented two major problems:

  • it requires SharpZipLib (a GPL licensed library) to handle Zlib compression
  • it’s quite slow and uses a lot of memory

The first problem is a definitive “no-no” for usage in closed code commercial apps, as GPL is ”viral license

The second problem is more related to the way Image Tools was developed, not considering usage in mobile devices that have lower specifications as to processor capacity or memory.

The Cimbalino Windows Phone Toolkit way

Cimbalino Windows Phone Toolkit version 3.2.0 presents a new WriteableBitmapExtensions containing a SavePng() method to create PNG files from WriteableBitmap instances!

Internally it uses DotNetZip (Ms-Pl license) to handle the required ZLib compression and it’s quite optimized for speed and low memory consumption.

To illustrate the speed improvement, Ertay Shashko was kind enough to test it with his Tile Me app, and here are the results of his personal usage:

I guess the numbers speak for themselves! :)