Beispiel #1
0
        public bool OnSingleTapConfirmed(Android.Views.MotionEvent e)
        {
            if (this._attacher == null)
            {
                return(false);
            }

            var imageView = _attacher.GetImageView();

            if (null != _attacher.GetOnPhotoTapListener())
            {
                var displayRect = _attacher.GetDisplayRect();

                if (null != displayRect)
                {
                    float x = e.GetX(), y = e.GetY();

                    if (displayRect.Contains(x, y))
                    {
                        float xResult = (x - displayRect.Left) / displayRect.Width();
                        float yResult = (y - displayRect.Top) / displayRect.Height();

                        _attacher.GetOnPhotoTapListener().OnPhotoTap(imageView, xResult, yResult);
                        return(true);
                    }
                }
            }

            if (null != _attacher.GetOnViewTapListener())
            {
                _attacher.GetOnViewTapListener().OnViewTap(imageView, e.GetX(), e.GetY());
            }

            return(false);
        }
 public override bool DispatchTouchEvent(Android.Views.MotionEvent e)
 {
     if (e.ActionMasked == Android.Views.MotionEventActions.Down)
     {
         //Record the position the list the touch landed on
         _mPosition = this.Control.PointToPosition((int)e.GetX(), (int)e.GetY());
     }
     if (e.ActionMasked == Android.Views.MotionEventActions.Move)
     {
         //Ignore move events
         return(true);
     }
     if (e.ActionMasked == Android.Views.MotionEventActions.Up)
     {
         //Check if we are still within the same view
         if (this.Control.PointToPosition((int)e.GetX(), (int)e.GetY()) == _mPosition)
         {
             base.DispatchTouchEvent(e);
         }
         else
         {
             //Clear pressed state, cancel action
             Pressed = false;
             Invalidate();
             return(true);
         }
     }
     return(base.DispatchTouchEvent(e));
 }
        public static TouchData FromAndroid(Android.Views.MotionEvent e)
        {
            TouchData t = new TouchData();

            switch (e.Action)
            {
            case Android.Views.MotionEventActions.Up:
                t.state = TouchState.Up;
                break;

            case Android.Views.MotionEventActions.Down:
                t.state = TouchState.Down;
                break;

            case Android.Views.MotionEventActions.Move:
                t.state = TouchState.Move;
                break;

            default:
                break;
            }

            t.x = e.GetX();
            t.y = e.GetY();

            return(t);
        }
Beispiel #4
0
        private void AndroidMap_MapSingleTap(object sender, Android.Views.MotionEvent e)
        {
            PointF     location = new PointF(e.GetX(), e.GetY());
            PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X,
                                                                 location.Y, androidMap.Width, androidMap.Height);

            LayerOverlay         worldOverlay     = (LayerOverlay)androidMap.Overlays["WorldOverlay"];
            LayerOverlay         highlightOverlay = (LayerOverlay)androidMap.Overlays["HighlightOverlay"];
            FeatureLayer         worldLayer       = (FeatureLayer)worldOverlay.Layers["WorldLayer"];
            InMemoryFeatureLayer highlightLayer   = (InMemoryFeatureLayer)highlightOverlay.Layers["HighlightLayer"];

            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(position, new string[1] {
                "CNTRY_NAME"
            });

            worldLayer.Close();

            highlightLayer.Open();
            highlightLayer.InternalFeatures.Clear();
            if (selectedFeatures.Count > 0)
            {
                highlightLayer.InternalFeatures.Add(selectedFeatures[0]);
            }
            highlightLayer.Close();

            highlightOverlay.Refresh();
        }
