Beispiel #1
0
            public Fling(ScaleImageView view, int velocityX, int velocityY)
            {
                try
                {
                    _view = view;
                    view.SetState(TouchState.Fling);
                    _scroller = new Scroller(view._context);
                    view._matrix.GetValues(view._m);

                    var startX = (int)view._m[Matrix.MtransX];
                    var startY = (int)view._m[Matrix.MtransY];
                    int minX, maxX, minY, maxY;

                    if (view.GetImageWidth() > view.ViewWidth)
                    {
                        minX = view.ViewWidth - (int)view.GetImageWidth();
                        maxX = 0;
                    }
                    else
                    {
                        minX = maxX = startX;
                    }
                    if (view.GetImageHeight() > view.ViewHeight)
                    {
                        minY = view.ViewHeight - (int)view.GetImageHeight();
                        maxY = 0;
                    }
                    else
                    {
                        minY = maxY = startY;
                    }
                    _scroller.Fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY);
                    _currX = startX;
                    _currY = startY;
                }
                catch (System.Exception ex)
                {
                    AppSettings.Logger.Warning(ex);
                }
            }
Beispiel #2
0
            public bool OnTouch(View v, MotionEvent evt)
            {
                _view._touchListener?.OnTouch(v, evt); // User-defined handler, maybe
                _view._scaleDetector?.OnTouchEvent(evt);
                _view._gestureDetector?.OnTouchEvent(evt);
                var currentX = evt.GetX();
                var currentY = evt.GetY();

                if (_view._state == TouchState.None || _view._state == TouchState.Drag || _view._state == TouchState.Fling)
                {
                    switch (evt.Action)
                    {
                    case MotionEventActions.Down:
                        _lastX = currentX;
                        _lastY = currentY;
                        _view._fling?.CancelFling();
                        _view.SetState(TouchState.Drag);
                        break;

                    case MotionEventActions.Move:
                        if (_view._state == TouchState.Drag)
                        {
                            var deltaX    = currentX - _lastX;
                            var deltaY    = currentY - _lastY;
                            var fixTransX = _view.GetFixDragTrans(deltaX, _view.ViewWidth, _view.GetImageWidth());
                            var fixTransY = _view.GetFixDragTrans(deltaY, _view.ViewHeight, _view.GetImageHeight());
                            _view._matrix.PostTranslate(fixTransX, fixTransY);
                            _view.FixTrans();
                            _lastX = currentX;
                            _lastY = currentY;
                        }
                        break;

                    case MotionEventActions.Up:
                    case MotionEventActions.PointerUp:
                        _view.SetState(TouchState.None);
                        break;
                    }
                }
                _view.ImageMatrix = _view._matrix;
                //
                // indicate event was handled
                //
                return(true);
            }