Exemple #1
0
        private static bool CancelPlay(bool manualActivatePage)
        {
            lock (typeof(YouTube))
            {
                if (_oldState == null && _cancellationToken == null)
                {
                    return(false);
                }

                if (_cancellationToken != null)
                {
                    _cancellationToken.Cancel();
                    _cancellationToken.Dispose();
                    _cancellationToken = null;
                }

                if (!manualActivatePage && _oldState != null)
                {
                    _oldState.Revert();
                    SystemTray.ProgressIndicator.IsVisible = false;
                    _oldState = null;
                }

                return(true);
            }
        }
		/// <summary>
		/// This method disables the current page and shows a progress indicator until the youtube movie url has been loaded and starts
		/// </summary>
		/// <param name="youTubeId"></param>
		/// <param name="manualActivatePage">if true add YouTube.CancelPlay() in OnNavigatedTo() of the page (better)</param>
		/// <param name="maxQuality"></param>
		/// <param name="completed"></param>
		public static void Play(string youTubeId, bool manualActivatePage, YouTubeQuality maxQuality = YouTubeQuality.Quality480P, Action<Exception> completed = null)
		{
			lock (typeof(YouTube))
			{
				if (oldState != null)
					return;

				if (SystemTray.ProgressIndicator == null)
					SystemTray.ProgressIndicator = new ProgressIndicator();

				SystemTray.ProgressIndicator.IsVisible = true;
				SystemTray.ProgressIndicator.IsIndeterminate = true; 

				var page = PhonePage.CurrentPage;
				oldState = PageDeactivator.Inactivate();
				httpResponse = Play(youTubeId, YouTubeQuality.Quality480P, ex => Deployment.Current.Dispatcher.BeginInvoke(
					delegate
					{
						if (page == PhonePage.CurrentPage) // !user navigated away
						{
							if (ex == null)
								CancelPlay(manualActivatePage);
							else
								CancelPlay(false);
						}

						if (completed != null)
							completed(ex);
					}));
			}
		}
Exemple #3
0
        private static bool CancelPlay(bool manualActivate)
        {
            lock (typeof(YouTube))
            {
                if (oldState == null && httpResponse == null)
                {
                    return(false);
                }

                if (httpResponse != null)
                {
                    httpResponse.Abort();
                    httpResponse = null;
                }

                if (!manualActivate && oldState != null)
                {
                    oldState.Revert();
                    SystemTray.ProgressIndicator.IsVisible = false;
                    oldState = null;
                }

                return(true);
            }
        }
Exemple #4
0
        /// <summary>Plays the YouTube video in the Windows Phone's external player.
        /// Disables the current page and shows a progress indicator until
        /// the YouTube movie URI has been loaded and the video playback starts. </summary>
        /// <param name="youTubeId">The YouTube ID</param>
        /// <param name="manualActivatePage">if true add YouTube.CancelPlay() in OnNavigatedTo() of the page (better)</param>
        /// <param name="maxQuality">The maximum allowed video quality. </param>
        /// <returns>Awaitable task. </returns>
        public static async Task PlayWithPageDeactivationAsync(string youTubeId, bool manualActivatePage, YouTubeQuality maxQuality)
        {
            PhoneApplicationPage page;

            lock (typeof(YouTube))
            {
                if (_oldState != null)
                {
                    return;
                }

                if (SystemTray.ProgressIndicator == null)
                {
                    SystemTray.ProgressIndicator = new ProgressIndicator();
                }

                SystemTray.ProgressIndicator.IsVisible       = true;
                SystemTray.ProgressIndicator.IsIndeterminate = true;

                page = Environment.PhoneApplication.CurrentPage;

                _oldState          = PageDeactivator.Inactivate();
                _cancellationToken = new CancellationTokenSource();
            }

            try
            {
                await PlayAsync(youTubeId, maxQuality, _cancellationToken.Token);

                if (page == Environment.PhoneApplication.CurrentPage)
                {
                    CancelPlay(manualActivatePage);
                }
            }
            catch (Exception)
            {
                if (page == Environment.PhoneApplication.CurrentPage)
                {
                    CancelPlay(false);
                }
                throw;
            }
        }
