List of usage examples for android.text TextUtils ellipsize
public static CharSequence ellipsize(CharSequence text, TextPaint p, float avail, TruncateAt where)
From source file:ticwear.design.widget.CollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;// w w w. j a v a 2 s. c om final float availableWidth; final float newTextSize; boolean updateDrawText = false; if (isClose(textSize, mCollapsedTextSize)) { availableWidth = mCollapsedBounds.width(); newTextSize = mCollapsedTextSize; mScale = 1f; if (mCurrentTypeface != mCollapsedTypeface) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } } else { availableWidth = mExpandedBounds.width(); newTextSize = mExpandedTextSize; if (mCurrentTypeface != mExpandedTypeface) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTextPaint.setTextSize(mCurrentTextSize); mTextPaint.setTypeface(mCurrentTypeface); // If we don't currently have text to draw, or the text size has changed, ellipsize... final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); if (!TextUtils.equals(title, mTextToDraw)) { mTextToDraw = title; mIsRtl = calculateIsRtl(mTextToDraw); } } }
From source file:android.support.designox.widget.CollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;/*from ww w . j a v a 2s . c o m*/ final float availableWidth; final float newTextSize; boolean updateDrawText = false; if (isClose(textSize, mCollapsedTextSize)) { availableWidth = mCollapsedBounds.width(); newTextSize = mCollapsedTextSize; mScale = 1f; if (mCurrentTypeface != mCollapsedTypeface) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } } else { availableWidth = mExpandedBounds.width(); newTextSize = mExpandedTextSize; if (mCurrentTypeface != mExpandedTypeface) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTextPaint.setTextSize(mCurrentTextSize); mTextPaint.setTypeface(mCurrentTypeface); // Use linear text scaling if we're scaling the canvas mTextPaint.setLinearText(mScale != 1f); // If we don't currently have text to draw, or the text size has changed, ellipsize... final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); if (!TextUtils.equals(title, mTextToDraw)) { mTextToDraw = title; mIsRtl = calculateIsRtl(mTextToDraw); } } }
From source file:com.tr4android.support.extension.widget.CollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;// w w w.j a va 2s. c o m final float availableWidth = lerp(mExpandedBounds.width(), mCollapsedBounds.width(), mExpandedFraction, mTextSizeInterpolator); final float newTextSize; boolean updateDrawText = false; if (isClose(textSize, mCollapsedTextSize)) { newTextSize = mCollapsedTextSize; mScale = 1f; if (mCurrentTypeface != mCollapsedTypeface) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } } else { newTextSize = mExpandedTextSize; if (mCurrentTypeface != mExpandedTypeface) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTextPaint.setTypeface(mCurrentTypeface); } // Now we update the text ellipsis... mTextPaint.setTextSize(textSize); final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); if (!TextUtils.equals(title, mTextToDraw)) { mTextToDraw = title; mIsRtl = calculateIsRtl(mTextToDraw); } mTextPaint.setTextSize(mCurrentTextSize); }
From source file:com.commonsware.cwac.crossport.design.widget.CollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;/*from w ww. j a v a 2s . c o m*/ final float collapsedWidth = mCollapsedBounds.width(); final float expandedWidth = mExpandedBounds.width(); final float availableWidth; final float newTextSize; boolean updateDrawText = false; if (isClose(textSize, mCollapsedTextSize)) { newTextSize = mCollapsedTextSize; mScale = 1f; if (areTypefacesDifferent(mCurrentTypeface, mCollapsedTypeface)) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } availableWidth = collapsedWidth; } else { newTextSize = mExpandedTextSize; if (areTypefacesDifferent(mCurrentTypeface, mExpandedTypeface)) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } final float textSizeRatio = mCollapsedTextSize / mExpandedTextSize; // This is the size of the expanded bounds when it is scaled to match the // collapsed text size final float scaledDownWidth = expandedWidth * textSizeRatio; if (scaledDownWidth > collapsedWidth) { // If the scaled down size is larger than the actual collapsed width, we need to // cap the available width so that when the expanded text scales down, it matches // the collapsed width availableWidth = Math.min(collapsedWidth / textSizeRatio, expandedWidth); } else { // Otherwise we'll just use the expanded width availableWidth = expandedWidth; } } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTextPaint.setTextSize(mCurrentTextSize); mTextPaint.setTypeface(mCurrentTypeface); // Use linear text scaling if we're scaling the canvas mTextPaint.setLinearText(mScale != 1f); // If we don't currently have text to draw, or the text size has changed, ellipsize... final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); if (!TextUtils.equals(title, mTextToDraw)) { mTextToDraw = title; mIsRtl = calculateIsRtl(mTextToDraw); } } }
From source file:android.support.design.widget.CollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;/*from ww w . j ava 2 s. co m*/ final float collapsedWidth = mCollapsedBounds.width(); final float expandedWidth = mExpandedBounds.width(); final float availableWidth; final float newTextSize; boolean updateDrawText = false; if (isClose(textSize, mCollapsedTextSize)) { newTextSize = mCollapsedTextSize; mScale = 1f; if (mCurrentTypeface != mCollapsedTypeface) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } availableWidth = collapsedWidth; } else { newTextSize = mExpandedTextSize; if (mCurrentTypeface != mExpandedTypeface) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } final float textSizeRatio = mCollapsedTextSize / mExpandedTextSize; // This is the size of the expanded bounds when it is scaled to match the // collapsed text size final float scaledDownWidth = expandedWidth * textSizeRatio; if (scaledDownWidth > collapsedWidth) { // If the scaled down size is larger than the actual collapsed width, we need to // cap the available width so that when the expanded text scales down, it matches // the collapsed width availableWidth = Math.min(collapsedWidth / textSizeRatio, expandedWidth); } else { // Otherwise we'll just use the expanded width availableWidth = expandedWidth; } } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTextPaint.setTextSize(mCurrentTextSize); mTextPaint.setTypeface(mCurrentTypeface); // Use linear text scaling if we're scaling the canvas mTextPaint.setLinearText(mScale != 1f); // If we don't currently have text to draw, or the text size has changed, ellipsize... final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); if (!TextUtils.equals(title, mTextToDraw)) { mTextToDraw = title; mIsRtl = calculateIsRtl(mTextToDraw); } } }
From source file:org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;//from www. j ava 2 s . com final float collapsedWidth = mCollapsedBounds.width(); final float expandedWidth = mExpandedBounds.width(); final float availableWidth; final float newTextSize; boolean updateDrawText = false; if (isClose(textSize, mCollapsedTextSize)) { newTextSize = mCollapsedTextSize; mScale = 1f; if (mCurrentTypeface != mCollapsedTypeface) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } availableWidth = collapsedWidth; } else { newTextSize = mExpandedTextSize; if (mCurrentTypeface != mExpandedTypeface) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } final float textSizeRatio = mCollapsedTextSize / mExpandedTextSize; // This is the size of the expanded bounds when it is scaled to match the // collapsed text size final float scaledDownWidth = expandedWidth * textSizeRatio; if (scaledDownWidth > collapsedWidth) { // If the scaled down size is larger than the actual collapsed width, we need to // cap the available width so that when the expanded text scales down, it matches // the collapsed width availableWidth = Math.min(collapsedWidth / textSizeRatio, expandedWidth); } else { // Otherwise we'll just use the expanded width availableWidth = expandedWidth; } } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTextPaint.setTextSize(mCurrentTextSize); mTextPaint.setTypeface(mCurrentTypeface); // Use linear text scaling if we're scaling the canvas mTextPaint.setLinearText(mScale != 1f); // If we don't currently have text to draw, or the text size has changed, ellipsize... final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); if (!TextUtils.equals(title, mTextToDraw)) { mTextToDraw = title; mIsRtl = calculateIsRtl(mTextToDraw); } } }
From source file:com.android.ex.chips.RecipientEditTextView.java
private CharSequence ellipsizeText(final CharSequence text, final TextPaint paint, final float maxWidth) { paint.setTextSize(mChipFontSize);//from ww w. j av a 2 s. c om if (maxWidth <= 0 && Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Max width is negative: " + maxWidth); final CharSequence ellipsize = TextUtils.ellipsize(text, paint, maxWidth, TextUtils.TruncateAt.END); return ellipsize; }
From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;/*from ww w . ja v a 2s . com*/ final float availableWidth; final float newTextSize; boolean updateDrawText = false; // BEGIN MODIFICATION: Add maxLines variable int maxLines; // END MODIFICATION if (isClose(textSize, mCollapsedTextSize)) { availableWidth = mCollapsedBounds.width(); newTextSize = mCollapsedTextSize; mScale = 1f; if (mCurrentTypeface != mCollapsedTypeface) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } // BEGIN MODIFICATION: Set maxLines variable maxLines = 1; // END MODIFICATION } else { availableWidth = mExpandedBounds.width(); newTextSize = mExpandedTextSize; if (mCurrentTypeface != mExpandedTypeface) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } // BEGIN MODIFICATION: Set maxLines variable maxLines = this.maxLines; // END MODIFICATION } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTextPaint.setTextSize(mCurrentTextSize); mTextPaint.setTypeface(mCurrentTypeface); // BEGIN MODIFICATION: Text layout creation and text truncation StaticLayout layout = new StaticLayout(mText, mTextPaint, (int) availableWidth, Layout.Alignment.ALIGN_NORMAL, 1, 0, false); CharSequence truncatedText; if (layout.getLineCount() > maxLines) { int lastLine = maxLines - 1; CharSequence textBefore = lastLine > 0 ? mText.subSequence(0, layout.getLineEnd(lastLine - 1)) : ""; CharSequence lineText = mText.subSequence(layout.getLineStart(lastLine), layout.getLineEnd(lastLine)); // if last char in line is space, move it behind the ellipsis CharSequence lineEnd = ""; if (lineText.charAt(lineText.length() - 1) == ' ') { lineEnd = lineText.subSequence(lineText.length() - 1, lineText.length()); lineText = lineText.subSequence(0, lineText.length() - 1); } // insert ellipsis character lineText = TextUtils.concat(lineText, "\u2026", lineEnd); // if the text is too long, truncate it CharSequence truncatedLineText = TextUtils.ellipsize(lineText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); truncatedText = TextUtils.concat(textBefore, truncatedLineText); } else { truncatedText = mText; } if (!TextUtils.equals(truncatedText, mTextToDraw)) { mTextToDraw = truncatedText; mIsRtl = calculateIsRtl(mTextToDraw); } final Layout.Alignment alignment; // Don't rectify gravity for RTL languages, Layout.Alignment does it already. switch (mExpandedTextGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: alignment = Layout.Alignment.ALIGN_CENTER; break; case Gravity.RIGHT: case Gravity.END: alignment = Layout.Alignment.ALIGN_OPPOSITE; break; case Gravity.LEFT: case Gravity.START: default: alignment = Layout.Alignment.ALIGN_NORMAL; break; } mTextLayout = new StaticLayout(mTextToDraw, mTextPaint, (int) availableWidth, alignment, 1, 0, false); // END MODIFICATION } }
From source file:android.support.design.widget.CustomCollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;//ww w . j a v a 2 s . com final float collapsedWidth = mCollapsedBounds.width(); final float expandedWidth = mExpandedBounds.width(); final float availableWidth; final float newTextSize; boolean updateDrawText = false; if (isClose(textSize, mCollapsedTextSize)) { newTextSize = mCollapsedTextSize; mScale = 1f; if (mCurrentTypeface != mCollapsedTypeface) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } availableWidth = collapsedWidth; } else { newTextSize = mExpandedTextSize; if (mCurrentTypeface != mExpandedTypeface) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } final float textSizeRatio = mCollapsedTextSize / mExpandedTextSize; // This is the size of the expanded bounds when it is scaled to match the // collapsed text size final float scaledDownWidth = expandedWidth * textSizeRatio; if (scaledDownWidth > collapsedWidth) { // If the scaled down size is larger than the actual collapsed width, we need to // cap the available width so that when the expanded text scales down, it matches // the collapsed width availableWidth = Math.min(collapsedWidth / textSizeRatio, expandedWidth); } else { // Otherwise we'll just use the expanded width availableWidth = expandedWidth; } } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTitlePaint.setTextSize(mCurrentTextSize); mTitlePaint.setTypeface(mCurrentTypeface); // Use linear text scaling if we're scaling the canvas mTitlePaint.setLinearText(mScale != 1f); // If we don't currently have text to draw, or the text size has changed, ellipsize... final CharSequence title = TextUtils.ellipsize(mText, mTitlePaint, availableWidth, TextUtils.TruncateAt.END); if (!TextUtils.equals(title, mTextToDraw)) { mTextToDraw = title; mIsRtl = calculateIsRtl(mTextToDraw); } } }
From source file:org.telegram.ui.Cells.DialogCell.java
public void buildLayout() { String nameString = ""; String timeString = ""; String countString = null;/*from w w w. j a v a2s .c o m*/ CharSequence messageString = ""; CharSequence printingString = null; if (isDialogCell) { printingString = MessagesController.getInstance().printingStrings.get(currentDialogId); } TextPaint currentNamePaint = namePaint; TextPaint currentMessagePaint = messagePaint; boolean checkMessage = true; drawNameGroup = false; drawNameBroadcast = false; drawNameLock = false; drawNameBot = false; drawVerified = false; if (encryptedChat != null) { drawNameLock = true; nameLockTop = AndroidUtilities.dp(16.5f); if (!LocaleController.isRTL) { nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline); nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + lockDrawable.getIntrinsicWidth(); } else { nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - lockDrawable.getIntrinsicWidth(); nameLeft = AndroidUtilities.dp(14); } } else { if (chat != null) { if (chat.id < 0 || ChatObject.isChannel(chat) && !chat.megagroup) { drawNameBroadcast = true; nameLockTop = AndroidUtilities.dp(16.5f); } else { drawNameGroup = true; nameLockTop = AndroidUtilities.dp(17.5f); } drawVerified = 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) - (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth()); nameLeft = AndroidUtilities.dp(14); } } else { if (!LocaleController.isRTL) { nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline); } else { nameLeft = AndroidUtilities.dp(14); } if (user != null) { if (user.bot) { drawNameBot = true; nameLockTop = AndroidUtilities.dp(16.5f); if (!LocaleController.isRTL) { nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline); nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + botDrawable.getIntrinsicWidth(); } else { nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - botDrawable.getIntrinsicWidth(); nameLeft = AndroidUtilities.dp(14); } } drawVerified = user.verified; } } } int lastDate = lastMessageDate; if (lastMessageDate == 0 && message != null) { lastDate = message.messageOwner.date; } if (isDialogCell) { draftMessage = DraftQuery.getDraft(currentDialogId); if (draftMessage != null && (TextUtils.isEmpty(draftMessage.message) && draftMessage.reply_to_msg_id == 0 || lastDate > draftMessage.date && unreadCount != 0) || ChatObject.isChannel(chat) && !chat.megagroup && !chat.creator && !chat.editor || chat != null && (chat.left || chat.kicked)) { draftMessage = null; } } else { draftMessage = null; } if (printingString != null) { lastPrintString = messageString = printingString; currentMessagePaint = messagePrintingPaint; } else { lastPrintString = null; if (draftMessage != null) { checkMessage = false; if (TextUtils.isEmpty(draftMessage.message)) { String draftString = LocaleController.getString("Draft", R.string.Draft); SpannableStringBuilder stringBuilder = SpannableStringBuilder.valueOf(draftString); stringBuilder.setSpan(new ForegroundColorSpan(Theme.DIALOGS_DRAFT_TEXT_COLOR), 0, draftString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); messageString = stringBuilder; } else { String mess = draftMessage.message; if (mess.length() > 150) { mess = mess.substring(0, 150); } String draftString = LocaleController.getString("Draft", R.string.Draft); SpannableStringBuilder stringBuilder = SpannableStringBuilder .valueOf(String.format("%s: %s", draftString, mess.replace('\n', ' '))); stringBuilder.setSpan(new ForegroundColorSpan(Theme.DIALOGS_DRAFT_TEXT_COLOR), 0, draftString.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); messageString = Emoji.replaceEmoji(stringBuilder, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false); } } else { if (message == null) { if (encryptedChat != null) { currentMessagePaint = messagePrintingPaint; if (encryptedChat instanceof TLRPC.TL_encryptedChatRequested) { messageString = LocaleController.getString("EncryptionProcessing", R.string.EncryptionProcessing); } else if (encryptedChat instanceof TLRPC.TL_encryptedChatWaiting) { if (user != null && user.first_name != null) { messageString = LocaleController.formatString("AwaitingEncryption", R.string.AwaitingEncryption, user.first_name); } else { messageString = LocaleController.formatString("AwaitingEncryption", R.string.AwaitingEncryption, ""); } } else if (encryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) { messageString = LocaleController.getString("EncryptionRejected", R.string.EncryptionRejected); } else if (encryptedChat instanceof TLRPC.TL_encryptedChat) { if (encryptedChat.admin_id == UserConfig.getClientUserId()) { if (user != null && user.first_name != null) { messageString = LocaleController.formatString("EncryptedChatStartedOutgoing", R.string.EncryptedChatStartedOutgoing, user.first_name); } else { messageString = LocaleController.formatString("EncryptedChatStartedOutgoing", R.string.EncryptedChatStartedOutgoing, ""); } } else { messageString = LocaleController.getString("EncryptedChatStartedIncoming", R.string.EncryptedChatStartedIncoming); } } } } else { TLRPC.User fromUser = null; TLRPC.Chat fromChat = null; if (message.isFromUser()) { fromUser = MessagesController.getInstance().getUser(message.messageOwner.from_id); } else { fromChat = MessagesController.getInstance().getChat(message.messageOwner.to_id.channel_id); } if (message.messageOwner instanceof TLRPC.TL_messageService) { messageString = message.messageText; currentMessagePaint = messagePrintingPaint; } else { if (chat != null && chat.id > 0 && fromChat == null) { String name; if (message.isOutOwner()) { name = LocaleController.getString("FromYou", R.string.FromYou); } else if (fromUser != null) { name = UserObject.getFirstName(fromUser).replace("\n", ""); } else if (fromChat != null) { name = fromChat.title.replace("\n", ""); } else { name = "DELETED"; } checkMessage = false; SpannableStringBuilder stringBuilder; if (message.caption != null) { String mess = message.caption.toString(); if (mess.length() > 150) { mess = mess.substring(0, 150); } stringBuilder = SpannableStringBuilder .valueOf(String.format("%s: %s", name, mess.replace('\n', ' '))); } else if (message.messageOwner.media != null && !message.isMediaEmpty()) { currentMessagePaint = messagePrintingPaint; if (message.messageOwner.media instanceof TLRPC.TL_messageMediaGame) { stringBuilder = SpannableStringBuilder.valueOf(String.format("%s: %s", name, "\uD83C\uDFAE " + message.messageOwner.media.game.title)); } else { stringBuilder = SpannableStringBuilder .valueOf(String.format("%s: %s", name, message.messageText)); } stringBuilder.setSpan(new ForegroundColorSpan(Theme.DIALOGS_ATTACH_TEXT_COLOR), name.length() + 2, stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (message.messageOwner.message != null) { String mess = message.messageOwner.message; if (mess.length() > 150) { mess = mess.substring(0, 150); } stringBuilder = SpannableStringBuilder .valueOf(String.format("%s: %s", name, mess.replace('\n', ' '))); } else { stringBuilder = SpannableStringBuilder.valueOf(""); } if (stringBuilder.length() > 0) { stringBuilder.setSpan(new ForegroundColorSpan(Theme.DIALOGS_NAME_TEXT_COLOR), 0, name.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } messageString = Emoji.replaceEmoji(stringBuilder, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false); } else { if (message.caption != null) { messageString = message.caption; } else { if (message.messageOwner.media instanceof TLRPC.TL_messageMediaGame) { messageString = "\uD83C\uDFAE " + message.messageOwner.media.game.title; } else { messageString = message.messageText; } if (message.messageOwner.media != null && !message.isMediaEmpty()) { currentMessagePaint = messagePrintingPaint; } } } } } } } if (draftMessage != null) { timeString = LocaleController.stringForMessageListDate(draftMessage.date); } else if (lastMessageDate != 0) { timeString = LocaleController.stringForMessageListDate(lastMessageDate); } else if (message != null) { timeString = LocaleController.stringForMessageListDate(message.messageOwner.date); } if (message == null) { drawCheck1 = false; drawCheck2 = false; drawClock = false; drawCount = false; drawError = false; } else { if (unreadCount != 0) { drawCount = true; countString = String.format("%d", unreadCount); } else { drawCount = false; } if (message.isOut() && draftMessage == null) { if (message.isSending()) { drawCheck1 = false; drawCheck2 = false; drawClock = true; drawError = false; } else if (message.isSendError()) { drawCheck1 = false; drawCheck2 = false; drawClock = false; drawError = true; drawCount = false; } else if (message.isSent()) { drawCheck1 = !message.isUnread() || ChatObject.isChannel(chat) && !chat.megagroup; drawCheck2 = true; drawClock = false; drawError = false; } } else { drawCheck1 = false; drawCheck2 = false; drawClock = false; drawError = false; } } int timeWidth = (int) Math.ceil(timePaint.measureText(timeString)); timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); if (!LocaleController.isRTL) { timeLeft = getMeasuredWidth() - AndroidUtilities.dp(15) - timeWidth; } else { timeLeft = AndroidUtilities.dp(15); } if (chat != null) { nameString = chat.title; } else if (user != null) { if (user.id == UserConfig.getClientUserId()) { nameString = LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName); } else if (user.id / 1000 != 777 && user.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(user.id) == null) { if (ContactsController.getInstance().contactsDict.size() == 0 && (!ContactsController.getInstance().contactsLoaded || ContactsController.getInstance().isLoadingContacts())) { nameString = UserObject.getUserName(user); } else { if (user.phone != null && user.phone.length() != 0) { nameString = PhoneFormat.getInstance().format("+" + user.phone); } else { nameString = UserObject.getUserName(user); } } } else { nameString = UserObject.getUserName(user); } if (encryptedChat != null) { currentNamePaint = nameEncryptedPaint; } } if (nameString.length() == 0) { nameString = LocaleController.getString("HiddenName", R.string.HiddenName); } int nameWidth; if (!LocaleController.isRTL) { nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14) - timeWidth; } else { nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - timeWidth; nameLeft += timeWidth; } if (drawNameLock) { nameWidth -= AndroidUtilities.dp(4) + lockDrawable.getIntrinsicWidth(); } else if (drawNameGroup) { nameWidth -= AndroidUtilities.dp(4) + groupDrawable.getIntrinsicWidth(); } else if (drawNameBroadcast) { nameWidth -= AndroidUtilities.dp(4) + broadcastDrawable.getIntrinsicWidth(); } else if (drawNameBot) { nameWidth -= AndroidUtilities.dp(4) + botDrawable.getIntrinsicWidth(); } if (drawClock) { int w = clockDrawable.getIntrinsicWidth() + AndroidUtilities.dp(5); nameWidth -= w; if (!LocaleController.isRTL) { checkDrawLeft = timeLeft - w; } else { checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(5); nameLeft += w; } } else if (drawCheck2) { int w = checkDrawable.getIntrinsicWidth() + AndroidUtilities.dp(5); nameWidth -= w; if (drawCheck1) { nameWidth -= halfCheckDrawable.getIntrinsicWidth() - AndroidUtilities.dp(8); if (!LocaleController.isRTL) { halfCheckDrawLeft = timeLeft - w; checkDrawLeft = halfCheckDrawLeft - AndroidUtilities.dp(5.5f); } else { checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(5); halfCheckDrawLeft = checkDrawLeft + AndroidUtilities.dp(5.5f); nameLeft += w + halfCheckDrawable.getIntrinsicWidth() - AndroidUtilities.dp(8); } } else { if (!LocaleController.isRTL) { checkDrawLeft = timeLeft - w; } else { checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(5); nameLeft += w; } } } if (dialogMuted && !drawVerified) { int w = AndroidUtilities.dp(6) + muteDrawable.getIntrinsicWidth(); nameWidth -= w; if (LocaleController.isRTL) { nameLeft += w; } } else if (drawVerified) { int w = AndroidUtilities.dp(6) + verifiedDrawable.getIntrinsicWidth(); nameWidth -= w; if (LocaleController.isRTL) { nameLeft += w; } } nameWidth = Math.max(AndroidUtilities.dp(12), nameWidth); try { CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace('\n', ' '), currentNamePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); nameLayout = new StaticLayout(nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); } catch (Exception e) { FileLog.e("tmessages", e); } int messageWidth = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 16); int avatarLeft; if (!LocaleController.isRTL) { messageLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline); avatarLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 13 : 9); } else { messageLeft = AndroidUtilities.dp(16); avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 65 : 61); } avatarImage.setImageCoords(avatarLeft, avatarTop, AndroidUtilities.dp(52), AndroidUtilities.dp(52)); if (drawError) { int w = errorDrawable.getIntrinsicWidth() + AndroidUtilities.dp(8); messageWidth -= w; if (!LocaleController.isRTL) { errorLeft = getMeasuredWidth() - errorDrawable.getIntrinsicWidth() - AndroidUtilities.dp(11); } else { errorLeft = AndroidUtilities.dp(11); messageLeft += w; } } else if (countString != null) { 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); messageWidth -= w; if (!LocaleController.isRTL) { countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(19); } else { countLeft = AndroidUtilities.dp(19); messageLeft += w; } drawCount = true; } else { drawCount = false; } if (checkMessage) { if (messageString == null) { messageString = ""; } String mess = messageString.toString(); if (mess.length() > 150) { mess = mess.substring(0, 150); } mess = mess.replace('\n', ' '); messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(17), false); } messageWidth = Math.max(AndroidUtilities.dp(12), messageWidth); CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); try { messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); } catch (Exception e) { FileLog.e("tmessages", e); } double widthpx; float left; if (LocaleController.isRTL) { if (nameLayout != null && nameLayout.getLineCount() > 0) { left = nameLayout.getLineLeft(0); widthpx = Math.ceil(nameLayout.getLineWidth(0)); if (dialogMuted && !drawVerified) { nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - muteDrawable.getIntrinsicWidth()); } else if (drawVerified) { nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - verifiedDrawable.getIntrinsicWidth()); } if (left == 0) { if (widthpx < nameWidth) { nameLeft += (nameWidth - widthpx); } } } if (messageLayout != null && messageLayout.getLineCount() > 0) { left = messageLayout.getLineLeft(0); if (left == 0) { widthpx = Math.ceil(messageLayout.getLineWidth(0)); if (widthpx < messageWidth) { messageLeft += (messageWidth - widthpx); } } } } else { if (nameLayout != null && nameLayout.getLineCount() > 0) { left = nameLayout.getLineRight(0); if (left == nameWidth) { widthpx = Math.ceil(nameLayout.getLineWidth(0)); if (widthpx < nameWidth) { nameLeft -= (nameWidth - widthpx); } } if (dialogMuted || drawVerified) { nameMuteLeft = (int) (nameLeft + left + AndroidUtilities.dp(6)); } } if (messageLayout != null && messageLayout.getLineCount() > 0) { left = messageLayout.getLineRight(0); if (left == messageWidth) { widthpx = Math.ceil(messageLayout.getLineWidth(0)); if (widthpx < messageWidth) { messageLeft -= (messageWidth - widthpx); } } } } }