What does Commerce Expansion Adjustment mean to me?

Windows Phone developers have received an email about the upcoming changes to make mobile operator billing available in more countries. In particular markets from March 2014 this means that there will be an additional deduction from your revenue for these specific markets when mobile billing is used (not for continued credit/debit card purchases). The markets in question are:-

Argentina, Chile, Colombia, Cost Rica, Malaysia, Mexico, Peru, South Africa.

For these purchases Microsoft will take an additional 13.9% of the receipt to cover processing costs leaving you with 56.1% of the "list price" rather than the usual 70%. A suggestion on Microsoft’s "Define pricing and market selection" page is to adjust the price for these markets, but then you’ll be penalising the end users and the increased price might deter customers. Hopefully the potential increase in sales from these markets will show that 56.1% of something is better than 70% of nothing and overall developers will see a benefit from reaching these markets.

Nokia DT-601 Review

DT-601

As part of the New Year tidy up I decided to add a wireless charging pad to my desk so that I can easily top up devices without too many trailing wires. I saw the new second generation DT-601 and thought it looked perfect – smaller than the original pad and with a USB interface which can go into a powered hub or optionally its own a/c adaptor. I picked the red one expecting bright post office red from the pictures but on the packaging it is described as neon red. Personally I would describe it as “Radioactive Salmon”, it has certainly brightened up my desk!

Charger and Phone

I plugged it in and tried a couple of devices on it and it was straight-forward to use. I have a 1020 with charging shell and this one was odd because you have to put the phone onto the round pad so the camera bezel sits on the edge of the pad so it’s not quite flat. This feels wrong but works fine – I guess the 1020 was always going to be a special case because of its unusually shaped derriere. If you have multiple devices you have to get used to where the charging point is as they seem to vary a bit. Keeping moving the phone around until you see that it is charging. I don’t have anything which supports QI charging which isn’t a Nokia phone but it should support any QI compatible device.

Tasks 1.81– Now with added programmability

In the latest update to the Windows Phone Tasks app I’ve added in some API features for other apps to hook into. This is facilitated by Windows Phone 8’s support for custom Uri schemes – the app supports the tasks: scheme and allows you to do a couple of useful things with it. You can use it both to launch the app and also to pre-populate the New Task dialog. This allows the user to save a new Task as they can a Calendar event or Contact from your app. Full details on the Uri scheme are maintained here:-

http://inthehand.uservoice.com/knowledgebase/articles/350181-tasks-uri-scheme

In addition to this and following the example of Nokia, I’ve created an API library for Windows Phone which is available now on NuGet. This simplifies the creation of a new Task by providing a SaveTodoTask which has a model which should be instantly familiar to any Windows Phone developer. I chose to name this SaveTodoTask rather than SaveTaskTask as that sounded clunky and task items are interchangeably known as to-dos as well.

This functionality follows swiftly on the heels of the 1.80 release which added a New Task optional start tile as a short-cut to this functionality. 1.81 also includes numerous bug fixes and sync improvements along with support for Lock Screen notifications.

If you have feedback for the Tasks app remember you can submit it to our Uservoice site which will help us plan future updates.

Linking to your other apps

Using the Windows Phone SDK the only method to return a list of your other published apps (e.g. for your About page) is to use the MarketplaceSearchTask and specify your company name in the search criteria. The problem with this is that it doesn’t return the actual publisher list but does a keyword search so you may find that a few other apps appear if other devs have used your company name in their descriptions or keywords.

The solution is to use a Uri and the LaunchUriAsync method in Windows Phone 8. The zune (yes it’s a throwback from the olden days) Uri scheme includes the ability to specify a publisher name e.g.

Windows.System.Launcher.LaunchUriAsync(new Uri("zune:search?publisher=APPA Mundi Ltd"));

In case you don’t want to hard-code your publisher name (to create a shared component for example) you can add this from the metadata of your app using Charming ApplicationModel e.g.

Windows.System.Launcher.LaunchUriAsync(new Uri("zune:search?publisher=" + InTheHand.ApplicationModel.Package.Current.PublisherDisplayName));

The equivalent functionality in Windows 8 is implemented through the ms-windows-store Uri scheme:-

ms-windows-store:Publisher?name=APPA%20Mundi%20Ltd

or again using package information:-

Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:Publisher?name=" + Windows.ApplicationModel.Package.Current.PublisherDisplayName));

Translating Windows Phone Features

