@@ -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