Beispiel #1
0
 @Override
 public boolean handleMotionEvent(MotionEvent event) {
   if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
     int actionPointerIndex = event.getActionIndex();
     int action = event.getActionMasked();
     switch (action) {
       case MotionEvent.ACTION_MOVE:
         SDLJoystick joystick = getJoystick(event.getDeviceId());
         if (joystick != null) {
           for (int i = 0; i < joystick.axes.size(); i++) {
             InputDevice.MotionRange range = joystick.axes.get(i);
             /* Normalize the value to -1...1 */
             float value =
                 (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin())
                         / range.getRange()
                         * 2.0f
                     - 1.0f;
             SDLActivity.onNativeJoy(joystick.device_id, i, value);
           }
         }
         break;
       default:
         break;
     }
   }
   return true;
 }
Beispiel #2
0
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
      // Set up the Scroller for a fling
      float scrollTheta =
          vectorToScalarScroll(
              velocityX,
              velocityY,
              e2.getX() - mPieBounds.centerX(),
              e2.getY() - mPieBounds.centerY());
      mScroller.fling(
          0,
          (int) getPieRotation(),
          0,
          (int) scrollTheta / FLING_VELOCITY_DOWNSCALE,
          0,
          0,
          Integer.MIN_VALUE,
          Integer.MAX_VALUE);

      // Start the animator and tell it to animate for the expected duration of the fling.
      if (Build.VERSION.SDK_INT >= 11) {
        mScrollAnimator.setDuration(mScroller.getDuration());
        mScrollAnimator.start();
      }
      return true;
    }
Beispiel #3
0
 @Override
 public boolean onTrackballEvent(MotionEvent event) {
   // Log.i(logTag, "onTrackballEvent");
   if (trackballEvent(event.getAction(), event.getX(), event.getY())) {
     postUpdate();
   }
   return true;
 }
Beispiel #4
0
  public boolean onTouchEvent(MotionEvent e) {
    x = e.getX();
    y = e.getY();

    // 更新を有効にする
    this.invalidate();
    return true;
  }
Beispiel #5
0
 // 새로운 볼 생성
 public boolean onTouchEvent(MotionEvent event) {
   if (event.getAction() == MotionEvent.ACTION_DOWN) {
     Ball NewBall = Ball.Create((int) event.getX(), (int) event.getY(), RAD);
     arBall.add(NewBall);
     invalidate();
     return true;
   }
   return false;
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (velocityTracker == null) { // If we do not have velocity tracker
      velocityTracker = VelocityTracker.obtain(); // then get one
    }
    velocityTracker.addMovement(event); // add this movement to it
    positiveScroll = true;

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (!flinger.isFinished()) { // If scrolling, then stop now
            flinger.forceFinished();
          }
          currentX = (int) event.getRawX();
          currentY = (int) event.getRawY();
          break;
        }
      case MotionEvent.ACTION_MOVE:
        {
          final int x2 = (int) event.getRawX();
          final int y2 = (int) event.getRawY();
          final int diffX = currentX - x2;
          final int diffY = currentY - y2;
          currentX = x2;
          currentY = y2;

          scrollBy(diffX, diffY);
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          final VelocityTracker velocityTracker = this.velocityTracker;
          velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
          int velocityX = (int) velocityTracker.getXVelocity();
          int velocityY = (int) velocityTracker.getYVelocity();

          if (Math.abs(velocityX) > minimumVelocity || Math.abs(velocityY) > minimumVelocity) {
            flinger.start(
                getActualScrollX(),
                getActualScrollY(),
                velocityX,
                velocityY,
                getMaxScrollX(),
                getMaxScrollY());
          } else {
            if (this.velocityTracker != null) { // If the velocity less than threshold
              this.velocityTracker.recycle(); // recycle the tracker
              this.velocityTracker = null;
            }
          }
          break;
        }
    }
    return true;
  }
