Example #1
0
        public RenderEditable(TextSpan text, TextDirection textDirection, ViewportOffset offset,
                              ValueNotifier <bool> showCursor,
                              TextAlign textAlign                = TextAlign.left, double textScaleFactor = 1.0, Color cursorColor = null,
                              bool?hasFocus                      = null, int?maxLines = 1, Color selectionColor = null,
                              TextSelection selection            = null, bool obscureText = false, SelectionChangedHandler onSelectionChanged = null,
                              CaretChangedHandler onCaretChanged = null, bool ignorePointer = false)
        {
            this._textPainter = new TextPainter(text: text, textAlign: textAlign, textDirection: textDirection,
                                                textScaleFactor: textScaleFactor);
            this._cursorColor       = cursorColor;
            this._showCursor        = showCursor ?? new ValueNotifier <bool>(false);
            this._hasFocus          = hasFocus ?? false;
            this._maxLines          = maxLines;
            this._selectionColor    = selectionColor;
            this._selection         = selection;
            this._obscureText       = obscureText;
            this._offset            = offset;
            this.ignorePointer      = ignorePointer;
            this.onCaretChanged     = onCaretChanged;
            this.onSelectionChanged = onSelectionChanged;

            D.assert(this._maxLines == null || this._maxLines > 0);
            D.assert(this._showCursor != null);
            D.assert(!this._showCursor.value || cursorColor != null);

            this._tap                   = new TapGestureRecognizer(this);
            this._doubleTap             = new DoubleTapGestureRecognizer(this);
            this._tap.onTapDown         = this._handleTapDown;
            this._tap.onTap             = this._handleTap;
            this._doubleTap.onDoubleTap = this._handleDoubleTap;
            this._longPress             = new LongPressGestureRecognizer(debugOwner: this);
            this._longPress.onLongPress = this._handleLongPress;
        }
Example #2
0
 private void CreateLongPressGesture()
 {
     longPressGesture = new LongPressGestureRecognizer();
     longPressGesture.MaximumNumberOfTouchesToTrack = 1;
     longPressGesture.StateUpdated += LongPressGestureCallback;
     FingersScript.Instance.AddGesture(longPressGesture);
 }
Example #3
0
    private void Start()
    {
        _camera         = Camera.main;
        _particleSystem = GetComponent <ParticleSystem>();
        _animator       = new MultiAnimator(modelMasked.GetComponentInChildren <Animator>(),
                                            modelUnmasked.GetComponentInChildren <Animator>());
        _boxCollider = GetComponent <BoxCollider>();
        _rigidbody   = GetComponent <Rigidbody>();

        _shoppingCart = GetComponentInChildren <ShoppingCart>();

        _cameraOffset = _camera.transform.position - transform.position;

        _fingersScript = GetComponent <FingersScript>();

        _tapRecognizer = new TapGestureRecognizer();
        _tapRecognizer.NumberOfTapsRequired = 1;
        _tapRecognizer.StateUpdated        += Controls.OnTap;

        _longPressGestureRecognizer = new LongPressGestureRecognizer();
        _longPressGestureRecognizer.MinimumDurationSeconds = 0.1f;
        _longPressGestureRecognizer.StateUpdated          += Controls.OnLongPress;

        _fingersScript.AddGesture(_tapRecognizer);
        _fingersScript.AddGesture(_longPressGestureRecognizer);

        _fingersScript.TreatMousePointerAsFinger = !Input.touchSupported;
    }
Example #4
0
    void CreateLongPressGesture()
    {
        LongPressGestureRecognizer tap = new LongPressGestureRecognizer();

        tap.MinimumDurationSeconds = 0f;
        tap.StateUpdated          += Tap_Updated;
        FingersScript.Instance.AddGesture(tap);
        tap.AllowSimultaneousExecutionWithAllGestures();
    }
		public void UpdateGestureRecognizers(List<IGestureRecognizer> gestureRecognizers)
		{
			this.tapGestureRecognizer = (TapGestureRecognizer)gestureRecognizers.FirstOrDefault(s => s is TapGestureRecognizer);
			this.longPressGestureRecognizer = (LongPressGestureRecognizer)gestureRecognizers.FirstOrDefault(s => s is LongPressGestureRecognizer);
			this.panGestureRecognizer = (PanGestureRecognizer)gestureRecognizers.FirstOrDefault(s => s is PanGestureRecognizer);
			this.pinchGestureRecognizer = (PinchGestureRecognizer)gestureRecognizers.FirstOrDefault(s => s is PinchGestureRecognizer);
			this.rotationGestureRecognizer = (RotationGestureRecognizer)gestureRecognizers.FirstOrDefault(s => s is RotationGestureRecognizer);
			this.swipeGestureRecognizer = (SwipeGestureRecognizer)gestureRecognizers.FirstOrDefault(s => s is SwipeGestureRecognizer);
		}
 private void SetupLongPressGesture()
 {
     longPressGesture = new LongPressGestureRecognizer
     {
         MaximumNumberOfTouchesToTrack = (ControlMode == ControlMode.LeftRight) ? 2 : 1,
         ThresholdUnits         = Mathf.Infinity,
         MinimumDurationSeconds = 0f
     };
     longPressGesture.StateUpdated += LongPressGestureCallback;
     FingersScript.Instance.AddGesture(longPressGesture);
 }
 private void AddGestures(ViewCell cell, UITableViewCell tableViewCell, UITableView tableView)
 {
     if (VisitActionDetailsPage.CurrentInstance.IsEditable)
     {
         if (VisitActionDetailsPage.CurrentInstance.SingleTypeCode != null)
         {
             tableViewCell.AddGestureRecognizer(LongPressGestureRecognizer.CreateGesture(tableView, cell));
         }
     }
     else
     {
         tableViewCell.RemoveGestureRecognizer(LongPressGestureRecognizer.CreateGesture(tableView, cell));
     }
 }
