void OnAction(BaseGestureRecognizer recognizer, GestureRecognizerState state)
 {
     var panRecognizer = recognizer as PanGestureRecognizer;
     var view = recognizer.View;
     if (state == GestureRecognizerState.Began) {
         _startBounds = recognizer.View.Bounds;
         Debug.WriteLine ("START " + _startBounds);
     }
     if (state == GestureRecognizerState.Changed) {
         var message = "PAN " + recognizer + "\n";
         message += "POS: " + recognizer.LocationInView (view.ParentView);
         var translation = panRecognizer.GetTranslationInView (view.ParentView);
     //			message += "touches: " + recognizer.NumberOfTouches + ", velocity: " + velocity;
         message += ", translation: " + translation;
         var bounds = new Rectangle (view.X + translation.X, view.Y + translation.Y, view.Width, view.Height);
         message += ", vb: " + bounds;
         _startBounds.X += translation.X;
         _startBounds.Y += translation.Y;
         Debug.WriteLine ("MOVE " + bounds);
         Device.BeginInvokeOnMainThread (() => {
             Label2.Layout (bounds);
         });
         OutputLabel.Text = message;
     }
 }
		void Gesture_OnAction (BaseGestureRecognizer recgonizer, GestureRecognizerState state)
		{
			var panGesture = recgonizer as PanGestureRecognizer;
			Point translation = panGesture.GetTranslationInView (MainLayout);
			Point velocity = panGesture.GetVelocityInView (MainLayout);
			panGesture.SetTranslationInView (new Point (0, 0), MainLayout);


			Debug.WriteLine ("GESTURE STATE " + state + " trans " + translation);
			switch (panGesture.State) {
			case GestureRecognizerState.Began:
				break;
			case GestureRecognizerState.Changed:
				if (recgonizer.View == ForegroundContent) {
					_contentBounds.X += translation.X;
					_contentBounds.Y = 0;
					ForegroundContent.Layout (_contentBounds);
				}
				break;
			case GestureRecognizerState.Cancelled:
			case GestureRecognizerState.Ended:
			case GestureRecognizerState.Failed:
				_contentBounds.X = (_contentBounds.X > -(MainLayout.Width / 4)) ? 0 : -(MainLayout.Width / 2);
				ForegroundContent.LayoutTo (_contentBounds);
				break;
			case GestureRecognizerState.Possible:
			default:
				break;
			}
		}
		void OnAction (BaseGestureRecognizer recognizer, GestureRecognizerState state)
		{
			var swipeRecognizer = recognizer as SwipeGestureRecognizer;
			var view = recognizer.View;
			var message = "SWIPE " + recognizer + "\n";
			message += "POS: " + recognizer.LocationInView (view.ParentView);
			message += "touches: " + recognizer.NumberOfTouches + ", direction: " + swipeRecognizer.Direction;
			OutputLabel.Text = message;
		}
		void OnAction (BaseGestureRecognizer recognizer, GestureRecognizerState state)
		{
			var tapRecognizer = recognizer as TwinTechs.Gestures.TapGestureRecognizer;
			var view = recognizer.View;
			var message = string.Format ("POS: {0} \n", recognizer.LocationInView (view).PrettyPrint ());
			message += string.Format ("PARENT POS: {0} \n", recognizer.LocationInView (view.ParentView).PrettyPrint ());
			message += string.Format ("PARENT.PARENT POS: {0} \n", recognizer.LocationInView (view.ParentView.ParentView).PrettyPrint ());
			message += string.Format ("PAGE POS: {0} \n", recognizer.LocationInView (this).PrettyPrint ());
			OutputLabel.Text = message;
		}
		void OnAction (BaseGestureRecognizer recognizer, GestureRecognizerState state)
		{
			var tapRecognizer = recognizer as TwinTechs.Gestures.LongPressGestureRecognizer;
			var view = recognizer.View;
			var message = recognizer + "\n";
			message += "POS: " + recognizer.LocationInView (view);
			message += "PARENT POS: " + recognizer.LocationInView (view.ParentView);
			message += "touches: " + recognizer.NumberOfTouches;// + ", taps required: " + tapRecognizer.NumberOfTapsRequired;
			OutputLabel.Text = message;
		}
		void OnAction (BaseGestureRecognizer recognizer, GestureRecognizerState state)
		{
			var panRecognizer = recognizer as PanGestureRecognizer;
			var view = recognizer.View;
			var message = "PAN " + recognizer + "\n";
			message += "ParentPOS: " + recognizer.LocationInView (view.ParentView);
			message += "POS: " + recognizer.LocationInView (view);
			var translation = panRecognizer.GetTranslationInView (view.ParentView);
			var velocity = panRecognizer.GetVelocityInView (view.ParentView);
			message += ", translation: " + translation;
			var bounds = new Rectangle (view.X + velocity.X, view.Y + velocity.Y, view.Width, view.Height);
			message += ", vb: " + bounds;
			OutputLabel.Text = message;
		}
		void Gesture_OnAction (BaseGestureRecognizer recgonizer, GestureRecognizerState state)
		{
			if (recgonizer.View != MediaItemsListView) {
				return;
			}
			var panGesture = recgonizer as PanGestureRecognizer;
			Point translation = panGesture.GetTranslationInView (MainLayout);
			Point velocity = panGesture.GetVelocityInView (MainLayout);
			panGesture.SetTranslationInView (new Point (0, 0), MainLayout);
			switch (panGesture.State) {
			case GestureRecognizerState.Began:
//				MediaItemsListView.IsEnabled = false;
				break;
			case GestureRecognizerState.Changed:
				var newY = _currentGridY + translation.Y;
				newY = Math.Max (0, newY);
				newY = Math.Min (400, newY);
				Debug.WriteLine ("newY {0} _currentGridY {1} _scrollPosition{2}", newY, _currentGridY, _scrollPosition);
				bool willMoveList = false;
				if (newY != _currentGridY) {
					willMoveList = _currentGridY > 0 || _scrollPosition <= 0 &&
					newY > 0 && newY < Height - 100;
					
					if (willMoveList) {
						_currentGridY = newY;
						var bounds = MediaItemsListView.Bounds;
						bounds.Y = _currentGridY;
						MediaItemsListView.Layout (bounds);
					}
					MediaItemsListView.IsScrollEnabled = !willMoveList;
				} else {
					MediaItemsListView.IsScrollEnabled = true;
					Debug.WriteLine ("no move " + MediaItemsListView.IsScrollEnabled);
				}
				break;
			case GestureRecognizerState.Cancelled:
			case GestureRecognizerState.Ended:
			case GestureRecognizerState.Failed:
				MediaItemsListView.IsScrollEnabled = true;
				if (_currentGridY != 0 && _currentGridY != 400) {
					_currentGridY = _currentGridY > 200 ? 400 : 0;
					MediaItemsListView.LayoutTo (new Rectangle (0, _currentGridY, Width, Height));
				}
				break;
			default:
				break;
			}
		}
		void Gesture_OnAction (BaseGestureRecognizer recgonizer, GestureRecognizerState state)
		{
			string message = "";
			var panGesture = recgonizer as PanGestureRecognizer;
			Point translation = panGesture.GetTranslationInView (MainLayout);
			Point velocity = panGesture.GetVelocityInView (MainLayout);
			panGesture.SetTranslationInView (new Point (0, 0), MainLayout);

			//			MyLabel.Text = "PAN " + recognizer.LocationInView (view.ParentView);
			//			Debug.WriteLine ("PAN " + panGesture);
			//			Debug.WriteLine ("location " + panGesture.LocationInView (this));

			switch (panGesture.State) {
			case GestureRecognizerState.Began:
				message += "BEGAN ";
				message += "POS: " + recgonizer.LocationInView (MainLayout);
				break;
			case GestureRecognizerState.Changed:
				message += "CHANGED ";
				message += ", translation: " + translation;
				message += ", velocity: " + velocity;
				message += "POS: \n" + recgonizer.LocationInView (panGesture.View).PrettyPrint ();
				message += "PARENT POS: \n" + recgonizer.LocationInView (MainLayout).PrettyPrint ();
				if (recgonizer.View == Box) {
					message += ", MOVING VIEW";
					_boxBounds.X += translation.X;
					_boxBounds.Y += translation.Y;
					Box.Layout (_boxBounds);
				}
				break;
			case GestureRecognizerState.Cancelled:
			case GestureRecognizerState.Ended:
			case GestureRecognizerState.Failed:
				message += "FINISHED ";
				break;
			case GestureRecognizerState.Possible:
			default:
				break;
			}
			OutputLabel.Text = message;
		}
		void Gesture_OnAction (BaseGestureRecognizer recgonizer, GestureRecognizerState state)
		{
			if (recgonizer.View != _contentPage.VideoPlayerView) {
				return;
			}
			var panGesture = recgonizer as PanGestureRecognizer;
			Point translation = panGesture.GetTranslationInView (MainLayout);
			Point velocity = panGesture.GetVelocityInView (MainLayout);
			panGesture.SetTranslationInView (new Point (0, 0), MainLayout);
			switch (panGesture.State) {
			case GestureRecognizerState.Began:
				break;
			case GestureRecognizerState.Changed:
				var newY = _contentBounds.Y + translation.Y;
				if (newY > 0 && newY < Height - _contentPage.MinimumHeightRequest) {
					var minHeight = _contentPage.MinimumHeightRequest;
					var minWidth = _contentPage.MinimumWidthRequest;
					_contentBounds.Y = newY;
					var complete = Math.Min (1, (Height - (_contentBounds.Y + minHeight)) / Height);
//					Debug.WriteLine ("complete {0} newY {1} h{2}", complete, newY, Height);
					var inverseCompletion = 1 - complete;
					_contentBounds.X = (Width - minWidth) * inverseCompletion;
					_contentBounds.Width = (minWidth) + ((Width - minWidth) * complete);
					_contentBounds.Height = Math.Max (minHeight, (Height + minHeight) * complete);
					PageContainer.Layout (_contentBounds);
				}
				break;
			case GestureRecognizerState.Cancelled:
			case GestureRecognizerState.Ended:
			case GestureRecognizerState.Failed:
				var isShowing = _contentBounds.Y < 200;
				ToggleShowing (isShowing, true);
				break;
			default:
				break;
			}
		}
		bool GetIsFinishedState (GestureRecognizerState state)
		{
			return state == GestureRecognizerState.Ended || state == GestureRecognizerState.Cancelled || state == GestureRecognizerState.Recognized ||
			state == GestureRecognizerState.Failed;
		}
		void Gesture_OnAction (BaseGestureRecognizer recgonizer, GestureRecognizerState state)
		{
			var panGesture = recgonizer as PanGestureRecognizer;
			Point translation = panGesture.GetTranslationInView (this);
			panGesture.SetTranslationInView (new Point (0, 0), this);

			//			MyLabel.Text = "PAN " + recognizer.LocationInView (view.ParentView);
//			Debug.WriteLine ("PAN " + panGesture);
//			Debug.WriteLine ("location " + panGesture.LocationInView (this));

			switch (panGesture.State) {
			case GestureRecognizerState.Began:
				break;
			case GestureRecognizerState.Changed:
				double newPosition = _contentView.X + translation.X;
				var endWidth = _contentWidth;
				Debug.WriteLine ("new pos " + newPosition + " endWidth " + endWidth);
				if (newPosition >= ((-endWidth) - (Width / 2)) && (newPosition <= (Width / 2))) {
					_contentView.Layout (GetBoundsWithX (newPosition));
				}
				break;
			case GestureRecognizerState.Cancelled:
			case GestureRecognizerState.Ended:
			case GestureRecognizerState.Failed:
				//scroll to page location, set index
				double currentPage = (-_contentView.X) / Width;
				Boolean isBehindHalfScreen = (currentPage - (int)currentPage) > 0.5;

				if (isBehindHalfScreen && (currentPage + 1) < NumberOfPages) {
					CurrentPageIndex = (int)(currentPage + 1);
				} else {
					CurrentPageIndex = (int)currentPage;
				}

				AnimateToPageIndex (CurrentPageIndex);
				break;
			case GestureRecognizerState.Possible:
			default:
				break;
			}
		}
Exemplo n.º 12
0
 protected override void didStopTrackingLastPointer(int pointer)
 {
     this._stopTimer();
     this.state = GestureRecognizerState.ready;
 }
		bool GetIsConsumedState (GestureRecognizerState state)
		{
			return state == GestureRecognizerState.Ended || state == GestureRecognizerState.Began ||
			state == GestureRecognizerState.Recognized || state == GestureRecognizerState.Changed;
		}