Beispiel #7
0
 @Override
 public boolean onTrackballEvent(MotionEvent event) {
   if (event.getAction() == MotionEvent.ACTION_DOWN) {
     onKeyDown(KeyEvent.KEYCODE_DPAD_CENTER, null);
   } else {
     ZLApplication.Instance()
         .getCurrentView()
         .onTrackballRotated((int) (10 * event.getX()), (int) (10 * event.getY()));
   }
   return true;
 }
Beispiel #8
0
  // Touch events
  public boolean onTouch(View v, MotionEvent event) {

    int action = event.getAction();
    float x = event.getX();
    float y = event.getY();
    float p = event.getPressure();

    // TODO: Anything else we need to pass?
    SDLActivity.onNativeTouch(action, x, y, p);
    return true;
  }
Beispiel #9
0
    @Override
    public boolean onSingleTapUp(MotionEvent e) {

      ChartAxes axes = isAvailableTap(e.getX(), e.getY());
      if (axes != null && tapPointListener != null) {
        tapPointListener.onTap(axes);
        currentPressedPoint = axes;
        refreshChart(0);
      }
      return true;
    }
Beispiel #10
0
 @Override
 public boolean onTouch(View view, MotionEvent event) {
   String str = null;
   int i = 0;
   str =
       "x="
           + event.getX(i) / view.getMeasuredWidth()
           + ",y="
           + event.getY(i) / view.getMeasuredHeight();
   textView.setText(str);
   return false;
 }
Beispiel #11
0
 @Override
 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
   // Set the pie rotation directly.
   float scrollTheta =
       vectorToScalarScroll(
           distanceX,
           distanceY,
           e2.getX() - mPieBounds.centerX(),
           e2.getY() - mPieBounds.centerY());
   setPieRotation(getPieRotation() - (int) scrollTheta / FLING_VELOCITY_DOWNSCALE);
   return true;
 }
Beispiel #12
0
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {

    float xDelta = Math.abs(motionEvent.getRawX() - showcaseX);
    float yDelta = Math.abs(motionEvent.getRawY() - showcaseY);
    double distanceFromFocus = Math.sqrt(Math.pow(xDelta, 2) + Math.pow(yDelta, 2));

    if (mOptions.hideOnClickOutside && distanceFromFocus > showcaseRadius) {
      this.hide();
      return true;
    }

    return mOptions.block && distanceFromFocus > showcaseRadius;
  }
Beispiel #13
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        path.reset();
        path.moveTo(event.getX(), event.getY());
        break;
      case MotionEvent.ACTION_MOVE:
        path.lineTo(event.getX(), event.getY());
        break;
    }

    return super.onTouchEvent(event);
  }
Beispiel #14
0
  /** 当屏幕被触摸时调用 */
  @Override
  public boolean onTouchEvent(MotionEvent event) {

    // 设置贝塞尔曲线的坐标为触摸时坐标
    qStartX = (int) event.getX();
    qStartY = (int) event.getY();

    // 设置贝塞尔曲线的控制点坐标为终点坐标与起点坐标对应的差值的一半,注意这里不是曲线的中点
    qControlX = Math.abs(qEndX - qStartX) / 2;
    qCOntrolY = Math.abs(qEndY - qStartY) / 2;

    // 设置控制点的横坐标不返回
    cReturn = false;
    return super.onTouchEvent(event);
  }
Beispiel #15
0
    public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int sel;
        sel = FindShapeIdx((int) event.getX(), (int) event.getY());

        // 빈 바닥을 찍었으면 무시한다.
        if (sel == -1) {
          return true;
        }

        // 마지막 추가된 도형을 제대로 찍었으면 다음 단계로 진행.
        // 빈 화면 잠시 보여준 후 새 도형 추가
        if (sel == arShape.size() - 1) {
          status = BLANK;
          invalidate();
          mHandler.sendEmptyMessageDelayed(0, DELAY);
          // 엉뚱한 도형을 찍었으면 질문 후 게임 종료 또는 재시작
        } else {
          new AlertDialog.Builder(getContext())
              .setMessage("재미있지! 또 할래?")
              .setTitle("게임 끝")
              .setPositiveButton(
                  "함더",
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                      arShape.clear();
                      status = BLANK;
                      invalidate();
                      mHandler.sendEmptyMessageDelayed(0, DELAY);
                    }
                  })
              .setNegativeButton(
                  "안해",
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                      mParent.finish();
                    }
                  })
              .show();
        }
        return true;
      }
      return false;
    }
