コード例 #1
0
        /**
         * Called by a {@link MotionImitator} (or another {@link
         * android.view.View.OnTouchListener}) when a {@link android.view.MotionEvent} occurs.
         *
         * @param offset
         *      the value offset
         * @param value
         *      the current value
         * @param delta
         *      the change in the value
         * @param event
         *      the motion event
         */
        protected virtual void Imitate(float offset, float value, float delta, MotionEvent ev)
        {
            if (ev != null)
            {
                switch (ev.Action)
                {
                case MotionEventActions.Down:
                    Constrain(ev);
                    break;

                case MotionEventActions.Move:
                    if (ev.HistorySize > 0)
                    {
                        Mime(offset, value, delta,
                             ev.EventTime - ev.GetHistoricalEventTime(0), ev);
                    }
                    else
                    {
                        Mime(offset, value, delta, 0, ev);
                    }
                    break;

                default:
                case MotionEventActions.Up:
                    Release(ev);
                    break;
                }
            }
        }
コード例 #2
0
        private void TouchesMoved(MotionEvent e, bool update = true)
        {
            // something may have happened (clear) so start the stroke again
            if (currentPath == null)
            {
                TouchesBegan(e);
            }

            var hasMoved = false;

            for (var i = 0; i < e.HistorySize; i++)
            {
                float historicalX = e.GetHistoricalX(i);
                float historicalY = e.GetHistoricalY(i);

                if (HasMovedFarEnough(currentPath, historicalX, historicalY))
                {
                    // update the dirty rectangle
                    UpdateBounds(historicalX, historicalY);
                    hasMoved = true;

                    // add it to the current path
                    currentPath.Path.LineTo(historicalX, historicalY);
                }

                currentPath.GetPoints().Add(new InkPoint(
                                                new System.Drawing.PointF(historicalX, historicalY),
                                                e.GetHistoricalPressure(i),
                                                null,
                                                TimeSpan.FromMilliseconds(e.GetHistoricalEventTime(i))));
            }

            float touchX = e.GetX();
            float touchY = e.GetY();

            if (HasMovedFarEnough(currentPath, touchX, touchY))
            {
                // add it to the current path
                currentPath.Path.LineTo(touchX, touchY);

                // update the dirty rectangle
                UpdateBounds(touchX, touchY);
                hasMoved = true;
            }

            currentPath.GetPoints().Add(new InkPoint(
                                            new System.Drawing.PointF(touchX, touchY),
                                            e.Pressure,
                                            null,
                                            TimeSpan.FromMilliseconds(e.EventTime)));

            if (update && hasMoved)
            {
                Invalidate(DirtyRect);
            }
        }