Montag, 5. November 2012

Windows Phone 8–Tiles and lock screen notification

The new Windows Phone 8 comes with 3 types of live tiles, represented by the following classes:

  • FlipTileData – this is the regular live tile that we are used to seeing in Windows Phone 7
  • IconicTileData – similar to the FlipTile but follows more closely the Windows Phone design principles and displays an icon instead of an image
  • CycleTileData – can cycle up to 9 images, similar to the Pictures live tile Windows Phone 8 Large Tile

Live tiles now also come in three sizes: small, medium and large. You can control if your primary tile supports the large size in the WMAppManifest.xml file (see screenshot).

Additional it is now possible for apps to display notifications on the lock screen. The information comes from the primary tile and you can enable this feature by editing the WMAppManifest.xml file. When this functionality is enabled, the user can select your app as notification app in the phone settings page. After this your primary tile notifications (the counter) will be shown at the lock screen with the referenced image in DeviceLockImageURI of your WMAppManifest.xml file.

The tile size is selected by the user from the start screen, but you can control which sizes your app supports. For a good user experience you should provide a separate image for each size.

The required images sizes are:

Flip and Cycle

Iconic

Small

159 × 159 px

110 × 110 px

Medium

336 × 336 px

202 × 202 px

Wide

691 × 336 px

N/A

You can create or update a tile using either XML or code. There is no way to know which tile size your customer has pinned to the start screen, so you should include all elements. The initial template is defined in the WMAppManifest.xml, but you can change the tile content at runtime.

Change the primary tile

Sample to change the counter or background text of the primary tile:

 FlipTileData primaryTileData = new FlipTileData();
 primaryTileData.Count = count;
 primaryTileData.BackContent = content;
 ShellTile primaryTile = ShellTile.ActiveTiles.First();
 primaryTile.Update(primaryTileData);

SecondaryTile

The most common way to create or update a tile is to use the FileTileData, IconicTileData or CycleTileData classes. As example here is a FlipTileData class to create a tile with an additional back  side.

       private ShellTileData CreateFlipTileData()
        {
            return new FlipTileData()
            {
                Title = "Flip Tile",
                BackTitle = "This is a flip tile",
                BackContent = "Second line of medium size",
                WideBackContent = "Second line of wide size",
                Count = 10,
                SmallBackgroundImage = new Uri("/Assets/Tiles/FlipTileSmallBackground.png", UriKind.Relative),
                BackgroundImage = new Uri("/Assets/Tiles/FlipTileBackground.png", UriKind.Relative),
                BackBackgroundImage = new Uri("/Assets/Tiles/FlipTileSmallBackBackground.png", UriKind.Relative),
                WideBackgroundImage = new Uri("/Assets/Tiles/FlipTileWideBackground.png", UriKind.Relative),
                WideBackBackgroundImage = new Uri("/Assets/Tiles/FlipTileWideBackBackground.png", UriKind.Relative)
            };
        }
Then you can create a secondary tile by:
            Uri tileUri = new Uri(string.Concat("/MainPage.xaml?", "tile=second"), UriKind.Relative);
            ShellTileData tileData = this.CreateFlipTileData();
            ShellTile.Create(tileUri, tileData, true);
To switch the style of the secondary tile you can use
ShellTile shellTile = ShellTile.ActiveTiles.FirstOrDefault(tile => tile.NavigationUri.ToString().Contains(partOfUri));
to find the tile and the before create the new tile type, delete the old one with shellTile.Delete.

An alternative way to initialize the FlipTemplateData object, is to provide it with a string that is an XML, containing all the data needed for the template. If you have read the content (for example as resource or getting it via push notification), you can create a new FlipTileData with this string as parameter in the contructor.

<?xml version="1.0"?>
<wp:Notification xmlns:wp="WPNotification" Version="2.0">
  <wp:Tile Id="[Tile ID]" Template="FlipTile">
    <wp:SmallBackgroundImage [Action="Clear"]>[small Tile size URI]</wp:SmallBackgroundImage>
    <wp:WideBackgroundImage Action="Clear">[front of wide Tile size URI]</wp:WideBackgroundImage>
    <wp:WideBackBackgroundImage Action="Clear">[back of wide Tile size URI]</wp:WideBackBackgroundImage>
    <wp:WideBackContent Action="Clear">[back of wide Tile size content]</wp:WideBackContent>
    <wp:BackgroundImage Action="Clear">[front of medium Tile size URI]</wp:BackgroundImage>
    <wp:Count Action="Clear">[count]</wp:Count>
    <wp:Title Action="Clear">[title]</wp:Title>
    <wp:BackBackgroundImage Action="Clear">[back of medium Tile size URI]</wp:BackBackgroundImage>
    <wp:BackTitle Action="Clear">[back of Tile title]</wp:BackTitle>
    <wp:BackContent Action="Clear">[back of medium Tile size content]</wp:BackContent>
  </wp:Tile>
Windows Phone 8 Lock Screen Notification</wp:Notification>

Lock screen Notifications

