コード例 #1
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    synchronized (this) {
      TouchEvent touchEvent = touchEventPool.newObject();
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          touchEvent.type = TouchEvent.TOUCH_DOWN;
          isTouched = true;
          break;
        case MotionEvent.ACTION_MOVE:
          touchEvent.type = TouchEvent.TOUCH_DRAGGED;
          isTouched = true;
          break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
          touchEvent.type = TouchEvent.TOUCH_UP;
          isTouched = false;
          break;
      }

      touchEvent.x = touchX = (int) (event.getX() * scaleX);
      touchEvent.y = touchY = (int) (event.getY() * scaleY);
      touchEventsBuffer.add(touchEvent);

      return true;
    }
  }
コード例 #2
0
 @Override
 public List<TouchEvent> getTouchEvents() {
   synchronized (this) {
     int len = touchEvents.size();
     for (int i = 0; i < len; i++) touchEventPool.free(touchEvents.get(i));
     touchEvents.clear();
     touchEvents.addAll(touchEventsBuffer);
     touchEventsBuffer.clear();
     return touchEvents;
   }
 }