コード例 #1
1
  @Override
  public void setMessageObject(MessageObject messageObject) {
    boolean dataChanged = currentMessageObject == messageObject && isUserDataChanged();
    if (currentMessageObject != messageObject || dataChanged) {
      if (AndroidUtilities.isTablet()) {
        backgroundWidth =
            Math.min(
                AndroidUtilities.getMinTabletSide()
                    - AndroidUtilities.dp(
                        isChat && messageObject.messageOwner.from_id > 0 ? 102 : 50),
                AndroidUtilities.dp(300));
      } else {
        backgroundWidth =
            Math.min(
                AndroidUtilities.displaySize.x
                    - AndroidUtilities.dp(
                        isChat && messageObject.messageOwner.from_id > 0 ? 102 : 50),
                AndroidUtilities.dp(300));
      }

      if (messageObject.isOutOwner()) {
        seekBar.type = 0;
        radialProgress.setProgressColor(theme.ChatMusicCell_radialProgress_color);
      } else {
        seekBar.type = 1;
        radialProgress.setProgressColor(theme.ChatMusicCell_radialProgress_color_2);
      }

      int maxWidth = backgroundWidth - AndroidUtilities.dp(86);

      CharSequence stringFinal =
          TextUtils.ellipsize(
              messageObject.getMusicTitle().replace("\n", " "),
              titlePaint,
              maxWidth,
              TextUtils.TruncateAt.END);
      titleLayout =
          new StaticLayout(
              stringFinal, titlePaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
      if (titleLayout.getLineCount() > 0) {
        titleX = (int) Math.ceil(titleLayout.getLineLeft(0));
      }

      stringFinal =
          TextUtils.ellipsize(
              messageObject.getMusicAuthor().replace("\n", " "),
              authorPaint,
              maxWidth,
              TextUtils.TruncateAt.END);
      authorLayout =
          new StaticLayout(
              stringFinal, authorPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
      if (authorLayout.getLineCount() > 0) {
        authorX = (int) Math.ceil(authorLayout.getLineLeft(0));
      }

      super.setMessageObject(messageObject);
    }
    updateButtonState(dataChanged);
  }
コード例 #2
0
 private void drawTitle(Canvas paramCanvas)
 {
   boolean bool = isPlaying();
   if (bool)
     drawLivingLabel(paramCanvas);
   TextPaint localTextPaint = SkinManager.getInstance().getNormalTextPaint();
   String str = getTitle();
   int j = this.mArrowRect.left;
   int i;
   float f1;
   label123: float f2;
   if (bool)
   {
     i = this.mLivingRect.right + this.channelLayout.leftMargin;
     str = TextUtils.ellipsize(str, localTextPaint, j - i, TextUtils.TruncateAt.END).toString();
     localTextPaint.getTextBounds(str, 0, str.length(), this.textBound);
     if (!bool)
       break label202;
     f1 = this.mLivingRect.right + this.livingLayout.leftMargin;
     f2 = this.channelLayout.topMargin + (this.channelLayout.height - this.textBound.top - this.textBound.bottom) / 2;
     if ((!bool) && (!isItemPressed()))
       break label214;
     paramCanvas.drawText(str, f1, f2, SkinManager.getInstance().getHighlightTextPaint());
   }
   while (true)
   {
     drawSubInfo(paramCanvas);
     return;
     i = this.channelLayout.leftMargin;
     break;
     label202: f1 = this.channelLayout.leftMargin;
     break label123;
     label214: paramCanvas.drawText(str, f1, f2, localTextPaint);
   }
 }
コード例 #3
0
ファイル: StringUtil.java プロジェクト: noorazmi/LLOOGGCCAATT
  private static CharSequence ellipsizeFromCache(CharSequence str, int width, TextPaint paint) {
    // the TextUtils.ellipsize method is really expensive, so we can exploit
    // the fact that we're using monospace-style text
    // to just cache the correct number of characters given the width

    Integer maxLength = PreferenceHelper.ellipsisLengthsCache.get(width);

    if (maxLength != null) { // cached

      if (str.length() < maxLength) {
        return str;
      }

      // truncate and add ellipsis
      StringBuilder stringBuilder = new StringBuilder(str);
      if (stringBuilder.length() > maxLength) {
        stringBuilder.delete(maxLength, stringBuilder.length());
      }
      if (stringBuilder.length() > 0) {
        stringBuilder.setCharAt(stringBuilder.length() - 1, (char) 8230); // add
        // ellipsis
        // character
      }
      return stringBuilder;
    }

    CharSequence result = TextUtils.ellipsize(str, paint, width, TruncateAt.END);
    if (result.length() < str.length()) { // was ellipsized
      PreferenceHelper.ellipsisLengthsCache.put(width, result.length());
    }
    return result;
  }
コード例 #4
0
  /**
   * @param textview
   * @return
   */
  private String adjustTextLength(TextView tv) {
    if (tv == null) {
      return "";
    }
    String input = tv.getText().toString();
    String result = input;
    String newtext = input;
    int lastSpaceIndex = 0;
    ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) tv.getLayoutParams();
    Paint p = tv.getPaint();
    Rect bound = new Rect();
    p.getTextBounds(input, 0, input.length() - 1, bound);
    float textHeight = p.getTextSize();
    float multiLine = (((lp.height - tv.getPaddingTop() - tv.getPaddingBottom()) / textHeight));
    float availableW = (lp.width - tv.getPaddingLeft() - tv.getPaddingRight()) * (multiLine + 0.2f);

    do {

      newtext = (String) TextUtils.ellipsize(result, tv.getPaint(), availableW, TruncateAt.END);
      if (!newtext.equals(result)) {
        lastSpaceIndex = newtext.lastIndexOf(" ");
        if (lastSpaceIndex > 0) {
          result = newtext.substring(0, lastSpaceIndex) + "...";
        } else {
          break;
        }
      } else {
        break;
      }
    } while (false);

    GKIMLog.lf(null, 0, TAG + "=>adjust title from: " + input + " to: " + result);
    tv.setText(result);
    return result;
  }
コード例 #5
0
 public void c(CharSequence paramCharSequence) {
   if (Build.VERSION.SDK_INT >= 14) {
     q = paramCharSequence;
     paramCharSequence = Long.valueOf(new Date().getTime());
     if ((paramCharSequence.longValue() - b >= 300L) || (u == v)) {
       break label91;
     }
   }
   for (; ; ) {
     return;
     if (paramCharSequence != null) {
       q = TextUtils.ellipsize(paramCharSequence, y, 200.0F, TextUtils.TruncateAt.MIDDLE);
       break;
     }
     q = "";
     break;
     label91:
     b = paramCharSequence.longValue();
     if (Build.VERSION.SDK_INT >= 14) {
       al.a(x).a("setContentText", CharSequence.class, q);
     }
     while (k) {
       c();
       return;
       if (u != -1L) {
         w.b(q + "  " + u * 100L / v + "%");
       } else {
         w.b(q);
       }
     }
   }
 }
コード例 #6
0
 private void drawRecentTitle(Canvas paramCanvas) {
   Object localObject2 = "继续收听  “";
   Object localObject1 = localObject2;
   if (this.mNode != null) {
     localObject1 = localObject2;
     if (this.mNode.nodeName != null) {
       localObject1 = localObject2;
       if (this.mNode.nodeName.equalsIgnoreCase("playhistory"))
         localObject1 =
             "继续收听  “" + ((ProgramNode) ((PlayHistoryNode) this.mNode).playNode).title + "”";
     }
   }
   localObject2 = SkinManager.getInstance().getSubTextPaint();
   localObject1 =
       TextUtils.ellipsize(
               (CharSequence) localObject1,
               (TextPaint) localObject2,
               this.recentTitleLayout.width,
               TextUtils.TruncateAt.END)
           .toString();
   Rect localRect = new Rect();
   ((TextPaint) localObject2)
       .getTextBounds((String) localObject1, 0, ((String) localObject1).length(), localRect);
   float f = this.recentTitleLayout.leftMargin;
   int i = this.recentTitleLayout.topMargin;
   int j = localRect.top;
   paramCanvas.drawText(
       (String) localObject1,
       f,
       (this.recentItemLayout.height - localRect.height()) / 2 + (i - j),
       (Paint) localObject2);
 }
コード例 #7
0
 private float a(TextView paramTextView, float paramFloat, String paramString)
 {
   float f3 = paramTextView.getTextSize();
   label23:
   Object localObject;
   if ((paramTextView == null) || (paramFloat <= 0.0F) || (paramString == null))
   {
     return f3;
     paramTextView.setTextSize(0, localObject);
   }
   for (;;)
   {
     float f2 = localObject;
     if (paramString != TextUtils.ellipsize(paramString, paramTextView.getPaint(), paramFloat, TextUtils.TruncateAt.END))
     {
       localObject -= 1.0F;
       if (f1 >= 0.0F) {
         break label23;
       }
       f2 = f1;
     }
     if (f2 < 0.0F) {
       break;
     }
     return f2;
     float f1 = f3;
   }
 }
コード例 #8
0
 private void drawUpdateTime(
     Canvas paramCanvas, float paramFloat1, float paramFloat2, int paramInt) {
   String str;
   if (this.mNode.nodeName.equalsIgnoreCase("program"))
     if (((ProgramNode) this.mNode).channelType == 1)
       str = getUpdateTimeString((ProgramNode) this.mNode);
   while (true)
     if (str == null) {
       return;
       if (((ProgramNode) this.mNode).getCurrPlayStatus() == 3)
         str = TimeUtil.msToDate5(((ProgramNode) this.mNode).getAbsoluteStartTime() * 1000L);
     } else {
       str =
           TextUtils.ellipsize(
                   str, this.mUpdateTimePaint, paramFloat2 - paramFloat1, TextUtils.TruncateAt.END)
               .toString();
       this.mUpdateTimePaint.getTextBounds(str, 0, str.length(), this.textBound);
       paramCanvas.drawText(
           str,
           this.otherInfoLayout.leftMargin + paramFloat1,
           this.otherInfoLayout.topMargin
               + paramInt
               + (this.otherInfoLayout.height - this.textBound.height()),
           this.mUpdateTimePaint);
       return;
       str = null;
     }
 }
コード例 #9
0
  private static String getStringWithEllipsis(String string, float width, float fontSize) {
    if (TextUtils.isEmpty(string)) {
      return "";
    }

    TextPaint paint = new TextPaint();
    paint.setTypeface(Typeface.DEFAULT);
    paint.setTextSize(fontSize);

    return TextUtils.ellipsize(string, paint, width, TextUtils.TruncateAt.END).toString();
  }
コード例 #10
0
  public UserSpan(UserVM user, int maxW) {
    this.user = user;
    this.maxW = maxW;
    if (textPaint == null) {
      textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
      textPaint.setTextSize(Screen.sp(16));
      textPaint.setColor(AndroidContext.getContext().getResources().getColor(R.color.text_primary));
    }

    int padding = Screen.dp(18);
    int maxWidth = maxW - padding;
    userText =
        TextUtils.ellipsize(user.getName().get(), textPaint, maxWidth, TextUtils.TruncateAt.END)
            .toString();
  }
コード例 #11
0
ファイル: DialogView.java プロジェクト: johack0/telegram
 private void updateTyping() {
   needNewUpdateTyping = false;
   if (description.getPeerType() == PeerType.PEER_USER
       || description.getPeerType() == PeerType.PEER_USER_ENCRYPTED) {
     if (userTypes) {
       typingLayout =
           new StaticLayout(
               getResources().getString(R.string.lang_common_typing),
               bodyHighlightPaint,
               layout.layoutMainWidth,
               Layout.Alignment.ALIGN_NORMAL,
               1.0f,
               0.0f,
               false);
     } else {
       typingLayout = null;
     }
   } else {
     if (typingUids != null && typingUids.length != 0) {
       String[] names = new String[typingUids.length];
       for (int i = 0; i < names.length; i++) {
         names[i] = application.getEngine().getUserRuntime(typingUids[i]).getFirstName();
       }
       String typing = TextUtil.formatTyping(names);
       Spannable spannable =
           application
               .getEmojiProcessor()
               .processEmojiCutMutable(typing, EmojiProcessor.CONFIGURATION_DIALOGS);
       CharSequence sequence =
           TextUtils.ellipsize(
               spannable, bodyHighlightPaint, layout.layoutMainWidth, TextUtils.TruncateAt.END);
       typingLayout =
           new StaticLayout(
               sequence,
               bodyHighlightPaint,
               layout.layoutMainWidth,
               Layout.Alignment.ALIGN_NORMAL,
               1.0f,
               0.0f,
               false);
     } else {
       typingLayout = null;
     }
   }
 }
コード例 #12
0
 @Override
 public CharSequence filter(
     CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
   char[] v = new char[end - start];
   TextUtils.getChars(source, start, end, v, 0);
   Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);
   if (source instanceof Spanned) {
     TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
   }
   view.getViewTreeObserver().addOnGlobalLayoutListener(this);
   if (view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) {
     return emojified;
   } else {
     return TextUtils.ellipsize(
         emojified,
         view.getPaint(),
         view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(),
         TruncateAt.END);
   }
 }