Windows Phone 8 now allows the user to select the applications from which to receive notifications on the lock screen. The information that is displayed on the lock screen actually comes from the app’s primary tile. In order to enable lock screen notification for your app you have to edit the WMAppManifest.xml file and change the Extensions element (which follows the Tokens element) to include the following structure:

   <Extensions>
      <Extension ExtensionName="LockScreen_Notification_IconCount" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />
      <Extension ExtensionName="LockScreen_Notification_TextField" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />
    </Extensions>

If the user choose your app in the Windows phone 8 settings page as lock screen notification app your primary tile updates (for example by a backgound agent) will be pushed to the lock screen.

The icon for the lock screen will be defined at the WMAppManifest.xml file.

Updating Primary tile via Background agent

To update the content of a primary or secondary tile you need a background agent, which also updates the notification displayed on the lock screen. To create a new background agent we are using the “Windows Phone Scheduled Task Agent” project template. Then in the OnInvoke method we will update in the sample snipplet the primary tile of our app.

To connect your application with the new background agent it is only necessary to add a reference in the app project to the “Windows Phone Scheduled Agent” project.

       protected override void OnInvoke(ScheduledTask task)
        {
            //TODO: Add code to perform your task in background
            System.Random randomCount = new System.Random(); 
            int count = randomCount.Next(10, 90); 
            string content = string.Format("{0} posts waiting for you!", count);
            UpdatePrimaryTile(count, content); 
            #if DEBUG 
                ScheduledActionService.LaunchForTest( task.Name, TimeSpan.FromSeconds(30));
            #endif
            NotifyComplete();
        }
To force the background agent during debugging you can use the LaunchForTest method.

Sonntag, 4. November 2012

Windows Phone 8–Fast resume

My favourite change for Windows Phone 8 are the changes for a better performance for starting a app. Except for code optimizations in the execution layer of Windows Phone 8 apps Microsoft also changed the startup and resuming behavior of Windows Phone 8 apps. For me is this one of the mayor changes of Windows Phone 8, because it brings with one declaration (see later) such an big effect for the user experience.

History of starting/resuming apps

First Micosoft introduce with Windows 7.0 the tombstoning – not so many people understands it and implement it correctly. With Windows 7.5 (Mango release) they changed the behaviour, that if you use the start button all applications which could hold in memory have a fast resuming behaviour. With the task switcher (press and hold the back button) the user can switch to the applications which are still in memory. Problem: Only power users has known of this feature and if the user start a app with a click on the start screen or the app list, a new instance of the app will be started. Result: bad user experiience.

The Solution with Windows Phone 8

With Windows Phone 8 Microsoft has changed now the behaviour of a Back-Button click on the last page of an application. This will not longer throw away the instance of your Windows Phone 8 application but put it in the memory stack, too. If the user starts the application from any point and the application is still in memory, it will be started in the resume mode – great stuff!

All you have to do is to declare a new ActivationPolicy in the WMAppManifest.xml of your solution.

    <Tasks>
      <DefaultTask  Name ="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"/>
    </Tasks>

See the behaviour here:

Windows Phone 8–New improved multitasking

Samstag, 3. November 2012

Windows Phone 8– The new controls and launchers, choosers

Here is a quick overview of the new and updated controls and launcher and chooser tasks that comes with de Windows Phone 8.0 SDK. Further details I will post later on.

ViewportControl

  • More “primitive” than ScrollViewer
  • Able to update bounds dynamically
  • Designed specifically for touch-specific scenarios
  • Base-control for LongListSelector
  • Input is off-thread

 

WebBrowser

  • IE10-based
  • Supports HTML5
  • Local storage, CSS3
  • Supports gestures

Pivot, Panorama control

These controls are updated and contains fixes for better performance and a better memory management.

Progressbar

Nobody uses the old progressbar of the Windows Phone SDK 7.x, because the progressbar blocks your UI thread. For the Windows Phone 8.0 these issues now fixed and the progressbar updates works not longer in the UI thread.

New LongListSelector control

The Windows Phone 8 SDK includes a new LongListSelector control that implements a jump-list style of UI that is usually used to display long lists of data. The control supports full UI and data virtualization and is actually recommended even for displaying flat lists.

It is compatible with the ListBox control.

Maps

Bing Maps is deprecated and the new Maps controls use technology supllied by Nokia. The new features are

  • Vector-based for faster rendering
  • Four cartographic map modes
  • Light and dark color modes
  • Display of landmarks and pedestrian features
  • Offline capability with apps wide caching

The new Map control is in the Microsoft.Phone.Maps.Contols namespace, in the Microsoft.Phone.Maps assembly, and in order to use it in XAML you must add the following namespace in your XAML:

xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"

New Location APIs

The Windows Phone 8 SDK comes with new Location APIs exposed through the Geolocator class. Continuous location tracking is now easier to implement, and you can even track the phone’s location in the background, which opens a range of new opportunities. You can even get the current location more efficiently and improve battery life using the new GetGeopositionAsync method.

New Launcher und Choosers

Windows Phone 8 SDK comes with several new Launchers which are exposed through the following classes:

  • SaveAppointmentTask – prompts the user to create a new appoint-ment
  • MapsTask – launches the built-in map app
  • MapsDirectionsTask – launches the built-in map app with directions
  • MapDownloaderTask – launches the map downloader for the built-in map app
  • ShareMediaTask – prompts the us-er to share a media file

