Java Code Examples for android.text.StaticLayout#getLineBottom()
The following examples show how to use
android.text.StaticLayout#getLineBottom() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextSelectionHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override protected int getLineHeight() { if (selectedView == null) { return 0; } else { arrayList.clear(); selectedView.fillTextLayoutBlocks(arrayList); int index = startPeek ? startViewChildPosition : endViewChildPosition; if (index < 0 || index >= arrayList.size()) { return 0; } StaticLayout layout = arrayList.get(index).getLayout(); int min = Integer.MAX_VALUE; for (int i = 0; i < layout.getLineCount(); i++) { int h = layout.getLineBottom(i) - layout.getLineTop(i); if (h < min) min = h; } return min; } }
Example 2
Source File: TextSelectionHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override protected int getLineHeight() { if (selectedView != null && selectedView.getMessageObject() != null) { MessageObject object = selectedView.getMessageObject(); StaticLayout layout = null; if (isDescription) { layout = selectedView.getDescriptionlayout(); } else if (selectedView.hasCaptionLayout()) { layout = selectedView.getCaptionLayout(); } else if (object.textLayoutBlocks != null) { layout = object.textLayoutBlocks.get(0).textLayout; } if (layout == null) { return 0; } int lineHeight = layout.getLineBottom(0) - layout.getLineTop(0); return lineHeight; } return 0; }
Example 3
Source File: LetterDrawable.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public void setTitle(String title) { stringBuilder.setLength(0); if (title != null && title.length() > 0) { stringBuilder.append(title.substring(0, 1)); } if (stringBuilder.length() > 0) { String text = stringBuilder.toString().toUpperCase(); try { textLayout = new StaticLayout(text, 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(e); } } else { textLayout = null; } }
Example 4
Source File: TextSelectionHelper.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override protected int getLineHeight() { if (selectedView == null) { return 0; } else { arrayList.clear(); selectedView.fillTextLayoutBlocks(arrayList); int index = startPeek ? startViewChildPosition : endViewChildPosition; if (index < 0 || index >= arrayList.size()) { return 0; } StaticLayout layout = arrayList.get(index).getLayout(); int min = Integer.MAX_VALUE; for (int i = 0; i < layout.getLineCount(); i++) { int h = layout.getLineBottom(i) - layout.getLineTop(i); if (h < min) min = h; } return min; } }
Example 5
Source File: TextViewLinkActivity.java From zone-sdk with MIT License | 5 votes |
private void roateSpan() { TextView tv_rotate_img_span = (TextView) findViewById(R.id.tv_rotate_img_span); ImageView img_rotate = (ImageView) findViewById(R.id.img_rotate); Drawable drawable = getResources().getDrawable(R.drawable.icon); // drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.setBounds(0, 0, 200, 200); img_rotate.setImageDrawable(drawable); ViewGroup.LayoutParams lp = img_rotate.getLayoutParams(); lp.width = 200; lp.height = 200; img_rotate.setLayoutParams(lp); //这个可以在oncreate的时候测量出来 StaticLayout sl = new StaticLayout("aa", tv_rotate_img_span.getPaint(), 100, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); int lineHeight = sl.getLineBottom(0) - sl.getLineTop(0);// 比 tv_rotate_img_span.getLineHeight() 这个好 因为每行高刚度可能不一致 int affectLine = 0; for (int i = 0; i < Integer.MAX_VALUE; i++) { if (i * lineHeight > 200 + 20) { affectLine = i - 1; break; } } SpannableString msp = new SpannableString("可是现在我已不是在天上翱翔的小鸟,在地上奔跑的动物了,因为我长大了,已经五年级了,大家都在努力地学习,谁都不想输给别人,每个人都在奋发图强,“学习如逆水行舟,不进则退”。这句话在我耳边回荡,难道我们就不应该有一个孩子应该有的童真吗?难道我已经失去了吗?难道现在我们所有的孩子都应该抓住学习这根攀山绳吗?为什么我们不?"); tv_rotate_img_span.setText(msp); tv_rotate_img_span.setGravity(Gravity.LEFT); msp.setSpan(new ImageRotate(affectLine), 0, msp.length() - 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE); tv_rotate_img_span.setText(msp); }
Example 6
Source File: LinkPath.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public void setCurrentLayout(StaticLayout layout, int start, float yOffset) { currentLayout = layout; currentLine = layout.getLineForOffset(start); lastTop = -1; heightOffset = yOffset; if (Build.VERSION.SDK_INT >= 28) { int lineCount = layout.getLineCount(); if (lineCount > 0) { lineHeight = layout.getLineBottom(lineCount - 1) - layout.getLineTop(lineCount - 1); } } }
Example 7
Source File: TextSelectionHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
protected int[] offsetToCord(int offset) { fillLayoutForOffset(offset, layoutBlock); StaticLayout layout = layoutBlock.layout; if (layout == null || offset > layout.getText().length()) { return tmpCoord; } int line = layout.getLineForOffset(offset); tmpCoord[0] = (int) (layout.getPrimaryHorizontal(offset) + layoutBlock.xOffset); tmpCoord[1] = layout.getLineBottom(line); tmpCoord[1] += layoutBlock.yOffset; return tmpCoord; }
Example 8
Source File: TextSelectionHelper.java From Telegram with GNU General Public License v2.0 | 5 votes |
protected int[] offsetToCord(int offset) { fillLayoutForOffset(offset, layoutBlock); StaticLayout layout = layoutBlock.layout; if (layout == null || offset > layout.getText().length()) { return tmpCoord; } int line = layout.getLineForOffset(offset); tmpCoord[0] = (int) (layout.getPrimaryHorizontal(offset) + layoutBlock.xOffset); tmpCoord[1] = layout.getLineBottom(line); tmpCoord[1] += layoutBlock.yOffset; return tmpCoord; }
Example 9
Source File: BannerTextView.java From SmartChart with Apache License 2.0 | 5 votes |
private int getHeightS() { TextPaint textPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); textPaint.setTextSize(getTextSize()); StaticLayout staticLayout = new StaticLayout(textList.get(currentPosition), textPaint, getWidth() - getPaddingLeft() - getPaddingRight(), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false); int height = staticLayout.getHeight(); if (staticLayout.getLineCount() > getMaxLines()) { int lineCount = staticLayout.getLineCount(); height = staticLayout.getLineBottom(getMaxLines() - 1); } return height; }
Example 10
Source File: LinkPath.java From Telegram with GNU General Public License v2.0 | 5 votes |
public void setCurrentLayout(StaticLayout layout, int start, float yOffset) { currentLayout = layout; currentLine = layout.getLineForOffset(start); lastTop = -1; heightOffset = yOffset; if (Build.VERSION.SDK_INT >= 28) { int lineCount = layout.getLineCount(); if (lineCount > 0) { lineHeight = layout.getLineBottom(lineCount - 1) - layout.getLineTop(lineCount - 1); } } }
Example 11
Source File: SubtitlePainter.java From no-player with Apache License 2.0 | 4 votes |
@SuppressWarnings("PMD.NPathComplexity") // TODO break this method up private void drawTextLayout(Canvas canvas) { StaticLayout layout = textLayout; if (layout == null) { // Nothing to draw. return; } int saveCount = canvas.save(); canvas.translate(textLeft, textTop); if (Color.alpha(windowColor) > 0) { paint.setColor(windowColor); canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(), paint); } if (Color.alpha(backgroundColor) > 0) { paint.setColor(backgroundColor); float previousBottom = layout.getLineTop(0); int lineCount = layout.getLineCount(); for (int i = 0; i < lineCount; i++) { lineBounds.left = layout.getLineLeft(i) - textPaddingX; lineBounds.right = layout.getLineRight(i) + textPaddingX; lineBounds.top = previousBottom; lineBounds.bottom = layout.getLineBottom(i); previousBottom = lineBounds.bottom; canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint); } } if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) { textPaint.setStrokeJoin(Join.ROUND); textPaint.setStrokeWidth(outlineWidth); textPaint.setColor(edgeColor); textPaint.setStyle(Style.FILL_AND_STROKE); layout.draw(canvas); } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) { textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor); } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) { boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED; int colorUp = raised ? Color.WHITE : edgeColor; int colorDown = raised ? edgeColor : Color.WHITE; float offset = shadowRadius / 2; textPaint.setColor(foregroundColor); textPaint.setStyle(Style.FILL); textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp); layout.draw(canvas); textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown); } textPaint.setColor(foregroundColor); textPaint.setStyle(Style.FILL); layout.draw(canvas); textPaint.setShadowLayer(0, 0, 0, 0); canvas.restoreToCount(saveCount); }
Example 12
Source File: SubtitlePainter.java From K-Sonic with MIT License | 4 votes |
private void drawTextLayout(Canvas canvas) { StaticLayout layout = textLayout; if (layout == null) { // Nothing to draw. return; } int saveCount = canvas.save(); canvas.translate(textLeft, textTop); if (Color.alpha(windowColor) > 0) { paint.setColor(windowColor); canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(), paint); } if (Color.alpha(backgroundColor) > 0) { paint.setColor(backgroundColor); float previousBottom = layout.getLineTop(0); int lineCount = layout.getLineCount(); for (int i = 0; i < lineCount; i++) { lineBounds.left = layout.getLineLeft(i) - textPaddingX; lineBounds.right = layout.getLineRight(i) + textPaddingX; lineBounds.top = previousBottom; lineBounds.bottom = layout.getLineBottom(i); previousBottom = lineBounds.bottom; canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint); } } if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) { textPaint.setStrokeJoin(Join.ROUND); textPaint.setStrokeWidth(outlineWidth); textPaint.setColor(edgeColor); textPaint.setStyle(Style.FILL_AND_STROKE); layout.draw(canvas); } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) { textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor); } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) { boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED; int colorUp = raised ? Color.WHITE : edgeColor; int colorDown = raised ? edgeColor : Color.WHITE; float offset = shadowRadius / 2f; textPaint.setColor(foregroundColor); textPaint.setStyle(Style.FILL); textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp); layout.draw(canvas); textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown); } textPaint.setColor(foregroundColor); textPaint.setStyle(Style.FILL); layout.draw(canvas); textPaint.setShadowLayer(0, 0, 0, 0); canvas.restoreToCount(saveCount); }
Example 13
Source File: SharedLinkCell.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (titleLayout != null) { canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY); titleLayout.draw(canvas); canvas.restore(); } if (descriptionLayout != null) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY); descriptionLayout.draw(canvas); canvas.restore(); } if (descriptionLayout2 != null) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), description2Y); descriptionLayout2.draw(canvas); canvas.restore(); } if (!linkLayout.isEmpty()) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText)); int offset = 0; for (int a = 0; a < linkLayout.size(); a++) { StaticLayout layout = linkLayout.get(a); if (layout.getLineCount() > 0) { canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY + offset); if (pressedLink == a) { canvas.drawPath(urlPath, Theme.linkSelectionPaint); } layout.draw(canvas); canvas.restore(); offset += layout.getLineBottom(layout.getLineCount() - 1); } } } letterDrawable.draw(canvas); if (drawLinkImageView) { linkImageView.draw(canvas); } if (needDivider) { if (LocaleController.isRTL) { canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, Theme.dividerPaint); } else { canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, Theme.dividerPaint); } } }
Example 14
Source File: MixtureTextView.java From MixtureTextView with Apache License 2.0 | 4 votes |
private void cacuLineHeight() { layout = new StaticLayout("爱我中华", mTextPaint, 0, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0f, false); mLineHeight = layout.getLineBottom(0) - layout.getLineTop(0); }
Example 15
Source File: AvatarDrawable.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast, String custom) { if (isProfile) { color = getProfileColorForId(id); } else { color = getColorForId(id); } drawBrodcast = isBroadcast; savedMessages = 0; 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.appendCodePoint(firstName.codePointAt(0)); } if (lastName != null && lastName.length() > 0) { Integer lastch = null; for (int a = lastName.length() - 1; a >= 0; a--) { if (lastch != null && lastName.charAt(a) == ' ') { break; } lastch = lastName.codePointAt(a); } if (Build.VERSION.SDK_INT > 17) { stringBuilder.append("\u200C"); } stringBuilder.appendCodePoint(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 > 17) { stringBuilder.append("\u200C"); } stringBuilder.appendCodePoint(firstName.codePointAt(a + 1)); break; } } } } } if (stringBuilder.length() > 0) { String text = stringBuilder.toString().toUpperCase(); try { textLayout = new StaticLayout(text, 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(e); } } else { textLayout = null; } }
Example 16
Source File: TextSelectionHelper.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override protected int getCharOffsetFromCord(int x, int y, int offsetX, int offsetY, ArticleSelectableView view, boolean maybe) { if (view == null) { return -1; } int line = -1; x -= offsetX; y -= offsetY; arrayList.clear(); view.fillTextLayoutBlocks(arrayList); int childIndex; if (maybe) { childIndex = maybeTextIndex; } else { childIndex = startPeek ? startViewChildPosition : endViewChildPosition; } StaticLayout layout = arrayList.get(childIndex).getLayout(); if (x < 0) { x = 1; } if (y < 0) { y = 1; } if (x > layout.getWidth()) { x = layout.getWidth(); } if (y > layout.getLineBottom(layout.getLineCount() - 1)) { y = (int) (layout.getLineBottom(layout.getLineCount() - 1) - 1); } for (int i = 0; i < layout.getLineCount(); i++) { if (y > layout.getLineTop(i) && y < layout.getLineBottom(i)) { line = i; break; } } if (line >= 0) { return layout.getOffsetForHorizontal(line, x); } return -1; }
Example 17
Source File: SharedLinkCell.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (titleLayout != null) { canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY); titleLayout.draw(canvas); canvas.restore(); } if (descriptionLayout != null) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY); descriptionLayout.draw(canvas); canvas.restore(); } if (descriptionLayout2 != null) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), description2Y); descriptionLayout2.draw(canvas); canvas.restore(); } if (!linkLayout.isEmpty()) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText)); int offset = 0; for (int a = 0; a < linkLayout.size(); a++) { StaticLayout layout = linkLayout.get(a); if (layout.getLineCount() > 0) { canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY + offset); if (pressedLink == a) { canvas.drawPath(urlPath, Theme.linkSelectionPaint); } layout.draw(canvas); canvas.restore(); offset += layout.getLineBottom(layout.getLineCount() - 1); } } } letterDrawable.draw(canvas); if (drawLinkImageView) { linkImageView.draw(canvas); } if (needDivider) { if (LocaleController.isRTL) { canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, Theme.dividerPaint); } else { canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, Theme.dividerPaint); } } }
Example 18
Source File: SharedLinkCell.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (titleLayout != null) { canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY); titleLayout.draw(canvas); canvas.restore(); } if (descriptionLayout != null) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY); descriptionLayout.draw(canvas); canvas.restore(); } if (descriptionLayout2 != null) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), description2Y); descriptionLayout2.draw(canvas); canvas.restore(); } if (!linkLayout.isEmpty()) { descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText)); int offset = 0; for (int a = 0; a < linkLayout.size(); a++) { StaticLayout layout = linkLayout.get(a); if (layout.getLineCount() > 0) { canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY + offset); if (pressedLink == a) { canvas.drawPath(urlPath, Theme.linkSelectionPaint); } layout.draw(canvas); canvas.restore(); offset += layout.getLineBottom(layout.getLineCount() - 1); } } } letterDrawable.draw(canvas); if (drawLinkImageView) { linkImageView.draw(canvas); } if (needDivider) { if (LocaleController.isRTL) { canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, Theme.dividerPaint); } else { canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, Theme.dividerPaint); } } }
Example 19
Source File: AvatarDrawable.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public void setInfo(int id, String firstName, String lastName, String custom) { if (isProfile) { color = getProfileColorForId(id); } else { color = getColorForId(id); } needApplyColorAccent = id == 5; // Tinting manually set blue color avatarType = AVATAR_TYPE_NORMAL; drawDeleted = false; 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.appendCodePoint(firstName.codePointAt(0)); } if (lastName != null && lastName.length() > 0) { Integer lastch = null; for (int a = lastName.length() - 1; a >= 0; a--) { if (lastch != null && lastName.charAt(a) == ' ') { break; } lastch = lastName.codePointAt(a); } if (Build.VERSION.SDK_INT > 17) { stringBuilder.append("\u200C"); } stringBuilder.appendCodePoint(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 > 17) { stringBuilder.append("\u200C"); } stringBuilder.appendCodePoint(firstName.codePointAt(a + 1)); break; } } } } } if (stringBuilder.length() > 0) { String text = stringBuilder.toString().toUpperCase(); try { textLayout = new StaticLayout(text, 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(e); } } else { textLayout = null; } }
Example 20
Source File: AvatarDrawable.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast, String custom) { if (isProfile) { color = getProfileColorForId(id); } else { color = getColorForId(id); } drawBrodcast = isBroadcast; savedMessages = 0; 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.appendCodePoint(firstName.codePointAt(0)); } if (lastName != null && lastName.length() > 0) { Integer lastch = null; for (int a = lastName.length() - 1; a >= 0; a--) { if (lastch != null && lastName.charAt(a) == ' ') { break; } lastch = lastName.codePointAt(a); } if (Build.VERSION.SDK_INT > 17) { stringBuilder.append("\u200C"); } stringBuilder.appendCodePoint(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 > 17) { stringBuilder.append("\u200C"); } stringBuilder.appendCodePoint(firstName.codePointAt(a + 1)); break; } } } } } if (stringBuilder.length() > 0) { String text = stringBuilder.toString().toUpperCase(); try { textLayout = new StaticLayout(text, 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(e); } } else { textLayout = null; } }