Exemple #1
0
        private async void btnSecTile_Click(object sender, RoutedEventArgs e)
        {
            Windows.Foundation.Rect rect = GetElementRect((FrameworkElement)sender);

            if (SecondaryTile.Exists("MyUnicTileID"))
            {
                SecondaryTile secondaryTile = new SecondaryTile("MyUnicTileID");

                bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(rect, Windows.UI.Popups.Placement.Above);

                ToggleAppBarButton(isUnpinned);
            }
            else
            {
                // Pin
                Uri    square150x150Logo       = new Uri("ms-appx:///Assets/Square150x150Logo.png");
                string tileActivationArguments = "Secondary tile was pinned at = " + DateTime.Now.ToLocalTime().ToString();
                string displayName             = "App Template";

                TileSize      newTileDesiredSize = TileSize.Square150x150;
                SecondaryTile secondaryTile      = new SecondaryTile("MyUnicTileID",
                                                                     displayName,
                                                                     tileActivationArguments,
                                                                     square150x150Logo,
                                                                     newTileDesiredSize);

                secondaryTile.VisualElements.Square44x44Logo             = new Uri("ms-appx:///Assets/Square44x44Logo.png");
                secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
                secondaryTile.VisualElements.ForegroundText = ForegroundText.Light;

                bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(rect, Windows.UI.Popups.Placement.Above);

                ToggleAppBarButton(!isPinned);
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates or Remove Pin for Note
        /// If Pin exists then create new SecondaryTile with the Note Unique Id (to obtain the exists SecondaryTile) and call RequestDeleteForSelectionAsync to remove the SecondaryTile.
        /// If it's a new Pin then create new SecondaryTile.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="item">Note item to Pin</param>
        /// <returns>True for completion or False if an error occurred.</returns>
        async public static Task <bool> Pin(object sender, NoteDataCommon item)
        {
            // Determine whether to pin or unpin.
            if (SecondaryTile.Exists(item.UniqueId))
            {
                SecondaryTile secondaryTile = new SecondaryTile(item.UniqueId);
                Rect          pinButtonRect = Helpers.GetElementRect((FrameworkElement)sender);
                return(await secondaryTile.RequestDeleteForSelectionAsync(pinButtonRect, Windows.UI.Popups.Placement.Above));
            }
            else
            {
                Uri logo     = GetPreviewImage(item, false);
                Uri logoWide = GetPreviewImage(item, true);

                string        tileActivationArguments = string.Format("{0}{1}", Consts.SecondaryTileFormat, item.UniqueId);
                SecondaryTile secondaryTile           = new SecondaryTile(item.UniqueId,
                                                                          item.Title,
                                                                          tileActivationArguments,
                                                                          logo, TileSize.Square150x150);
                secondaryTile.VisualElements.Wide310x150Logo = logoWide;

                Rect pinButtonRect = Helpers.GetElementRect((FrameworkElement)sender);
                return(await secondaryTile.RequestCreateForSelectionAsync(pinButtonRect, Windows.UI.Popups.Placement.Above));
            }
        }
Exemple #3
0
        async void pinToAppBar_Click(object sender, RoutedEventArgs e)
        {
            rootPage.BottomAppBar.IsSticky = true;
            // Let us first verify if we need to pin or unpin
            if (SecondaryTile.Exists(MainPage.appbarTileId))
            {
                // First prepare the tile to be unpinned
                SecondaryTile secondaryTile = new SecondaryTile(MainPage.appbarTileId);
                // Now make the delete request.
                bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);

                if (isUnpinned)
                {
                    rootPage.NotifyUser(MainPage.appbarTileId + " unpinned.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser(MainPage.appbarTileId + " not unpinned.", NotifyType.ErrorMessage);
                }

                ToggleAppBarButton(isUnpinned);
            }
            else
            {
                // Prepare package images for use as the Tile Logo in our tile to be pinned
                Uri logo = new Uri("ms-appx:///Assets/squareTile-sdk.png");

                // During creation of secondary tile, an application may set additional arguments on the tile that will be passed in during activation.
                // These arguments should be meaningful to the application. In this sample, we'll pass in the date and time the secondary tile was pinned.
                string tileActivationArguments = MainPage.appbarTileId + " WasPinnedAt=" + DateTime.Now.ToLocalTime().ToString();

                // Create a 1x1 Secondary tile
                SecondaryTile secondaryTile = new SecondaryTile(MainPage.appbarTileId,
                                                                "Secondary tile pinned via AppBar",
                                                                "SDK Sample Secondary Tile pinned from AppBar",
                                                                tileActivationArguments,
                                                                TileOptions.ShowNameOnLogo,
                                                                logo);

                // Specify a foreground text value.
                // The tile background color is inherited from the parent unless a separate value is specified.
                secondaryTile.ForegroundText = ForegroundText.Dark;

                // OK, the tile is created and we can now attempt to pin the tile.
                // Note that the status message is updated when the async operation to pin the tile completes.
                bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);

                if (isPinned)
                {
                    rootPage.NotifyUser(MainPage.appbarTileId + " successfully pinned.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser(MainPage.appbarTileId + " not pinned.", NotifyType.ErrorMessage);
                }

                ToggleAppBarButton(!isPinned);
            }
            rootPage.BottomAppBar.IsSticky = false;
        }
Exemple #4
0
        public async Task <bool> UnpinQuickAdd()
        {
            var  tile   = new SecondaryTile(quickAddTaskTileId);
            bool result = await tile.RequestDeleteForSelectionAsync(GetPlacement(), Placement.Below);

            return(result);
        }
        private async void pinUnpinButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (SecondaryTile.Exists(thisItem.Title))
                {
                    SecondaryTile    secondaryTile = new SecondaryTile(thisItem.Title);
                    FrameworkElement element       = (FrameworkElement)sender;
                    GeneralTransform transform     = element.TransformToVisual(null);
                    Point            point         = transform.TransformPoint(new Point());
                    Rect             rect          = new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
                    await secondaryTile.RequestDeleteForSelectionAsync(rect, Placement.Above);

                    pinButton.Content = "pin";
                    thisItem.IsPinned = false;
                }
                else
                {
                    SecondaryTile secondaryTile = new SecondaryTile(
                        thisItem.Title, thisItem.Title, thisItem.Title,
                        new Uri(string.Format(CultureInfo.CurrentCulture, "ms-appx://{0}", thisItem.Photo)), TileSize.Square150x150);
                    secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
                    await secondaryTile.RequestCreateAsync();

                    pinButton.Content = "unpin";
                    thisItem.IsPinned = true;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("SecondaryTilePage.pinUnpinButton_Click: " + ex.ToString());
            }
        }
        /// <summary>
        /// This is the click handler for the 'Unpin' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void UnpinSecondaryTile_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            if (button != null)
            {
                if (Windows.UI.StartScreen.SecondaryTile.Exists(MainPage.logoSecondaryTileId))
                {
                    // First prepare the tile to be unpinned
                    SecondaryTile secondaryTile = new SecondaryTile(MainPage.logoSecondaryTileId);
                    // Now make the delete request.
                    bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Below);

                    if (isUnpinned)
                    {
                        rootPage.NotifyUser("Secondary tile successfully unpinned.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser("Secondary tile not unpinned.", NotifyType.ErrorMessage);
                    }
                }
                else
                {
                    rootPage.NotifyUser(MainPage.logoSecondaryTileId + " is not currently pinned.", NotifyType.ErrorMessage);
                }
            }
        }