Example #8
0
            private static void OnRecognizing(UILongPressGestureRecognizer r)
            {
                LongPressGestureRecognizer recognizer = r as LongPressGestureRecognizer;
                UITableView tableView;

                recognizer.TableView.TryGetTarget(out tableView);
                ViewCell cell;

                recognizer.ViewCell.TryGetTarget(out cell);
                if (tableView == null || cell == null)
                {
                    return;
                }
                OnRecognizing(recognizer, tableView, cell);
            }
Example #9
0
 private void OnLongTap(LongPressGestureRecognizer gesture)
 {
     print("LONGTAP");
     var GO = PickObject(gesture.Position);
     if (GO)
     {
         Debug.Log("LongTap" + GO.name);
         if (GO.tag == "classic_cell")
             if (OnCellLongTap != null)
                 OnCellLongTap(GO.GetComponent<CellViewClassic>().Model);
         if(GO.tag=="GUI")
             if (OnGUITap != null)
                 OnGUITap(GO);
     }
 }
            private static void OnRecognizing(LongPressGestureRecognizer recognizer, UITableView tableView, ViewCell cell)
            {
                NSIndexPath indexPath = tableView.IndexPathForRowAtPoint(recognizer.LocationInView(tableView));

                switch (recognizer.State)
                {
                case UIGestureRecognizerState.Began:
                    if (indexPath != null)
                    {
                        // Remember the source row
                        recognizer.sourceIndexPath      = indexPath;
                        recognizer.destinationIndexPath = indexPath;
                        cell.View.BackgroundColor       = Color.Gray;
                    }
                    break;

                case UIGestureRecognizerState.Changed:
                    if ((recognizer.destinationIndexPath != null) && (indexPath != null) && (recognizer.destinationIndexPath != indexPath))
                    {
                        // Dragged to a new row location, so show it to the user with animation
                        tableView.MoveRow(recognizer.destinationIndexPath, indexPath);
                        recognizer.destinationIndexPath = indexPath;
                    }
                    break;

                case UIGestureRecognizerState.Cancelled:
                case UIGestureRecognizerState.Failed:
                    recognizer.sourceIndexPath = null;
                    cell.View.BackgroundColor  = Color.Transparent;
                    break;

                case UIGestureRecognizerState.Recognized:
                    // Move the data source finally
                    if ((recognizer.sourceIndexPath != null) && (recognizer.destinationIndexPath != null) && (recognizer.sourceIndexPath != recognizer.destinationIndexPath))
                    {
                        // Reset the move because otherwise the underneath control will get out of sync with
                        // the Xamarin.Forms element. The next line will drive the real change from ItemsSource
                        tableView.MoveRow(recognizer.destinationIndexPath, recognizer.sourceIndexPath);
                        tableView.Source.MoveRow(tableView, recognizer.sourceIndexPath, recognizer.destinationIndexPath);
                    }

                    recognizer.sourceIndexPath      = null;
                    recognizer.destinationIndexPath = null;
                    cell.View.BackgroundColor       = Color.Transparent;
                    break;
                }
            }
        private void Start()
        {
            //add gesture
            gesture = new LongPressGestureRecognizer();
            FingersScript.Instance.AddGesture(gesture);

            gesture.AllowSimultaneousExecutionWithAllGestures();

            gesture.MinimumNumberOfTouchesToTrack = minimumTouches;
            gesture.MinimumDurationSeconds        = minimumDurationSeconds;
            gesture.ThresholdUnits = maximumMovementDistance;

            gesture.StateUpdated += LongPressGesture_StateUpdated;

            foreach (var gestureHandler in requiredToFail)
            {
                RequireGestureHandlerToFail(gestureHandler);
            }
        }