Exemple #5
0
		public static Popup Show(PopupControl control, bool hideApplicationBar, bool showFullScreen, Action<PopupControl> completed)
		{
			if (popupStack == null)
				popupStack = new Stack<PopupControl>();

			var oldState = new PageDeactivator();
			var page = PhoneApplication.CurrentPage;

			var heightSub = 0.0;
			if (hideApplicationBar && page.ApplicationBar != null && page.ApplicationBar.IsVisible)
			{
				page.ApplicationBar.IsVisible = false;
				heightSub = page.ApplicationBar.Mode == ApplicationBarMode.Minimized
					? page.ApplicationBar.MiniSize
					: page.ApplicationBar.DefaultSize;
			}
			else
				hideApplicationBar = false;

			var content = page.Content;
			content.IsHitTestVisible = false;

			var popup = new Popup
			{
				Child = control,
				HorizontalAlignment = HorizontalAlignment.Stretch,
				VerticalAlignment = VerticalAlignment.Stretch
			};

			control.Popup = popup;

			if (SystemTray.IsVisible && !(SystemTray.Opacity < 1.0))
				heightSub += 32; 

			// set popup size
			if (showFullScreen)
				popup.Height = page.ActualHeight + heightSub;
			popup.Width = page.ActualWidth;

			// set control size
			if (showFullScreen)
				control.Height = page.ActualHeight + heightSub;
			control.Width = page.ActualWidth;

			// hide underlying page
			if (showFullScreen && content.Visibility == Visibility.Visible)
				content.Visibility = Visibility.Collapsed;
			else
				showFullScreen = false; 

			// deactivate page
            var color = ColorUtilities.RemoveAlpha(
                PhoneApplication.IsDarkTheme ? ColorUtilities.FromHex("#22FFFFFF") :
                ColorUtilities.FromHex("#DDFFFFFF"), Colors.Black);
			var oldColor = SystemTray.BackgroundColor;

			control.SetBackgroundColor(color);
			oldState.DoIt(false);

			// register back key event
			object handlerObject = null; 
			if (page is ExtendedPage)
			{
				handlerObject = ((ExtendedPage)page).AddBackKeyPressHandler(args =>
				{
					if (popupStack.Peek() == control)
					{
						args.Cancel = true;
						control.GoBack();
					}
				});
			}
			else
			{
				var handler = new EventHandler<CancelEventArgs>((sender, args) =>
				{
					if (popupStack.Peek() == control)
					{
						args.Cancel = true;
						control.GoBack();
					}
				});
				page.BackKeyPress += handler;
				handlerObject = handler;
			}

			SystemTray.BackgroundColor = color;

			popup.IsOpen = true;

			// hide underlying popups
			foreach (var p in popupStack)
				p.Visibility = Visibility.Collapsed;
			popupStack.Push(control);

			control.Closed += delegate
			{
				if (showFullScreen)
					content.Visibility = Visibility.Visible;

				if (hideApplicationBar && page.ApplicationBar != null)
					page.ApplicationBar.IsVisible = true;

				content.IsHitTestVisible = true;

				popup.IsOpen = false;

				popupStack.Pop();
				if (popupStack.Count > 0)
					popupStack.Peek().Visibility = Visibility.Visible; 

				oldState.Revert();

				if (page is ExtendedPage)
					((ExtendedPage)page).RemoveBackKeyPressAsyncHandler((Func<CancelEventArgs, Task>) handlerObject);
				else
					page.BackKeyPress -= (EventHandler<CancelEventArgs>)handlerObject;
				
				SystemTray.BackgroundColor = oldColor;
				if (completed != null)
					completed(control);
			};

			return popup;
		}
		public static Popup Show(PopupControl control, bool hideApplicationBar, bool showFullScreen, Action<PopupControl> completed)
		{
			var oldState = new PageDeactivator();
			var page = PhonePage.CurrentPage;

			var heightSub = 0.0;
			if (hideApplicationBar && page.ApplicationBar.IsVisible)
			{
				page.ApplicationBar.IsVisible = false;
				heightSub = page.ApplicationBar.Mode == ApplicationBarMode.Minimized
								? page.ApplicationBar.MiniSize
								: page.ApplicationBar.DefaultSize;
			}
			else
				hideApplicationBar = false;

			var content = page.Content;
			content.IsHitTestVisible = false;

			if (showFullScreen && content.Visibility == Visibility.Visible)
				content.Visibility = Visibility.Collapsed;
			else
				showFullScreen = false; 

			var popup = new Popup
			{
				Child = control,
				HorizontalAlignment = HorizontalAlignment.Stretch,
				VerticalAlignment = VerticalAlignment.Stretch
			};

			control.Popup = popup;

			if (showFullScreen)
				popup.Height = page.ActualHeight + heightSub;
			popup.Width = page.ActualWidth;

			if (showFullScreen)
				control.Height = page.ActualHeight + heightSub;
			control.Width = page.ActualWidth;

			var color = ColorUtility.RemoveAlpha(
				PhoneApplication.IsDarkTheme ? ColorUtility.FromHex("#22FFFFFF") :
				ColorUtility.FromHex("#DDFFFFFF"), Colors.Black);

			var oldColor = SystemTray.BackgroundColor;

			control.SetBackgroundColor(color);
			oldState.DoIt(false);

			var del = new EventHandler<CancelEventArgs>(delegate(object sender, CancelEventArgs args)
			{
				args.Cancel = true;
				control.GoBack();
			});
			page.BackKeyPress += del;

			SystemTray.BackgroundColor = color;

			popup.IsOpen = true;
			control.Closed += delegate
			{
				if (showFullScreen)
					content.Visibility = Visibility.Visible;

				if (hideApplicationBar)
					page.ApplicationBar.IsVisible = true;

				content.IsHitTestVisible = true;

				popup.IsOpen = false;
				oldState.Revert();

				page.BackKeyPress -= del;
				SystemTray.BackgroundColor = oldColor;

				if (completed != null)
					completed(control);
			};

			return popup;
		}
