using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Diagnostics;
using System.ComponentModel;

namespace WPCustomPanFlickHold
{
    public partial class MainPage : PhoneApplicationPage
    {

        public string ActualGesture
        {
            get { return tBData.Text ; }
            set
            {
                tBData.Text = value;
            }
        }

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void rectangle_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            Debug.WriteLine("{0}:x={1}, y={2}\r\n", "ManipulationStarted - Position", e.ManipulationOrigin.X, e.ManipulationOrigin.Y);
            ActualGesture = "Hold-Geste";

        }

        private void rectangle_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            Debug.WriteLine("{0}:\t x={1}, y={2}", "ManipulationDelta - Position", e.ManipulationOrigin.X, e.ManipulationOrigin.Y);
            Debug.WriteLine("{0}:\t x={1}, y={2}", "ManipulationDelta - Cumulative", e.CumulativeManipulation.Translation.X, e.CumulativeManipulation.Translation.Y);
            Debug.WriteLine("{0}:\t x={1}, y={2}\r\n", "ManipulationDelta - Delta", e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);

            if (e.IsInertial)
            {
                ActualGesture = "Flick-Geste";
                return;                
            }

            var translation = e.DeltaManipulation.Translation;
            if (ActualGesture.Contains("Hold-Geste"))
            {
                ActualGesture = "Drag-Geste";
            }
        }

        private void rectangle_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            Debug.WriteLine("{0}:x={1}, y={2}", "ManipulationCompleted - Position", e.ManipulationOrigin.X, e.ManipulationOrigin.Y);
            Debug.WriteLine("{0}:x={1}, y={2}\r\n", "ManipulationCompleted - TotalManipulation", e.TotalManipulation.Translation.X, e.TotalManipulation.Translation.Y);
            //Velocity

            if (e.IsInertial)
            {
                ActualGesture = "Flick-Geste";
            }
            else
            {
                ActualGesture = "Keine Geste";
            }

        }
    }
}
