InputMethodService
open class InputMethodService : AbstractInputMethodService
kotlin.Any | |||||
↳ | android.content.Context | ||||
↳ | android.content.ContextWrapper | ||||
↳ | android.app.Service | ||||
↳ | android.inputmethodservice.AbstractInputMethodService | ||||
↳ | android.inputmethodservice.InputMethodService |
InputMethodService provides a standard implementation of an InputMethod, which final implementations can derive from and customize. See the base class AbstractInputMethodService
and the InputMethod
interface for more information on the basics of writing input methods.
In addition to the normal Service lifecycle methods, this class introduces some new specific callbacks that most subclasses will want to make use of:
-
onInitializeInterface()
for user-interface initialization, in particular to deal with configuration changes while the service is running. -
onBindInput
to find out about switching to a new client. -
onStartInput
to deal with an input session starting with the client. -
onCreateInputView()
,onCreateCandidatesView()
, andonCreateExtractTextView()
for non-demand generation of the UI. -
onStartInputView(android.view.inputmethod.EditorInfo,boolean)
to deal with input starting within the input area of the IME.
An input method has significant discretion in how it goes about its work: the android.inputmethodservice.InputMethodService
provides a basic framework for standard UI elements (input view, candidates view, and running in fullscreen mode), but it is up to a particular implementor to decide how to use them. For example, one input method could implement an input area with a keyboard, another could allow the user to draw text, while a third could have no input area (and thus not be visible to the user) but instead listen to audio and perform text to speech conversion.
In the implementation provided here, all of these elements are placed together in a single window managed by the InputMethodService. It will execute callbacks as it needs information about them, and provides APIs for programmatic control over them. They layout of these elements is explicitly defined:
- The soft input view, if available, is placed at the bottom of the screen.
- The candidates view, if currently shown, is placed above the soft input view.
- If not running fullscreen, the application is moved or resized to be above these views; if running fullscreen, the window will completely cover the application and its top part will contain the extract text of what is currently being edited by the application.
Soft Input View
Central to most input methods is the soft input view. This is where most user interaction occurs: pressing on soft keys, drawing characters, or however else your input method wants to generate text. Most implementations will simply have their own view doing all of this work, and return a new instance of it when onCreateInputView()
is called. At that point, as long as the input view is visible, you will see user interaction in that view and can call back on the InputMethodService to interact with the application as appropriate.
There are some situations where you want to decide whether or not your soft input view should be shown to the user. This is done by implementing the onEvaluateInputViewShown()
to return true or false based on whether it should be shown in the current environment. If any of your state has changed that may impact this, call updateInputViewShown()
to have it re-evaluated. The default implementation always shows the input view unless there is a hard keyboard available, which is the appropriate behavior for most input methods.
Candidates View
Often while the user is generating raw text, an input method wants to provide them with a list of possible interpretations of that text that can be selected for use. This is accomplished with the candidates view, and like the soft input view you implement onCreateCandidatesView()
to instantiate your own view implementing your candidates UI.
Management of the candidates view is a little different than the input view, because the candidates view tends to be more transient, being shown only when there are possible candidates for the current text being entered by the user. To control whether the candidates view is shown, you use setCandidatesViewShown(boolean)
. Note that because the candidate view tends to be shown and hidden a lot, it does not impact the application UI in the same way as the soft input view: it will never cause application windows to resize, only cause them to be panned if needed for the user to see the current focus.
Fullscreen Mode
Sometimes your input method UI is too large to integrate with the application UI, so you just want to take over the screen. This is accomplished by switching to full-screen mode, causing the input method window to fill the entire screen and add its own "extracted text" editor showing the user the text that is being typed. Unlike the other UI elements, there is a standard implementation for the extract editor that you should not need to change. The editor is placed at the top of the IME, above the input and candidates views.
Similar to the input view, you control whether the IME is running in fullscreen mode by implementing onEvaluateFullscreenMode()
to return true or false based on whether it should be fullscreen in the current environment. If any of your state has changed that may impact this, call updateFullscreenMode()
to have it re-evaluated. The default implementation selects fullscreen mode when the screen is in a landscape orientation, which is appropriate behavior for most input methods that have a significant input area.
When in fullscreen mode, you have some special requirements because the user can not see the application UI. In particular, you should implement onDisplayCompletions(android.view.inputmethod.CompletionInfo[])
to show completions generated by your application, typically in your candidates view like you would normally show candidates.
Generating Text
The key part of an IME is of course generating text for the application. This is done through calls to the android.view.inputmethod.InputConnection
interface to the application, which can be retrieved from getCurrentInputConnection()
. This interface allows you to generate raw key events or, if the target supports it, directly edit in strings of candidates and committed text.
Information about what the target is expected and supports can be found through the android.view.inputmethod.EditorInfo
class, which is retrieved with getCurrentInputEditorInfo()
method. The most important part of this is EditorInfo.inputType
; in particular, if this is EditorInfo.TYPE_NULL
, then the target does not support complex edits and you need to only deliver raw key events to it. An input method will also want to look at other values here, to for example detect password mode, auto complete text views, phone number entry, etc.
When the user switches between input targets, you will receive calls to onFinishInput()
and onStartInput(android.view.inputmethod.EditorInfo,boolean)
. You can use these to reset and initialize your input state for the current target. For example, you will often want to clear any input state, and update a soft keyboard to be appropriate for the new inputType.
Summary
Nested classes | |
---|---|
open |
Concrete implementation of |
open |
Concrete implementation of |
Information about where interesting parts of the input method UI appear. |
XML attributes | |
---|---|
android:imeExtractEnterAnimation |
Animation to use when showing the fullscreen extract UI after it had previously been hidden. |
android:imeExtractExitAnimation |
Animation to use when hiding the fullscreen extract UI after it had previously been shown. |
android:imeFullscreenBackground |
Background to use for entire input method when it is being shown in fullscreen mode with the extract view, to ensure that it completely covers the application. |
Constants | |
---|---|
static Int |
Asks the system to not adjust the back button affordance even when the software keyboard is shown. |
static Int |
Allows the system to optimize the back button affordance based on the presence of software keyboard. |
static Int |
Deprecated flag. |
static Int |
Deprecated flag. |
Inherited constants | |
---|---|
Public constructors | |
---|---|
Public methods | |
---|---|
open Boolean |
You can call this to try to enable accelerated drawing for your IME. |
Unit |
Finishes the current connectionless stylus handwriting session and delivers the result. |
Unit |
Finish the current stylus handwriting session. |
open Int |
Retrieves the current disposition mode that indicates the expected back button affordance. |
open Int |
Returns the visibility mode (either |
open InputBinding! |
Return the currently active InputBinding for the input method, or null if there is none. |
open InputConnection! |
Retrieve the currently active InputConnection that is bound to the input method, or null if there is none. |
open EditorInfo! | |
open Boolean | |
open Int |
Aimed to return the previous input method's |
open LayoutInflater! | |
open Int |
Return the maximum width, in pixels, available the input method. |
static Duration |
Returns the maximum stylus handwriting session idle-timeout for use with |
Duration |
Returns the duration after which an ongoing stylus handwriting session that hasn't received new |
Window? |
Returns the stylus handwriting inking window. |
open Any! |
getSystemService(name: String) Return the handle to a system-level service by name. |
open CharSequence! |
getTextForImeAction(imeOptions: Int) Return text that can be used as a button label for the given |
open Dialog! | |
open Unit | |
open Unit | |
open Boolean |
Return whether the fullscreen extract view is shown. |
open Boolean |
Return whether the input method is currently running in fullscreen mode. |
open Boolean |
Return whether the soft input view is currently shown to the user. |
open Boolean |
Returns true if we have been asked to show our input view. |
open Unit |
onAppPrivateCommand(action: String!, data: Bundle!) Not implemented in this class. |
open Unit |
Called when a new client has bound to the input method. |
open Unit |
onComputeInsets(outInsets: InputMethodService.Insets!) Compute the interesting insets into your UI. |
open Unit |
onConfigurationChanged(newConfig: Configuration) Take care of handling configuration changes. |
open Unit |
onConfigureWindow(win: Window!, isFullscreen: Boolean, isCandidatesOnly: Boolean) Update the given window's parameters for the given mode. |
open Unit |
onCreate() |
open View! |
Create and return the view hierarchy used to show candidates. |
open View! |
Called by the framework to create the layout for showing extracted text. |
open InlineSuggestionsRequest? |
onCreateInlineSuggestionsRequest(uiExtras: Bundle) Called when Autofill is requesting an |
open AbstractInputMethodService.AbstractInputMethodImpl! |
Implement to return our standard |
open AbstractInputMethodService.AbstractInputMethodSessionImpl! |
Implement to return our standard |
open View! |
Create and return the view hierarchy used for the input area (such as a soft keyboard). |
open Unit | |
open Unit |
onDisplayCompletions(completions: Array<CompletionInfo!>!) Called when the application has reported auto-completion candidates that it would like to have the input method displayed. |
open Boolean |
Override this to control when the input method should run in fullscreen mode. |
open Boolean |
Override this to control when the soft input area should be shown to the user. |
open Boolean |
This is called when the user has selected a context menu item from the extracted text view, when running in fullscreen mode. |
open Unit |
onExtractedCursorMovement(dx: Int, dy: Int) This is called when the user has performed a cursor movement in the extracted text view, when it is running in fullscreen mode. |
open Unit |
onExtractedSelectionChanged(start: Int, end: Int) This is called when the user has moved the cursor in the extracted text view, when running in fullsreen mode. |
open Unit |
This is called when the user has clicked on the extracted text view, when running in fullscreen mode. |
open Unit |
This is called when, while currently displayed in extract mode, the current input target changes. |
open Unit |
onFinishCandidatesView(finishingInput: Boolean) Called when the candidates view is being hidden from the user. |
open Unit |
Called to inform the input method that text input has finished in the last editor. |
open Unit |
onFinishInputView(finishingInput: Boolean) Called when the input view is being hidden from the user. |
open Unit |
Called when the current stylus handwriting session was finished (either by the system or via |
open Boolean |
onGenericMotionEvent(event: MotionEvent!) Override this to intercept generic motion events before they are processed by the application. |
open Unit |
This is a hook that subclasses can use to perform initialization of their interface. |
open Boolean |
Called when Autofill responds back with |
open Boolean |
Called back when a |
open Boolean |
onKeyLongPress(keyCode: Int, event: KeyEvent!) Default implementation of |
open Boolean |
onKeyMultiple(keyCode: Int, count: Int, event: KeyEvent!) Override this to intercept special key multiple events before they are processed by the application. |
open Boolean |
Override this to intercept key up events before they are processed by the application. |
open Unit |
Called to prepare stylus handwriting. |
open Boolean |
onShowInputRequested(flags: Int, configChange: Boolean) The system has decided that it may be time to show your input method. |
open Unit |
onStartCandidatesView(editorInfo: EditorInfo!, restarting: Boolean) Called when only the candidates view has been shown for showing processing as the user enters text through a hard keyboard. |
open Boolean |
onStartConnectionlessStylusHandwriting(inputType: Int, cursorAnchorInfo: CursorAnchorInfo?) Called when an app requests to start a connectionless stylus handwriting session using one of |
open Unit |
onStartInput(attribute: EditorInfo!, restarting: Boolean) Called to inform the input method that text input has started in an editor. |
open Unit |
onStartInputView(editorInfo: EditorInfo!, restarting: Boolean) Called when the input view is being shown and input has started on a new editor. |
open Boolean |
Called when an app requests stylus handwriting |
open Unit |
onStylusHandwritingMotionEvent(motionEvent: MotionEvent) Called after |
open Boolean |
onTrackballEvent(event: MotionEvent!) Override this to intercept trackball motion events before they are processed by the application. |
open Unit |
Called when the previous bound client is no longer associated with the input method. |
open Unit |
onUpdateCursor(newCursor: Rect!) Called when the application has reported a new location of its text cursor. |
open Unit |
onUpdateCursorAnchorInfo(cursorAnchorInfo: CursorAnchorInfo!) Called when the application has reported a new location of its text insertion point and characters in the composition string. |
open Unit |
onUpdateEditorToolType(toolType: Int) Called when the user tapped or clicked an editor. |
open Unit |
onUpdateExtractedText(token: Int, text: ExtractedText!) Called when the application has reported new extracted text to be shown due to changes in its current text state. |
open Unit |
Called when the fullscreen-mode extracting editor info has changed, to update the state of its UI such as the action buttons shown. |
open Unit |
Called when the fullscreen-mode extracting editor info has changed, to determine whether the extracting (extract text and candidates) portion of the UI should be shown. |
open Unit |
onUpdateSelection(oldSelStart: Int, oldSelEnd: Int, newSelStart: Int, newSelEnd: Int, candidatesStart: Int, candidatesEnd: Int) Called when the application has reported a new selection region of the text. |
open Unit |
onViewClicked(focusChanged: Boolean) Called when the user tapped or clicked a text view. |
open Unit |
Called when the input method window has been hidden from the user, after previously being visible. |
open Unit |
Called immediately before the input method window is shown to the user. |
open Unit |
requestHideSelf(flags: Int) Close this input method's soft input area, removing it from the display. |
Unit |
requestShowSelf(flags: Int) Show the input method's soft input area, so the user sees the input method window and can interact with it. |
open Boolean |
sendDefaultEditorAction(fromEnterKey: Boolean) Ask the input target to execute its default action via |
open Unit |
sendDownUpKeyEvents(keyEventCode: Int) Send the given key event code (as defined by |
open Unit |
sendKeyChar(charCode: Char) Send the given UTF-16 character to the current input connection. |
open Unit |
setBackDisposition(disposition: Int) Sets the disposition mode that indicates the expected affordance for the back button. |
open Unit |
setCandidatesView(view: View!) Replaces the current candidates view with a new one. |
open Unit |
setCandidatesViewShown(shown: Boolean) Controls the visibility of the candidates display area. |
open Unit |
setExtractView(view: View!) |
open Unit |
setExtractViewShown(shown: Boolean) Controls the visibility of the extracted text area. |
open Unit |
setInputView(view: View!) Replaces the current input view with a new one. |
Unit |
setStylusHandwritingSessionTimeout(duration: Duration) Sets the duration after which an ongoing stylus handwriting session that hasn't received new |
open Unit |
You can call this to customize the theme used by your IME's window. |
Boolean |
Returns true if the current IME needs to offer the users ways to switch to a next input method (e.g. a globe key.). |
open Unit |
showStatusIcon(iconResId: Int) |
open Unit |
showWindow(showInput: Boolean) |
open Unit |
switchInputMethod(id: String!) Force switch to a new input method, as identified by id. |
Unit |
switchInputMethod(id: String!, subtype: InputMethodSubtype!) Force switch to a new input method, as identified by |
Boolean |
switchToNextInputMethod(onlyCurrentIme: Boolean) Force switch to the next input method and subtype. |
Boolean |
Force switch to the last used input method and subtype. |
open Unit |
Re-evaluate whether the input method should be running in fullscreen mode, and update its UI if this has changed since the last time it was evaluated. |
open Unit |
Re-evaluate whether the soft input area should currently be shown, and update its UI if this has changed since the last time it was evaluated. |
Protected methods | |
---|---|
open Unit |
dump(fd: FileDescriptor!, fout: PrintWriter!, args: Array<String!>!) Performs a dump of the InputMethodService's internal state. |
open Unit |
onCurrentInputMethodSubtypeChanged(newSubtype: InputMethodSubtype!) Called when the subtype was changed. |
Inherited functions | |
---|---|
XML attributes
android:imeExtractEnterAnimation
android:imeExtractEnterAnimation
Animation to use when showing the fullscreen extract UI after it had previously been hidden.
May be a reference to another resource, in the form "@[+][package:]type/name
" or a theme attribute in the form "?[package:]type/name
".
android:imeExtractExitAnimation
android:imeExtractExitAnimation
Animation to use when hiding the fullscreen extract UI after it had previously been shown.
May be a reference to another resource, in the form "@[+][package:]type/name
" or a theme attribute in the form "?[package:]type/name
".
android:imeFullscreenBackground
android:imeFullscreenBackground
Background to use for entire input method when it is being shown in fullscreen mode with the extract view, to ensure that it completely covers the application. This allows, for example, the candidate view to be hidden while in fullscreen mode without having the application show through behind it.
May be a reference to another resource, in the form "@[+][package:]type/name
" or a theme attribute in the form "?[package:]type/name
".
May be a color value, in the form of "rgb
", "argb
", "rrggbb
", or "aarrggbb
".
Constants
BACK_DISPOSITION_ADJUST_NOTHING
static val BACK_DISPOSITION_ADJUST_NOTHING: Int
Asks the system to not adjust the back button affordance even when the software keyboard is shown.
This mode is useful for UI modes where IME's main soft input window is used for some supplemental UI, such as floating candidate window for languages such as Chinese and Japanese, where users expect the back button is, or at least looks to be, handled by the target application rather than the UI shown by the IME even while isInputViewShown()
returns true
.
Note that KeyEvent#KEYCODE_BACK
events continue to be sent to onKeyDown(int,android.view.KeyEvent)
even when this mode is specified. The default implementation of onKeyDown(int,android.view.KeyEvent)
for KeyEvent#KEYCODE_BACK
does not take this mode into account.
Value: 3
See Also
BACK_DISPOSITION_DEFAULT
static val BACK_DISPOSITION_DEFAULT: Int
Allows the system to optimize the back button affordance based on the presence of software keyboard.
For instance, on devices that have navigation bar and software-rendered back button, the system may use a different icon while isInputViewShown()
returns true
, to indicate that the back button has "dismiss" affordance.
Note that KeyEvent#KEYCODE_BACK
events continue to be sent to onKeyDown(int,android.view.KeyEvent)
even when this mode is specified. The default implementation of onKeyDown(int,android.view.KeyEvent)
for KeyEvent#KEYCODE_BACK
does not take this mode into account.
For API level android.os.Build.VERSION_CODES#O_MR1
and lower devices, this is the only mode you can safely specify without worrying about the compatibility.
Value: 0
See Also
BACK_DISPOSITION_WILL_DISMISS
static valBACK_DISPOSITION_WILL_DISMISS: Int
Deprecated: on android.os.Build.VERSION_CODES#P
and later devices, this flag is handled as a synonym of BACK_DISPOSITION_DEFAULT
. On android.os.Build.VERSION_CODES#O_MR1
and prior devices, expected behavior of this mode had not been well defined. In AOSP implementation running on devices that have navigation bar, specifying this flag could change the software back button to "Dismiss" icon no matter whether the software keyboard is shown or not, but there would be no easy way to restore the icon state even after IME lost the connection to the application. To avoid user confusions, do not specify this mode anyway
Deprecated flag.
To avoid compatibility issues, IME developers should not use this flag.
Value: 2
See Also
BACK_DISPOSITION_WILL_NOT_DISMISS
static valBACK_DISPOSITION_WILL_NOT_DISMISS: Int
Deprecated: on android.os.Build.VERSION_CODES#P
and later devices, this flag is handled as a synonym of BACK_DISPOSITION_DEFAULT
. On android.os.Build.VERSION_CODES#O_MR1
and prior devices, expected behavior of this mode had not been well defined. Most likely the end result would be the same as BACK_DISPOSITION_DEFAULT
. Either way it is not recommended to use this mode
Deprecated flag.
To avoid compatibility issues, IME developers should not use this flag.
Value: 1
See Also
Public constructors
InputMethodService
InputMethodService()
Public methods
enableHardwareAcceleration
open funenableHardwareAcceleration(): Boolean
Deprecated: Starting in API 21, hardware acceleration is always enabled on capable devices
You can call this to try to enable accelerated drawing for your IME. This must be set before onCreate()
, so you will typically call it in your constructor. It is not always possible to use hardware accelerated drawing in an IME (for example on low-end devices that do not have the resources to support this), so the call true
if it succeeds otherwise false
if you will need to draw in software. You must be able to handle either case.
In API 21 and later, system may automatically enable hardware accelerated drawing for your IME on capable devices even if this method is not explicitly called. Make sure that your IME is able to handle either case.
Return | |
---|---|
Boolean |
true if accelerated drawing is successfully enabled otherwise false . On API 21 and later devices the return value is basically just a hint and your IME does not need to change the behavior based on the it |
finishConnectionlessStylusHandwriting
fun finishConnectionlessStylusHandwriting(text: CharSequence?): Unit
Finishes the current connectionless stylus handwriting session and delivers the result.
This dismisses the ink window
and stops intercepting stylus MotionEvent
s.
Note for IME developers: Call this method at any time to finish the current handwriting session. Generally, this should be invoked after a short timeout, giving the user enough time to start the next stylus stroke, if any. By default, system will time-out after few seconds. To override default timeout, use setStylusHandwritingSessionTimeout(java.time.Duration)
.
Parameters | |
---|---|
text |
CharSequence?: This value may be null . |
finishStylusHandwriting
fun finishStylusHandwriting(): Unit
Finish the current stylus handwriting session.
This dismisses the ink window
and stops intercepting stylus MotionEvent
s.
Note for IME developers: Call this method at any time to finish the current handwriting session. Generally, this should be invoked after a short timeout, giving the user enough time to start the next stylus stroke, if any. By default, system will time-out after few seconds. To override default timeout, use setStylusHandwritingSessionTimeout(java.time.Duration)
.
Handwriting session will be finished by framework on next onFinishInput()
.
getBackDisposition
open fun getBackDisposition(): Int
Retrieves the current disposition mode that indicates the expected back button affordance.
See Also
getCandidatesHiddenVisibility
open fun getCandidatesHiddenVisibility(): Int
Returns the visibility mode (either View.INVISIBLE
or View.GONE
) of the candidates view when it is not shown. The default implementation returns GONE when isExtractViewShown
returns true, otherwise INVISIBLE. Be careful if you change this to return GONE in other situations -- if showing or hiding the candidates view causes your window to resize, this can cause temporary drawing artifacts as the resize takes place.
getCurrentInputBinding
open fun getCurrentInputBinding(): InputBinding!
Return the currently active InputBinding for the input method, or null if there is none.
getCurrentInputConnection
open fun getCurrentInputConnection(): InputConnection!
Retrieve the currently active InputConnection that is bound to the input method, or null if there is none.
getInputMethodWindowRecommendedHeight
open fungetInputMethodWindowRecommendedHeight(): Int
Deprecated: the actual behavior of this method has never been well defined. You cannot use this method in a reliable and predictable way
Aimed to return the previous input method's Insets#contentTopInsets
, but its actual semantics has never been well defined.
Note that the previous document clearly mentioned that this method could return 0
at any time for whatever reason. Now this method is just always returning 0
.
Return | |
---|---|
Int |
on Android android.os.Build.VERSION_CODES#Q and later devices this method always returns 0 |
getMaxWidth
open fun getMaxWidth(): Int
Return the maximum width, in pixels, available the input method. Input methods are positioned at the bottom of the screen and, unless running in fullscreen, will generally want to be as short as possible so should compute their height based on their contents. However, they can stretch as much as needed horizontally. The function returns to you the maximum amount of space available horizontally, which you can use if needed for UI placement.
In many cases this is not needed, you can just rely on the normal view layout mechanisms to position your views within the full horizontal space given to the input method.
Note that this value can change dynamically, in particular when the screen orientation changes.
getStylusHandwritingIdleTimeoutMax
static fun getStylusHandwritingIdleTimeoutMax(): Duration
Returns the maximum stylus handwriting session idle-timeout for use with setStylusHandwritingSessionTimeout(java.time.Duration)
.
Return | |
---|---|
Duration |
This value cannot be null . |
getStylusHandwritingSessionTimeout
fun getStylusHandwritingSessionTimeout(): Duration
Returns the duration after which an ongoing stylus handwriting session that hasn't received new MotionEvent
s will time out and finishStylusHandwriting()
will be called. The current timeout can be changed using setStylusHandwritingSessionTimeout(java.time.Duration)
.
Return | |
---|---|
Duration |
This value cannot be null . |
getStylusHandwritingWindow
fun getStylusHandwritingWindow(): Window?
Returns the stylus handwriting inking window. IMEs supporting stylus input are expected to attach their inking views to this window (e.g. with Window#setContentView(View)
)). Handwriting-related MotionEvent
s are dispatched to the attached view hierarchy. Note: This returns null
if IME doesn't support stylus handwriting i.e. if InputMethodInfo#supportsStylusHandwriting()
is false. This method should be called after onStartStylusHandwriting()
.
See Also
getSystemService
open fun getSystemService(name: String): Any!
Return the handle to a system-level service by name. The class of the returned object varies by the requested name. Currently available names are:
-
WINDOW_SERVICE
("window") - The top-level window manager in which you can place custom windows. The returned object is a
android.view.WindowManager
. Must only be obtained from a visual context such as Activity or a Context created withcreateWindowContext(int,android.os.Bundle)
, which are adjusted to the configuration and visual bounds of an area on screen. -
LAYOUT_INFLATER_SERVICE
("layout_inflater") - A
android.view.LayoutInflater
for inflating layout resources in this context. Must only be obtained from a visual context such as Activity or a Context created withcreateWindowContext(int,android.os.Bundle)
, which are adjusted to the configuration and visual bounds of an area on screen. -
ACTIVITY_SERVICE
("activity") - A
android.app.ActivityManager
for interacting with the global activity state of the system. -
WALLPAPER_SERVICE
("wallpaper") - A
android.service.wallpaper.WallpaperService
for accessing wallpapers in this context. Must only be obtained from a visual context such as Activity or a Context created withcreateWindowContext(int,android.os.Bundle)
, which are adjusted to the configuration and visual bounds of an area on screen. -
POWER_SERVICE
("power") - A
android.os.PowerManager
for controlling power management. -
ALARM_SERVICE
("alarm") - A
android.app.AlarmManager
for receiving intents at the time of your choosing. -
NOTIFICATION_SERVICE
("notification") - A
android.app.NotificationManager
for informing the user of background events. -
KEYGUARD_SERVICE
("keyguard") - A
android.app.KeyguardManager
for controlling keyguard. -
LOCATION_SERVICE
("location") - A
android.location.LocationManager
for controlling location (e.g., GPS) updates. -
SEARCH_SERVICE
("search") - A
android.app.SearchManager
for handling search. -
VIBRATOR_MANAGER_SERVICE
("vibrator_manager") - A
android.os.VibratorManager
for accessing the device vibrators, interacting with individual ones and playing synchronized effects on multiple vibrators. -
VIBRATOR_SERVICE
("vibrator") - A
android.os.Vibrator
for interacting with the vibrator hardware. -
CONNECTIVITY_SERVICE
("connectivity") - A
ConnectivityManager
for handling management of network connections. -
IPSEC_SERVICE
("ipsec") - A
IpSecManager
for managing IPSec on sockets and networks. -
WIFI_SERVICE
("wifi") - A
WifiManager
for management of Wi-Fi connectivity. On releases before Android 7, it should only be obtained from an application context, and not from any other derived context to avoid memory leaks within the calling process. -
WIFI_AWARE_SERVICE
("wifiaware") - A
WifiAwareManager
for management of Wi-Fi Aware discovery and connectivity. -
WIFI_P2P_SERVICE
("wifip2p") - A
WifiP2pManager
for management of Wi-Fi Direct connectivity. -
INPUT_METHOD_SERVICE
("input_method") - An
InputMethodManager
for management of input methods. -
UI_MODE_SERVICE
("uimode") - An
android.app.UiModeManager
for controlling UI modes. -
DOWNLOAD_SERVICE
("download") - A
android.app.DownloadManager
for requesting HTTP downloads -
BATTERY_SERVICE
("batterymanager") - A
android.os.BatteryManager
for managing battery state -
JOB_SCHEDULER_SERVICE
("taskmanager") - A
android.app.job.JobScheduler
for managing scheduled tasks -
NETWORK_STATS_SERVICE
("netstats") - A
NetworkStatsManager
for querying network usage statistics. -
HARDWARE_PROPERTIES_SERVICE
("hardware_properties") - A
android.os.HardwarePropertiesManager
for accessing hardware properties. -
DOMAIN_VERIFICATION_SERVICE
("domain_verification") - A
android.content.pm.verify.domain.DomainVerificationManager
for accessing web domain approval state. -
DISPLAY_HASH_SERVICE
("display_hash") - A
android.view.displayhash.DisplayHashManager
for management of display hashes.
Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)
Note: Instant apps, for which PackageManager#isInstantApp()
returns true, don't have access to the following system services: DEVICE_POLICY_SERVICE
, FINGERPRINT_SERVICE
, KEYGUARD_SERVICE
, SHORTCUT_SERVICE
, USB_SERVICE
, WALLPAPER_SERVICE
, WIFI_P2P_SERVICE
, WIFI_SERVICE
, WIFI_AWARE_SERVICE
. For these services this method will return null
. Generally, if you are running as an instant app you should always check whether the result of this method is null
.
Note: When implementing this method, keep in mind that new services can be added on newer Android releases, so if you're looking for just the explicit names mentioned above, make sure to return null
when you don't recognize the name — if you throw a RuntimeException
exception instead, your app might break on new Android releases.
Parameters | |
---|---|
name |
String: This value cannot be null . |
Return | |
---|---|
Any! |
The service or null if the name does not exist. |
getTextForImeAction
open fun getTextForImeAction(imeOptions: Int): CharSequence!
Return text that can be used as a button label for the given EditorInfo.imeOptions
. Returns null if there is no action requested. Note that there is no guarantee that the returned text will be relatively short, so you probably do not want to use it as text on a soft keyboard key label.
Parameters | |
---|---|
imeOptions |
Int: The value from EditorInfo.imeOptions . |
Return | |
---|---|
CharSequence! |
Returns a label to use, or null if there is no action. |
isExtractViewShown
open fun isExtractViewShown(): Boolean
Return whether the fullscreen extract view is shown. This will only return true if isFullscreenMode()
returns true, and in that case its value depends on the last call to setExtractViewShown(boolean)
. This effectively lets you determine if the application window is entirely covered (when this returns true) or if some part of it may be shown (if this returns false, though if isFullscreenMode()
returns true in that case then it is probably only a sliver of the application).
isFullscreenMode
open fun isFullscreenMode(): Boolean
Return whether the input method is currently running in fullscreen mode. This is the mode that was last determined and applied by updateFullscreenMode()
.
isInputViewShown
open fun isInputViewShown(): Boolean
Return whether the soft input view is currently shown to the user. This is the state that was last determined and applied by updateInputViewShown()
.
isShowInputRequested
open fun isShowInputRequested(): Boolean
Returns true if we have been asked to show our input view.
onAppPrivateCommand
open fun onAppPrivateCommand(
action: String!,
data: Bundle!
): Unit
Not implemented in this class.
onBindInput
open fun onBindInput(): Unit
Called when a new client has bound to the input method. This may be followed by a series of onStartInput(android.view.inputmethod.EditorInfo,boolean)
and onFinishInput()
calls as the user navigates through its UI. Upon this call you know that getCurrentInputBinding
and getCurrentInputConnection
return valid objects.
onComputeInsets
open fun onComputeInsets(outInsets: InputMethodService.Insets!): Unit
Compute the interesting insets into your UI. The default implementation uses the top of the candidates frame for the visible insets, and the top of the input frame for the content insets. The default touchable insets are Insets#TOUCHABLE_INSETS_VISIBLE
.
Note that this method is not called when isExtractViewShown
returns true, since in that case the application is left as-is behind the input method and not impacted by anything in its UI.
Parameters | |
---|---|
outInsets |
InputMethodService.Insets!: Fill in with the current UI insets. |
onConfigurationChanged
open fun onConfigurationChanged(newConfig: Configuration): Unit
Take care of handling configuration changes. Subclasses of InputMethodService generally don't need to deal directly with this on their own; the standard implementation here takes care of regenerating the input method UI as a result of the configuration change, so you can rely on your onCreateInputView
and other methods being called as appropriate due to a configuration change.
When a configuration change does happen, onInitializeInterface()
is guaranteed to be called the next time prior to any of the other input or UI creation callbacks. The following will be called immediately depending if appropriate for current state: onStartInput
if input is active, and onCreateInputView
and onStartInputView
and related appropriate functions if the UI is displayed.
Starting with Build.VERSION_CODES#S
, IMEs can opt into handling configuration changes themselves instead of being restarted with android.R.styleable#InputMethod_configChanges
.
Parameters | |
---|---|
newConfig |
Configuration: The new device configuration. This value cannot be null . |
configuration |
This value cannot be null . |
onConfigureWindow
open fun onConfigureWindow(
win: Window!,
isFullscreen: Boolean,
isCandidatesOnly: Boolean
): Unit
Update the given window's parameters for the given mode. This is called when the window is first displayed and each time the fullscreen or candidates only mode changes.
The default implementation makes the layout for the window MATCH_PARENT x MATCH_PARENT when in fullscreen mode, and MATCH_PARENT x WRAP_CONTENT when in non-fullscreen mode.
Parameters | |
---|---|
win |
Window!: The input method's window. |
isFullscreen |
Boolean: If true, the window is running in fullscreen mode and intended to cover the entire application display. |
isCandidatesOnly |
Boolean: If true, the window is only showing the candidates view and none of the rest of its UI. This is mutually exclusive with fullscreen mode. |
onCreateCandidatesView
open fun onCreateCandidatesView(): View!
Create and return the view hierarchy used to show candidates. This will be called once, when the candidates are first displayed. You can return null to have no candidates view; the default implementation returns null.
To control when the candidates view is displayed, use setCandidatesViewShown(boolean)
. To change the candidates view after the first one is created by this function, use setCandidatesView(android.view.View)
.
onCreateExtractTextView
open fun onCreateExtractTextView(): View!
Called by the framework to create the layout for showing extracted text. Only called when in fullscreen mode. The returned view hierarchy must have an ExtractEditText
whose ID is android.R.id#inputExtractEditText
, with action ID android.R.id#inputExtractAction
and accessories ID android.R.id#inputExtractAccessories
.
onCreateInlineSuggestionsRequest
open fun onCreateInlineSuggestionsRequest(uiExtras: Bundle): InlineSuggestionsRequest?
Called when Autofill is requesting an InlineSuggestionsRequest
from the IME.
The Autofill Framework will first request the IME to create and send an InlineSuggestionsRequest
back. Once Autofill Framework receives a valid request and also receives valid inline suggestions, they will be returned via onInlineSuggestionsResponse(android.view.inputmethod.InlineSuggestionsResponse)
.
IME Lifecycle - The request will wait to be created after inputStarted
If the IME wants to support displaying inline suggestions, they must set supportsInlineSuggestions in its XML and implement this method to return a valid InlineSuggestionsRequest
.
Parameters | |
---|---|
uiExtras |
Bundle: the extras that contain the UI renderer related information This value cannot be null . |
Return | |
---|---|
InlineSuggestionsRequest? |
an InlineSuggestionsRequest to be sent to Autofill. This value may be null . |
onCreateInputMethodInterface
open funonCreateInputMethodInterface(): AbstractInputMethodService.AbstractInputMethodImpl!
Deprecated: Overriding or calling this method is strongly discouraged. A future version of Android will remove the ability to use this method. Use the callbacks on InputMethodService
as InputMethodService#onBindInput()
, InputMethodService#onUnbindInput()
, InputMethodService#onWindowShown()
, InputMethodService#onWindowHidden()
, etc.
Implement to return our standard InputMethodImpl
.
onCreateInputMethodSessionInterface
open funonCreateInputMethodSessionInterface(): AbstractInputMethodService.AbstractInputMethodSessionImpl!
Deprecated: Overriding or calling this method is strongly discouraged. Most methods in InputMethodSessionImpl
have corresponding callbacks. Use InputMethodService#onFinishInput()
, InputMethodService#onDisplayCompletions(CompletionInfo[])
, InputMethodService#onUpdateExtractedText(int, ExtractedText)
, InputMethodService#onUpdateSelection(int, int, int, int, int, int)
instead.
Implement to return our standard InputMethodSessionImpl
.
IMEs targeting on Android U and above cannot override this method, or an LinkageError
would be thrown.
onCreateInputView
open fun onCreateInputView(): View!
Create and return the view hierarchy used for the input area (such as a soft keyboard). This will be called once, when the input area is first displayed. You can return null to have no input area; the default implementation returns null.
To control when the input view is displayed, implement onEvaluateInputViewShown()
. To change the input view after the first one is created by this function, use setInputView(android.view.View)
.
onDisplayCompletions
open fun onDisplayCompletions(completions: Array<CompletionInfo!>!): Unit
Called when the application has reported auto-completion candidates that it would like to have the input method displayed. Typically these are only used when an input method is running in full-screen mode, since otherwise the user can see and interact with the pop-up window of completions shown by the application.
The default implementation here does nothing.
onEvaluateFullscreenMode
open fun onEvaluateFullscreenMode(): Boolean
Override this to control when the input method should run in fullscreen mode. The default implementation runs in fullsceen only when the screen is in landscape mode. If you change what this returns, you will need to call updateFullscreenMode()
yourself whenever the returned value may have changed to have it re-evaluated and applied.
onEvaluateInputViewShown
open fun onEvaluateInputViewShown(): Boolean
Override this to control when the soft input area should be shown to the user. The default implementation returns false
when there is no hard keyboard or the keyboard is hidden unless the user shows an intention to use software keyboard. If you change what this returns, you will need to call updateInputViewShown()
yourself whenever the returned value may have changed to have it re-evaluated and applied.
When you override this method, it is recommended to call super.onEvaluateInputViewShown()
and return true
when true
is returned.
If you override this method you must call through to the superclass implementation.
onExtractTextContextMenuItem
open fun onExtractTextContextMenuItem(id: Int): Boolean
This is called when the user has selected a context menu item from the extracted text view, when running in fullscreen mode. The default implementation sends this action to the current InputConnection's InputConnection#performContextMenuAction(int)
, for it to be processed in underlying "real" editor. Re-implement this to provide whatever behavior you want.
onExtractedCursorMovement
open fun onExtractedCursorMovement(
dx: Int,
dy: Int
): Unit
This is called when the user has performed a cursor movement in the extracted text view, when it is running in fullscreen mode. The default implementation hides the candidates view when a vertical movement happens, but only if the extracted text editor has a vertical scroll bar because its text doesn't fit. Re-implement this to provide whatever behavior you want.
Parameters | |
---|---|
dx |
Int: The amount of cursor movement in the x dimension. |
dy |
Int: The amount of cursor movement in the y dimension. |
onExtractedSelectionChanged
open fun onExtractedSelectionChanged(
start: Int,
end: Int
): Unit
This is called when the user has moved the cursor in the extracted text view, when running in fullsreen mode. The default implementation performs the corresponding selection change on the underlying text editor.
onExtractedTextClicked
open fun onExtractedTextClicked(): Unit
This is called when the user has clicked on the extracted text view, when running in fullscreen mode. The default implementation hides the candidates view when this happens, but only if the extracted text editor has a vertical scroll bar because its text doesn't fit. Re-implement this to provide whatever behavior you want.
onExtractingInputChanged
open fun onExtractingInputChanged(ei: EditorInfo!): Unit
This is called when, while currently displayed in extract mode, the current input target changes. The default implementation will auto-hide the IME if the new target is not a full editor, since this can be a confusing experience for the user.
onFinishCandidatesView
open fun onFinishCandidatesView(finishingInput: Boolean): Unit
Called when the candidates view is being hidden from the user. This will be called either prior to hiding the window, or prior to switching to another target for editing.
The default implementation uses the InputConnection to clear any active composing text; you can override this (not calling the base class implementation) to perform whatever behavior you would like.
Parameters | |
---|---|
finishingInput |
Boolean: If true, onFinishInput will be called immediately after. |
onFinishInput
open fun onFinishInput(): Unit
Called to inform the input method that text input has finished in the last editor. At this point there may be a call to onStartInput(android.view.inputmethod.EditorInfo,boolean)
to perform input in a new editor, or the input method may be left idle. This method is not called when input restarts in the same editor.
The default implementation uses the InputConnection to clear any active composing text; you can override this (not calling the base class implementation) to perform whatever behavior you would like.
onFinishInputView
open fun onFinishInputView(finishingInput: Boolean): Unit
Called when the input view is being hidden from the user. This will be called either prior to hiding the window, or prior to switching to another target for editing.
The default implementation uses the InputConnection to clear any active composing text; you can override this (not calling the base class implementation) to perform whatever behavior you would like.
Parameters | |
---|---|
finishingInput |
Boolean: If true, onFinishInput will be called immediately after. |
onFinishStylusHandwriting
open fun onFinishStylusHandwriting(): Unit
Called when the current stylus handwriting session was finished (either by the system or via finishStylusHandwriting()
. When this is called, the ink window has been made invisible, and the IME no longer intercepts handwriting-related MotionEvent
s.
onGenericMotionEvent
open fun onGenericMotionEvent(event: MotionEvent!): Boolean
Override this to intercept generic motion events before they are processed by the application. If you return true, the application will not itself process the event. If you return false, the normal application processing will occur as if the IME had not seen the event at all.
Parameters | |
---|---|
event |
MotionEvent!: The motion event being received. |
Return | |
---|---|
Boolean |
True if the event was handled in this function, false otherwise. |
onInitializeInterface
open fun onInitializeInterface(): Unit
This is a hook that subclasses can use to perform initialization of their interface. It is called for you prior to any of your UI objects being created, both after the service is first created and after a configuration change happens.
onInlineSuggestionsResponse
open fun onInlineSuggestionsResponse(response: InlineSuggestionsResponse): Boolean
Called when Autofill responds back with InlineSuggestionsResponse
containing inline suggestions.
Should be implemented by subclasses.
Parameters | |
---|---|
response |
InlineSuggestionsResponse: InlineSuggestionsResponse passed back by Autofill. This value cannot be null . |
Return | |
---|---|
Boolean |
Whether the IME will use and render the inline suggestions. |
onKeyDown
open fun onKeyDown(
keyCode: Int,
event: KeyEvent!
): Boolean
Called back when a KeyEvent
is forwarded from the target application.
The default implementation intercepts KeyEvent#KEYCODE_BACK
if the IME is currently shown , to possibly hide it when the key goes up (if not canceled or long pressed). In addition, in fullscreen mode only, it will consume DPAD movement events to move the cursor in the extracted text view, not allowing them to perform navigation in the underlying application.
The default implementation does not take flags specified to setBackDisposition(int)
into account, even on API version android.os.Build.VERSION_CODES#P
and later devices. IME developers are responsible for making sure that their special handling for KeyEvent#KEYCODE_BACK
are consistent with the flag they specified to setBackDisposition(int)
.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode() |
event |
KeyEvent!: Description of the key event |
Return | |
---|---|
Boolean |
true if the event is consumed by the IME and the application no longer needs to consume it. Return false when the event should be handled as if the IME had not seen the event at all. |
onKeyLongPress
open fun onKeyLongPress(
keyCode: Int,
event: KeyEvent!
): Boolean
Default implementation of KeyEvent.Callback.onKeyLongPress()
: always returns false (doesn't handle the event).
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent!: Description of the key event. |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyMultiple
open fun onKeyMultiple(
keyCode: Int,
count: Int,
event: KeyEvent!
): Boolean
Override this to intercept special key multiple events before they are processed by the application. If you return true, the application will not itself process the event. If you return false, the normal application processing will occur as if the IME had not seen the event at all.
The default implementation always returns false, except when in fullscreen mode, where it will consume DPAD movement events to move the cursor in the extracted text view, not allowing them to perform navigation in the underlying application.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
count |
Int: Number of pairs as returned by event.getRepeatCount(). |
event |
KeyEvent!: Description of the key event. |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyUp
open fun onKeyUp(
keyCode: Int,
event: KeyEvent!
): Boolean
Override this to intercept key up events before they are processed by the application. If you return true, the application will not itself process the event. If you return false, the normal application processing will occur as if the IME had not seen the event at all.
The default implementation intercepts KeyEvent.KEYCODE_BACK
to hide the current IME UI if it is shown. In addition, in fullscreen mode only, it will consume DPAD movement events to move the cursor in the extracted text view, not allowing them to perform navigation in the underlying application.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent!: Description of the key event. |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onPrepareStylusHandwriting
open fun onPrepareStylusHandwriting(): Unit
Called to prepare stylus handwriting. The system calls this before the onStartStylusHandwriting
request.
Note: The system tries to call this as early as possible, when it detects that handwriting stylus input is imminent. However, that a subsequent call to onStartStylusHandwriting
actually happens is not guaranteed.
onShowInputRequested
open fun onShowInputRequested(
flags: Int,
configChange: Boolean
): Boolean
The system has decided that it may be time to show your input method. This is called due to a corresponding call to your InputMethod.showSoftInput()
method. The default implementation uses onEvaluateInputViewShown()
, onEvaluateFullscreenMode()
, and the current configuration to decide whether the input view should be shown at this point.
Parameters | |
---|---|
configChange |
Boolean: This is true if we are re-showing due to a configuration change. |
flags |
Int: Value is either 0 or a combination of android.view.inputmethod.InputMethod#SHOW_EXPLICIT , and android.view.inputmethod.InputMethod#SHOW_FORCED |
Return | |
---|---|
Boolean |
Returns true to indicate that the window should be shown. |
onStartCandidatesView
open fun onStartCandidatesView(
editorInfo: EditorInfo!,
restarting: Boolean
): Unit
Called when only the candidates view has been shown for showing processing as the user enters text through a hard keyboard. This will always be called after onStartInput
, allowing you to do your general setup there and just view-specific setup here. You are guaranteed that onCreateCandidatesView()
will have been called some time before this function is called.
Note that this will not be called when the input method is running in full editing mode, and thus receiving onStartInputView
to initiate that operation. This is only for the case when candidates are being shown while the input method editor is hidden but wants to show its candidates UI as text is entered through some other mechanism.
Parameters | |
---|---|
editorInfo |
EditorInfo!: Description of the type of text being edited. |
restarting |
Boolean: Set to true if we are restarting input on the same text field as before. |
onStartConnectionlessStylusHandwriting
open fun onStartConnectionlessStylusHandwriting(
inputType: Int,
cursorAnchorInfo: CursorAnchorInfo?
): Boolean
Called when an app requests to start a connectionless stylus handwriting session using one of InputMethodManager#startConnectionlessStylusHandwriting(View, CursorAnchorInfo,
, android.view.inputmethod.InputMethodManager#startConnectionlessStylusHandwritingForDelegation(android.view.View,android.view.inputmethod.CursorAnchorInfo,java.util.concurrent.Executor,android.view.inputmethod.ConnectionlessHandwritingCallback)
, or android.view.inputmethod.InputMethodManager#startConnectionlessStylusHandwritingForDelegation(android.view.View,android.view.inputmethod.CursorAnchorInfo,java.lang.String,java.util.concurrent.Executor,android.view.inputmethod.ConnectionlessHandwritingCallback)
.
A connectionless stylus handwriting session differs from a regular session in that an input connection is not used to communicate with a text editor. Instead, the recognised text is delivered when the IME finishes the connectionless session using finishConnectionlessStylusHandwriting(java.lang.CharSequence)
.
If the IME can start the connectionless handwriting session, it should return true
, ensure its inking views are attached to the getStylusHandwritingWindow()
, and handle stylus input received from onStylusHandwritingMotionEvent(android.view.MotionEvent)
on the getStylusHandwritingWindow()
.
Parameters | |
---|---|
cursorAnchorInfo |
CursorAnchorInfo?: This value may be null . |
onStartInput
open fun onStartInput(
attribute: EditorInfo!,
restarting: Boolean
): Unit
Called to inform the input method that text input has started in an editor. You should use this callback to initialize the state of your input to match the state of the editor given to it.
Parameters | |
---|---|
attribute |
EditorInfo!: The attributes of the editor that input is starting in. |
restarting |
Boolean: Set to true if input is restarting in the same editor such as because the application has changed the text in the editor. Otherwise will be false, indicating this is a new session with the editor. |
onStartInputView
open fun onStartInputView(
editorInfo: EditorInfo!,
restarting: Boolean
): Unit
Called when the input view is being shown and input has started on a new editor. This will always be called after onStartInput
, allowing you to do your general setup there and just view-specific setup here. You are guaranteed that onCreateInputView()
will have been called some time before this function is called.
Parameters | |
---|---|
editorInfo |
EditorInfo!: Description of the type of text being edited. |
restarting |
Boolean: Set to true if we are restarting input on the same text field as before. |
onStartStylusHandwriting
open fun onStartStylusHandwriting(): Boolean
Called when an app requests stylus handwriting InputMethodManager#startStylusHandwriting(View)
. This will always be preceded by onStartInput(android.view.inputmethod.EditorInfo,boolean)
for the EditorInfo
and InputConnection
for which stylus handwriting is being requested. If the IME supports handwriting for the current input, it should return true
, ensure its inking views are attached to the getStylusHandwritingWindow()
, and handle stylus input received from onStylusHandwritingMotionEvent(android.view.MotionEvent)
on the getStylusHandwritingWindow()
via getCurrentInputConnection()
.
Return | |
---|---|
Boolean |
true if IME can honor the request, false if IME cannot at this time. |
onStylusHandwritingMotionEvent
open fun onStylusHandwritingMotionEvent(motionEvent: MotionEvent): Unit
Called after onStartStylusHandwriting()
returns true
for every Stylus MotionEvent
. By default, this method forwards all MotionEvent
s to the getStylusHandwritingWindow()
once its visible, however IME can override it to receive them sooner.
Parameters | |
---|---|
motionEvent |
MotionEvent: MotionEvent from stylus. This value cannot be null . |
onTrackballEvent
open fun onTrackballEvent(event: MotionEvent!): Boolean
Override this to intercept trackball motion events before they are processed by the application. If you return true, the application will not itself process the event. If you return false, the normal application processing will occur as if the IME had not seen the event at all.
Parameters | |
---|---|
event |
MotionEvent!: The motion event being received. |
Return | |
---|---|
Boolean |
True if the event was handled in this function, false otherwise. |
onUnbindInput
open fun onUnbindInput(): Unit
Called when the previous bound client is no longer associated with the input method. After returning getCurrentInputBinding
and getCurrentInputConnection
will no longer return valid objects.
onUpdateCursor
open funonUpdateCursor(newCursor: Rect!): Unit
Deprecated: Use onUpdateCursorAnchorInfo(android.view.inputmethod.CursorAnchorInfo)
instead.
Called when the application has reported a new location of its text cursor. This is only called if explicitly requested by the input method. The default implementation does nothing.
onUpdateCursorAnchorInfo
open fun onUpdateCursorAnchorInfo(cursorAnchorInfo: CursorAnchorInfo!): Unit
Called when the application has reported a new location of its text insertion point and characters in the composition string. This is only called if explicitly requested by the input method. The default implementation does nothing.
Parameters | |
---|---|
cursorAnchorInfo |
CursorAnchorInfo!: The positional information of the text insertion point and the composition string. |
onUpdateEditorToolType
open fun onUpdateEditorToolType(toolType: Int): Unit
Called when the user tapped or clicked an editor. This can be useful when IME makes a decision of showing Virtual keyboard based on what MotionEvent#getToolType(int)
was used to click the editor. e.g. when toolType is MotionEvent#TOOL_TYPE_STYLUS
, IME may choose to show a companion widget instead of normal virtual keyboard.
This method is called after onStartInput(android.view.inputmethod.EditorInfo,boolean)
and before onStartInputView(android.view.inputmethod.EditorInfo,boolean)
when editor was clicked with a known tool type.
Default implementation does nothing.
Parameters | |
---|---|
toolType |
Int: what MotionEvent#getToolType(int) was used to click on editor. Value is android.view.MotionEvent#TOOL_TYPE_UNKNOWN , android.view.MotionEvent#TOOL_TYPE_FINGER , android.view.MotionEvent#TOOL_TYPE_STYLUS , android.view.MotionEvent#TOOL_TYPE_MOUSE , android.view.MotionEvent#TOOL_TYPE_ERASER , or android.view.MotionEvent.TOOL_TYPE_PALM |
onUpdateExtractedText
open fun onUpdateExtractedText(
token: Int,
text: ExtractedText!
): Unit
Called when the application has reported new extracted text to be shown due to changes in its current text state. The default implementation here places the new text in the extract edit text, when the input method is running in fullscreen mode.
onUpdateExtractingViews
open fun onUpdateExtractingViews(ei: EditorInfo!): Unit
Called when the fullscreen-mode extracting editor info has changed, to update the state of its UI such as the action buttons shown. You do not need to deal with this if you are using the standard full screen extract UI. If replacing it, you will need to re-implement this to put the appropriate action button in your own UI and handle it, and perform any other changes.
The standard implementation turns on or off its accessory area depending on whether there is an action button, and hides or shows the entire extract area depending on whether it makes sense for the current editor. In particular, a InputType#TYPE_NULL
or InputType#TYPE_TEXT_VARIATION_FILTER
input type will turn off the extract area since there is no text to be shown.
onUpdateExtractingVisibility
open fun onUpdateExtractingVisibility(ei: EditorInfo!): Unit
Called when the fullscreen-mode extracting editor info has changed, to determine whether the extracting (extract text and candidates) portion of the UI should be shown. The standard implementation hides or shows the extract area depending on whether it makes sense for the current editor. In particular, a InputType#TYPE_NULL
input type or EditorInfo#IME_FLAG_NO_EXTRACT_UI
flag will turn off the extract area since there is no text to be shown.
onUpdateSelection
open fun onUpdateSelection(
oldSelStart: Int,
oldSelEnd: Int,
newSelStart: Int,
newSelEnd: Int,
candidatesStart: Int,
candidatesEnd: Int
): Unit
Called when the application has reported a new selection region of the text. This is called whether or not the input method has requested extracted text updates, although if so it will not receive this call if the extracted text has changed as well.
The default implementation takes care of updating the cursor in the extract text, if it is being shown.
onViewClicked
open funonViewClicked(focusChanged: Boolean): Unit
Deprecated: The method may not be called for composite View
that works as a giant "Canvas", which can host its own UI hierarchy and sub focus state. android.webkit.WebView
is a good example. Application / IME developers should not rely on this method. If your goal is just being notified when an on-going input is interrupted, simply monitor onFinishInput()
. If your goal is to know what MotionEvent#getToolType(int)
clicked on editor, use onUpdateEditorToolType(int)
instead.
Called when the user tapped or clicked a text view. IMEs can't rely on this method being called because this was not part of the original IME protocol, so applications with custom text editing written before this method appeared will not call to inform the IME of this interaction.
Parameters | |
---|---|
focusChanged |
Boolean: true if the user changed the focused view by this click. |
onWindowHidden
open fun onWindowHidden(): Unit
Called when the input method window has been hidden from the user, after previously being visible.
onWindowShown
open fun onWindowShown(): Unit
Called immediately before the input method window is shown to the user. You could override this to prepare for the window to be shown (update view structure etc).
requestHideSelf
open fun requestHideSelf(flags: Int): Unit
Close this input method's soft input area, removing it from the display. The input method will continue running, but the user can no longer use it to generate input by touching the screen.
Parameters | |
---|---|
flags |
Int: Value is either 0 or a combination of android.view.inputmethod.InputMethodManager#HIDE_IMPLICIT_ONLY , and android.view.inputmethod.InputMethodManager#HIDE_NOT_ALWAYS |
requestShowSelf
fun requestShowSelf(flags: Int): Unit
Show the input method's soft input area, so the user sees the input method window and can interact with it.
Parameters | |
---|---|
flags |
Int: Value is either 0 or a combination of android.view.inputmethod.InputMethodManager#SHOW_IMPLICIT , and android.view.inputmethod.InputMethodManager#SHOW_FORCED |
sendDefaultEditorAction
open fun sendDefaultEditorAction(fromEnterKey: Boolean): Boolean
Ask the input target to execute its default action via InputConnection.performEditorAction()
.
For compatibility, this method does not execute a custom action even if EditorInfo.actionLabel
is set. The implementor should directly call InputConnection.performEditorAction()
with EditorInfo.actionId
if they want to execute a custom action.
Parameters | |
---|---|
fromEnterKey |
Boolean: If true, this will be executed as if the user had pressed an enter key on the keyboard, that is it will not be done if the editor has set EditorInfo.IME_FLAG_NO_ENTER_ACTION . If false, the action will be sent regardless of how the editor has set that flag. |
Return | |
---|---|
Boolean |
Returns a boolean indicating whether an action has been sent. If false, either the editor did not specify a default action or it does not want an action from the enter key. If true, the action was sent (or there was no input connection at all). |
sendDownUpKeyEvents
open fun sendDownUpKeyEvents(keyEventCode: Int): Unit
Send the given key event code (as defined by KeyEvent
) to the current input connection is a key down + key up event pair. The sent events have KeyEvent.FLAG_SOFT_KEYBOARD
set, so that the recipient can identify them as coming from a software input method, and KeyEvent.FLAG_KEEP_TOUCH_MODE
, so that they don't impact the current touch mode of the UI.
Note that it's discouraged to send such key events in normal operation; this is mainly for use with android.text.InputType#TYPE_NULL
type text fields, or for non-rich input methods. A reasonably capable software input method should use the android.view.inputmethod.InputConnection#commitText family of methods to send text to an application, rather than sending key events.
Parameters | |
---|---|
keyEventCode |
Int: The raw key code to send, as defined by KeyEvent . |
sendKeyChar
open fun sendKeyChar(charCode: Char): Unit
Send the given UTF-16 character to the current input connection. Most characters will be delivered simply by calling android.view.inputmethod.InputConnection#commitText with the character; some, however, may be handled different. In particular, the enter character ('\n') will either be delivered as an action code or a raw key event, as appropriate. Consider this as a convenience method for IMEs that do not have a full implementation of actions; a fully complying IME will decide of the right action for each event and will likely never call this method except maybe to handle events coming from an actual hardware keyboard.
Parameters | |
---|---|
charCode |
Char: The UTF-16 character code to send. |
setBackDisposition
open fun setBackDisposition(disposition: Int): Unit
Sets the disposition mode that indicates the expected affordance for the back button.
Keep in mind that specifying this flag does not change the the default behavior of onKeyDown(int,android.view.KeyEvent)
. It is IME developers' responsibility for making sure that their custom implementation of onKeyDown(int,android.view.KeyEvent)
is consistent with the mode specified to this API.
See Also
setCandidatesView
open fun setCandidatesView(view: View!): Unit
Replaces the current candidates view with a new one. You only need to call this when dynamically changing the view; normally, you should implement onCreateCandidatesView()
and create your view when first needed by the input method.
setCandidatesViewShown
open fun setCandidatesViewShown(shown: Boolean): Unit
Controls the visibility of the candidates display area. By default it is hidden.
setExtractViewShown
open fun setExtractViewShown(shown: Boolean): Unit
Controls the visibility of the extracted text area. This only applies when the input method is in fullscreen mode, and thus showing extracted text. When false, the extracted text will not be shown, allowing some of the application to be seen behind. This is normally set for you by onUpdateExtractingVisibility
. This controls the visibility of both the extracted text and candidate view; the latter since it is not useful if there is no text to see.
setInputView
open fun setInputView(view: View!): Unit
Replaces the current input view with a new one. You only need to call this when dynamically changing the view; normally, you should implement onCreateInputView()
and create your view when first needed by the input method.
setStylusHandwritingSessionTimeout
fun setStylusHandwritingSessionTimeout(duration: Duration): Unit
Sets the duration after which an ongoing stylus handwriting session that hasn't received new MotionEvent
s will time out and finishStylusHandwriting()
will be called. The maximum allowed duration is returned by getStylusHandwritingIdleTimeoutMax()
, larger values will be clamped. Note: this value is bound to the InputMethodService
instance and resets to the default whenever a new instance is constructed.
Parameters | |
---|---|
duration |
Duration: timeout to set. This value cannot be null . |
setTheme
open fun setTheme(theme: Int): Unit
You can call this to customize the theme used by your IME's window. This theme should typically be one that derives from android.R.style#Theme_InputMethod
, which is the default theme you will get. This must be set before onCreate
, so you will typically call it in your constructor with the resource ID of your custom theme.
Parameters | |
---|---|
resid |
The style resource describing the theme. |
shouldOfferSwitchingToNextInputMethod
fun shouldOfferSwitchingToNextInputMethod(): Boolean
Returns true if the current IME needs to offer the users ways to switch to a next input method (e.g. a globe key.). When an IME sets supportsSwitchingToNextInputMethod and this method returns true, the IME has to offer ways to to invoke switchToNextInputMethod
accordingly.
Note that the system determines the most appropriate next input method and subtype in order to provide the consistent user experience in switching between IMEs and subtypes.
switchInputMethod
open fun switchInputMethod(id: String!): Unit
Force switch to a new input method, as identified by id. This input method will be destroyed, and the requested one started on the current input field.
Parameters | |
---|---|
id |
String!: Unique identifier of the new input method to start. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the input method is unknown or filtered by the rules of package visibility. |
switchInputMethod
fun switchInputMethod(
id: String!,
subtype: InputMethodSubtype!
): Unit
Force switch to a new input method, as identified by id
. This input method will be destroyed, and the requested one started on the current input field.
Parameters | |
---|---|
id |
String!: Unique identifier of the new input method to start. |
subtype |
InputMethodSubtype!: The new subtype of the new input method to be switched to. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the input method is unknown or filtered by the rules of package visibility. |
switchToNextInputMethod
fun switchToNextInputMethod(onlyCurrentIme: Boolean): Boolean
Force switch to the next input method and subtype. If there is no IME enabled except current IME and subtype, do nothing.
Parameters | |
---|---|
onlyCurrentIme |
Boolean: if true, the framework will find the next subtype which belongs to the current IME |
Return | |
---|---|
Boolean |
true if the current input method and subtype was successfully switched to the next input method and subtype. |
switchToPreviousInputMethod
fun switchToPreviousInputMethod(): Boolean
Force switch to the last used input method and subtype. If the last input method didn't have any subtypes, the framework will simply switch to the last input method with no subtype specified.
Return | |
---|---|
Boolean |
true if the current input method and subtype was successfully switched to the last used input method and subtype. |
updateFullscreenMode
open fun updateFullscreenMode(): Unit
Re-evaluate whether the input method should be running in fullscreen mode, and update its UI if this has changed since the last time it was evaluated. This will call onEvaluateFullscreenMode()
to determine whether it should currently run in fullscreen mode. You can use isFullscreenMode()
to determine if the input method is currently running in fullscreen mode.
updateInputViewShown
open fun updateInputViewShown(): Unit
Re-evaluate whether the soft input area should currently be shown, and update its UI if this has changed since the last time it was evaluated. This will call onEvaluateInputViewShown()
to determine whether the input view should currently be shown. You can use isInputViewShown()
to determine if the input view is currently shown.
Protected methods
dump
protected open fun dump(
fd: FileDescriptor!,
fout: PrintWriter!,
args: Array<String!>!
): Unit
Performs a dump of the InputMethodService's internal state. Override to add your own information to the dump.
Parameters | |
---|---|
fd |
FileDescriptor!: The raw file descriptor that the dump is being sent to. |
writer |
The PrintWriter to which you should dump your state. This will be closed for you after you return. |
args |
Array<String!>!: additional arguments to the dump request. |
onCurrentInputMethodSubtypeChanged
protected open fun onCurrentInputMethodSubtypeChanged(newSubtype: InputMethodSubtype!): Unit
Called when the subtype was changed.
Parameters | |
---|---|
newSubtype |
InputMethodSubtype!: the subtype which is being changed to. |