Exemple #7
0
        public static async Task <bool> RemoveTile(string tileID, Rect popupRect, Placement placement = Placement.Default)
        {
            if (DoesTileExist(tileID))
            {
                // First prepare the tile to be unpinned
                SecondaryTile secondaryTile = new SecondaryTile(tileID);

                // Now make the delete request.
                bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(popupRect, placement);

                if (isUnpinned)
                {
                    try {
                        await StorageTools.DeleteFile(StorageTools.StorageConsts.TileFolder + "\\" +
                                                      tileID + ".jpg",
                                                      Windows.Storage.StorageDeleteOption.PermanentDelete);
                    }
                    catch (Exception) { }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #8
0
        /// <summary>
        /// It pins the app to the StartPage.
        /// </summary>
        /// <param name="sender">Object Sender is a parameter called Sender that contains a reference to the control/object that raised the event.</param>
        /// <param name="e">RoutedEventArgs e is a parameter called e that contains the event data, see the RoutedEventArgs MSDN page for more information.</param>
        async void pinToAppBar_Click(object sender, RoutedEventArgs e)
        {
            if (SecondaryTile.Exists(AppInstance.app.Name.Replace(" ", "")))
            {
                SecondaryTile secondaryTile = new SecondaryTile(AppInstance.app.Name.Replace(" ", ""));
                bool          isUnpinned    = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Below);

                if (isUnpinned)
                {
                    ToggleAppBarButton(isUnpinned);
                }
            }
            else
            {
                Uri           square150x150Logo       = new Uri("ms-appx:///Assets/Logo.scale-100.png");
                string        tileActivationArguments = AppInstance.app.Name;
                SecondaryTile secondaryTile           = new SecondaryTile(AppInstance.app.Name.Replace(" ", ""),
                                                                          AppInstance.app.Name,
                                                                          tileActivationArguments,
                                                                          square150x150Logo,
                                                                          TileSize.Square150x150);
                secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
                secondaryTile.VisualElements.ForegroundText = ForegroundText.Dark;
                secondaryTile.RoamingEnabled = false;
                ToggleAppBarButton(false);
                await secondaryTile.RequestCreateAsync();
            }
        }
        /// <summary>
        /// Unpins the item from the StartScreen and shows confirmation popup
        /// at the specified placement, relative to the sourceElement
        /// </summary>
        /// <param name="tileId"></param>
        /// <param name="shortName"></param>
        /// <param name="displayName"></param>
        /// <param name="logo"></param>
        /// <param name="sourceElement"></param>
        /// <param name="placement"></param>
        /// <returns></returns>
        public static async Task <bool> UnpinItem(string tileId, FrameworkElement sourceElement, Placement placement)
        {
            var tileToDelete = new SecondaryTile(tileId);

            bool unpinSuccess = await tileToDelete.RequestDeleteForSelectionAsync(VisualTreeHelperExtensions.GetElementRect(sourceElement), placement);

            return(unpinSuccess);
        }
Exemple #10
0
        private async void UnPin_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            SecondaryTile secondaryTile = ViewModel.CreateTileForStation();

            // Now make the delete request.
            bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Below);

            ViewModel.SetPinned(!isUnpinned);
        }
