Beispiel #1
0
 public static void EnsureLongClickCancellation(this AView view, MotionEvent motionEvent, bool handled, VisualElement element)
 {
     if (motionEvent.Action == MotionEventActions.Up && handled && view.LongClickable && element.IsInViewCell())
     {
         // In order for long presses/clicks (for opening context menus) to work in a ViewCell
         // which contains any Clickable Views (e.g., any with TapGestures associated, or Buttons)
         // the top-level container in the ViewCell has to be LongClickable; unfortunately, Android
         // cancels a pending long press/click during MotionEventActions.Up, which the View won't
         // get if the gesture listener has already processed it. So when all these conditions are
         // true, we need to go ahead and send the Up event to the View; if we don't, the context menu will open
         view.OnTouchEvent(motionEvent);
     }
 }
        public bool OnTouch(Android.Views.View v, MotionEvent e)
        {
            v.OnTouchEvent(e);
            var imm = (InputMethodManager)v.Context.GetSystemService(Android.Content.Context.InputMethodService);

            if (imm != null)
            {
                imm.HideSoftInputFromWindow(v.WindowToken, 0);
            }

            if (e.EventTime == StrangeEventTime)
            {
                SetSelection();
                ClearFocus();
            }
            else
            {
                Utils.LastSelection = Control.SelectionStart;
            }

            return(true);
        }
 public bool OnTouch(View v, MotionEvent e)
 {
     switch (e.Action)
     {
     case MotionEventActions.Down:
         lastPositionX = e.GetX ();
         Log.Debug ("Touch position: " , lastPositionX+"");
         return true;
     case MotionEventActions.Move:
         var currentPositionX = e.GetX ();
         Log.Debug ("Touch position: " , currentPositionX+"");
         var delta = currentPositionX - lastPositionX;
         Log.Debug ("Touch delta: " , delta+"");
         var translation = v.TranslationX;
         translation -= delta;
         if (translation < 0)
             translation = 0;
         v.TranslationX = translation;
         return true;
     default:
         return v.OnTouchEvent (e);
     }
 }
        private bool handleMoveEvent(View view, MotionEvent motionEvent) {
        if (mVelocityTracker == null || mCurrentView == null) {
            return false;
        }

        mVelocityTracker.AddMovement(motionEvent);

        float deltaX = motionEvent.GetX() - mDownX;
        float deltaY = motionEvent.GetY() - mDownY;

        if (Math.Abs(deltaX) > mSlop && Math.Abs(deltaX) > Math.Abs(deltaY)) {
            if (!mSwiping) {
                mActiveSwipeCount++;
                onStartSwipe(mCurrentView, mCurrentPosition);
            }
            mSwiping = true;
            mListViewWrapper.getListView().RequestDisallowInterceptTouchEvent(true);

            /* Cancel ListView's touch (un-highlighting the item) */
            if (view != null) {
                MotionEvent cancelEvent = MotionEvent.Obtain(motionEvent);

                int mode = (int)MotionEventActions.Cancel | (motionEvent.ActionIndex << (int)MotionEventActions.PointerIndexShift);
                cancelEvent.Action=(MotionEventActions)mode;
                view.OnTouchEvent(cancelEvent);
                cancelEvent.Recycle();
            }
        }

        if (mSwiping) {
            if (mCanDismissCurrent) {
                //ViewHelper.setTranslationX(mSwipingView, deltaX);
				mSwipingView.TranslationX=deltaX;                
                //ViewHelper.setAlpha(mSwipingView, Math.Max(mMinimumAlpha, Math.Min(1, 1 - 2 * Math.Abs(deltaX) / mViewWidth)));
			    mSwipingView.Alpha=Math.Max(mMinimumAlpha, Math.Min(1, 1 - 2 * Math.Abs(deltaX) / mViewWidth));

            } else {
                //ViewHelper.setTranslationX(mSwipingView, deltaX * 0.1f);
				mSwipingView.TranslationX= deltaX * 0.1f;
            }
            return true;
        }
        return false;
    }
        private bool handleDownEvent(View view, MotionEvent motionEvent)
        {
            if (!mSwipeEnabled)
            {
                return false;
            }

            View downView = findDownView(motionEvent);
            if (downView == null)
            {
                return false;
            }

            int downPosition = AdapterViewUtil.getPositionForView(mListViewWrapper, downView);
            mCanDismissCurrent = isDismissable(downPosition);

            /* Check if we are processing the item at this position */
            if (mCurrentPosition == downPosition || downPosition >= mVirtualListCount)
            {
                return false;
            }

            if (view != null)
            {
                view.OnTouchEvent(motionEvent);
            }

            disableHorizontalScrollContainerIfNecessary(motionEvent, downView);

            mDownX = motionEvent.GetX();
            mDownY = motionEvent.GetY();

            mCurrentView = downView;
            mSwipingView = getSwipeView(downView);
            mCurrentPosition = downPosition;

            mVelocityTracker = VelocityTracker.Obtain();
            mVelocityTracker.AddMovement(motionEvent);
            return true;
        }
        public bool OnTouch(View v, MotionEvent e)
        {
            switch (e.Action) {
            case MotionEventActions.Down:

                layoutLastPosY = e.GetY ();
                return true;

            case MotionEventActions.Move:

                var currentPosition = e.GetY ();
                var deltaY = layoutLastPosY - currentPosition;

                var transY = v.TranslationY;

                transY -= deltaY;

                if (transY < 0) {
                    transY = 0;
                }

                v.TranslationY = transY;

                return true;

            default:
                return v.OnTouchEvent (e);
            }
        }