Ejemplo n.º 1
0
        // According to the event's position, change the focus to the first
        // hitting cropping rectangle.
        private void RecomputeFocus(MotionEvent e)
        {
            int count = this.MotionHighlightViews.Count;

            for (int i = 0; i < count; i++)
            {
                EmHighlightView hv = this.MotionHighlightViews [i];
                hv.Focused = false;
                hv.Invalidate();
            }

            for (int i = 0; i < count; i++)
            {
                EmHighlightView hv   = this.MotionHighlightViews [i];
                int             edge = hv.GetHit(e.GetX(), e.GetY());
                if (edge != HighlightView.GrowNone)
                {
                    if (!hv.Focused)
                    {
                        hv.Focused = true;
                        hv.Invalidate();
                    }
                    break;
                }
            }

            this.Invalidate();
        }
Ejemplo n.º 2
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            EmCropImage cropImage = (EmCropImage)this.Context;

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

            switch (e.Action)
            {
            case MotionEventActions.Down:
            {
                if (cropImage.WaitingToPick)
                {
                    RecomputeFocus(e);
                }
                else
                {
                    for (int i = 0; i < this.MotionHighlightViews.Count; i++)
                    {
                        EmHighlightView hv   = this.MotionHighlightViews [i];
                        int             edge = hv.GetHit(e.GetX(), e.GetY());
                        if (edge != HighlightView.GrowNone)
                        {
                            this.MotionEdge          = edge;
                            this.MotionHighlightView = hv;
                            this.LastX = e.GetX();
                            this.LastY = e.GetY();
                            this.MotionHighlightView.SetMode(
                                (edge == EmHighlightView.MOVE)
                                                                        ? EmHighlightView.ModifyMode.Move
                                                                        : EmHighlightView.ModifyMode.Grow);
                            break;
                        }
                    }
                }

                break;
            }

            case MotionEventActions.Up:
            {
                if (cropImage.WaitingToPick)
                {
                    for (int i = 0; i < this.MotionHighlightViews.Count; i++)
                    {
                        EmHighlightView hv = this.MotionHighlightViews [i];
                        if (hv.Focused)
                        {
                            cropImage.MCrop = hv;
                            for (int j = 0; j < this.MotionHighlightViews.Count; j++)
                            {
                                if (j == i)
                                {
                                    continue;
                                }
                                this.MotionHighlightViews [j].Hidden = true;
                            }

                            CenterBasedOnHighlightView(hv);
                            ((EmCropImage)this.Context).WaitingToPick = false;
                            return(true);
                        }
                    }
                }
                else
                {
                    if (this.MotionHighlightView != null)
                    {
                        CenterBasedOnHighlightView(this.MotionHighlightView);
                        this.MotionHighlightView.SetMode(EmHighlightView.ModifyMode.None);
                    }
                }

                this.MotionHighlightView = null;
                break;
            }

            case MotionEventActions.Move:
            {
                if (cropImage.WaitingToPick)
                {
                    RecomputeFocus(e);
                }
                else
                {
                    if (this.MotionHighlightView != null)
                    {
                        this.MotionHighlightView.HandleMotion(this.MotionEdge,
                                                              e.GetX() - this.LastX,
                                                              e.GetY() - this.LastY);
                        this.LastX = e.GetX();
                        this.LastY = e.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(this.MotionHighlightView);
                        }
                    }
                }
                break;
            }
            }

            switch (e.Action)
            {
            case MotionEventActions.Up:
            {
                this.Center(true, true);
                break;
            }

            case MotionEventActions.Move:
            {
                if (this.GetScale() == 1f)
                {
                    Center(true, true);
                }
                break;
            }
            }

            return(true);
        }