Exemple #11
0
        internal static async Task <Boolean> UnpinSecondaryTile(FrameworkElement _element)
        {
            // First prepare the tile to be unpinned
            SecondaryTile secondaryTile = new SecondaryTile(_logoSecondaryTileId);

            GeneralTransform buttonTransform = _element.TransformToVisual(null);
            Point            point           = buttonTransform.TransformPoint(new Point());
            Rect             rect            = new Rect(point, new Size(_element.ActualWidth, _element.ActualHeight));

            return(await secondaryTile.RequestDeleteForSelectionAsync(rect, Placement.Above));
        }
        public async Task <bool> UnpinAsync(string Id, Windows.UI.Popups.Placement placement = Windows.UI.Popups.Placement.Above)
        {
            System.Diagnostics.Contracts.Contract.Requires(Id != null, "TileId");
            if (!SecondaryTile.Exists(Id))
            {
                return(true);
            }
            var tile   = new SecondaryTile(Id);
            var result = await tile.RequestDeleteForSelectionAsync(new Rect(0, 0, 0, 0), placement);

            return(result);
        }
        public async Task <bool> Unpin(TileInfo tileInfo)
        {
            var wasUnpinned = false;

            if (SecondaryTile.Exists(tileInfo.TileId))
            {
                var secondaryTile = new SecondaryTile(tileInfo.TileId);
                wasUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(
                    GetElementRect(tileInfo.AnchorElement), tileInfo.RequestPlacement);
            }

            return(wasUnpinned);
        }
