@Override
  public boolean onTouch(View v, MotionEvent ev) {
    if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) {
      return false;
    }

    mDetector.onTouchEvent(ev);
    if (mRemoveEnabled && mDragging && mRemoveMode == FLING_REMOVE) {
      mFlingRemoveDetector.onTouchEvent(ev);
    }

    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mCurrX = (int) ev.getX();
        mCurrY = (int) ev.getY();
        break;
      case MotionEvent.ACTION_UP:
        if (mRemoveEnabled && mIsRemoving) {
          int x = mPositionX >= 0 ? mPositionX : -mPositionX;
          int removePoint = mDslv.getWidth() / 2;
          if (x > removePoint) {
            mDslv.stopDragWithVelocity(true, 0);
          }
        }
      case MotionEvent.ACTION_CANCEL:
        mIsRemoving = false;
        mDragging = false;
        break;
    }

    return false;
  }
Beispiel #2
0
  @Override
  public boolean onTouch(View v, MotionEvent ev) {
    mDetector.onTouchEvent(ev);
    if (mRemoveEnabled
        && mDragging
        && (mRemoveMode == FLING_RIGHT_REMOVE || mRemoveMode == FLING_LEFT_REMOVE)) {
      mFlingRemoveDetector.onTouchEvent(ev);
    }

    int action = ev.getAction() & MotionEvent.ACTION_MASK;

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mCurrX = (int) ev.getX();
        mCurrY = (int) ev.getY();
        break;
      case MotionEvent.ACTION_UP:
        if (mRemoveEnabled) {
          final int x = (int) ev.getX();
          int thirdW = mDslv.getWidth() / 3;
          int twoThirdW = mDslv.getWidth() - thirdW;
          if ((mRemoveMode == SLIDE_RIGHT_REMOVE && x > twoThirdW)
              || (mRemoveMode == SLIDE_LEFT_REMOVE && x < thirdW)) {
            mDslv.stopDrag(true);
          }
        }
      case MotionEvent.ACTION_CANCEL:
        mDragging = false;
        break;
    }

    return false;
  }
 @Test
 public void canAnswerLastGestureDetector() throws Exception {
   GestureDetector newDetector = new GestureDetector(Robolectric.application, null);
   assertNotSame(newDetector, ShadowGestureDetector.getLastActiveDetector());
   newDetector.onTouchEvent(null);
   assertSame(newDetector, ShadowGestureDetector.getLastActiveDetector());
 }
  @Test
  public void getOnDoubleTapListener_shouldReturnSetDoubleTapListener() throws Exception {
    GestureDetector subject = new GestureDetector(Robolectric.application, null);
    GestureDetector.OnDoubleTapListener onDoubleTapListener =
        new GestureDetector.OnDoubleTapListener() {
          @Override
          public boolean onSingleTapConfirmed(MotionEvent e) {
            return false;
          }

          @Override
          public boolean onDoubleTap(MotionEvent e) {
            return false;
          }

          @Override
          public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
          }
        };

    subject.setOnDoubleTapListener(onDoubleTapListener);
    assertEquals(shadowOf(subject).getOnDoubleTapListener(), onDoubleTapListener);

    subject.setOnDoubleTapListener(null);
    assertEquals(shadowOf(subject).getOnDoubleTapListener(), null);
  }
  @Override
  public boolean onTouchEventInternal(MotionEvent e) {
    final int action = e.getActionMasked();

    // This path mimics the Android long press detection while still allowing
    // other touch events to come through the gesture detector.
    if (!mUseDefaultLongPress) {
      if (e.getPointerCount() > 1) {
        // If there's more than one pointer ignore the long press.
        if (mLongPressRunnable.isPending()) {
          cancelLongPress();
        }
      } else if (action == MotionEvent.ACTION_DOWN) {
        // If there was a pending event kill it off.
        if (mLongPressRunnable.isPending()) {
          cancelLongPress();
        }
        mLongPressRunnable.init(e);
        mLongPressHandler.postDelayed(mLongPressRunnable, mLongPressTimeoutMs);
      } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        cancelLongPress();
      } else if (mLongPressRunnable.isPending()) {
        // Allow for a little bit of touch slop.
        MotionEvent initialEvent = mLongPressRunnable.getInitialEvent();
        float distanceX = initialEvent.getX() - e.getX();
        float distanceY = initialEvent.getY() - e.getY();
        float distance = distanceX * distanceX + distanceY * distanceY;

        // Save a square root here by comparing to squared touch slop
        if (distance > mScaledTouchSlop * mScaledTouchSlop) {
          cancelLongPress();
        }
      }
    }

    // Sends the pinch event if two or more fingers touch the screen. According to test
    // Android handles the fingers order pretty consistently so always requesting
    // index 0 and 1 works here.
    // This might need some rework if 3 fingers event are supported.
    if (e.getPointerCount() > 1) {
      mHandler.onPinch(
          e.getX(0) * mPxToDp,
          e.getY(0) * mPxToDp,
          e.getX(1) * mPxToDp,
          e.getY(1) * mPxToDp,
          action == MotionEvent.ACTION_POINTER_DOWN);
      mDetector.setIsLongpressEnabled(false);
      mSingleInput = false;
    } else {
      mDetector.setIsLongpressEnabled(mUseDefaultLongPress);
      mSingleInput = true;
    }
    mDetector.onTouchEvent(e);

    // Propagate the up event after any gesture events.
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
      mHandler.onUpOrCancel();
    }
    return true;
  }
  @Test
  public void test_setNextOnTouchEventReturnValue() throws Exception {
    assertTrue(detector.onTouchEvent(motionEvent));

    shadowOf(detector).setNextOnTouchEventReturnValue(true);
    assertTrue(detector.onTouchEvent(motionEvent));

    shadowOf(detector).setNextOnTouchEventReturnValue(false);
    assertFalse(detector.onTouchEvent(motionEvent));
  }
 @Override
 public boolean dispatchTouchEvent(MotionEvent ev) {
   super.dispatchTouchEvent(ev);
   boolean consumed = gesturedetector.onTouchEvent(ev);
   if (!consumed && ev.getAction() == MotionEvent.ACTION_DOWN) return true;
   else return consumed;
 }
  @Override
  public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) {
    childView = view.findChildViewUnder(event.getX(), event.getY());
    childViewPosition = view.getChildPosition(childView);

    return childView != null && gestureDetector.onTouchEvent(event);
  }
  @Override
  public boolean dispatchTouchEvent(MotionEvent event) {
    boolean ret = false;

    if (mIsScroll && event.getAction() == MotionEvent.ACTION_UP) {
      if (mScrollX > 0 && mScrollX < mMaxDistance) {
        unFold();
        ret = true;
      }
      event.setAction(MotionEvent.ACTION_CANCEL);
      mIsScroll = false;
    } else if (mGestureDetector != null && mGestureDetector.onTouchEvent(event)) {
      event.setAction(MotionEvent.ACTION_CANCEL);
      ret = true;
    }

    if (super.dispatchTouchEvent(event)) {
      ret = true;
    }

    if (ret) {
      invalidate();
    }
    return ret;
  }
 public void onTouchEvent(MotionEvent event) {
   mGestureDetector.onTouchEvent(event);
   mScaleDetector.onTouchEvent(event);
   if (event.getAction() == MotionEvent.ACTION_UP) {
     mListener.onUp(event.getX(), event.getY());
   }
 }
