Class SessionTextInput

Object
org.mozilla.geckoview.SessionTextInput

public final class SessionTextInput extends Object
SessionTextInput handles text input for GeckoSession through key events or input methods. It is typically used to implement certain methods in View such as View.onCreateInputConnection(android.view.inputmethod.EditorInfo), by forwarding such calls to corresponding methods in SessionTextInput.

For full functionality, SessionTextInput requires a View to be set first through setView(android.view.View). When a View is not set or set to null, SessionTextInput will operate in a reduced functionality mode. See onCreateInputConnection(android.view.inputmethod.EditorInfo) and methods in GeckoSession.TextInputDelegate for changes in behavior in this viewless mode.

  • Method Details

    • getHandler

      @AnyThread @NonNull public Handler getHandler(@NonNull Handler defHandler)
      Get a Handler for the background input method thread. In order to use a background thread for input method operations on systems prior to Nougat, first override View.getHandler() for the View returning the InputConnection instance, and then call this method from the overridden method.

      For example:

       @Override
       public Handler getHandler() {
           if (Build.VERSION.SDK_INT >= 24) {
               return super.getHandler();
           }
           return getSession().getTextInput().getHandler(super.getHandler());
       }
      Parameters:
      defHandler - Handler returned by the system getHandler implementation.
      Returns:
      Handler to return to the system through getHandler.
    • getView

      @UiThread @Nullable public View getView()
      Get the current View for text input.
      Returns:
      Current text input View or null if not set.
      See Also:
    • setView

      @UiThread public void setView(@Nullable View view)
      Set the current View for text input. The View is used to interact with the system input method manager and to display certain text input UI elements. See the SessionTextInput class documentation for information on viewless mode, when the current View is not set or set to null.
      Parameters:
      view - Text input View or null to clear current View.
      See Also:
    • onCreateInputConnection

      @AnyThread @Nullable public InputConnection onCreateInputConnection(@NonNull EditorInfo attrs)
      Get an InputConnection instance. In viewless mode, this method still fills out the EditorInfo object, but the return value will always be null.
      Parameters:
      attrs - EditorInfo instance to be filled on return.
      Returns:
      InputConnection instance, or null if there is no active input (or if in viewless mode).
    • onKeyPreIme

      @UiThread public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event)
      Process a KeyEvent as a pre-IME event.
      Parameters:
      keyCode - Key code.
      event - KeyEvent instance.
      Returns:
      True if the event was handled.
    • onKeyDown

      @UiThread public boolean onKeyDown(int keyCode, @NonNull KeyEvent event)
      Process a KeyEvent as a key-down event.
      Parameters:
      keyCode - Key code.
      event - KeyEvent instance.
      Returns:
      True if the event was handled.
    • onKeyUp

      @UiThread public boolean onKeyUp(int keyCode, @NonNull KeyEvent event)
      Process a KeyEvent as a key-up event.
      Parameters:
      keyCode - Key code.
      event - KeyEvent instance.
      Returns:
      True if the event was handled.
    • onKeyLongPress

      @UiThread public boolean onKeyLongPress(int keyCode, @NonNull KeyEvent event)
      Process a KeyEvent as a long-press event.
      Parameters:
      keyCode - Key code.
      event - KeyEvent instance.
      Returns:
      True if the event was handled.
    • onKeyMultiple

      @UiThread public boolean onKeyMultiple(int keyCode, int repeatCount, @NonNull KeyEvent event)
      Process a KeyEvent as a multiple-press event.
      Parameters:
      keyCode - Key code.
      repeatCount - Key repeat count.
      event - KeyEvent instance.
      Returns:
      True if the event was handled.
    • setDelegate

      @UiThread public void setDelegate(@Nullable GeckoSession.TextInputDelegate delegate)
      Set the current text input delegate.
      Parameters:
      delegate - TextInputDelegate instance or null to restore to default.
    • getDelegate

      @UiThread @NonNull public GeckoSession.TextInputDelegate getDelegate()
      Get the current text input delegate.
      Returns:
      TextInputDelegate instance or a default instance if no delegate has been set.