Skip to content

Commit b4aff97

Browse files
committed
Introduce an API to cancel pending/running spell check tasks
Bug: 5554629 Change-Id: Ifd840ea13976813639a2ee259124a21d9bb56893
1 parent 76bb11c commit b4aff97

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24825,6 +24825,7 @@ package android.view.textservice {
2482524825
}
2482624826

2482724827
public class SpellCheckerSession {
24828+
method public void cancel();
2482824829
method public void close();
2482924830
method public android.view.textservice.SpellCheckerInfo getSpellChecker();
2483024831
method public void getSuggestions(android.view.textservice.TextInfo, int);

core/java/android/view/textservice/SpellCheckerSession.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ public SpellCheckerInfo getSpellChecker() {
145145
return mSpellCheckerInfo;
146146
}
147147

148+
/**
149+
* Cancel pending and running spell check tasks
150+
*/
151+
public void cancel() {
152+
mSpellCheckerSessionListenerImpl.cancel();
153+
}
154+
148155
/**
149156
* Finish this session and allow TextServicesManagerService to disconnect the bound spell
150157
* checker.
@@ -242,6 +249,13 @@ public synchronized void onServiceConnected(ISpellCheckerSession session) {
242249
}
243250
}
244251

252+
public void cancel() {
253+
if (DBG) {
254+
Log.w(TAG, "cancel");
255+
}
256+
processOrEnqueueTask(new SpellCheckerParams(TASK_CANCEL, null, 0, false));
257+
}
258+
245259
public void getSuggestionsMultiple(
246260
TextInfo[] textInfos, int suggestionsLimit, boolean sequentialWords) {
247261
if (DBG) {
@@ -275,8 +289,22 @@ private void processOrEnqueueTask(SpellCheckerParams scp) {
275289
if (DBG) {
276290
Log.d(TAG, "process or enqueue task: " + mISpellCheckerSession);
277291
}
292+
SpellCheckerParams closeTask = null;
278293
if (mISpellCheckerSession == null) {
294+
if (scp.mWhat == TASK_CANCEL) {
295+
while (!mPendingTasks.isEmpty()) {
296+
final SpellCheckerParams tmp = mPendingTasks.poll();
297+
if (tmp.mWhat == TASK_CLOSE) {
298+
// Only one close task should be processed, while we need to remove all
299+
// close tasks from the queue
300+
closeTask = tmp;
301+
}
302+
}
303+
}
279304
mPendingTasks.offer(scp);
305+
if (closeTask != null) {
306+
mPendingTasks.offer(closeTask);
307+
}
280308
} else {
281309
processTask(scp);
282310
}

0 commit comments

Comments
 (0)