示例#1
0
        public static void CreateTile(Post post)
        {
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.EnableNotificationQueue(true);
            updater.Clear();

            var tileLarge = TileContentFactory.CreateTileWide310x150PeekImage01();

            tileLarge.Image.Src = "ms-appx:///Assets/WideLogo.scale-240.png";
            string title = post.Title;

            //if (title.Length > 13)
            //{
            //    title = title.Substring(0, 12) + "…";
            //}
            tileLarge.TextBodyWrap.Text = post.Summary;
            tileLarge.TextHeading.Text  = title;

            var tileSmall = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            tileSmall.Image.Src         = "ms-appx:///Assets/Logo.scale-240.png";
            tileSmall.TextHeading.Text  = post.BlogApp;
            tileSmall.TextBodyWrap.Text = post.Title;

            tileLarge.Square150x150Content = tileSmall;
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileLarge.CreateNotification());
        }
        private TileSquare150x150PeekImageAndText02 get150x150Content(string title, string content)
        {
            TileSquare150x150PeekImageAndText02 tileContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText02() as TileSquare150x150PeekImageAndText02;

            tileContent.TextHeading.Text  = title;
            tileContent.TextBodyWrap.Text = content;
            tileContent.Image.Src         = "ms-appx:///Images/" + imageNum + "/150_150.jpg";
            return(tileContent);
        }
        private TileSquare150x150PeekImageAndText02 get150x150Content(string title, string content)
        {
            TileSquare150x150PeekImageAndText02 tileContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText02() as TileSquare150x150PeekImageAndText02;

            tileContent.TextHeading.Text  = title;
            tileContent.TextBodyWrap.Text = content;
            tileContent.Image.Src         = "ms-appx:///Assets/squaretile-sdk.png";
            return(tileContent);
        }
        public void CreateTileSquare150x150PeekImageAndText02(string backTitle, string backContent)
        {
            var tileContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            tileContent.TextHeading.Text  = backTitle;
            tileContent.TextBodyWrap.Text = backContent;
            tileContent.Image.Src         = "";
            var tileNotification = tileContent.CreateNotification();

            Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
        }
示例#5
0
        private async void UpdateTileOnNewTrack(IPlayerTrack track)
        {
            try
            {
                string artistImage = await _imagesCacheService.GetCachedArtistImage(track.Artist);

                var images = await _imagesCacheService.GetCachedAlbumsImages(3);

                if (images.Count == 1)
                {
                    images.Add("ms-appx:///Assets/Images/PlayerLogo2.png");
                }

                int count = 5 - images.Count;
                for (int i = 1; i <= count; i++)
                {
                    images.Add($"ms-appx:///Assets/Images/PlayerLogo{i}.png");
                }

                var wideTile = TileContentFactory.CreateTileWide310x150PeekImageCollection01();
                wideTile.TextBodyWrap.Text = track.Title;
                wideTile.TextHeading.Text  = track.Artist;

                wideTile.ImageMain.Src             = images[0];
                wideTile.ImageSmallColumn1Row1.Src = images[1];
                wideTile.ImageSmallColumn1Row2.Src = images[2];
                wideTile.ImageSmallColumn2Row1.Src = images[3];
                wideTile.ImageSmallColumn2Row2.Src = images[4];

                var squareTile = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();
                squareTile.TextBodyWrap.Text = track.Title;
                squareTile.TextHeading.Text  = track.Artist;
                squareTile.Image.Src         = String.IsNullOrEmpty(artistImage) ? images[0] : artistImage;

                wideTile.RequireSquare150x150Content = true;
                wideTile.Square150x150Content        = squareTile;

                var tileNotification = wideTile.CreateNotification();

                if (_manager.CurrentTrack.Equals(track))
                {
                    TileUpdateManager.CreateTileUpdaterForApplication("App").Update(tileNotification);
                }
            }
            catch (Exception ex)
            {
                _logService.LogText($"Tile update exception: {ex.ToString()}");
            }
        }