Exemple #14
0
        private async void TogglePin(SubredditItem subreddit, Rect rect)
        {
            string tileId = subreddit.Url;

            if (SecondaryTile.Exists(tileId))
            {
                SecondaryTile secondaryTile           = new SecondaryTile(tileId);
                Windows.UI.Popups.Placement placement = Windows.UI.Popups.Placement.Above;
                bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(rect, placement);

                ToggleAppBarButton(isUnpinned);
            }
            else
            {
                string   displayName             = $"/r/{subreddit.Url}";
                string   tileActivationArguments = $"subreddit://{tileId}";
                Uri      logo = new Uri("ms-appx:///Assets/Square150x150Logo.png");
                TileSize newTileDesiredSize = TileSize.Square150x150;

                SecondaryTile secondaryTile = new SecondaryTile(tileId, displayName, tileActivationArguments, logo, newTileDesiredSize);

                secondaryTile.VisualElements.Square71x71Logo   = new Uri("ms-appx:///Assets/Square71x71Logo.png");
                secondaryTile.VisualElements.Wide310x150Logo   = new Uri("ms-appx:///Assets/Wide310x150Logo.png");
                secondaryTile.VisualElements.Square310x310Logo = new Uri("ms-appx:///Assets/Square310x310Logo.png");
                secondaryTile.VisualElements.Square44x44Logo   = new Uri("ms-appx:///Assets/Square44x44Logo.png");

                secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
                secondaryTile.VisualElements.ShowNameOnSquare310x310Logo = true;
                secondaryTile.VisualElements.ShowNameOnWide310x150Logo   = true;

                Windows.UI.Popups.Placement placement = Windows.UI.Popups.Placement.Above;
                var tileManager = SimpleIoc.Default.GetInstance <TileManager>();
                if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent(("Windows.Phone.UI.Input.HardwareButtons"))))
                {
                    bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(rect, placement);

                    ToggleAppBarButton(!isPinned);
                }

                //Phone
                if ((Windows.Foundation.Metadata.ApiInformation.IsTypePresent(("Windows.Phone.UI.Input.HardwareButtons"))))
                {
                    //tileManager.ScheduleRedditTileUpdate(tileId, Vm.Images);
                    bool isPinned = await secondaryTile.RequestCreateAsync();

                    ToggleAppBarButton(!isPinned);
                }
                tileManager.UpdateRedditTile(tileId, Vm.Images);
            }
        }
Exemple #15
0
        //Reset TimeMe status and All Files
        async void btn_ResetTimeMeStatus_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Nullable <bool> MessageDialogResult = null;
                MessageDialog   MessageDialog       = new MessageDialog("Do you really want to reset the TimeMe status and remove all files which will reset TimeMe to it's defaults? This is only recommended when TimeMe has stopped updating the live tile.\n\nAfter the application has been reset to it's defaults TimeMe will be closed and will need to be run again manually before live tile updates start to work.", "TimeMe");
                MessageDialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler((cmd) => MessageDialogResult = true)));
                MessageDialog.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => MessageDialogResult  = false)));
                await MessageDialog.ShowAsync();

                if (MessageDialogResult == true)
                {
                    grid_Main.Opacity          = 0.60;
                    grid_Main.IsHitTestVisible = false;
                    txt_StatusBar.Text         = "Resetting TimeMe, please wait...";
                    sp_StatusBar.Visibility    = Visibility.Visible;

                    //Stop all background tasks
                    foreach (KeyValuePair <Guid, IBackgroundTaskRegistration> BackgroundTask in BackgroundTaskRegistration.AllTasks)
                    {
                        BackgroundTask.Value.Unregister(true);
                    }

                    //Reset application settings
                    foreach (KeyValuePair <string, object> AppSetting in ApplicationData.Current.LocalSettings.Values)
                    {
                        ApplicationData.Current.LocalSettings.Values.Remove(AppSetting.Key);
                    }

                    //Delete all files from local storage
                    foreach (IStorageItem LocalFile in await ApplicationData.Current.LocalFolder.GetItemsAsync())
                    {
                        try { await LocalFile.DeleteAsync(StorageDeleteOption.PermanentDelete); } catch { }
                    }

                    //Unpin all the live tiles
                    foreach (SecondaryTile SecondaryTile in await SecondaryTile.FindAllAsync())
                    {
                        await SecondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Below);
                    }

                    //Clear all notification messages
                    ToastNotificationManager.History.Clear();

                    Application.Current.Exit();
                }
            }
            catch { Application.Current.Exit(); }
        }
        private async void OnUnpinSecondTileClick(object sender, RoutedEventArgs e)
        {
            SecondaryTile secondaryTile = new SecondaryTile(MainPage.SecondaryTileId);
            bool          isUnpinned    = await secondaryTile.RequestDeleteForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Below);

            if (isUnpinned)
            {
                this.SetSuccessStatus("Secondary tile was successfully unpinned.");
                this.IsSecondaryTilePinned = false;
            }
            else
            {
                this.SetErrorMessage("Secondary tile is not unpinned.");
            }
        }
