示例#1
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    final ZLView view = ZLApplication.Instance().getCurrentView();
    switch (event.getAction()) {
      case MotionEvent.ACTION_UP:
        if (myPendingDoubleTap) {
          view.onFingerDoubleTap(x, y);
        } else if (myLongClickPerformed) {
          view.onFingerReleaseAfterLongPress(x, y);
        } else {
          if (myPendingLongClickRunnable != null) {
            removeCallbacks(myPendingLongClickRunnable);
            myPendingLongClickRunnable = null;
          }
          if (myPendingPress) {
            if (view.isDoubleTapSupported()) {
              if (myPendingShortClickRunnable == null) {
                myPendingShortClickRunnable = new ShortClickRunnable();
              }
              postDelayed(myPendingShortClickRunnable, ViewConfiguration.getDoubleTapTimeout());
            } else {
              view.onFingerSingleTap(x, y);
            }
          } else {
            view.onFingerRelease(x, y);
          }
        }
        myPendingDoubleTap = false;
        myPendingPress = false;
        myScreenIsTouched = false;
        break;
      case MotionEvent.ACTION_DOWN:
        if (myPendingShortClickRunnable != null) {
          removeCallbacks(myPendingShortClickRunnable);
          myPendingShortClickRunnable = null;
          myPendingDoubleTap = true;
        } else {
          postLongClickRunnable();
          myPendingPress = true;
        }
        myScreenIsTouched = true;
        myPressedX = x;
        myPressedY = y;
        break;
      case MotionEvent.ACTION_MOVE:
        {
          final int slop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
          final boolean isAMove =
              Math.abs(myPressedX - x) > slop || Math.abs(myPressedY - y) > slop;
          if (isAMove) {
            myPendingDoubleTap = false;
          }
          if (myLongClickPerformed) {
            view.onFingerMoveAfterLongPress(x, y);
          } else {
            if (myPendingPress) {
              if (isAMove) {
                if (myPendingShortClickRunnable != null) {
                  removeCallbacks(myPendingShortClickRunnable);
                  myPendingShortClickRunnable = null;
                }
                if (myPendingLongClickRunnable != null) {
                  removeCallbacks(myPendingLongClickRunnable);
                }
                view.onFingerPress(myPressedX, myPressedY);
                myPendingPress = false;
              }
            }
            if (!myPendingPress) {
              view.onFingerMove(x, y);
            }
          }
          break;
        }
    }

    return true;
  }