コード例 #13
0
  @Override
  protected void measureBubbleContent(int width) {
    int realWidth = width - getPx(50); // Avatar
    if (showAddButton) {
      realWidth -= getPx(54); // Button
    }

    realWidth -= getPx(4);

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

    title = TextUtils.ellipsize(title, senderPaint, realWidth, TextUtils.TruncateAt.END).toString();
    layoutWidth =
        Math.max(
            (int) senderPaint.measureText(title, 0, title.length()),
            (int) bodyPaint.measureText(phone, 0, phone.length()));
    layoutWidth += getPx(42);
    layoutWidth += getPx(4);
    if (showAddButton) {
      setBubbleMeasuredContent(layoutWidth + getPx(56 + 16), getPx(60));
    } else {
      setBubbleMeasuredContent(layoutWidth + getPx(16), getPx(60));
    }
  }
コード例 #14
0
 public static StaticLayout createStaticLayout(
     CharSequence source,
     int bufstart,
     int bufend,
     TextPaint paint,
     int outerWidth,
     Layout.Alignment align,
     float spacingMult,
     float spacingAdd,
     boolean includePad,
     TextUtils.TruncateAt ellipsize,
     int ellipsisWidth,
     int maxLines) {
   /*if (Build.VERSION.SDK_INT >= 14) {
       init();
       try {
           sConstructorArgs[0] = source;
           sConstructorArgs[1] = bufstart;
           sConstructorArgs[2] = bufend;
           sConstructorArgs[3] = paint;
           sConstructorArgs[4] = outerWidth;
           sConstructorArgs[5] = align;
           sConstructorArgs[6] = sTextDirection;
           sConstructorArgs[7] = spacingMult;
           sConstructorArgs[8] = spacingAdd;
           sConstructorArgs[9] = includePad;
           sConstructorArgs[10] = ellipsize;
           sConstructorArgs[11] = ellipsisWidth;
           sConstructorArgs[12] = maxLines;
           return sConstructor.newInstance(sConstructorArgs);
       } catch (Exception e) {
           FileLog.e("tmessages", e);
       }
   }*/
   try {
     if (maxLines == 1) {
       CharSequence text =
           TextUtils.ellipsize(source, paint, ellipsisWidth, TextUtils.TruncateAt.END);
       return new StaticLayout(
           text, 0, text.length(), paint, outerWidth, align, spacingMult, spacingAdd, includePad);
     } else {
       StaticLayout layout =
           new StaticLayout(source, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
       if (layout.getLineCount() <= maxLines) {
         return layout;
       } else {
         int off;
         float left = layout.getLineLeft(maxLines - 1);
         if (left != 0) {
           off = layout.getOffsetForHorizontal(maxLines - 1, left);
         } else {
           off = layout.getOffsetForHorizontal(maxLines - 1, layout.getLineWidth(maxLines - 1));
         }
         SpannableStringBuilder stringBuilder =
             new SpannableStringBuilder(source.subSequence(0, Math.max(0, off - 1)));
         stringBuilder.append("\u2026");
         return new StaticLayout(
             stringBuilder, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
       }
     }
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return null;
 }
コード例 #15
0
  @Override
  public void setMessageObject(MessageObject messageObject) {
    if (currentMessageObject != messageObject || isUserDataChanged()) {

      int uid = messageObject.messageOwner.media.user_id;
      contactUser = MessagesController.getInstance().getUser(uid);

      drawAddButton =
          contactUser != null
              && uid != UserConfig.getClientUserId()
              && ContactsController.getInstance().contactsDict.get(uid) == null;

      int maxWidth;
      if (AndroidUtilities.isTablet()) {
        maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
      } else {
        maxWidth =
            (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
      }
      maxWidth -= AndroidUtilities.dp(58 + (drawAddButton ? 42 : 0));

      if (contactUser != null) {
        if (contactUser.photo != null) {
          currentPhoto = contactUser.photo.photo_small;
        } else {
          currentPhoto = null;
        }
        avatarDrawable.setInfo(contactUser);
      } else {
        currentPhoto = null;
        avatarDrawable.setInfo(uid, null, null, false);
      }
      avatarImage.setImage(currentPhoto, "50_50", avatarDrawable, null, false);

      String currentNameString =
          ContactsController.formatName(
              messageObject.messageOwner.media.first_name,
              messageObject.messageOwner.media.last_name);
      int nameWidth = Math.min((int) Math.ceil(namePaint.measureText(currentNameString)), maxWidth);

      CharSequence stringFinal =
          TextUtils.ellipsize(
              currentNameString.replace("\n", " "), namePaint, nameWidth, TextUtils.TruncateAt.END);
      nameLayout =
          new StaticLayout(
              stringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
      if (nameLayout.getLineCount() > 0) {
        nameWidth = (int) Math.ceil(nameLayout.getLineWidth(0));
      } else {
        nameWidth = 0;
      }

      String phone = messageObject.messageOwner.media.phone_number;
      if (phone != null && phone.length() != 0) {
        if (!phone.startsWith("+")) {
          phone = "+" + phone;
        }
        phone = PhoneFormat.getInstance().format(phone);
      } else {
        phone = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
      }
      int phoneWidth = Math.min((int) Math.ceil(phonePaint.measureText(phone)), maxWidth);
      stringFinal =
          TextUtils.ellipsize(
              phone.replace("\n", " "), phonePaint, phoneWidth, TextUtils.TruncateAt.END);
      phoneLayout =
          new StaticLayout(
              stringFinal,
              phonePaint,
              phoneWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);
      if (phoneLayout.getLineCount() > 0) {
        phoneWidth = (int) Math.ceil(phoneLayout.getLineWidth(0));
      } else {
        phoneWidth = 0;
      }

      namesWidth = Math.max(nameWidth, phoneWidth);
      backgroundWidth = AndroidUtilities.dp(77 + (drawAddButton ? 42 : 0)) + namesWidth;

      super.setMessageObject(messageObject);
    }
  }
コード例 #16
0
ファイル: MessageView.java プロジェクト: markadam/telegram
    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");
    }
コード例 #17
0
  private void adjustTextBounds(NMapView mapView) {

    //  First determine the screen coordinates of the selected MapLocation
    mapView.getMapProjection().toPixels(mOverlayItem.getPointInUtmk(), mTempPoint);

    int mapViewWidth = mapView.getMapController().getViewFrameVisibleWidth();
    if (mTitleTruncated == null || mWidthTitleTruncated != mapViewWidth) {
      mWidthTitleTruncated = mapViewWidth;
      float maxWidth = mWidthTitleTruncated - 2 * mMarginX - 2 * mPaddingX;
      if (DEBUG) {
        Log.i(
            LOG_TAG,
            "adjustTextBounds: maxWidth="
                + maxWidth
                + ", mMarginX="
                + mMarginX
                + ", mPaddingX="
                + mPaddingX);
      }

      if (mDrawableRightButton != null) {
        maxWidth -= mPaddingX + mCalloutRightButtonWidth;
      }

      if (mTailText != null) {
        mTextPaint.getTextBounds(mTailText, 0, mTailText.length(), mTempRect);
        mTailTextWidth = mTempRect.width();

        maxWidth -= mTailGapX + mTailTextWidth;
      }

      final String title =
          TextUtils.ellipsize(
                  mOverlayItem.getTitle(), mTextPaint, maxWidth, TextUtils.TruncateAt.END)
              .toString();

      mTitleTruncated = title;

      if (DEBUG) {
        Log.i(
            LOG_TAG,
            "adjustTextBounds: mTitleTruncated="
                + mTitleTruncated
                + ", length="
                + mTitleTruncated.length());
      }
    }

    mTextPaint.getTextBounds(mTitleTruncated, 0, mTitleTruncated.length(), mTempRect);

    if (mDrawableRightButton != null) {
      mTempRect.right += mPaddingX + mCalloutRightButtonWidth;
    }

    if (mTailText != null) {
      mTempRect.right += mTailGapX + mTailTextWidth;
    }

    if (DEBUG) {
      Log.i(
          LOG_TAG,
          "adjustTextBounds: mTempRect.width="
              + mTempRect.width()
              + ", mTempRect.height="
              + mTempRect.height());
    }

    //  Setup the callout with the right size & location
    mTempRectF.set(mTempRect);
    final float dy = (mBackgroundHeight - mTempRect.height()) / 2;
    mTempRectF.inset(-mPaddingX, -dy);
    // mTempRectF.inset(-mPaddingX, -mPaddingY);

    // set minimum size
    if (mTempRectF.width() < mMinimumWidth) {
      final float dx = (mMinimumWidth - mTempRectF.width()) / 2;
      mTempRectF.inset(-dx, 0);
    }

    // set position
    float left = mTempPoint.x - (int) (mTempRectF.width() * mOverlayItem.getAnchorXRatio());
    float top =
        mTempPoint.y
            - (int) (mItemBounds.height() * mOverlayItem.getAnchorYRatio())
            - mItemGapY
            - mTotalHeight;
    mTempRectF.set(left, top, left + mTempRectF.width(), top + mTempRectF.height());
  }
コード例 #18
0
ファイル: ComposeText.java プロジェクト: aknik/SMSSecure
 private CharSequence ellipsizeToWidth(CharSequence text) {
   return TextUtils.ellipsize(
       text, getPaint(), getWidth() - getPaddingLeft() - getPaddingRight(), TruncateAt.END);
 }
コード例 #19
0
ファイル: p.java プロジェクト: JaapSuter/Niets
 public void draw(Canvas paramCanvas) {
   boolean bool = DialogToastListActivity.f;
   super.draw(paramCanvas);
   Paint localPaint = new Paint();
   localPaint.setAntiAlias(true);
   RectF localRectF = new RectF(getBounds());
   if (this.d != null) {
     int i = (int) (13.333333F * j4.a(App.Mb.getApplicationContext()).d);
     int j = (int) (2.0F * i);
     Path localPath = new Path();
     localPath.moveTo(localRectF.left, localRectF.bottom - j);
     localPath.lineTo(localRectF.right, localRectF.bottom - j);
     localPath.lineTo(localRectF.right, localRectF.bottom - this.a);
     localPath.arcTo(
         new RectF(
             localRectF.right - 2.0F * this.a,
             localRectF.bottom - 2.0F * this.a,
             localRectF.right,
             localRectF.bottom),
         0.0F,
         90.0F);
     localPath.lineTo(localRectF.left + this.a, localRectF.bottom);
     localPath.arcTo(
         new RectF(
             localRectF.left,
             localRectF.bottom - 2.0F * this.a,
             localRectF.left + 2.0F * this.a,
             localRectF.bottom),
         90.0F,
         90.0F);
     localPath.lineTo(localRectF.left, localRectF.bottom - j);
     localPaint.setStyle(Paint.Style.FILL);
     if (this.b == 16842919) {
       localPaint.setColor(-1712291840);
       if (!bool) ;
     } else {
       localPaint.setColor(1073741824);
     }
     paramCanvas.drawPath(localPath, localPaint);
     TextPaint localTextPaint = new TextPaint();
     localTextPaint.setAntiAlias(true);
     localTextPaint.setColor(-1);
     localTextPaint.setTextSize(i);
     localTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
     localTextPaint.setTextAlign(Paint.Align.CENTER);
     paramCanvas.drawText(
         TextUtils.ellipsize(
                 this.d, localTextPaint, localRectF.width() - this.a, TextUtils.TruncateAt.END)
             .toString(),
         localRectF.left + localRectF.width() / 2.0F,
         localRectF.bottom - (j - i) / 2,
         localTextPaint);
   }
   localPaint.setStyle(Paint.Style.STROKE);
   localPaint.setStrokeJoin(Paint.Join.ROUND);
   localPaint.setStrokeCap(Paint.Cap.ROUND);
   localRectF.top = (1.0F + localRectF.top);
   localRectF.bottom = (1.0F + localRectF.bottom);
   localPaint.setStrokeWidth(1.5F);
   localPaint.setColor(-1711276033);
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
   localRectF.top -= 1.0F;
   localRectF.bottom -= 1.0F;
   if (this.b == 16842919) {
     localPaint.setColor(-1015808);
     if (!bool) ;
   } else {
     localPaint.setColor(1711276032);
   }
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
   localPaint.setStrokeWidth(1.0F);
   localPaint.setAntiAlias(false);
   if (this.b == 16842919) {
     localPaint.setColor(871399424);
     if (!bool) ;
   } else {
     localPaint.setColor(855638016);
   }
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
 }
コード例 #20
0
  /**
   * Attempts to draw the given event. Returns the y for the next event or the original y if the
   * event will not fit. An event is considered to not fit if the event and its extras won't fit or
   * if there are more events and the more events line would not fit after drawing this event.
   *
   * @param canvas the canvas to draw on
   * @param event the event to draw
   * @param x the top left corner for this event's color chip
   * @param y the top left corner for this event's color chip
   * @param rightEdge the rightmost point we're allowed to draw on (exclusive)
   * @param moreEvents indicates whether additional events will follow this one
   * @param showTimes if set, a second line with a time range will be displayed for non-all-day
   *     events
   * @param doDraw if set, do the actual drawing; otherwise this just computes the height and
   *     returns
   * @return the y for the next event or the original y if it won't fit
   */
  protected int drawEvent(
      Canvas canvas,
      Event event,
      int x,
      int y,
      int rightEdge,
      boolean moreEvents,
      boolean showTimes,
      boolean doDraw) {
    /*
     * Vertical layout:
     *   (top of box)
     * a. EVENT_Y_OFFSET_LANDSCAPE or portrait equivalent
     * b. Event title: mEventHeight for a normal event, + 2xBORDER_SPACE for all-day event
     * c. [optional] Time range (mExtrasHeight)
     * d. EVENT_LINE_PADDING
     *
     * Repeat (b,c,d) as needed and space allows.  If we have more events than fit, we need
     * to leave room for something like "+2" at the bottom:
     *
     * e. "+ more" line (mExtrasHeight)
     *
     * f. EVENT_BOTTOM_PADDING (overlaps EVENT_LINE_PADDING)
     *   (bottom of box)
     */
    final int BORDER_SPACE = EVENT_SQUARE_BORDER + 1; // want a 1-pixel gap inside border
    final int STROKE_WIDTH_ADJ = EVENT_SQUARE_BORDER / 2; // adjust bounds for stroke width
    boolean allDay = event.allDay;
    int eventRequiredSpace = mEventHeight;
    if (allDay) {
      // Add a few pixels for the box we draw around all-day events.
      eventRequiredSpace += BORDER_SPACE * 2;
    } else if (showTimes) {
      // Need room for the "1pm - 2pm" line.
      eventRequiredSpace += mExtrasHeight;
    }
    int reservedSpace = EVENT_BOTTOM_PADDING; // leave a bit of room at the bottom
    if (moreEvents) {
      // More events follow.  Leave a bit of space between events.
      eventRequiredSpace += EVENT_LINE_PADDING;

      // Make sure we have room for the "+ more" line.  (The "+ more" line is expected
      // to be <= the height of an event line, so we won't show "+1" when we could be
      // showing the event.)
      reservedSpace += mExtrasHeight;
    }

    if (y + eventRequiredSpace + reservedSpace > mHeight) {
      // Not enough space, return original y
      return y;
    } else if (!doDraw) {
      return y + eventRequiredSpace;
    }

    boolean isDeclined = event.selfAttendeeStatus == Attendees.ATTENDEE_STATUS_DECLINED;
    int color = event.color;
    if (isDeclined) {
      color = Utils.getDeclinedColorFromColor(color);
    }

    int textX, textY, textRightEdge;

    if (allDay) {
      // We shift the render offset "inward", because drawRect with a stroke width greater
      // than 1 draws outside the specified bounds.  (We don't adjust the left edge, since
      // we want to match the existing appearance of the "event square".)
      r.left = x;
      r.right = rightEdge - STROKE_WIDTH_ADJ;
      r.top = y + STROKE_WIDTH_ADJ;
      r.bottom = y + mEventHeight + BORDER_SPACE * 2 - STROKE_WIDTH_ADJ;
      textX = x + BORDER_SPACE;
      textY = y + mEventAscentHeight + BORDER_SPACE;
      textRightEdge = rightEdge - BORDER_SPACE;
    } else {
      r.left = x;
      r.right = x + EVENT_SQUARE_WIDTH;
      r.bottom = y + mEventAscentHeight;
      r.top = r.bottom - EVENT_SQUARE_WIDTH;
      textX = x + EVENT_SQUARE_WIDTH + EVENT_RIGHT_PADDING;
      textY = y + mEventAscentHeight;
      textRightEdge = rightEdge;
    }

    Style boxStyle = Style.STROKE;
    boolean solidBackground = false;
    if (event.selfAttendeeStatus != Attendees.ATTENDEE_STATUS_INVITED) {
      boxStyle = Style.FILL_AND_STROKE;
      if (allDay) {
        solidBackground = true;
      }
    }
    mEventSquarePaint.setStyle(boxStyle);
    mEventSquarePaint.setColor(color);
    canvas.drawRect(r, mEventSquarePaint);

    float avail = textRightEdge - textX;
    CharSequence text =
        TextUtils.ellipsize(event.title, mEventPaint, avail, TextUtils.TruncateAt.END);
    Paint textPaint;
    if (solidBackground) {
      // Text color needs to contrast with solid background.
      textPaint = mSolidBackgroundEventPaint;
    } else if (isDeclined) {
      // Use "declined event" color.
      textPaint = mDeclinedEventPaint;
    } else if (allDay) {
      // Text inside frame is same color as frame.
      mFramedEventPaint.setColor(color);
      textPaint = mFramedEventPaint;
    } else {
      // Use generic event text color.
      textPaint = mEventPaint;
    }
    canvas.drawText(text.toString(), textX, textY, textPaint);
    y += mEventHeight;
    if (allDay) {
      y += BORDER_SPACE * 2;
    }

    if (showTimes && !allDay) {
      // show start/end time, e.g. "1pm - 2pm"
      textY = y + mExtrasAscentHeight;
      mStringBuilder.setLength(0);
      text =
          DateUtils.formatDateRange(
                  getContext(),
                  mFormatter,
                  event.startMillis,
                  event.endMillis,
                  DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL,
                  Utils.getTimeZone(getContext(), null))
              .toString();
      text = TextUtils.ellipsize(text, mEventExtrasPaint, avail, TextUtils.TruncateAt.END);
      canvas.drawText(
          text.toString(),
          textX,
          textY,
          isDeclined ? mEventDeclinedExtrasPaint : mEventExtrasPaint);
      y += mExtrasHeight;
    }

    y += EVENT_LINE_PADDING;

    return y;
  }
コード例 #21
0
ファイル: NiceTabStrip.java プロジェクト: Efunbukola/app
  /**
   * Draw badge
   *
   * @param canvas The canvas
   */
  private void drawBadge(Canvas canvas) {
    if (mBadgesMap != null && !mBadgesMap.isEmpty()) {
      int badgeLeft = 0, badgeRight = 0, badgeBottom, badgeWidth;
      int badgeHeight;
      float textWidth = 0, textHeight = 0;
      Rect textBounds = new Rect();

      for (int i : mBadgesMap.keySet()) {
        final View child = getChildAt(i);
        final Badge badge = mBadgesMap.get(i);
        String text = badge.getText();

        if (badge.isSmall()) {
          badgeWidth = mBadgeSmallSize;
          badgeHeight = mBadgeSmallSize;
        } else {
          badgeHeight = mBadgeHeight;
          if (text != null) {
            mBadgeTextPaint.getTextBounds(text, 0, text.length(), textBounds);
            textWidth = mBadgeTextPaint.measureText(text); // Use measureText to calculate width
            textHeight = textBounds.height(); // Use height from getTextBounds()
          } else {
            textWidth = 0;
            textHeight = 0;
          }

          if (textWidth > 0) {
            if (textWidth > (mBadgeMaxWidth - mBadgePaddingLeftRight * 2)) {
              textWidth = mBadgeMaxWidth - mBadgePaddingLeftRight * 2;
              text =
                  TextUtils.ellipsize(text, mBadgeTextPaint, textWidth, TextUtils.TruncateAt.END)
                      .toString();
              badgeWidth = mBadgeMaxWidth;
            } else {
              badgeWidth =
                  Math.max(Math.round((mBadgePaddingLeftRight * 2) + textWidth), mBadgeMinWidth);
            }
          } else {
            badgeWidth = mBadgeMinWidth;
          }
        }

        badgeBottom = mBadgeMarginTop + badgeHeight;

        switch (mBadgeGravity) {
          case LEFT:
            {
              badgeLeft = child.getLeft() + mBadgeMarginLeft;
              badgeRight = badgeLeft + badgeWidth;
              break;
            }
          case CENTER_LEFT:
            {
              final int center = child.getRight() - child.getMeasuredWidth() / 2;
              badgeRight = center - mBadgeMarginRight;
              badgeLeft = badgeRight - badgeWidth;
              break;
            }
          case CENTER_RIGHT:
            {
              final int center = child.getRight() - child.getMeasuredWidth() / 2;
              badgeLeft = center + mBadgeMarginLeft;
              badgeRight = badgeLeft + badgeWidth;
              break;
            }
          case RIGHT:
            {
              badgeRight = child.getRight() - mBadgeMarginRight;
              badgeLeft = badgeRight - badgeWidth;
              break;
            }
        }

        mBadgeBackground.setBounds(badgeLeft, mBadgeMarginTop, badgeRight, badgeBottom);
        mBadgeBackground.draw(canvas);

        if (text != null && textWidth > 0) {
          canvas.drawText(
              text,
              mBadgeBackground.getBounds().centerX() - (textWidth / 2f),
              mBadgeBackground.getBounds().centerY() + (textHeight / 2f),
              mBadgeTextPaint);
        }
      }
    }
  }
コード例 #22
0
    public void build(int width, int height) {
      CharSequence nameString = "";
      TextPaint currentNamePaint;

      drawNameBroadcast = false;
      drawNameLock = false;
      drawNameGroup = false;

      if (encryptedChat != null) {
        drawNameLock = true;
        if (!LocaleController.isRTL) {
          nameLockLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
          nameLeft =
              AndroidUtilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth();
        } else {
          nameLockLeft =
              width
                  - AndroidUtilities.dp(63 + (usePadding ? 11 : 0))
                  - lockDrawable.getIntrinsicWidth();
          nameLeft = usePadding ? AndroidUtilities.dp(11) : 0;
        }
        nameLockTop = AndroidUtilities.dp(15);
      } else {
        if (chat != null) {
          nameLockTop = AndroidUtilities.dp(26);
          if (chat.id < 0) {
            drawNameBroadcast = true;
          } else {
            drawNameGroup = true;
          }
          if (!LocaleController.isRTL) {
            nameLockLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
            nameLeft =
                AndroidUtilities.dp(65 + (usePadding ? 11 : 0))
                    + (drawNameGroup
                        ? groupDrawable.getIntrinsicWidth()
                        : broadcastDrawable.getIntrinsicWidth());
          } else {
            nameLockLeft =
                width
                    - AndroidUtilities.dp(63 + (usePadding ? 11 : 0))
                    - (drawNameGroup
                        ? groupDrawable.getIntrinsicWidth()
                        : broadcastDrawable.getIntrinsicWidth());
            nameLeft = usePadding ? AndroidUtilities.dp(11) : 0;
          }
        } else {
          if (!LocaleController.isRTL) {
            nameLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
          } else {
            nameLeft = usePadding ? AndroidUtilities.dp(11) : 0;
          }
        }
      }

      if (currentName != null) {
        nameString = currentName;
      } else {
        String nameString2 = "";
        if (chat != null) {
          nameString2 = chat.title;
        } else if (user != null) {
          nameString2 = ContactsController.formatName(user.first_name, user.last_name);
        }
        nameString = nameString2.replace("\n", " ");
      }
      if (nameString.length() == 0) {
        if (user != null && user.phone != null && user.phone.length() != 0) {
          nameString = PhoneFormat.getInstance().format("+" + user.phone);
        } else {
          nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
        }
      }
      if (encryptedChat != null) {
        currentNamePaint = nameEncryptedPaint;
      } else {
        currentNamePaint = namePaint;
      }

      if (!LocaleController.isRTL) {
        onlineWidth = nameWidth = width - nameLeft - AndroidUtilities.dp(3 + (usePadding ? 11 : 0));
      } else {
        onlineWidth =
            nameWidth = width - nameLeft - AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
      }
      if (drawNameLock) {
        nameWidth -= AndroidUtilities.dp(6) + lockDrawable.getIntrinsicWidth();
      } else if (drawNameBroadcast) {
        nameWidth -= AndroidUtilities.dp(6) + broadcastDrawable.getIntrinsicWidth();
      }

      CharSequence nameStringFinal =
          TextUtils.ellipsize(
              nameString,
              currentNamePaint,
              nameWidth - AndroidUtilities.dp(12),
              TextUtils.TruncateAt.END);
      nameLayout =
          new StaticLayout(
              nameStringFinal,
              currentNamePaint,
              nameWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);

      if (chat == null) {
        if (!LocaleController.isRTL) {
          onlineLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0));
        } else {
          onlineLeft = usePadding ? AndroidUtilities.dp(11) : 0;
        }

        CharSequence onlineString = "";
        TextPaint currentOnlinePaint = offlinePaint;

        if (subLabel != null) {
          onlineString = subLabel;
        } else {
          onlineString = LocaleController.formatUserStatus(user);
          if (user != null
              && (user.id == UserConfig.getClientUserId()
                  || user.status != null
                      && user.status.expires > ConnectionsManager.getInstance().getCurrentTime())) {
            currentOnlinePaint = onlinePaint;
            onlineString = LocaleController.getString("Online", R.string.Online);
          }
        }

        CharSequence onlineStringFinal =
            TextUtils.ellipsize(
                onlineString,
                currentOnlinePaint,
                nameWidth - AndroidUtilities.dp(12),
                TextUtils.TruncateAt.END);
        onlineLayout =
            new StaticLayout(
                onlineStringFinal,
                currentOnlinePaint,
                nameWidth,
                Layout.Alignment.ALIGN_NORMAL,
                1.0f,
                0.0f,
                false);
        nameTop = AndroidUtilities.dp(12);
      } else {
        onlineLayout = null;
        nameTop = AndroidUtilities.dp(22);
      }

      if (!LocaleController.isRTL) {
        avatarLeft = usePadding ? AndroidUtilities.dp(11) : 0;
      } else {
        avatarLeft = width - AndroidUtilities.dp(50 + (usePadding ? 11 : 0));
      }
      avatarImage.setImageCoords(
          avatarLeft, avatarTop, AndroidUtilities.dp(50), AndroidUtilities.dp(50));

      double widthpx = 0;
      float left = 0;
      if (LocaleController.isRTL) {
        if (nameLayout.getLineCount() > 0) {
          left = nameLayout.getLineLeft(0);
          if (left == 0) {
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (widthpx < nameWidth) {
              nameLeft += (nameWidth - widthpx);
            }
          }
        }
        if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
          left = onlineLayout.getLineLeft(0);
          if (left == 0) {
            widthpx = Math.ceil(onlineLayout.getLineWidth(0));
            if (widthpx < onlineWidth) {
              onlineLeft += (onlineWidth - widthpx);
            }
          }
        }
      } else {
        if (nameLayout.getLineCount() > 0) {
          left = nameLayout.getLineRight(0);
          if (left == nameWidth) {
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (widthpx < nameWidth) {
              nameLeft -= (nameWidth - widthpx);
            }
          }
        }
        if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
          left = onlineLayout.getLineRight(0);
          if (left == onlineWidth) {
            widthpx = Math.ceil(onlineLayout.getLineWidth(0));
            if (widthpx < onlineWidth) {
              onlineLeft -= (onlineWidth - widthpx);
            }
          }
        }
      }
    }
