@Override
    public boolean onTouchEvent(MotionEvent event) {
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          handleMouseDown(event.getX(), event.getY(), event.getEventTime());
          return true;
        case MotionEvent.ACTION_MOVE:
          handleMouseDrag(event.getX(), event.getY(), event.getEventTime());
          return true;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
          handleMouseUp(event.getX(), event.getY(), event.getEventTime());
          return true;
        default:
          break;
      }

      return false;
    }
Ejemplo n.º 2
0
    @Override
    public boolean onTouchEvent(MotionEvent event) {
      int action = event.getAction();
      long time = event.getEventTime();

      switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
          handleMouseDown(host, event.getPointerId(0), event.getX(), event.getY(), time);
          return true;

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
          handleMouseUp(host, event.getPointerId(0), event.getX(), event.getY(), time);
          return true;

        case MotionEvent.ACTION_MOVE:
          {
            int n = event.getPointerCount();
            for (int i = 0; i < n; ++i)
              handleMouseDrag(host, event.getPointerId(i), event.getX(i), event.getY(i), time);

            return true;
          }

        case MotionEvent.ACTION_POINTER_UP:
          {
            int i =
                (action & MotionEvent.ACTION_POINTER_INDEX_MASK)
                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            handleMouseUp(host, event.getPointerId(i), event.getX(i), event.getY(i), time);
            return true;
          }

        case MotionEvent.ACTION_POINTER_DOWN:
          {
            int i =
                (action & MotionEvent.ACTION_POINTER_INDEX_MASK)
                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            handleMouseDown(host, event.getPointerId(i), event.getX(i), event.getY(i), time);
            return true;
          }

        default:
          break;
      }

      return false;
    }