Android view inputmethod inputmethodmanager

InputMethodManager

java.lang.Object
android.view.inputmethod.InputMethodManager

Class Overview

Central system API to the overall input method framework (IMF) architecture, which arbitrates interaction between applications and the current input method. You can retrieve an instance of this interface with Context.getSystemService() .

Architecture Overview

There are three primary parties involved in the input method framework (IMF) architecture:

  • The input method manager as expressed by this class is the central point of the system that manages interaction between all other parts. It is expressed as the client-side API here which exists in each application context and communicates with a global system service that manages the interaction across all processes.
  • An input method (IME) implements a particular interaction model allowing the user to generate text. The system binds to the current input method that is use, causing it to be created and run, and tells it when to hide and show its UI. Only one IME is running at a time.
  • Multiple client applications arbitrate with the input method manager for input focus and control over the state of the IME. Only one such client is ever active (working with the IME) at a time.

Applications

In most cases, applications that are using the standard TextView or its subclasses will have little they need to do to work well with soft input methods. The main things you need to be aware of are:

  • Properly set the inputType in your editable text views, so that the input method will have enough context to help the user in entering text into them.
  • Deal well with losing screen space when the input method is displayed. Ideally an application should handle its window being resized smaller, but it can rely on the system performing panning of the window if needed. You should set the windowSoftInputMode attribute on your activity or the corresponding values on windows you create to help the system determine whether to pan or resize (it will try to determine this automatically but may get it wrong).
  • You can also control the preferred soft input state (open, closed, etc) for your window using the same windowSoftInputMode attribute.

More finer-grained control is available through the APIs here to directly interact with the IMF and its IME — either showing or hiding the input area, letting the user pick an input method, etc.

For the rare people amongst us writing their own text editors, you will need to implement onCreateInputConnection(EditorInfo) to return a new instance of your own InputConnection interface allowing the IME to interact with your editor.

Input Methods

An input method (IME) is implemented as a Service , typically deriving from InputMethodService . It must provide the core InputMethod interface, though this is normally handled by InputMethodService and implementors will only need to deal with the higher-level API there.

See the InputMethodService class for more information on implementing IMEs.

Security

There are a lot of security issues associated with input methods, since they essentially have freedom to completely drive the UI and monitor everything the user enters. The Android input method framework also allows arbitrary third party IMEs, so care must be taken to restrict their selection and interactions.

Читайте также:  Ar ruler 4pda android

Here are some key points about the security architecture behind the IMF:

Only the system is allowed to directly access an IME’s InputMethod interface, via the BIND_INPUT_METHOD permission. This is enforced in the system by not binding to an input method service that does not require this permission, so the system can guarantee no other untrusted clients are accessing the current input method outside of its control.

There may be many client processes of the IMF, but only one may be active at a time. The inactive clients can not interact with key parts of the IMF through the mechanisms described below.

Clients of an input method are only given access to its InputMethodSession interface. One instance of this interface is created for each client, and only calls from the session associated with the active client will be processed by the current IME. This is enforced by AbstractInputMethodService for normal IMEs, but must be explicitly handled by an IME that is customizing the raw InputMethodSession implementation.

Only the active client’s InputConnection will accept operations. The IMF tells each client process whether it is active, and the framework enforces that in inactive processes calls on to the current InputConnection will be ignored. This ensures that the current IME can only deliver events and text edits to the UI that the user sees as being in focus.

An IME can never interact with an InputConnection while the screen is off. This is enforced by making all clients inactive while the screen is off, and prevents bad IMEs from driving the UI when the user can not be aware of its behavior.

A client application can ask that the system let the user pick a new IME, but can not programmatically switch to one itself. This avoids malicious applications from switching the user to their own IME, which remains running when the user navigates away to another application. An IME, on the other hand, is allowed to programmatically switch the system to another IME, since it already has full control of user input.

The user must explicitly enable a new IME in settings before they can switch to it, to confirm with the system that they know about it and want to make it available for use.

Summary

Constants
int HIDE_IMPLICIT_ONLY Flag for hideSoftInputFromWindow(IBinder, int) to indicate that the soft input window should only be hidden if it was not explicitly shown by the user.
int HIDE_NOT_ALWAYS Flag for hideSoftInputFromWindow(IBinder, int) to indicate that the soft input window should normally be hidden, unless it was originally shown with SHOW_FORCED .
int RESULT_HIDDEN Flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window changed from shown to hidden.
int RESULT_SHOWN Flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window changed from hidden to shown.
int RESULT_UNCHANGED_HIDDEN Flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window was unchanged and remains hidden.
int RESULT_UNCHANGED_SHOWN Flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window was unchanged and remains shown.
int SHOW_FORCED Flag for showSoftInput(View, int) to indicate that the user has forced the input method open (such as by long-pressing menu) so it should not be closed until they explicitly do so.
int SHOW_IMPLICIT Flag for showSoftInput(View, int) to indicate that this is an implicit request to show the input window, not as the result of a direct request by the user.
Читайте также:  Vpn соединение для андроида
Public Methods

Constants

public static final int HIDE_IMPLICIT_ONLY

Flag for hideSoftInputFromWindow(IBinder, int) to indicate that the soft input window should only be hidden if it was not explicitly shown by the user.

public static final int HIDE_NOT_ALWAYS

