Skip to content

Commit ab3b0e4

Browse files
Joe MalinAndroid Git Automerger
authored andcommitted
am 6187ba5: am 136de4e: am 6a04325: DOC CHANGE: Spell Checker article
* commit '6187ba507601c88ef4464951f9d70ae8dc97973f': DOC CHANGE: Spell Checker article
2 parents 4da5c4a + 6187ba5 commit ab3b0e4

File tree

7 files changed

+258
-2
lines changed

7 files changed

+258
-2
lines changed
47.2 KB
Loading
72.1 KB
Loading
1.86 KB
Loading
11.8 KB
Loading

docs/html/resources/articles/index.jd

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ parent.link=../browser.html?tag=article
4747
<dt><a href="{@docRoot}resources/articles/glsurfaceview.html">Introducing GLSurfaceView</a></dt>
4848
<dd>This article provides an overview of GLSurfaceView, a class that makes it easy to implement 2D or 3D OpenGL rendering inside of an Android application.</dd>
4949
</dl>
50-
50+
<dl>
51+
<dt>
52+
<a href="{@docRoot}resources/articles/spell-checker-framework.jd">
53+
Using the Spell Checker Framework</a>
54+
</dt>
55+
<dd>
56+
This article describes how to use the Spell Checker Framework to check spelling in
57+
various ways in your application.
58+
</dd>
59+
</dl>
5160
<dl>
5261
<dt><a href="{@docRoot}resources/articles/layout-tricks-reuse.html">Layout Tricks: Creating Reusable UI Components</a></dt>
5362
<dd>Learn how to combine multiple standard UI widgets into a single high-level component, which can be reused throughout your application.</dd>
@@ -149,7 +158,7 @@ parent.link=../browser.html?tag=article
149158
</dl>
150159