コード例 #23
0
ファイル: ChatOrUserCell.java プロジェクト: Bogrome/zapzap
    public void build(int width, int height) {
      CharSequence nameString = "";
      TextPaint currentNamePaint;

      if (encryptedChat != null) {
        drawNameLock = true;
        if (!LocaleController.isRTL) {
          nameLockLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
          nameLeft = Utilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth();
        } else {
          nameLockLeft =
              width - Utilities.dp(63 + (usePadding ? 11 : 0)) - lockDrawable.getIntrinsicWidth();
          nameLeft = usePadding ? Utilities.dp(11) : 0;
        }
      } else {
        drawNameLock = false;
        if (!LocaleController.isRTL) {
          nameLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
        } else {
          nameLeft = usePadding ? Utilities.dp(11) : 0;
        }
      }

      if (currentName != null) {
        nameString = currentName;
      } else {
        String nameString2 = "";
        if (chat != null) {
          nameString2 = chat.title;
        } else if (user != null) {
          nameString2 = Utilities.formatName(user.first_name, user.last_name);
        }
        nameString = nameString2.replace("\n", " ");
      }
      if (nameString.length() == 0) {
        if (user.phone != null && user.phone.length() != 0) {
          nameString = PhoneFormat.getInstance().format("+" + user.phone);
        } else {
          nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
        }
      }
      if (encryptedChat != null) {
        currentNamePaint = nameEncryptedPaint;
      } else {
        currentNamePaint = namePaint;
      }

      if (!LocaleController.isRTL) {
        onlineWidth = nameWidth = width - nameLeft - Utilities.dp(3 + (usePadding ? 11 : 0));
      } else {
        onlineWidth = nameWidth = width - nameLeft - Utilities.dp(61 + (usePadding ? 11 : 0));
      }
      if (drawNameLock) {
        nameWidth -= Utilities.dp(6) + lockDrawable.getIntrinsicWidth();
      }

      CharSequence nameStringFinal =
          TextUtils.ellipsize(
              nameString, currentNamePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
      nameLayout =
          new StaticLayout(
              nameStringFinal,
              currentNamePaint,
              nameWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);

      if (chat == null) {
        if (!LocaleController.isRTL) {
          onlineLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
        } else {
          onlineLeft = usePadding ? Utilities.dp(11) : 0;
        }

        String onlineString = "";
        TextPaint currentOnlinePaint = offlinePaint;

        if (subLabel != null) {
          onlineString = subLabel;
        } else {
          if (user != null) {
            if (user.status == null) {
              onlineString = getResources().getString(R.string.Offline);
            } else {
              int currentTime = ConnectionsManager.getInstance().getCurrentTime();
              if (user.id == UserConfig.clientUserId || user.status.expires > currentTime) {
                currentOnlinePaint = onlinePaint;
                onlineString = getResources().getString(R.string.Online);
              } else {
                if (user.status.expires <= 10000) {
                  onlineString = getResources().getString(R.string.Invisible);
                } else {
                  onlineString = LocaleController.formatDateOnline(user.status.expires);
                }
              }
            }
          }
        }

        CharSequence onlineStringFinal =
            TextUtils.ellipsize(
                onlineString,
                currentOnlinePaint,
                nameWidth - Utilities.dp(12),
                TextUtils.TruncateAt.END);
        onlineLayout =
            new StaticLayout(
                onlineStringFinal,
                currentOnlinePaint,
                nameWidth,
                Layout.Alignment.ALIGN_NORMAL,
                1.0f,
                0.0f,
                false);
        nameTop = Utilities.dp(12);
      } else {
        onlineLayout = null;
        nameTop = Utilities.dp(22);
      }

      if (!LocaleController.isRTL) {
        avatarLeft = usePadding ? Utilities.dp(11) : 0;
      } else {
        avatarLeft = width - Utilities.dp(50 + (usePadding ? 11 : 0));
      }
      avatarImage.imageX = avatarLeft;
      avatarImage.imageY = avatarTop;
      avatarImage.imageW = Utilities.dp(50);
      avatarImage.imageH = Utilities.dp(50);

      double widthpx = 0;
      float left = 0;
      if (LocaleController.isRTL) {
        if (nameLayout.getLineCount() > 0) {
          left = nameLayout.getLineLeft(0);
          if (left == 0) {
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (widthpx < nameWidth) {
              nameLeft += (nameWidth - widthpx);
            }
          }
        }
        if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
          left = onlineLayout.getLineLeft(0);
          if (left == 0) {
            widthpx = Math.ceil(onlineLayout.getLineWidth(0));
            if (widthpx < onlineWidth) {
              onlineLeft += (onlineWidth - widthpx);
            }
          }
        }
      } else {
        if (nameLayout.getLineCount() > 0) {
          left = nameLayout.getLineRight(0);
          if (left == nameWidth) {
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (widthpx < nameWidth) {
              nameLeft -= (nameWidth - widthpx);
            }
          }
        }
        if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
          left = onlineLayout.getLineRight(0);
          if (left == onlineWidth) {
            widthpx = Math.ceil(onlineLayout.getLineWidth(0));
            if (widthpx < onlineWidth) {
              onlineLeft -= (onlineWidth - widthpx);
            }
          }
        }
      }
    }