Exemple #17
0
        public async Task <bool> UnpinPoll(FrameworkElement anchorElement, int pollId)
        {
            var wasUnpinned = false;

            var tileId = string.Format(SecondaryPinner.TileIdFormat, pollId);

            if (SecondaryTile.Exists(tileId))
            {
                var secondaryTile = new SecondaryTile(tileId);
                wasUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(
                    GetElementRect(anchorElement), Placement.Above);
            }

            return(wasUnpinned);
        }
Exemple #18
0
        public async Task <bool> UnpinAsync(IAbstractFolder folder)
        {
            if (this.IsPinned(folder))
            {
                string id     = LaunchArgumentsHelper.GetArgSelectFolder(folder);
                var    tile   = new SecondaryTile(id);
                bool   result = await tile.RequestDeleteForSelectionAsync(GetPlacement(), Placement.Below);

                if (result)
                {
                    this.secondaryTiles.Remove(t => t.TileId == id);
                    this.notificationService?.ShowNotification(string.Format(StringResources.Notification_FolderUnpinnedFormat, folder.Name), ToastType.Info);
                }

                return(result);
            }

            return(false);
        }
Exemple #19
0
        public async Task <bool> UnPin(SecondaryTile tile, Rect elementRect)
        {
            bool result = await tile.RequestDeleteForSelectionAsync(elementRect, Windows.UI.Popups.Placement.Below);

            if (result)
            {
                try
                {
                    StorageFolder tileFolder = await StorageTask.Instance.GetFolder(RootFolder, TileManager.TileImagesFolderName);

                    StorageFile imageFile = await StorageTask.Instance.GetFile(tileFolder, tile.TileId + ".jpg");

                    await StorageTask.Instance.DeleteItem(StorageTask.StorageFileToIStorageItem(imageFile), StorageDeleteOption.PermanentDelete);
                }
                catch (Exception) { }
            }

            return(result);
        }
Exemple #20
0
        /// <summary>
        /// This method unpins the existing secondary tile.
        /// The user is showna  message informing whether the tile is unpinned successfully
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="appbarTileId">The appbar tile id.</param>
        /// <returns></returns>
        private async Task UnpinSecondaryTile(object sender, string appbarTileId)
        {
            SecondaryTile secondaryTile = new SecondaryTile(appbarTileId);
            bool          isUnpinned    = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender),
                                                                                             Windows.UI.Popups.Placement.Above);

            if (isUnpinned)
            {
                MessageDialog dialog =
                    new MessageDialog("Job " + job.JobNumber + " (" + job.Title + ") successfully unpinned.");
                await dialog.ShowAsync();
            }
            else
            {
                MessageDialog dialog = new MessageDialog("Job " + job.JobNumber + " (" + job.Title + ") not unpinned.");
                await dialog.ShowAsync();
            }

            ToggleAppBarButton(isUnpinned, sender as AppBarButton);
        }
Exemple #21
0
        private async void delButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (subscrGridView.SelectedItems.Count == 0)
            {
                return;
            }

            var itemsSelected = subscrGridView.SelectedItems.ToArray();

            foreach (SiteViewModel item in itemsSelected)
            {
                if (SecondaryTile.Exists(item.siteName))
                {
                    var st = new SecondaryTile(item.siteName);
                    await st.RequestDeleteForSelectionAsync(getElementRect((FrameworkElement)sender));
                }
                app.vm.delSecSiteAndAqView(item.siteName);
            }
            await app.vm.delSubscrSite(itemsSelected);
        }
Exemple #22
0
        async public static Task <bool> Pin(object sender, Reservation reservation)
        {
            // Determine whether to pin or unpin.
            if (SecondaryTile.Exists(reservation.ReservationId.ToString()))
            {
                SecondaryTile secondaryTile = new SecondaryTile(reservation.ReservationId.ToString());
                Rect          pinButtonRect = GetElementRect((FrameworkElement)sender);
                return(await secondaryTile.RequestDeleteForSelectionAsync(pinButtonRect, Windows.UI.Popups.Placement.Above));
            }
            else
            {
                Uri           logo          = null; // GetPreviewImage(item, false);
                Uri           logoWide      = null; // GetPreviewImage(item, true);
                var           flight        = reservation.DepartureFlight.FlightInfo.Flight;
                var           title         = string.Format(Accessories.resourceLoader.GetString("SourceToDestinationAtDate"), flight.Source.City, flight.Destination.City, reservation.ReservationDate);
                SecondaryTile secondaryTile = new SecondaryTile(title, title, title, title, TileOptions.None, logo, logoWide);

                Rect pinButtonRect = GetElementRect((FrameworkElement)sender);
                return(await secondaryTile.RequestCreateForSelectionAsync(pinButtonRect, Windows.UI.Popups.Placement.Above));
            }
        }