Example #12
0
    void Start()
    {
        swipe = new SwipeGestureRecognizer();
        swipe.StateUpdated                 += Swipe_Updated;
        swipe.DirectionThreshold            = 0;
        swipe.MinimumSpeedUnits             = 1f;
        swipe.MinimumDistanceUnits          = 1f;
        swipe.MinimumNumberOfTouchesToTrack = swipe.MaximumNumberOfTouchesToTrack = SwipeTouchCount;
        swipe.ThresholdSeconds              = SwipeThresholdSeconds;
        FingersScript.Instance.AddGesture(swipe);
        LongPressGestureRecognizer tap = new LongPressGestureRecognizer();

        tap.MinimumDurationSeconds = 0f;
        tap.StateUpdated          += Tap_Updated;
        FingersScript.Instance.AddGesture(tap);
        tap.AllowSimultaneousExecutionWithAllGestures();
        swipe.AllowSimultaneousExecutionWithAllGestures();

        _cam = Camera.main;
    }
Example #13
0
        public void Start()
        {
            tapGesture       = new TapGestureRecognizer();
            doubleTapGesture = new TapGestureRecognizer();
            swipeGesture     = new SwipeGestureRecognizer();
            panGesture       = new PanGestureRecognizer();
            scaleGesture     = new ScaleGestureRecognizer();
            rotateGesture    = new RotateGestureRecognizer();
            longPressGesture = new LongPressGestureRecognizer();
            tripleTapGesture = new TapGestureRecognizer();

            //CreateDoubleTapGesture();
            //CreateTapGesture();
            CreateSwipeGesture();

            //CreatePanGesture();
            //CreateScaleGesture();
            //CreateRotateGesture();
            //CreateLongPressGesture();
            //CreatePlatformSpecificViewTripleTapGesture();
        }
