/** * Flush view no matter what height and width the {@link WXDomObject} specifies. * @param extra must be a {@link Layout} object, otherwise, nothing will happen. */ private void flushView(Object extra) { if (extra instanceof Layout && getHostView() != null && !extra.equals(getHostView().getTextLayout())) { final Layout layout = (Layout) extra; /**The following if block change the height of the width of the textView. * other part of the code is the same to updateExtra */ ViewGroup.LayoutParams layoutParams = getHostView().getLayoutParams(); if (layoutParams != null) { layoutParams.height = layout.getHeight(); layoutParams.width = layout.getWidth(); getHostView().setLayoutParams(layoutParams); } getHostView().setTextLayout(layout); getHostView().invalidate(); } }
/** * Show the end of the URL rather than the beginning. */ @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { Layout layout = mUrlBar.getLayout(); if (layout == null) return; // Android doesn't account for the compound Drawable in its width calculations, leading to // improper scrolling and even Android improperly placing the horizontal fade in its // TextView calculation. Get around it by calculating that width manually: crbug.com/303908 int urlBarWidth = mUrlBar.getWidth(); int iconWidth = mCurrentIconResource == 0 ? 0 : mIconResourceWidths.get(mCurrentIconResource); int availableTextWidth = urlBarWidth - iconWidth; int desiredWidth = (int) Layout.getDesiredWidth(layout.getText(), layout.getPaint()); if (desiredWidth > availableTextWidth) { mUrlBar.scrollTo(desiredWidth - availableTextWidth, 0); } else { mUrlBar.scrollTo(0, 0); } }
/** * @return True, if adjustments were made that require the view to be invalidated. */ private boolean adjustBottomLines() { // Bail out if we have a zero width; lines will be adjusted during next layout. if (getWidth() == 0) { return false; } int destBottomLines; textPaint.setTextSize(bottomTextSize); if (tempErrorText != null || helperText != null) { Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ? Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER; textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true); destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines); } else { destBottomLines = minBottomLines; } if (bottomLines != destBottomLines) { getBottomLinesAnimator(destBottomLines).start(); } bottomLines = destBottomLines; return true; }
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout l) { if (first) { TextPaint paint = new TextPaint(p); paint.setStyle(Paint.Style.FILL); if (options.textSize != -1) { paint.setTextSize(options.textSize); } if (options.textColor != -1) { paint.setColor(options.textColor); } if (options.typeface != null) { paint.setTypeface(options.typeface); } c.save(); c.drawText(data, x + options.leadWidth, baseline, paint); c.restore(); } }
private void moveCursor(int x, int y) { x -= edit.getPaddingLeft(); y -= edit.getPaddingTop(); Layout l = edit.getLayout(); int offset; int line = l.getLineForVertical(y); if(line == 0 && y < l.getLineTop(line)) { offset = 0; } else if(line >= l.getLineCount() - 1 && y >= l.getLineTop(line + 1)) { offset = l.getText().length(); } else { offset = l.getOffsetForHorizontal(line, x); } edit.setSelection(offset); }
@Override public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) { if (multiline) { paint.setStyle(Paint.Style.FILL); paint.setColor(theme.getCodeBackgroundColor(p)); final int left; final int right; if (dir > 0) { left = x; right = c.getWidth(); } else { left = x - c.getWidth(); right = x; } rect.set(left, top, right, bottom); c.drawRect(rect, paint); } }
private void configureTextLayouts(final int availableWidth) { if (!textLayoutsConfigured) { final int totalNeededPadding = getPaddingLeft() + getPaddingRight(); // Create new static layout only if needed! if ((titleLayout.getWidth() + totalNeededPadding) > availableWidth) { this.titleLayout = new StaticLayout(title, titlePaint, availableWidth, Layout.Alignment.ALIGN_NORMAL, 1.15f, 0, false); } // Create new static layout only if needed! if ((subtitleLayout.getWidth() + totalNeededPadding) > availableWidth) { this.subtitleLayout = new StaticLayout(subtitle, subtitlePaint, availableWidth, Layout.Alignment.ALIGN_NORMAL, 1.15f, 0, false); } textLayoutsConfigured = true; } }
private void drawIndicatorsTextAbove(Canvas canvas, String text, TextPaint paintText, float x, float y, Layout.Alignment alignment) { final float textHeight = calculateTextMultilineHeight(text, paintText); y -= textHeight; final int width = (int) paintText.measureText(text); if (x >= getWidth() - settings.paddingCorners) { x = (getWidth() - width - settings.paddingCorners / 2f); } else if (x <= 0) { x = width / 2f; } else { x = (x - width / 2f); } if (x < 0) { x = 0; } if (x + width > getWidth()) { x = getWidth() - width; } drawText(canvas, text, x, y, paintText, alignment); }
public static int getPreciseOffset(TextView textView, int x, int y) { Layout layout = textView.getLayout(); if (layout != null) { int topVisibleLine = layout.getLineForVertical(y); int offset = layout.getOffsetForHorizontal(topVisibleLine, x); int offsetX = (int) layout.getPrimaryHorizontal(offset); if (offsetX > x) { return layout.getOffsetToLeftOf(offset); } else { return offset; } } else { return -1; } }
private static String getTextDirection(Spanned text, int start, int end) { // FIXME not supported int paraDir = Layout.DIR_LEFT_TO_RIGHT; // final int len = end - start; // final byte[] levels = ArrayUtils.newUnpaddedByteArray(len); // final char[] buffer = TextUtils.obtain(len); // TextUtils.getChars(text, start, end, buffer, 0); // int paraDir = AndroidBidi.bidi(Layout.DIR_REQUEST_DEFAULT_LTR, buffer, levels, len, // false /* no info */); switch (paraDir) { case Layout.DIR_RIGHT_TO_LEFT: return " dir=\"rtl\""; case Layout.DIR_LEFT_TO_RIGHT: default: return " dir=\"ltr\""; } }
/** * Sets the text size of a clone of the view's {@link TextPaint} object * and uses a {@link StaticLayout} instance to measure the height of the text. * * @param source * @param availableWidthPixels * @param textSizePixels * @return the height of the text when placed in a view * with the specified width * and when the text has the specified size. */ private int getTextHeightPixels( CharSequence source, int availableWidthPixels, float textSizePixels) { // Make a copy of the original TextPaint object // since the object gets modified while measuring // (see also the docs for TextView.getPaint() // which states to access it read-only) TextPaint textPaintCopy = new TextPaint(getPaint()); textPaintCopy.setTextSize(textSizePixels); // Measure using a StaticLayout instance StaticLayout staticLayout = new StaticLayout( source, textPaintCopy, availableWidthPixels, Layout.Alignment.ALIGN_NORMAL, mLineSpacingMultiplier, mLineSpacingExtra, true); return staticLayout.getHeight(); }
public boolean isTitleTruncated() { if (this.mTitleTextView == null) { return false; } Layout titleLayout = this.mTitleTextView.getLayout(); if (titleLayout == null) { return false; } int lineCount = titleLayout.getLineCount(); for (int i = 0; i < lineCount; i++) { if (titleLayout.getEllipsisCount(i) > 0) { return true; } } return false; }
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) { Paint.Style prevStyle = p.getStyle(); int prevColor = p.getColor(); p.setStyle(Paint.Style.FILL); p.setColor(lineColor); c.drawRect(x, top, x + dir * lineWidth, bottom, p); p.setStyle(prevStyle); p.setColor(prevColor); }
/** * 微博文本触摸监听处理 * * @param textView 点击的TextView * @param event * @return true:点击事件被处理;false:点击事件未被处理,向上冒泡 */ private boolean textTouchEvent(TextView textView, MotionEvent event) { boolean ret = false; CharSequence text = textView.getText(); Spannable sText = Spannable.Factory.getInstance().newSpannable(text); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); x -= textView.getTotalPaddingLeft(); y -= textView.getTotalPaddingTop(); x += textView.getScrollX(); y += textView.getScrollY(); Layout layout = textView.getLayout(); int line = layout.getLineForVertical(y); int offset = layout.getOffsetForHorizontal(line, x); ClickableSpan[] links = sText.getSpans(offset, offset, ClickableSpan.class); if (links.length != 0) { if (action == MotionEvent.ACTION_UP) { links[0].onClick(textView); } ret = true; } } return ret; }
private void updateSecretTimeText() { if (currentMessageObject == null) { return; } String str = currentMessageObject.getSecretTimeString(); if (str == null) { return; } if (currentInfoString == null || !currentInfoString.equals(str)) { currentInfoString = str; infoWidth = (int)Math.ceil(infoPaint.measureText(currentInfoString)); CharSequence str2 = TextUtils.ellipsize(currentInfoString, infoPaint, infoWidth, TextUtils.TruncateAt.END); infoLayout = new StaticLayout(str2, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); invalidate(); } }
protected void onPopupChangePosition() { try { Layout layout = getLayout(); if (layout != null) { int pos = getSelectionStart(); int line = layout.getLineForOffset(pos); int baseline = layout.getLineBaseline(line); int ascent = layout.getLineAscent(line); float x = layout.getPrimaryHorizontal(pos); float y = baseline + ascent; int offsetHorizontal = (int) x + mLeftPadding; setDropDownHorizontalOffset(offsetHorizontal); int heightVisible = getHeightVisible(); int offsetVertical = (int) ((y + mCharHeight) - getScrollY()); int tmp = offsetVertical + getDropDownHeight() + mCharHeight; if (tmp < heightVisible) { tmp = offsetVertical + mCharHeight / 2; setDropDownVerticalOffset(tmp); } else { tmp = offsetVertical - getDropDownHeight() - mCharHeight; setDropDownVerticalOffset(tmp); } } } catch (Exception ignored) { //nothing } }
/** * @deprecated Use a non-deprecated constructor for ReactTextUpdate instead. This one remains * because it's being used by a unit test that isn't currently open source. */ @Deprecated public ReactTextUpdate( Spannable text, int jsEventCounter, boolean containsImages, float paddingStart, float paddingTop, float paddingEnd, float paddingBottom, int textAlign) { this(text, jsEventCounter, containsImages, paddingStart, paddingTop, paddingEnd, paddingBottom, textAlign, Layout.BREAK_STRATEGY_HIGH_QUALITY); }
private void init() { circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setDither(true); circlePaint.setColor(backgroundColor); circlePaint.setStyle(Paint.Style.FILL); textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setDither(true); textPaint.setColor(textColor); textPaint.setTextSize(textSize); textPaint.setTextAlign(Paint.Align.CENTER); borderPaint = new Paint(); borderPaint.setAntiAlias(true); borderPaint.setDither(true); borderPaint.setColor(borderColor); borderPaint.setStrokeWidth(borderWidth); borderPaint.setStyle(Paint.Style.STROKE); int textWidth = (int) textPaint.measureText(text.substring(0, (text.length() + 1) / 2)); staticLayout = new StaticLayout(text, textPaint, textWidth, Layout.Alignment.ALIGN_NORMAL, 1F, 0, false); }
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { if (event.getAction() == 1) { this.mLinkClicked = false; this.mClickedLink = null; int x = (((int) event.getX()) - widget.getTotalPaddingLeft()) + widget.getScrollX(); int y = (((int) event.getY()) - widget.getTotalPaddingTop()) + widget.getScrollY(); Layout layout = widget.getLayout(); int off = layout.getOffsetForHorizontal(layout.getLineForVertical(y), (float) x); ClickableSpan[] link = (ClickableSpan[]) buffer.getSpans(off, off, ClickableSpan .class); if (link.length != 0) { SensibleUrlSpan span = link[0]; this.mLinkClicked = span.onClickSpan(widget); this.mClickedLink = span.getURL(); return this.mLinkClicked; } } super.onTouchEvent(widget, buffer, event); return false; }
public void checkUnreadCounter(int mask) { if (mask != 0 && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) == 0 && (mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) == 0) { return; } TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id); if (dialog != null && dialog.unread_count != 0) { if (lastUnreadCount != dialog.unread_count) { 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); if (mask != 0) { invalidate(); } } } else if (countLayout != null) { if (mask != 0) { invalidate(); } lastUnreadCount = 0; countLayout = null; } }
private static Layout.Alignment getAlignmentByGravity(int gravity) { switch (gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.START: return Layout.Alignment.ALIGN_NORMAL; case Gravity.END: return Layout.Alignment.ALIGN_OPPOSITE; case Gravity.LEFT: return Layout.Alignment.ALIGN_LEFT; case Gravity.RIGHT: return Layout.Alignment.ALIGN_RIGHT; case Gravity.CENTER_HORIZONTAL: return Layout.Alignment.ALIGN_CENTER; default: return Layout.Alignment.ALIGN_NORMAL; } }
public Bitmap createViewBitmap(View view, Layout textLayout, int bitmapWidth, int bitmapHeight, int vertical_align) { final int actualBitmapWidth = getPowerOfTwo(bitmapWidth); final int actualBitmapHeight = getPowerOfTwo(bitmapHeight); Bitmap destBitmap = Bitmap.createBitmap( actualBitmapWidth, actualBitmapHeight, Bitmap.Config.ARGB_8888 ); destBitmap.eraseColor(Color.TRANSPARENT); synchronized (mCanvas) { mCanvas.setBitmap(destBitmap); mCanvas.save(); // Center the bitmap horizontally inside the "powerOfTwo" texture bitmap mCanvas.translate((actualBitmapWidth - bitmapWidth) / 2, 0); // Align vertically depending of the argument switch (vertical_align) { case ALIGN_BOTTOM: mCanvas.translate(0,actualBitmapHeight - bitmapHeight); break; case ALIGN_TOP: break; case ALIGN_CENTER: default: mCanvas.translate(0, (actualBitmapHeight - bitmapHeight) / 2); } view.draw(mCanvas); if (textLayout != null) { // Draw the text using the TextLayout if one is provided mCanvas.translate(0, (actualBitmapHeight - bitmapHeight) / 2); textLayout.draw(mCanvas); } mCanvas.restore(); } return destBitmap; }
public void drawLeadingMargin(final Canvas c, final Paint p, int x, final int dir, final int top, final int baseline, final int bottom, final CharSequence text, final int start, final int end, final boolean first, final Layout layout) { int st = ((Spanned) text).getSpanStart(this); int itop = layout.getLineTop(layout.getLineForOffset(st)); if (dir < 0) x -= mBitmap.getWidth(); int delta = totalHeight - mBitmap.getHeight(); if (delta > 0) { if (mVerticalAlignment == ALIGN_TOP) { c.drawBitmap(mBitmap, x, itop, p); } else if (mVerticalAlignment == ALIGN_CENTER) { c.drawBitmap(mBitmap, x, itop + delta / 2, p); } else { c.drawBitmap(mBitmap, x, itop + delta, p); } } else { c.drawBitmap(mBitmap, x, itop, p); } }
private Layout makeNewLayout(int i, BoringLayout.Metrics metrics, int i2, boolean z) { int i3; boolean z2; if (i < 0) { i3 = 0; } else { i3 = i; } this.mOldMaxLines = this.mMaxLines; if (this.mEllipsize != null) { z2 = true; } else { z2 = false; } return makeSingleLayout(i3, metrics, i2, this.mLayoutAlignment, z2, this.mEllipsize, z); }
public ITouchableSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); x -= textView.getTotalPaddingLeft(); y -= textView.getTotalPaddingTop(); x += textView.getScrollX(); y += textView.getScrollY(); Layout layout = textView.getLayout(); int line = layout.getLineForVertical(y); int off = layout.getOffsetForHorizontal(line, x); if (x < layout.getLineLeft(line) || x > layout.getLineRight(line)) { // 实际上没点到任何内容 off = -1; } ITouchableSpan[] link = spannable.getSpans(off, off, ITouchableSpan.class); ITouchableSpan touchedSpan = null; if (link.length > 0) { touchedSpan = link[0]; } return touchedSpan; }
@Override public void setTextBreakStrategy(@Nullable String textBreakStrategy) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return; } if (textBreakStrategy == null || "simple".equals(textBreakStrategy)) { mTextBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE; } else if ("highQuality".equals(textBreakStrategy)) { mTextBreakStrategy = Layout.BREAK_STRATEGY_HIGH_QUALITY; } else if ("balanced".equals(textBreakStrategy)) { mTextBreakStrategy = Layout.BREAK_STRATEGY_BALANCED; } else { throw new JSApplicationIllegalArgumentException("Invalid textBreakStrategy: " + textBreakStrategy); } }
private void drawMultilineText(Canvas canvas, String text, float x, float y, TextPaint paint, Layout.Alignment aligment) { final float lineHeight = paint.getTextSize(); float lineY = y; for (CharSequence line : text.split("\n")) { canvas.save(); { final float lineWidth = (int) paint.measureText(line.toString()); float lineX = x; if (aligment == Layout.Alignment.ALIGN_CENTER) { lineX -= lineWidth / 2f; } if (lineX < 0) { lineX = 0; } final float right = lineX + lineWidth; if (right > canvas.getWidth()) { lineX = canvas.getWidth() - lineWidth - settings.paddingCorners; } canvas.translate(lineX, lineY); final StaticLayout staticLayout = new StaticLayout(line, paint, (int) lineWidth, aligment, 1.0f, 0, false); staticLayout.draw(canvas); lineY += lineHeight; } canvas.restore(); } }
public static Layout.Alignment getTextAlignment(Map<String, Object> style){ Layout.Alignment alignment= Layout.Alignment.ALIGN_NORMAL; String textAlign= (String) style.get(Constants.Name.TEXT_ALIGN); if(TextUtils.equals(Constants.Value.LEFT,textAlign)){ alignment= Layout.Alignment.ALIGN_NORMAL; } else if(TextUtils.equals(Constants.Value.CENTER,textAlign)){ alignment=Layout.Alignment.ALIGN_CENTER; } else if(TextUtils.equals(Constants.Value.RIGHT,textAlign)){ alignment= Layout.Alignment.ALIGN_OPPOSITE; } return alignment; }
@Override public void updateExtra(Object extra) { if (extra instanceof Layout && getHostView() != null && !extra.equals(getHostView().getTextLayout())) { final Layout layout = (Layout) extra; getHostView().setTextLayout(layout); getHostView().invalidate(); } }
/** * Calculates desired height for layout * * @param layout the source layout * @return the desired layout height */ private int getDesiredHeight(Layout layout) { if (layout == null) { return 0; } int desired = getItemHeight() * visibleItems - ITEM_OFFSET * 2 - ADDITIONAL_ITEM_HEIGHT; // Check against our minimum height desired = Math.max(desired, getSuggestedMinimumHeight()); return desired; }
private float getMaxLineWidth(Layout layout) { float max_width = 0.0f; int lines = layout.getLineCount(); for (int i = 0; i < lines; i++) { if (layout.getLineWidth(i) > max_width) { max_width = layout.getLineWidth(i); } } return max_width; }
@Override /* package */ void updateNodeRegion( float left, float top, float right, float bottom, boolean isVirtual) { NodeRegion nodeRegion = getNodeRegion(); if (mDrawCommand == null) { if (!nodeRegion.matches(left, top, right, bottom, isVirtual)) { setNodeRegion(new TextNodeRegion(left, top, right, bottom, getReactTag(), isVirtual, null)); } return; } Layout layout = null; if (nodeRegion instanceof TextNodeRegion) { layout = ((TextNodeRegion) nodeRegion).getLayout(); } Layout newLayout = mDrawCommand.getLayout(); if (!nodeRegion.matches(left, top, right, bottom, isVirtual) || layout != newLayout) { setNodeRegion( new TextNodeRegion(left, top, right, bottom, getReactTag(), isVirtual, newLayout)); } }
public static int getStartIndexAtLine(EditText editable, int line) { Layout layout = editable.getLayout(); if (layout != null) { return layout.getLineStart(line); } return 0; }
protected void onMeasure(int i, int i2) { String generateCacheKey = generateCacheKey(); this.mCacheText = (TextCache) getAreaCache(generateCacheKey); if (this.mCacheText == null || this.mCacheText.mLayout == null || this.mMeasureDirty) { this.mCacheText = new TextCache(); addAreaCache(generateCacheKey, this.mCacheText); int mode = View.MeasureSpec.getMode(i); int mode2 = View.MeasureSpec.getMode(i2); int size = View.MeasureSpec.getSize(i); int size2 = View.MeasureSpec.getSize(i2); if (mode == 1073741824) { this.mCacheText.measuredWidth = size; } else { this.mBoring = BoringLayout.isBoring(this.mText, this.mPaint, UNKNOWN_BORING); if (this.mBoring == null || this.mBoring == UNKNOWN_BORING) { this.mCacheText.measuredWidth = (int) Layout.getDesiredWidth(this.mText, this.mPaint); } else { this.mCacheText.measuredWidth = this.mBoring.width; } TextCache textCache = this.mCacheText; textCache.measuredWidth = textCache.measuredWidth + (this.paddingLeft + this.paddingRight); if (mode == Integer.MIN_VALUE) { this.mCacheText.measuredWidth = Math.min(size, this.mCacheText.measuredWidth); } } mode = (this.mCacheText.measuredWidth - this.paddingLeft) - this.paddingRight; this.mCacheText.mLayout = makeNewLayout(mode, this.mBoring, mode, false); if (mode2 == 1073741824) { this.mCacheText.measuredHeight = size2; } else { this.mCacheText.measuredHeight = getDesiredHeight(); if (mode2 == Integer.MIN_VALUE) { this.mCacheText.measuredHeight = Math.min(size2, this.mCacheText.measuredHeight); } } setMeasuredDimension(this.mCacheText.measuredWidth, this.mCacheText.measuredHeight); return; } setMeasuredDimension(this.mCacheText.measuredWidth, this.mCacheText.measuredHeight); }
private static Layout.Alignment getAlignment(int alignment) { if (alignment == TextSection.CENTER) { return Layout.Alignment.ALIGN_CENTER; } else if (alignment == TextSection.RIGHT) return Layout.Alignment.ALIGN_OPPOSITE; return Layout.Alignment.ALIGN_NORMAL; }
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; }
public boolean handleTouchEvent(MotionEvent event) { int action = event.getAction(); if (action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_DOWN) { return true; } else { int x = (int) event.getX(); int y = (int) event.getY(); x -= getTotalPaddingLeft(); y -= getTotalPaddingTop(); x += getScrollX(); y += getScrollY(); Layout layout = getLayout(); int line = layout.getLineForVertical(y); int offset = layout.getOffsetForHorizontal(line, x); float width = layout.getLineWidth(line); if (y > width) { offset = y; } if (!(getText() instanceof Spannable)) { return true; } else { Spannable span = (Spannable) getText(); ClickableSpan[] clickSpan = span.getSpans(offset, offset, ClickableSpan.class); if (clickSpan == null || clickSpan.length == 0) { am[] aam = span.getSpans(offset, offset, am.class); if (aam != null && aam.length != 0) return false; return true; } else { return false; } } } }