コード例 #24
0
ファイル: DialogView.java プロジェクト: johack0/telegram
    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;
      }
    }
コード例 #25
0
  public void buildLayout() {
    CharSequence nameString;
    TextPaint currentNamePaint;

    drawNameBroadcast = false;
    drawNameLock = false;
    drawNameGroup = false;
    drawCheck = false;
    drawNameBot = false;

    if (encryptedChat != null) {
      drawNameLock = true;
      dialog_id = ((long) encryptedChat.id) << 32;
      if (!LocaleController.isRTL) {
        nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
        nameLeft =
            AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                + lockDrawable.getIntrinsicWidth();
      } else {
        nameLockLeft =
            getMeasuredWidth()
                - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                - lockDrawable.getIntrinsicWidth();
        nameLeft = AndroidUtilities.dp(11);
      }
      nameLockTop = AndroidUtilities.dp(16.5f);
    } else {
      if (chat != null) {
        if (chat.id < 0) {
          dialog_id = AndroidUtilities.makeBroadcastId(chat.id);
          drawNameBroadcast = true;
          nameLockTop = AndroidUtilities.dp(28.5f);
        } else {
          dialog_id = -chat.id;
          if (ChatObject.isChannel(chat) && !chat.megagroup) {
            drawNameBroadcast = true;
            nameLockTop = AndroidUtilities.dp(28.5f);
          } else {
            drawNameGroup = true;
            nameLockTop = AndroidUtilities.dp(30);
          }
        }
        drawCheck = chat.verified;
        if (!LocaleController.isRTL) {
          nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
          nameLeft =
              AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                  + (drawNameGroup
                      ? groupDrawable.getIntrinsicWidth()
                      : broadcastDrawable.getIntrinsicWidth());
        } else {
          nameLockLeft =
              getMeasuredWidth()
                  - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                  - (drawNameGroup
                      ? groupDrawable.getIntrinsicWidth()
                      : broadcastDrawable.getIntrinsicWidth());
          nameLeft = AndroidUtilities.dp(11);
        }
      } else {
        dialog_id = user.id;
        if (!LocaleController.isRTL) {
          nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
        } else {
          nameLeft = AndroidUtilities.dp(11);
        }
        if (user.bot) {
          drawNameBot = true;
          if (!LocaleController.isRTL) {
            nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
            nameLeft =
                AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                    + botDrawable.getIntrinsicWidth();
          } else {
            nameLockLeft =
                getMeasuredWidth()
                    - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                    - botDrawable.getIntrinsicWidth();
            nameLeft = AndroidUtilities.dp(11);
          }
          nameLockTop = AndroidUtilities.dp(16.5f);
        } else {
          nameLockTop = AndroidUtilities.dp(17);
        }
        drawCheck = user.verified;
      }
    }

    if (currentName != null) {
      nameString = currentName;
    } else {
      String nameString2 = "";
      if (chat != null) {
        nameString2 = chat.title;
      } else if (user != null) {
        nameString2 = UserObject.getUserName(user);
      }
      nameString = nameString2.replace('\n', ' ');
    }
    if (nameString.length() == 0) {
      if (user != null && user.phone != null && user.phone.length() != 0) {
        nameString = PhoneFormat.getInstance().format("+" + user.phone);
      } else {
        nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
      }
    }
    if (encryptedChat != null) {
      currentNamePaint = nameEncryptedPaint;
    } else {
      currentNamePaint = namePaint;
    }

    int onlineWidth;
    int nameWidth;
    if (!LocaleController.isRTL) {
      onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14);
    } else {
      onlineWidth =
          nameWidth =
              getMeasuredWidth() - nameLeft - AndroidUtilities.dp(AndroidUtilities.leftBaseline);
    }
    if (drawNameLock) {
      nameWidth -= AndroidUtilities.dp(6) + lockDrawable.getIntrinsicWidth();
    } else if (drawNameBroadcast) {
      nameWidth -= AndroidUtilities.dp(6) + broadcastDrawable.getIntrinsicWidth();
    } else if (drawNameGroup) {
      nameWidth -= AndroidUtilities.dp(6) + groupDrawable.getIntrinsicWidth();
    } else if (drawNameBot) {
      nameWidth -= AndroidUtilities.dp(6) + botDrawable.getIntrinsicWidth();
    }

    if (drawCount) {
      TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
      if (dialog != null && dialog.unread_count != 0) {
        lastUnreadCount = dialog.unread_count;
        String countString = String.format("%d", dialog.unread_count);
        countWidth =
            Math.max(AndroidUtilities.dp(12), (int) Math.ceil(countPaint.measureText(countString)));
        countLayout =
            new StaticLayout(
                countString,
                countPaint,
                countWidth,
                Layout.Alignment.ALIGN_CENTER,
                1.0f,
                0.0f,
                false);
        int w = countWidth + AndroidUtilities.dp(18);
        nameWidth -= w;
        if (!LocaleController.isRTL) {
          countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(19);
        } else {
          countLeft = AndroidUtilities.dp(19);
          nameLeft += w;
        }
      } else {
        lastUnreadCount = 0;
        countLayout = null;
      }
    } else {
      lastUnreadCount = 0;
      countLayout = null;
    }

    CharSequence nameStringFinal =
        TextUtils.ellipsize(
            nameString,
            currentNamePaint,
            nameWidth - AndroidUtilities.dp(12),
            TextUtils.TruncateAt.END);
    nameLayout =
        new StaticLayout(
            nameStringFinal,
            currentNamePaint,
            nameWidth,
            Layout.Alignment.ALIGN_NORMAL,
            1.0f,
            0.0f,
            false);

    if (chat == null || subLabel != null) {
      if (!LocaleController.isRTL) {
        onlineLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
      } else {
        onlineLeft = AndroidUtilities.dp(11);
      }

      CharSequence onlineString = "";
      TextPaint currentOnlinePaint = offlinePaint;

      if (subLabel != null) {
        onlineString = subLabel;
      } else if (user != null) {
        if (user.bot) {
          onlineString = LocaleController.getString("Bot", R.string.Bot);
        } else {
          onlineString = LocaleController.formatUserStatus(user);
          if (user != null
              && (user.id == UserConfig.getClientUserId()
                  || user.status != null
                      && user.status.expires > ConnectionsManager.getInstance().getCurrentTime())) {
            currentOnlinePaint = onlinePaint;
            onlineString = LocaleController.getString("Online", R.string.Online);
          }
        }
      }

      CharSequence onlineStringFinal =
          TextUtils.ellipsize(
              onlineString,
              currentOnlinePaint,
              onlineWidth - AndroidUtilities.dp(12),
              TextUtils.TruncateAt.END);
      onlineLayout =
          new StaticLayout(
              onlineStringFinal,
              currentOnlinePaint,
              onlineWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);
      nameTop = AndroidUtilities.dp(13);
      if (subLabel != null && chat != null) {
        nameLockTop -= AndroidUtilities.dp(12);
      }
    } else {
      onlineLayout = null;
      nameTop = AndroidUtilities.dp(25);
    }

    int avatarLeft;
    if (!LocaleController.isRTL) {
      avatarLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 13 : 9);
    } else {
      avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 65 : 61);
    }

    avatarImage.setImageCoords(
        avatarLeft, AndroidUtilities.dp(10), AndroidUtilities.dp(52), AndroidUtilities.dp(52));

    double widthpx;
    float left;
    if (LocaleController.isRTL) {
      if (nameLayout.getLineCount() > 0) {
        left = nameLayout.getLineLeft(0);
        if (left == 0) {
          widthpx = Math.ceil(nameLayout.getLineWidth(0));
          if (widthpx < nameWidth) {
            nameLeft += (nameWidth - widthpx);
          }
        }
      }
      if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
        left = onlineLayout.getLineLeft(0);
        if (left == 0) {
          widthpx = Math.ceil(onlineLayout.getLineWidth(0));
          if (widthpx < onlineWidth) {
            onlineLeft += (onlineWidth - widthpx);
          }
        }
      }
    } else {
      if (nameLayout.getLineCount() > 0) {
        left = nameLayout.getLineRight(0);
        if (left == nameWidth) {
          widthpx = Math.ceil(nameLayout.getLineWidth(0));
          if (widthpx < nameWidth) {
            nameLeft -= (nameWidth - widthpx);
          }
        }
      }
      if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
        left = onlineLayout.getLineRight(0);
        if (left == onlineWidth) {
          widthpx = Math.ceil(onlineLayout.getLineWidth(0));
          if (widthpx < onlineWidth) {
            onlineLeft -= (onlineWidth - widthpx);
          }
        }
      }
    }
  }