io.flutter.embedding.android

## Class AndroidKeyProcessor

- java.lang.Object
- - io.flutter.embedding.android.AndroidKeyProcessor

-     public class AndroidKeyProcessor
      extends Object

  A class to process key events from Android, passing them to the framework as messages using `KeyEventChannel`.

  A class that sends Android key events to the framework, and re-dispatches those not handled by the framework.

  Flutter uses asynchronous event handling to avoid blocking the UI thread, but Android requires that events are handled synchronously. So, when a key event is received by Flutter, it tells Android synchronously that the key has been handled so that it won't propagate to other components. Flutter 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.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AndroidKeyProcessor(View view, KeyEventChannel keyEventChannel, TextInputPlugin textInputPlugin)` Constructor for AndroidKeyProcessor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `destroy()` Detaches the key processor from the Flutter engine.
    `boolean` | `isPendingEvent(KeyEvent event)` Returns whether or not the given event is currently being processed by this key processor.
    `boolean` | `onKeyEvent(KeyEvent keyEvent)` Called when a key event is received by the `FlutterView` or the `InputConnectionAdaptor`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AndroidKeyProcessor

          public AndroidKeyProcessor(@NonNull
                                     View view,
                                     @NonNull
                                     KeyEventChannel keyEventChannel,
                                     @NonNull
                                     TextInputPlugin textInputPlugin)

      Constructor for AndroidKeyProcessor.

      The view is used as the destination to send the synthesized key to. This means that the the next thing in the focus chain will get the event when the framework returns 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.
        `keyEventChannel` - the event channel to listen to for new key events.
        `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.

  - ### Method Detail

    - #### destroy

          public void destroy()

      Detaches the key processor from the Flutter engine.

      The AndroidKeyProcessor instance should not be used after calling this.

    - #### onKeyEvent

          public boolean onKeyEvent(@NonNull
                                    KeyEvent keyEvent)

      Called when a key event is received by the `FlutterView` or the `InputConnectionAdaptor`.
      Parameters:
        `keyEvent` - the Android key event to respond to.
      Returns:
        true if the key event should not be propagated to other Android components. Delayed synthesis events will return false, so that other components may handle them.

    - #### isPendingEvent

          public boolean isPendingEvent(@NonNull
                                        KeyEvent event)

      Returns whether or not the given event is currently being processed by this key processor. This is used to determine if a new key event sent to the `InputConnectionAdaptor` originates from a hardware key event, or a soft keyboard editing event.
      Parameters:
        `event` - the event to check for being the current event.
      Returns: