Example #1
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            CropImageActivity cropImage = (CropImageActivity)context;

            if (cropImage.Saving)
            {
                return(false);
            }

            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::com.bytewild.imaging.cropping.HighlightView.HitPosition.None)
                    {
                        motionEdge           = edge;
                        mMotionHighlightView = hv;
                        mLastX = ev.GetX();
                        mLastY = ev.GetY();
                        mMotionHighlightView.Mode =
                            (edge == global::com.bytewild.imaging.cropping.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;
                break;

            case MotionEventActions.Move:
                if (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);
        }