Skip to content

Commit 405bc51

Browse files
author
Jean Chalard
committed
Add/refine comments to reflect key event policies
Make clearer how the platform is handling key events following some unfortunate uses by third party applications. Also highlight the changes in Jelly Bean default keyboard. Bug: 6566711 Change-Id: Ibcdaf54c6d629fd0733529bfe2fffc82f555f084
1 parent c3a5cf9 commit 405bc51

17 files changed

+119
-14
lines changed

core/java/android/inputmethodservice/InputMethodService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,13 @@ boolean doMovementKey(int keyCode, KeyEvent event, int count) {
18921892
* {@link KeyEvent#FLAG_KEEP_TOUCH_MODE KeyEvent.FLAG_KEEP_TOUCH_MODE}, so
18931893
* that they don't impact the current touch mode of the UI.
18941894
*
1895+
* <p>Note that it's discouraged to send such key events in normal operation;
1896+
* this is mainly for use with {@link android.text.InputType#TYPE_NULL} type
1897+
* text fields, or for non-rich input methods. A reasonably capable software
1898+
* input method should use the
1899+
* {@link android.view.inputmethod.InputConnection#commitText} family of methods
1900+
* to send text to an application, rather than sending key events.</p>
1901+
*
18951902
* @param keyEventCode The raw key code to send, as defined by
18961903
* {@link KeyEvent}.
18971904
*/
@@ -1949,7 +1956,11 @@ public boolean sendDefaultEditorAction(boolean fromEnterKey) {
19491956
* {@link InputConnection#commitText InputConnection.commitText()} with
19501957
* the character; some, however, may be handled different. In particular,
19511958
* the enter character ('\n') will either be delivered as an action code
1952-
* or a raw key event, as appropriate.
1959+
* or a raw key event, as appropriate. Consider this as a convenience
1960+
* method for IMEs that do not have a full implementation of actions; a
1961+
* fully complying IME will decide of the right action for each event and
1962+
* will likely never call this method except maybe to handle events coming
1963+
* from an actual hardware keyboard.
19531964
*
19541965
* @param charCode The UTF-16 character code to send.
19551966
*/

core/java/android/text/method/BaseKeyListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
* Provides a basic foundation for entering and editing text.
2929
* Subclasses should override {@link #onKeyDown} and {@link #onKeyUp} to insert
3030
* characters as keys are pressed.
31+
* <p></p>
32+
* As for all implementations of {@link KeyListener}, this class is only concerned
33+
* with hardware keyboards. Software input methods have no obligation to trigger
34+
* the methods in this class.
3135
*/
3236
public abstract class BaseKeyListener extends MetaKeyKeyListener
3337
implements KeyListener {

core/java/android/text/method/DateKeyListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
/**
2323
* For entering dates in a text field.
24+
* <p></p>
25+
* As for all implementations of {@link KeyListener}, this class is only concerned
26+
* with hardware keyboards. Software input methods have no obligation to trigger
27+
* the methods in this class.
2428
*/
2529
public class DateKeyListener extends NumberKeyListener
2630
{

core/java/android/text/method/DateTimeKeyListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
/**
2323
* For entering dates and times in the same text field.
24+
* <p></p>
25+
* As for all implementations of {@link KeyListener}, this class is only concerned
26+
* with hardware keyboards. Software input methods have no obligation to trigger
27+
* the methods in this class.
2428
*/
2529
public class DateTimeKeyListener extends NumberKeyListener
2630
{

core/java/android/text/method/DialerKeyListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
/**
2525
* For dialing-only text entry
26+
* <p></p>
27+
* As for all implementations of {@link KeyListener}, this class is only concerned
28+
* with hardware keyboards. Software input methods have no obligation to trigger
29+
* the methods in this class.
2630
*/
2731
public class DialerKeyListener extends NumberKeyListener
2832
{

core/java/android/text/method/DigitsKeyListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
/**
2626
* For digits-only text entry
27+
* <p></p>
28+
* As for all implementations of {@link KeyListener}, this class is only concerned
29+
* with hardware keyboards. Software input methods have no obligation to trigger
30+
* the methods in this class.
2731
*/
2832
public class DigitsKeyListener extends NumberKeyListener
2933
{

core/java/android/text/method/KeyListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
* {@link android.view.inputmethod.InputMethod}; it should only be used
2828
* for cases where an application has its own on-screen keypad and also wants
2929
* to process hard keyboard events to match it.
30+
* <p></p>
31+
* Key presses on soft input methods are not required to trigger the methods
32+
* in this listener, and are in fact discouraged to do so. The default
33+
* android keyboard will not trigger these for any key to any application
34+
* targetting Jelly Bean or later, and will only deliver it for some
35+
* key presses to applications targetting Ice Cream Sandwich or earlier.
3036
*/
3137
public interface KeyListener {
3238
/**

core/java/android/text/method/MultiTapKeyListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
* This is the standard key listener for alphabetic input on 12-key
2929
* keyboards. You should generally not need to instantiate this yourself;
3030
* TextKeyListener will do it for you.
31+
* <p></p>
32+
* As for all implementations of {@link KeyListener}, this class is only concerned
33+
* with hardware keyboards. Software input methods have no obligation to trigger
34+
* the methods in this class.
3135
*/
3236
public class MultiTapKeyListener extends BaseKeyListener
3337
implements SpanWatcher {

core/java/android/text/method/NumberKeyListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
/**
2929
* For numeric text entry
30+
* <p></p>
31+
* As for all implementations of {@link KeyListener}, this class is only concerned
32+
* with hardware keyboards. Software input methods have no obligation to trigger
33+
* the methods in this class.
3034
*/
3135
public abstract class NumberKeyListener extends BaseKeyListener
3236
implements InputFilter

core/java/android/text/method/QwertyKeyListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
* This is the standard key listener for alphabetic input on qwerty
2828
* keyboards. You should generally not need to instantiate this yourself;
2929
* TextKeyListener will do it for you.
30+
* <p></p>
31+
* As for all implementations of {@link KeyListener}, this class is only concerned
32+
* with hardware keyboards. Software input methods have no obligation to trigger
33+
* the methods in this class.
3034
*/
3135
public class QwertyKeyListener extends BaseKeyListener {
3236
private static QwertyKeyListener[] sInstance =

0 commit comments

Comments
 (0)