コード例 #1
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            float currentX = e.GetX();
            float currentY = e.GetY();

            switch (e.Action)
            {
            case MotionEventActions.Down:
                path.MoveTo(currentX, currentY);

                previousX = currentX;
                previouxY = currentY;
                return(true);

            case MotionEventActions.Move:
            case MotionEventActions.Up:
                for (int i = 0; i < e.HistorySize; i++)
                {
                    float historicalX = e.GetHistoricalX(i);
                    float historicalY = e.GetHistoricalY(i);
                    path.LineTo(historicalX, historicalY);
                }
                path.LineTo(currentX, currentY);

                Invalidate();

                previousX = currentX;
                previouxY = currentY;
                return(true);

            default:
                return(false);
            }
        }
コード例 #2
0
        //Iterate through the touch history since the last touch event and add them to the path and points list.
        void handleTouch(MotionEvent e)
        {
            float touchX = e.GetX();
            float touchY = e.GetY();

            System.Drawing.PointF touch = new System.Drawing.PointF(touchX, touchY);

            resetBounds(touchX, touchY);

            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                System.Drawing.PointF historical = new System.Drawing.PointF(historicalX, historicalY);

                updateBounds(historicalX, historicalY);

                currentPath.LineTo(historicalX, historicalY);
                currentPoints.Add(historical);
            }

            currentPath.LineTo(touchX, touchY);
            currentPoints.Add(touch);
        }
コード例 #3
0
ファイル: InkPresenter.cs プロジェクト: branux/SignaturePad
        private void TouchesMoved(MotionEvent e, bool update = true)
        {
            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                // update the dirty rectangle
                UpdateBounds(historicalX, historicalY);

                // add it to the current path
                currentPath.Path.LineTo(historicalX, historicalY);
                currentPath.GetPoints().Add(new System.Drawing.PointF(historicalX, historicalY));
            }

            float touchX = e.GetX();
            float touchY = e.GetY();

            // add it to the current path
            currentPath.Path.LineTo(touchX, touchY);
            currentPath.GetPoints().Add(new System.Drawing.PointF(touchX, touchY));

            // update the dirty rectangle
            UpdateBounds(touchX, touchY);
            if (update)
            {
                Invalidate(DirtyRect);
            }
        }
コード例 #4
0
        private void ApplyHeaderPadding(MotionEvent ev)
        {
            int pointerCount = ev.HistorySize;

            for (int p = 0; p < pointerCount; p++)
            {
                if (mRefreshState == RELEASE_TO_REFRESH)
                {
                    if (VerticalFadingEdgeEnabled)
                    {
                        VerticalScrollBarEnabled = false;
                    }

                    int historicalY = (int)ev.GetHistoricalY(p);
                    int topPadding  = (int)(((historicalY - mLastMotionY)
                                             - mRefreshViewHeight) / 1.7);

                    mRefreshView.SetPadding(
                        mRefreshView.PaddingLeft,
                        topPadding,
                        mRefreshView.PaddingRight,
                        mRefreshView.PaddingBottom);
                }
            }
        }
コード例 #5
0
ファイル: InkView.cs プロジェクト: tonyshark1/WritePadSDK
        public override bool OnTouchEvent(MotionEvent ev)
        {
            float x = ev.GetX();
            float y = ev.GetY();

            switch (ev.Action)
            {
            case MotionEventActions.Down:
                touch_start(x, y);
                Invalidate();
                break;

            case MotionEventActions.Move:
                for (int i = 0, n = ev.HistorySize; i < n; i++)
                {
                    touch_move(ev.GetHistoricalX(i), ev.GetHistoricalY(i));
                }
                touch_move(x, y);
                Invalidate();
                break;

            case MotionEventActions.Up:
                touch_up(x, y);
                Invalidate();
                break;
            }
            return(true);
        }
コード例 #6
0
        private void handleMouseMoveRelativeEvent(MotionEvent evt)
        {
            for (int i = 0; i < evt.HistorySize; i++)
            {
                handleMouseMoveRelative(new Vector2(evt.GetHistoricalX(i), evt.GetHistoricalY(i)));
            }

            handleMouseMoveRelative(new Vector2(evt.GetX(), evt.GetY()));
        }
