@@ -4,6 +4,30 @@ page.tags="ime","keyboard","inputmethodservice"
44
55<div id="qv-wrapper">
66<div id="qv">
7+ <h2>In This Document</h2>
8+ <ol>
9+ <li>
10+ <a href="#InputMethodLifecycle">The IME Lifecycle</a>
11+ </li>
12+ <li>
13+ <a href="#DefiningIME">Declaring IME Components in the Manifest</a>
14+ </li>
15+ <li>
16+ <a href="#IMEAPI">The Input Method API</a>
17+ </li>
18+ <li>
19+ <a href="#IMEUI">Designing the Input Method UI</a>
20+ </li>
21+ <li>
22+ <a href="#SendText">Sending Text to the Application</a>
23+ </li>
24+ <li>
25+ <a href="#IMESubTypes">Creating an IME Subtype</a>
26+ </li>
27+ <li>
28+ <a href="#GeneralDesign">General IME Considerations</a>
29+ </li>
30+ </ol>
731<h2>See also</h2>
832<ol>
933 <li>
@@ -16,29 +40,20 @@ page.tags="ime","keyboard","inputmethodservice"
1640</div>
1741</div>
1842<p>
19- An input method editor (IME) is a user control that enables users to enter text. Android
20- provides an extensible input method framework that allows applications to provide users
21- alternative input methods, such as on-screen keyboards or even speech input. Once installed,
22- users can select which IME they want to use from the system settings and use it across the
43+ An input method editor (IME) is a user control that enables users to enter text. Android
44+ provides an extensible input method framework that allows applications to provide users
45+ alternative input methods, such as on-screen keyboards or even speech input. Once installed,
46+ users can select which IME they want to use from the system settings and use it across the
2347 entire system; only one IME may be enabled at a time.
2448</p>
2549<p>
2650 To add an IME to the Android system, you create an Android application
27- containing a class that extends {@link android.inputmethodservice.InputMethodService}. In
51+ containing a class that extends {@link android.inputmethodservice.InputMethodService}. In
2852 addition, you usually create a "settings" activity that passes options to the IME
2953 service. You can also define a settings UI that's displayed as part of the system settings.
3054</p>
31- <p>This article covers the following:</p>
32- <ul>
33- <li>The IME lifecycle.</li>
34- <li>Declaring IME components in the application manifest.</li>
35- <li>The IME API.</li>
36- <li>Designing an IME UI.</li>
37- <li>Sending text from an IME to an application.</li>
38- <li>Working with IME subtypes.</li>
39- </ul>
4055<p>
41- If you haven't worked with IMEs before, you should read the introductory article
56+ If you haven't worked with IMEs before, you should read the introductory article
4257 <a href="http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html">Onscreen Input Methods</a> first.
4358 Also, the Soft Keyboard sample app included in the SDK contains sample code that you can modify
4459 to start building your own IME.
@@ -59,16 +74,16 @@ page.tags="ime","keyboard","inputmethodservice"
5974<h2 id="DefiningIME">Declaring IME Components in the Manifest</h2>
6075<p>
6176 In the Android system, an IME is an Android application that contains a special IME service.
62- The application's manifest file must declare the service, request the necessary permissions,
63- provide an intent filter that matches the action <code>action.view.InputMethod</code>, and
77+ The application's manifest file must declare the service, request the necessary permissions,
78+ provide an intent filter that matches the action <code>action.view.InputMethod</code>, and
6479 provide metadata that defines characteristics of the IME. In addition, to provide a settings
6580 interface that allows the user to modify the behavior of the IME, you can define a "settings"
6681 activity that can be launched from System Settings.
6782</p>
6883<p>
6984 The following snippet declares IME service. It requests the permission {@link
70- android.Manifest.permission#BIND_INPUT_METHOD} to allow the service to connect the IME to
71- the system, sets up an intent filter that matches the action
85+ android.Manifest.permission#BIND_INPUT_METHOD} to allow the service to connect the IME to
86+ the system, sets up an intent filter that matches the action
7287 <code>android.view.InputMethod</code>, and defines metadata for the IME:
7388</p>
7489<pre>
@@ -88,7 +103,7 @@ page.tags="ime","keyboard","inputmethodservice"
88103 for the IME application:</p>
89104<pre>
90105 <!-- Optional: an activity for controlling the IME settings -->
91- <activity android:name="FastInputIMESettings"
106+ <activity android:name="FastInputIMESettings"
92107 android:label="@string/fast_input_settings">
93108 <intent-filter>
94109 <action android:name="android.intent.action.MAIN"/>
@@ -105,12 +120,12 @@ page.tags="ime","keyboard","inputmethodservice"
105120 handling keyboard characters.
106121</p>
107122<p>
108- The central part of an IME is a service component, a class that extends
109- {@link android.inputmethodservice.InputMethodService}. In addition to implementing the
110- normal service lifecycle, this class has callbacks for providing your IME's UI, handling user
123+ The central part of an IME is a service component, a class that extends
124+ {@link android.inputmethodservice.InputMethodService}. In addition to implementing the
125+ normal service lifecycle, this class has callbacks for providing your IME's UI, handling user
111126 input, and delivering text to the field that currently has focus. By default, the
112- {@link android.inputmethodservice.InputMethodService} class provides most of the implementation
113- for managing the state and visibility of the IME and communicating with the current
127+ {@link android.inputmethodservice.InputMethodService} class provides most of the implementation
128+ for managing the state and visibility of the IME and communicating with the current
114129 input field.
115130</p>
116131<p>
@@ -122,13 +137,13 @@ page.tags="ime","keyboard","inputmethodservice"
122137 Defines the communication channel from an {@link android.view.inputmethod.InputMethod}
123138 back to the application that is receiving its input. You use it to read text around the
124139 cursor, commit text to the text box, and send raw key events to the application.
125- Applications should extend this class rather than implementing the base interface
140+ Applications should extend this class rather than implementing the base interface
126141 {@link android.view.inputmethod.InputConnection}.
127142 </dd>
128143 <dt>{@link android.inputmethodservice.KeyboardView}</dt>
129144 <dd>
130145 An extension of {@link android.view.View} that renders a keyboard and responds to user
131- input events. The keyboard layout is specified by an instance of
146+ input events. The keyboard layout is specified by an instance of
132147 {@link android.inputmethodservice.Keyboard}, which you can define in an XML file.
133148 </dd>
134149</dl>
@@ -141,40 +156,40 @@ page.tags="ime","keyboard","inputmethodservice"
141156<h3 id="InputView">Input view</h3>
142157<p>
143158 The input view is the UI where the user inputs text, in the form of keyclicks, handwriting or
144- gestures. When the iIME is displayed for the first time, the system calls the
159+ gestures. When the iIME is displayed for the first time, the system calls the
145160 {@link android.inputmethodservice.InputMethodService#onCreateInputView()} callback. In your
146161 implementation of this method, you create the layout you want to display in the IME
147162 window and return the layout to the system. This snippet is an example of implementing the
148163 {@link android.inputmethodservice.InputMethodService#onCreateInputView()} method:
149164<pre>
150- @Override
151- public View onCreateInputView() {
152- MyKeyboardView inputView =
165+ @Override
166+ public View onCreateInputView() {
167+ MyKeyboardView inputView =
153168 (MyKeyboardView) getLayoutInflater().inflate( R.layout.input, null);
154-
155- inputView.setOnKeyboardActionListener(this); inputView.setKeyboard(mLatinKeyboard);
156-
157- return mInputView;
158- }
169+
170+ inputView.setOnKeyboardActionListener(this); inputView.setKeyboard(mLatinKeyboard);
171+
172+ return mInputView;
173+ }
159174</pre>
160175<p>
161- In this example, {@code MyKeyboardView} is an instance of a custom implementation of
162- {@link android.inputmethodservice.KeyboardView} that renders a
163- {@link android.inputmethodservice.Keyboard}. If you’re building a traditional QWERTY keyboard,
164- see the Soft Keyboard <a href="{@docRoot}tools/samples/index.html">sample
176+ In this example, {@code MyKeyboardView} is an instance of a custom implementation of
177+ {@link android.inputmethodservice.KeyboardView} that renders a
178+ {@link android.inputmethodservice.Keyboard}. If you’re building a traditional QWERTY keyboard,
179+ see the Soft Keyboard <a href="{@docRoot}tools/samples/index.html">sample
165180 app</a> for an example of how to extend the {@link android.inputmethodservice.KeyboardView} class.
166181</p>
167182<h3 id="CandidateView">Candidates view</h3>
168183<p>
169184 The candidates view is the UI where the IME displays potential word corrections or
170- suggestions for the user to select. In the IME lifecycle, the system calls
171- {@link android.inputmethodservice.InputMethodService#onCreateCandidatesView()} when it's ready
185+ suggestions for the user to select. In the IME lifecycle, the system calls
186+ {@link android.inputmethodservice.InputMethodService#onCreateCandidatesView()} when it's ready
172187 to display the candidate view. In your implementation of this method, return a layout that shows
173188 word suggestions, or return null if you don’t want to show anything (a null response is the
174189 default behavior, so you don’t have to implement this if you don’t provide suggestions).</p>
175190<p>
176- For an example implementation that provides user suggestions, see the
177- Soft Keyboard <a href="{@docRoot}tools/samples/index.html">sample
191+ For an example implementation that provides user suggestions, see the
192+ Soft Keyboard <a href="{@docRoot}tools/samples/index.html">sample
178193 app</a>.
179194</p>
180195<h3 id="DesignConsiderations">UI design considerations</h3>
@@ -209,10 +224,10 @@ page.tags="ime","keyboard","inputmethodservice"
209224 <strong>Figure 2.</strong> Latin IME input types.
210225</p>
211226<p>
212- When an input field receives focus and your IME starts, the system calls
227+ When an input field receives focus and your IME starts, the system calls
213228 {@link android.inputmethodservice.InputMethodService#onStartInputView(EditorInfo, boolean)
214- onStartInputView()}, passing in an {@link android.view.inputmethod.EditorInfo} object that
215- contains details about the input type and other attributes of the text field. In this object,
229+ onStartInputView()}, passing in an {@link android.view.inputmethod.EditorInfo} object that
230+ contains details about the input type and other attributes of the text field. In this object,
216231 the {@link android.view.inputmethod.EditorInfo#inputType} field contains the text field's input
217232 type.
218233</p>
@@ -223,7 +238,7 @@ page.tags="ime","keyboard","inputmethodservice"
223238 this:
224239</p>
225240<pre>
226- inputType & InputType.TYPE_MASK_CLASS
241+ inputType & InputType.TYPE_MASK_CLASS
227242</pre>
228243<p>
229244The input type bit pattern can have one of several values, including:
@@ -248,7 +263,7 @@ The input type bit pattern can have one of several values, including:
248263 </dd>
249264</dl>
250265<p>
251- These constants are described in more detail in the reference documentation for
266+ These constants are described in more detail in the reference documentation for
252267 {@link android.text.InputType}.
253268</p>
254269<p>
@@ -287,8 +302,8 @@ The input type bit pattern can have one of several values, including:
287302<p>
288303 As the user inputs text with your IME, you can send text to the application by
289304 sending individual key events or by editing the text around the cursor in the application's text
290- field. In either case, you use an instance of {@link android.view.inputmethod.InputConnection}
291- to deliver the text. To get this instance, call
305+ field. In either case, you use an instance of {@link android.view.inputmethod.InputConnection}
306+ to deliver the text. To get this instance, call
292307 {@link android.inputmethodservice.InputMethodService#getCurrentInputConnection
293308 InputMethodService.getCurrentInputConnection()}.
294309</p>
@@ -336,18 +351,18 @@ The input type bit pattern can have one of several values, including:
336351</p>
337352<pre>
338353 InputConnection ic = getCurrentInputConnection();
339-
354+
340355 ic.deleteSurroundingText(4, 0);
341-
356+
342357 ic.commitText("Hello", 1);
343-
358+
344359 ic.commitText("!", 1);
345360</pre>
346361<h3 id="ComposeThenCommit">Composing text before committing</h3>
347362<p>
348363 If your IME does text prediction or requires multiple steps to compose a glyph or
349364 word, you can show the progress in the text field until the user commits the word, and then you
350- can replace the partial composition with the completed text. You may give special treatment to
365+ can replace the partial composition with the completed text. You may give special treatment to
351366 the text by adding a "span" to it when you pass it to InputConnection#setComposingText().
352367</p>
353368<p>
@@ -385,18 +400,18 @@ The input type bit pattern can have one of several values, including:
385400 selection during composition. You may also want to trap the back key to dismiss any popups
386401 originating from the input method window.</p>
387402<p>
388- To intercept hardware keys, override
403+ To intercept hardware keys, override
389404 {@link android.inputmethodservice.InputMethodService#onKeyDown(int, KeyEvent) onKeyDown()}
390- and {@link android.inputmethodservice.InputMethodService#onKeyUp(int, KeyEvent) onKeyUp()}.
391- See the Soft Keyboard <a href="{@docRoot}tools/samples/index.html">sample
405+ and {@link android.inputmethodservice.InputMethodService#onKeyUp(int, KeyEvent) onKeyUp()}.
406+ See the Soft Keyboard <a href="{@docRoot}tools/samples/index.html">sample
392407 app</a> for an example.
393408</p>
394409<p>
395410 Remember to call the <code>super()</code> method for keys you don't want to handle yourself.
396411</p>
397412<h2 id="IMESubTypes">Creating an IME Subtype</h2>
398413<p>
399- Subtypes allow the IME to expose multiple input modes and languages supported by an IME. A
414+ Subtypes allow the IME to expose multiple input modes and languages supported by an IME. A
400415 subtype can represent:
401416</p>
402417<ul>
@@ -414,13 +429,13 @@ The input type bit pattern can have one of several values, including:
414429<p>
415430 Subtype information is used for an IME switcher dialog that's available from the notification
416431 bar and also for IME settings. The information also allows the framework to bring up a
417- specific subtype of an IME directly. When you build an IME, use the subtype facility, because
432+ specific subtype of an IME directly. When you build an IME, use the subtype facility, because
418433 it helps the user identify and switch between different IME languages and modes.
419434</p>
420435<p>
421436 You define subtypes in one of the input method's XML resource files, using the
422- <code><subtype></code> element. The following snippet defines an IME with two
423- subtypes: a keyboard subtype for the US English locale, and another keyboard subtype for the
437+ <code><subtype></code> element. The following snippet defines an IME with two
438+ subtypes: a keyboard subtype for the US English locale, and another keyboard subtype for the
424439 French language locale for France:
425440</p>
426441<pre>
@@ -457,8 +472,8 @@ The input type bit pattern can have one of several values, including:
457472 android:imeSubtypeMode="keyboard" />
458473</pre>
459474<p>
460- The next snippet is part of the IME's <code>strings.xml</code> file. The string
461- resource <code>label_subtype_generic</code>, which is used by the input method UI definition to
475+ The next snippet is part of the IME's <code>strings.xml</code> file. The string
476+ resource <code>label_subtype_generic</code>, which is used by the input method UI definition to
462477 set the subtype's label, is defined as:
463478</p>
464479<pre>
@@ -487,16 +502,17 @@ The input type bit pattern can have one of several values, including:
487502<h3 id="SubtypeSettings">Choosing IME subtypes from System Settings</h3>
488503<p>
489504 A user can control how subtypes are used in the “Language & input” settings panel in the
490- System Settings area. In the Soft Keyboard sample, the file
491- <code>InputMethodSettingsFragment.java</code> contains an implementation that
492- facilitates a subtype enabler in the IME settings. Please refer to the SoftKeyboard sample in
505+ System Settings area. In the Soft Keyboard sample, the file
506+ <code>InputMethodSettingsFragment.java</code> contains an implementation that
507+ facilitates a subtype enabler in the IME settings. Please refer to the SoftKeyboard sample in
493508 the Android SDK for more information about how to support Input Method Subtypes in your IME.
494509</p>
495510<img src="{@docRoot}resources/articles/images/inputmethod_subtype_settings.png" alt=""
496511 height="210" id="figure6" />
497512<p class="img-caption">
498513 <strong>Figure 6.</strong> Choosing a language for the IME.
499514</p>
515+
500516<h2 id="GeneralDesign">General IME Considerations</h2>
501517<p>
502518 Here are some other things to consider as you're implementing your IME:
@@ -506,22 +522,22 @@ The input type bit pattern can have one of several values, including:
506522 Provide a way for users to set options directly from the IME's UI.
507523</li>
508524<li>
509- Because multiple IMEs may be installed on the device, provide a way for the user to switch to a
525+ Because multiple IMEs may be installed on the device, provide a way for the user to switch to a
510526 different IME directly from the input method UI.
511527</li>
512528<li>
513- Bring up the IME's UI quickly. Preload or load on demand any large resources so that users
514- see the IME as soon as they tap on a text field. Cache resources and views for subsequent
529+ Bring up the IME's UI quickly. Preload or load on demand any large resources so that users
530+ see the IME as soon as they tap on a text field. Cache resources and views for subsequent
515531 invocations of the input method.
516532</li>
517533<li>
518- Conversely, you should release large memory allocations soon after the input method window is
534+ Conversely, you should release large memory allocations soon after the input method window is
519535 hidden, so that applications can have sufficient memory to run. Consider using a delayed message
520536 to release resources if the IME is in a hidden state for a few seconds.
521- </li>
537+ </li>
522538<li>
523- Make sure that users can enter as many characters as possible for the language or locale
524- associated with the IME. Remember that users may use punctuation in passwords or user
539+ Make sure that users can enter as many characters as possible for the language or locale
540+ associated with the IME. Remember that users may use punctuation in passwords or user
525541 names, so your IME has to provide many different characters to allow users to enter a
526542 password and get access to the device.
527543</li>
0 commit comments