diff options
| author | Yohei Yukawa <yukawa@google.com> | 2015-06-24 00:20:24 -0700 |
|---|---|---|
| committer | Yohei Yukawa <yukawa@google.com> | 2015-06-24 00:20:24 -0700 |
| commit | 38940aab693be587d5901f4ef110cbf95da0e22f (patch) | |
| tree | 13bccaa3aa3a8d942fa51e9821b6fa7f0d9aa986 /core/java/android/inputmethodservice/InputMethodService.java | |
| parent | ddfe5d573ec002843324694c2bed723acf1d293e (diff) | |
Handle back key to cancel text action mode in full-screen IME.
This CL is a follow up to I7998c8ee2162a0e01525a0cd66ec14fa505,
which completely removed ExtractActionMode including back key
handling in InputMethodService when full-screen mode is enabled.
It turns out that back key events still need to be handled in
InputMethodService when full-screen mode is enabled so that
users can still cancel floating text action mode with back key.
Bug: 22034992
Change-Id: I5f8db34f7425eef343d40d9820925ea6aaf9fccc
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index ae74b9aaed8b..ff7a300cbf92 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -1819,7 +1819,18 @@ public class InputMethodService extends AbstractInputMethodService { } return false; } - + + /** + * @return {#link ExtractEditText} if it is considered to be visible and active. Otherwise + * {@code null} is returned. + */ + private ExtractEditText getExtractEditTextIfVisible() { + if (!isExtractViewShown() || !isInputViewShown()) { + return null; + } + return mExtractEditText; + } + /** * Override this to intercept key down events before they are processed by the * application. If you return true, the application will not @@ -1835,6 +1846,10 @@ public class InputMethodService extends AbstractInputMethodService { */ public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { + final ExtractEditText eet = getExtractEditTextIfVisible(); + if (eet != null && eet.handleBackInTextActionModeIfNeeded(event)) { + return true; + } if (handleBack(false)) { event.startTracking(); return true; @@ -1882,11 +1897,15 @@ public class InputMethodService extends AbstractInputMethodService { * them to perform navigation in the underlying application. */ public boolean onKeyUp(int keyCode, KeyEvent event) { - if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.isTracking() - && !event.isCanceled()) { - return handleBack(true); + if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { + final ExtractEditText eet = getExtractEditTextIfVisible(); + if (eet != null && eet.handleBackInTextActionModeIfNeeded(event)) { + return true; + } + if (event.isTracking() && !event.isCanceled()) { + return handleBack(true); + } } - return doMovementKey(keyCode, event, MOVEMENT_UP); } @@ -1952,10 +1971,10 @@ public class InputMethodService extends AbstractInputMethodService { } onExtractedCursorMovement(dx, dy); } - + boolean doMovementKey(int keyCode, KeyEvent event, int count) { - final ExtractEditText eet = mExtractEditText; - if (isExtractViewShown() && isInputViewShown() && eet != null) { + 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. @@ -2006,7 +2025,7 @@ public class InputMethodService extends AbstractInputMethodService { return true; } } - + return false; } |