Beispiel #5
0
        public bool OnDoubleTap(Android.Views.MotionEvent ev)
        {
            if (photoViewAttacher == null)
            {
                return(false);
            }
            try {
                float scale = photoViewAttacher.GetScale();
                float x     = ev.GetX();
                float y     = ev.GetY();

                if (scale > photoViewAttacher.GetMinimumScale())
                {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMinimumScale(), x, y, true);
                }
                else
                {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMediumScale(), x, y, true);
                }

                /*
                 *              if (scale < photoViewAttacher.GetMediumScale()) {
                 *                      photoViewAttacher.SetScale(photoViewAttacher.GetMediumScale(), x, y, true);
                 *              } else if (scale >= photoViewAttacher.GetMediumScale() && scale < photoViewAttacher.GetMaximumScale()) {
                 *                      photoViewAttacher.SetScale(photoViewAttacher.GetMaximumScale(), x, y, true);
                 *              } else {
                 *                      photoViewAttacher.SetScale(photoViewAttacher.GetMinimumScale(), x, y, true);
                 *              }*/
            } catch (Java.Lang.ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return(true);
        }
Beispiel #6
0
        public bool OnDoubleTap(Android.Views.MotionEvent e)
        {
            if (_attacher == null)
            {
                return(false);
            }

            try
            {
                float scale = _attacher.GetScale();
                float x     = e.GetX();
                float y     = e.GetY();

                if (scale < _attacher.GetMediumScale())
                {
                    _attacher.SetScale(_attacher.GetMediumScale(), x, y, true);
                }
                else if (scale >= _attacher.GetMediumScale() && scale < _attacher.GetMaximumScale())
                {
                    _attacher.SetScale(_attacher.GetMaximumScale(), x, y, true);
                }
                else
                {
                    _attacher.SetScale(_attacher.GetMinimumScale(), x, y, true);
                }
            }
            catch (Java.Lang.ArrayIndexOutOfBoundsException ex)
            {
                // Can sometimes happen when getX() and getY() is called
            }

            return(true);
        }
Beispiel #7
0
                public override bool OnTouchEvent(MotionEvent e)
                {
                    var         touchX = e.GetX();
                    var         touchY = e.GetY();
                    PathMeasure pm     = new PathMeasure(DrawPath, false);

                    //coordinates will be here
                    float[] PrevCoords = { 0f, 0f };
                    //get coordinates of the middle point
                    pm.GetPosTan(pm.Length, PrevCoords, null);
                    switch (e.Action)
                    {
                    case MotionEventActions.Down:
                        DrawPath.MoveTo(touchX, touchY);
                        PointerDown = true;
                        try { Invalidate(); } catch (ObjectDisposedException) { return(false); }
                        PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs.
                                                                        PointerEventType.Down, new Point(PrevCoords[0], PrevCoords[1]),
                                                                        new Point(touchX, touchY), PointerDown));
                        break;

                    case MotionEventActions.Move:
                        DrawPath.LineTo(touchX, touchY);
                        try { Invalidate(); } catch (ObjectDisposedException) { return(false); }
                        PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs.
                                                                        PointerEventType.Move, new Point(PrevCoords[0], PrevCoords[1]),
                                                                        new Point(touchX, touchY), PointerDown));
                        break;

                    case MotionEventActions.Up:
                        DrawCanvas.DrawPath(DrawPath, DrawPaint);
                        DrawPath.Reset();
                        PointerDown = false;
                        try { Invalidate(); } catch (ObjectDisposedException) { return(false); }
                        PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs.
                                                                        PointerEventType.Up, new Point(PrevCoords[0], PrevCoords[1]),
                                                                        new Point(touchX, touchY), PointerDown));
                        break;

                    case MotionEventActions.Cancel:
                        DrawCanvas.DrawPath(DrawPath, DrawPaint);
                        DrawPath.Reset();
                        PointerDown = false;
                        try { Invalidate(); } catch (ObjectDisposedException) { return(false); }
                        PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs.
                                                                        PointerEventType.Cancel, new Point(PrevCoords[0], PrevCoords[1]),
                                                                        new Point(touchX, touchY), PointerDown));
                        break;

                    default:
                        return(false);
                    }

                    return(true);
                }
