Java Code Examples for android.text.StaticLayout#getLineForOffset()
The following examples show how to use
android.text.StaticLayout#getLineForOffset() .
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 | 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 2
Source File: TextSelectionHint.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private void drawSelection(Canvas canvas, StaticLayout layout, int selectionStart, int selectionEnd) { int startLine = layout.getLineForOffset(selectionStart); int endLine = layout.getLineForOffset(selectionEnd); int startX = (int) layout.getPrimaryHorizontal(selectionStart); int endX = (int) layout.getPrimaryHorizontal(selectionEnd); if (startLine == endLine) { canvas.drawRect(startX, layout.getLineTop(startLine), endX, layout.getLineBottom(startLine), selectionPaint); } else { canvas.drawRect(startX, layout.getLineTop(startLine), layout.getLineWidth(startLine), layout.getLineBottom(startLine), selectionPaint); canvas.drawRect(0, layout.getLineTop(endLine), endX, layout.getLineBottom(endLine), selectionPaint); for (int i = startLine + 1; i < endLine; i++) { canvas.drawRect(0, layout.getLineTop(i), layout.getLineWidth(i), layout.getLineBottom(i), selectionPaint); } } }
Example 3
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 4
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 5
Source File: TextSelectionHint.java From Telegram with GNU General Public License v2.0 | 5 votes |
private void drawSelection(Canvas canvas, StaticLayout layout, int selectionStart, int selectionEnd) { int startLine = layout.getLineForOffset(selectionStart); int endLine = layout.getLineForOffset(selectionEnd); int startX = (int) layout.getPrimaryHorizontal(selectionStart); int endX = (int) layout.getPrimaryHorizontal(selectionEnd); if (startLine == endLine) { canvas.drawRect(startX, layout.getLineTop(startLine), endX, layout.getLineBottom(startLine), selectionPaint); } else { canvas.drawRect(startX, layout.getLineTop(startLine), layout.getLineWidth(startLine), layout.getLineBottom(startLine), selectionPaint); canvas.drawRect(0, layout.getLineTop(endLine), endX, layout.getLineBottom(endLine), selectionPaint); for (int i = startLine + 1; i < endLine; i++) { canvas.drawRect(0, layout.getLineTop(i), layout.getLineWidth(i), layout.getLineBottom(i), selectionPaint); } } }
Example 6
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 7
Source File: LinkPath.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public void setCurrentLayout(StaticLayout layout, int start, float yOffset) { currentLayout = layout; currentLine = layout.getLineForOffset(start); lastTop = -1; heightOffset = yOffset; }
Example 8
Source File: LinkPath.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public void setCurrentLayout(StaticLayout layout, int start, float yOffset) { currentLayout = layout; currentLine = layout.getLineForOffset(start); lastTop = -1; heightOffset = yOffset; }