Example #1
0
        public void SaveTile(bool failed, UserBalance balance, string backcontent, string path)
        {
            try
            {
                var color = (bool)IsolatedStorageSettings.ApplicationSettings["tileAccentColor"]
                    ? (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"]
                    : new SolidColorBrush(new Color { A = 255, R = 150, G = 8, B = 8 });
                var tile = GetElement();
                tile.Measure(new Size(336, 336));
                tile.Arrange(new Rect(0, 0, 336, 336));
                var bmp = new WriteableBitmap(336, 336);
                bmp.Render(tile, null);
                bmp.Invalidate();

                using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isf.DirectoryExists("/CustomLiveTiles"))
                    {
                        isf.CreateDirectory("/CustomLiveTiles");
                    }

                    using (var stream = isf.OpenFile(path, FileMode.OpenOrCreate))
                    {
                        bmp.SaveJpeg(stream, 336, 366, 0, 100);
                    }
                }
            }
            catch (Exception)
            {
                //sleep for 0.5 seconds in order to try to resolve the isolatedstorage issues
                Thread.Sleep(500);
                SaveTile(failed, balance, backcontent, path);
            }
        }
Example #2
0
 public static void SaveTile(bool failed, UserBalance balance, string backcontent)
 {
     var i = 0;
     while (i < 5)
     {
         try
         {
             var color = (bool) IsolatedStorageSettings.ApplicationSettings["tileAccentColor"]
                 ? (SolidColorBrush)Application.Current.Resources["TransparentBrush"]
                 : new SolidColorBrush(new Color {A = 255, R = 150, G = 8, B = 8});
             BackTile customBackTile;
             if (failed)
             {
                 customBackTile = new BackTile(color, backcontent, string.Empty, string.Empty, string.Empty,
                     string.Empty);
             }
             else if (balance.Data != null)
             {
                 customBackTile = new BackTile(color, balance.Credit, balance.Data, balance.Sms,
                     balance.VikingSms, balance.VikingMinutes);
             }
             else
             {
                 customBackTile = new BackTile(color, balance.Credit, "0 MB", "0 SMS", balance.VikingMinutes,
                     string.Empty);
             }
             if (!Helper.SaveElement(customBackTile, Tile.Back))
             {
                 i++;
                 continue;
             }
         }
         catch (Exception)
         {
             i++;
             if (i == 5)
             {
                 return;
             }
         }
         i = 5;
     }
 }
Example #3
0
 public static void SaveTile(bool failed, UserBalance balance)
 {
     var i = 0;
     while (i < 5)
     {
         try
         {
             var color = (bool)IsolatedStorageSettings.ApplicationSettings["tileAccentColor"]
                 ? (SolidColorBrush)Application.Current.Resources["TransparentBrush"]
                 : new SolidColorBrush(new Color { A = 255, R = 150, G = 8, B = 8 });
             OldSmallTile customSmallTile;
             if (failed)
             {
                 customSmallTile = new OldSmallTile(color, "?");
             }
             else if (balance.Data != null)
             {
                 customSmallTile = new OldSmallTile(color, string.IsNullOrWhiteSpace(balance.Remaining.ToString()) ? "?" : balance.Remaining.ToString());
             }
             else
             {
                 customSmallTile = new OldSmallTile(color, "0");
             }
             if (!Helper.SaveElement(customSmallTile, Tile.Small))
             {
                 i++;
                 continue;
             }
         }
         catch (Exception)
         {
             i++;
             if (i == 5)
             {
                 return;
             }
             continue;
         }
         i = 5;
     }
 }
Example #4
0
        public void SaveTile(bool failed, UserBalance balance, string backcontent, string path)
        {
            try
            {
                var color = (bool)IsolatedStorageSettings.ApplicationSettings["tileAccentColor"]
                    ? (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"]
                    : new SolidColorBrush(new Color {
                    A = 255, R = 150, G = 8, B = 8
                });
                var tile = GetElement();
                tile.Measure(new Size(336, 336));
                tile.Arrange(new Rect(0, 0, 336, 336));
                var bmp = new WriteableBitmap(336, 336);
                bmp.Render(tile, null);
                bmp.Invalidate();

                using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isf.DirectoryExists("/CustomLiveTiles"))
                    {
                        isf.CreateDirectory("/CustomLiveTiles");
                    }

                    using (var stream = isf.OpenFile(path, FileMode.OpenOrCreate))
                    {
                        bmp.SaveJpeg(stream, 336, 366, 0, 100);
                    }
                }
            }
            catch (Exception)
            {
                //sleep for 0.5 seconds in order to try to resolve the isolatedstorage issues
                Thread.Sleep(500);
                SaveTile(failed, balance, backcontent, path);
            }
        }