コード例 #7
0
        private void TouchesMoved(MotionEvent e, bool update = true)
        {
            // something may have happened (clear) so start the stroke again
            if (currentPath == null)
            {
                TouchesBegan(e);
            }

            var hasMoved = false;

            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                if (HasMovedFarEnough(currentPath, historicalX, historicalY))
                {
                    // update the dirty rectangle
                    UpdateBounds(historicalX, historicalY);
                    hasMoved = true;

                    // add it to the current path
                    currentPath.Path.LineTo(historicalX, historicalY);
                }

                currentPath.GetPoints().Add(new InkPoint(
                                                new System.Drawing.PointF(historicalX, historicalY),
                                                e.GetHistoricalPressure(i),
                                                null,
                                                TimeSpan.FromMilliseconds(e.GetHistoricalEventTime(i))));
            }

            float touchX = e.GetX();
            float touchY = e.GetY();

            if (HasMovedFarEnough(currentPath, touchX, touchY))
            {
                // add it to the current path
                currentPath.Path.LineTo(touchX, touchY);

                // update the dirty rectangle
                UpdateBounds(touchX, touchY);
                hasMoved = true;
            }

            currentPath.GetPoints().Add(new InkPoint(
                                            new System.Drawing.PointF(touchX, touchY),
                                            e.Pressure,
                                            null,
                                            TimeSpan.FromMilliseconds(e.EventTime)));

            if (update && hasMoved)
            {
                Invalidate(DirtyRect);
            }
        }
コード例 #8
0
        private void handleMouseMoveEvent(MotionEvent evt)
        {
            // https://developer.android.com/reference/android/View/MotionEvent#batching
            for (int i = 0; i < evt.HistorySize; i++)
            {
                handleMouseMove(new Vector2(evt.GetHistoricalX(i), evt.GetHistoricalY(i)));
            }

            handleMouseMove(new Vector2(evt.RawX, evt.RawY));
        }
コード例 #9
0
        private void handleMouseMoveEvent(MotionEvent evt)
        {
            // https://developer.android.com/reference/android/View/MotionEvent#batching
            for (int i = 0; i < evt.HistorySize; i++)
            {
                handleMouseMove(new Vector2(evt.GetHistoricalX(i), evt.GetHistoricalY(i)));
            }

            handleMouseMove(new Vector2(evt.GetX(), evt.GetY()));

            absolutePositionReceived = true;

            // we may lose pointer capture if we lose focus / the app goes to the background,
            // so we use this opportunity to update capture if the user has requested it.
            updatePointerCapture();
        }
コード例 #10
0
        //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
        //ORIGINAL LINE: public float getHistoricalValue(@Nullable final android.view.MotionEvent event, final int index)
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        public float GetHistoricalValue(MotionEvent @event, int index)
        {
            if (@event != null)
            {
                switch (innerEnumValue)
                {
                case InnerEnum.X:
                    return(@event.GetHistoricalX(index));

                case InnerEnum.Y:
                    return(@event.GetHistoricalY(index));

                default:
                    return(0);
                }
            }

            return(0);
        }
コード例 #11
0
        internal void TrackMotionDirections(MotionEvent e)
        {
            if (!_shouldRecalibrateFlingVelocity)
            {
                return;
            }

            switch (e.Action)
            {
            case MotionEventActions.Down:
                _deltaX = _deltaY = null;
                SaveCurrentCoordinates();
                break;

            case MotionEventActions.Move:
                ComputeMotionDirections();
                SaveCurrentCoordinates();
                break;

            case MotionEventActions.Up:
                // Note that ACTION_UP and ACTION_POINTER_UP always report the last known position
                // of the pointers that went up. -- VelocityTracker.cpp
                // Ignoring this one, since trying to compute directions here will always return 0s.
                break;

            case MotionEventActions.Cancel:
                _deltaX = _deltaY = null;
                break;
            }

            void SaveCurrentCoordinates()
            {
                _previousX = e.GetX();
                _previousY = e.GetY();
            }

            void ComputeMotionDirections()
            {
                _deltaX = e.GetX() - (e.HistorySize > 0 ? e.GetHistoricalX(e.HistorySize - 1) : _previousX);
                _deltaY = e.GetY() - (e.HistorySize > 0 ? e.GetHistoricalY(e.HistorySize - 1) : _previousY);
            }
        }