示例#6
0
        /// <summary>
        /// TileWideSmallImageAndText02
        /// On the left, one small image; on the right, one header string in larger text on the first line over four strings of regular text on the next four lines. Text does not wrap.
        /// http://msdn.microsoft.com/en-us/library/windows/apps/hh761491#TileWideSmallImageAndText02
        ///
        /// TileSquarePeekImageAndText02
        /// Top: Square image, no text. Bottom: One header string in larger text on the first line, over one string of regular text wrapped over a maximum of three lines.
        /// http://msdn.microsoft.com/en-us/library/windows/apps/hh761491#TileSquarePeekImageAndText02
        /// </summary>
        /// <param name="item"></param>
        private static void CreateSeconderyNoteBook(NoteBook item)
        {
            var imgUrl     = GetPreviewImage(item, false).ToString();
            var imgWideUrl = GetPreviewImage(item, true).ToString();

            ITileWide310x150SmallImageAndText02 tileContent = TileContentFactory.CreateTileWide310x150SmallImageAndText02();

            tileContent.TextHeading.Text = item.Title;
            var count = item.Items.Count < 4 ? item.Items.Count : 4;

            for (var i = 0; i < count; i++)
            {
                var noteTitle = item.Items[i].Title;
                switch (i)
                {
                case 0:
                    tileContent.TextBody1.Text = noteTitle;
                    break;

                case 1:
                    tileContent.TextBody2.Text = noteTitle;
                    break;

                case 2:
                    tileContent.TextBody3.Text = noteTitle;
                    break;

                case 3:
                    tileContent.TextBody3.Text = noteTitle;
                    break;
                }
            }

            tileContent.Image.Src = imgWideUrl;
            tileContent.Image.Alt = item.Title;

            tileContent.Branding = TileBranding.Name;

            ITileSquare150x150PeekImageAndText02 squareTileContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            squareTileContent.Image.Src         = imgUrl;
            squareTileContent.Image.Alt         = item.Title;
            squareTileContent.TextHeading.Text  = item.Title;
            squareTileContent.TextBodyWrap.Text = item.Description.Equals(Consts.DefaultDescriptionText) ? string.Empty : item.Description.ToShortString();
            tileContent.Square150x150Content    = squareTileContent;

            TileUpdateManager.CreateTileUpdaterForSecondaryTile(item.UniqueId).Update(tileContent.CreateNotification());
        }
示例#7
0
        public void CreateTileWide310x150Text09(string title, string content)
        {
            var tileContent150 = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            tileContent150.TextHeading.Text  = title;
            tileContent150.TextBodyWrap.Text = content;
            tileContent150.Image.Src         = "";
            var tileContent = TileContentFactory.CreateTileWide310x150Text09();

            tileContent.TextHeading.Text            = title;
            tileContent.TextBodyWrap.Text           = content;
            tileContent.RequireSquare150x150Content = true;
            tileContent.Square150x150Content        = tileContent150;
            var tileNotification = tileContent.CreateNotification();

            Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
        }
示例#8
0
        /// <summary>
        /// 更新头条文章的磁贴tile
        /// </summary>
        /// <param name="t"></param>
        private static void UpdateTile(LatestStories t)
        {
            //头5条 循环更新到tile中
            List <string> list       = t.Top_Stories.ToList().Select(s => s.Title).ToList();
            List <string> list_image = t.Top_Stories.ToList().Select(s => s.Image).ToList();

            var tileUpdater          = TileUpdateManager.CreateTileUpdaterForApplication();
            var plannedNotifications = tileUpdater.GetScheduledTileNotifications();

            DateTime now        = DateTime.Now;
            DateTime updateTime = now;
            DateTime planTill   = now.AddMinutes(60); //每次制定1小时的tile更新计划

            //删除还未执行的计划
            if (plannedNotifications.Count > 0)
            {
                plannedNotifications.ToList().ForEach(s => tileUpdater.RemoveFromSchedule(s));
            }

            int index = 0;
            int count = list.Count;

            //制定tile更新的计划
            for (var startPlanning = updateTime; startPlanning < planTill; startPlanning = startPlanning.AddSeconds(10))
            {
                try
                {
                    var tilexml = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();
                    tilexml.Image.Src         = list_image[index % count];
                    tilexml.TextHeading.Text  = "知乎日报UWP";
                    tilexml.TextBodyWrap.Text = list[index % count];
                    index++;

                    ScheduledTileNotification stn = new ScheduledTileNotification(tilexml.GetXml(), startPlanning);
                    stn.ExpirationTime = startPlanning.AddSeconds(8);

                    tileUpdater.AddToSchedule(stn);
                }
                catch
                {
                }
            }
        }
        public void UpdateSecondaryTile(string tileID, string backtitle, string backcontent)
        {
            if (string.IsNullOrEmpty(tileID) || string.IsNullOrEmpty(backcontent))
            {
                return;
            }
            if (!SecondaryTile.Exists(tileID))
            {
                return;
            }
            var tileContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            tileContent.TextHeading.Text  = backtitle;
            tileContent.TextBodyWrap.Text = backcontent;
            tileContent.Image.Src         = "ms-appx:///Assets/Tile150x150.png";
            var         tileNotification = tileContent.CreateNotification();
            TileUpdater updater          = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileID);

            updater.EnableNotificationQueue(false);
            updater.Update(tileNotification);
        }
