List of usage examples for android.text StaticLayout StaticLayout
@Deprecated public StaticLayout(CharSequence source, TextPaint paint, int width, Alignment align, float spacingmult, float spacingadd, boolean includepad)
From source file:org.telegram.ui.Cells.SharedLinkCell.java
@SuppressLint("DrawAllocation") @Override//w ww. ja va 2 s .c o m protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { drawLinkImageView = false; descriptionLayout = null; titleLayout = null; descriptionLayout2 = null; description2Y = descriptionY; linkLayout.clear(); links.clear(); int maxWidth = MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - AndroidUtilities.dp(8); String title = null; String description = null; String description2 = null; String webPageLink = null; boolean hasPhoto = false; if (message.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && message.messageOwner.media.webpage instanceof TLRPC.TL_webPage) { TLRPC.WebPage webPage = message.messageOwner.media.webpage; if (message.photoThumbs == null && webPage.photo != null) { message.generateThumbs(true); } hasPhoto = webPage.photo != null && message.photoThumbs != null; title = webPage.title; if (title == null) { title = webPage.site_name; } description = webPage.description; webPageLink = webPage.url; } if (message != null && !message.messageOwner.entities.isEmpty()) { for (int a = 0; a < message.messageOwner.entities.size(); a++) { TLRPC.MessageEntity entity = message.messageOwner.entities.get(a); if (entity.length <= 0 || entity.offset < 0 || entity.offset >= message.messageOwner.message.length()) { continue; } else if (entity.offset + entity.length > message.messageOwner.message.length()) { entity.length = message.messageOwner.message.length() - entity.offset; } if (a == 0 && webPageLink != null && !(entity.offset == 0 && entity.length == message.messageOwner.message.length())) { if (message.messageOwner.entities.size() == 1) { if (description == null) { description2 = message.messageOwner.message; } } else { description2 = message.messageOwner.message; } } try { String link = null; if (entity instanceof TLRPC.TL_messageEntityTextUrl || entity instanceof TLRPC.TL_messageEntityUrl) { if (entity instanceof TLRPC.TL_messageEntityUrl) { link = message.messageOwner.message.substring(entity.offset, entity.offset + entity.length); } else { link = entity.url; } if (title == null || title.length() == 0) { title = link; Uri uri = Uri.parse(title); title = uri.getHost(); if (title == null) { title = link; } int index; if (title != null && (index = title.lastIndexOf('.')) >= 0) { title = title.substring(0, index); if ((index = title.lastIndexOf('.')) >= 0) { title = title.substring(index + 1); } title = title.substring(0, 1).toUpperCase() + title.substring(1); } if (entity.offset != 0 || entity.length != message.messageOwner.message.length()) { description = message.messageOwner.message; } } } else if (entity instanceof TLRPC.TL_messageEntityEmail) { if (title == null || title.length() == 0) { link = "mailto:" + message.messageOwner.message.substring(entity.offset, entity.offset + entity.length); title = message.messageOwner.message.substring(entity.offset, entity.offset + entity.length); if (entity.offset != 0 || entity.length != message.messageOwner.message.length()) { description = message.messageOwner.message; } } } if (link != null) { if (link.toLowerCase().indexOf("http") != 0 && link.toLowerCase().indexOf("mailto") != 0) { links.add("http://" + link); } else { links.add(link); } } } catch (Exception e) { FileLog.e("tmessages", e); } } } if (webPageLink != null && links.isEmpty()) { links.add(webPageLink); } if (title != null) { try { int width = (int) Math.ceil(titleTextPaint.measureText(title)); CharSequence titleFinal = TextUtils.ellipsize(title.replace('\n', ' '), titleTextPaint, Math.min(width, maxWidth), TextUtils.TruncateAt.END); titleLayout = new StaticLayout(titleFinal, titleTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); } catch (Exception e) { FileLog.e("tmessages", e); } letterDrawable.setTitle(title); } if (description != null) { try { descriptionLayout = ChatMessageCell.generateStaticLayout(description, descriptionTextPaint, maxWidth, maxWidth, 0, 3); if (descriptionLayout.getLineCount() > 0) { description2Y = descriptionY + descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1) + AndroidUtilities.dp(1); } } catch (Exception e) { FileLog.e("tmessages", e); } } if (description2 != null) { try { descriptionLayout2 = ChatMessageCell.generateStaticLayout(description2, descriptionTextPaint, maxWidth, maxWidth, 0, 3); int height = descriptionLayout2.getLineBottom(descriptionLayout2.getLineCount() - 1); if (descriptionLayout != null) { description2Y += AndroidUtilities.dp(10); } } catch (Exception e) { FileLog.e("tmessages", e); } } if (!links.isEmpty()) { for (int a = 0; a < links.size(); a++) { try { String link = links.get(a); int width = (int) Math.ceil(descriptionTextPaint.measureText(link)); CharSequence linkFinal = TextUtils.ellipsize(link.replace('\n', ' '), descriptionTextPaint, Math.min(width, maxWidth), TextUtils.TruncateAt.MIDDLE); StaticLayout layout = new StaticLayout(linkFinal, descriptionTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); linkY = description2Y; if (descriptionLayout2 != null && descriptionLayout2.getLineCount() != 0) { linkY += descriptionLayout2.getLineBottom(descriptionLayout2.getLineCount() - 1) + AndroidUtilities.dp(1); } linkLayout.add(layout); } catch (Exception e) { FileLog.e("tmessages", e); } } } int maxPhotoWidth = AndroidUtilities.dp(52); int x = LocaleController.isRTL ? MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(10) - maxPhotoWidth : AndroidUtilities.dp(10); letterDrawable.setBounds(x, AndroidUtilities.dp(10), x + maxPhotoWidth, AndroidUtilities.dp(62)); if (hasPhoto) { TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, maxPhotoWidth, true); TLRPC.PhotoSize currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, 80); if (currentPhotoObjectThumb == currentPhotoObject) { currentPhotoObjectThumb = null; } currentPhotoObject.size = -1; if (currentPhotoObjectThumb != null) { currentPhotoObjectThumb.size = -1; } linkImageView.setImageCoords(x, AndroidUtilities.dp(10), maxPhotoWidth, maxPhotoWidth); String fileName = FileLoader.getAttachFileName(currentPhotoObject); boolean photoExist = true; File cacheFile = FileLoader.getPathToAttach(currentPhotoObject, true); if (!cacheFile.exists()) { photoExist = false; } String filter = String.format(Locale.US, "%d_%d", maxPhotoWidth, maxPhotoWidth); if (photoExist || MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO) || FileLoader.getInstance().isLoadingFile(fileName)) { linkImageView.setImage(currentPhotoObject.location, filter, currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, String.format(Locale.US, "%d_%d_b", maxPhotoWidth, maxPhotoWidth), 0, null, false); } else { if (currentPhotoObjectThumb != null) { linkImageView.setImage(null, null, currentPhotoObjectThumb.location, String.format(Locale.US, "%d_%d_b", maxPhotoWidth, maxPhotoWidth), 0, null, false); } else { linkImageView.setImageBitmap((Drawable) null); } } drawLinkImageView = true; } int height = 0; if (titleLayout != null && titleLayout.getLineCount() != 0) { height += titleLayout.getLineBottom(titleLayout.getLineCount() - 1); } if (descriptionLayout != null && descriptionLayout.getLineCount() != 0) { height += descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1); } if (descriptionLayout2 != null && descriptionLayout2.getLineCount() != 0) { height += descriptionLayout2.getLineBottom(descriptionLayout2.getLineCount() - 1); if (descriptionLayout != null) { height += AndroidUtilities.dp(10); } } for (int a = 0; a < linkLayout.size(); a++) { StaticLayout layout = linkLayout.get(a); if (layout.getLineCount() > 0) { height += layout.getLineBottom(layout.getLineCount() - 1); } } if (hasPhoto) { height = Math.max(AndroidUtilities.dp(48), height); } checkBox.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(22), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(22), MeasureSpec.EXACTLY)); setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), Math.max(AndroidUtilities.dp(72), height + AndroidUtilities.dp(16)) + (needDivider ? 1 : 0)); }
From source file:com.resonos.apps.library.tabviewpager.TabPageIndicator.java
/** * Does a bit of calculations to better measure the size of tabs. * This is to fix a bug where text would occasionally get cut off. *///from w ww. j ava 2s . c o m private void doPreMeasure() { TabView tabView = (TabView) mInflater.inflate(R.layout.vpi__tab, null); TextView textView = (TextView) tabView.findViewById(android.R.id.text1); ImageView imageView = (ImageView) tabView.findViewById(R.id.img); mTextPaint = textView.getPaint(); mTextPadding = textView.getTotalPaddingLeft() + textView.getTotalPaddingRight() + tabView.getPaddingLeft() + tabView.getPaddingRight(); int mImagePadding = imageView.getPaddingLeft() + imageView.getPaddingRight(); int t = 0; int count = getTitleProvider().getCount(); mAllMinWidths = new int[count]; String text; Drawable d; for (int i = 0; i < count; i++) { d = getTitleProvider().getIcon(i); text = getTitleProvider().getTitle(i); if (d != null) { mAllMinWidths[i] = d.getIntrinsicWidth() + mImagePadding; } else { StaticLayout layout = new StaticLayout(text, mTextPaint, MAX_TAB_WIDTH, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); int w = (int) (layout.getLineWidth(0) + 1); mAllMinWidths[i] = mTextPadding + w; } if (getTitleProvider().isVisible(i)) t += mAllMinWidths[i]; } mTotalMinWidth = t; }
From source file:com.yek.keyboard.keyboards.views.CandidateView.java
/** * If the canvas is null, then only touch calculations are performed to pick * the target candidate.//from w ww . j ava2 s.c o m */ @Override protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } mTotalWidth = 0; final int height = getHeight(); if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } mDivider.setBounds(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight()); } final int dividerYOffset = (height - mDivider.getMinimumHeight()) / 2; final int count = mSuggestions.size(); final Rect bgPadding = mBgPadding; final Paint paint = mPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final boolean typedWordValid = mTypedWordValid; int x = 0; for (int i = 0; i < count; i++) { CharSequence suggestion = mSuggestions.get(i); if (suggestion == null) continue; final int wordLength = suggestion.length(); paint.setColor(mColorNormal); if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) { paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setColor(mColorRecommended); // existsAutoCompletion = true; } else if (i != 0 || (wordLength == 1 && count > 1)) { // HACK: even if i == 0, we use mColorOther when this // suggestion's length is 1 and // there are multiple suggestions, such as the default // punctuation list. paint.setColor(mColorOther); } // now that we set the typeFace, we can measure int wordWidth; if ((wordWidth = mWordWidth[i]) == 0) { float textWidth = paint.measureText(suggestion, 0, wordLength); // wordWidth = Math.max(0, (int) textWidth + X_GAP * 2); wordWidth = (int) (textWidth + mXGap * 2); mWordWidth[i] = wordWidth; } mWordX[i] = x; if (touchX != OUT_OF_BOUNDS_X_CORD && !scrolled && touchX + scrollX >= x && touchX + scrollX < x + wordWidth) { if (canvas != null && !mShowingAddToDictionary) { canvas.translate(x, 0); mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height); mSelectionHighlight.draw(canvas); canvas.translate(-x, 0); } mSelectedString = suggestion; mSelectedIndex = i; } if (canvas != null) { // (+)This is the trick to get RTL/LTR text correct if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) { final int y = (int) (height + paint.getTextSize() - paint.descent()) / 2; canvas.drawText(suggestion, 0, wordLength, x + wordWidth / 2, y, paint); } else { final int y = (int) (height - paint.getTextSize() + paint.descent()) / 2; // no matter what: StaticLayout float textX = x + (wordWidth / 2) - mXGap; float textY = y - bgPadding.bottom - bgPadding.top; canvas.translate(textX, textY); mTextPaint.setTypeface(paint.getTypeface()); mTextPaint.setColor(paint.getColor()); StaticLayout suggestionText = new StaticLayout(suggestion, mTextPaint, wordWidth, Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); suggestionText.draw(canvas); canvas.translate(-textX, -textY); } // (-) paint.setColor(mColorOther); canvas.translate(x + wordWidth, 0); // Draw a divider unless it's after the hint //or the last suggested word if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) { canvas.translate(0, dividerYOffset); mDivider.draw(canvas); canvas.translate(0, -dividerYOffset); } canvas.translate(-x - wordWidth, 0); } paint.setTypeface(Typeface.DEFAULT); x += wordWidth; } mTotalWidth = x; if (mTargetScrollX != scrollX) { scrollToTarget(); } }
From source file:org.telegram.ui.Components.AvatarDrawable.java
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast, String custom) { if (isProfile) { color = arrColorsProfiles[getColorIndex(id)]; } else {/*from ww w . java 2 s. c om*/ color = arrColors[getColorIndex(id)]; } drawBrodcast = isBroadcast; if (firstName == null || firstName.length() == 0) { firstName = lastName; lastName = null; } stringBuilder.setLength(0); if (custom != null) { stringBuilder.append(custom); } else { if (firstName != null && firstName.length() > 0) { stringBuilder.append(firstName.substring(0, 1)); } if (lastName != null && lastName.length() > 0) { String lastch = null; for (int a = lastName.length() - 1; a >= 0; a--) { if (lastch != null && lastName.charAt(a) == ' ') { break; } lastch = lastName.substring(a, a + 1); } if (Build.VERSION.SDK_INT >= 16) { stringBuilder.append("\u200C"); } stringBuilder.append(lastch); } else if (firstName != null && firstName.length() > 0) { for (int a = firstName.length() - 1; a >= 0; a--) { if (firstName.charAt(a) == ' ') { if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') { if (Build.VERSION.SDK_INT >= 16) { stringBuilder.append("\u200C"); } stringBuilder.append(firstName.substring(a + 1, a + 2)); break; } } } } } if (stringBuilder.length() > 0) { String text = stringBuilder.toString().toUpperCase(); try { textLayout = new StaticLayout(text, (smallStyle ? namePaintSmall : namePaint), AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); if (textLayout.getLineCount() > 0) { textLeft = textLayout.getLineLeft(0); textWidth = textLayout.getLineWidth(0); textHeight = textLayout.getLineBottom(0); } } catch (Exception e) { FileLog.e("tmessages", e); } } else { textLayout = null; } }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
/** * If the canvas is null, then only touch calculations are performed to pick * the target candidate./*from ww w. ja v a 2 s. c om*/ */ @Override protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } mTotalWidth = 0; final int height = getHeight(); if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } mDivider.setBounds(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight()); } final int dividerYOffset = (height - mDivider.getMinimumHeight()) / 2; final int count = mSuggestions.size(); final Rect bgPadding = mBgPadding; final Paint paint = mPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final boolean typedWordValid = mTypedWordValid; int x = 0; for (int i = 0; i < count; i++) { CharSequence suggestion = mSuggestions.get(i); if (suggestion == null) continue; final int wordLength = suggestion.length(); paint.setColor(mColorNormal); if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) { paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setColor(mColorRecommended); // existsAutoCompletion = true; } else if (i != 0 || (wordLength == 1 && count > 1)) { // HACK: even if i == 0, we use mColorOther when this // suggestion's length is 1 and // there are multiple suggestions, such as the default // punctuation list. paint.setColor(mColorOther); } // now that we set the typeFace, we can measure int wordWidth; if ((wordWidth = mWordWidth[i]) == 0) { float textWidth = paint.measureText(suggestion, 0, wordLength); // wordWidth = Math.max(0, (int) textWidth + X_GAP * 2); wordWidth = (int) (textWidth + mHorizontalGap * 2); mWordWidth[i] = wordWidth; } mWordX[i] = x; if (touchX != OUT_OF_BOUNDS_X_CORD && !scrolled && touchX + scrollX >= x && touchX + scrollX < x + wordWidth) { if (canvas != null && !mShowingAddToDictionary) { canvas.translate(x, 0); mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height); mSelectionHighlight.draw(canvas); canvas.translate(-x, 0); } mSelectedString = suggestion; mSelectedIndex = i; } if (canvas != null) { // (+)This is the trick to get RTL/LTR text correct if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) { final int y = (int) (height + paint.getTextSize() - paint.descent()) / 2; canvas.drawText(suggestion, 0, wordLength, x + wordWidth / 2, y, paint); } else { final int y = (int) (height - paint.getTextSize() + paint.descent()) / 2; // no matter what: StaticLayout float textX = x + (wordWidth / 2) - mHorizontalGap; float textY = y - bgPadding.bottom - bgPadding.top; canvas.translate(textX, textY); mTextPaint.setTypeface(paint.getTypeface()); mTextPaint.setColor(paint.getColor()); StaticLayout suggestionText = new StaticLayout(suggestion, mTextPaint, wordWidth, Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); suggestionText.draw(canvas); canvas.translate(-textX, -textY); } // (-) paint.setColor(mColorOther); canvas.translate(x + wordWidth, 0); // Draw a divider unless it's after the hint //or the last suggested word if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) { canvas.translate(0, dividerYOffset); mDivider.draw(canvas); canvas.translate(0, -dividerYOffset); } canvas.translate(-x - wordWidth, 0); } paint.setTypeface(Typeface.DEFAULT); x += wordWidth; } mTotalWidth = x; if (mTargetScrollX != scrollX) { scrollToTarget(); } }
From source file:com.example.view.wheel.WheelView.java
/** * Creates layouts/*ww w.j ava 2 s . c o m*/ * @param widthItems width of items layout * @param widthLabel width of label layout */ private void createLayouts(int widthItems, int widthLabel) { if (itemsLayout == null || itemsLayout.getWidth() > widthItems) { itemsLayout = new StaticLayout(buildText(isScrollingPerformed), itemsPaint, widthItems, widthLabel > 0 ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER, 1, ADDITIONAL_ITEM_HEIGHT, false); } else { itemsLayout.increaseWidthTo(widthItems); } if (!isScrollingPerformed && (valueLayout == null || valueLayout.getWidth() > widthItems)) { String text = getAdapter() != null ? getAdapter().getItem(currentItem) : null; valueLayout = new StaticLayout(text != null ? text : "", valuePaint, widthItems, widthLabel > 0 ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER, 1, ADDITIONAL_ITEM_HEIGHT, false); } else if (isScrollingPerformed) { valueLayout = null; } else { valueLayout.increaseWidthTo(widthItems); } if (widthLabel > 0) { if (labelLayout == null || labelLayout.getWidth() > widthLabel) { labelLayout = new StaticLayout(label, valuePaint, widthLabel, Layout.Alignment.ALIGN_NORMAL, 1, ADDITIONAL_ITEM_HEIGHT, false); } else { labelLayout.increaseWidthTo(widthLabel); } } }
From source file:io.plaidapp.ui.widget.CollapsingTitleLayout.java
private void createLayoutPreM(int width, int lineSpacingAdd) { layout = new StaticLayout(displayText, paint, width - titleInsetStart - titleInsetEnd, Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingAdd, true); lineCount = layout.getLineCount();//from w w w . j a va 2s.c o m if (lineCount > maxLines) { // if it exceeds our max number of lines then truncate the displayText & recreate the layout int endIndex = layout.getLineEnd(maxLines - 1) - 2; // minus 2 chars for the ellipse displayText = new SpannableStringBuilder(title.subSequence(0, endIndex) + ""); layout = new StaticLayout(displayText, paint, width - titleInsetStart - titleInsetEnd, Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingAdd, true); lineCount = maxLines; } }
From source file:com.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java
private void createLayoutPreM(int width, float lineSpacingAdd) { layout = new StaticLayout(displayText, paint, width - titleInsetStart - titleInsetEnd, Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingAdd, true); lineCount = layout.getLineCount();// www . ja v a 2 s . c o m if (lineCount > maxLines) { // if it exceeds our max number of lines then truncate the text & recreate the layout int endIndex = layout.getLineEnd(maxLines - 1) - 2; // minus 2 chars for the ellipse displayText = new SpannableStringBuilder(title.subSequence(0, endIndex) + ""); layout = new StaticLayout(displayText, paint, width - titleInsetStart - titleInsetEnd, Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingAdd, true); lineCount = maxLines; } }
From source file:org.wikipedia.page.shareafact.SnippetImage.java
private static StaticLayout buildLayout(TextLayoutParams params) { return new StaticLayout(params.text, params.textPaint, params.lineWidth, params.align, params.spacingMultiplier, 0.0f, false); }
From source file:org.telegram.ui.Cells.ProfileSearchCell.java
public void buildLayout() { CharSequence nameString;/*from ww w.ja v a 2 s . co m*/ 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); } } } } }