151160
<dl>
152-
<dt><a href="{@docRoot}resources/articles/window-bg-speed.html">Window Backgrounds & UI Speed</a></dt>
161+
<dt><a href="{@docRoot}resources/articles/window-bg-speed.html">Window Backgrounds &amp; UI Speed</a></dt>
153162
<dd>Some Android applications need to squeeze every bit of performance out of the UI toolkit and there are many ways to do so. In this article, you will discover how to speed up the drawing and the perceived startup time of your activities. Both of these techniques rely on a single feature, the window's background drawable.</dd>
154163
</dl>
155164

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
page.title=Using the Spell Checker Framework
2+
parent.title=Articles
3+
parent.link=../browser.html?tag=article
4+
@jd:body
5+
<div id="qv-wrapper">
6+
<div id="qv">
7+
<h2>In This Document</h2>
8+
<ol>
9+
<li>
10+
<a href="#SpellCheckLifeCycle">Spell Check Lifecycle</a>
11+
</li>
12+
<li>
13+
<a href="#SpellCheckImplementation">Implementing a Spell Checker Service</a>
14+
</li>
15+
<li>
16+
<a href="#SpellCheckClient">Implementing a Spell Checker Client</a>
17+
</li>
18+
</ol>
19+
<h2>See also</h2>
20+
<ol>
21+
<li>
22+
<a href="{@docRoot}resources/samples/SpellChecker/SampleSpellCheckerService/index.html">
23+
Spell Checker Service</a> sample app
24+
</li>
25+
<li>
26+
<a href="{@docRoot}resources/samples/SpellChecker/HelloSpellChecker/index.html">
27+
Spell Checker Client</a> sample app
28+
</li>
29+
</ol>
30+
</div>
31+
</div>
32+
33+
<p>
34+
The Android platform offers a spell checker framework that lets you implement
35+
and access spell checking in your application. The framework is one of the
36+
Text Service APIs offered by the Android platform.
37+
</p>
38+
<p>
39+
To use the framework in your app, you create a special type of Android service that
40+
generates a spell checker <strong>session</strong> object. Based on text you provide,
41+
the session object returns spelling suggestions generated by the spell checker.
42+
</p>
43+
<h2 id="SpellCheckLifeCycle">Spell Checker Lifecycle</h2>
44+
<p>
45+
The following diagram shows the lifecycle of the spell checker service:
46+
</p>
47+
<img src="{@docRoot}resources/articles/images/spellcheck_lifecycle.png" alt="" height="596"
48+
id="figure1" />
49+
<p class="img-caption">
50+
<strong>Figure 1.</strong> The spell checker service lifecycle.
51+
</p>
52+
<p>
53+
To initiate spell checking, your app starts its implementation of the spell checker
54+
service. Clients in your app, such as activities or individual UI elements, request a
55+
spell checker session from the service, then use the session to get suggestions for text.
56+
As a client terminates its operation, it closes its spell checker session. If necessary, your
57+
app can shut down the spell checker service at any time.
58+
</p>
59+
<h2 id="SpellCheckImplementation">Implementing a Spell Checker Service</h2>
60+
<p>
61+
To use the spell checker framework in your app, add a spell checker service component including
62+
the session object definition. You can also add to your app an optional activity that
63+
controls settings. You must also add an XML metadata file that describes
64+
the spell checker service, and add the appropriate elements to your manifest file.
65+
</p>
66+
<h3 id="SpellCheckCode">Spell checker classes</h3>
67+
<p>
68+
Define the service and session object with the following classes:
69+
</p>
70+
<dl>
71+
<dt>
72+
A subclass of {@link android.service.textservice.SpellCheckerService}
73+
</dt>
74+
<dd>
75+
The {@link android.service.textservice.SpellCheckerService} implements both the
76+
{@link android.app.Service} class and the spell checker framework interface. Within your
77+
subclass, you must implement the following method:
78+
<dl>
79+
<dt>{@link android.service.textservice.SpellCheckerService#createSession()}</dt>
80+
<dd>
81+
A factory method that returns a
82+
{@link android.service.textservice.SpellCheckerService.Session} object to a
83+
client that wants to do spell checking.
84+
</dd>
85+
</dl>
86+
<p>
87+
See the
88+
<a href="{@docRoot}resources/samples/SpellChecker/SampleSpellCheckerService/index.html">
89+
Spell Checker Service</a> sample app to learn more about implementing this class.
90+
</p>
91+
</dd>
92+
<dt>
93+
An implementation of {@link android.service.textservice.SpellCheckerService.Session}
94+
</dt>
95+
<dd>
96+
An object that the spell checker service provides to clients, to let them pass text to
97+
the spell checker and receive suggestions. Within this class, you must implement the
98+
following methods:
99+
<dl>
100+
<dt>
101+
{@link android.service.textservice.SpellCheckerService.Session#onCreate()}
102+
</dt>
103+
<dd>
104+
Called by the system in response to
105+
{@link android.service.textservice.SpellCheckerService#createSession()}. In this
106+
method, you can initialize the
107+
{@link android.service.textservice.SpellCheckerService.Session} object based on
108+
the current locale and so forth.
109+
</dd>
110+
<dt>
111+
{@link android.service.textservice.SpellCheckerService.Session#onGetSuggestions(TextInfo, int)
112+
onGetSuggestions()}
113+
</dt>
114+
<dd>
115+
Does the actual spell checking. This method returns an object containing
116+
suggestions for the text passed to it.
117+
</dd>
118+
</dl>
119+
<p>
120+
Optionally, you can implement
121+
{@link android.service.textservice.SpellCheckerService.Session#onCancel()}, which
122+
handles requests to cancel spell checking, or
123+
{@link android.service.textservice.SpellCheckerService.Session#onGetSuggestionsMultiple(TextInfo[], int, boolean)
124+
onGetSuggestionsMultiple()}, which handles batches of suggestion requests, or both.
125+
</p>
126+
<p>
127+
See the
128+
<a href="{@docRoot}resources/samples/SpellChecker/HelloSpellChecker/index.html">
129+
Spell Checker Client</a> sample app to learn more about implementing this class.
130+
</p>
131+
</dd>
132+
</dl>
133+
<p class="note">
134+
<strong>Note:</strong> You must implement all aspects of spell checking as asynchronous and
135+
thread-safe. A spell checker may be called simultaneously by different threads running on
136+
different cores. The {@link android.service.textservice.SpellCheckerService} and
137+
{@link android.service.textservice.SpellCheckerService.Session} take care of this
138+
automatically.
139+
</p>
140+
<h3 id="SpellCheckXML">Spell checker manifest and metadata</h3>
141+
<p>
142+
In addition to code, you need to provide the appropriate manifest file and a metadata file for
143+
the spell checker.
144+
</p>
145+
<p>
146+
The manifest file defines the application, the service, and the activity for controlling
147+
settings, as shown in the following snippet:
148+
</p>
149+
<pre>
150+
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
151+
package="com.example.android.samplespellcheckerservice" &gt;
152+
&lt;application
153+
android:label="&#64;string/app_name" &gt;
154+
&lt;service
155+
android:label="&#64;string/app_name"
156+
android:name=".SampleSpellCheckerService"
157+
android:permission="android.permission.BIND_TEXT_SERVICE" &gt;
158+
&lt;intent-filter &gt;
159+
&lt;action android:name="android.service.textservice.SpellCheckerService" /&gt;
160+
&lt;/intent-filter&gt;
161+
162+
&lt;meta-data
163+
android:name="android.view.textservice.scs"
164+
android:resource="&#64;xml/spellchecker" /&gt;
165+
&lt;/service&gt;
166+
167+
&lt;activity
168+
android:label="&#64;string/sample_settings"
169+
android:name="SpellCheckerSettingsActivity" &gt;
170+
&lt;intent-filter &gt;
171+
&lt;action android:name="android.intent.action.MAIN" /&gt;
172+
&lt;/intent-filter&gt;
173+
&lt;/activity&gt;
174+
&lt;/application&gt;
175+
&lt;/manifest&gt;
176+
</pre>
177+
<p>
178+
Notice that components that want to use the service must request the permission
179+
{@link android.Manifest.permission#BIND_TEXT_SERVICE} to ensure that only the system binds to
180+
the service. The service's definition also specifies the <code>spellchecker.xml</code> metadata
181+
file, which is described in the next section.
182+
</p>
183+
<p>
184+
The metadata file <code>spellchecker.xml</code> contains the following XML:
185+
</p>
186+
<pre>
187+
&lt;spell-checker xmlns:android="http://schemas.android.com/apk/res/android"
188+
android:label="&#64;string/spellchecker_name"
189+
android:settingsActivity="com.example.SpellCheckerSettingsActivity"&gt;
190+
&lt;subtype
191+
android:label="&#64;string/subtype_generic"
192+
android:subtypeLocale="en”
193+
/&gt;
194+
&lt;subtype
195+
android:label="&#64;string/subtype_generic"
196+
android:subtypeLocale="fr”
197+
/&gt;
198+
&lt;/spell-checker&gt;
199+
</pre>
200+
<p>
201+
The metadata specifies the activity that the spell checker uses for controlling settings. It
202+
also defines subtypes for the spell checker; in this case, the subtypes define locales that
203+
the spell checker can handle.
204+
</p>
205+
206+
207+
<!-- Accessing the Spell Checker Service from a Client -->
208+
<h2 id="SpellCheckClient">Accessing the Spell Checker Service from a Client</h2>
209+
<p>
210+
Applications that use {@link android.widget.TextView} views automatically benefit from spell
211+
checking, because {@link android.widget.TextView} automatically uses a spell checker. The
212+
following screenshots show this:
213+
</p>
214+
<img src="{@docRoot}resources/articles/images/textview_spellcheck_screenshot_1.png" alt=""
215+
height="45" id="figure2a" />
216+
<br>
217+
<img src="{@docRoot}resources/articles/images/textview_spellcheck_screenshot_2.png" alt=""
218+
height="121" id="figure2b" />
219+
<p class="img-caption">
220+
<strong>Figure 2.</strong> Spell checking in TextView.
221+
</p>
222+
<p>
223+
However, you may want to interact directly with a spell checker service in other cases as well.
224+
The following diagram shows the flow of control for interacting with a spell checker service:
225+
</p>
226+
<img src="{@docRoot}resources/articles/images/spellcheck_client_flow.png" alt=""
227+
height="394" id="figure3" />
228+
<p class="img-caption">
229+
<strong>Figure 3.</strong> Interacting with a spell checker service.
230+
</p>
231+
<p>
232+
The <a href="{@docRoot}resources/samples/SpellChecker/HelloSpellChecker/index.html">
233+
Spell Checker Client</a> sample app shows how to interact with a spell checker service. The
234+
LatinIME input method editor in the Android Open Source Project also contains an example of
235+
spell checking.
236+
</p>

docs/html/resources/resources-data.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ var ANDROID_RESOURCES = [
262262
en: 'This article describes the changes and improvements to services introduced in Android 2.0, as well as strategies for compatibility with older versions of the platform.'
263263
}
264264
},
265+
{
266+
tags: ['article', 'input', 'ui'],
267+
path: 'articles/spell-checker-framework.html',
268+
title: {
269+
en: 'The Android Spell Checker Framework'
270+
},
271+
description: {
272+
en: 'This article describes the Android spell checker framework and how to use to implement spell checking in applications.'
273+
}
274+
},
275+
265276
{
266277
tags: ['article', 'ui'],
267278
path: 'articles/touch-mode.html',

0 commit comments

Comments
 (0)