Java Code Examples for android.text.Layout#getLineAscent()
The following examples show how to use
android.text.Layout#getLineAscent() .
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: LayoutMeasureUtil.java From TextLayoutBuilder with Apache License 2.0 | 6 votes |
/** * Prior to version 20, If the Layout specifies extra space between lines (either by spacingmult * or spacingadd) the StaticLayout would erroneously add this space after the last line as well. * This bug was fixed in version 20. This method calculates the extra space and reduces the height * by that amount. * * @param layout The layout. * @return The height of the layout. */ public static int getHeight(Layout layout) { if (layout == null) { return 0; } int extra = 0; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH && layout instanceof StaticLayout) { int line = Math.max(0, layout.getLineCount() - 1); int above = layout.getLineAscent(line); int below = layout.getLineDescent(line); float originalSize = (below - above - layout.getSpacingAdd()) / layout.getSpacingMultiplier(); float ex = below - above - originalSize; if (ex >= 0) { extra = (int) (ex + 0.5); } else { extra = -(int) (-ex + 0.5); } } return layout.getHeight() - extra; }
Example 2
Source File: HighlightEditor.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * @param line - current line * @param column - column of line * @return Position (in pixels) for edittext at line and column */ public Point getDebugPosition(int line, int column, int gravity) { Layout layout = getLayout(); if (layout != null) { int pos = layout.getLineStart(line) + column; int baseline = layout.getLineBaseline(line); int ascent = layout.getLineAscent(line); int offsetHorizontal = (int) layout.getPrimaryHorizontal(pos) + mLinePadding; //x float y; int offsetVertical = 0; if (gravity == Gravity.BOTTOM) { y = baseline + ascent; if (verticalScroll != null) { offsetVertical = (int) ((y + mCharHeight) - verticalScroll.getScrollY()); } else { offsetVertical = (int) ((y + mCharHeight) - getScrollY()); } return new Point(offsetHorizontal, offsetVertical); } else if (gravity == Gravity.TOP) { y = layout.getLineTop(line); if (verticalScroll != null) { offsetVertical = (int) (y - verticalScroll.getScrollY()); } else { offsetVertical = (int) (y - getScrollY()); } return new Point(offsetHorizontal, offsetVertical); } return new Point(offsetHorizontal, offsetVertical); } return new Point(); }
Example 3
Source File: HighlightEditor.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@Override public 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 + mLinePadding; setDropDownHorizontalOffset(offsetHorizontal); int heightVisible = getHeightVisible(); int offsetVertical = 0; if (verticalScroll != null) { offsetVertical = (int) ((y + mCharHeight) - verticalScroll.getScrollY()); } else { 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) { } }
Example 4
Source File: TextProcessor.java From CodeEditor with Apache License 2.0 | 4 votes |
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); Rect bounds = new Rect(); Paint textPaint = getPaint(); String sample="A"; textPaint.getTextBounds(sample, 0, sample.length(), bounds); int width = bounds.width()/sample.length(); float x = layout.getPrimaryHorizontal(pos); float y = baseline + ascent; int offsetHorizontal = (int) x + mGutterWidth; setDropDownHorizontalOffset(offsetHorizontal); int heightVisible = getHeightVisible(); int offsetVertical = (int) ((y + mCharHeight) - getScrollY()); int tmp = offsetVertical + getDropDownHeight() + mCharHeight; //if (tmp < heightVisible) { tmp = -h + ((offsetVertical*2 / (mCharHeight)) * (mCharHeight / 2))+(mCharHeight/2); setDropDownVerticalOffset(tmp); //((Activity)(mContext)).setTitle("ov :"+offsetVertical +" ch "+mCharHeight+" tmp"+tmp +"h "+h+"p:"+pos); // } else { // tmp = offsetVertical - getDropDownHeight() - mCharHeight; // setDropDownVerticalOffset(tmp); // ((Activity)(mContext)).setTitle(" 2 tmp :"+tmp); // } // 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 + mGutterWidth; // setDropDownHorizontalOffset(offsetHorizontal); // // // int heightVisible = getHeightVisible(); // int offsetVertical = (int) ((y + mCharHeight) - getScrollY()); // // int tmp = offsetVertical + getDropDownHeight() + mCharHeight; //// if (tmp < heightVisible) { // tmp = -(offsetVertical + mCharHeight) + ((offsetVertical / mCharHeight) * (mCharHeight / 2)); // setDropDownVerticalOffset(tmp); //// } else { //// tmp = offsetVertical - getDropDownHeight() - mCharHeight; //// setDropDownVerticalOffset(tmp); //// } } } catch (Exception e) { Logger.error(TAG, e); } }