void OnTouch(object?sender, View.TouchEventArgs e)
        {
            if (e.Event == null)
            {
                return;
            }

            float   density = Context?.Resources?.DisplayMetrics?.Density ?? 1.0f;
            APointF point   = new APointF(e.Event.GetX() / density, e.Event.GetY() / density);

            switch (e.Event.Action)
            {
            case MotionEventActions.Down:
                VirtualView?.OnTouchDown(new Point(point.X, point.Y));
                break;

            case MotionEventActions.Move:
                VirtualView?.OnTouchMove(new Point(point.X, point.Y));
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
                VirtualView?.OnTouchUp(new Point(point.X, point.Y));
                break;

            default:
                break;
            }
        }
Beispiel #2
0
        bool ProcessTouchUp(APointF point)
        {
            _isTouchDown = false;

            if (CanProcessTouchSwipeItems(point))
            {
                ProcessTouchSwipeItems(point);
            }

            if (!_isSwiping)
            {
                return(false);
            }

            _isSwiping = false;

            RaiseSwipeEnded();

            if (_isResettingSwipe || !ValidateSwipeDirection())
            {
                return(false);
            }

            ValidateSwipeThreshold();

            return(false);
        }
        private async void AddStop(Android.Graphics.PointF tappedPosition)
        {
            try
            {
                // Get the location on the map.
                MapPoint tappedLocation = _myMapView.ScreenToLocation(tappedPosition);

                // Name the stop by its number.
                string stopName = $"{_stopsOverlay.Graphics.Count + 1}";

                // Create a pushpin marker for the stop.
                PictureMarkerSymbol pushpinMarker = await GetPictureMarker();

                // Create the text symbol for labeling the stop.
                TextSymbol stopSymbol = new TextSymbol(stopName, Color.White, 15,
                                                       HorizontalAlignment.Center, VerticalAlignment.Middle);
                stopSymbol.OffsetY = 15;

                // Create a combined symbol with the pushpin and the label.
                CompositeSymbol combinedSymbol = new CompositeSymbol(new MarkerSymbol[] { pushpinMarker, stopSymbol });

                // Create the graphic from the geometry and the symbology.
                Graphic newStopGraphic = new Graphic(tappedLocation, combinedSymbol);

                // Add the stop to the overlay.
                _stopsOverlay.Graphics.Add(newStopGraphic);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                ShowMessage("Couldn't select or add stop", "Couldn't select or add stop. See debug output for details.");
            }
        }
 private void FindTagByPosition(Android.Graphics.PointF position)
 {
     try
     {
         if (null != listGraphicsOverlay && listGraphicsOverlay.Count > 0)
         {
             foreach (var item in listGraphicsOverlay)
             {
                 var      pointFind = new MapPoint(position.X, position.Y, mapView.LocationDisplay.Location.Position.SpatialReference);
                 var      simpleMarkerSymbolFind = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 10);
                 var      graphicFind            = new Graphic(pointFind, simpleMarkerSymbolFind);
                 Geometry geometryData           = GeometryEngine.Project(item.Value, mapView.LocationDisplay.Location.Position.SpatialReference);
                 Boolean  result          = GeometryEngine.Contains(geometryData, graphicFind.Geometry);
                 Boolean  resultIntersect = GeometryEngine.Intersects(geometryData, graphicFind.Geometry);
                 if (result && resultIntersect)
                 {
                     var intent = new Intent(this, typeof(ConsultarTap));
                     intent.PutExtra("codigoTag", item.Key);
                     StartActivity(intent);
                     SetContentView(Resource.Layout.Fragment_ConsultarTap);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Info("Error", ex.Message);
         throw new System.Exception(ex.Message);
     }
 }
Beispiel #5
0
        private async void BtnRcenter_Click(object sender, EventArgs e)
        {
            try
            {
                var      screenCenter = new Android.Graphics.PointF(this._sceneLeftView.Width / 2, this._sceneLeftView.Height / 2);
                MapPoint ptCenter     = await this._sceneLeftView.ScreenToLocationAsync(screenCenter);

                if (ptCenter == null)
                {
                    return;
                }

                if (isRotate)
                {
                    isRotate = false;
                }
                else
                {
                    isRotate = true;
                }
                while (isRotate)
                {
                    await this._sceneLeftView.SetViewpointCameraAsync(this._sceneLeftView.Camera.RotateAround(ptCenter, 10, 0, 0));
                }
                ;
            }
            catch
            {
            }
        }
Beispiel #6
0
        bool HandleTouchInteractions(GestureStatus status, APointF point)
        {
            if (!_isSwipeEnabled)
            {
                return(false);
            }

            switch (status)
            {
            case GestureStatus.Started:
                return(!ProcessTouchDown(point));

            case GestureStatus.Running:
                return(!ProcessTouchMove(point));

            case GestureStatus.Canceled:
            case GestureStatus.Completed:
                ProcessTouchUp(point);
                break;
            }

            _isTouchDown = false;

            return(true);
        }
Beispiel #7
0
        public override bool DispatchTouchEvent(MotionEvent?e)
        {
            if (e?.Action == MotionEventActions.Down)
            {
                _initialPoint = new APointF(e.GetX() / _density, e.GetY() / _density);
            }

            if (e?.Action == MotionEventActions.Move)
            {
                ResetSwipe(e);
            }

            if (e?.Action == MotionEventActions.Up)
            {
                var touchUpPoint = new APointF(e.GetX() / _density, e.GetY() / _density);

                if (CanProcessTouchSwipeItems(touchUpPoint))
                {
                    ProcessTouchSwipeItems(touchUpPoint);
                }
                else
                {
                    ResetSwipe(e);
                    PropagateParentTouch();
                }
            }

            return(base.DispatchTouchEvent(e));
        }
Beispiel #8
0
        protected override void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (disposing)
            {
                if (Element != null)
                {
                    Element.OpenRequested  -= OnOpenRequested;
                    Element.CloseRequested -= OnCloseRequested;
                }

                if (_scrollParent != null)
                {
                    if (_scrollParent is ScrollView scrollView)
                    {
                        scrollView.Scrolled -= OnParentScrolled;
                    }

                    if (_scrollParent is ListView listView)
                    {
                        listView.Scrolled -= OnParentScrolled;
                    }

                    if (_scrollParent is System.Maui.CollectionView collectionView)
                    {
                        collectionView.Scrolled -= OnParentScrolled;
                    }
                }

                if (_contentView != null)
                {
                    _contentView.RemoveFromParent();
                    _contentView.Dispose();
                    _contentView = null;
                }

                if (_actionView != null)
                {
                    _actionView.RemoveFromParent();
                    _actionView.Dispose();
                    _actionView = null;
                }

                if (_initialPoint != null)
                {
                    _initialPoint.Dispose();
                    _initialPoint = null;
                }
            }

            _isDisposed = true;

            base.Dispose(disposing);
        }
Beispiel #9
0
        bool TouchInsideContent(APointF point)
        {
            if (_contentView == null)
            {
                return(false);
            }

            bool touchContent = TouchInsideContent(_contentView.Left + _contentView.TranslationX, _contentView.Top + _contentView.TranslationY, _contentView.Width, _contentView.Height, _context.ToPixels(point.X), _context.ToPixels(point.Y));

            return(touchContent);
        }
Beispiel #10
0
        void ResetSwipe(MotionEvent e, bool animated = true)
        {
            if (!_isSwiping && _isOpen)
            {
                var touchPoint = new APointF(e.GetX() / _density, e.GetY() / _density);

                if (TouchInsideContent(touchPoint))
                {
                    ResetSwipe(animated);
                }
            }
        }
Beispiel #11
0
        bool ProcessTouchDown(APointF point)
        {
            if (_isSwiping || _isTouchDown || _contentView == null)
            {
                return(false);
            }

            _initialPoint = point;
            _isTouchDown  = true;

            return(true);
        }
Beispiel #12
0
        public void PlatformToSystemF()
        {
#if __IOS__
            var platform = new CoreGraphics.CGPoint(x, y);
#elif __ANDROID__
            var platform = new Android.Graphics.PointF(x, y);
#else
            var platform = new Windows.Foundation.Point(x, y);
#endif
            var system = platform.ToSystemPointF();
            Assert.Equal(x, system.X);
            Assert.Equal(y, system.Y);
        }
        bool ProcessTouchMove(APointF point)
        {
            if (_contentView == null || !TouchInsideContent(point))
            {
                return(false);
            }

            var swipeDirection = _swipeDirection;

            if (!_isOpen && !_isResettingSwipe)
            {
                swipeDirection = SwipeDirectionHelper.GetSwipeDirection(new Point(_initialPoint.X, _initialPoint.Y), new Point(point.X, point.Y));
            }

            if (_swipeDirection != swipeDirection)
            {
                _swipeDirection = swipeDirection;

                if (!_isOpen)
                {
                    DisposeSwipeItems();
                    UpdateSwipeItems();
                }
            }

            if (!_isSwiping)
            {
                RaiseSwipeStarted();
                _isSwiping = true;
            }

            if (!ValidateSwipeDirection() || _isResettingSwipe)
            {
                return(false);
            }

            _swipeOffset = GetSwipeOffset(_initialPoint, point);

            UpdateSwipeItems();

            if (Math.Abs(_swipeOffset) > double.Epsilon)
            {
                Swipe();
            }

            RaiseSwipeChanging();

            return(true);
        }
Beispiel #14
0
        bool CanProcessTouchSwipeItems(APointF point)
        {
            // We only invoke the SwipeItem command if we tap on the SwipeItems area
            // and the SwipeView is fully open.
            if (TouchInsideContent(point))
            {
                return(false);
            }

            if (_swipeOffset == _swipeThreshold)
            {
                return(true);
            }

            return(false);
        }
Beispiel #15
0
        bool ProcessTouchDown(APointF point)
        {
            if (_isSwiping || _isTouchDown || _contentView == null)
            {
                return(false);
            }

            if (TouchInsideContent(point) && _isOpen)
            {
                ResetSwipe();
            }

            _initialPoint = point;
            _isTouchDown  = true;

            return(true);
        }
Beispiel #16
0
        public override bool OnInterceptTouchEvent(MotionEvent e)
        {
            switch (e.Action)
            {
            case MotionEventActions.Down:
                _downX        = e.RawX;
                _downY        = e.RawY;
                _initialPoint = new APointF(e.GetX() / _density, e.GetY() / _density);
                break;

            case MotionEventActions.Move:
            case MotionEventActions.Cancel:
            case MotionEventActions.Up:
                ProcessSwipingInteractions(e);
                break;
            }

            return(false);
        }
Beispiel #17
0
        bool ProcessTouchMove(APointF point)
        {
            if (_contentView == null || !TouchInsideContent(point) || _initialPoint == null)
            {
                return(false);
            }

            if (!_isOpen)
            {
                ResetSwipeToInitialPosition();

                _swipeDirection = SwipeDirectionHelper.GetSwipeDirection(new Point(_initialPoint.X, _initialPoint.Y), new Point(point.X, point.Y));

                UpdateSwipeItems();
            }

            if (!_isSwiping)
            {
                RaiseSwipeStarted();
                _isSwiping = true;
            }

            if (!ValidateSwipeDirection() || _isResettingSwipe)
            {
                return(false);
            }

            EnableParentGesture(false);
            _swipeOffset = GetSwipeOffset(_initialPoint, point);
            UpdateIsOpen(_swipeOffset != 0);

            UpdateSwipeItems();

            if (Math.Abs(_swipeOffset) > double.Epsilon)
            {
                Swipe();
            }

            RaiseSwipeChanging();

            return(true);
        }
Beispiel #18
0
        void ProcessTouchSwipeItems(APointF point)
        {
            if (_isResettingSwipe)
            {
                return;
            }

            var swipeItems = GetSwipeItemsByDirection();

            if (swipeItems == null || _actionView == null)
            {
                return;
            }

            for (int i = 0; i < _actionView.ChildCount; i++)
            {
                var swipeButton = _actionView.GetChildAt(i);

                if (swipeButton.Visibility == ViewStates.Visible)
                {
                    var swipeItemX      = swipeButton.Left / _density;
                    var swipeItemY      = swipeButton.Top / _density;
                    var swipeItemHeight = swipeButton.Height / _density;
                    var swipeItemWidth  = swipeButton.Width / _density;

                    if (TouchInsideContent(swipeItemX, swipeItemY, swipeItemWidth, swipeItemHeight, point.X, point.Y))
                    {
                        var swipeItem = swipeItems[i];

                        ExecuteSwipeItem(swipeItem);

                        if (swipeItems.SwipeBehaviorOnInvoked != SwipeBehaviorOnInvoked.RemainOpen)
                        {
                            ResetSwipe();
                        }

                        break;
                    }
                }
            }
        }
Beispiel #19
0
        private async Task <Graphic> GetGraphicAsync()
        {
            // Wait for the user to click a location on the map
            Geometry mapPoint = await _myMapView.SketchEditor.StartAsync(SketchCreationMode.Point, false);

            // Convert the map point to a screen point
            Android.Graphics.PointF screenCoordinate = _myMapView.LocationToScreen((MapPoint)mapPoint);

            // Identify graphics in the graphics overlay using the point
            IReadOnlyList <IdentifyGraphicsOverlayResult> results = await _myMapView.IdentifyGraphicsOverlaysAsync(screenCoordinate, 2, false);

            // If results were found, get the first graphic
            Graphic graphic = null;
            IdentifyGraphicsOverlayResult idResult = results.FirstOrDefault();

            if (idResult != null && idResult.Graphics.Count > 0)
            {
                graphic = idResult.Graphics.FirstOrDefault();
            }

            // Return the graphic (or null if none were found)
            return(graphic);
        }
Beispiel #20
0
        float GetSwipeOffset(APointF initialPoint, APointF endPoint)
        {
            float swipeOffset = 0;

            switch (_swipeDirection)
            {
            case SwipeDirection.Left:
            case SwipeDirection.Right:
                swipeOffset = endPoint.X - initialPoint.X;
                break;

            case SwipeDirection.Up:
            case SwipeDirection.Down:
                swipeOffset = endPoint.Y - initialPoint.Y;
                break;
            }

            if (swipeOffset == 0)
            {
                swipeOffset = GetSwipeContentOffset();
            }

            return(swipeOffset);
        }
 /// <summary>
 /// A method used to convert pixels into points.
 /// </summary>
 /// <returns>A PointF containing the point X and Y values for the pixel X and Y values that were supplied.</returns>
 public static Android.Graphics.PointF PointsFromPixels(float pixelsX, float pixelsY, Android.Graphics.PointF Dpi)
 {
     return(new Android.Graphics.PointF(PointsFromPixels(pixelsX, Dpi.X), PointsFromPixels(pixelsY, Dpi.Y)));
 }
 public static PointF ToSystemPointF(this AndroidPointF point) =>
 new PointF(point.X, point.Y);
Beispiel #23
0
        bool ProcessSwipingInteractions(MotionEvent e)
        {
            bool?handled = true;
            var  point   = new APointF(e.GetX() / _density, e.GetY() / _density);

            switch (e.Action)
            {
            case MotionEventActions.Down:
                _downX = e.RawX;
                _downY = e.RawY;

                handled = HandleTouchInteractions(GestureStatus.Started, point);

                if (handled == true)
                {
                    Parent.RequestDisallowInterceptTouchEvent(true);
                }

                break;

            case MotionEventActions.Up:
                handled = HandleTouchInteractions(GestureStatus.Completed, point);

                if (Parent == null)
                {
                    break;
                }

                Parent.RequestDisallowInterceptTouchEvent(false);
                break;

            case MotionEventActions.Move:
                handled = HandleTouchInteractions(GestureStatus.Running, point);

                if (handled == true || Parent == null)
                {
                    break;
                }

                Parent.RequestDisallowInterceptTouchEvent(true);
                break;

            case MotionEventActions.Cancel:
                handled = HandleTouchInteractions(GestureStatus.Canceled, point);

                if (Parent == null)
                {
                    break;
                }

                Parent.RequestDisallowInterceptTouchEvent(false);
                break;
            }

            if (handled.HasValue)
            {
                return(!handled.Value);
            }

            return(false);
        }