Beispiel #11
0
  /**
   * Clean-up the resources attached to this object. This needs to be called when the ImageView is
   * no longer used. A good example is from {@link android.view.View#onDetachedFromWindow()} or from
   * {@link android.app.Activity#onDestroy()}. This is automatically called if you are using {@link
   * uk.co.senab.photoview.PhotoView}.
   */
  @SuppressWarnings("deprecation")
  public void cleanup() {
    if (null != mImageView) {
      // Remove this as a global layout listener
      ViewTreeObserver observer = mImageView.getViewTreeObserver();
      if (null != observer && observer.isAlive()) {
        observer.removeGlobalOnLayoutListener(this);
      }

      // Remove the ImageView's reference to this
      mImageView.setOnTouchListener(null);

      // make sure a pending fling runnable won't be run
      cancelFling();
    }

    if (null != mGestureDetector) {
      mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
  }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   // 触摸时停止自动播放
   flipStop(); // 点击事件后,停止自动播放
   gestureDetector.onTouchEvent(event); // 注册手势事件
   return true;
 }
  /**
   * Handles Touch event
   *
   * @param event the motion event
   * @return
   */
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        lastTouchedPosition = getMotionEventPosition(event);
        scroller.forceFinished(true);
        clearMessages();
        listener.onTouch();
        break;

      case MotionEvent.ACTION_UP:
        if (scroller.isFinished()) listener.onTouchUp();
        break;

      case MotionEvent.ACTION_MOVE:
        // perform scrolling
        int distance = (int) (getMotionEventPosition(event) - lastTouchedPosition);
        if (distance != 0) {
          startScrolling();
          listener.onScroll(distance);
          lastTouchedPosition = getMotionEventPosition(event);
        }
        break;
    }

    if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
      justify();
    }

    return true;
  }
