Class KeyboardManager
- java.lang.Object
-
- io.flutter.embedding.android.KeyboardManager
-
public class KeyboardManager extends Object
A class to processKeyEvents dispatched to aFlutterView, either from a hardware keyboard or an IME event.A class that sends Android
KeyEventto the a list ofKeyboardManager.Responders, and re-dispatches those not handled by the primary responders.Flutter uses asynchronous event handling to avoid blocking the UI thread, but Android requires that events are handled synchronously. So, when the Android system sends new @{link KeyEvent} to Flutter, Flutter responds synchronously that the key has been handled so that it won't propagate to other components. It then uses "delayed event synthesis", where it sends the event to the framework, and if the framework responds that it has not handled the event, then this class synthesizes a new event to send to Android, without handling it this time.
A new
KeyEventsent to aKeyboardManagercan be propagated to 3 different types of responders (in the listed order):KeyboardManager.Responders: An immutable list of key responders in aKeyboardManagerthat each implements theKeyboardManager.Responderinterface. AKeyboardManager.Responderis a key responder that's capable of handlingKeyEvents asynchronously.When a new
KeyEventis received,KeyboardManagercalls theKeyboardManager.Responder.handleEvent(KeyEvent, OnKeyEventHandledCallback)method on itsKeyboardManager.Responders. EachKeyboardManager.Respondermust call the suppliedKeyboardManager.Responder.OnKeyEventHandledCallbackexactly once, when it has decided whether to handle the key event callback. More than oneKeyboardManager.Responderis allowed to reply true and handle the sameKeyEvent.Typically a
KeyboardManageruses aKeyChannelResponderas its onlyKeyboardManager.Responder.TextInputPlugin: if everyKeyboardManager.Responderhas replied false to aKeyEvent, or if theKeyboardManagerhas zeroKeyboardManager.Responders, theKeyEventwill be sent to the currently focused editable text field inTextInputPlugin, if any.- "Redispatch": if there's no currently focused text field in
TextInputPlugin, or the text field does not handle theKeyEventeither, theKeyEventwill be sent back to the top of the activity's view hierachy, allowing it to be "redispatched", only this time theKeyboardManagerwill not try to handle the redispatchedKeyEvent.
-
-
Field Summary
Fields Modifier and Type Field Description protected io.flutter.embedding.android.KeyboardManager.Responder[]responders
-
Constructor Summary
Constructors Constructor Description KeyboardManager(View view, TextInputPlugin textInputPlugin, io.flutter.embedding.android.KeyboardManager.Responder[] responders)Constructor forKeyboardManagerthat takes a list ofKeyboardManager.Responders.
-
-
-
Constructor Detail
-
KeyboardManager
public KeyboardManager(@NonNull View view, @NonNull TextInputPlugin textInputPlugin, @NonNull io.flutter.embedding.android.KeyboardManager.Responder[] responders)Constructor forKeyboardManagerthat takes a list ofKeyboardManager.Responders.The view is used as the destination to send the synthesized key to. This means that the next thing in the focus chain will get the event when the
KeyboardManager.Responders return false from onKeyDown/onKeyUp.It is possible that that in the middle of the async round trip, the focus chain could change, and instead of the native widget that was "next" when the event was fired getting the event, it may be the next widget when the event is synthesized that gets it. In practice, this shouldn't be a huge problem, as this is an unlikely occurrence to happen without user input, and it may actually be desired behavior, but it is possible.
- Parameters:
view- takes the activity to use for re-dispatching of events that were not handled by the framework.textInputPlugin- a plugin, which, if set, is given key events before the framework is, and if it has a valid input connection and is accepting text, then it will handle the event and the framework will not receive it.responders- theKeyboardManager.Responders newKeyEvents will be first dispatched to.
-
-
Method Detail
-
handleEvent
public boolean handleEvent(@NonNull KeyEvent keyEvent)
-
destroy
public void destroy()
-
-