Beispiel #8
0
        public override bool OnTouchEvent(Android.Views.MotionEvent e)
        {
            double x = (e.GetX() * LayoutElement.Width) / this.Width;
            double y = (e.GetY() * LayoutElement.Height) / this.Height;

            switch (e.Action)
            {
            case Android.Views.MotionEventActions.Down:
                HandleTouchStart(x, y);
                startX = x;
                startY = y;
                break;

            case Android.Views.MotionEventActions.Move:
                if (LayoutElement.Dragging)
                {
                    LayoutElement.HandleTouch(x, y);
                }
                break;

            case Android.Views.MotionEventActions.Up:
                if (currentDraggable != null && ((currentDraggable.Status == DragState.None || currentDraggable.Status == DragState.Started) || BelowTapThreshold(x, y)))
                {
                    if (currentDraggable.TapEnabled)
                    {
                        currentDraggable.OnTapped();
                    }
                    currentDraggable = null;
                }

                if (LayoutElement.Dragging)
                {
                    MessagingCenter.Send <DragAndDropLayoutRenderer, bool>(this, "IsDragging", false);
                    LayoutElement.StopDragging();
                    LayoutElement.Dragging = false;
                    currentDraggable       = null;
                }
                break;

            default:
                break;
            }

            return(true);
        }
Beispiel #9
0
        public override bool OnInterceptTouchEvent(Android.Views.MotionEvent ev)
        {
            if (!LayoutElement.GestureEnabled)
            {
                return(false);
            }

            double x = (ev.GetX() * LayoutElement.Width) / this.Width;
            double y = (ev.GetY() * LayoutElement.Height) / this.Height;

            IDrag draggable;

            if (LayoutElement.IDragTouched(x, y, out draggable))
            {
                currentDraggable = draggable;
                return(true);
            }

            return(false);
        }
        // ===========================================================
        // Getter & Setter
        // ===========================================================

        // ===========================================================
        // Methods for/from SuperClass/Interfaces
        // ===========================================================

        public override bool OnHandleMotionEvent(MotionEvent pMotionEvent)
        {
            //return this.fireTouchEvent(pMotionEvent.getX(), pMotionEvent.getY(), pMotionEvent.getAction(), 0, pMotionEvent);
            return this.FireTouchEvent(pMotionEvent.GetX(), pMotionEvent.GetY(), pMotionEvent.Action, 0, pMotionEvent);
        }