Beispiel #16
0
 public boolean onTouchEvent(MotionEvent event) {
   super.onTouchEvent(event);
   if (event.getAction() == MotionEvent.ACTION_DOWN) {
     x += 15;
     y += 15;
     invalidate();
     return true;
   }
   return false;
 }
    @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;
    }
Beispiel #18
0
  // Generic Motion (mouse hover, joystick...) events go here
  @Override
  public boolean onGenericMotion(View v, MotionEvent event) {
    float x, y;
    int mouseButton;
    int action;

    switch (event.getSource()) {
      case InputDevice.SOURCE_JOYSTICK:
      case InputDevice.SOURCE_GAMEPAD:
      case InputDevice.SOURCE_DPAD:
        SDLActivity.handleJoystickMotionEvent(event);
        return true;

      case InputDevice.SOURCE_MOUSE:
        action = event.getActionMasked();
        switch (action) {
          case MotionEvent.ACTION_SCROLL:
            x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
            y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
            SDLActivity.onNativeMouse(0, action, x, y);
            return true;

          case MotionEvent.ACTION_HOVER_MOVE:
            x = event.getX(0);
            y = event.getY(0);

            SDLActivity.onNativeMouse(0, action, x, y);
            return true;

          default:
            break;
        }

      default:
        break;
    }

    // Event was not managed
    return false;
  }
 @Override
 public boolean onInterceptTouchEvent(MotionEvent event) {
   boolean intercept = false;
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       {
         currentX = (int) event.getRawX();
         currentY = (int) event.getRawY();
         break;
       }
     case MotionEvent.ACTION_MOVE:
       {
         int x2 = Math.abs(currentX - (int) event.getRawX());
         int y2 = Math.abs(currentY - (int) event.getRawY());
         if (x2 > touchSlop || y2 > touchSlop) {
           intercept = true;
         }
         break;
       }
   }
   return intercept;
 }
