Ejemplo n.º 1
0
  protected boolean touchEvent(TouchEvent te) {
    System.out.println("touchEvent type " + Integer.toString(te.getEvent()));
    if (te.getEvent() == TouchEvent.CANCEL) return true;
    int x = te.getX(1);
    int y = te.getY(1);
    if (x < 0 || x > this.getWidth() || y < 0 || y > this.getHeight()) {
      Logger.log(
          "touchedEvent type "
              + Integer.toString(te.getEvent())
              + " x="
              + Integer.toString(x)
              + " y="
              + Integer.toString(x)
              + " outside "
              + Integer.toString(getWidth())
              + "x"
              + Integer.toString(getHeight()));
      return super.touchEvent(te);
    }
    switch (te.getEvent()) {
      case TouchEvent.DOWN:
        touchDownEvent(x, y);
        break;
      case TouchEvent.UP:
        touchUpEvent(x, y);
        break;
      case TouchEvent.MOVE:
        touchMovedEvent(x, y);
        break;
      default:
        return super.touchEvent(te);
    }

    return true;
  }
Ejemplo n.º 2
0
  protected boolean touchEvent(TouchEvent message) {
    boolean isConsumed = false;
    boolean isOutOfBounds = false;
    int x = message.getX(1);
    int y = message.getY(1);
    // Check to ensure point is within this field
    if (x < 0 || y < 0 || x > getExtent().width || y > getExtent().height) {
      isOutOfBounds = true;
    }
    switch (message.getEvent()) {
      case TouchEvent.CLICK:
      case TouchEvent.MOVE:
        if (isOutOfBounds) return true; // consume
        _selected = true; // Pressed effect

        // update state
        int stateWidth = getExtent().width / _numStates;
        int numerator = x / stateWidth;
        int denominator = x % stateWidth;
        if (denominator > stateWidth / 2) {
          numerator++;
        }
        _currentState = numerator;
        invalidate();

        isConsumed = true;
        break;
      case TouchEvent.UNCLICK:
        if (isOutOfBounds) {
          _selected = false; // Reset presssed effect
          return true;
        }

        // A field change notification is only sent on UNCLICK to allow for recovery
        // should the user cancel, i.e. click and move off the button

        _selected = false; // Reset pressed effect

        // Update state
        stateWidth = getExtent().width / _numStates;
        numerator = x / stateWidth;
        denominator = x % stateWidth;
        if (denominator > stateWidth / 2) {
          numerator++;
        }
        _currentState = numerator;
        invalidate();

        fieldChangeNotify(0);

        isConsumed = true;
        break;
    }
    return isConsumed;
  }
Ejemplo n.º 3
0
  /** 多点 */
  public synchronized void multiTouch(List<TouchEvent> events) {
    if (preTouch) {
      touchUp(mTouchX, mTouchY);
    } else {
      performMultiPointerUp();
    }

    Log.d(TAG, "touchUp: " + mTouchX + "," + mTouchY);

    if (events.isEmpty()) {
      return;
    }

    List<PointerCoords[]> coordsList = new ArrayList<PointerCoords[]>();

    for (TouchEvent event : events) {
      switch (event.getAction()) {
        case TouchEvent.ACTION_DOWN:
          PointerCoords[] pointers = new PointerCoords[1];
          pointers[0] = createPoint(event.getX(), event.getY());

          coordsList.add(pointers);
          break;

        case TouchEvent.ACTION_UP:
          break;

        case TouchEvent.ACTION_SWIPE:
          break;
      }
    }

    PointerCoords[][] pointers = coordsList.toArray(new PointerCoords[1][2]);

    Log.d(TAG, "Size: " + coordsList.size());
    if (coordsList.size() > 1) {
      performMultiPointers(pointers);
      performMultiPointerDown();
      preTouch = false;
    } else if (coordsList.size() == 1) {
      if (coordsList.get(0) != null && coordsList.get(0).length > 0) {
        mTouchX = (int) pointers[0][0].x;
        mTouchY = (int) pointers[0][0].y;
        touchDown(mTouchX, mTouchY, 0);
        preTouch = true;
        Log.d(TAG, "touchDown: " + mTouchX + "," + mTouchY);
      }
    } else {
      Log.d(TAG, "tap: ");
    }
  }