示例#10
0
        /// <summary>
        /// TileWideSmallImageAndText04
        /// On the left, one small image; on the right, one header string of larger text on the first line over one string of regular text wrapped over a maximum of four lines.
        /// http://msdn.microsoft.com/en-us/library/windows/apps/hh761491#TileWideSmallImageAndText04
        ///
        /// TileSquarePeekImageAndText02
        /// Top: Square image, no text. Bottom: One header string in larger text on the first line, over one string of regular text wrapped over a maximum of three lines.
        /// http://msdn.microsoft.com/en-us/library/windows/apps/hh761491#TileSquarePeekImageAndText02
        /// </summary>
        /// <param name="item"></param>
        private static void CreateSeconderyWithImage(NoteDataCommon item)
        {
            var imgUrl     = GetPreviewImage(item, false).ToString();
            var imgWideUrl = GetPreviewImage(item, true).ToString();

            ITileWide310x150SmallImageAndText04 tileContent = TileContentFactory.CreateTileWide310x150SmallImageAndText04();

            tileContent.TextHeading.Text  = item.Title;
            tileContent.TextBodyWrap.Text = item.Description.Equals(Consts.DefaultDescriptionText) ? string.Empty : item.Description.ToShortString();
            tileContent.Image.Src         = imgWideUrl;
            tileContent.Image.Alt         = item.Title;

            ITileSquare150x150PeekImageAndText02 squareTileContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            squareTileContent.Image.Src         = imgUrl;
            squareTileContent.Image.Alt         = item.Title;
            squareTileContent.TextHeading.Text  = item.Title;
            squareTileContent.TextBodyWrap.Text = item.Description.Equals(Consts.DefaultDescriptionText) ? string.Empty : item.Description.ToShortString();
            tileContent.Square150x150Content    = squareTileContent;

            tileContent.Branding = TileBranding.Name;
            TileUpdateManager.CreateTileUpdaterForSecondaryTile(item.UniqueId).Update(tileContent.CreateNotification());
        }
