Methods Summary |
---|
protected boolean | bottom(android.widget.TextView widget, android.text.Spannable buffer)Performs a bottom movement action.
Moves the cursor or scrolls to the bottom of the buffer.
return false;
|
public boolean | canSelectArbitrarily()
return false;
|
protected boolean | down(android.widget.TextView widget, android.text.Spannable buffer)Performs a down movement action.
Moves the cursor or scrolls down by one line.
return false;
|
protected boolean | end(android.widget.TextView widget, android.text.Spannable buffer)Performs an end movement action.
Moves the cursor or scrolls to the start of the line or to the top of the
document depending on whether the insertion point is being moved or
the document is being scrolled.
return false;
|
private int | getBottomLine(android.widget.TextView widget)
return widget.getLayout().getLineForVertical(widget.getScrollY() + getInnerHeight(widget));
|
private int | getCharacterWidth(android.widget.TextView widget)
return (int) Math.ceil(widget.getPaint().getFontSpacing());
|
private int | getInnerHeight(android.widget.TextView widget)
return widget.getHeight() - widget.getTotalPaddingTop() - widget.getTotalPaddingBottom();
|
private int | getInnerWidth(android.widget.TextView widget)
return widget.getWidth() - widget.getTotalPaddingLeft() - widget.getTotalPaddingRight();
|
protected int | getMovementMetaState(android.text.Spannable buffer, android.view.KeyEvent event)Gets the meta state used for movement using the modifiers tracked by the text
buffer as well as those present in the key event.
The movement meta state excludes the state of locked modifiers or the SHIFT key
since they are not used by movement actions (but they may be used for selection).
// We ignore locked modifiers and SHIFT.
int metaState = MetaKeyKeyListener.getMetaState(buffer, event)
& ~(MetaKeyKeyListener.META_ALT_LOCKED | MetaKeyKeyListener.META_SYM_LOCKED);
return KeyEvent.normalizeMetaState(metaState) & ~KeyEvent.META_SHIFT_MASK;
|
private int | getScrollBoundsLeft(android.widget.TextView widget)
final Layout layout = widget.getLayout();
final int topLine = getTopLine(widget);
final int bottomLine = getBottomLine(widget);
if (topLine > bottomLine) {
return 0;
}
int left = Integer.MAX_VALUE;
for (int line = topLine; line <= bottomLine; line++) {
final int lineLeft = (int) Math.floor(layout.getLineLeft(line));
if (lineLeft < left) {
left = lineLeft;
}
}
return left;
|
private int | getScrollBoundsRight(android.widget.TextView widget)
final Layout layout = widget.getLayout();
final int topLine = getTopLine(widget);
final int bottomLine = getBottomLine(widget);
if (topLine > bottomLine) {
return 0;
}
int right = Integer.MIN_VALUE;
for (int line = topLine; line <= bottomLine; line++) {
final int lineRight = (int) Math.ceil(layout.getLineRight(line));
if (lineRight > right) {
right = lineRight;
}
}
return right;
|
private int | getTopLine(android.widget.TextView widget)
return widget.getLayout().getLineForVertical(widget.getScrollY());
|
protected boolean | handleMovementKey(android.widget.TextView widget, android.text.Spannable buffer, int keyCode, int movementMetaState, android.view.KeyEvent event)Performs a movement key action.
The default implementation decodes the key down and invokes movement actions
such as {@link #down} and {@link #up}.
{@link #onKeyDown(TextView, Spannable, int, KeyEvent)} calls this method once
to handle an {@link KeyEvent#ACTION_DOWN}.
{@link #onKeyOther(TextView, Spannable, KeyEvent)} calls this method repeatedly
to handle each repetition of an {@link KeyEvent#ACTION_MULTIPLE}.
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
return left(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_CTRL_ON)) {
return leftWord(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_ALT_ON)) {
return lineStart(widget, buffer);
}
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
return right(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_CTRL_ON)) {
return rightWord(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_ALT_ON)) {
return lineEnd(widget, buffer);
}
break;
case KeyEvent.KEYCODE_DPAD_UP:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
return up(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_ALT_ON)) {
return top(widget, buffer);
}
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
return down(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_ALT_ON)) {
return bottom(widget, buffer);
}
break;
case KeyEvent.KEYCODE_PAGE_UP:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
return pageUp(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_ALT_ON)) {
return top(widget, buffer);
}
break;
case KeyEvent.KEYCODE_PAGE_DOWN:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
return pageDown(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_ALT_ON)) {
return bottom(widget, buffer);
}
break;
case KeyEvent.KEYCODE_MOVE_HOME:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
return home(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_CTRL_ON)) {
return top(widget, buffer);
}
break;
case KeyEvent.KEYCODE_MOVE_END:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
return end(widget, buffer);
} else if (KeyEvent.metaStateHasModifiers(movementMetaState,
KeyEvent.META_CTRL_ON)) {
return bottom(widget, buffer);
}
break;
}
return false;
|
protected boolean | home(android.widget.TextView widget, android.text.Spannable buffer)Performs a home movement action.
Moves the cursor or scrolls to the start of the line or to the top of the
document depending on whether the insertion point is being moved or
the document is being scrolled.
return false;
|
public void | initialize(android.widget.TextView widget, android.text.Spannable text)
|
protected boolean | left(android.widget.TextView widget, android.text.Spannable buffer)Performs a left movement action.
Moves the cursor or scrolls left by one character.
return false;
|
protected boolean | leftWord(android.widget.TextView widget, android.text.Spannable buffer){@hide}
return false;
|
protected boolean | lineEnd(android.widget.TextView widget, android.text.Spannable buffer)Performs a line-end movement action.
Moves the cursor or scrolls to the end of the line.
return false;
|
protected boolean | lineStart(android.widget.TextView widget, android.text.Spannable buffer)Performs a line-start movement action.
Moves the cursor or scrolls to the start of the line.
return false;
|
public boolean | onGenericMotionEvent(android.widget.TextView widget, android.text.Spannable text, android.view.MotionEvent event)
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL: {
final float vscroll;
final float hscroll;
if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
vscroll = 0;
hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
} else {
vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
}
boolean handled = false;
if (hscroll < 0) {
handled |= scrollLeft(widget, text, (int)Math.ceil(-hscroll));
} else if (hscroll > 0) {
handled |= scrollRight(widget, text, (int)Math.ceil(hscroll));
}
if (vscroll < 0) {
handled |= scrollUp(widget, text, (int)Math.ceil(-vscroll));
} else if (vscroll > 0) {
handled |= scrollDown(widget, text, (int)Math.ceil(vscroll));
}
return handled;
}
}
}
return false;
|
public boolean | onKeyDown(android.widget.TextView widget, android.text.Spannable text, int keyCode, android.view.KeyEvent event)
final int movementMetaState = getMovementMetaState(text, event);
boolean handled = handleMovementKey(widget, text, keyCode, movementMetaState, event);
if (handled) {
MetaKeyKeyListener.adjustMetaAfterKeypress(text);
MetaKeyKeyListener.resetLockedMeta(text);
}
return handled;
|
public boolean | onKeyOther(android.widget.TextView widget, android.text.Spannable text, android.view.KeyEvent event)
final int movementMetaState = getMovementMetaState(text, event);
final int keyCode = event.getKeyCode();
if (keyCode != KeyEvent.KEYCODE_UNKNOWN
&& event.getAction() == KeyEvent.ACTION_MULTIPLE) {
final int repeat = event.getRepeatCount();
boolean handled = false;
for (int i = 0; i < repeat; i++) {
if (!handleMovementKey(widget, text, keyCode, movementMetaState, event)) {
break;
}
handled = true;
}
if (handled) {
MetaKeyKeyListener.adjustMetaAfterKeypress(text);
MetaKeyKeyListener.resetLockedMeta(text);
}
return handled;
}
return false;
|
public boolean | onKeyUp(android.widget.TextView widget, android.text.Spannable text, int keyCode, android.view.KeyEvent event)
return false;
|
public void | onTakeFocus(android.widget.TextView widget, android.text.Spannable text, int direction)
|
public boolean | onTouchEvent(android.widget.TextView widget, android.text.Spannable text, android.view.MotionEvent event)
return false;
|
public boolean | onTrackballEvent(android.widget.TextView widget, android.text.Spannable text, android.view.MotionEvent event)
return false;
|
protected boolean | pageDown(android.widget.TextView widget, android.text.Spannable buffer)Performs a page-down movement action.
Moves the cursor or scrolls down by one page.
return false;
|
protected boolean | pageUp(android.widget.TextView widget, android.text.Spannable buffer)Performs a page-up movement action.
Moves the cursor or scrolls up by one page.
return false;
|
protected boolean | right(android.widget.TextView widget, android.text.Spannable buffer)Performs a right movement action.
Moves the cursor or scrolls right by one character.
return false;
|
protected boolean | rightWord(android.widget.TextView widget, android.text.Spannable buffer){@hide}
return false;
|
protected boolean | scrollBottom(android.widget.TextView widget, android.text.Spannable buffer)Performs a scroll to bottom action.
Scrolls to the bottom of the document.
final Layout layout = widget.getLayout();
final int lineCount = layout.getLineCount();
if (getBottomLine(widget) <= lineCount - 1) {
Touch.scrollTo(widget, layout, widget.getScrollX(),
layout.getLineTop(lineCount) - getInnerHeight(widget));
return true;
}
return false;
|
protected boolean | scrollDown(android.widget.TextView widget, android.text.Spannable buffer, int amount)Performs a scroll down action.
Scrolls down by the specified number of lines.
final Layout layout = widget.getLayout();
final int innerHeight = getInnerHeight(widget);
final int bottom = widget.getScrollY() + innerHeight;
int bottomLine = layout.getLineForVertical(bottom);
if (layout.getLineTop(bottomLine + 1) < bottom + 1) {
// Less than a pixel of this line is out of view,
// so we must have tried to make it entirely in view
// and now want the next line to be in view instead.
bottomLine += 1;
}
final int limit = layout.getLineCount() - 1;
if (bottomLine <= limit) {
bottomLine = Math.min(bottomLine + amount - 1, limit);
Touch.scrollTo(widget, layout, widget.getScrollX(),
layout.getLineTop(bottomLine + 1) - innerHeight);
return true;
}
return false;
|
protected boolean | scrollLeft(android.widget.TextView widget, android.text.Spannable buffer, int amount)Performs a scroll left action.
Scrolls left by the specified number of characters.
final int minScrollX = getScrollBoundsLeft(widget);
int scrollX = widget.getScrollX();
if (scrollX > minScrollX) {
scrollX = Math.max(scrollX - getCharacterWidth(widget) * amount, minScrollX);
widget.scrollTo(scrollX, widget.getScrollY());
return true;
}
return false;
|
protected boolean | scrollLineEnd(android.widget.TextView widget, android.text.Spannable buffer)Performs a scroll to line end action.
Scrolls to the end of the line.
final int maxScrollX = getScrollBoundsRight(widget) - getInnerWidth(widget);
int scrollX = widget.getScrollX();
if (scrollX < maxScrollX) {
widget.scrollTo(maxScrollX, widget.getScrollY());
return true;
}
return false;
|
protected boolean | scrollLineStart(android.widget.TextView widget, android.text.Spannable buffer)Performs a scroll to line start action.
Scrolls to the start of the line.
final int minScrollX = getScrollBoundsLeft(widget);
int scrollX = widget.getScrollX();
if (scrollX > minScrollX) {
widget.scrollTo(minScrollX, widget.getScrollY());
return true;
}
return false;
|
protected boolean | scrollPageDown(android.widget.TextView widget, android.text.Spannable buffer)Performs a scroll page up action.
Scrolls down by one page.
final Layout layout = widget.getLayout();
final int innerHeight = getInnerHeight(widget);
final int bottom = widget.getScrollY() + innerHeight + innerHeight;
int bottomLine = layout.getLineForVertical(bottom);
if (bottomLine <= layout.getLineCount() - 1) {
Touch.scrollTo(widget, layout, widget.getScrollX(),
layout.getLineTop(bottomLine + 1) - innerHeight);
return true;
}
return false;
|
protected boolean | scrollPageUp(android.widget.TextView widget, android.text.Spannable buffer)Performs a scroll page up action.
Scrolls up by one page.
final Layout layout = widget.getLayout();
final int top = widget.getScrollY() - getInnerHeight(widget);
int topLine = layout.getLineForVertical(top);
if (topLine >= 0) {
Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop(topLine));
return true;
}
return false;
|
protected boolean | scrollRight(android.widget.TextView widget, android.text.Spannable buffer, int amount)Performs a scroll right action.
Scrolls right by the specified number of characters.
final int maxScrollX = getScrollBoundsRight(widget) - getInnerWidth(widget);
int scrollX = widget.getScrollX();
if (scrollX < maxScrollX) {
scrollX = Math.min(scrollX + getCharacterWidth(widget) * amount, maxScrollX);
widget.scrollTo(scrollX, widget.getScrollY());
return true;
}
return false;
|
protected boolean | scrollTop(android.widget.TextView widget, android.text.Spannable buffer)Performs a scroll to top action.
Scrolls to the top of the document.
final Layout layout = widget.getLayout();
if (getTopLine(widget) >= 0) {
Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop(0));
return true;
}
return false;
|
protected boolean | scrollUp(android.widget.TextView widget, android.text.Spannable buffer, int amount)Performs a scroll up action.
Scrolls up by the specified number of lines.
final Layout layout = widget.getLayout();
final int top = widget.getScrollY();
int topLine = layout.getLineForVertical(top);
if (layout.getLineTop(topLine) == top) {
// If the top line is partially visible, bring it all the way
// into view; otherwise, bring the previous line into view.
topLine -= 1;
}
if (topLine >= 0) {
topLine = Math.max(topLine - amount + 1, 0);
Touch.scrollTo(widget, layout, widget.getScrollX(), layout.getLineTop(topLine));
return true;
}
return false;
|
protected boolean | top(android.widget.TextView widget, android.text.Spannable buffer)Performs a top movement action.
Moves the cursor or scrolls to the top of the buffer.
return false;
|
protected boolean | up(android.widget.TextView widget, android.text.Spannable buffer)Performs an up movement action.
Moves the cursor or scrolls up by one line.
return false;
|