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! :)

Handle 1080p in Windows Phone like a Pro!

The change log for Windows Phone 8 update 3 (also known as GDR3) has been known for a few weeks and one of the new features is the added

support for bigger, higher-resolution screens

This is obviously only for new devices, with 5” or 6” screens using 1080p resolution, like the amazing Nokia Lumia 1520!

Here’s the complete list of Windows Phone supported resolutions, divided by aspect ratio:

  • 15:9
    • WVGA (480x800, 1.0x scale factor) - this is the only resolution available in WP7
    • WXGA (768x1280, 1.6x scale factor)
  • 16:9
    • 720p (720x1280, 1.5x scale factor)
    • 1080p (1080x1920, 2.25x scale factor) - only supported in the new large screen devices with WP8 update 3

As a Windows Phone developer/designer, you don’t need to know this!

All you need to do is design the interface in XAML for the 480x800 resolution, and it will automatically scale up using a fixed scale factor! How cool is that? :)

Now if you really want to know what is the device scale factor (maybe to create different app resolution-aware layouts), you can read the Application.Current.Host.Content.ScaleFactor (note: this property will return the scale factor * 100).

But there’s a catch: for the new 1080p devices, the scale factor is returned as 1.5x, just as the 720p devices, instead of the correct 2.25x…

To get the real scale factor, you can use the following code snippet:

public int ScaleFactor
{
get
{
object physicalScreenResolutionObject;

if (DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out physicalScreenResolutionObject))
{
var physicalScreenResolution = (Size)physicalScreenResolutionObject;

return (int)(physicalScreenResolution.Width / 4.8);
}

return Application.Current.Host.Content.ScaleFactor;
}
}

In WP8 update 3 you can use DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out physicalScreenResolutionObject) to retrieve the screen Size resolution in pixels, take the Width of it and divide it by 4.8 to know the correct scale factor.

If the call to DeviceExtendedProperties.TryGetValue fails it just means you don’t have a WP8 GDR3 device, and as such the device is not a 1080p device and you can just fallback to use the Application.Current.Host.Content.ScaleFactor approach!

The Cimbalino Windows Phone Toolkit way

Previous versions of Cimbalino Windows Phone Toolkit already had the IScreenInfoService to help handling this, and since version 3.2.0, you can also count on the added 1080p support! :)

Cimbalino Windows Phone Toolkit Updated to v3.2.0

Version 3.2.0 of Cimbalino Windows Phone Toolkit is now available!

This release is mostly a bug/performance fix; here’s the change log:

  • Added the WriteableBitmapExtensions, which provides a high-performance & low memory impact SavePng() method!
  • Improved the IScreenInfoService and ResolutionAwareUriConverter to contemplate 1080p screens
  • The usual improvements and bug fixes

Windows Phone Week

Windows Phone Week

Directly from the official site:

Windows Phone Week is a series of events created for the developer community by Windows Phone Developer MVPs.

The events are in nine countries, encouraging developers from around the world to explore app and gaming development.

Each event has a unique agenda, format and registration process so please check the details at the location nearest you.

Although at this stage only 9 countries are participating, there are plans to expand to other territories, so stay tuned! ;)