コード例 #12
0
        private void TouchesMoved(MotionEvent e, bool update = true)
        {
            // something may have happened (clear) so start the stroke again
            if (currentPath == null)
            {
                TouchesBegan(e);
            }

            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                if (HasMovedFarEnough(currentPath, historicalX, historicalY))
                {
                    // update the dirty rectangle
                    UpdateBounds(historicalX, historicalY);

                    // add it to the current path
                    currentPath.Path.LineTo(historicalX, historicalY);
                    currentPath.GetPoints().Add(new System.Drawing.PointF(historicalX, historicalY));
                }
            }

            float touchX = e.GetX();
            float touchY = e.GetY();

            if (HasMovedFarEnough(currentPath, touchX, touchY))
            {
                // add it to the current path
                currentPath.Path.LineTo(touchX, touchY);
                currentPath.GetPoints().Add(new System.Drawing.PointF(touchX, touchY));

                // update the dirty rectangle
                UpdateBounds(touchX, touchY);
                if (update)
                {
                    Invalidate(DirtyRect);
                }
            }
        }
コード例 #13
0
ファイル: AndroidGameView.cs プロジェクト: Milstein/GameStack
        public override bool OnTouchEvent(MotionEvent e)
        {
            var spos = new Vector2(e.GetX(), _size.Y - e.GetY());
            var pos  = this.NormalizeToViewport(spos);

            switch (e.Action)
            {
            case MotionEventActions.Down:
                _queue.Enqueue(new Touch(TouchState.Start, pos, spos));
                break;

            case MotionEventActions.Up:
                _queue.Enqueue(new Touch(TouchState.End, pos, spos));
                break;

            case MotionEventActions.Move:
                for (var i = 0; i < e.HistorySize; i++)
                {
                    var shpos = new Vector2(e.GetHistoricalX(i), _size.Y - e.GetHistoricalY(i));
                    var hpos  = this.NormalizeToViewport(shpos);
                    _queue.Enqueue(new Touch(TouchState.Move, hpos, shpos));
                }
                _queue.Enqueue(new Touch(TouchState.Move, pos, spos));
                break;

            case MotionEventActions.Cancel:
                _queue.Enqueue(new Touch(TouchState.Cancel, pos, spos));
                break;

            default:
                break;
            }
            if (_gestureDetector != null)
            {
                _gestureDetector.OnTouchEvent(e);
            }
            return(true);
        }
コード例 #14
0
            public override bool OnTrackballEvent(MotionEvent e)
            {
                MotionEventActions action = e.ActionMasked;

                if (action == MotionEventActions.Down)
                {
                    // Advance color when the trackball button is pressed.
                    AdvanceColor();
                }

                if (action == MotionEventActions.Down || action == MotionEventActions.Move)
                {
                    int   N      = e.HistorySize;
                    float scaleX = e.XPrecision * TRACKBALL_SCALE;
                    float scaleY = e.YPrecision * TRACKBALL_SCALE;
                    for (int i = 0; i < N; i++)
                    {
                        MoveTrackball(e.GetHistoricalX(i) * scaleX,
                                      e.GetHistoricalY(i) * scaleY);
                    }
                    MoveTrackball(e.GetX() * scaleX, e.GetY() * scaleY);
                }
                return(true);
            }