Beispiel #14
0
 private void init(Context context, AttributeSet attributeset, int i)
 {
     ViewConfiguration viewconfiguration = ViewConfiguration.get(context);
     mScaledDensity = context.getResources().getDisplayMetrics().density / 2.0F;
     attributeset = context.getTheme().obtainStyledAttributes(attributeset, com.aviary.android.feather.sdk.R.styleable.AviaryWheel, i, 0);
     mShadowBottom = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelShadowTop);
     mLinesSingle = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelLine);
     mLinesIndicator = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelIndicator);
     mEdgeStyle = attributeset.getResourceId(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviary_edgeStyle, 0);
     attributeset.recycle();
     mEdgeOffset = (float)(20D * (double)mScaledDensity);
     mLineWidth = mLinesSingle.getIntrinsicWidth();
     mLinesPaint = new Paint(7);
     if (!isInEditMode())
     {
         mGestureDetector = new GestureDetector(context, this);
         mGestureDetector.setIsLongpressEnabled(false);
     }
     mScroller = new ScrollerRunnable(this, 200, viewconfiguration.getScaledOverflingDistance(), null);
     mVibrationHelper = new VibrationHelper(context, true);
     mEdgeLeft = new AviaryEdgeEffect(getContext(), mEdgeStyle);
     mEdgeRight = new AviaryEdgeEffect(getContext(), mEdgeStyle);
     mEdgeLeft.setEdgeMaxAlpha(100);
     mEdgeRight.setEdgeMaxAlpha(100);
     mNextValue = -1;
     mCurrentValue = 0.0D;
 }
Beispiel #15
0
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    mGestureDetector.onTouchEvent(ev);
    // scroll.onTouchEvent(ev);

    return super.dispatchTouchEvent(ev);
  }
Beispiel #16
0
        public boolean onTouch(View v, MotionEvent event) {
          if (mState == State.ANIMATING) {
            // we are animating
            return false;
          }

          int action = event.getAction();
          if (action == MotionEvent.ACTION_DOWN) {
            //	           if (mBringToFront) {
            bringToFront();
            //	            }
            touchX = event.getX();
            touchY = event.getY();
          }

          if (!mGestureDetector.onTouchEvent(event)) {
            if (action == MotionEvent.ACTION_UP) {
              // tup up after scrolling
              int size = (int) (Math.abs(touchX - event.getX()) + Math.abs(touchY - event.getY()));

              if (size == mContentWidth || size == mContentHeight) {
                mState = State.ABOUT_TO_ANIMATE;
                // Log.e("size", String.valueOf(size));
                // Log.e(String.valueOf(mContentWidth),String.valueOf(mContentHeight));
              }

              post(startAnimation);
            }
          }
          return false;
        }
  @Override
  public final boolean onTouchEvent(MotionEvent event) {

    gestureDetector.onTouchEvent(event);

    return super.onTouchEvent(event);
  }
  public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    mViewTreeObserver = imageView.getViewTreeObserver();
    mViewTreeObserver.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (!imageView.isInEditMode()) {
      // Create Gesture Detectors...
      mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

      mGestureDetector =
          new GestureDetector(
              imageView.getContext(),
              new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                  if (null != mLongClickListener) {
                    mLongClickListener.onLongClick(mImageView.get());
                  }
                }
              });

      mGestureDetector.setOnDoubleTapListener(this);

      // Finally, update the UI so that we're zoomable
      setZoomable(true);
    }
  }
