FileDocCategorySizeDatePackage
SpellCheckerSession.javaAPI DocAndroid 5.1 API19975Thu Mar 12 22:22:10 GMT 2015android.view.textservice

SpellCheckerSession

public class SpellCheckerSession extends Object
The SpellCheckerSession interface provides the per client functionality of SpellCheckerService.

Applications

In most cases, applications that are using the standard {@link android.widget.TextView} or its subclasses will have little they need to do to work well with spell checker services. The main things you need to be aware of are:

  • Properly set the {@link android.R.attr#inputType} in your editable text views, so that the spell checker will have enough context to help the user in editing text in them.

For the rare people amongst us writing client applications that use the spell checker service directly, you will need to use {@link #getSuggestions(TextInfo, int)} or {@link #getSuggestions(TextInfo[], int, boolean)} for obtaining results from the spell checker service by yourself.

Security

There are a lot of security issues associated with spell checkers, since they could monitor all the text being sent to them through, for instance, {@link android.widget.TextView}. The Android spell checker framework also allows arbitrary third party spell checkers, so care must be taken to restrict their selection and interactions.

Here are some key points about the security architecture behind the spell checker framework:

  • Only the system is allowed to directly access a spell checker framework's {@link android.service.textservice.SpellCheckerService} interface, via the {@link android.Manifest.permission#BIND_TEXT_SERVICE} permission. This is enforced in the system by not binding to a spell checker service that does not require this permission.
  • The user must explicitly enable a new spell checker in settings before they can be enabled, to confirm with the system that they know about it and want to make it available for use.

Fields Summary
private static final String
TAG
private static final boolean
DBG
public static final String
SERVICE_META_DATA
Name under which a SpellChecker service component publishes information about itself. This meta-data must reference an XML resource.
private static final int
MSG_ON_GET_SUGGESTION_MULTIPLE
private static final int
MSG_ON_GET_SUGGESTION_MULTIPLE_FOR_SENTENCE
private final InternalListener
mInternalListener
private final com.android.internal.textservice.ITextServicesManager
mTextServicesManager
private final android.view.textservice.SpellCheckerInfo
mSpellCheckerInfo
private final SpellCheckerSessionListenerImpl
mSpellCheckerSessionListenerImpl
private final SpellCheckerSubtype
mSubtype
private boolean
mIsUsed
private SpellCheckerSessionListener
mSpellCheckerSessionListener
private final android.os.Handler
mHandler
Handler that will execute the main tasks
Constructors Summary
public SpellCheckerSession(android.view.textservice.SpellCheckerInfo info, com.android.internal.textservice.ITextServicesManager tsm, SpellCheckerSessionListener listener, SpellCheckerSubtype subtype)
Constructor

hide


           
     
                 
              
        if (info == null || listener == null || tsm == null) {
            throw new NullPointerException();
        }
        mSpellCheckerInfo = info;
        mSpellCheckerSessionListenerImpl = new SpellCheckerSessionListenerImpl(mHandler);
        mInternalListener = new InternalListener(mSpellCheckerSessionListenerImpl);
        mTextServicesManager = tsm;
        mIsUsed = true;
        mSpellCheckerSessionListener = listener;
        mSubtype = subtype;
    
Methods Summary
public voidcancel()
Cancel pending and running spell check tasks

        mSpellCheckerSessionListenerImpl.cancel();
    
public voidclose()
Finish this session and allow TextServicesManagerService to disconnect the bound spell checker.

        mIsUsed = false;
        try {
            mSpellCheckerSessionListenerImpl.close();
            mTextServicesManager.finishSpellCheckerService(mSpellCheckerSessionListenerImpl);
        } catch (RemoteException e) {
            // do nothing
        }
    
protected voidfinalize()

        super.finalize();
        if (mIsUsed) {
            Log.e(TAG, "SpellCheckerSession was not finished properly." +
                    "You should call finishShession() when you finished to use a spell checker.");
            close();
        }
    
public voidgetSentenceSuggestions(android.view.textservice.TextInfo[] textInfos, int suggestionsLimit)
Get suggestions from the specified sentences

param
textInfos an array of text metadata for a spell checker
param
suggestionsLimit the maximum number of suggestions that will be returned

        mSpellCheckerSessionListenerImpl.getSentenceSuggestionsMultiple(
                textInfos, suggestionsLimit);
    
public android.view.textservice.SpellCheckerInfogetSpellChecker()
Get the spell checker service info this spell checker session has.

return
SpellCheckerInfo for the specified locale.

        return mSpellCheckerInfo;
    
public com.android.internal.textservice.ISpellCheckerSessionListenergetSpellCheckerSessionListener()

hide

        return mSpellCheckerSessionListenerImpl;
    
public voidgetSuggestions(android.view.textservice.TextInfo textInfo, int suggestionsLimit)
Get candidate strings for a substring of the specified text.

param
textInfo text metadata for a spell checker
param
suggestionsLimit the maximum number of suggestions that will be returned
deprecated
use {@link SpellCheckerSession#getSentenceSuggestions(TextInfo[], int)} instead

        getSuggestions(new TextInfo[] {textInfo}, suggestionsLimit, false);
    
public voidgetSuggestions(android.view.textservice.TextInfo[] textInfos, int suggestionsLimit, boolean sequentialWords)
A batch process of getSuggestions

param
textInfos an array of text metadata for a spell checker
param
suggestionsLimit the maximum number of suggestions that will be returned
param
sequentialWords true if textInfos can be treated as sequential words.
deprecated
use {@link SpellCheckerSession#getSentenceSuggestions(TextInfo[], int)} instead

        if (DBG) {
            Log.w(TAG, "getSuggestions from " + mSpellCheckerInfo.getId());
        }
        mSpellCheckerSessionListenerImpl.getSuggestionsMultiple(
                textInfos, suggestionsLimit, sequentialWords);
    
public com.android.internal.textservice.ITextServicesSessionListenergetTextServicesSessionListener()

hide

        return mInternalListener;
    
private voidhandleOnGetSentenceSuggestionsMultiple(SentenceSuggestionsInfo[] suggestionInfos)

        mSpellCheckerSessionListener.onGetSentenceSuggestions(suggestionInfos);
    
private voidhandleOnGetSuggestionsMultiple(android.view.textservice.SuggestionsInfo[] suggestionInfos)

        mSpellCheckerSessionListener.onGetSuggestions(suggestionInfos);
    
public booleanisSessionDisconnected()

return
true if the connection to a text service of this session is disconnected and not alive.

        return mSpellCheckerSessionListenerImpl.isDisconnected();