public class InputMethodService extends AbstractInputMethodService
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(android.view.inputmethod.EditorInfo, boolean)
to deal with an input session starting with
the client.
onCreateInputView()
, onCreateCandidatesView()
,
and onCreateExtractTextView()
for non-demand generation of the UI.
onStartInputView(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 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:
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.
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.
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(CompletionInfo[])
to show completions
generated by your application, typically in your candidates view like you
would normally show candidates.
The key part of an IME is of course generating text for the application.
This is done through calls to the
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 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(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.
Modifier and Type | Class and Description |
---|---|
class |
InputMethodService.InputMethodImpl
Concrete implementation of
AbstractInputMethodService.AbstractInputMethodImpl that provides
all of the standard behavior for an input method. |
class |
InputMethodService.InputMethodSessionImpl
Concrete implementation of
AbstractInputMethodService.AbstractInputMethodSessionImpl that provides
all of the standard behavior for an input method session. |
static class |
InputMethodService.Insets
Information about where interesting parts of the input method UI appear.
|
AbstractInputMethodService.AbstractInputMethodImpl, AbstractInputMethodService.AbstractInputMethodSessionImpl
Service.StartArgFlags, Service.StartResult, Service.StopForegroundFlags
Context.BindServiceFlags, Context.CreatePackageOptions, Context.ServiceName
Modifier and Type | Field and Description |
---|---|
static int |
BACK_DISPOSITION_DEFAULT
The back button will close the input window.
|
static int |
BACK_DISPOSITION_WILL_DISMISS
This input method will consume the back key.
|
static int |
BACK_DISPOSITION_WILL_NOT_DISMISS
This input method will not consume the back key.
|
static int |
IME_ACTIVE |
static int |
IME_VISIBLE |
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, START_TASK_REMOVED_COMPLETE, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_REMOVE
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_ALLOW_WHITELIST_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_FOREGROUND_SERVICE, BIND_FOREGROUND_SERVICE_WHILE_AWAKE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_SHOWING_UI, BIND_TREAT_LIKE_ACTIVITY, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_CREDENTIAL_PROTECTED_STORAGE, CONTEXT_DEVICE_PROTECTED_STORAGE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_REGISTER_PACKAGE, CONTEXT_RESTRICTED, CONTEXTHUB_SERVICE, COUNTRY_DETECTOR, DEVICE_IDLE_CONTROLLER, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, ETHERNET_SERVICE, FINGERPRINT_SERVICE, GATEKEEPER_SERVICE, HARDWARE_PROPERTIES_SERVICE, HDMI_CONTROL_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_SCORE_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, PERSISTENT_DATA_BLOCK_SERVICE, POWER_SERVICE, PRINT_SERVICE, RADIO_SERVICE, RECOVERY_SERVICE, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SHORTCUT_SERVICE, SIP_SERVICE, SOUND_TRIGGER_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TRUST_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, VOICE_INTERACTION_MANAGER_SERVICE, WALLPAPER_SERVICE, WIFI_NAN_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_SERVICE, WIFI_SCANNING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
InputMethodService() |
Modifier and Type | Method and Description |
---|---|
protected void |
dump(FileDescriptor fd,
PrintWriter fout,
String[] args)
Performs a dump of the InputMethodService's internal state.
|
boolean |
enableHardwareAcceleration()
Deprecated.
Starting in API 21, hardware acceleration is always enabled
on capable devices.
|
void |
exposeContent(InputContentInfo inputContentInfo,
InputConnection inputConnection)
Allow the receiver of
InputContentInfo to obtain a temporary read-only access
permission to the content. |
int |
getBackDisposition() |
int |
getCandidatesHiddenVisibility()
Returns the visibility mode (either
View.INVISIBLE
or View.GONE ) of the candidates view when it is not
shown. |
InputBinding |
getCurrentInputBinding()
Return the currently active InputBinding for the input method, or
null if there is none.
|
InputConnection |
getCurrentInputConnection()
Retrieve the currently active InputConnection that is bound to
the input method, or null if there is none.
|
EditorInfo |
getCurrentInputEditorInfo() |
boolean |
getCurrentInputStarted() |
int |
getInputMethodWindowRecommendedHeight() |
LayoutInflater |
getLayoutInflater() |
int |
getMaxWidth()
Return the maximum width, in pixels, available the input method.
|
CharSequence |
getTextForImeAction(int imeOptions)
Return text that can be used as a button label for the given
EditorInfo.imeOptions . |
Dialog |
getWindow() |
void |
hideStatusIcon() |
void |
hideWindow() |
boolean |
isExtractViewShown()
Return whether the fullscreen extract view is shown.
|
boolean |
isFullscreenMode()
Return whether the input method is currently running in
fullscreen mode.
|
boolean |
isInputViewShown()
Return whether the soft input view is currently shown to the
user.
|
boolean |
isShowInputRequested()
Returns true if we have been asked to show our input view.
|
void |
onAppPrivateCommand(String action,
Bundle data) |
void |
onBindInput()
Called when a new client has bound to the input method.
|
void |
onComputeInsets(InputMethodService.Insets outInsets)
Compute the interesting insets into your UI.
|
void |
onConfigurationChanged(Configuration newConfig)
Take care of handling configuration changes.
|
void |
onConfigureWindow(Window win,
boolean isFullscreen,
boolean isCandidatesOnly)
Update the given window's parameters for the given mode.
|
void |
onCreate()
Called by the system when the service is first created.
|
View |
onCreateCandidatesView()
Create and return the view hierarchy used to show candidates.
|
View |
onCreateExtractTextView()
Called by the framework to create the layout for showing extacted text.
|
AbstractInputMethodService.AbstractInputMethodImpl |
onCreateInputMethodInterface()
Implement to return our standard
InputMethodService.InputMethodImpl . |
AbstractInputMethodService.AbstractInputMethodSessionImpl |
onCreateInputMethodSessionInterface()
Implement to return our standard
InputMethodService.InputMethodSessionImpl . |
View |
onCreateInputView()
Create and return the view hierarchy used for the input area (such as
a soft keyboard).
|
protected void |
onCurrentInputMethodSubtypeChanged(InputMethodSubtype newSubtype)
Called when the subtype was changed.
|
void |
onDestroy()
Called by the system to notify a Service that it is no longer used and is being removed.
|
void |
onDisplayCompletions(CompletionInfo[] completions)
Called when the application has reported auto-completion candidates that
it would like to have the input method displayed.
|
boolean |
onEvaluateFullscreenMode()
Override this to control when the input method should run in
fullscreen mode.
|
boolean |
onEvaluateInputViewShown()
Override this to control when the soft input area should be shown to the user.
|
void |
onExtractedCursorMovement(int dx,
int dy)
This is called when the user has performed a cursor movement in the
extracted text view, when it is running in fullscreen mode.
|
void |
onExtractedDeleteText(int start,
int end) |
void |
onExtractedReplaceText(int start,
int end,
CharSequence text) |
void |
onExtractedSelectionChanged(int start,
int end)
This is called when the user has moved the cursor in the extracted
text view, when running in fullsreen mode.
|
void |
onExtractedSetSpan(Object span,
int start,
int end,
int flags) |
void |
onExtractedTextClicked()
This is called when the user has clicked on the extracted text view,
when running in fullscreen mode.
|
void |
onExtractingInputChanged(EditorInfo ei)
This is called when, while currently displayed in extract mode, the
current input target changes.
|
boolean |
onExtractTextContextMenuItem(int id)
This is called when the user has selected a context menu item from the
extracted text view, when running in fullscreen mode.
|
void |
onFinishCandidatesView(boolean finishingInput)
Called when the candidates view is being hidden from the user.
|
void |
onFinishInput()
Called to inform the input method that text input has finished in
the last editor.
|
void |
onFinishInputView(boolean finishingInput)
Called when the input view is being hidden from the user.
|
boolean |
onGenericMotionEvent(MotionEvent event)
Override this to intercept generic motion events before they are
processed by the application.
|
void |
onInitializeInterface()
This is a hook that subclasses can use to perform initialization of
their interface.
|
boolean |
onKeyDown(int keyCode,
KeyEvent event)
Override this to intercept key down events before they are processed by the
application.
|
boolean |
onKeyLongPress(int keyCode,
KeyEvent event)
Default implementation of
KeyEvent.Callback.onKeyLongPress() : always returns false (doesn't handle
the event). |
boolean |
onKeyMultiple(int keyCode,
int count,
KeyEvent event)
Override this to intercept special key multiple events before they are
processed by the
application.
|
boolean |
onKeyUp(int keyCode,
KeyEvent event)
Override this to intercept key up events before they are processed by the
application.
|
boolean |
onShowInputRequested(int flags,
boolean configChange)
The system has decided that it may be time to show your input method.
|
void |
onStartCandidatesView(EditorInfo info,
boolean restarting)
Called when only the candidates view has been shown for showing
processing as the user enters text through a hard keyboard.
|
void |
onStartInput(EditorInfo attribute,
boolean restarting)
Called to inform the input method that text input has started in an
editor.
|
void |
onStartInputView(EditorInfo info,
boolean restarting)
Called when the input view is being shown and input has started on
a new editor.
|
boolean |
onTrackballEvent(MotionEvent event)
Override this to intercept trackball motion events before they are
processed by the application.
|
void |
onUnbindInput()
Called when the previous bound client is no longer associated
with the input method.
|
void |
onUpdateCursor(Rect newCursor)
Deprecated.
Use {#link onUpdateCursorAnchorInfo(CursorAnchorInfo)} instead.
|
void |
onUpdateCursorAnchorInfo(CursorAnchorInfo cursorAnchorInfo)
Called when the application has reported a new location of its text insertion point and
characters in the composition string.
|
void |
onUpdateExtractedText(int token,
ExtractedText text)
Called when the application has reported new extracted text to be shown
due to changes in its current text state.
|
void |
onUpdateExtractingViews(EditorInfo ei)
Called when the fullscreen-mode extracting editor info has changed,
to update the state of its UI such as the action buttons shown.
|
void |
onUpdateExtractingVisibility(EditorInfo ei)
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.
|
void |
onUpdateSelection(int oldSelStart,
int oldSelEnd,
int newSelStart,
int newSelEnd,
int candidatesStart,
int candidatesEnd)
Called when the application has reported a new selection region of
the text.
|
void |
onViewClicked(boolean focusChanged)
Called when the user tapped or clicked a text view.
|
void |
onWindowHidden()
Called when the input method window has been hidden from the user,
after previously being visible.
|
void |
onWindowShown()
Called when the input method window has been shown to the user, after
previously not being visible.
|
void |
requestHideSelf(int flags)
Close this input method's soft input area, removing it from the display.
|
boolean |
sendDefaultEditorAction(boolean fromEnterKey)
Ask the input target to execute its default action via
InputConnection.performEditorAction() . |
void |
sendDownUpKeyEvents(int keyEventCode)
Send the given key event code (as defined by
KeyEvent ) to the
current input connection is a key down + key up event pair. |
void |
sendKeyChar(char charCode)
Send the given UTF-16 character to the current input connection.
|
void |
setBackDisposition(int disposition) |
void |
setCandidatesView(View view)
Replaces the current candidates view with a new one.
|
void |
setCandidatesViewShown(boolean shown)
Controls the visibility of the candidates display area.
|
void |
setExtractView(View view) |
void |
setExtractViewShown(boolean shown)
Controls the visibility of the extracted text area.
|
void |
setInputView(View view)
Replaces the current input view with a new one.
|
void |
setTheme(int theme)
You can call this to customize the theme used by your IME's window.
|
void |
showStatusIcon(int iconResId) |
void |
showWindow(boolean showInput) |
void |
switchInputMethod(String id)
Force switch to a new input method, as identified by id.
|
void |
updateFullscreenMode()
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.
|
void |
updateInputViewShown()
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.
|
getKeyDispatcherState, onBind
attach, getApplication, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, onUnbind, setForeground, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
attachBaseContext, bindService, bindServiceAsUser, canStartActivityForResult, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermission, clearWallpaper, createApplicationContext, createConfigurationContext, createCredentialProtectedStorageContext, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getBasePackageName, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getDisplay, getDisplayAdjustments, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPreferences, getSharedPreferencesPath, getSystemService, getSystemServiceName, getTheme, getThemeResId, getUserId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isCredentialProtectedStorage, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastMultiplePermissions, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, setWallpaper, startActivities, startActivities, startActivitiesAsUser, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startActivityForResult, startInstrumentation, startIntentSender, startIntentSender, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver
bindServiceAsUser, createCredentialEncryptedStorageContext, createDeviceEncryptedStorageContext, getColor, getColorStateList, getDrawable, getSharedPrefsFile, getString, getString, getSystemService, getText, isCredentialEncryptedStorage, isDeviceEncryptedStorage, migrateDatabaseFrom, migrateSharedPreferencesFrom, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
public static final int BACK_DISPOSITION_DEFAULT
public static final int BACK_DISPOSITION_WILL_NOT_DISMISS
public static final int BACK_DISPOSITION_WILL_DISMISS
public static final int IME_ACTIVE
public static final int IME_VISIBLE
public void setTheme(int theme)
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.setTheme
in class ContextWrapper
theme
- The style resource describing the theme.public boolean enableHardwareAcceleration()
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
returns true if it succeeds otherwise false if you will need to draw
in software. You must be able to handle either case.public void onCreate()
Service
public void onInitializeInterface()
public void onDestroy()
Service
public void onConfigurationChanged(Configuration newConfig)
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(android.view.inputmethod.EditorInfo, boolean)
if input is active, and
onCreateInputView()
and onStartInputView(android.view.inputmethod.EditorInfo, boolean)
and related
appropriate functions if the UI is displayed.
onConfigurationChanged
in interface ComponentCallbacks
onConfigurationChanged
in class Service
newConfig
- The new device configuration.public AbstractInputMethodService.AbstractInputMethodImpl onCreateInputMethodInterface()
InputMethodService.InputMethodImpl
. Subclasses
can override to provide their own customized version.onCreateInputMethodInterface
in class AbstractInputMethodService
public AbstractInputMethodService.AbstractInputMethodSessionImpl onCreateInputMethodSessionInterface()
InputMethodService.InputMethodSessionImpl
. Subclasses
can override to provide their own customized version.onCreateInputMethodSessionInterface
in class AbstractInputMethodService
public LayoutInflater getLayoutInflater()
public Dialog getWindow()
public void setBackDisposition(int disposition)
public int getBackDisposition()
public int getMaxWidth()
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.
public InputBinding getCurrentInputBinding()
public InputConnection getCurrentInputConnection()
public boolean getCurrentInputStarted()
public EditorInfo getCurrentInputEditorInfo()
public void updateFullscreenMode()
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.public void onConfigureWindow(Window win, boolean isFullscreen, boolean isCandidatesOnly)
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.
win
- The input method's window.isFullscreen
- If true, the window is running in fullscreen mode
and intended to cover the entire application display.isCandidatesOnly
- 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.public boolean isFullscreenMode()
updateFullscreenMode()
.public boolean onEvaluateFullscreenMode()
updateFullscreenMode()
yourself whenever the returned value may have changed to have it
re-evaluated and applied.public void setExtractViewShown(boolean shown)
onUpdateExtractingVisibility(android.view.inputmethod.EditorInfo)
. 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.public boolean isExtractViewShown()
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).public void onComputeInsets(InputMethodService.Insets outInsets)
InputMethodService.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.
outInsets
- Fill in with the current UI insets.public void updateInputViewShown()
onEvaluateInputViewShown()
to
determine whether the input view should currently be shown. You
can use isInputViewShown()
to determine if the input view
is currently shown.public boolean isShowInputRequested()
public boolean isInputViewShown()
updateInputViewShown()
.public boolean onEvaluateInputViewShown()
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.
public void setCandidatesViewShown(boolean shown)
public int getCandidatesHiddenVisibility()
View.INVISIBLE
or View.GONE
) of the candidates view when it is not
shown. The default implementation returns GONE when
isExtractViewShown()
returns true,
otherwise VISIBLE. 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.public void showStatusIcon(@DrawableRes int iconResId)
public void hideStatusIcon()
public void switchInputMethod(String id)
id
- Unique identifier of the new input method ot start.public void setExtractView(View view)
public void setCandidatesView(View view)
onCreateCandidatesView()
and create your view when
first needed by the input method.public void setInputView(View view)
onCreateInputView()
and create your view when
first needed by the input method.public View onCreateExtractTextView()
ExtractEditText
whose ID is
android.R.id#inputExtractEditText
.public View onCreateCandidatesView()
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(View)
.
public View onCreateInputView()
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(View)
.
public void onStartInputView(EditorInfo info, boolean restarting)
onStartInput(android.view.inputmethod.EditorInfo, boolean)
,
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.info
- Description of the type of text being edited.restarting
- Set to true if we are restarting input on the
same text field as before.public void onFinishInputView(boolean finishingInput)
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.
finishingInput
- If true, onFinishInput()
will be
called immediately after.public void onStartCandidatesView(EditorInfo info, boolean restarting)
onStartInput(android.view.inputmethod.EditorInfo, boolean)
,
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(android.view.inputmethod.EditorInfo, boolean)
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.
info
- Description of the type of text being edited.restarting
- Set to true if we are restarting input on the
same text field as before.public void onFinishCandidatesView(boolean finishingInput)
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.
finishingInput
- If true, onFinishInput()
will be
called immediately after.public boolean onShowInputRequested(int flags, boolean configChange)
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.flags
- Provides additional information about the show request,
as per InputMethod.showSoftInput()
.configChange
- This is true if we are re-showing due to a
configuration change.public void showWindow(boolean showInput)
public void hideWindow()
public void onWindowShown()
public void onWindowHidden()
public void onBindInput()
onStartInput(EditorInfo, boolean)
and onFinishInput()
calls as the user navigates through its
UI. Upon this call you know that getCurrentInputBinding()
and getCurrentInputConnection()
return valid objects.public void onUnbindInput()
getCurrentInputBinding()
and getCurrentInputConnection()
will no longer return
valid objects.public void onStartInput(EditorInfo attribute, boolean restarting)
attribute
- The attributes of the editor that input is starting
in.restarting
- 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.public void onFinishInput()
onStartInput(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.
public void onDisplayCompletions(CompletionInfo[] completions)
The default implementation here does nothing.
public void onUpdateExtractedText(int token, ExtractedText text)
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd)
Be careful about changing the text in reaction to this call with methods such as setComposingText, commitText or deleteSurroundingText. If the cursor moves as a result, this method will be called again, which may result in an infinite loop.
The default implementation takes care of updating the cursor in the extract text, if it is being shown.
public void onViewClicked(boolean focusChanged)
focusChanged
- true if the user changed the focused view by this click.@Deprecated public void onUpdateCursor(Rect newCursor)
public void onUpdateCursorAnchorInfo(CursorAnchorInfo cursorAnchorInfo)
cursorAnchorInfo
- The positional information of the text insertion point and the
composition string.public void requestHideSelf(int flags)
flags
- Provides additional operating flags. Currently may be
0 or have the InputMethodManager.HIDE_IMPLICIT_ONLY
bit set.public boolean onKeyDown(int keyCode, KeyEvent event)
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.
keyCode
- The value in event.getKeyCode().event
- Description of the key event.public boolean onKeyLongPress(int keyCode, KeyEvent event)
KeyEvent.Callback.onKeyLongPress()
: always returns false (doesn't handle
the event).keyCode
- The value in event.getKeyCode().event
- Description of the key event.public boolean onKeyMultiple(int keyCode, int count, KeyEvent event)
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.
keyCode
- The value in event.getKeyCode().count
- Number of pairs as returned by event.getRepeatCount().event
- Description of the key event.public boolean onKeyUp(int keyCode, KeyEvent event)
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.
keyCode
- The value in event.getKeyCode().event
- Description of the key event.public boolean onTrackballEvent(MotionEvent event)
onTrackballEvent
in class AbstractInputMethodService
event
- The motion event being received.View.onTrackballEvent(MotionEvent)
public boolean onGenericMotionEvent(MotionEvent event)
onGenericMotionEvent
in class AbstractInputMethodService
event
- The motion event being received.View.onGenericMotionEvent(MotionEvent)
public void sendDownUpKeyEvents(int keyEventCode)
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 InputType.TYPE_NULL
type
text fields, or for non-rich input methods. A reasonably capable software
input method should use the
InputConnection.commitText(java.lang.CharSequence, int)
family of methods
to send text to an application, rather than sending key events.
keyEventCode
- The raw key code to send, as defined by
KeyEvent
.public boolean sendDefaultEditorAction(boolean fromEnterKey)
InputConnection.performEditorAction()
.fromEnterKey
- 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.public void sendKeyChar(char charCode)
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.charCode
- The UTF-16 character code to send.public void onExtractedSelectionChanged(int start, int end)
public void onExtractedDeleteText(int start, int end)
public void onExtractedReplaceText(int start, int end, CharSequence text)
public void onExtractedSetSpan(Object span, int start, int end, int flags)
public void onExtractedTextClicked()
public void onExtractedCursorMovement(int dx, int dy)
dx
- The amount of cursor movement in the x dimension.dy
- The amount of cursor movement in the y dimension.public boolean onExtractTextContextMenuItem(int id)
InputConnection.performContextMenuAction(int)
, for it
to be processed in underlying "real" editor. Re-implement this to
provide whatever behavior you want.public CharSequence getTextForImeAction(int imeOptions)
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.imeOptions
- The value from @link EditorInfo#imeOptions EditorInfo.imeOptions}.public void onUpdateExtractingVisibility(EditorInfo ei)
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.public void onUpdateExtractingViews(EditorInfo ei)
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.
public void onExtractingInputChanged(EditorInfo ei)
protected void onCurrentInputMethodSubtypeChanged(InputMethodSubtype newSubtype)
newSubtype
- the subtype which is being changed to.public int getInputMethodWindowRecommendedHeight()
onStartInputView(EditorInfo, boolean)
.
If you don't need to use a predefined fixed height, you can avoid the window-resizing of IME
switching by using this value as a visible inset height. It's efficient for the smooth
transition between different IMEs. However, note that this may return 0 (or possibly
unexpectedly low height). You should thus avoid relying on the return value of this method
all the time. Please make sure to use a reasonable height for the IME.public final void exposeContent(InputContentInfo inputContentInfo, InputConnection inputConnection)
InputContentInfo
to obtain a temporary read-only access
permission to the content.exposeContent
in class AbstractInputMethodService
inputContentInfo
- Content to be temporarily exposed from the input method to the
application.
This cannot be null
.inputConnection
- InputConnection
with which
InputConnection#commitContent(InputContentInfo, Bundle)
will be called.protected void dump(FileDescriptor fd, PrintWriter fout, String[] args)
dump
in class AbstractInputMethodService
fd
- The raw file descriptor that the dump is being sent to.fout
- The PrintWriter to which you should dump your state. This will be
closed for you after you return.args
- additional arguments to the dump request.