Example #14
0
 private void AddGestures(ViewCell cell, UITableViewCell tableViewCell, UITableView tableView)
 {
     tableViewCell.AddGestureRecognizer(LongPressGestureRecognizer.CreateGesture(tableView, cell));
 }
            private static void OnRecognizing(LongPressGestureRecognizer recognizer, UITableView tableView, ViewCell cell)
            {
                NSIndexPath indexPath = tableView.IndexPathForRowAtPoint(recognizer.LocationInView(tableView));

                switch (recognizer.State)
                {
                case UIGestureRecognizerState.Began:
                    tableView.ScrollEnabled = false;
                    if (indexPath != null)
                    {
                        // Remember the source row
                        sourceIndexPath      = indexPath;
                        destinationIndexPath = indexPath;
                        var selectedCell = tableView.CellAt(indexPath);
                        UIGraphics.BeginImageContext(selectedCell.ContentView.Bounds.Size);
                        selectedCell.ContentView.Layer.RenderInContext(UIGraphics.GetCurrentContext());
                        UIImage img = UIGraphics.GetImageFromCurrentImageContext();
                        UIGraphics.EndImageContext();

                        UIImageView iv = new UIImageView(img);
                        dragAndDropView       = new UIView();
                        dragAndDropView.Frame = iv.Frame;
                        dragAndDropView.Add(iv);
                        //dragAndDropView.BackgroundColor = UIColor.Blue;
                        sourceTableView = tableView;

                        UIApplication.SharedApplication.KeyWindow.Add(dragAndDropView);

                        dragAndDropView.Center = recognizer.LocationInView(UIApplication.SharedApplication.KeyWindow);

                        dragAndDropView.AddGestureRecognizer(selectedCell.GestureRecognizers [0]);
                    }

                    break;

                case UIGestureRecognizerState.Changed:
                    dragAndDropView.Center = recognizer.LocationInView(UIApplication.SharedApplication.KeyWindow);
                    destinationIndexPath   = indexPath;
                    break;

                case UIGestureRecognizerState.Cancelled:
                case UIGestureRecognizerState.Failed:
                    sourceIndexPath           = null;
                    cell.View.BackgroundColor = Color.Transparent;
                    break;

                case UIGestureRecognizerState.Ended:

                    if (dragAndDropView == null)
                    {
                        return;
                    }

                    dragAndDropView.RemoveFromSuperview();
                    dragAndDropView = null;


                    UIView view = UIApplication.SharedApplication.KeyWindow;

                    UIView viewHit = view.HitTest(recognizer.LocationInView(view), null);

                    int removeLocation = (int)sourceIndexPath.Item;
                    int insertLocation = destinationIndexPath != null ? (int)destinationIndexPath.Item : -1;

                    UITableView destinationTableView = viewHit as UITableView;

                    if (viewHit is UITableView)
                    {
                        destinationTableView = viewHit as UITableView;
                    }
                    else
                    {
                        while (!(viewHit is UITableViewCell) && viewHit != null)
                        {
                            viewHit = viewHit.Superview;
                        }

                        UIView tempView = viewHit?.Superview;

                        while (!(tempView is UITableView) && tempView != null)
                        {
                            tempView = tempView.Superview;
                        }

                        if (tempView != null)
                        {
                            destinationTableView = tempView as UITableView;
                            insertLocation       = (int)destinationTableView.IndexPathForCell((UITableViewCell)viewHit).Item;
                        }
                    }

                    if (destinationTableView != null)
                    {
                        if (DragAndDropListViewRenderer.ListMap.ContainsKey(tableView.Tag.ToString()) && DragAndDropListViewRenderer.ListMap.ContainsKey(destinationTableView.Tag.ToString()))
                        {
                            var sourceList      = (IList)DragAndDropListViewRenderer.ListMap [tableView.Tag.ToString()].Item2;
                            var destinationList = (IList)DragAndDropListViewRenderer.ListMap [destinationTableView.Tag.ToString()].Item2;
                            if (!tableView.Tag.Equals(destinationTableView.Tag) || removeLocation != insertLocation)
                            {
                                if (sourceList.Contains(cell.BindingContext))
                                {
                                    sourceList.Remove(cell.BindingContext);

                                    if (insertLocation != -1)
                                    {
                                        destinationList.Insert(insertLocation, cell.BindingContext);
                                    }
                                    else
                                    {
                                        destinationList.Add(cell.BindingContext);
                                    }
                                }
                                tableView.ReloadData();
                                destinationTableView.ReloadData();
                            }
                        }
                    }


                    tableView.ScrollEnabled = true;

                    break;
                }
            }
        protected override void HandleLongPressGesture()
        {
            switch (LongPressGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                // we try to grab the current seelected item and draw a floating copy of it on the Drag Surface
                // the copy is just an image of it using RasterizedImage
                var currentIndexPath = CollectionView.IndexPathForItemAtPoint(LongPressGestureRecognizer.LocationInView(CollectionView));

                SelectedItemIndexPath = currentIndexPath;
                if (SelectedItemIndexPath == null)
                {
                    return;
                }

                if (!DataSource.CanMoveItemAtIndexPath(SelectedItemIndexPath))
                {
                    return;
                }

                var collectionViewCell = CollectionView.CellForItem(SelectedItemIndexPath);

                var        tpoint = DragSurface.ConvertPointFromView(collectionViewCell.Frame.Location, CollectionView);
                RectangleF frame  = new RectangleF(tpoint.X, tpoint.Y, collectionViewCell.Frame.Size.Width, collectionViewCell.Frame.Size.Height);
                CurrentView = new UIView(frame);

                collectionViewCell.Highlighted = true;
                var highlightedImageView = new UIImageView(RastertizedImage(collectionViewCell));
                highlightedImageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                highlightedImageView.Alpha            = 1.0f;

                collectionViewCell.Highlighted = false;
                var imageView = new UIImageView(RastertizedImage(collectionViewCell));
                imageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                imageView.Alpha            = 0.0f;

                CurrentView.AddSubview(imageView);
                CurrentView.AddSubview(highlightedImageView);
                DragSurface.AddSubview(CurrentView);         // add this to the top level view so that we can drag outside
                CurrentViewCenter = CurrentView.Center;

                OnWillBeginDraggingItem(SelectedItemIndexPath);

                // we animate the drawing out of the floating copy
                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        CurrentView.Transform      = CGAffineTransform.MakeScale(1.1f, 1.1f);
                        highlightedImageView.Alpha = 0.0f;
                        imageView.Alpha            = 1.0f;
                    },
                               () =>
                    {
                        highlightedImageView.RemoveFromSuperview();
                        OnDidBegingDraggingItem(SelectedItemIndexPath);
                    });
                InvalidateLayout();
            }
            break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Ended:
            {
                var currentIndexPath = SelectedItemIndexPath;
                if (currentIndexPath == null || CurrentView == null)
                {
                    return;
                }
                SelectedItemIndexPath = null;
                CurrentViewCenter     = PointF.Empty;

                OnWillEndDraggingItem(currentIndexPath);

                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        var layoutAttributes  = this.LayoutAttributesForItem(currentIndexPath);
                        CurrentView.Transform = CGAffineTransform.MakeScale(1.0f, 1.0f);
                        CurrentView.Center    = CollectionView.ConvertPointToView(layoutAttributes.Center, DragSurface);
                    },
                               () =>
                    {
                        CurrentView.RemoveFromSuperview();
                        CurrentView = null;
                        InvalidateLayout();

                        OnDidEndDraggingItem(currentIndexPath);
                    });
            }
            break;
            }
        }
 public override void initState()
 {
     base.initState();
     this._longPressRecognizer             = new LongPressGestureRecognizer();
     this._longPressRecognizer.onLongPress = this._handlePress;
 }
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);
            var viewGesture = (ViewGestures)Element;

            var tapGestureRecognizer = new TapGestureRecognizer()
            {
                OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)),
                OnTouchesEnded = (() => viewGesture.OnTouchEnded()),
                OnTap = ((x, y) => viewGesture.OnTap(x, y)),
            };

            var longPressGestureRecognizer = new LongPressGestureRecognizer(() => viewGesture.OnLongTap())
            {
                OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)),
                OnTouchesEnded = (() => viewGesture.OnTouchEnded()),
            };
            
            #region SwipeGestureRecognizer
            var swipeLeftGestureRecognizer = new SwipeGestureRecognizer(() => viewGesture.OnSwipeLeft())
            {
                Direction = UISwipeGestureRecognizerDirection.Left,

                OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)),
                OnTouchesEnded = (() => viewGesture.OnTouchEnded()),
            };

            var swipeRightGestureRecognizer = new SwipeGestureRecognizer(() => viewGesture.OnSwipeRight())
            {
                Direction = UISwipeGestureRecognizerDirection.Right,

                OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)),
                OnTouchesEnded = (() => viewGesture.OnTouchEnded()),
            };

            var swipeUpGestureRecognizer = new SwipeGestureRecognizer(() => viewGesture.OnSwipeUp())
            {
                Direction = UISwipeGestureRecognizerDirection.Up,

                OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)),
                OnTouchesEnded = (() => viewGesture.OnTouchEnded()),
            };

            var swipeDownGestureRecognizer = new SwipeGestureRecognizer(() => viewGesture.OnSwipeDown())
            {
                Direction = UISwipeGestureRecognizerDirection.Down,

                OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)),
                OnTouchesEnded = (() => viewGesture.OnTouchEnded()),
            };
            #endregion

            #region DragGestureRecognizer
            var dragGestureRecognizer = new DragGestureRecognizer()
            {

                OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)),
                OnTouchesEnded = (() => viewGesture.OnTouchEnded()),
                OnDrag = ((x, y) => viewGesture.OnDrag(x, y)),
            };

            //from iOS Developer Library (Gesture Recognizers)
            //...For your view to recognize both swipes and pans, you want the swipe gesture recognizer to analyze the touch event before the pan gesture recognizer does...
            if ((viewGesture.SupportGestures & ViewGestures.GestureType.gtSwipeLeft) != 0)
                dragGestureRecognizer.RequireGestureRecognizerToFail(swipeLeftGestureRecognizer);
            if ((viewGesture.SupportGestures & ViewGestures.GestureType.gtSwipeRight) != 0)
                dragGestureRecognizer.RequireGestureRecognizerToFail(swipeRightGestureRecognizer);
            if ((viewGesture.SupportGestures & ViewGestures.GestureType.gtSwipeUp) != 0)
                dragGestureRecognizer.RequireGestureRecognizerToFail(swipeUpGestureRecognizer);
            if ((viewGesture.SupportGestures & ViewGestures.GestureType.gtSwipeDown) != 0)
                dragGestureRecognizer.RequireGestureRecognizerToFail(swipeDownGestureRecognizer);
            #endregion

            if (e.NewElement == null)
            {
                if (tapGestureRecognizer != null)
                    this.RemoveGestureRecognizer(tapGestureRecognizer);

                if (longPressGestureRecognizer != null)
                    this.RemoveGestureRecognizer(longPressGestureRecognizer);

                if (swipeLeftGestureRecognizer != null)
                    this.RemoveGestureRecognizer(swipeLeftGestureRecognizer);

                if (swipeRightGestureRecognizer != null)
                    this.RemoveGestureRecognizer(swipeRightGestureRecognizer);
                
                if (swipeUpGestureRecognizer != null)
                    this.RemoveGestureRecognizer(swipeUpGestureRecognizer);
                
                if (swipeDownGestureRecognizer != null)
                    this.RemoveGestureRecognizer(swipeDownGestureRecognizer);

                if (dragGestureRecognizer != null)
                    this.RemoveGestureRecognizer(dragGestureRecognizer);
            }

            if (e.OldElement == null)
            {
                this.AddGestureRecognizer(tapGestureRecognizer);
                this.AddGestureRecognizer(longPressGestureRecognizer);
                this.AddGestureRecognizer(swipeLeftGestureRecognizer);
                this.AddGestureRecognizer(swipeRightGestureRecognizer);
                this.AddGestureRecognizer(swipeUpGestureRecognizer);
                this.AddGestureRecognizer(swipeDownGestureRecognizer);
                this.AddGestureRecognizer(dragGestureRecognizer);
            }
        }
		public iOS_LongPressGestureEventArgs(LongPressGestureRecognizer gestureRecognizer, UILongPressGestureRecognizer platformGestureRecognizer)
		{
			this.gestureRecognizer = gestureRecognizer;
			this.platformGestureRecognizer = platformGestureRecognizer;
		}
            private static void OnRecognizing(LongPressGestureRecognizer recognizer, UITableView tableView, ViewCell cell)
            {
                try
                {
                    NSIndexPath indexPath = tableView.IndexPathForRowAtPoint(recognizer.LocationInView(tableView));

                    Items = AppData.PropertyModel.SelectedAction.Action.Paragraphs;
                    if (indexPath != null)
                    {
                        if (VisitActionDetailsPage.CurrentInstance.IsEditable)
                        {
                            if (!VisitActionDetailsPage.CurrentInstance.SingleTypeCode.Contains(Items[(int)indexPath.LongRow].ParagraphType))
                            {
                                switch (recognizer.State)
                                {
                                case UIGestureRecognizerState.Began:
                                    tableView.ScrollEnabled = false;
                                    if (indexPath != null)
                                    {
                                        // Remember the source row
                                        sourceIndexPath      = indexPath;
                                        destinationIndexPath = indexPath;
                                        var selectedCell = tableView.CellAt(indexPath);
                                        UIGraphics.BeginImageContext(selectedCell.ContentView.Bounds.Size);
                                        selectedCell.ContentView.Layer.RenderInContext(UIGraphics.GetCurrentContext());
                                        UIImage img = UIGraphics.GetImageFromCurrentImageContext();
                                        UIGraphics.EndImageContext();


                                        UIImageView iv = new UIImageView(img);
                                        dragAndDropView       = new UIView();
                                        dragAndDropView.Frame = iv.Frame;
                                        dragAndDropView.Add(iv);
                                        //dragAndDropView.BackgroundColor = UIColor.Blue;
                                        sourceTableView = tableView;

                                        UIApplication.SharedApplication.KeyWindow.Add(dragAndDropView);

                                        dragAndDropView.Center = recognizer.LocationInView(UIApplication.SharedApplication.KeyWindow);

                                        dragAndDropView.AddGestureRecognizer(selectedCell.GestureRecognizers[0]);
                                    }

                                    break;

                                case UIGestureRecognizerState.Changed:
                                    dragAndDropView.Center = recognizer.LocationInView(UIApplication.SharedApplication.KeyWindow);
                                    destinationIndexPath   = indexPath;
                                    break;

                                case UIGestureRecognizerState.Cancelled:
                                case UIGestureRecognizerState.Failed:
                                    sourceIndexPath           = null;
                                    cell.View.BackgroundColor = Color.Transparent;
                                    break;

                                case UIGestureRecognizerState.Ended:

                                    if (dragAndDropView == null)
                                    {
                                        return;
                                    }

                                    dragAndDropView.RemoveFromSuperview();
                                    dragAndDropView = null;

                                    UIView view = UIApplication.SharedApplication.KeyWindow;

                                    UIView viewHit = view.HitTest(recognizer.LocationInView(view), null);

                                    int removeLocation = (int)sourceIndexPath.Item;
                                    int insertLocation = destinationIndexPath != null ? (int)destinationIndexPath.Item : -1;

                                    while (!(viewHit is UITableViewCell) && viewHit != null)
                                    {
                                        viewHit = viewHit.Superview;
                                    }

                                    UIView tempView = viewHit?.Superview;

                                    while (!(tempView is UITableView) && tempView != null)
                                    {
                                        tempView = tempView.Superview;
                                    }

                                    insertLocation = (int)tableView.IndexPathForCell((UITableViewCell)viewHit).Item;

                                    if (CustomTableViewRenderer.ListMap.ContainsKey(tableView.Tag.ToString()))
                                    {
                                        var sourceList = (IList)CustomTableViewRenderer.ListMap[tableView.Tag.ToString()].Item2;

                                        if (!tableView.Tag.Equals(tableView.Tag) || removeLocation != insertLocation)
                                        {
                                            if (Items[removeLocation].ParagraphType == Items[insertLocation].ParagraphType)
                                            {
                                                if (sourceList.Contains(cell.BindingContext))
                                                {
                                                    sourceList.Remove(cell.BindingContext);

                                                    if (insertLocation != -1)
                                                    {
                                                        sourceList.Insert(insertLocation, cell.BindingContext);
                                                    }
                                                    else
                                                    {
                                                        sourceList.Add(cell.BindingContext);
                                                    }
                                                }
                                                tableView.ReloadData();
                                            }
                                        }
                                    }

                                    VisitActionDetailsPage.CurrentInstance.RefreshList();
                                    tableView.ScrollEnabled = true;

                                    break;
                                }
                            }
                            else
                            {
                                dragAndDropView.RemoveFromSuperview();
                                VisitActionDetailsPage.CurrentInstance.RefreshList();
                            }
                        }
                    }
                    else
                    {
                        dragAndDropView.RemoveFromSuperview();
                        VisitActionDetailsPage.CurrentInstance.RefreshList();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("==={0}===", ex.Message);
                }
            }
		private readonly Android_GestureListener androidGestureListener;

		// TODO: implement state information
Example #22
0
        protected override void HandleLongPressGesture()
        {
            switch (LongPressGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                // we get the current item and draw a floating copy on it on the Collection View, so that it cannot be taken outside the bounds of the collection view
                // we get the copy usign RasterizedImage
                var currentIndexPath = CollectionView.IndexPathForItemAtPoint(LongPressGestureRecognizer.LocationInView(CollectionView));
                SelectedItemIndexPath = currentIndexPath;
                if (SelectedItemIndexPath == null)
                {
                    return;
                }

                if (!DataSource.CanMoveItemAtIndexPath(SelectedItemIndexPath))
                {
                    return;
                }

                var collectionViewCell = CollectionView.CellForItem(SelectedItemIndexPath);
                CurrentView = new UIView(collectionViewCell.Frame);

                collectionViewCell.Highlighted = true;
                var highlightedImageView = new UIImageView(RastertizedImage(collectionViewCell));
                highlightedImageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                highlightedImageView.Alpha            = 1.0f;

                collectionViewCell.Highlighted = false;
                var imageView = new UIImageView(RastertizedImage(collectionViewCell));
                imageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                imageView.Alpha            = 0.0f;

                CurrentView.AddSubview(imageView);
                CurrentView.AddSubview(highlightedImageView);
                CollectionView.AddSubview(CurrentView);
                CurrentViewCenter = CurrentView.Center;

                OnWillBeginDraggingItem(SelectedItemIndexPath);

                // animate the floating copy into existence
                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        CurrentView.Transform      = CGAffineTransform.MakeScale(1.1f, 1.1f);
                        highlightedImageView.Alpha = 0.0f;
                        imageView.Alpha            = 1.0f;
                    },
                               () =>
                    {
                        highlightedImageView.RemoveFromSuperview();
                        OnDidBegingDraggingItem(SelectedItemIndexPath);
                    });
                InvalidateLayout();
            }
            break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Ended:
            {
                var currentIndexPath = SelectedItemIndexPath;
                if (currentIndexPath == null)
                {
                    return;
                }
                SelectedItemIndexPath = null;
                CurrentViewCenter     = PointF.Empty;

                OnWillEndDraggingItem(currentIndexPath);

                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        var layoutAttributes  = LayoutAttributesForItem(currentIndexPath);
                        CurrentView.Transform = CGAffineTransform.MakeScale(1.0f, 1.0f);
                        CurrentView.Center    = layoutAttributes.Center;
                    },
                               () =>
                    {
                        CurrentView.RemoveFromSuperview();
                        CurrentView = null;
                        InvalidateLayout();

                        OnDidEndDraggingItem(currentIndexPath);
                    });
            }
            break;
            }
        }
