/** * @return the Layout that is currently being used to display the text. * This can be null if the text or width has recently changes. */ public final Layout getLayout (){ return mInputView.getLayout(); }
public int getCurrentCursorLine(EditText editText) { int selectionStart = Selection.getSelectionStart(editText.getText()); Layout layout = editText.getLayout(); if (!(selectionStart == -1)) { return layout.getLineForOffset(selectionStart); } return -1; }
public int getCurrentCursorLine(EditText editText) { int selectionStart = Selection.getSelectionStart(editText.getText()); Layout layout = editText.getLayout(); if (selectionStart != -1) { return layout.getLineForOffset(selectionStart); } return -1; }
public int getCurrentCursorLine(EditText editText) { int selectionStart = Selection.getSelectionStart(editText.getText()); Layout layout = editText.getLayout(); if (!(selectionStart == -1)) { return layout.getLineForOffset(selectionStart); } return -1; }
@Override public boolean onQueryTextSubmit(String query) { // Find next text if (matcher.find()) { // Get index index = matcher.start(); // Get text position int line = textView.getLayout().getLineForOffset(index); int pos = textView.getLayout().getLineBaseline(line); // Scroll to it scrollView.smoothScrollTo(0, pos - height / 2); // Highlight it editable.setSpan(span, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { matcher.reset(); index = 0; } return true; } }
int endOfFirstLine = editText.getLayout().getLineEnd(0)-1;
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mCustomKeyboardView.setVisibility(View.VISIBLE); mCustomKeyboardView.setEnabled(true); Layout layout = ((EditText) v).getLayout(); float x = event.getX() + mSearchEditText.getScrollX(); int offset = layout.getOffsetForHorizontal(0, x); if (offset > 0) if (x > layout.getLineMax(0)) mSearchEditText.setSelection(offset); // Touch was at the end of the text else mSearchEditText.setSelection(offset - 1); break; case MotionEvent.ACTION_MOVE: layout = ((EditText) v).getLayout(); x = event.getX() + mSearchEditText.getScrollX(); offset = layout.getOffsetForHorizontal(0, x); if (offset > 0) if (x > layout.getLineMax(0)) mSearchEditText.setSelection(offset); // Touch point was at the end of the text else mSearchEditText.setSelection(offset - 1); break; } return true; } };
case MotionEvent.ACTION_MOVE: EditText editText = (EditText) view; Layout layout = ((EditText) view).getLayout(); if (layout != null) { float x = event.getX() + editText.getScrollX();
@Override public void setBounds(int left, int top, int right, int bottom) { int pos = mEditText.getSelectionStart(); Layout layout = mEditText.getLayout(); int cursorLine = layout.getLineForOffset(pos); int lineCount = mEditText.getLineCount(); int heightVary = cursorLine != lineCount - 1 ? mNormalLineHeightVary : mLastLineHeightVary; super.setBounds(left, top, right, bottom + heightVary); } }
public static int getCursorY(EditText et) { int pos = et.getSelectionStart(); Layout layout = et.getLayout(); int line = layout.getLineForOffset(pos); int baseline = layout.getLineBaseline(line); int ascent = layout.getLineAscent(line); return baseline + ascent; } }
@Override public boolean onLongClick(View v) { final Layout layout = editText.getLayout(); final int line = layout.getLineForOffset(editText.getSelectionStart()); final int start = layout.getLineStart(line);
y += et.getScrollY(); Layout layout = et.getLayout(); int line = layout.getLineForVertical(y); int offset = layout.getOffsetForHorizontal(line, x);