Beispiel #19
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    boolean spend = false;
    spend = detector.onTouchEvent(ev);
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        // log("onInterceptTouchEvent.ACTION_DOWN, " + spend);
        break;
      case MotionEvent.ACTION_MOVE:
        // log("onInterceptTouchEvent.ACTION_MOVE, " + spend);
        // detector.onTouchEvent(ev);
        break;
      case MotionEvent.ACTION_UP:
        // log("onInterceptTouchEvent.ACTION_UP, " + spend);
        // onTouchRelease();
        ov.clear();
        break;
      case MotionEvent.ACTION_CANCEL:
        // log("onInterceptTouchEvent.ACTION_CANCEL, " + spend);
        // onTouchRelease();
        break;
    }

    return spend;
  }
  private void initialize(Context context) {
    Context applicationContext = context.getApplicationContext();
    Injector injector = AirCastingApplication.class.cast(applicationContext).getInjector();
    injector.injectMembers(this);

    gestureDetector.setOnDoubleTapListener(this);
  }
  /**
   * Constructor
   *
   * @param context the current context
   * @param listener the scrolling listener
   */
  public WheelScroller(Context context, ScrollingListener listener) {
    gestureDetector =
        new GestureDetector(
            context,
            new SimpleOnGestureListener() {
              public boolean onScroll(
                  MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                // Do scrolling in onTouchEvent() since onScroll() are not call immediately
                //  when user touch and move the spinnerwheel
                return true;
              }

              public boolean onFling(
                  MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                lastScrollPosition = 0;
                scrollerFling(lastScrollPosition, (int) velocityX, (int) velocityY);
                setNextMessage(MESSAGE_SCROLL);
                return true;
              }

              // public boolean onDown(MotionEvent motionEvent);

            });
    gestureDetector.setIsLongpressEnabled(false);

    scroller = new Scroller(context);

    this.listener = listener;
    this.context = context;
  }
 @Override
 public boolean dispatchTouchEvent(MotionEvent ev) {
   if (gd != null) {
     if (gd.onTouchEvent(ev)) return true;
   }
   return super.dispatchTouchEvent(ev);
 }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {

    mGestureDetector = new GestureDetector(new YScrollDetector());

    return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
  }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // Avoid short-circuit logic evaluation - ensure all gesture detectors see all events so
    // that they generate correct notifications.
    boolean handled = mScroller.onTouchEvent(event);
    handled |= mZoomer.onTouchEvent(event);
    handled |= mTapDetector.onTouchEvent(event);
    mSwipePinchDetector.onTouchEvent(event);

    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        mViewer.setAnimationEnabled(false);
        mSuppressCursorMovement = false;
        mSuppressFling = false;
        mSwipeCompleted = false;
        break;

      case MotionEvent.ACTION_POINTER_DOWN:
        mTotalMotionY = 0;
        break;

      case MotionEvent.ACTION_UP:
        releaseAnyHeldButton();
        break;

      default:
        break;
    }
    return handled;
  }
 public FilmStripGestureRecognizer(Context context, Listener listener) {
   mListener = listener;
   mGestureDetector =
       new GestureDetector(context, new MyGestureListener(), null, true /* ignoreMultitouch */);
   mGestureDetector.setOnDoubleTapListener(new MyDoubleTapListener());
   mScaleDetector = new ScaleGestureDetector(context, new MyScaleListener());
 }
  /** 事件拦截操作 */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {

    // 处理ViewPager冲突问题
    ViewPager mViewPager = getTouchViewPager(mViewPagers, ev);
    Log.i(TAG, "mViewPager = " + mViewPager);

    if (mViewPager != null && mViewPager.getCurrentItem() != 0) {
      return super.onInterceptTouchEvent(ev);
    }

    // 如果是左右滑动事件,则不将事件传递给子view
    if (mGesture.onTouchEvent(ev)) {
      return true;
    }

    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        downX = tempX = (int) ev.getRawX();
        downY = (int) ev.getRawY();
        break;
      case MotionEvent.ACTION_MOVE:
        int moveX = (int) ev.getRawX();
        // 满足此条件屏蔽SildingFinishLayout里面子类的touch事件
        if (moveX - downX > mTouchSlop && Math.abs((int) ev.getRawY() - downY) < mTouchSlop) {
          return true;
        }
        break;
    }

    return super.onInterceptTouchEvent(ev);
  }
  /*----------------------onTouchEvent-------------------------------------------------------------------------------*/
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    Log.d(TAG, "onTouchEvent()");

    mGestureDetector.onTouchEvent(event);
    return multiTouchController.onTouchEvent(event);
  }
  public boolean onTouch(View v, MotionEvent event) {
    boolean result = false;

    for (int i = 0; i < buttons.length; ++i) {
      if (buttons[i].processTouch(v, event)) {
        result = true;
        break;
      }
    }

    if (result != true) {
      gestureDetector.onTouchEvent(event);

      for (int i = 0; i < joysticks.length; ++i) {
        JoystickBase joy = joysticks[i];
        if (joy != null) {
          if (joy.processTouch(v, event)) {

            result = true;
          }
        }
      }
    }

    //		if (event.getAction() == MotionEvent.ACTION_MOVE) {
    //		    // Trying to avoid flooding of ACTION_MOVE events
    //			try {
    //				Thread.sleep(33);
    //			} catch (InterruptedException e) {
    //				e.printStackTrace();
    //			}
    //		}

    return result;
  }
  public TrackingInputHandler(DesktopViewInterface viewer, Context context, RenderData renderData) {
    mViewer = viewer;
    mRenderData = renderData;

    GestureListener listener = new GestureListener();
    mScroller = new GestureDetector(context, listener, null, false);

    // If long-press is enabled, the gesture-detector will not emit any further onScroll
    // notifications after the onLongPress notification. Since onScroll is being used for
    // moving the cursor, it means that the cursor would become stuck if the finger were held
    // down too long.
    mScroller.setIsLongpressEnabled(false);

    mZoomer = new ScaleGestureDetector(context, listener);
    mTapDetector = new TapGestureDetector(context, listener);
    mFlingScroller = new Scroller(context);
    mSwipePinchDetector = new SwipePinchDetector(context);

    mCursorPosition = new PointF();

    // The threshold needs to be bigger than the ScaledTouchSlop used by the gesture-detectors,
    // so that a gesture cannot be both a tap and a swipe. It also needs to be small enough so
    // that intentional swipes are usually detected.
    float density = context.getResources().getDisplayMetrics().density;
    mSwipeThreshold = 40 * density;
  }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (mGesture.onTouchEvent(event)) {
      return true;
    }
    switch (event.getAction()) {
      case MotionEvent.ACTION_MOVE:
        int moveX = (int) event.getRawX();
        int deltaX = tempX - moveX;
        tempX = moveX;
        if (moveX - downX > mTouchSlop && Math.abs((int) event.getRawY() - downY) < mTouchSlop) {
          isSilding = true;
        }

        if (moveX - downX >= 0 && isSilding) {
          mContentView.scrollBy(deltaX, 0);
        }
        break;
      case MotionEvent.ACTION_UP:
        isSilding = false;
        if (mContentView.getScrollX() <= -viewWidth / 2) {
          isFinish = true;
          scrollRight();
        } else {
          scrollOrigin();
          isFinish = false;
        }
        break;
    }

    return true;
  }