Flag for hideSoftInputFromWindow(IBinder, int) to indicate that the soft input window should normally be hidden, unless it was originally shown with SHOW_FORCED .

public static final int RESULT_HIDDEN

Flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window changed from shown to hidden.

public static final int RESULT_SHOWN

Flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window changed from hidden to shown.

public static final int RESULT_UNCHANGED_HIDDEN

Flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window was unchanged and remains hidden.

public static final int RESULT_UNCHANGED_SHOWN

Flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver) : the state of the soft input window was unchanged and remains shown.

public static final int SHOW_FORCED

Flag for showSoftInput(View, int) to indicate that the user has forced the input method open (such as by long-pressing menu) so it should not be closed until they explicitly do so.

public static final int SHOW_IMPLICIT

Flag for showSoftInput(View, int) to indicate that this is an implicit request to show the input window, not as the result of a direct request by the user. The window may not be shown in this case.

Public Methods

public void displayCompletions (View view, CompletionInfo[] completions)

public InputMethodSubtype getCurrentInputMethodSubtype ()

Returns the current input method subtype. This subtype is one of the subtypes in the current input method. This method returns null when the current input method doesn’t have any input method subtype.

public List getEnabledInputMethodList ()

public List getEnabledInputMethodSubtypeList (InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes)

Returns a list of enabled input method subtypes for the specified input method info.

Источник

Input Method Manager. Show Soft Input Method

Definition

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

Synonym for #showSoftInput(View, int, ResultReceiver) without a result receiver: explicitly request that the current input method’s soft input area be shown to the user, if needed.

Synonym for #showSoftInput(View, int, ResultReceiver) without a result receiver: explicitly request that the current input method’s soft input area be shown to the user, if needed.

ShowSoftInput(View, ShowFlags)

Synonym for #showSoftInput(View, int, ResultReceiver) without a result receiver: explicitly request that the current input method’s soft input area be shown to the user, if needed.

Parameters

The currently focused view, which would like to receive soft keyboard input.

Provides additional operating flags. Currently may be 0 or have the #SHOW_IMPLICIT bit set.

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

ShowSoftInput(View, ShowFlags, ResultReceiver)

Synonym for #showSoftInput(View, int, ResultReceiver) without a result receiver: explicitly request that the current input method’s soft input area be shown to the user, if needed.

Parameters

The currently focused view, which would like to receive soft keyboard input.

Provides additional operating flags. Currently may be 0 or have the #SHOW_IMPLICIT bit set.

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Источник

IInput Connection Interface

Definition

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

The InputConnection interface is the communication channel from an InputMethod back to the application that is receiving its input.

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)

Handler
JniIdentityHashCode (Inherited from IJavaPeerable)
JniManagedPeerState (Inherited from IJavaPeerable)
JniPeerMembers (Inherited from IJavaPeerable)
PeerReference (Inherited from IJavaPeerable)

Methods

Tell the editor that you are starting a batch of editor operations.

Clear the given meta key pressed states in the given input connection.

Commit a completion the user has selected from the possible ones previously reported to InputMethodSession#displayCompletions InputMethodSession#displayCompletions(CompletionInfo[]) or InputMethodManager#displayCompletions InputMethodManager#displayCompletions(View, CompletionInfo[]) .

Called by the input method to commit content such as a PNG image to the editor.

Commit a correction automatically performed on the raw user’s input.

Commit text to the text box and set the new cursor position.

Delete beforeLength characters of text before the current cursor position, and delete afterLength characters of text after the current cursor position, excluding the selection.

A variant of #deleteSurroundingText(int, int) .

Disposed() (Inherited from IJavaPeerable) DisposeUnlessReferenced() (Inherited from IJavaPeerable) EndBatchEdit()

Tell the editor that you are done with a batch edit previously initiated with #beginBatchEdit .

Have the text editor finish whatever composing text is currently active.

Retrieve the current capitalization mode in effect at the current cursor position in the text.

Retrieve the current text in the input connection’s editor, and monitor for any changes to it.

Gets the selected text, if any.

Gets the surrounding text around the current cursor, with beforeLength characters of text before the cursor (start of the selection), afterLength characters of text after the cursor (end of the selection), and all of the selected text.

Get n characters of text after the current cursor position.

Get n characters of text before the current cursor position.

Perform a context menu action on the field.

Have the editor perform an action it has said it can do.

API to send private commands from an input method to its connected editor.

Have the editor perform spell checking for the full content.

Called back when the connected IME switches between fullscreen and normal modes.

Called by the input method to ask the editor for calling back InputMethodManager#updateCursorAnchorInfo(android.view.View, CursorAnchorInfo) to notify cursor/anchor locations.

Send a key event to the process that is currently attached through this input connection.

Mark a certain region of text as composing text.

Replace the currently composing text with the given text, and set the new cursor position.

Called by the input method to indicate that it consumes all input for itself, or no longer does so.

SetJniIdentityHashCode(Int32) (Inherited from IJavaPeerable) SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable) SetPeerReference(JniObjectReference) (Inherited from IJavaPeerable) SetSelection(Int32, Int32)

Set the selection of the text editor.

UnregisterFromRuntime() (Inherited from IJavaPeerable)

Extension Methods

Performs an Android runtime-checked type conversion.

Источник

Читайте также:  Mx player 4pda android tv box
Оцените статью