예제 #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
  private static void checkResources(Context context) {
    if (isLoaded) {
      return;
    }

    StelsApplication application = (StelsApplication) context.getApplicationContext();

    int fontSize;
    int fontSizeClock;
    switch (application.getUserSettings().getBubbleFontSizeId()) {
      default:
      case UserSettings.BUBBLE_FONT_NORMAL:
        fontSize = UserSettings.BUBBLE_FONT_NORMAL_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_NORMAL_VALUE_CLOCK;
        break;
      case UserSettings.BUBBLE_FONT_HUGE:
        fontSize = UserSettings.BUBBLE_FONT_HUGE_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_HUGE_VALUE_CLOCK;
        break;
      case UserSettings.BUBBLE_FONT_SMALL:
        fontSize = UserSettings.BUBBLE_FONT_SMALL_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_SMALL_VALUE_CLOCK;
        break;
      case UserSettings.BUBBLE_FONT_TINY:
        fontSize = UserSettings.BUBBLE_FONT_TINY_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_TINY_VALUE_CLOCK;
        break;
      case UserSettings.BUBBLE_FONT_LARGE:
        fontSize = UserSettings.BUBBLE_FONT_LARGE_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_LARGE_VALUE_CLOCK;
        break;
    }

    bodyPaint = initTextPaint();
    bodyPaint.setTypeface(FontController.loadTypeface(context, "regular"));
    bodyPaint.setTextSize(sp(fontSize));
    bodyPaint.setColor(0xff000000);

    clockOutPaint = initTextPaint();
    clockOutPaint.setTypeface(FontController.loadTypeface(context, "regular"));
    clockOutPaint.setTextSize(sp(fontSizeClock));
    clockOutPaint.setColor(0xff70B15C);

    senderPaintBase = initTextPaint();
    senderPaintBase.setTypeface(FontController.loadTypeface(context, "regular"));
    senderPaintBase.setTextSize(sp(fontSize));
    senderPaintBase.setColor(0xff000000);

    forwardingPaintBase = initTextPaint();
    forwardingPaintBase.setTypeface(FontController.loadTypeface(context, "regular"));
    forwardingPaintBase.setTextSize(sp(fontSize));
    forwardingPaintBase.setColor(0xff000000);

    Drawable inBubble = context.getResources().getDrawable(R.drawable.st_bubble_in);
    inBubblePadding = new Rect();
    inBubble.getPadding(inBubblePadding);

    Drawable outBubble = context.getResources().getDrawable(R.drawable.st_bubble_out);
    outBubblePadding = new Rect();
    outBubble.getPadding(outBubblePadding);

    isLoaded = true;
  }