Beispiel #20
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // TODO 0 Slices
    //       if(mData.size() < 1)
    //    	   return false;

    // Let the GestureDetector interpret this event
    boolean result = mDetector.onTouchEvent(event);

    // If the GestureDetector doesn't want this event, do some custom processing.
    // This code just tries to detect when the user is done scrolling by looking
    // for ACTION_UP events.
    if (!result) {
      if (event.getAction() == MotionEvent.ACTION_UP) {
        // User is done scrolling, it's now safe to do things like autocenter
        stopScrolling();
        result = true;
      }
    }
    return result;
  }
  public boolean onTouchEvent(MotionEvent ev) {
    if (mapThreadRunning) return false; // no updates when download is running
    if (gestureDetector.onTouchEvent(ev)) return true;

    final int action = ev.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        {
          mLastTouchX = ev.getX();
          mLastTouchY = ev.getY();
          mActivePointerId = ev.getPointerId(0);
          break;
        }
      case MotionEvent.ACTION_POINTER_DOWN:
        {
          mLastTouchX2 = ev.getX();
          mLastTouchY2 = ev.getY();
          if (ev.getPointerCount() > 1) mActivePointerId2 = ev.getPointerId(1);
          break;
        }
      case MotionEvent.ACTION_MOVE:
        {
          int pointerIndex;
          float x = 0.0f, y = 0.0f;

          try {
            if ((mActivePointerId != INVALID_POINTER_ID)
                || (mActivePointerId2 != INVALID_POINTER_ID)) {
              pointerIndex = ev.findPointerIndex(mActivePointerId);
              x = ev.getX(pointerIndex);
              y = ev.getY(pointerIndex);
            }
            if ((mActivePointerId != INVALID_POINTER_ID)
                && (mActivePointerId2 != INVALID_POINTER_ID)) {
              double d1, d2;

              pointerIndex = ev.findPointerIndex(mActivePointerId2);
              if (pointerIndex < 0) return false;
              float x2 = ev.getX(pointerIndex);
              float y2 = ev.getY(pointerIndex);

              d1 = java.lang.Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
              d2 =
                  java.lang.Math.sqrt(
                      (mLastTouchX - mLastTouchX2) * (mLastTouchX - mLastTouchX2)
                          + (mLastTouchY - mLastTouchY2) * (mLastTouchY - mLastTouchY2));

              /*                  if ((Math.abs(d1)>300) || (Math.abs(d2)>300))
              {
                 int i=0;
                 i=i;
              }*/

              if ((d1 > 0) && (d2 > 0)) {
                float w, h, s;

                s = (float) (d1 / d2);
                mScaleFactor *= s;
                matrix.postScale(s, s);
                w = scrWidth / 2.0f;
                h = scrHeight / 2.0f;

                matrix.postTranslate(w, h);
                imgOffsetX += w;
                imgOffsetY += h;
              }

              mLastTouchX2 = x2;
              mLastTouchY2 = y2;
            } else if (mScaleFactor == 1.0) {
              mScaleFactor = 1.0f;
              imgOffsetX += (x - mLastTouchX);
              imgOffsetY += (y - mLastTouchY);
              matrix.setTranslate(imgOffsetX, imgOffsetY);
            }

            if ((mActivePointerId != INVALID_POINTER_ID)
                || (mActivePointerId2 != INVALID_POINTER_ID)) {
              mLastTouchX = x;
              mLastTouchY = y;
            }
          } catch (Exception e) {
            // can be caused by
            // pointerIndex= ev.findPointerIndex(mActivePointerId);
            // x= ev.getX(pointerIndex);
            // above which seems to be a Android bug
          }
          invalidate();
          break;
        }
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
        {
          breakMapThread = true;
          mActivePointerId = INVALID_POINTER_ID;
          mActivePointerId2 = INVALID_POINTER_ID;
          restartMap();
          break;
        }
    }
    return true;
  }
Beispiel #22
0
  // Touch events
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    final int touchDevId = event.getDeviceId();
    final int pointerCount = event.getPointerCount();
    // touchId, pointerId, action, x, y, pressure
    int actionPointerIndex =
        (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK)
            >> MotionEvent.ACTION_POINTER_ID_SHIFT; /* API 8: event.getActionIndex(); */
    int pointerFingerId = event.getPointerId(actionPointerIndex);
    int action =
        (event.getAction() & MotionEvent.ACTION_MASK); /* API 8: event.getActionMasked(); */

    float x = event.getX(actionPointerIndex) / mWidth;
    float y = event.getY(actionPointerIndex) / mHeight;
    float p = event.getPressure(actionPointerIndex);

    if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) {
      // TODO send motion to every pointer if its position has
      // changed since prev event.
      for (int i = 0; i < pointerCount; i++) {
        pointerFingerId = event.getPointerId(i);
        x = event.getX(i) / mWidth;
        y = event.getY(i) / mHeight;
        p = event.getPressure(i);
        SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
      }
    } else {
      SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
    }
    return true;
  }
Beispiel #23
0
  // Touch events
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    /* Ref: http://developer.android.com/training/gestures/multi.html */
    final int touchDevId = event.getDeviceId();
    final int pointerCount = event.getPointerCount();
    int action = event.getActionMasked();
    int pointerFingerId;
    int i = -1;
    float x, y, p;

    switch (action) {
      case MotionEvent.ACTION_MOVE:
        for (i = 0; i < pointerCount; i++) {
          pointerFingerId = event.getPointerId(i);
          x = event.getX(i) / mWidth;
          y = event.getY(i) / mHeight;
          p = event.getPressure(i);
          SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
        }
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_DOWN:
        // Primary pointer up/down, the index is always zero
        i = 0;
      case MotionEvent.ACTION_POINTER_UP:
      case MotionEvent.ACTION_POINTER_DOWN:
        // Non primary pointer up/down
        if (i == -1) {
          i = event.getActionIndex();
        }

        pointerFingerId = event.getPointerId(i);
        x = event.getX(i) / mWidth;
        y = event.getY(i) / mHeight;
        p = event.getPressure(i);
        SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
        break;

      default:
        break;
    }

    return true;
  }