Exemple #23
0
        public static async Task <bool> CreateOrReplaceSecondaryTile(VLCItemType type, int id, string title)
        {
            string tileId = "SecondaryTile-" + type.ToString() + "-" + id;

            if (!SecondaryTile.Exists(tileId))
            {
                var tileData = new SecondaryTile()
                {
                    TileId      = tileId,
                    DisplayName = title,
                    Arguments   = tileId
                };
                string subfolder = null;
                switch (type)
                {
                case VLCItemType.Album:
                    subfolder = "albumPic";
                    break;

                case VLCItemType.Artist:
                    subfolder = "artistPic";
                    break;
                }
                tileData.VisualElements.ShowNameOnSquare150x150Logo = true;
                tileData.DisplayName = title;
                tileData.VisualElements.Square150x150Logo =
                    new Uri("ms-appdata:///local/" + subfolder + "/" + id + ".jpg");
                bool success = await tileData.RequestCreateAsync();

                return(success);
            }
            else
            {
                SecondaryTile secondaryTile = new SecondaryTile(tileId);
                await secondaryTile.RequestDeleteForSelectionAsync(Window.Current.Bounds, Placement.Default);

                ToastHelper.Basic(Strings.TileRemoved);
                return(false);
            }
        }
        private async void OnPinToStart(object sender, RoutedEventArgs e)
        {
            try
            {
                var fixedtitle = Regex.Replace(Scenario.Title, @"\W", "-");
                if (PinToStart.IsOn)
                {
                    if (string.IsNullOrWhiteSpace(fixedtitle))
                    {
                        PinToStart.IsOn = false;
                    }
                    else if (!SecondaryTile.Exists(fixedtitle))
                    {
                        Uri logo = new Uri(@"ms-appx:///Assets/Square150x150Logo.scale-200.png");
                        var tile = new SecondaryTile(fixedtitle,
                                                     Scenario.Title,
                                                     Scenario.Title,
                                                     logo,
                                                     TileSize.Default);

                        await tile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender));
                    }
                }
                else if (!string.IsNullOrWhiteSpace(fixedtitle))
                {
                    if (SecondaryTile.Exists(fixedtitle))
                    {
                        SecondaryTile               secondaryTile = new SecondaryTile(fixedtitle);
                        Windows.Foundation.Rect     rect          = GetElementRect((FrameworkElement)sender);
                        Windows.UI.Popups.Placement placement     = Windows.UI.Popups.Placement.Above;
                        bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(rect, placement);
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                throw;
            }
        }
        /// <summary>
        /// This method unpins the existing secondary tile.
        /// The user is shown a message informing whether the tile is unpinned successfully
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="vm">The Current Product View Model.</param>
        /// <returns></returns>
        private async Task UnpinSecondaryTile(object sender, ViewProductViewModel vm)
        {
            try
            {
                if (SecondaryTile.Exists(vm.ProductDetails.Id))
                {
                    SecondaryTile secondaryTile = new SecondaryTile(vm.ProductDetails.Id);

                    //nb: should always return true as we checked with Exists()
                    if (secondaryTile != null)
                    {
                        bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Above);

                        vm.SetPinnedState(!isUnpinned);

                        if (isUnpinned)
                        {
                            MessageDialog dialog = new MessageDialog("Product " + vm.ProductDetails.Name + " successfully unpinned.");
                            await dialog.ShowAsync();
                        }
                        else
                        {
                            MessageDialog dialog = new MessageDialog("Product " + vm.ProductDetails.Name + " not unpinned.");
                            await dialog.ShowAsync();
                        }
                    }
                }
                else
                {
                    MessageDialog dialog = new MessageDialog("The tile for Product " + vm.ProductDetails.Name + " was not located.");
                    await dialog.ShowAsync();
                }
            }
            catch (Exception e)
            {
                MessageDialog dialog = new MessageDialog("There was an error unpinning this tile. \n\n Message : " + (e.Message ?? "(Error Details Unavailable)"), "Error Unpinning Tile");
                await dialog.ShowAsync();
            }
        }
