예제 #1
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            SwipeMenuLayout layout = null;

            if (convertView == null)
            {
                View      contentView = mAdapter.GetView(position, convertView, parent);
                SwipeMenu menu        = new SwipeMenu(mContext);
                menu.ViewType = mAdapter.GetItemViewType(position);
                CreateMenu(menu);
                Cooksts.Droid.SWipeMenuList.SwipeListView listview = (Cooksts.Droid.SWipeMenuList.SwipeListView)parent;
                SwipeMenuView menuView = new SwipeMenuView(menu, listview);
                menuView.ItemClickListener = this;
                layout = new SwipeMenuLayout(contentView, menuView,
                                             listview.CloseInterpolator,
                                             listview.OpenInterpolator);
                layout.Position = position;
            }
            else
            {
                layout = (SwipeMenuLayout)convertView;
                layout.CloseMenu();
                layout.Position = position;
                View view = mAdapter.GetView(position, layout.ContentView, parent);
            }
            return(layout);
        }
예제 #2
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (!(e.Action != MotionEventActions.Down && mTouchView == null))
            {
                switch (e.Action)
                {
                case MotionEventActions.Down:
                {
                    int oldPos = mTouchPosition;
                    mDownX      = e.RawX;
                    mDownY      = e.RawY;
                    mTouchState = TOUCH_STATE_NONE;

                    mTouchPosition = PointToPosition((int)e.GetX(), (int)e.GetY());

                    if (mTouchPosition == oldPos && mTouchView != null &&
                        mTouchView.IsOpen())
                    {
                        mTouchState = TOUCH_STATE_X;
                        mTouchView.OnSwipe(e);
                        return(true);
                    }

                    View view = GetChildAt(mTouchPosition - FirstVisiblePosition);

                    if (mTouchView != null && mTouchView.IsOpen())
                    {
                        mTouchView.SmoothCloseMenu();
                        mTouchView = null;

                        MotionEvent cancelEvent = MotionEvent.Obtain(e);
                        cancelEvent.Action = MotionEventActions.Cancel;
                        OnTouchEvent(cancelEvent);
                        return(true);
                    }
                    if (view is SwipeMenuLayout)
                    {
                        mTouchView = (SwipeMenuLayout)view;
                    }
                    if (mTouchView != null)
                    {
                        mTouchView.OnSwipe(e);
                    }
                }
                break;

                case MotionEventActions.Move:
                {
                    float dy = Math.Abs(e.RawY - mDownY);
                    float dx = Math.Abs(e.RawX - mDownX);
                    if (mTouchState == TOUCH_STATE_X)
                    {
                        if (mTouchView != null)
                        {
                            mTouchView.OnSwipe(e);
                        }
                        Selector.SetState(new int[] { 0 });
                        e.Action = MotionEventActions.Cancel;
                        base.OnTouchEvent(e);
                        return(true);
                    }
                    else if (mTouchState == TOUCH_STATE_NONE)
                    {
                        if (Math.Abs(dy) > MAX_Y)
                        {
                            mTouchState = TOUCH_STATE_Y;
                        }
                        else if (dx > MAX_X)
                        {
                            mTouchState = TOUCH_STATE_X;
                            if (mOnSwipeListener != null)
                            {
                                mOnSwipeListener.OnSwipeStart(mTouchPosition);
                            }
                        }
                    }
                }
                break;

                case MotionEventActions.Up:
                {
                    if (mTouchState == TOUCH_STATE_X)
                    {
                        mTouchView.OnSwipe(e);
                        if (!mTouchView.IsOpen())
                        {
                            mTouchPosition = -1;
                            mTouchView     = null;
                        }
                        if (mOnSwipeListener != null)
                        {
                            mOnSwipeListener.OnSwipeEnd(mTouchPosition);
                        }
                        e.Action = MotionEventActions.Cancel;
                        base.OnTouchEvent(e);
                        return(true);
                    }
                }
                break;
                }
            }
            //if (mTouchState != TOUCH_STATE_X)
            //{
            //    return (Parent as ViewWrapper).OnTouchEvent(e) || IgnoreTouchEvents || base.OnTouchEvent(e);
            //}
            //else
            //{
            return(base.OnTouchEvent(e));
            //}
        }