예제 #1
0
  private void drawPlaceHolder(Canvas canvas) {
    placeholderPaint.setColor(layout.placeHolderColor);

    placeholderTextPaint.setAlpha(255);
    placeholderPaint.setAlpha(255);
    avatarPaint.setAlpha(255);

    rect.set(
        layout.layoutAvatarLeft,
        layout.layoutAvatarTop,
        layout.layoutAvatarLeft + layout.layoutAvatarWidth,
        layout.layoutAvatarTop + layout.layoutAvatarWidth);

    canvas.drawRect(rect, placeholderPaint);
    if (layout.usePlaceholder) {
      canvas.drawText(
          layout.placeHolderName,
          layout.placeholderLeft,
          layout.placeholderTop,
          placeholderTextPaint);
    } else {
      rect2.set(0, 0, placeholder.getWidth(), placeholder.getHeight());
      canvas.drawBitmap(placeholder, rect2, rect, avatarPaint);
    }
  }
예제 #2
0
  @Override
  protected void onDraw(Canvas canvas) {

    if (layout == null) {
      requestLayout();
      return;
    }

    if (description == null) {
      return;
    }

    if (needNewUpdateTyping) {
      updateTyping();
    }

    if (layout.isEncrypted) {
      bounds(secureIcon, layout.layoutEncryptedLeft, layout.layoutEncryptedTop);
      secureIcon.draw(canvas);
    }

    if (layout.titleLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutTitleLeft, layout.layoutTitleLayoutTop);
      layout.titleLayout.draw(canvas);
      canvas.restore();
    } else if (layout.titleString != null) {
      TextPaint paint =
          layout.isEncrypted
              ? titleEncryptedPaint
              : (layout.isHighlighted ? titleHighlightPaint : titlePaint);
      canvas.drawText(layout.titleString, layout.layoutTitleLeft, layout.layoutTitleTop, paint);
    }

    if (state != MessageState.FAILURE && description.getSenderId() == currentUserUid) {
      switch (state) {
        default:
        case MessageState.PENDING:
          bound(statePending, layout.layoutClockLeft, layout.layoutClockTop);
          statePending.draw(canvas);
          break;
        case MessageState.SENT:
          bound(stateSent, layout.layoutStateLeft, layout.layoutStateTop);
          stateSent.draw(canvas);
          break;
        case MessageState.READED:
          bound(stateSent, layout.layoutStateLeftDouble, layout.layoutStateTop);
          stateSent.draw(canvas);
          bound(stateHalfCheck, layout.layoutStateLeft, layout.layoutStateTop);
          stateHalfCheck.draw(canvas);
          break;
      }
    }

    TextPaint timePaint =
        HIGHLIGHT_UNDEAD ? (layout.isUnreadIn ? unreadClockPaint : readClockPaint) : readClockPaint;
    canvas.drawText(layout.time, layout.layoutTimeLeft, layout.layoutTimeTop, timePaint);

    if (typingLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutMainLeft, layout.layoutMainContentTop);
      typingLayout.draw(canvas);
      canvas.restore();
    } else if (layout.bodyLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutMainLeft, layout.layoutMainContentTop);
      layout.bodyLayout.draw(canvas);
      canvas.restore();
    } else if (layout.bodyString != null) {
      //            canvas.save();
      //            canvas.translate(layout.layoutMainLeft, layout.layoutMainTop);
      //            layout.bodyLayout.draw(canvas);
      //            canvas.restore();
      canvas.drawText(layout.bodyString, layout.layoutMainLeft, layout.layoutMainTop, bodyPaint);
    }

    if (avatarHolder != null) {
      long time = SystemClock.uptimeMillis() - avatarAppearTime;
      if (time > AVATAR_FADE_TIME || !AVATAR_FADE) {
        avatarPaint.setAlpha(255);
        canvas.drawBitmap(
            avatarHolder.getBitmap(), layout.layoutAvatarLeft, layout.layoutAvatarTop, avatarPaint);
      } else {
        drawPlaceHolder(canvas);

        float alpha = time / (float) AVATAR_FADE_TIME;
        avatarPaint.setAlpha((int) (255 * alpha));
        canvas.drawBitmap(
            avatarHolder.getBitmap(), layout.layoutAvatarLeft, layout.layoutAvatarTop, avatarPaint);

        inavalidateForAnimation();
      }
    } else {
      drawPlaceHolder(canvas);
    }

    if (description.isErrorState()
        || (state == MessageState.FAILURE && description.getSenderId() == currentUserUid)) {
      bound(stateFailure, layout.layoutMarkLeft, layout.layoutMarkTop);
      stateFailure.draw(canvas);
    } else if (description.getUnreadCount() > 0) {
      canvas.drawRoundRect(
          layout.layoutMarkRect, layout.layoutMarkRadius, layout.layoutMarkRadius, counterPaint);
      canvas.drawText(
          layout.unreadCountText,
          layout.layoutMarkLeft + layout.layoutMarkTextLeft,
          layout.layoutMarkTextTop,
          counterTitlePaint);
    }
  }