List of usage examples for android.text TextUtils ellipsize
public static CharSequence ellipsize(CharSequence text, TextPaint p, float avail, TruncateAt where)
From source file:Main.java
public static String getTextOmit(TextPaint paint, String str, int width) { String des = null;//from ww w . j av a 2 s . c o m CharSequence sequence = TextUtils.ellipsize(str, paint, width, TruncateAt.END); if (sequence != null) { des = sequence.toString(); } return des; }
From source file:Main.java
private static CharSequence getEllipsizedText(final CharSequence text, final int maxWidth, final TextPaint paint) { if (text == null) { return null; }/* w w w .j a v a2 s . c o m*/ final float scaleX = getTextScaleX(text, maxWidth, paint); if (scaleX >= MIN_TEXT_XSCALE) { paint.setTextScaleX(scaleX); return text; } // Note that TextUtils.ellipsize() use text-x-scale as 1.0 if ellipsize is needed. To // get squeezed and ellipsized text, passes enlarged width (maxWidth / MIN_TEXT_XSCALE). final float upscaledWidth = maxWidth / MIN_TEXT_XSCALE; CharSequence ellipsized = TextUtils.ellipsize(text, paint, upscaledWidth, TextUtils.TruncateAt.MIDDLE); // For an unknown reason, ellipsized seems to return a text that does indeed fit inside the // passed width according to paint.measureText, but not according to paint.getTextWidths. // But when rendered, the text seems to actually take up as many pixels as returned by // paint.getTextWidths, hence problem. // To save this case, we compare the measured size of the new text, and if it's too much, // try it again removing the difference. This may still give a text too long by one or // two pixels so we take an additional 2 pixels cushion and call it a day. // TODO: figure out why getTextWidths and measureText don't agree with each other, and // remove the following code. final float ellipsizedTextWidth = getTextWidth(ellipsized, paint); if (upscaledWidth <= ellipsizedTextWidth) { ellipsized = TextUtils.ellipsize(text, paint, upscaledWidth - (ellipsizedTextWidth - upscaledWidth) - 2, TextUtils.TruncateAt.MIDDLE); } paint.setTextScaleX(MIN_TEXT_XSCALE); return ellipsized; }
From source file:Main.java
public static String getEllipsisedText(TextView textView) { try {/*from w w w. j a v a2s. c o m*/ String text = textView.getText().toString(); int lines = textView.getLineCount(); int width = textView.getWidth(); int len = text.length(); Log.d("Test", "text-->" + text + "; lines-->" + lines + "; width-->" + width + ";len-->" + len); TextUtils.TruncateAt where = TextUtils.TruncateAt.END; TextPaint paint = textView.getPaint(); StringBuffer result = new StringBuffer(); int spos = 0, cnt, tmp, hasLines = 0; while (hasLines < lines - 1) { cnt = paint.breakText(text, spos, len, true, width, null); if (cnt >= len - spos) { result.append(text.substring(spos)); break; } tmp = text.lastIndexOf('\n', spos + cnt - 1); if (tmp >= 0 && tmp < spos + cnt) { result.append(text.substring(spos, tmp + 1)); spos += tmp + 1; } else { tmp = text.lastIndexOf(' ', spos + cnt - 1); if (tmp >= spos) { result.append(text.substring(spos, tmp + 1)); spos += tmp + 1; } else { result.append(text.substring(spos, cnt)); spos += cnt; } } hasLines++; } if (spos < len) { result.append(TextUtils.ellipsize(text.subSequence(spos, len), paint, (float) width, where)); } return result.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
@Nullable private static CharSequence getEllipsizedTextWithSettingScaleX(@Nullable final CharSequence text, final int maxWidth, @Nonnull final TextPaint paint) { if (text == null) { return null; }/*from w ww .j a v a 2 s .c om*/ final float scaleX = getTextScaleX(text, maxWidth, paint); if (scaleX >= MIN_TEXT_XSCALE) { paint.setTextScaleX(scaleX); return text; } // <code>text</code> must be ellipsized with minimum text scale x. paint.setTextScaleX(MIN_TEXT_XSCALE); final boolean hasBoldStyle = hasStyleSpan(text, BOLD_SPAN); final boolean hasUnderlineStyle = hasStyleSpan(text, UNDERLINE_SPAN); // TextUtils.ellipsize erases any span object existed after ellipsized point. // We have to restore these spans afterward. final CharSequence ellipsizedText = TextUtils.ellipsize(text, paint, maxWidth, TextUtils.TruncateAt.MIDDLE); if (!hasBoldStyle && !hasUnderlineStyle) { return ellipsizedText; } final Spannable spannableText = (ellipsizedText instanceof Spannable) ? (Spannable) ellipsizedText : new SpannableString(ellipsizedText); if (hasBoldStyle) { addStyleSpan(spannableText, BOLD_SPAN); } if (hasUnderlineStyle) { addStyleSpan(spannableText, UNDERLINE_SPAN); } return spannableText; }
From source file:com.android.mail.text.FolderSpan.java
@Override public void draw(Canvas canvas, CharSequence charSequence, int start, int end, float x, int top, int baseline, int bottom, Paint paint) { mWorkPaint.set(paint);// w w w .j av a2s. c o m mWorkPaint.setTextSize(mRes.folderFontSize); final int width = getWidth(mWorkPaint); final int height = getHeight(mWorkPaint); String name = mName; if (width == mDim.getMaxChipWidth()) { name = TextUtils.ellipsize(mName, mWorkPaint, width - 2 * mRes.folderHorizontalPadding, TextUtils.TruncateAt.MIDDLE).toString(); } FolderDisplayer.drawFolder(canvas, x, baseline - height, width, height, name, mFgColor, mBgColor, mRes, mFormatter, mWorkPaint); }
From source file:org.smssecure.smssecure.util.ViewUtil.java
public static CharSequence ellipsize(@Nullable CharSequence text, @NonNull TextView view) { if (TextUtils.isEmpty(text) || view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) { return text; } else {/*ww w . j a v a 2 s. c om*/ return TextUtils.ellipsize(text, view.getPaint(), view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(), TruncateAt.END); } }
From source file:org.telegram.ui.Cells.ContextLinkCell.java
@SuppressLint("DrawAllocation") @Override//from www . ja v a 2 s . c o m protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { drawLinkImageView = false; descriptionLayout = null; titleLayout = null; linkLayout = null; linkY = AndroidUtilities.dp(27); if (inlineResult == null && documentAttach == null) { setMeasuredDimension(AndroidUtilities.dp(100), AndroidUtilities.dp(100)); return; } int viewWidth = MeasureSpec.getSize(widthMeasureSpec); int maxWidth = viewWidth - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - AndroidUtilities.dp(8); TLRPC.PhotoSize currentPhotoObject = null; TLRPC.PhotoSize currentPhotoObjectThumb = null; ArrayList<TLRPC.PhotoSize> photoThumbs = null; String url = null; if (documentAttach != null) { photoThumbs = new ArrayList<>(); photoThumbs.add(documentAttach.thumb); } else if (inlineResult != null && inlineResult.photo != null) { photoThumbs = new ArrayList<>(inlineResult.photo.sizes); } if (!mediaWebpage && inlineResult != null) { if (inlineResult.title != null) { try { int width = (int) Math.ceil(titleTextPaint.measureText(inlineResult.title)); CharSequence titleFinal = TextUtils.ellipsize( Emoji.replaceEmoji(inlineResult.title.replace('\n', ' '), titleTextPaint.getFontMetricsInt(), AndroidUtilities.dp(15), false), titleTextPaint, Math.min(width, maxWidth), TextUtils.TruncateAt.END); titleLayout = new StaticLayout(titleFinal, titleTextPaint, maxWidth + AndroidUtilities.dp(4), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); } catch (Exception e) { FileLog.e("tmessages", e); } letterDrawable.setTitle(inlineResult.title); } if (inlineResult.description != null) { try { descriptionLayout = ChatMessageCell.generateStaticLayout( Emoji.replaceEmoji(inlineResult.description, descriptionTextPaint.getFontMetricsInt(), AndroidUtilities.dp(13), false), descriptionTextPaint, maxWidth, maxWidth, 0, 3); if (descriptionLayout.getLineCount() > 0) { linkY = descriptionY + descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1) + AndroidUtilities.dp(1); } } catch (Exception e) { FileLog.e("tmessages", e); } } if (inlineResult.url != null) { try { int width = (int) Math.ceil(descriptionTextPaint.measureText(inlineResult.url)); CharSequence linkFinal = TextUtils.ellipsize(inlineResult.url.replace('\n', ' '), descriptionTextPaint, Math.min(width, maxWidth), TextUtils.TruncateAt.MIDDLE); linkLayout = new StaticLayout(linkFinal, descriptionTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); } catch (Exception e) { FileLog.e("tmessages", e); } } } String ext = null; if (documentAttach != null) { if (MessageObject.isGifDocument(documentAttach)) { currentPhotoObject = documentAttach.thumb; } else if (MessageObject.isStickerDocument(documentAttach)) { currentPhotoObject = documentAttach.thumb; ext = "webp"; } else { if (documentAttachType != DOCUMENT_ATTACH_TYPE_MUSIC && documentAttachType != DOCUMENT_ATTACH_TYPE_AUDIO) { currentPhotoObject = documentAttach.thumb; } } } else if (inlineResult != null && inlineResult.photo != null) { currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, AndroidUtilities.getPhotoSize(), true); currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, 80); if (currentPhotoObjectThumb == currentPhotoObject) { currentPhotoObjectThumb = null; } } if (inlineResult != null) { if (inlineResult.content_url != null) { if (inlineResult.type != null) { if (inlineResult.type.startsWith("gif")) { if (documentAttachType != DOCUMENT_ATTACH_TYPE_GIF) { url = inlineResult.content_url; documentAttachType = DOCUMENT_ATTACH_TYPE_GIF; } } else if (inlineResult.type.equals("photo")) { url = inlineResult.thumb_url; if (url == null) { url = inlineResult.content_url; } } } } if (url == null && inlineResult.thumb_url != null) { url = inlineResult.thumb_url; } } if (url == null && currentPhotoObject == null && currentPhotoObjectThumb == null) { if (inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue || inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaGeo) { double lat = inlineResult.send_message.geo.lat; double lon = inlineResult.send_message.geo._long; url = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=15&size=72x72&maptype=roadmap&scale=%d&markers=color:red|size:small|%f,%f&sensor=false", lat, lon, Math.min(2, (int) Math.ceil(AndroidUtilities.density)), lat, lon); } } int width; int w = 0; int h = 0; if (documentAttach != null) { for (int b = 0; b < documentAttach.attributes.size(); b++) { TLRPC.DocumentAttribute attribute = documentAttach.attributes.get(b); if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) { w = attribute.w; h = attribute.h; break; } } } if (w == 0 || h == 0) { if (currentPhotoObject != null) { if (currentPhotoObjectThumb != null) { currentPhotoObjectThumb.size = -1; } w = currentPhotoObject.w; h = currentPhotoObject.h; } else if (inlineResult != null) { w = inlineResult.w; h = inlineResult.h; } } if (w == 0 || h == 0) { w = h = AndroidUtilities.dp(80); } if (documentAttach != null || currentPhotoObject != null || url != null) { String currentPhotoFilter; String currentPhotoFilterThumb = "52_52_b"; if (mediaWebpage) { width = (int) (w / (h / (float) AndroidUtilities.dp(80))); if (documentAttachType == DOCUMENT_ATTACH_TYPE_GIF) { currentPhotoFilterThumb = currentPhotoFilter = String.format(Locale.US, "%d_%d_b", (int) (width / AndroidUtilities.density), 80); } else { currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (width / AndroidUtilities.density), 80); currentPhotoFilterThumb = currentPhotoFilter + "_b"; } } else { currentPhotoFilter = "52_52"; } linkImageView.setAspectFit(documentAttachType == DOCUMENT_ATTACH_TYPE_STICKER); if (documentAttachType == DOCUMENT_ATTACH_TYPE_GIF) { if (documentAttach != null) { linkImageView.setImage(documentAttach, null, currentPhotoObject != null ? currentPhotoObject.location : null, currentPhotoFilter, documentAttach.size, ext, false); } else { linkImageView.setImage(null, url, null, null, currentPhotoObject != null ? currentPhotoObject.location : null, currentPhotoFilter, -1, ext, true); } } else { if (currentPhotoObject != null) { linkImageView.setImage(currentPhotoObject.location, currentPhotoFilter, currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, currentPhotoFilterThumb, currentPhotoObject.size, ext, false); } else { linkImageView.setImage(null, url, currentPhotoFilter, null, currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, currentPhotoFilterThumb, -1, ext, true); } } drawLinkImageView = true; } if (mediaWebpage) { setBackgroundDrawable(null); width = viewWidth; int height = MeasureSpec.getSize(heightMeasureSpec); if (height == 0) { height = AndroidUtilities.dp(100); } setMeasuredDimension(width, height); int x = (width - AndroidUtilities.dp(24)) / 2; int y = (height - AndroidUtilities.dp(24)) / 2; radialProgress.setProgressRect(x, y, x + AndroidUtilities.dp(24), y + AndroidUtilities.dp(24)); linkImageView.setImageCoords(0, 0, width, height); } else { setBackgroundResource(R.drawable.list_selector); 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 (linkLayout != null && linkLayout.getLineCount() > 0) { height += linkLayout.getLineBottom(linkLayout.getLineCount() - 1); } height = Math.max(AndroidUtilities.dp(52), height); setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), Math.max(AndroidUtilities.dp(68), height + AndroidUtilities.dp(16)) + (needDivider ? 1 : 0)); int maxPhotoWidth = AndroidUtilities.dp(52); int x = LocaleController.isRTL ? MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(8) - maxPhotoWidth : AndroidUtilities.dp(8); letterDrawable.setBounds(x, AndroidUtilities.dp(8), x + maxPhotoWidth, AndroidUtilities.dp(60)); linkImageView.setImageCoords(x, AndroidUtilities.dp(8), maxPhotoWidth, maxPhotoWidth); if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) { radialProgress.setProgressRect(x + AndroidUtilities.dp(4), AndroidUtilities.dp(12), x + AndroidUtilities.dp(48), AndroidUtilities.dp(56)); } } }
From source file:com.cocosw.accessory.views.layout.CollapsingTitleLayout.java
private void setInterpolatedTextSize(final float textSize) { if (mTitle == null) return;//from ww w . ja va2 s .co m if (isClose(textSize, mCollapsedTitleTextSize) || isClose(textSize, mExpandedTitleTextSize) || mTitleToDraw == null) { // If the text size is 'close' to being a decimal, then we use this as a sync-point. // We disable our manual scaling and set the paint's text size. mTextPaint.setTextSize(textSize); mScale = 1f; // We also use this as an opportunity to ellipsize the string final CharSequence title = TextUtils.ellipsize(mTitle, mTextPaint, (mTextRight - mTextLeft), TextUtils.TruncateAt.END); if (title != mTitleToDraw) { // If the title has changed, turn it into a string mTitleToDraw = title.toString(); } // As we've changed the text size (and possibly the text) we'll re-measure the text mTextPaint.getTextBounds(mTitleToDraw, 0, mTitleToDraw.length(), mTextPaintBounds); mDrawnTextBounds.set(mTextPaintBounds); if (USE_SCALING_TEXTURE && isClose(textSize, mExpandedTitleTextSize)) { ensureExpandedTexture(); } mUseTexture = false; } else { // We're not close to a decimal so use our canvas scaling method if (mExpandedTitleTexture != null) { mScale = textSize / mExpandedTitleTextSize; } else { mScale = textSize / mTextPaint.getTextSize(); } // Because we're scaling using canvas, we need to update the drawn text bounds too mDrawnTextBounds.set(mTextPaintBounds); mDrawnTextBounds.left *= mScale; mDrawnTextBounds.top *= mScale; mDrawnTextBounds.right *= mScale; mDrawnTextBounds.bottom *= mScale; mUseTexture = USE_SCALING_TEXTURE; } ViewCompat.postInvalidateOnAnimation(this); }
From source file:org.telegram.ui.Cells.SharedLinkCell.java
@SuppressLint("DrawAllocation") @Override//from w w w . j av a2 s . com 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.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java
private void setInterpolatedTextSize(final float textSize) { if (mTitle == null) return;//from w w w . j a v a 2s .c o m if (isClose(textSize, mCollapsedTitleTextSize) || isClose(textSize, mExpandedTitleTextSize) || mTitleToDraw == null) { // If the text size is 'close' to being a decimal, then we use this as a sync-point. // We disable our manual scaling and set the paint's text size. mTextPaint.setTextSize(textSize); mScale = 1f; // We also use this as an opportunity to ellipsize the string final CharSequence title = TextUtils.ellipsize(mTitle, mTextPaint, mTextRight - mTextLeft, TextUtils.TruncateAt.END); if (title != mTitleToDraw) { // If the title has changed, turn it into a string mTitleToDraw = title.toString(); } if (USE_SCALING_TEXTURE && isClose(textSize, mExpandedTitleTextSize)) { ensureExpandedTexture(); } mUseTexture = false; } else { // We're not close to a decimal so use our canvas scaling method if (mExpandedTitleTexture != null) { mScale = textSize / mExpandedTitleTextSize; } else { mScale = textSize / mTextPaint.getTextSize(); } mUseTexture = USE_SCALING_TEXTURE; } ViewCompat.postInvalidateOnAnimation(this); }