Ejemplo n.º 1
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();

    boolean result = false;
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      if (delegate != null) {
        if (currentMessageObject.type == 11 && imageReceiver.isInsideImage(x, y)) {
          imagePressed = true;
          result = true;
        }
        if (result) {
          startCheckLongPress();
        }
      }
    } else {
      if (event.getAction() != MotionEvent.ACTION_MOVE) {
        cancelCheckLongPress();
      }
      if (imagePressed) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
          imagePressed = false;
          if (delegate != null) {
            delegate.didClickedImage(this);
            playSoundEffect(SoundEffectConstants.CLICK);
          }
        } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
          imagePressed = false;
        } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
          if (!imageReceiver.isInsideImage(x, y)) {
            imagePressed = false;
          }
        }
      }
    }
    if (!result) {
      if (event.getAction() == MotionEvent.ACTION_DOWN
          || pressedLink != null && event.getAction() == MotionEvent.ACTION_UP) {
        if (x >= textX && y >= textY && x <= textX + textWidth && y <= textY + textHeight) {
          y -= textY;
          x -= textXLeft;

          final int line = textLayout.getLineForVertical((int) y);
          final int off = textLayout.getOffsetForHorizontal(line, x);
          final float left = textLayout.getLineLeft(line);
          if (left <= x
              && left + textLayout.getLineWidth(line) >= x
              && currentMessageObject.messageText instanceof Spannable) {
            Spannable buffer = (Spannable) currentMessageObject.messageText;
            URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);

            if (link.length != 0) {
              if (event.getAction() == MotionEvent.ACTION_DOWN) {
                pressedLink = link[0];
                result = true;
              } else {
                if (link[0] == pressedLink) {
                  if (delegate != null) {
                    delegate.needOpenUserProfile(Integer.parseInt(link[0].getURL()));
                  }
                  result = true;
                }
              }
            } else {
              pressedLink = null;
            }
          } else {
            pressedLink = null;
          }
        } else {
          pressedLink = null;
        }
      }
    }

    if (!result) {
      result = super.onTouchEvent(event);
    }

    return result;
  }
Ejemplo n.º 2
0
 @Override
 protected void onLongPress() {
   if (delegate != null) {
     delegate.didLongPressed(this);
   }
 }