Exemple #26
0
        async void pinToAppBar_Click(object sender, RoutedEventArgs e)
        {
            string selectedApp = selectedAppObject.ToString();

            SecondaryTileAppBar.IsSticky = true;
            if (SecondaryTile.Exists(selectedApp))
            {
                SecondaryTile secondaryTile = new SecondaryTile(selectedApp);
                bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);

                ToggleAppBarButton(isUnpinned);
            }
            else
            {
                Uri logo = Helpers.GetSnappedURI(Helpers.selectImage(selectedAppObject, true));
                string tileActivationArguments = selectedApp;

                SecondaryTile secondaryTile = new SecondaryTile(selectedApp,
                                                                App.Apps.UnitConverter.ToString() + " - " + selectedApp,
                                                                tileActivationArguments,
                                                                logo,
                                                                TileSize.Default
                                                                );

                secondaryTile.VisualElements.ForegroundText = ForegroundText.Dark;
                secondaryTile.VisualElements.Square44x44Logo = Helpers.GetSnappedURI(Helpers.selectImage(selectedAppObject, true));

                bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);

                ToggleAppBarButton(!isPinned);

                // uncheck the items in mainscape
                MainScape.UnselectCurrentItem();


            }
            SecondaryTileAppBar.IsSticky = false;
            SecondaryTileAppBar.IsOpen = false;
        }
        private async void ButtonPinReportClick(object sender, RoutedEventArgs e)
        {
            var item = itemsGrid.SelectedItem as StiReportData.StiReportItem;

            if (item == null)
            {
                return;
            }

            SecondaryTile secondaryTile;
            var           rect = StiGlobalHelper.GetElementRect(buttonPinReport);

            if (SecondaryTile.Exists(item.FileName))
            {
                secondaryTile = new SecondaryTile(item.FileName);
                await secondaryTile.RequestDeleteForSelectionAsync(rect, Windows.UI.Popups.Placement.Above);
            }
            else
            {
                var logo      = new Uri("ms-appx:///Assets/LogoSecondary.png");
                var smallLogo = new Uri("ms-appx:///Assets/SmallLogo.png");

                if (StiDemoReportsPage.NavigatorReportsType == ReportsType.Demo)
                {
                    secondaryTile = new SecondaryTile(item.FileName, item.FileName, item.FileName, item.FileName + ".mrt", TileOptions.ShowNameOnLogo, logo);
                }
                else
                {
                    secondaryTile = new SecondaryTile(item.FileName, item.Header, item.FileName, item.FileName + ".mdc", TileOptions.ShowNameOnLogo, logo);
                }

                secondaryTile.ForegroundText = ForegroundText.Dark;
                secondaryTile.SmallLogo      = smallLogo;
                await secondaryTile.RequestCreateForSelectionAsync(rect, Windows.UI.Popups.Placement.Above);
            }

            UpdateSecondaryTile(item.FileName);
        }
Exemple #28
0
        //Unpin all the live tiles
        async void btn_UnpinAllTiles_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            try
            {
                foreach (SecondaryTile SecondaryTile in await SecondaryTile.FindAllAsync())
                {
                    await SecondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Below);
                }

                btn_PinPlayPause.Content  = "Pin Play or Pause";
                btn_PinPrevious.Content   = "Pin Previous Item";
                btn_PinNext.Content       = "Pin Next Item";
                btn_PinVolUp.Content      = "Pin Volume Up";
                btn_PinVolDown.Content    = "Pin Volume Down";
                btn_PinVolMute.Content    = "Pin Volume Mute";
                btn_PinArrowLeft.Content  = "Pin Arrow Left";
                btn_PinArrowRight.Content = "Pin Arrow Right";
                btn_PinFullscreen.Content = "Pin Fullscreen";

                await new MessageDialog("All the remote tiles have been unpinned from your start screen.", App.vApplicationName).ShowAsync();
            }
            catch { }
        }
