示例#1
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            //return base.OnTouchEvent(e);
            int  action          = MotionEventCompat.GetActionMasked(e);
            bool isStickerOnEdit = true;

            switch (action)
            {
            case (int)MotionEventActions.Down:
                downX = e.GetX();
                downY = e.GetY();
                if (sticker == null)
                {
                    return(false);
                }
                if (removeIcon.isInActionCheck(e))
                {
                    if (listener != null)
                    {
                        listener.onDelete(this);
                    }
                }
                else if (rotateIcon.isInActionCheck(e))
                {
                    mode = (int)ActionMode.ROTATE;
                    downMatrix.Set(sticker.getMatrix());
                    imageMidPoint = sticker.getImageMidPoint(downMatrix);
                    oldRotation   = sticker.getSpaceRotation(e, imageMidPoint);
                    Log.Debug("onTouchEvent", "Rotate gesture");
                }
                else if (zoomIcon.isInActionCheck(e))
                {
                    mode = (int)ActionMode.ZOOM_SINGLE;
                    downMatrix.Set(sticker.getMatrix());
                    imageMidPoint = sticker.getImageMidPoint(downMatrix);
                    oldDistance   = sticker.getSingleTouchDistance(e, imageMidPoint);
                    Log.Debug("onTouchEvent", "Single point zoom gesture");
                }

                else if (isInStickerArea(sticker, e))
                {
                    mode = (int)ActionMode.TRANS;
                    downMatrix.Set(sticker.getMatrix());
                    Log.Debug("onTouchEvent", "Pan gesture");
                }
                else
                {
                    isStickerOnEdit = false;
                }
                break;

            case (int)MotionEventActions.PointerDown:
                mode        = (int)ActionMode.ZOOM_MULTI;
                oldDistance = sticker.getMultiTouchDistance(e);
                midPoint    = sticker.getMidPoint(e);
                downMatrix.Set(sticker.getMatrix());
                break;

            case (int)MotionEventActions.Move:
                if (mode == (int)ActionMode.ROTATE)
                {
                    moveMatrix.Set(downMatrix);
                    float deltaRotation = sticker.getSpaceRotation(e, imageMidPoint) - oldRotation;
                    moveMatrix.PostRotate(deltaRotation, imageMidPoint.X, imageMidPoint.Y);
                    sticker.getMatrix().Set(moveMatrix);
                    Invalidate();
                }
                else if (mode == (int)ActionMode.ZOOM_SINGLE)
                {
                    moveMatrix.Set(downMatrix);
                    float scale = sticker.getSingleTouchDistance(e, imageMidPoint) / oldDistance;
                    moveMatrix.PostScale(scale, scale, imageMidPoint.X, imageMidPoint.Y);
                    sticker.getMatrix().Set(moveMatrix);
                    Invalidate();
                }
                else if (mode == (int)ActionMode.ZOOM_MULTI)
                {
                    moveMatrix.Set(downMatrix);
                    float scale = sticker.getMultiTouchDistance(e) / oldDistance;
                    moveMatrix.PostScale(scale, scale, midPoint.X, midPoint.Y);
                    sticker.getMatrix().Set(moveMatrix);
                    Invalidate();
                }
                else if (mode == (int)ActionMode.TRANS)
                {
                    moveMatrix.Set(downMatrix);
                    moveMatrix.PostTranslate(e.GetX() - downX, e.GetY() - downY);
                    sticker.getMatrix().Set(moveMatrix);
                    Invalidate();
                }
                break;

            case (int)MotionEventActions.PointerUp:
            case (int)MotionEventActions.Up:
                mode          = (int)ActionMode.NONE;
                midPoint      = null;
                imageMidPoint = null;
                break;

            default:
                break;
            }
            if (isStickerOnEdit && listener != null)
            {
                listener.onEdit(this);
            }
            return(isStickerOnEdit);
        }