Beispiel #11
0
        public void ProcessTouchEvent(Android.Views.MotionEvent e)
        {
            try
            {
                switch(e.ActionMasked)
                {
                    case Android.Views.MotionEventActions.Down:
                    case Android.Views.MotionEventActions.PointerDown:
                        {
                            var ptProp = mPointerPropPool.QueryObjectSync();
                            e.GetPointerProperties(e.ActionIndex, ptProp);
                            if(ptProp.Id >= Input.InputServer.MaxMultiTouchNumber)
                            {
                                mPointerPropPool.ReleaseObject(ptProp);
                                return;
                            }

                            mStartX[ptProp.Id] = e.GetX(e.ActionIndex);
                            mStartY[ptProp.Id] = e.GetY(e.ActionIndex);

                            var touch = mTouchArgs[ptProp.Id];
                            if(touch == null)
                            {
                                touch = new EngineNS.Input.Device.TouchDevice.TouchInputEventArgs();
                                mTouchArgs[ptProp.Id] = touch;
                            }
                            touch.TouchEvent.State = Input.Device.TouchDevice.enTouchState.Down;
                            touch.TouchEvent.PosX = mStartX[ptProp.Id];
                            touch.TouchEvent.PosY = mStartY[ptProp.Id];
                            touch.TouchEvent.FingerIdx = ptProp.Id;
                            touch.TouchEvent.ToolType = (EngineNS.Input.Device.TouchDevice.enToolType)e.GetToolType(e.ActionIndex);
                            EngineNS.CEngine.Instance.InputServerInstance.OnInputEvnet(touch);
                            mPointerPropPool.ReleaseObject(ptProp);
                        }
                        break;
                    case Android.Views.MotionEventActions.Up:
                    case Android.Views.MotionEventActions.PointerUp:
                        {
                            var ptProp = mPointerPropPool.QueryObjectSync();
                            e.GetPointerProperties(e.ActionIndex, ptProp);
                            if(ptProp.Id >= Input.InputServer.MaxMultiTouchNumber)
                            {
                                mPointerPropPool.ReleaseObject(ptProp);
                                return;
                            }

                            mStartX[ptProp.Id] = e.GetX(e.ActionIndex);
                            mStartY[ptProp.Id] = e.GetY(e.ActionIndex);

                            var touch = mTouchArgs[ptProp.Id];
                            if (touch == null)
                            {
                                touch = new EngineNS.Input.Device.TouchDevice.TouchInputEventArgs();
                                mTouchArgs[ptProp.Id] = touch;
                            }
                            touch.TouchEvent.State = Input.Device.TouchDevice.enTouchState.Up;
                            touch.TouchEvent.PosX = mStartX[ptProp.Id];
                            touch.TouchEvent.PosY = mStartY[ptProp.Id];
                            touch.TouchEvent.FingerIdx = ptProp.Id;
                            touch.TouchEvent.ToolType = (EngineNS.Input.Device.TouchDevice.enToolType)e.GetToolType(e.ActionIndex);
                            EngineNS.CEngine.Instance.InputServerInstance.OnInputEvnet(touch);
                            mPointerPropPool.ReleaseObject(ptProp);
                        }
                        break;
                    case Android.Views.MotionEventActions.Move:
                        {
                            var ptProp = mPointerPropPool.QueryObjectSync();
                            for(int acindex = 0; acindex < e.PointerCount; acindex++)
                            {
                                e.GetPointerProperties(acindex, ptProp);
                                if (ptProp.Id >= Input.InputServer.MaxMultiTouchNumber)
                                    continue;

                                float x = e.GetX(acindex);
                                float y = e.GetY(acindex);
                                var deltaX = x - mStartX[ptProp.Id];
                                var deltaY = y - mStartY[ptProp.Id];
                                mStartX[ptProp.Id] = x;
                                mStartY[ptProp.Id] = y;

                                // 去除微小抖动
                                if (System.Math.Abs(deltaX) < 0.5f && System.Math.Abs(deltaY) < 0.5f)
                                    continue;

                                var touch = mTouchArgs[ptProp.Id];
                                if (touch == null)
                                {
                                    touch = new EngineNS.Input.Device.TouchDevice.TouchInputEventArgs();
                                    mTouchArgs[ptProp.Id] = touch;
                                }
                                touch.TouchEvent.State = Input.Device.TouchDevice.enTouchState.Move;
                                touch.TouchEvent.PosX = x;
                                touch.TouchEvent.PosY = y;
                                touch.TouchEvent.DeltaX = deltaX;
                                touch.TouchEvent.DeltaY = deltaY;
                                touch.TouchEvent.FingerIdx = ptProp.Id;
                                touch.TouchEvent.ToolType = (EngineNS.Input.Device.TouchDevice.enToolType)e.GetToolType(acindex);
                                EngineNS.CEngine.Instance.InputServerInstance.OnInputEvnet(touch);
                            }
                            mPointerPropPool.ReleaseObject(ptProp);
                        }
                        break;
                }
            }
            catch(System.Exception)
            {

            }
        }
        // ===========================================================
        // Getter & Setter
        // ===========================================================

        // ===========================================================
        // Methods for/from SuperClass/Interfaces
        // ===========================================================

        public override bool OnHandleMotionEvent(MotionEvent pMotionEvent)
        {
            //return this.fireTouchEvent(pMotionEvent.getX(), pMotionEvent.getY(), pMotionEvent.getAction(), 0, pMotionEvent);
            return(this.FireTouchEvent(pMotionEvent.GetX(), pMotionEvent.GetY(), pMotionEvent.Action, 0, pMotionEvent));
        }