Exemple #29
0
        public async override void Execute(FrameworkElement parameter)
        {
            var parent = (FrameworkElement)parameter.Parent;

            while ((parent is AppBar) == false)
            {
                parent = (FrameworkElement)parent.Parent;
            }
            var appBar = (AppBar)parent;

            appBar.IsSticky = true;

            if (IsAlreadyPinned)
            {
                var secondaryTile = new SecondaryTile(AppbarTileId);
                var isUnpinned    = await secondaryTile.RequestDeleteForSelectionAsync(parameter.GetElementRect(), Windows.UI.Popups.Placement.Above);

                NotifyChanged(() => IsAlreadyPinned);
                NotifyChanged(() => IsNotAlreadyPinned);
            }
            else
            {
                var secondaryTile = new SecondaryTile(AppbarTileId,
                                                      TileTitle,
                                                      ActivationArguments,
                                                      TileMediumImageUri,
                                                      TileSize.Default);
                secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;

                if (TileSmallImageUri != null)
                {
                    secondaryTile.VisualElements.Square30x30Logo = TileSmallImageUri;
                }
                if (TileWideImageUri != null)
                {
                    secondaryTile.VisualElements.Wide310x150Logo           = TileWideImageUri;
                    secondaryTile.VisualElements.ShowNameOnWide310x150Logo = true;
                }
                if (TileLargeImageUri != null)
                {
                    // You'll get an exception from Windows if you specify a large logo without also specifying a wide one.
                    if (TileWideImageUri == null)
                    {
                        throw new InvalidOperationException("To support a large tile you must also support a wide tile");
                    }
                    secondaryTile.VisualElements.Square310x310Logo           = TileLargeImageUri;
                    secondaryTile.VisualElements.ShowNameOnSquare310x310Logo = true;
                }

                if (LockScreenBadgeLogoUri != null)
                {
                    secondaryTile.LockScreenBadgeLogo = LockScreenBadgeLogoUri;
                    secondaryTile.LockScreenDisplayBadgeAndTileText = LockScreenDisplayBadgeAndTileText;
                }

                bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(parameter.GetElementRect(), Windows.UI.Popups.Placement.Above);

                NotifyChanged(() => IsAlreadyPinned);
                NotifyChanged(() => IsNotAlreadyPinned);
            }
            appBar.IsSticky = false;
        }
        async void pinToAppBar_Click(object sender, RoutedEventArgs e)
        {
            rootPage.BottomAppBar.IsSticky = true;
            // Let us first verify if we need to pin or unpin
            if (SecondaryTile.Exists(MainPage.appbarTileId))
            {
                // First prepare the tile to be unpinned
                SecondaryTile secondaryTile = new SecondaryTile(MainPage.appbarTileId);

                // Now make the delete request.
                bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);

                if (isUnpinned)
                {
                    rootPage.NotifyUser(MainPage.appbarTileId + " unpinned.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser(MainPage.appbarTileId + " not unpinned.", NotifyType.ErrorMessage);
                }

                ToggleAppBarButton(isUnpinned);
            }
            else
            {
                // Prepare package images for the medium tile size in our tile to be pinned
                Uri square150x150Logo = new Uri("ms-appx:///Assets/square150x150Tile-sdk.png");

                // During creation of secondary tile, an application may set additional arguments on the tile that will be passed in during activation.
                // These arguments should be meaningful to the application. In this sample, we'll pass in the date and time the secondary tile was pinned.
                string tileActivationArguments = MainPage.appbarTileId + " WasPinnedAt=" + DateTime.Now.ToLocalTime().ToString();

                // Create a Secondary tile with all the required arguments.
                // Note the last argument specifies what size the Secondary tile should show up as by default in the Pin to start fly out.
                // It can be set to TileSize.Square150x150, TileSize.Wide310x150, or TileSize.Default.
                // If set to TileSize.Wide310x150, then the asset for the wide size must be supplied as well.
                // TileSize.Default will default to the wide size if a wide size is provided, and to the medium size otherwise.
                SecondaryTile secondaryTile = new SecondaryTile(MainPage.appbarTileId,
                                                                "Secondary tile pinned via AppBar",
                                                                tileActivationArguments,
                                                                square150x150Logo,
                                                                TileSize.Square150x150);

                // Whether or not the app name should be displayed on the tile can be controlled for each tile size.  The default is false.
                secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;

                // Specify a foreground text value.
                // The tile background color is inherited from the parent unless a separate value is specified.
                secondaryTile.VisualElements.ForegroundText = ForegroundText.Dark;

                // OK, the tile is created and we can now attempt to pin the tile.
                // Note that the status message is updated when the async operation to pin the tile completes.
                bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);

                if (isPinned)
                {
                    rootPage.NotifyUser(MainPage.appbarTileId + " successfully pinned.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser(MainPage.appbarTileId + " not pinned.", NotifyType.ErrorMessage);
                }

                ToggleAppBarButton(!isPinned);
            }
            rootPage.BottomAppBar.IsSticky = false;
        }