Exemple #1
0
        /// <summary>
        /// Finishes the manipulation.
        /// </summary>
        /// <param name="svi">The ItemProxy.</param>
        private void FinishManipulation(ScatterViewItem svi)
        {
            RiverItemState state = GetState(svi);
            if (state == null)
            {
                return;
            }

            if (state.RemovedSize == Size.Empty)
            {
                RiverItemBase riverItem = svi.FindVisualChild<RiverItemBase>();
                if (riverItem != null)
                {
                    state.AnimateToRemovedSizeBeginTime = DateTime.Now;
                    state.IsAnimatingToRemovedSize = true;
                    Thickness padding = Plane.GetPlaneFrontPadding(svi);
                    RiverSize riverSize = riverItem.Removed();
                    state.RemovedSize = riverSize.RemovedSize;
                    state.MinSize = riverSize.MinSize;
                    svi.MaxWidth = riverSize.MaxSize.Width + padding.Left + padding.Right;
                    svi.MaxHeight = riverSize.MaxSize.Height + padding.Top + padding.Bottom;
                    Audio.Instance.PlayCue("streamItem_tapRelease");
                }
            }

            if (!svi.AreAnyTouchesCapturedWithin)
            {
                BeginIdleTimeout(svi);
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns an SVI to the river.
        /// </summary>
        /// <param name="svi">The ItemProxy.</param>
        private void ReturnItemProxyToRiver(ScatterViewItem svi)
        {
            RiverItemState state = GetState(svi);
            if (state == null)
            {
                return;
            }

            CancelIdleTimeout(svi);

            if (!state.IsRemovedFromRiver)
            {
                return;
            }

            Audio.Instance.PlayCue("streamItem_close");
            svi.CanScale = false;
            svi.MinHeight = GridCellSize.Height;
            svi.MinWidth = GridCellSize.Width;
            state.IsAnimatingBackToRiver = true;
            state.Svi.IsHitTestVisible = false;
            state.IsAnimatingToRemovedSize = false;
            state.IsAnimatingToContactOrientation = false;
            state.AnimateBackBeginTime = DateTime.Now;
            state.ReturnHorizontalOffset = _cumulativeScrollChange;
            ScatterFlip.SetIsFlipped(svi, false);

            RiverItemBase riverItem = svi.FindVisualChild<RiverItemBase>();
            if (riverItem != null)
            {
                riverItem.Added();
            }
        }
Exemple #3
0
        /// <summary>
        /// Handles the PreviewContactDown event of the ItemProxy control.
        /// If a ItemProxy can't move, block the contact so that a manipulation doesn't begin. Otherwise, create an SVI from the proxy.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.TouchEventArgs"/> instance containing the event data.</param>
        private void ItemProxy_PreviewTouchDown(object sender, TouchEventArgs e)
        {
            ItemProxy proxy = sender as ItemProxy;
            RiverItemState state = GetState(proxy);

            if (!proxy.CanMove || state.IsAnimatingToContactOrientation || state.IsAnimatingToRemovedSize || state.IsAnimatingBackToRiver)
            {
                e.Handled = true;
                return;
            }

            if ((e.OriginalSource as FrameworkElement).FindVisualParent<Button>() != null)
            {
                // Ignore if an admin button is pressed.
                return;
            }

            // Create the SVI and set its position and orientation.
            ScatterViewItem svi = new ScatterViewItem();
            _scatterView.Items.Add(svi);
            state.Svi = svi;
            svi.Style = state.ItemStyle;
            svi.MinHeight = proxy.MinHeight;
            svi.MinWidth = proxy.MinWidth;
            svi.Center = proxy.Center;
            svi.Orientation = proxy.Orientation;
            svi.CanScale = false;
            svi.CanRotate = false;

            // Set the SVI size.
            bool isPortrait = state.RowSpan > state.ColumnSpan;
            double itemWidth = state.ColumnSpan * GridCellSize.Width;
            double itemHeight = state.RowSpan * GridCellSize.Height;
            itemWidth += Plane.GetPlaneFrontPadding(svi).Left + Plane.GetPlaneFrontPadding(svi).Right;
            itemHeight += Plane.GetPlaneFrontPadding(svi).Top + Plane.GetPlaneFrontPadding(svi).Bottom;
            svi.Width = isPortrait ? itemHeight : itemWidth;
            svi.Height = isPortrait ? itemWidth : itemHeight;

            // Hook events.
            svi.ContainerActivated += ScatterViewItem_Activated;
            svi.ContainerManipulationDelta += ScatterViewItem_ScatterManipulationDelta;
            svi.ContainerDeactivated += ScatterViewItem_Deactivated;
            svi.ContainerManipulationCompleted += ScatterViewItem_ScatterManipulationCompleted;
            TouchChangedEvents.AddAreAnyTouchesCapturedWithinChangedHandler(svi, new RoutedEventHandler(ScatterViewItem_AreAnyTouchesCapturedWithinChanged));
            svi.AddHandler(RiverItemBase.FlipRequestedEvent, new RiverItemBase.SourceRoutedEventHandler(ScatterViewItem_FlipRequested));
            svi.AddHandler(RiverItemBase.CloseRequestedEvent, new RiverItemBase.SourceRoutedEventHandler(ScatterViewItem_CloseRequested));

            svi.Unloaded += (a, b) =>
            {
                // Unhook events on unload.
                svi.ContainerActivated -= ScatterViewItem_Activated;
                svi.ContainerManipulationDelta -= ScatterViewItem_ScatterManipulationDelta;
                svi.ContainerDeactivated -= ScatterViewItem_Deactivated;
                svi.ContainerManipulationCompleted -= ScatterViewItem_ScatterManipulationCompleted;
                TouchChangedEvents.RemoveAreAnyTouchesCapturedWithinChangedHandler(svi, new RoutedEventHandler(ScatterViewItem_AreAnyTouchesCapturedWithinChanged));
                svi.RemoveHandler(RiverItemBase.FlipRequestedEvent, new RiverItemBase.SourceRoutedEventHandler(ScatterViewItem_FlipRequested));
                svi.RemoveHandler(RiverItemBase.CloseRequestedEvent, new RiverItemBase.SourceRoutedEventHandler(ScatterViewItem_CloseRequested));
            };

            svi.Loaded += (a, b) =>
            {
                // Populate with data when loaded.
                RiverItemBase proxyItem = proxy.FindVisualChild<RiverItemBase>();
                RiverItemBase sviItem = svi.FindVisualChild<RiverItemBase>();
                sviItem.RenderData(state, proxyItem.DataContext);
                proxy.Visibility = Visibility.Hidden;
            };

            // Steal the touch from the proxy.
            svi.UpdateLayout();
            svi.CaptureTouch(e.TouchDevice);
        }