View-specific IME?

I have a custom view for which I want the user to be able to enter characters from a specific character set. For this, as I understand it, I need to write an input method service. The user must not only install it, but then must enable the IME in Settings> Language and Keyboard, and then select the custom IME to use in the view.

It seems really crazy. I want this IME to be used for only one view in one application. I do not want it to be available on a system-wide basis or to force the user to make global settings changes.

The only alternative I see is defining my own custom view in the application and simulating an IME (possibly full screen) when the view gets focus. Is there nothing better?

+3
source share
1 answer

I do not think that IMEs are designed for this kind of task. Their concept is to allow the user to introduce a standardized method so that it can be used in several applications from different vendors.

My strategy will be similar to what you think:

  • Do not show soft keyboard,
  • intercept the menu button button to display your own,
  • add a custom layout (possibly a GridView or TableView inside a RelativeLayout with lower gravity)
  • use OnItemClickListener
  • send the required KeyEvent to the root of the View . If characters are thought up, KeyCodes don't even need to bind to an ASCII character. You just intercept the code and use it as you wish.

Sorry, I can’t give you the option as you requested, but this alternative does not seem to be much more than creating a whole new IME.

Edit : When reading a related question, it makes sense to use android.inputmethodservice.KeyboardView instead of reinventing the wheel with a GridView .

+2
source

Source: https://habr.com/ru/post/1397511/


All Articles