There are a number of steps when translating a Windows Phone app. Hopefully you are using the Microsoft Multilingual App Toolkit (http://msdn.microsoft.com/en-us/windows/apps/bg127574) which supports the standard XLIFF format. Often you will start with your own language string resources and then add other languages, possibly first with machine translation and then passing them to a native speaker to correct. Since Windows Phone (and Windows 8) adopt quite an informal conversational style it is likely that colloquialisms will enter your text which won’t necessarily translate literally. Also there will be times when you want to use a phrase for a system feature or action where there are existing strings which appear throughout the system. You’ll want to match these to avoid confusing the user. Take for example “Pin to Start” – if translated literally it would imply that you must use a pin to start some action (e.g. French “broche pour commencer”), when actually you want to place a link on your start screen, the OS uses the following string “épingler sur l’écran d’accueil”. The good news is all of these are available publicly for all of the supported Windows Phone languages. The Microsoft Languages site (http://www.microsoft.com/language) has a search tool which allows you to look up phrases for particular products and in specific languages. For example a deep link to the “pin to Start” string would be:-

http://www.microsoft.com/Language/en-US/Search.aspx?sString=pin+to+start&langID=fr-fr

Don’t be surprised if the search returns multiple identical matches, I’ve noticed this happens frequently. An example of where I used this was in my NFC Share Task. In order to be instantly familiar I wanted exactly the same text and appearance as activating the feature from built in apps, and I wouldn’t be able to call on native speakers from every possible language for Windows Phone 8. You get the advantage here of Microsoft’s own user testing and provide consistent wording to features the user will already be familiar with.

Launching System Features From Windows Store Apps

In Windows Phone we have a number of Launchers and Choosers for interacting with system features. For the most part the approach used in Windows Store is to use special URI schemes to achieve the same end result and launch platform features. I’ve collated together a list below of some known ones. Some like maps are documented in detail, others not. All can be launched with Windows.System.Launcher.LaunchUriAsync() (which also exists in Windows Phone 8 for launching other apps via a uri).

 

ms-windows-store: – Windows Store “Hub”

ms-windows-store:PDP?PFN={your package family name} – App detail page. Get your PFN from Windows.ApplicationModel.Package.Current.Id.FamilyName

ms-windows-store:REVIEW?PFN={your package family name} – Write a review page

ms-windows-store:Search?query={query term} -Remember to URI escape your query term text

 

xboxgames: – launches the games hub

 

The following launch Microsoft/Bing apps (if installed)

bingfinance: – Finance

bingfoodanddrink: – Food & Drink

binghealthnfitness: – Health & Fitness

bingmaps: – Maps. Full details here:- http://msdn.microsoft.com/en-us/library/windows/apps/jj635237.aspx

bingnews: – News

bingsports: – Sports

bingtravel: – Travel

bingweather: – Weather

microsoftmusic: – Music

microsoftvideo: – Video

ms-mail: – Mail

windowsreadinglist: – Reading List

wlcalendar: – Calendar

wlpeople: – People

xboxsmartglass: – Smart Glass

 

Jumping back to the first set which cover the Store. In order to make these simpler to call and help with porting existing code from Windows Phone I’ve added a new library to the Charming suite. This is the first library to go the other way – provide a phone style API for Windows Store.

https://www.nuget.org/packages/InTheHand.Phone.Tasks.RT/

This library provides the MarketplaceHubTask, MarketplaceDetailTask and MarketplaceSearchTask which we know and love from Windows Phone and launches the equivalent functionality on Windows. The key differences beside the namespaces are that the content identifier for the MarketplaceDetailTask is a Package Family Name and there is no ContentType property to distinguish between apps, games and music. For the purposes of Windows Store all apps and games are treated the same and there is no music in the Windows Store. Code and documentation will be updated on the CodePlex site shortly though if you’ve used these features under Windows Phone you already know how to use it!

Detect When Running on Windows Simulator

The Windows Simulator is a deployment target for Visual Studio which allows you to run your Windows Store apps in a simulated device. This allows you to test touch interaction and different screen sizes and orientations on your development machine. The way this works is that it creates a Remote Desktop session into your PC. This is why when you run it you’ll see your own start screen and user account. The problem with this is that some APIs fail on the simulator such as setting up a Push Notification channel. We need a way to detect if we are running in the simulator so that we can react accordingly. If you try to poke around for hardware information you’ll find it returns the same as running directly on your machine. This makes sense when you know it’s a Remote Desktop session. Luckily there is an API specifically designed for this scenario:-


bool isRemote = Windows.System.RemoteDesktop.InteractiveSession.IsRemote;

This will return true in a Simulator session. We can use this to avoid calling any code which will fail on the simulator and can easily switch between local machine and simulator deployment to test various aspects of the app without touching the code or using different project configurations and conditional compilation.

Charming Storage for Windows Phone

A tweet by @martinsuchan earlier reminded me of an issue I faced porting some code from Windows Phone to Windows Store. Moving from the Isolated Storage API to the new Windows.Storage namespace there was nothing built-in to determine if a file/folder exists prior to Windows 8.1. This meant the only supported option was to try and access the file and catch an exception. This is in itself horrible but even worse if you’re trying to use the same code on Windows Phone and Windows 8, because these exceptions have an even worse impact on the phone. My solution was to create an extension method for StorageFolder which would use the Isolated Storage API under the hood to call FileExists() or DirectoryExists() on Windows Phone and only the try/catch method when compiled on Windows 8. I had this code sitting around for a while and following 8.1 I reworked the code to add a TryGetItemAsync extension method for Windows Phone and I didn’t need the Windows 8 version any more. This functionality is packaged up in “Charming Storage” which is available on NuGet:-

https://www.nuget.org/packages/InTheHand.Storage/

Add the package, insert:

using InTheHand.Storage;

At the top of your code file and then you can use the extension method in exactly the same way as the Windows 8.1 method. Checking for file existence is as simple as:-

if(await Windows.Storage.ApplicationData.Current.LocalFolder.TryGetItemAsync("cheese") != null)

The Charming Storage library also adds a local settings API which is code compatible with Windows 8 and stores settings in the package’s local storage. This offers a replacement to IsolatedStorageSettings and gives you the same code as Windows Store (just the namespace is different).

Windows Phone: App Accent Color

The last post showed how to get the current app’s tile colour in Windows 8. What about Windows Phone? There isn’t the concept of a tile colour – you provide a full image for your app icon and tiles and this can be whatever colour you choose or transparent in which case the user’s accent colour is used. In terms of a theme colour for phone apps the application icon is probably a better place to start. The vast majority of apps use a solid colour background, this is seldom the case with games but since this post focusses on apps let’s not worry about that.

The Charming ApplicationModel library contains a more complete implementation of the Windows.ApplicationModel.Package class for reading app metadata at runtime – on Windows Phone most of the properties are not implemented. This has been updated with a number of new Windows 8.1 properties such as Logo which returns a Uri to the application logo file within your package. We can then use a WriteableBitmap to read an individual pixel from the image and create a solid colour brush to be used inside the app. This allows you to change the appearance of your app without any code or XAML changes, and is also useful for custom controls where the code might reside separately from the application itself. Below is the equivalent code to the Win8 version posted before. This creates a resource “AppAccentBrush” which can be used within the app UI.

System.Windows.Resources.StreamResourceInfo sri = Application.GetResourceStream(InTheHand.ApplicationModel.Package.Current.Logo);

System.Windows.Media.Imaging.BitmapImage img = new System.Windows.Media.Imaging.BitmapImage();
img.SetSource(sri.Stream);

System.Windows.Media.Imaging.WriteableBitmap wb = new System.Windows.Media.Imaging.WriteableBitmap(img);
int rgb = wb.Pixels[0];
           
byte r, g, b;
r = (byte)((rgb & 0xFF0000) >> 16);
g = (byte)((rgb & 0xFF00) >> 8);
b = (byte)(rgb & 0xFF);
System.Windows.Media.Color c = System.Windows.Media.Color.FromArgb(0xff, r, g, b);
Application.Current.Resources.Add(“AppAccentBrush”, new System.Windows.Media.SolidColorBrush(c));

There is currently no check here for transparent backgrounds as we’d probably want to default to a solid colour in this case (perhaps fall back to PhoneAccentBrush). I’m looking at improving this code and integrating it into the charming libraries, to provide customisation to some of the UI such as the settings screens. You can grab the Charming libraries from Codeplex (http://charming.codeplex.com) or NuGet (http://www.nuget.org/packages?q=charming).

Windows Store Apps: Application Tile Colour Within an App

When you define your package manifest for a Windows Store app you can specify the background colour used for your tile. Chances are this is a brand colour which you want to use throughout your app. You could specify it twice – once in the manifest and once in a XAML resource. However imagine the scenario where you are creating a custom control and need to use this colour without actually having access to the executing app code. The solution is quite simple and involves reading the compiled manifest from within your executing app package. The file in question is called AppxManifest.xml. We can use an XmlReader to locate the specific attribute we need. I wouldn’t poke around for too many things in this file as most of this information is accessible through the Windows.ApplicationModel.Package class. The code below (error checking removed for clarity) shows the steps to open the file for reading, locating the required Element and reading the “BackgroundColor” attribute. This string contains an RGB value in HEX notation so we can extract the Red, Green and Blue values and save to a Color. I’ve saved this to the apps Resources dictionary with the name “AppAccentBrush”.

Stream s = await Windows.ApplicationModel.Package.Current.InstalledLocation.OpenStreamForReadAsync("AppxManifest.xml");
System.Xml.XmlReader reader = System.Xml.XmlReader.Create(s);
reader.ReadToDescendant(<"VisualElements", "http://schemas.microsoft.com/appx/2013/manifest");
string attr = reader.GetAttribute("BackgroundColor");
byte r, g, b;
r = byte.Parse(attr.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);
g = byte.Parse(attr.Substring(3, 2), System.Globalization.NumberStyles.HexNumber);
b = byte.Parse(attr.Substring(5, 2), System.Globalization.NumberStyles.HexNumber);
accentColor = Windows.UI.Color.FromArgb(0xff, r, g, b);
this.Resources.Add("AppAccentBrush", new SolidColorBrush(accentColor));

What else might you want to use this for? Well one feature we found annoying was that regardless of your colour scheme the indeterminate progress bar uses a default colour. As it turns out this is defined in the ProgressBarIndeterminateForegroundThemeBrush resource. You can access this Brush and modify its colour to match your tile colour.

if(this.Resources.ContainsKey("ProgressBarIndeterminateForegroundThemeBrush")) 
{
 var brush = this.Resources["ProgressBarIndeterminateForegroundThemeBrush"] as SolidColorBrush;
 brush.Color = accentColor;
}