Beispiel #1
0
  @Override
  protected boolean drawBubble(Canvas canvas) {
    boolean isAnimated = false;

    rect.set(getPx(6), getPx(6), getPx(42 + 6), getPx(42 + 6));
    if (contactAvatar != null) {
      long animationTime = SystemClock.uptimeMillis() - avatarAppearTime;
      if (animationTime < FADE_ANIMATION_TIME) {
        float alpha = fadeEasing(animationTime / (float) FADE_ANIMATION_TIME);

        canvas.drawRect(rect, placeHolderBgPaint);
        basePlaceholder.setBounds(rect);
        basePlaceholder.draw(canvas);

        avatarPaint.setAlpha((int) (alpha * 255));
        canvas.drawBitmap(
            contactAvatar.getBitmap(), new Rect(0, 0, getPx(42), getPx(42)), rect, avatarPaint);
        isAnimated = true;
      } else {
        avatarPaint.setAlpha(255);
        canvas.drawBitmap(
            contactAvatar.getBitmap(), new Rect(0, 0, getPx(42), getPx(42)), rect, avatarPaint);
      }
    } else {
      canvas.drawRect(rect, placeHolderBgPaint);
      basePlaceholder.setBounds(rect);
      basePlaceholder.draw(canvas);
    }

    canvas.drawText(title, getPx(56), getPx(20), senderPaint);
    canvas.drawText(phone, getPx(56), getPx(38), bodyPaint);

    isAnimated |= drawState(canvas, px(8), px(4));

    if (showAddButton) {
      Paint p = new Paint();
      p.setStrokeWidth(getPx(1));
      p.setColor(0xffececec);
      canvas.drawLine(layoutWidth + getPx(10), getPx(2), layoutWidth + getPx(10), getPx(52), p);
      addContactResource.setBounds(
          layoutWidth + getPx(20),
          getPx(12),
          layoutWidth + getPx(20) + addContactResource.getIntrinsicWidth(),
          getPx(12) + addContactResource.getIntrinsicHeight());
      addContactResource.draw(canvas);
    }

    return isAnimated;
  }
Beispiel #2
0
 private void releaseAvatar() {
   if (avatarHolder != null) {
     avatarHolder.release();
     avatarHolder = null;
   }
 }
Beispiel #3
0
 private void unbindAvatar() {
   if (contactAvatar != null) {
     contactAvatar.release();
     contactAvatar = null;
   }
 }
Beispiel #4
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);
    }
  }