コード例 #15
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            var hist   = 0.0f;
            var deltaY = 0.0f;
            var listY  = 0.0f;

            _historyEvent = ev;
            vT.AddMovement(ev);
            if (_overscrolling)
            {
                var firstOverscroll = _firstOverscroll;
                _firstOverscroll = false;
                if (ev.Action == MotionEventActions.Move && ev.HistorySize >= 1)
                {
                    hist   = ev.GetHistoricalY(0, 0);
                    deltaY = ev.GetY() - hist;
                    listY  = _listView.GetY();

                    if (_header != null)
                    {
                        var headerY = _header.GetY();
                        if (deltaY > 0)
                        {
                            if ((int)Math.Ceiling(headerY) == (0))
                            {
                                return(_listView.DispatchTouchEvent(ev));
                            }

                            if (headerY + deltaY <= (0))
                            {
                                UpdateHeaderPosition(deltaY);
                                _listView.SetY(_listView.GetY() + deltaY);
                                _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height + deltaY);
                                _listView.Invalidate();
                                return(true);
                            }
                            if (headerY + deltaY > 0)
                            {
                                deltaY = 0 - headerY;
                                UpdateHeaderPosition(0 - headerY);
                                _listView.SetY(_listView.GetY() + deltaY);
                                _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height + deltaY);
                                _listView.Invalidate();
                                return(true);
                            }
                        }
                        if (deltaY < 0)
                        {
                            _overscrolling = false;
                        }
                    }


                    if (listY + deltaY <= 0)
                    {
                        deltaY         = 0 - listY;
                        _overscrolling = false;
                    }
                    else if (deltaY > 0)
                    {
                        deltaY *= 0.4f;
                    }
                    Log.Info("OverScrollingIntercept", "{0}", deltaY);
                    _listView.SetY(_listView.GetY() + deltaY);
                    _lastHistory = ev.HistorySize;
                }
                else if (ev.Action == MotionEventActions.Up)
                {
                    _overscrolling = false;
                    _lastHistory   = 0;
                    _listView.Animate().Y(_header != null ? _header.Height : 0.0f).SetDuration(250).Start();
                }


                Log.Info("Interceptor", "Overscrolling True");
                return(true);
            }
            var hitRect = new Rect();

            _header.GetHitRect(hitRect);

            if (hitRect.Contains((int)Math.Ceiling(ev.GetX()), (int)Math.Ceiling(ev.GetY())))
            {
                return(_header.DispatchTouchEvent(ev));
            }
            else
            {
                if (_header != null)
                {
                    var headerY = _header.GetY();
                    if (ev.Action == MotionEventActions.Move && ev.HistorySize >= 1)
                    {
                        hist   = ev.GetHistoricalY(0, 0);
                        deltaY = ev.GetY() - hist;

                        if (deltaY < 0)
                        {
                            if ((int)Math.Ceiling(headerY) == (0 - _header.Height))
                            {
                                return(_listView.DispatchTouchEvent(ev));
                            }

                            if (headerY + deltaY >= (0 - _header.Height))
                            {
                                UpdateHeaderPosition(deltaY);
                                _listView.SetY(_listView.GetY() + deltaY);
                                _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height - deltaY);
                                _listView.RequestLayout();
                                return(true);
                            }
                            else if (headerY + deltaY < (0 - _header.Height))
                            {
                                deltaY = 0 - (headerY + _header.Height);
                                UpdateHeaderPosition(deltaY);
                                _listView.SetY(_listView.GetY() + deltaY);
                                _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height - deltaY);
                                _listView.RequestLayout();
                                _listView.DispatchTouchEvent(ev);
                                return(true);
                            }
                        }
                        _listView.DispatchTouchEvent(ev);
                        return(true);
                    }
                    else if (ev.Action == MotionEventActions.Up || ev.Action == MotionEventActions.Cancel)
                    {
                        vT.ComputeCurrentVelocity(1);
                        long duration = Math.Abs((long)Math.Ceiling(Math.Abs(_header.Height) / vT.GetYVelocity(0)));

                        if (duration < 750)
                        {
                            _header.Animate()
                            .Y(0 - _header.Height)
                            .SetDuration(duration)
                            .SetInterpolator(new DecelerateInterpolator(1.0f))
                            .Start();
                            _listView.Animate()
                            .Y(0)
                            .SetDuration(duration)
                            .SetInterpolator(new DecelerateInterpolator(1.0f))
                            .Start();
                        }
                        return(_listView.DispatchTouchEvent(ev));
                    }
                }
                return(_listView.DispatchTouchEvent(ev));
            }
        }
コード例 #16
0
            bool OnTouchOrHoverEvent(MotionEvent e, bool isTouch)
            {
                MotionEventButtonState buttonState    = e.ButtonState;
                MotionEventButtonState pressedButtons = buttonState & ~mOldButtonState;

                mOldButtonState = buttonState;

                if ((pressedButtons & MotionEventButtonState.Secondary) != 0)
                {
                    // Advance color when the right mouse button or first stylus button
                    // is pressed.
                    AdvanceColor();
                }

                PaintMode mode;

                if ((buttonState & MotionEventButtonState.Tertiary) != 0)
                {
                    // Splat paint when the middle mouse button or second stylus button is pressed.
                    mode = PaintMode.Splat;
                }
                else if (isTouch || (buttonState & MotionEventButtonState.Primary) != 0)
                {
                    // Draw paint when touching or if the primary button is pressed.
                    mode = PaintMode.Draw;
                }
                else
                {
                    // Otherwise, do not paint anything.
                    return(false);
                }

                MotionEventActions action = e.ActionMasked;

                if (action == MotionEventActions.Down || action == MotionEventActions.Move ||
                    action == MotionEventActions.HoverMove)
                {
                    int N = e.HistorySize;
                    int P = e.PointerCount;
                    for (int i = 0; i < N; i++)
                    {
                        for (int j = 0; j < P; j++)
                        {
                            Paint(GetPaintModeForTool(e.GetToolType(j), mode),
                                  e.GetHistoricalX(j, i),
                                  e.GetHistoricalY(j, i),
                                  e.GetHistoricalPressure(j, i),
                                  e.GetHistoricalTouchMajor(j, i),
                                  e.GetHistoricalTouchMinor(j, i),
                                  e.GetHistoricalOrientation(j, i),
                                  e.GetHistoricalAxisValue(Axis.Distance, j, i),
                                  e.GetHistoricalAxisValue(Axis.Tilt, j, i));
                        }
                    }
                    for (int j = 0; j < P; j++)
                    {
                        Paint(GetPaintModeForTool(e.GetToolType(j), mode),
                              e.GetX(j),
                              e.GetY(j),
                              e.GetPressure(j),
                              e.GetTouchMajor(j),
                              e.GetTouchMinor(j),
                              e.GetOrientation(j),
                              e.GetAxisValue(Axis.Distance, j),
                              e.GetAxisValue(Axis.Tilt, j));
                    }
                    mCurX = e.GetX();
                    mCurY = e.GetY();
                }
                return(true);
            }