Beispiel #24
0
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      // detector.onTouchEvent(event);
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          startX = event.getX();
          downX = event.getX();
          break;
        case MotionEvent.ACTION_UP:
          v.performClick();
          break;
        case MotionEvent.ACTION_MOVE:
          // 是否已滚动到无法继续滑动
          boolean isEnable = false;
          // 手指move的像素值超过系统判定判定滚动的最小临界值,避免手指抖动造成chart图抖动
          if (Math.abs(event.getX() - downX)
              > ViewConfiguration.get(context).getScaledTouchSlop()) {
            int transValue = (int) (event.getX() - startX);
            if (axesData.size() > 1) {
              int max = axesData.get(axesData.size() - 1).X;
              int min = axesData.get(0).X;
              int maxLimit = width - rightPadding - POINT_PADDING;
              int minLimit = leftPadding + yTextWidth + POINT_PADDING;
              if (min + transValue > minLimit) { // 滑动以后左边界判断
                if (min < minLimit) {
                  transValue = minLimit - min;
                  isEnable = true;
                } else {
                  transValue = 0;
                  if (loadMore != null) {
                    loadMore.onLoad();
                  }
                }
              } else {
                isEnable = true;
              }
              if (max + transValue < maxLimit) { // 滑动后右边界判断
                if (max > maxLimit) {
                  transValue = maxLimit - max;
                  isEnable = true;
                } else {
                  transValue = 0;
                }
              } else {
                isEnable = true;
              }
              Log.d("min", min + "");
              Log.d("minLimit", minLimit + "");
              Log.d("transValue", transValue + "");
              if (isEnable) {
                startX = event.getX();
                refreshChart(transValue);
              }
            }
          }
          break;

        default:
          break;
      }
      return true;
    }
Beispiel #25
0
  // Touch events
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    /* Ref: http://developer.android.com/training/gestures/multi.html */
    final int touchDevId = event.getDeviceId();
    final int pointerCount = event.getPointerCount();
    int action = event.getActionMasked();
    int pointerFingerId;
    int mouseButton;
    int i = -1;
    float x, y, p;

    // !!! FIXME: dump this SDK check after 2.0.4 ships and require API14.
    if (event.getSource() == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) {
      if (Build.VERSION.SDK_INT < 14) {
        mouseButton = 1; // For Android==12 all mouse buttons are the left button
      } else {
        try {
          mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
        } catch (Exception e) {
          mouseButton = 1; // oh well.
        }
      }
      SDLActivity.onNativeMouse(mouseButton, action, event.getX(0), event.getY(0));
    } else {
      switch (action) {
        case MotionEvent.ACTION_MOVE:
          for (i = 0; i < pointerCount; i++) {
            pointerFingerId = event.getPointerId(i);
            x = event.getX(i) / mWidth;
            y = event.getY(i) / mHeight;
            p = event.getPressure(i);
            SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
          }
          break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_DOWN:
          // Primary pointer up/down, the index is always zero
          i = 0;
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_POINTER_DOWN:
          // Non primary pointer up/down
          if (i == -1) {
            i = event.getActionIndex();
          }

          pointerFingerId = event.getPointerId(i);
          x = event.getX(i) / mWidth;
          y = event.getY(i) / mHeight;
          p = event.getPressure(i);
          SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
          break;

        case MotionEvent.ACTION_CANCEL:
          for (i = 0; i < pointerCount; i++) {
            pointerFingerId = event.getPointerId(i);
            x = event.getX(i) / mWidth;
            y = event.getY(i) / mHeight;
            p = event.getPressure(i);
            SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
          }
          break;

        default:
          break;
      }
    }

    return true;
  }
Beispiel #26
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;
  }
Beispiel #27
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;
    }