Exemple #7
0
        public static Popup Show(PopupControl control, bool hideApplicationBar, bool showFullScreen, Action <PopupControl> completed)
        {
            if (popupStack == null)
            {
                popupStack = new Stack <PopupControl>();
            }

            var oldState = new PageDeactivator();
            var page     = PhoneApplication.CurrentPage;

            var heightSub = 0.0;

            if (hideApplicationBar && page.ApplicationBar != null && page.ApplicationBar.IsVisible)
            {
                page.ApplicationBar.IsVisible = false;
                heightSub = page.ApplicationBar.Mode == ApplicationBarMode.Minimized
                                        ? page.ApplicationBar.MiniSize
                                        : page.ApplicationBar.DefaultSize;
            }
            else
            {
                hideApplicationBar = false;
            }

            var content = page.Content;

            content.IsHitTestVisible = false;

            var popup = new Popup
            {
                Child = control,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            control.Popup = popup;

            if (SystemTray.IsVisible && !(SystemTray.Opacity < 1.0))
            {
                heightSub += 32;
            }

            // set popup size
            if (showFullScreen)
            {
                popup.Height = page.ActualHeight + heightSub;
            }
            popup.Width = page.ActualWidth;

            // set control size
            if (showFullScreen)
            {
                control.Height = page.ActualHeight + heightSub;
            }
            control.Width = page.ActualWidth;

            // hide underlying page
            if (showFullScreen && content.Visibility == Visibility.Visible)
            {
                content.Visibility = Visibility.Collapsed;
            }
            else
            {
                showFullScreen = false;
            }

            // deactivate page
            var color = ColorUtilities.RemoveAlpha(
                PhoneApplication.IsDarkTheme ? ColorUtilities.FromHex("#22FFFFFF") :
                ColorUtilities.FromHex("#DDFFFFFF"), Colors.Black);
            var oldColor = SystemTray.BackgroundColor;

            control.SetBackgroundColor(color);
            oldState.DoIt(false);

            // register back key event
            object handlerObject = null;

            if (page is ExtendedPage)
            {
                handlerObject = ((ExtendedPage)page).AddBackKeyPressHandler(args =>
                {
                    if (popupStack.Peek() == control)
                    {
                        args.Cancel = true;
                        control.GoBack();
                    }
                });
            }
            else
            {
                var handler = new EventHandler <CancelEventArgs>((sender, args) =>
                {
                    if (popupStack.Peek() == control)
                    {
                        args.Cancel = true;
                        control.GoBack();
                    }
                });
                page.BackKeyPress += handler;
                handlerObject      = handler;
            }

            SystemTray.BackgroundColor = color;

            popup.IsOpen = true;

            // hide underlying popups
            foreach (var p in popupStack)
            {
                p.Visibility = Visibility.Collapsed;
            }
            popupStack.Push(control);

            control.Closed += delegate
            {
                if (showFullScreen)
                {
                    content.Visibility = Visibility.Visible;
                }

                if (hideApplicationBar && page.ApplicationBar != null)
                {
                    page.ApplicationBar.IsVisible = true;
                }

                content.IsHitTestVisible = true;

                popup.IsOpen = false;

                popupStack.Pop();
                if (popupStack.Count > 0)
                {
                    popupStack.Peek().Visibility = Visibility.Visible;
                }

                oldState.Revert();

                if (page is ExtendedPage)
                {
                    ((ExtendedPage)page).RemoveBackKeyPressAsyncHandler((Func <CancelEventArgs, Task>)handlerObject);
                }
                else
                {
                    page.BackKeyPress -= (EventHandler <CancelEventArgs>)handlerObject;
                }

                SystemTray.BackgroundColor = oldColor;
                if (completed != null)
                {
                    completed(control);
                }
            };

            return(popup);
        }