diff options
Diffstat (limited to 'Juick/Classes')
-rw-r--r-- | Juick/Classes/TileHelper.cs | 130 |
1 files changed, 52 insertions, 78 deletions
diff --git a/Juick/Classes/TileHelper.cs b/Juick/Classes/TileHelper.cs index 223340b..aa26690 100644 --- a/Juick/Classes/TileHelper.cs +++ b/Juick/Classes/TileHelper.cs @@ -1,78 +1,52 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Phone.Shell; - -namespace Juick.Classes -{ - static class TileHelper - { - public static void UpdateFlipTile( - string title, - string backTitle, - string backContent, - string wideBackContent, - int? count, - string smallBackgroundImageStringUri, - string backgroundImageStringUri, - string backBackgroundImageStringUri, - string wideBackgroundImageStringUri, - string wideBackBackgroundImageStringUri) - { - if (!CanUseLiveTiles) - { - return; - } - var smallBackgroundImage = CreateRelativeUri(smallBackgroundImageStringUri); - var backgroundImage = CreateRelativeUri(backgroundImageStringUri); - var backBackgroundImage = CreateRelativeUri(backBackgroundImageStringUri); - var wideBackgroundImage = CreateRelativeUri(wideBackgroundImageStringUri); - var wideBackBackgroundImage = CreateRelativeUri(wideBackBackgroundImageStringUri); - - Type flipTileDataType = Type.GetType("Microsoft.Phone.Shell.FlipTileData, Microsoft.Phone"); - - // Get the ShellTile type so we can call the new version of "Update" that takes the new Tile templates. - Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone"); - - // Loop through any existing Tiles that are pinned to Start. - foreach (var tileToUpdate in ShellTile.ActiveTiles) - { - var UpdateTileData = flipTileDataType.GetConstructor(new Type[] { }).Invoke(null); - - // Set the properties. - SetProperty(UpdateTileData, "Title", title); - SetProperty(UpdateTileData, "Count", count); - SetProperty(UpdateTileData, "BackTitle", backTitle); - SetProperty(UpdateTileData, "BackContent", backContent); - SetProperty(UpdateTileData, "SmallBackgroundImage", smallBackgroundImage); - SetProperty(UpdateTileData, "BackgroundImage", backgroundImage); - SetProperty(UpdateTileData, "BackBackgroundImage", backBackgroundImage); - SetProperty(UpdateTileData, "WideBackgroundImage", wideBackgroundImage); - SetProperty(UpdateTileData, "WideBackBackgroundImage", wideBackBackgroundImage); - SetProperty(UpdateTileData, "WideBackContent", wideBackContent); - - // Invoke the new version of ShellTile.Update. - shellTileType.GetMethod("Update").Invoke(tileToUpdate, new Object[] { UpdateTileData }); - } - } - - static Uri CreateRelativeUri(string uriString) - { - return !string.IsNullOrEmpty(uriString) ? new Uri(uriString, UriKind.Relative) : null; - } - - static void SetProperty(object instance, string name, object value) - { - var setMethod = instance.GetType().GetProperty(name).GetSetMethod(); - setMethod.Invoke(instance, new object[] { value }); - } - - static readonly Version targetedVersion78 = new Version(7, 10, 8858); - - static bool CanUseLiveTiles - { - get { return Environment.OSVersion.Version >= targetedVersion78; } - } - } -} +using System;
+using Microsoft.Phone.Shell;
+
+namespace Juick.Classes
+{
+ static class TileHelper
+ {
+ public static void UpdateFlipTile(
+ string title,
+ string backTitle,
+ string backContent,
+ string wideBackContent,
+ int? count,
+ string smallBackgroundImageStringUri,
+ string backgroundImageStringUri,
+ string backBackgroundImageStringUri,
+ string wideBackgroundImageStringUri,
+ string wideBackBackgroundImageStringUri)
+ {
+ var smallBackgroundImage = CreateRelativeUri(smallBackgroundImageStringUri);
+ var backgroundImage = CreateRelativeUri(backgroundImageStringUri);
+ var backBackgroundImage = CreateRelativeUri(backBackgroundImageStringUri);
+ var wideBackgroundImage = CreateRelativeUri(wideBackgroundImageStringUri);
+ var wideBackBackgroundImage = CreateRelativeUri(wideBackBackgroundImageStringUri);
+
+ // Loop through any existing Tiles that are pinned to Start.
+ foreach (var tileToUpdate in ShellTile.ActiveTiles)
+ {
+ var updateTileData = new FlipTileData
+ {
+ Title = title,
+ Count = count,
+ BackTitle = backTitle,
+ BackContent = backContent,
+ SmallBackgroundImage = smallBackgroundImage,
+ BackgroundImage = backgroundImage,
+ BackBackgroundImage = backBackgroundImage,
+ WideBackgroundImage = wideBackgroundImage,
+ WideBackBackgroundImage = wideBackBackgroundImage,
+ WideBackContent = wideBackContent
+ };
+
+ tileToUpdate.Update(updateTileData);
+ }
+ }
+
+ static Uri CreateRelativeUri(string uriString)
+ {
+ return !string.IsNullOrEmpty(uriString) ? new Uri(uriString, UriKind.Relative) : null;
+ }
+ }
+}
|