I am working these days on samples for the new controls. My results will be posted here.

Freitag, 26. Oktober 2012

Windows Phone 8 is coming

On Monday October 29th the time of waiting for the new Windows 8 Phone is over. The presentation of Windows Phone 8 will be in San Francisco. You can tune in the live webcast here. I hope they will show us what everyone is expecting – a new awesome release of Windows Phone fitting to Windows 8 with the new Windows RT surface tablets.

Montag, 10. September 2012

Nokia Lumia 820–Windows Phone 8

Here the specs for the new Nokia Lumia 820 smartphone running with Windows Phone 8.

Sonntag, 12. August 2012

Using GIT on a QNap server with Windows clients

Because I am using now a long time my Qnap server as home server in meantime for media streaming and as NAS file storage system, I tried now to use it as source control server for my personal projects too. My requirement was to have a source control system also for my IOS projects and Windows Visual Studio projects. So my decision was to use GIT.

Because it was a little bit tricky to install, here are my installation steps:

Installing GIT for Windows

Download and install Git for Windows at
http://msysgit.github.com/

Also you need PuTTY for the ssh connection to remote control the Qnap system.

PuTTY-Connection

# ipkg install git
# ipkg install gitosis

Check the passwd file at the Qnap system if the Gitosis user is created and the
home directory for the user exists. If not, create the user with the Qnap Web interface.

Maybe you have to login the user (no password)
at the web file system interface of Qnap to create the home directory.

 

GITBASH

1.$ cd ~/.ssh // move to dir where keys are normally stored
2.$ ls // list contents of .ssh directory
3.id_rsa id_rsa.pub known_hosts public.ppk
4.// here you can see I have an existing pair of msys keys
5.$ mkdir key_backup // make a directory to move old keys
6.$ cp id_rsa* key_backup // copy keys to key_backup dir
7.$ rm id_rsa* // remove original keys

Generate public and private key pair at the windows client and transfer it to the
Qnap system. Then you can do the git administration from this client.

1.$ ssh-keygen -t rsa -C "youremail@address.com"
2.Generating public/private rsa key pair.
3.Enter file in which to save the key (/c/documents/<user>/ssh/id_rsa):
4.Enter passphrase (empty for no passphrase):
5.Enter same passphrase again:
6.Your identification has been saved in /c/documents/<user>/ssh/id_rsa.
7.Your public key has been saved in /c/documents/<user>/ssh/id_rsa.pub.
8.The key fingerprint is:
9.e8:ae:60:8f:38:c2:98:1d:6d:84:60:8c:9e:dd:47:81 youremail@address.com

copy public Key to your Qnap host:

scp ~/.ssh/id_rsa.pub admin@<host>:/tmp/

 

PuTTY-Connection

Generate ECDSA Key if it not exists in /opt/etc/openssh:

/share/MD0_DATA/.qpkg/Optware/bin/ssh-keygen -t ecdsa -f /opt/etc/openssh/ssh_host_ecdsa_key -N ''

Init Gitosis with the public key of your administration windows client:

sudo -H -u gitosis /opt/bin/gitosis-init < /tmp/id_rsa.pub

the following folders should be genarted in the referenced home directory of the gitosis user (see passwd file)
'/share/HDA_DATA/gitosis/gitsosis'
'/share/HDA_DATA/gitosis/repositories'
-> here gitosis-admin.git
/share/HDA_DATA/gitosis/.ssh/authorized_keys

change access rights:

chmod 755 /share/HDA_DATA/gitosis/repositories/gitosis-admin.git/hooks/post-update

Change standard port of the Qnap SSH over Web interface

change port from 22 to 2201 for SSH. You have to change the remote control SSH session to the new port. The port 22 is now used by Gitosis with Openssh.

Install OpenSSH

# ipkg install openssh openssh-sftp-server

You can configure OpenSSH with the file '/opt/etc/openssh/sshd_config' (note: not ssh_config!).
After you have made your changes, you need to reload the daemon configuration:

# /opt/etc/init.d/S40sshd reload

I changed this value of my sshd_config:

Protocol 2
AllowUsers gitosis <--- make gitosis the only user authorized
PermitRootLogin no
UsePrivilegeSeparation no
PermitUserEnvironment yes <--- load user environment (home directory)

Subsystem sftp /opt/libexec/sftp-server

# /opt/etc/init.d/S40sshd start
or
# /opt/etc/init.d/S40sshd restart

GITBASH


# git clone gitosis@host:gitosis-admin.git

Maybe you have to delete the known_hosts file in ~/.ssh at the windows client

Further informations: http://wiki.qnap.com/wiki/Gitosis

Samstag, 30. Juni 2012

Empty Guid

Some times I need a empty Guid. The first purpose of this blog entry is therefore to find my empty guid quicker .-)

If you want to create a empty Guid with .NET in C# there are two ways:

Guid myGuid = new Guid();

This creates the exact same empty Guid ( 00000000-0000-0000-0000-000000000000 ) as:

Guid myGuid = Guid.Empty;