use of android.text.method.MovementMethod in project android_frameworks_base by ResurrectionRemix.
the class InputMethodService method doMovementKey.
boolean doMovementKey(int keyCode, KeyEvent event, int count) {
final ExtractEditText eet = getExtractEditTextIfVisible();
if (eet != null) {
// If we are in fullscreen mode, the cursor will move around
// the extract edit text, but should NOT cause focus to move
// to other fields.
MovementMethod movement = eet.getMovementMethod();
Layout layout = eet.getLayout();
if (movement != null && layout != null) {
// cursor will properly move in our own word wrapping.
if (count == MOVEMENT_DOWN) {
if (movement.onKeyDown(eet, eet.getText(), keyCode, event)) {
reportExtractedMovement(keyCode, 1);
return true;
}
} else if (count == MOVEMENT_UP) {
if (movement.onKeyUp(eet, eet.getText(), keyCode, event)) {
return true;
}
} else {
if (movement.onKeyOther(eet, eet.getText(), event)) {
reportExtractedMovement(keyCode, count);
} else {
KeyEvent down = KeyEvent.changeAction(event, KeyEvent.ACTION_DOWN);
if (movement.onKeyDown(eet, eet.getText(), keyCode, down)) {
KeyEvent up = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
movement.onKeyUp(eet, eet.getText(), keyCode, up);
while (--count > 0) {
movement.onKeyDown(eet, eet.getText(), keyCode, down);
movement.onKeyUp(eet, eet.getText(), keyCode, up);
}
reportExtractedMovement(keyCode, count);
}
}
}
}
// we never allow DPAD navigation to the application.
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
return true;
}
}
return false;
}
use of android.text.method.MovementMethod in project android_frameworks_base by ParanoidAndroid.
the class Editor method onFocusChanged.
void onFocusChanged(boolean focused, int direction) {
mShowCursor = SystemClock.uptimeMillis();
ensureEndedBatchEdit();
if (focused) {
int selStart = mTextView.getSelectionStart();
int selEnd = mTextView.getSelectionEnd();
// SelectAllOnFocus fields are highlighted and not selected. Do not start text selection
// mode for these, unless there was a specific selection already started.
final boolean isFocusHighlighted = mSelectAllOnFocus && selStart == 0 && selEnd == mTextView.getText().length();
mCreatedWithASelection = mFrozenWithFocus && mTextView.hasSelection() && !isFocusHighlighted;
if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
// If a tap was used to give focus to that view, move cursor at tap position.
// Has to be done before onTakeFocus, which can be overloaded.
final int lastTapPosition = getLastTapPosition();
if (lastTapPosition >= 0) {
Selection.setSelection((Spannable) mTextView.getText(), lastTapPosition);
}
// Note this may have to be moved out of the Editor class
MovementMethod mMovement = mTextView.getMovementMethod();
if (mMovement != null) {
mMovement.onTakeFocus(mTextView, (Spannable) mTextView.getText(), direction);
}
// It would be better to know why the DecorView does not have focus at that time.
if (((mTextView instanceof ExtractEditText) || mSelectionMoved) && selStart >= 0 && selEnd >= 0) {
/*
* Someone intentionally set the selection, so let them
* do whatever it is that they wanted to do instead of
* the default on-focus behavior. We reset the selection
* here instead of just skipping the onTakeFocus() call
* because some movement methods do something other than
* just setting the selection in theirs and we still
* need to go through that path.
*/
Selection.setSelection((Spannable) mTextView.getText(), selStart, selEnd);
}
if (mSelectAllOnFocus) {
mTextView.selectAllText();
}
mTouchFocusSelected = true;
}
mFrozenWithFocus = false;
mSelectionMoved = false;
if (mError != null) {
showError();
}
makeBlink();
} else {
if (mError != null) {
hideError();
}
// Don't leave us in the middle of a batch edit.
mTextView.onEndBatchEdit();
if (mTextView instanceof ExtractEditText) {
// terminateTextSelectionMode removes selection, which we want to keep when
// ExtractEditText goes out of focus.
final int selStart = mTextView.getSelectionStart();
final int selEnd = mTextView.getSelectionEnd();
hideControllers();
Selection.setSelection((Spannable) mTextView.getText(), selStart, selEnd);
} else {
if (mTemporaryDetach)
mPreserveDetachedSelection = true;
hideControllers();
if (mTemporaryDetach)
mPreserveDetachedSelection = false;
downgradeEasyCorrectionSpans();
}
// No need to create the controller
if (mSelectionModifierCursorController != null) {
mSelectionModifierCursorController.resetTouchOffsets();
}
}
}
use of android.text.method.MovementMethod in project android_frameworks_base by AOSPA.
the class Editor method onFocusChanged.
void onFocusChanged(boolean focused, int direction) {
mShowCursor = SystemClock.uptimeMillis();
ensureEndedBatchEdit();
if (focused) {
int selStart = mTextView.getSelectionStart();
int selEnd = mTextView.getSelectionEnd();
// SelectAllOnFocus fields are highlighted and not selected. Do not start text selection
// mode for these, unless there was a specific selection already started.
final boolean isFocusHighlighted = mSelectAllOnFocus && selStart == 0 && selEnd == mTextView.getText().length();
mCreatedWithASelection = mFrozenWithFocus && mTextView.hasSelection() && !isFocusHighlighted;
if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
// If a tap was used to give focus to that view, move cursor at tap position.
// Has to be done before onTakeFocus, which can be overloaded.
final int lastTapPosition = getLastTapPosition();
if (lastTapPosition >= 0) {
Selection.setSelection((Spannable) mTextView.getText(), lastTapPosition);
}
// Note this may have to be moved out of the Editor class
MovementMethod mMovement = mTextView.getMovementMethod();
if (mMovement != null) {
mMovement.onTakeFocus(mTextView, (Spannable) mTextView.getText(), direction);
}
// It would be better to know why the DecorView does not have focus at that time.
if (((mTextView.isInExtractedMode()) || mSelectionMoved) && selStart >= 0 && selEnd >= 0) {
/*
* Someone intentionally set the selection, so let them
* do whatever it is that they wanted to do instead of
* the default on-focus behavior. We reset the selection
* here instead of just skipping the onTakeFocus() call
* because some movement methods do something other than
* just setting the selection in theirs and we still
* need to go through that path.
*/
Selection.setSelection((Spannable) mTextView.getText(), selStart, selEnd);
}
if (mSelectAllOnFocus) {
mTextView.selectAllText();
}
mTouchFocusSelected = true;
}
mFrozenWithFocus = false;
mSelectionMoved = false;
if (mError != null) {
showError();
}
makeBlink();
} else {
if (mError != null) {
hideError();
}
// Don't leave us in the middle of a batch edit.
mTextView.onEndBatchEdit();
if (mTextView.isInExtractedMode()) {
hideCursorAndSpanControllers();
stopTextActionModeWithPreservingSelection();
} else {
hideCursorAndSpanControllers();
if (mTextView.isTemporarilyDetached()) {
stopTextActionModeWithPreservingSelection();
} else {
stopTextActionMode();
}
downgradeEasyCorrectionSpans();
}
// No need to create the controller
if (mSelectionModifierCursorController != null) {
mSelectionModifierCursorController.resetTouchOffsets();
}
}
}
use of android.text.method.MovementMethod in project platform_frameworks_base by android.
the class Editor method onFocusChanged.
void onFocusChanged(boolean focused, int direction) {
mShowCursor = SystemClock.uptimeMillis();
ensureEndedBatchEdit();
if (focused) {
int selStart = mTextView.getSelectionStart();
int selEnd = mTextView.getSelectionEnd();
// SelectAllOnFocus fields are highlighted and not selected. Do not start text selection
// mode for these, unless there was a specific selection already started.
final boolean isFocusHighlighted = mSelectAllOnFocus && selStart == 0 && selEnd == mTextView.getText().length();
mCreatedWithASelection = mFrozenWithFocus && mTextView.hasSelection() && !isFocusHighlighted;
if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
// If a tap was used to give focus to that view, move cursor at tap position.
// Has to be done before onTakeFocus, which can be overloaded.
final int lastTapPosition = getLastTapPosition();
if (lastTapPosition >= 0) {
Selection.setSelection((Spannable) mTextView.getText(), lastTapPosition);
}
// Note this may have to be moved out of the Editor class
MovementMethod mMovement = mTextView.getMovementMethod();
if (mMovement != null) {
mMovement.onTakeFocus(mTextView, (Spannable) mTextView.getText(), direction);
}
// It would be better to know why the DecorView does not have focus at that time.
if (((mTextView.isInExtractedMode()) || mSelectionMoved) && selStart >= 0 && selEnd >= 0) {
/*
* Someone intentionally set the selection, so let them
* do whatever it is that they wanted to do instead of
* the default on-focus behavior. We reset the selection
* here instead of just skipping the onTakeFocus() call
* because some movement methods do something other than
* just setting the selection in theirs and we still
* need to go through that path.
*/
Selection.setSelection((Spannable) mTextView.getText(), selStart, selEnd);
}
if (mSelectAllOnFocus) {
mTextView.selectAllText();
}
mTouchFocusSelected = true;
}
mFrozenWithFocus = false;
mSelectionMoved = false;
if (mError != null) {
showError();
}
makeBlink();
} else {
if (mError != null) {
hideError();
}
// Don't leave us in the middle of a batch edit.
mTextView.onEndBatchEdit();
if (mTextView.isInExtractedMode()) {
hideCursorAndSpanControllers();
stopTextActionModeWithPreservingSelection();
} else {
hideCursorAndSpanControllers();
if (mTextView.isTemporarilyDetached()) {
stopTextActionModeWithPreservingSelection();
} else {
stopTextActionMode();
}
downgradeEasyCorrectionSpans();
}
// No need to create the controller
if (mSelectionModifierCursorController != null) {
mSelectionModifierCursorController.resetTouchOffsets();
}
}
}
use of android.text.method.MovementMethod in project android_frameworks_base by DirtyUnicorns.
the class InputMethodService method doMovementKey.
boolean doMovementKey(int keyCode, KeyEvent event, int count) {
final ExtractEditText eet = getExtractEditTextIfVisible();
if (eet != null) {
// If we are in fullscreen mode, the cursor will move around
// the extract edit text, but should NOT cause focus to move
// to other fields.
MovementMethod movement = eet.getMovementMethod();
Layout layout = eet.getLayout();
if (movement != null && layout != null) {
// cursor will properly move in our own word wrapping.
if (count == MOVEMENT_DOWN) {
if (movement.onKeyDown(eet, eet.getText(), keyCode, event)) {
reportExtractedMovement(keyCode, 1);
return true;
}
} else if (count == MOVEMENT_UP) {
if (movement.onKeyUp(eet, eet.getText(), keyCode, event)) {
return true;
}
} else {
if (movement.onKeyOther(eet, eet.getText(), event)) {
reportExtractedMovement(keyCode, count);
} else {
KeyEvent down = KeyEvent.changeAction(event, KeyEvent.ACTION_DOWN);
if (movement.onKeyDown(eet, eet.getText(), keyCode, down)) {
KeyEvent up = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
movement.onKeyUp(eet, eet.getText(), keyCode, up);
while (--count > 0) {
movement.onKeyDown(eet, eet.getText(), keyCode, down);
movement.onKeyUp(eet, eet.getText(), keyCode, up);
}
reportExtractedMovement(keyCode, count);
}
}
}
}
// we never allow DPAD navigation to the application.
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
return true;
}
}
return false;
}
Aggregations