Example #1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (currentMessageObject == null) {
      setMeasuredDimension(
          MeasureSpec.getSize(widthMeasureSpec), textHeight + AndroidUtilities.dp(14));
      return;
    }
    int width = Math.max(AndroidUtilities.dp(30), MeasureSpec.getSize(widthMeasureSpec));
    if (width != previousWidth) {
      previousWidth = width;

      textLayout =
          new StaticLayout(
              currentMessageObject.messageText,
              textPaint,
              width - AndroidUtilities.dp(30),
              Layout.Alignment.ALIGN_CENTER,
              1.0f,
              0.0f,
              false);
      textHeight = 0;
      textWidth = 0;
      try {
        int linesCount = textLayout.getLineCount();
        for (int a = 0; a < linesCount; a++) {
          float lineWidth;
          try {
            lineWidth = textLayout.getLineWidth(a);
            textHeight = (int) Math.max(textHeight, Math.ceil(textLayout.getLineBottom(a)));
          } catch (Exception e) {
            FileLog.e("tmessages", e);
            return;
          }
          textWidth = (int) Math.max(textWidth, Math.ceil(lineWidth));
        }
      } catch (Exception e) {
        FileLog.e("tmessages", e);
      }

      textX = (width - textWidth) / 2;
      textY = AndroidUtilities.dp(7);
      textXLeft = (width - textLayout.getWidth()) / 2;

      if (currentMessageObject.type == MessageObject.Type.MSG_ACTION) {
        imageReceiver.setImageCoords(
            (width - AndroidUtilities.dp(64)) / 2,
            textHeight + AndroidUtilities.dp(15),
            AndroidUtilities.dp(64),
            AndroidUtilities.dp(64));
      }
    }
    setMeasuredDimension(
        width,
        textHeight
            + AndroidUtilities.dp(
                14 + (currentMessageObject.type == MessageObject.Type.MSG_ACTION ? 70 : 0)));
  }
Example #2
0
    private void renderBottomLabel(
        Canvas canvas, RadRect dataPointSlot, String labelText, StaticLayout textBounds) {
      RectF labelBounds = new RectF();
      double height = textBounds.getHeight() + this.labelPadding * 2;
      double top = dataPointSlot.getBottom() + this.labelMargin;
      labelBounds.set(
          (float) dataPointSlot.x,
          (float) top,
          (float) dataPointSlot.getRight(),
          (float) (top + height));

      canvas.drawRect(
          labelBounds.left, labelBounds.top, labelBounds.right, labelBounds.bottom, this.lowFill);
      canvas.drawRect(
          labelBounds.left, labelBounds.top, labelBounds.right, labelBounds.bottom, this.stroke);
      canvas.drawText(
          labelText,
          (float)
              (dataPointSlot.x + (dataPointSlot.width / 2.0) - textBounds.getLineWidth(0) / 2.0f),
          labelBounds.centerY() + textBounds.getLineBottom(0) - textBounds.getLineBaseline(0),
          paint);
    }