Example #23
0
 private static void OnRecognizing(LongPressGestureRecognizer recognizer, UITableView tableView, ViewCell cell)
 {
     NSIndexPath indexPath = tableView.IndexPathForRowAtPoint(recognizer.LocationInView(tableView));
     switch (recognizer.State)
     {
         case UIGestureRecognizerState.Began:
             if (indexPath != null)
             {
                 // Remember the source row
                 recognizer.sourceIndexPath = indexPath;
                 recognizer.destinationIndexPath = indexPath;
                 cell.View.BackgroundColor = Color.Gray;
             }
             break;
         case UIGestureRecognizerState.Changed:
             if (recognizer.destinationIndexPath != null && indexPath != null && recognizer.destinationIndexPath != indexPath)
             {
                 // Dragged to a new row location, so show it to the user with animation
                 tableView.MoveRow(recognizer.destinationIndexPath, indexPath);
                 recognizer.destinationIndexPath = indexPath;
             }
             break;
         case UIGestureRecognizerState.Cancelled:
         case UIGestureRecognizerState.Failed:
             recognizer.sourceIndexPath = null;
             cell.View.BackgroundColor = Color.Transparent;
             break;
         case UIGestureRecognizerState.Recognized:
             // Move the data source finally
             if (recognizer.sourceIndexPath != null && recognizer.destinationIndexPath != null && recognizer.sourceIndexPath != recognizer.destinationIndexPath)
             {
                 // Reset the move because otherwise the underneath control will get out of sync with
                 // the Xamarin.Forms element. The next line will drive the real change from ItemsSource
                 tableView.MoveRow(recognizer.destinationIndexPath, recognizer.sourceIndexPath);
                 tableView.Source.MoveRow(tableView, recognizer.sourceIndexPath, recognizer.destinationIndexPath);
             }
             recognizer.sourceIndexPath = null;
             recognizer.destinationIndexPath = null;
             cell.View.BackgroundColor = Color.Transparent;
             break;
     }
 }