コード例 #17
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            _touchReleased = false;
            float eventX;
            float eventY;

            if (_previousWidth != 0.0)
            {
                _widthRatio = _screenWidth / _previousWidth;
            }

            if (Resources.Configuration.Orientation == Orientation.Landscape)
            {
                var x = e.GetX() / _widthRatio;
                var y = e.GetY() / _widthRatio;
                eventX = x - _newPositionOfX;
                eventY = y - newPositionOfY;
            }
            else
            {
                eventX = e.GetX();
                eventY = e.GetY();
            }

            _pathContainerOpen = true;

            if (!_autoTouchtriggered)
            {
                switch (e.Action)
                {
                case MotionEventActions.Down:
                    _path.MoveTo(eventX, eventY);
                    if (!_autoTouchtriggered)
                    {
                        if (_vectorStringData.Contains("M"))
                        {
                            _vectorStringData +=
                                " \" fill=\"none\" stroke=\"black\" stroke-width=\"1\"/>\n\"  <path d=\"";
                            _vectorStringData += $"M {eventX} {eventY}";
                        }
                        else
                        {
                            if (_vectorStringData.Contains(SvgEnd))
                            {
                                _vectorStringData = _vectorStringData.Replace(SvgEnd, "");
                            }
                            _vectorStringData = $"M {eventX} {eventY}";
                        }
                    }
                    _lastTouchX = eventX;
                    _lastTouchY = eventY;
                    return(true);

                case MotionEventActions.Move:

                case MotionEventActions.Up:
                    ResetSignatureBoundRect(eventX, eventY);
                    var historySize = e.HistorySize;

                    for (var i = 0; i < historySize; i++)
                    {
                        float historicalX;
                        float historicalY;
                        if (Resources.Configuration.Orientation == Orientation.Landscape)
                        {
                            historicalX = e.
                                          GetHistoricalX(i) / _widthRatio
                                          - _newPositionOfX;
                            historicalY        = e.GetHistoricalY(i) / _widthRatio - newPositionOfY;
                            _vectorStringData += $" L {e.GetHistoricalX(i) / _widthRatio} {e.GetHistoricalY(i) / _widthRatio}";
                        }
                        else
                        {
                            historicalX = e.
                                          GetHistoricalX(i)
                                          - _newPositionOfX;
                            historicalY = e.
                                          GetHistoricalY(i)
                                          - newPositionOfY;
                            _vectorStringData += $" L {e.GetHistoricalX(i)} {e.GetHistoricalY(i)}";
                        }
                        ExpandSignatureBoundRect(historicalX, historicalY);
                        _path.LineTo(historicalX, historicalY);
                    }

                    _path.LineTo(eventX, eventY);
                    _vectorStringData += $" L {eventX} {eventY}";
                    break;

                default:
                    return(false);
                }
            }
            else
            {
                _autoTouchtriggered = false;
            }

            _touchReleased = true;

            Invalidate((int)(_signatureBoundRect.Left - _strokeWidth / 2),
                       (int)(_signatureBoundRect.Top - _strokeWidth / 2),
                       (int)(_signatureBoundRect.Right + _strokeWidth / 2),
                       (int)(_signatureBoundRect.Bottom + _strokeWidth / 2));

            _lastTouchX = eventX;
            _lastTouchY = eventY;

            return(true);
        }