예제 #3
0
    public void build(MessageWireframe wireframe, int desiredWidth, StelsApplication application) {

      Logger.d(TAG, "Build layout start");

      checkResources(application);

      senderPaint = initTextPaint();
      senderPaint.setTypeface(FontController.loadTypeface(application, "regular"));
      senderPaint.setTextSize(bodyPaint.getTextSize());
      senderPaint.setColor(0xff000000);

      forwardingPaint = initTextPaint();
      forwardingPaint.setTypeface(FontController.loadTypeface(application, "light"));
      forwardingPaint.setTextSize(bodyPaint.getTextSize());
      forwardingPaint.setColor(0xff000000);

      this.layoutDesiredWidth = desiredWidth;
      this.isOut = wireframe.message.isOut();
      this.showState = isOut;
      this.isGroup = wireframe.message.getPeerType() == PeerType.PEER_CHAT && !isOut;
      if (isGroup) {
        User user = wireframe.senderUser;
        this.senderName = user.getDisplayName();
        if (!wireframe.message.isForwarded()) {
          senderPaint.setColor(
              Placeholders.USER_PLACEHOLDERS_COLOR[
                  wireframe.message.getSenderId() % Placeholders.USER_PLACEHOLDERS_COLOR.length]);
          forwardingPaint.setColor(
              Placeholders.USER_PLACEHOLDERS_COLOR[
                  wireframe.message.getSenderId() % Placeholders.USER_PLACEHOLDERS_COLOR.length]);
        }
      }

      if (wireframe.message.isForwarded()) {
        isForwarded = true;
        this.forwarderName = wireframe.forwardUser.getDisplayName();
        if (isOut) {
          forwardingPaint.setColor(0xff739f53);
          senderPaint.setColor(0xff739f53);
        } else {
          forwardingPaint.setColor(0xff4884cf);
          senderPaint.setColor(0xff4884cf);
        }
      } else {
        isForwarded = false;
      }

      if (isGroup) {
        User user = application.getEngine().getUser(wireframe.message.getSenderId());
        this.senderName = user.getDisplayName();
      }
      if (wireframe.message.isForwarded()) {
        isForwarded = true;
        this.forwarderName = wireframe.forwardUser.getDisplayName();
      } else {
        isForwarded = false;
      }

      layoutDesiredWidth = desiredWidth;
      long start = SystemClock.uptimeMillis();

      this.spannable =
          application
              .getEmojiProcessor()
              .processEmojiCompatMutable(
                  wireframe.message.getMessage(), EmojiProcessor.CONFIGURATION_BUBBLES);

      // spannable = new SpannableString(wireframe.message.getMessage());
      Logger.d(TAG, "Emoji processed in " + (SystemClock.uptimeMillis() - start) + " ms");
      start = SystemClock.uptimeMillis();
      Linkify.addLinks(
          this.spannable, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES);
      fixLinks(spannable);
      Logger.d(TAG, "Added links in " + (SystemClock.uptimeMillis() - start) + " ms");
      start = SystemClock.uptimeMillis();
      layout =
          new StaticLayout(
              spannable, bodyPaint, desiredWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
      Logger.d(TAG, "Built base layout in " + (SystemClock.uptimeMillis() - start) + " ms");

      if (layout.getLineCount() < 20) {
        int layoutTextWidth = 0;

        for (int i = 0; i < layout.getLineCount(); i++) {
          layoutTextWidth = (int) Math.max(layout.getLineWidth(i), layoutTextWidth);
        }

        if (layoutTextWidth < layout.getWidth() - px(10)) {
          layout =
              new StaticLayout(
                  spannable,
                  bodyPaint,
                  layoutTextWidth + px(2),
                  Layout.Alignment.ALIGN_NORMAL,
                  1.0f,
                  0.0f,
                  true);
        }
      }

      layoutRealWidth = layout.getWidth();

      timeWidth = (int) clockOutPaint.measureText(wireframe.date) + px((showState ? 23 : 0) + 6);

      if (layout.getLineCount() == 1) {
        boolean isLastRtl = layout.getParagraphDirection(0) == Layout.DIR_RIGHT_TO_LEFT;
        if (!isLastRtl && desiredWidth - layoutRealWidth > timeWidth) {
          layoutRealWidth += timeWidth;
          layoutHeight = layout.getHeight() + px(3);
        } else if (isLastRtl && desiredWidth - layout.getWidth() > timeWidth) {
          layoutRealWidth = layout.getWidth() + timeWidth;
          layoutHeight = layout.getHeight() + px(3);
        } else {
          if (isLastRtl) {
            layoutRealWidth = layout.getWidth();
          }

          layoutHeight = layout.getHeight() + px(17);
        }
      } else {
        boolean isLastRtl =
            layout.getParagraphDirection(layout.getLineCount() - 1) == Layout.DIR_RIGHT_TO_LEFT;
        if (!isLastRtl
            && (desiredWidth - layout.getLineWidth(layout.getLineCount() - 1) > timeWidth)) {
          layoutRealWidth =
              (int)
                  Math.max(
                      layoutRealWidth, layout.getLineWidth(layout.getLineCount() - 1) + timeWidth);
          layoutHeight = layout.getHeight() + px(3);
        } else if (isLastRtl && (desiredWidth - layout.getWidth() > timeWidth)) {
          layoutRealWidth = (int) Math.max(layoutRealWidth, layout.getWidth() + timeWidth);
          layoutHeight = layout.getHeight() + px(3);
        } else {
          layoutHeight = layout.getHeight() + px(17);
        }
      }

      if (layoutRealWidth < timeWidth) {
        layoutRealWidth = timeWidth;
      }

      if (isForwarded) {
        layoutHeight += px(19) * 2;
        forwardOffset = (int) forwardingPaintBase.measureText("From ");
        layoutRealWidth =
            (int) Math.max(layoutRealWidth, forwardingPaintBase.measureText("Forwarded message"));
        forwarderNameMeasured =
            TextUtils.ellipsize(
                    forwarderName,
                    senderPaintBase,
                    desiredWidth - forwardOffset,
                    TextUtils.TruncateAt.END)
                .toString();
        layoutRealWidth =
            (int)
                Math.max(
                    layoutRealWidth,
                    forwardOffset + senderPaintBase.measureText(forwarderNameMeasured));
      }

      if (isGroup && !isOut && !isForwarded) {
        layoutHeight += px(19);
        senderNameMeasured =
            TextUtils.ellipsize(senderName, senderPaintBase, desiredWidth, TextUtils.TruncateAt.END)
                .toString();
        int width = (int) senderPaintBase.measureText(senderNameMeasured);
        layoutRealWidth = Math.max(layoutRealWidth, width);
      }

      Logger.d(TAG, "Build layout end");
    }
예제 #4
0
  @Override
  protected boolean drawBubble(Canvas canvas) {
    if (messageLayout == null) {
      requestLayout();
      return false;
    }

    boolean isAnimated = false;

    if (messageLayout.isForwarded) {
      canvas.drawText("Forwarded message", 0, getPx(16), messageLayout.forwardingPaint);
      canvas.drawText("From", 0, getPx(35), messageLayout.forwardingPaint);
      canvas.drawText(
          messageLayout.forwarderNameMeasured,
          messageLayout.forwardOffset,
          getPx(35),
          messageLayout.senderPaint);
      canvas.save();
      canvas.translate(0, getPx(19) * 2);
      messageLayout.layout.draw(canvas);
      canvas.restore();
    } else {
      if (!messageLayout.isOut & messageLayout.isGroup) {
        canvas.drawText(messageLayout.senderNameMeasured, 0, getPx(16), messageLayout.senderPaint);
        canvas.save();
        canvas.translate(0, getPx(19));
        messageLayout.layout.draw(canvas);
        canvas.restore();
      } else {
        messageLayout.layout.draw(canvas);
      }
    }

    if (messageLayout.showState) {
      if (state == MessageState.PENDING) {
        canvas.save();
        canvas.translate(
            messageLayout.layoutRealWidth - getPx(12),
            messageLayout.layoutHeight - getPx(12) - getPx(3));
        canvas.drawCircle(getPx(6), getPx(6), getPx(6), clockIconPaint);
        double time = (System.currentTimeMillis() / 15.0) % (12 * 60);
        double angle = (time / (6 * 60)) * Math.PI;

        int x = (int) (Math.sin(-angle) * getPx(4));
        int y = (int) (Math.cos(-angle) * getPx(4));
        canvas.drawLine(getPx(6), getPx(6), getPx(6) + x, getPx(6) + y, clockIconPaint);

        x = (int) (Math.sin(-angle * 12) * getPx(5));
        y = (int) (Math.cos(-angle * 12) * getPx(5));
        canvas.drawLine(getPx(6), getPx(6), getPx(6) + x, getPx(6) + y, clockIconPaint);

        canvas.restore();

        clockOutPaint.setColor(COLOR_NORMAL);

        isAnimated = true;
      } else if (state == MessageState.READED
          && prevState == MessageState.SENT
          && (SystemClock.uptimeMillis() - stateChangeTime < STATE_ANIMATION_TIME)) {
        long animationTime = SystemClock.uptimeMillis() - stateChangeTime;
        float progress = easeStateFade(animationTime / (float) STATE_ANIMATION_TIME);
        int offset = (int) (getPx(5) * progress);
        int alphaNew = (int) (progress * 255);

        bounds(
            stateSent,
            messageLayout.layoutRealWidth - stateSent.getIntrinsicWidth() - offset,
            messageLayout.layoutHeight - stateSent.getIntrinsicHeight() - getPx(3));
        stateSent.setAlpha(255);
        stateSent.draw(canvas);

        bounds(
            stateHalfCheck,
            messageLayout.layoutRealWidth - stateHalfCheck.getIntrinsicWidth() + getPx(5) - offset,
            messageLayout.layoutHeight - stateHalfCheck.getIntrinsicHeight() - getPx(3));
        stateHalfCheck.setAlpha(alphaNew);
        stateHalfCheck.draw(canvas);

        clockOutPaint.setColor(COLOR_NORMAL);

        isAnimated = true;
      } else {
        Drawable stateDrawable = getStateDrawable(state);

        bounds(
            stateDrawable,
            messageLayout.layoutRealWidth - stateDrawable.getIntrinsicWidth(),
            messageLayout.layoutHeight - stateDrawable.getIntrinsicHeight() - getPx(3));
        stateDrawable.setAlpha(255);
        stateDrawable.draw(canvas);

        if (state == MessageState.READED) {
          bounds(
              stateSent,
              messageLayout.layoutRealWidth - stateSent.getIntrinsicWidth() - getPx(5),
              messageLayout.layoutHeight - stateDrawable.getIntrinsicHeight() - getPx(3));
          stateSent.setAlpha(255);
          stateSent.draw(canvas);
        }

        if (state == MessageState.FAILURE) {
          clockOutPaint.setColor(COLOR_ERROR);
        } else {
          clockOutPaint.setColor(COLOR_NORMAL);
        }
      }
    } else {
      clockOutPaint.setColor(COLOR_IN);
    }
    canvas.drawText(
        wireframe.date,
        messageLayout.layoutRealWidth - messageLayout.timeWidth + getPx(6),
        messageLayout.layoutHeight - getPx(4),
        clockOutPaint);
    return isAnimated;
  }
예제 #5
0
    public void build(DialogWireframe description, int w, int h, TelegramApplication application) {
      layoutH = h;
      layoutW = w;

      if (description.getPeerType() == PeerType.PEER_USER) {
        if (description.getPeerId() == 333000) {
          isHighlighted = false;
        } else {
          User user = description.getDialogUser();
          isHighlighted = user.getLinkType() == LinkType.FOREIGN;
        }
        isGroup = false;
        isEncrypted = false;
      } else if (description.getPeerType() == PeerType.PEER_CHAT) {
        isHighlighted = false;
        isGroup = true;
        isEncrypted = false;
      } else if (description.getPeerType() == PeerType.PEER_USER_ENCRYPTED) {
        isHighlighted = false;
        isGroup = false;
        isEncrypted = true;
      }

      isBodyHighlighted = description.getContentType() != ContentType.MESSAGE_TEXT;

      if (description.getUnreadCount() != 0 && !description.isMine()) {
        isUnreadIn = true;
      } else {
        isUnreadIn = false;
      }

      time = org.telegram.android.ui.TextUtil.formatDate(description.getDate(), application);
      isRtl = application.isRTL();

      if (IS_LARGE) {
        layoutAvatarWidth = px(64);
        layoutPadding = application.getResources().getDimensionPixelSize(R.dimen.dialogs_padding);
        layoutBodyPadding = layoutAvatarWidth + layoutPadding + px(12);
        layoutAvatarTop = px(8);
        layoutTitleTop = px(34);
        layoutMainTop = px(60);
        layoutTimeTop = px(34);

        layoutMarkTop = px(44);
        layoutMarkBottom = layoutMarkTop + px(22);
        layoutMarkTextTop = layoutMarkTop + px(18);
      } else {
        layoutAvatarWidth = px(54);
        layoutPadding = application.getResources().getDimensionPixelSize(R.dimen.dialogs_padding);
        layoutBodyPadding = layoutAvatarWidth + layoutPadding + px(12);
        layoutAvatarTop = px(8);
        layoutTitleTop = px(30);
        layoutMainTop = px(54);
        layoutTimeTop = px(30);

        layoutMarkTop = px(38);
        layoutMarkBottom = layoutMarkTop + px(22);
        layoutMarkTextTop = layoutMarkTop + px(18);
      }

      layoutMainContentTop = (int) (layoutMainTop + bodyPaint.getFontMetrics().ascent);
      layoutTitleLayoutTop = (int) (layoutTitleTop + titlePaint.getFontMetrics().ascent);
      layoutStateTop = layoutTimeTop - px(10);
      layoutClockTop = layoutTimeTop - px(12);
      layoutEncryptedTop = layoutTimeTop - px(14);

      if (isRtl) {
        layoutAvatarLeft = w - layoutPadding - layoutAvatarWidth;
      } else {
        layoutAvatarLeft = layoutPadding;
      }

      int timeWidth = (int) unreadClockPaint.measureText(time);
      if (isRtl) {
        layoutTimeLeft = layoutPadding;
        layoutStateLeftDouble = layoutPadding + timeWidth + px(2);
        layoutStateLeft = layoutStateLeftDouble + px(6);
        layoutClockLeft = layoutPadding + timeWidth + px(2);
      } else {
        layoutTimeLeft = w - layoutPadding - timeWidth;
        layoutClockLeft = w - layoutPadding - timeWidth - px(14);
        layoutStateLeft = w - layoutPadding - timeWidth - px(16);
        layoutStateLeftDouble = w - layoutPadding - timeWidth - px(6 + 16);
      }

      layoutMarkRadius = px(2);
      if (description.isErrorState()
          || (description.getMessageState() == MessageState.FAILURE && description.isMine())) {
        layoutMarkWidth = px(22);
        if (isRtl) {
          layoutMarkLeft = layoutPadding; // getMeasuredWidth() - layoutMarkWidth - getPx(80);
        } else {
          layoutMarkLeft = w - layoutMarkWidth - layoutPadding;
        }
      } else {
        if (description.getUnreadCount() > 0) {
          if (description.getUnreadCount() >= 1000) {
            unreadCountText =
                I18nUtil.getInstance().correctFormatNumber(description.getUnreadCount() / 1000)
                    + "K";
          } else {
            unreadCountText =
                I18nUtil.getInstance().correctFormatNumber(description.getUnreadCount());
          }
          int width = (int) counterTitlePaint.measureText(unreadCountText);
          Rect r = new Rect();
          counterTitlePaint.getTextBounds(unreadCountText, 0, unreadCountText.length(), r);
          layoutMarkTextTop =
              layoutMarkTop + (layoutMarkBottom - layoutMarkTop + r.top) / 2 - r.top;
          if (width < px(22 - 14)) {
            layoutMarkWidth = px(22);
          } else {
            layoutMarkWidth = px(14) + width;
          }
          layoutMarkTextLeft = (layoutMarkWidth - width) / 2;

          if (isRtl) {
            layoutMarkLeft = layoutPadding; // getMeasuredWidth() - layoutMarkWidth - getPx(80);
          } else {
            layoutMarkLeft = w - layoutMarkWidth - layoutPadding;
          }
        } else {
          layoutMarkLeft = 0;
          layoutMarkWidth = 0;
        }
      }
      layoutMarkRect.set(
          layoutMarkLeft, layoutMarkTop, layoutMarkLeft + layoutMarkWidth, layoutMarkBottom);

      if (description.getPeerType() == PeerType.PEER_USER_ENCRYPTED) {
        if (isRtl) {
          if (description.isMine()) {
            layoutTitleLeft = timeWidth + px(16) + px(16);
          } else {
            layoutTitleLeft = timeWidth + px(12);
          }
          layoutTitleWidth = w - layoutTitleLeft - layoutBodyPadding - px(14) - px(6);
          layoutEncryptedLeft = w - layoutBodyPadding - px(12);
        } else {
          layoutTitleLeft = layoutBodyPadding + px(16);
          if (description.isMine()) {
            layoutTitleWidth = w - layoutTitleLeft - timeWidth - px(24);
          } else {
            layoutTitleWidth = w - layoutTitleLeft - timeWidth - px(12);
          }

          layoutEncryptedLeft = layoutBodyPadding + px(2);
        }
      } else {
        if (isRtl) {
          if (description.isMine()) {
            layoutTitleLeft = timeWidth + px(16) + px(16);
          } else {
            layoutTitleLeft = timeWidth + px(12);
          }
          layoutTitleWidth = w - layoutTitleLeft - layoutBodyPadding;
        } else {
          layoutTitleLeft = layoutBodyPadding;
          if (description.isMine()) {
            layoutTitleWidth = w - layoutTitleLeft - timeWidth - px(24) - px(12);
          } else {
            layoutTitleWidth = w - layoutTitleLeft - timeWidth - px(12);
          }
        }
      }

      layoutMainWidth = w - layoutBodyPadding - layoutPadding;
      if (isRtl) {
        layoutMainLeft = w - layoutMainWidth - layoutBodyPadding;
        if (layoutMarkWidth != 0) {
          layoutMainLeft += layoutMarkWidth + px(8);
          layoutMainWidth -= layoutMarkWidth + px(8);
        }
      } else {
        layoutMainLeft = layoutBodyPadding;
        if (layoutMarkWidth != 0) {
          layoutMainWidth -= layoutMarkWidth + px(8);
        }
      }

      avatarRect.set(
          layoutAvatarLeft,
          layoutAvatarTop,
          layoutAvatarLeft + layoutAvatarWidth,
          layoutAvatarTop + layoutAvatarWidth);

      // Building text layouts
      {
        String message = description.getMessage();
        if (message.length() > 150) {
          message = message.substring(0, 150) + "...";
        }
        message = message.replace("\n", " ");

        TextPaint bodyTextPaint;
        if (isBodyHighlighted) {
          bodyTextPaint = bodyHighlightPaint;
        } else {
          if (HIGHLIGHT_UNDEAD) {
            if (isUnreadIn) {
              bodyTextPaint = bodyUnreadPaint;
            } else {
              bodyTextPaint = bodyPaint;
            }
          } else {
            bodyTextPaint = bodyPaint;
          }
        }

        int nameLength = 0;

        if (description.getContentType() != ContentType.MESSAGE_SYSTEM) {
          if (description.isMine()) {
            String name = application.getResources().getString(R.string.st_dialog_you);
            nameLength = BidiFormatter.getInstance().unicodeWrap(name).length();
            message =
                BidiFormatter.getInstance().unicodeWrap(name)
                    + ": "
                    + BidiFormatter.getInstance().unicodeWrap(message);
          } else {
            if (isGroup) {
              User user = description.getSender();
              nameLength = BidiFormatter.getInstance().unicodeWrap(user.getFirstName()).length();
              message =
                  BidiFormatter.getInstance().unicodeWrap(user.getFirstName().replace("\n", " "))
                      + ": "
                      + BidiFormatter.getInstance().unicodeWrap(message);
            }
          }
        }

        String preSequence =
            TextUtils.ellipsize(message, bodyTextPaint, layoutMainWidth, TextUtils.TruncateAt.END)
                .toString();

        //                Spannable sequence =
        // application.getEmojiProcessor().processEmojiCutMutable(preSequence,
        // EmojiProcessor.CONFIGURATION_DIALOGS);
        //                if (nameLength != 0) {
        //                    sequence.setSpan(new ForegroundColorSpan(HIGHLIGHT_COLOR), 0,
        // Math.min(nameLength, sequence.length()), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        //                }
        //                CharSequence resSequence = TextUtils.ellipsize(sequence, bodyTextPaint,
        // layoutMainWidth, TextUtils.TruncateAt.END);
        //                bodyLayout = new StaticLayout(resSequence, bodyTextPaint, layoutMainWidth,
        // Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        //                bodyString = null;

        Spannable sequence =
            application
                .getEmojiProcessor()
                .processEmojiCutMutable(preSequence, EmojiProcessor.CONFIGURATION_DIALOGS);
        if (nameLength != 0) {
          sequence.setSpan(
              new ForegroundColorSpan(HIGHLIGHT_COLOR),
              0,
              Math.min(nameLength, sequence.length()),
              Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        }

        CharSequence resSequence =
            TextUtils.ellipsize(sequence, bodyTextPaint, layoutMainWidth, TextUtils.TruncateAt.END);
        bodyLayout =
            new StaticLayout(
                resSequence,
                bodyTextPaint,
                layoutMainWidth,
                Layout.Alignment.ALIGN_NORMAL,
                1.0f,
                0.0f,
                false);
        bodyString = null;
        //                if (EmojiProcessor.containsEmoji(message)) {
        //                    Spannable sequence =
        // application.getEmojiProcessor().processEmojiCutMutable(preSequence,
        // EmojiProcessor.CONFIGURATION_DIALOGS);
        //                    if (nameLength != 0) {
        //                        sequence.setSpan(new ForegroundColorSpan(HIGHLIGHT_COLOR), 0,
        // Math.min(nameLength, sequence.length()), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        //                    }
        //
        //                    CharSequence resSequence = TextUtils.ellipsize(sequence,
        // bodyTextPaint, layoutMainWidth, TextUtils.TruncateAt.END);
        //                    bodyLayout = new StaticLayout(resSequence, bodyTextPaint,
        // layoutMainWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        //                    bodyString = null;
        //                } else {
        //                    bodyString = preSequence;
        //                    bodyLayout = null;
        //                }
      }

      // Title
      {
        String title = description.getDialogTitle();
        if (title.length() > 150) {
          title = title.substring(150) + "...";
        }
        title = title.replace("\n", " ");

        TextPaint paint =
            isEncrypted ? titleEncryptedPaint : (isHighlighted ? titleHighlightPaint : titlePaint);

        //                Spannable preSequence =
        // application.getEmojiProcessor().processEmojiCutMutable(title,
        // EmojiProcessor.CONFIGURATION_DIALOGS);
        //                CharSequence sequence = TextUtils.ellipsize(preSequence, paint,
        // layoutTitleWidth, TextUtils.TruncateAt.END);
        //                titleLayout = new StaticLayout(sequence, paint, layoutTitleWidth,
        // Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        //                titleString = null;

        if (EmojiProcessor.containsEmoji(title)) {
          Spannable preSequence =
              application
                  .getEmojiProcessor()
                  .processEmojiCutMutable(title, EmojiProcessor.CONFIGURATION_DIALOGS);
          CharSequence sequence =
              TextUtils.ellipsize(preSequence, paint, layoutTitleWidth, TextUtils.TruncateAt.END);
          titleLayout =
              new StaticLayout(
                  sequence,
                  paint,
                  layoutTitleWidth,
                  Layout.Alignment.ALIGN_NORMAL,
                  1.0f,
                  0.0f,
                  false);
          titleString = null;
        } else {
          titleString =
              TextUtils.ellipsize(title, paint, layoutTitleWidth, TextUtils.TruncateAt.END)
                  .toString();
          titleLayout = null;
        }
      }

      // Placeholder
      placeHolderName = description.getDialogName();
      placeHolderColor = Placeholders.getBgColor(description.getPeerId());

      if (placeHolderName.length() > 0) {
        usePlaceholder = true;
        placeholderLeft = layoutAvatarLeft + layoutAvatarWidth / 2;
        Rect rect = new Rect();
        placeholderTextPaint.getTextBounds(placeHolderName, 0, placeHolderName.length(), rect);
        placeholderTop = layoutAvatarTop + (layoutAvatarWidth / 2 + ((rect.bottom - rect.top) / 2));
      } else {
        usePlaceholder = false;
      }
    }
예제 #6
0
  private static void checkResources(Context context) {
    if (!isLoaded) {
      TelegramApplication application = (TelegramApplication) context.getApplicationContext();
      IS_LARGE =
          application.getUserSettings().getDialogItemSize() == UserSettings.DIALOG_SIZE_LARGE;

      avatarPaint = new Paint();

      if (FontController.USE_SUBPIXEL) {
        titlePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        titlePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }

      titlePaint.setColor(0xff222222);
      if (IS_LARGE) {
        titlePaint.setTextSize(sp(20f));
        titlePaint.setTypeface(FontController.loadTypeface(context, "medium"));
      } else {
        titlePaint.setTextSize(sp(18f));
        titlePaint.setTypeface(FontController.loadTypeface(context, "medium"));
      }

      if (FontController.USE_SUBPIXEL) {
        titleHighlightPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        titleHighlightPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      titleHighlightPaint.setColor(0xff006FC8);
      if (IS_LARGE) {
        titleHighlightPaint.setTextSize(sp(20f));
        titleHighlightPaint.setTypeface(FontController.loadTypeface(context, "medium"));
      } else {
        titleHighlightPaint.setTextSize(sp(18f));
        titleHighlightPaint.setTypeface(FontController.loadTypeface(context, "medium"));
      }

      if (FontController.USE_SUBPIXEL) {
        titleEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        titleEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      titleEncryptedPaint.setColor(0xff368c3e);
      if (IS_LARGE) {
        titleEncryptedPaint.setTextSize(sp(20f));
        titleEncryptedPaint.setTypeface(FontController.loadTypeface(context, "medium"));
      } else {
        titleEncryptedPaint.setTextSize(sp(18f));
        titleEncryptedPaint.setTypeface(FontController.loadTypeface(context, "medium"));
      }

      if (FontController.USE_SUBPIXEL) {
        unreadClockPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        unreadClockPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      unreadClockPaint.setColor(UNREAD_TIME_COLOR);
      unreadClockPaint.setTextSize(sp(14));
      unreadClockPaint.setTypeface(FontController.loadTypeface(context, "regular"));

      if (FontController.USE_SUBPIXEL) {
        readClockPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        readClockPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      readClockPaint.setColor(READ_TIME_COLOR);
      readClockPaint.setTextSize(sp(14));
      readClockPaint.setTypeface(FontController.loadTypeface(context, "regular"));

      if (FontController.USE_SUBPIXEL) {
        bodyPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        bodyPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      bodyPaint.setColor(READ_COLOR);
      bodyPaint.setTextSize(sp(17f));
      bodyPaint.setTypeface(FontController.loadTypeface(context, "regular"));

      if (FontController.USE_SUBPIXEL) {
        bodyUnreadPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        bodyUnreadPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      bodyUnreadPaint.setColor(UNREAD_COLOR);
      bodyUnreadPaint.setTextSize(sp(17f));
      bodyUnreadPaint.setTypeface(FontController.loadTypeface(context, "regular"));

      if (FontController.USE_SUBPIXEL) {
        bodyHighlightPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        bodyHighlightPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      bodyHighlightPaint.setColor(HIGHLIGHT_COLOR);
      bodyHighlightPaint.setTextSize(sp(17f));
      bodyHighlightPaint.setTypeface(FontController.loadTypeface(context, "regular"));

      if (FontController.USE_SUBPIXEL) {
        typingPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        typingPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      typingPaint.setColor(0xff006FC8);
      typingPaint.setTextSize(sp(16f));
      typingPaint.setTypeface(FontController.loadTypeface(context, "regular"));

      if (FontController.USE_SUBPIXEL) {
        counterTitlePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        counterTitlePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      counterTitlePaint.setColor(0xffffffff);
      if (IS_LARGE) {
        counterTitlePaint.setTextSize(sp(15.5f));
      } else {
        counterTitlePaint.setTextSize(sp(14f));
      }
      counterTitlePaint.setTypeface(FontController.loadTypeface(context, "regular"));

      counterPaint = new Paint();
      counterPaint.setColor(0xff8fc478);
      counterPaint.setAntiAlias(true);

      placeholderPaint = new Paint();
      placeholderPaint.setAntiAlias(true);

      if (FontController.USE_SUBPIXEL) {
        placeholderTextPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      } else {
        placeholderTextPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      }
      placeholderTextPaint.setColor(0xffffffff);
      placeholderTextPaint.setTextSize(px(28f));
      placeholderTextPaint.setTypeface(FontController.loadTypeface(context, "regular"));
      placeholderTextPaint.setTextAlign(Paint.Align.CENTER);

      isLoaded = true;
    }
  }