Example #24
0
 public void CreateLongPress(GestureRecognizerStateUpdatedDelegate gestureRecognizerStateUpdatedDelegate)
 {
     longpressgesture = new LongPressGestureRecognizer();
     longpressgesture.StateUpdated += gestureRecognizerStateUpdatedDelegate;
     FingersScript.AddGesture(longpressgesture);
 }
        /// <summary>
        /// Refresh the recognizers attached to the sandbox.
        /// </summary>
        private void RefreshRecognizers()
        {
            GestureView.GestureRecognizers.Clear();
            GestureView.Effects.Clear();

            if (TapEnabled.IsChecked)
            {
                var tapRecognizer = new TapGestureRecognizer()
                {
                    NumberOfTapsRequired    = int.Parse(TapNumberOfTaps.Text),
                    NumberOfTouchesRequired = int.Parse(TapNumberOfTouches.Text)
                };

                tapRecognizer.Tapped       += OnTapped;
                tapRecognizer.TouchesBegan += OnTouchesBegan;
                tapRecognizer.TouchesEnded += OnTouchesEnded;
                GestureView.GestureRecognizers.Add(tapRecognizer);
            }

            if (LongPressEnabled.IsChecked)
            {
                var longPressRecognizer = new LongPressGestureRecognizer()
                {
                    NumberOfTouchesRequired = int.Parse(LongPressNumberOfTouches.Text)
                };

                longPressRecognizer.LongPressed  += OnLongPressed;
                longPressRecognizer.TouchesBegan += OnTouchesBegan;
                longPressRecognizer.TouchesEnded += OnTouchesEnded;
                GestureView.GestureRecognizers.Add(longPressRecognizer);
            }

            if (SwipeEnabled.IsChecked)
            {
                var swipeRecognizer = new SwipeGestureRecognizer()
                {
                    NumberOfTouchesRequired = int.Parse(SwipeNumberOfTouches.Text)
                };

                swipeRecognizer.Swiped       += OnSwiped;
                swipeRecognizer.TouchesBegan += OnTouchesBegan;
                swipeRecognizer.TouchesEnded += OnTouchesEnded;
                GestureView.GestureRecognizers.Add(swipeRecognizer);
            }

            if (PanEnabled.IsChecked)
            {
                var panRecognizer = new PanGestureRecognizer();
                panRecognizer.Panning      += OnPanning;
                panRecognizer.TouchesBegan += OnTouchesBegan;
                panRecognizer.TouchesEnded += OnTouchesEnded;
                GestureView.GestureRecognizers.Add(panRecognizer);
            }

            if (PinchEnabled.IsChecked)
            {
                var pinchRecognizer = new PinchGestureRecognizer();
                pinchRecognizer.Pinching     += OnPinching;
                pinchRecognizer.TouchesBegan += OnTouchesBegan;
                pinchRecognizer.TouchesEnded += OnTouchesEnded;
                GestureView.GestureRecognizers.Add(pinchRecognizer);
            }

            if (HoverEnabled.IsChecked)
            {
                var hoverRecognizer = new HoverGestureRecognizer();
                hoverRecognizer.Hovering     += OnHovering;
                hoverRecognizer.TouchesBegan += OnTouchesBegan;
                hoverRecognizer.TouchesEnded += OnTouchesEnded;
                GestureView.GestureRecognizers.Add(hoverRecognizer);
            }

            if (KeyEnabled.IsChecked)
            {
                var keyListener = new KeyGestureListener();
                keyListener.Pressed += OnPressed;
                keyListener.KeyDown += OnKeyDown;
                keyListener.KeyUp   += OnKeyUp;
                GestureView.GestureRecognizers.Add(keyListener);
            }

            GestureView.Effects.Add(Effect.Resolve($"Velocity.{nameof(RecognizerEffect)}"));
            GestureView.Effects.Add(Effect.Resolve($"Velocity.{nameof(ListenerEffect)}"));
        }