Beispiel #1
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            if (saving)            
                return false;

            _scaleDetector.OnTouchEvent(ev);

            switch (ev.Action)
            {
                case MotionEventActions.Down:

                    for (int i = 0; i < hightlightViews.Count; i++)
                    {
                        HighlightView hv = hightlightViews[i];
                        var edge = hv.GetHit(ev.GetX(), ev.GetY());
                        if (edge != global::Plugin.ImageCrop.HighlightView.HitPosition.None)
                        {
                            motionEdge = edge;
                            mMotionHighlightView = hv;
                            mLastX = ev.GetX();
                            mLastY = ev.GetY();
                            mMotionHighlightView.Mode =
                            (edge == global::Plugin.ImageCrop.HighlightView.HitPosition.Move)
                                ? HighlightView.ModifyMode.Move
                                : HighlightView.ModifyMode.Grow;
                            break;
                        }
                    }
                    break;

                case MotionEventActions.Up:
                    if (mMotionHighlightView != null)
                    {
                        centerBasedOnHighlightView(mMotionHighlightView);
                        mMotionHighlightView.Mode = HighlightView.ModifyMode.None;
                    }

                    mMotionHighlightView = null;
                    isScaling = false;
                    break;

                case MotionEventActions.Move:
                    if (!isScaling && mMotionHighlightView != null)
                    {
                        mMotionHighlightView.HandleMotion(motionEdge,
                                                          ev.GetX() - mLastX,
                                                          ev.GetY() - mLastY);
                        mLastX = ev.GetX();
                        mLastY = ev.GetY();

                        if (true)
                        {
                            // This section of code is optional. It has some user
                            // benefit in that moving the crop rectangle against
                            // the edge of the screen causes scrolling but it means
                            // that the crop rectangle is no longer fixed under
                            // the user's finger.
                            ensureVisible(mMotionHighlightView);
                        }
                    }
                    break;                    
            }

            switch (ev.Action)
            {
                case MotionEventActions.Up:
                    Center(true, true);
                    break;
                case MotionEventActions.Move:
                    // if we're not zoomed then there's no point in even allowing
                    // the user to move the image around.  This call to center puts
                    // it back to the normalized location (with false meaning don't
                    // animate).
                    if (GetScale() == 1F)
                    {
                        Center(true, true);
                    }
                    break;
            }

            return true;
        }