示例#11
0
        public static void CreateTile(Post post)
        {
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.EnableNotificationQueue(true);
            updater.Clear();

            var tileLarge = TileContentFactory.CreateTileWide310x150PeekImage01();

            tileLarge.Image.Src = "ms-appx:///Assets/TileUpdateBG_Wide_310x150.png";
            string title = post.Title;

            tileLarge.TextBodyWrap.Text = post.Summary;
            tileLarge.TextHeading.Text  = title;

            var tileSmall = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            tileSmall.Image.Src         = "ms-appx:///Assets/TileUpdateBG_Square_150x150.png";
            tileSmall.TextHeading.Text  = post.BlogApp;
            tileSmall.TextBodyWrap.Text = post.Title;

            tileLarge.Square150x150Content = tileSmall;
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileLarge.CreateNotification());
        }
        void UpdateTile()
        {
            try
            {
                var imgs = ViewModel.RecommandSection.First(g => g.Key.Contains("更新")).Take(6).ToArray();

                var tileContent = TileContentFactory.CreateTileSquare310x310ImageCollectionAndText01();
                tileContent.AddImageQuery = true;

                tileContent.ImageMain.Src        = imgs[0].CoverImageUri;
                tileContent.ImageMain.Alt        = imgs[0].Title;
                tileContent.ImageSmall1.Src      = imgs[1].CoverImageUri;
                tileContent.ImageSmall1.Alt      = imgs[1].Title;
                tileContent.ImageSmall2.Src      = imgs[2].CoverImageUri;
                tileContent.ImageSmall2.Alt      = imgs[2].Title;
                tileContent.ImageSmall3.Src      = imgs[3].CoverImageUri;
                tileContent.ImageSmall3.Alt      = imgs[3].Title;
                tileContent.ImageSmall4.Src      = imgs[4].CoverImageUri;
                tileContent.ImageSmall4.Alt      = imgs[4].Title;
                tileContent.TextCaptionWrap.Text = imgs[0].Description;
                // Create a notification for the Wide310x150 tile using one of the available templates for the size.
                //var wide310x150Content = TileContentFactory.CreateTileWide310x150ImageAndText01();
                //wide310x150Content.TextCaptionWrap.Text = "This tile notification uses web images";
                //wide310x150Content.Image.Src = ImgUri;
                //wide310x150Content.Image.Alt = "Web image";
                var wide310x150Content = TileContentFactory.CreateTileWide310x150PeekImageCollection05();
                wide310x150Content.AddImageQuery = true;
                //wide310x150Content.Lang = "zh-Hans";
                wide310x150Content.ImageMain.Src             = imgs[0].CoverImageUri;
                wide310x150Content.ImageMain.Alt             = imgs[0].Title;
                wide310x150Content.ImageSecondary.Src        = imgs[0].CoverImageUri;
                wide310x150Content.ImageSecondary.Alt        = imgs[0].Title;
                wide310x150Content.ImageSmallColumn1Row1.Src = imgs[1].CoverImageUri;
                wide310x150Content.ImageSmallColumn1Row1.Alt = imgs[1].Title;
                wide310x150Content.ImageSmallColumn1Row2.Src = imgs[2].CoverImageUri;
                wide310x150Content.ImageSmallColumn1Row2.Alt = imgs[2].Title;
                wide310x150Content.ImageSmallColumn2Row1.Src = imgs[3].CoverImageUri;
                wide310x150Content.ImageSmallColumn2Row1.Alt = imgs[3].Title;
                wide310x150Content.ImageSmallColumn2Row2.Src = imgs[4].CoverImageUri;
                wide310x150Content.ImageSmallColumn2Row2.Alt = imgs[4].Title;
                wide310x150Content.TextHeading.Text          = imgs[0].Title;
                wide310x150Content.TextBodyWrap.Text         = imgs[0].Description;

                // Create a notification for the Square150x150 tile using one of the available templates for the size.
                var square150x150Content = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();
                //square150x150Content.Lang = "zh-Hans";
                square150x150Content.Image.Src         = imgs[0].CoverImageUri;
                square150x150Content.Image.Alt         = imgs[0].Title;
                square150x150Content.TextHeading.Text  = imgs[0].Title;
                square150x150Content.TextBodyWrap.Text = imgs[0].Description;
                //var square150x150Content = TileContentFactory.CreateTileSquare150x150Image();
                //square150x150Content.Image.Src = ImgUri;
                //square150x150Content.Image.Alt = "Web image";

                var square71x71Content = TileContentFactory.CreateTileSquare71x71Image();
                square71x71Content.Image.Src = imgs[0].CoverImageUri;;
                square71x71Content.Image.Alt = imgs[0].Title;

                // Attached the Square71x71 template to the Square150x150 template.
                square150x150Content.Square71x71Content = square71x71Content;

                // Attach the Square150x150 template to the Wide310x150 template.
                wide310x150Content.Square150x150Content = square150x150Content;

                // Attach the Wide310x150 template to the Square310x310 template.
                tileContent.Wide310x150Content = wide310x150Content;

                // Send the notification to the application’s tile.
                TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification());
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }
        }
        public static async Task <bool> UpdateNoteTileIfExists(Note note, bool transparentTile = false)
        {
            //must exists
            if (!SecondaryTile.Exists(note.ID))
            {
                return(false);
            }

            //update background
            await UpdateNoteTileBackgroundColor(note, transparentTile);

            string contentWithoutTitle = note.GetContent(true, false, 150, 3);
            string contentWithTitle    = note.GetContent(true, true, 200, 3);

            var tileSquare71Content = TileContentFactory.CreateTileSquare71x71Image();

            tileSquare71Content.Image.Src = "ms-appx:///Assets/Tiles/Transparent/Square71x71Logo.png";

            ITileNotificationContent biggerTile;
            ISquare150x150TileNotificationContent tileSquare150Content;

            if (note.Images != null && note.Images.Count > 0)
            {
                tileSquare150Content = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

                var _tileSquare150Content = tileSquare150Content as ITileSquare150x150PeekImageAndText02;
                _tileSquare150Content.TextHeading.Text   = note.Title;
                _tileSquare150Content.TextBodyWrap.Text  = contentWithoutTitle;
                _tileSquare150Content.Image.Src          = note.Images[0].URL;
                _tileSquare150Content.Square71x71Content = tileSquare71Content;
                _tileSquare150Content.Branding           = NotificationsExtensions.TileContent.TileBranding.Logo;
            }
            else
            {
                tileSquare150Content = TileContentFactory.CreateTileSquare150x150Text02();

                var _tileSquare150Content = tileSquare150Content as ITileSquare150x150Text02;
                _tileSquare150Content.TextHeading.Text   = note.Title;
                _tileSquare150Content.TextBodyWrap.Text  = contentWithoutTitle;
                _tileSquare150Content.Square71x71Content = tileSquare71Content;
                _tileSquare150Content.Branding           = NotificationsExtensions.TileContent.TileBranding.Logo;
            }

            IWide310x150TileNotificationContent tileWide310x150Content;

            if (note.Images != null && note.Images.Count > 0)
            {
                tileWide310x150Content = TileContentFactory.CreateTileWide310x150PeekImage01();

                var _tileWide310x150Content = tileWide310x150Content as ITileWide310x150PeekImage01;
                _tileWide310x150Content.TextHeading.Text     = note.Title;
                _tileWide310x150Content.TextBodyWrap.Text    = contentWithoutTitle;
                _tileWide310x150Content.Image.Src            = note.Images[0].URL;
                _tileWide310x150Content.Square150x150Content = tileSquare150Content;
                _tileWide310x150Content.Branding             = NotificationsExtensions.TileContent.TileBranding.Logo;
            }
            else
            {
                tileWide310x150Content = TileContentFactory.CreateTileWide310x150Text09();

                var _tileWide310x150Content = tileWide310x150Content as ITileWide310x150Text09;
                _tileWide310x150Content.TextHeading.Text     = note.Title;
                _tileWide310x150Content.TextBodyWrap.Text    = contentWithoutTitle;
                _tileWide310x150Content.Square150x150Content = tileSquare150Content;
                _tileWide310x150Content.Branding             = NotificationsExtensions.TileContent.TileBranding.Logo;
            }

#if WINDOWS_PHONE_APP
            biggerTile = tileWide310x150Content;
#else
            ISquare310x310TileNotificationContent tileSquare310Content;
            if (note.Images != null && note.Images.Count > 0)
            {
                tileSquare310Content = TileContentFactory.CreateTileSquare310x310ImageAndTextOverlay02();

                var _tileSquare310Content = tileSquare310Content as ITileSquare310x310ImageAndTextOverlay02;
                _tileSquare310Content.TextHeadingWrap.Text = note.Title;
                _tileSquare310Content.TextBodyWrap.Text    = contentWithoutTitle;
                _tileSquare310Content.Image.Src            = note.Images[0].URL;
                _tileSquare310Content.Wide310x150Content   = tileWide310x150Content;
                _tileSquare310Content.Branding             = NotificationsExtensions.TileContent.TileBranding.Logo;
            }
            else
            {
                tileSquare310Content = TileContentFactory.CreateTileSquare310x310ImageAndTextOverlay02();

                var _tileSquare310Content = tileSquare310Content as ITileSquare310x310ImageAndTextOverlay02;
                _tileSquare310Content.TextHeadingWrap.Text = note.Title;
                _tileSquare310Content.TextBodyWrap.Text    = contentWithoutTitle;
                _tileSquare310Content.Image.Src            = "";
                _tileSquare310Content.Wide310x150Content   = tileWide310x150Content;
                _tileSquare310Content.Branding             = NotificationsExtensions.TileContent.TileBranding.Logo;
            }

            biggerTile = tileSquare310Content;
#endif

            //create notification
            var notification = biggerTile.CreateNotification();
            notification.Tag = note.ID.Substring(0, 16);

            //update
            var tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(note.ID);
            tileUpdater.Clear();
            //tileUpdater.EnableNotificationQueue(false); //crashing on w10mobile
            tileUpdater.Update(notification);

            return(true);
        }