diff options
Diffstat (limited to 'core/java/android')
3 files changed, 55 insertions, 38 deletions
diff --git a/core/java/android/service/textservice/SpellCheckerSession.java b/core/java/android/service/textservice/SpellCheckerSession.java index a575220..400454d 100644 --- a/core/java/android/service/textservice/SpellCheckerSession.java +++ b/core/java/android/service/textservice/SpellCheckerSession.java @@ -25,10 +25,12 @@ import android.os.Handler; import android.os.Message; import android.os.RemoteException; import android.util.Log; +import android.view.textservice.SpellCheckerInfo; import android.view.textservice.SuggestionsInfo; import android.view.textservice.TextInfo; import java.util.LinkedList; +import java.util.Locale; import java.util.Queue; /** @@ -42,6 +44,7 @@ public class SpellCheckerSession { private final InternalListener mInternalListener; private final ITextServicesManager mTextServicesManager; + private final SpellCheckerInfo mSpellCheckerInfo; private final SpellCheckerSessionListenerImpl mSpellCheckerSessionListenerImpl; private boolean mIsUsed; @@ -63,10 +66,12 @@ public class SpellCheckerSession { * Constructor * @hide */ - public SpellCheckerSession(ITextServicesManager tsm, SpellCheckerSessionListener listener) { - if (listener == null || tsm == null) { + public SpellCheckerSession( + SpellCheckerInfo info, ITextServicesManager tsm, SpellCheckerSessionListener listener) { + if (info == null || listener == null || tsm == null) { throw new NullPointerException(); } + mSpellCheckerInfo = info; mSpellCheckerSessionListenerImpl = new SpellCheckerSessionListenerImpl(mHandler); mInternalListener = new InternalListener(); mTextServicesManager = tsm; @@ -83,6 +88,14 @@ public class SpellCheckerSession { } /** + * Get the spell checker service info this spell checker session has. + * @return SpellCheckerInfo for the specified locale. + */ + public SpellCheckerInfo getSpellChecker() { + return mSpellCheckerInfo; + } + + /** * Finish this session and allow TextServicesManagerService to disconnect the bound spell * checker. */ diff --git a/core/java/android/view/textservice/SuggestionsInfo.java b/core/java/android/view/textservice/SuggestionsInfo.java index b0ccbea..3332f1e 100644 --- a/core/java/android/view/textservice/SuggestionsInfo.java +++ b/core/java/android/view/textservice/SuggestionsInfo.java @@ -23,27 +23,23 @@ import android.os.Parcelable; * This class contains a metadata of suggestions from the text service */ public final class SuggestionsInfo implements Parcelable { + private static final String[] EMPTY = new String[0]; + /** * Flag of the attributes of the suggestions that can be obtained by * {@link #getSuggestionsAttributes}: this tells that the requested word was found * in the dictionary in the text service. */ public static final int RESULT_ATTR_IN_THE_DICTIONARY = 0x0001; - /** Flag of the attributes of the suggestions that can be obtained by - * {@link #getSuggestionsAttributes}: this tells that there are one or more suggestions - * available for the requested word. This doesn't necessarily mean that the suggestions - * are actually in this SuggestionsInfo. For instance, the caller could have been asked to - * limit the maximum number of suggestions returned. - */ - public static final int RESULT_ATTR_SUGGESTIONS_AVAILABLE = 0x0002; /** * Flag of the attributes of the suggestions that can be obtained by * {@link #getSuggestionsAttributes}: this tells that the text service thinks the requested * word looks a typo. */ - public static final int RESULT_ATTR_LOOKS_TYPO = 0x0004; + public static final int RESULT_ATTR_LOOKS_TYPO = 0x0002; private final int mSuggestionsAttributes; private final String[] mSuggestions; + private final boolean mSuggestionsAvailable; private int mCookie; private int mSequence; @@ -53,11 +49,14 @@ public final class SuggestionsInfo implements Parcelable { * @param suggestions from the text service */ public SuggestionsInfo(int suggestionsAttributes, String[] suggestions) { + mSuggestionsAttributes = suggestionsAttributes; if (suggestions == null) { - throw new NullPointerException(); + mSuggestions = EMPTY; + mSuggestionsAvailable = false; + } else { + mSuggestions = suggestions; + mSuggestionsAvailable = true; } - mSuggestionsAttributes = suggestionsAttributes; - mSuggestions = suggestions; mCookie = 0; mSequence = 0; } @@ -72,10 +71,13 @@ public final class SuggestionsInfo implements Parcelable { public SuggestionsInfo( int suggestionsAttributes, String[] suggestions, int cookie, int sequence) { if (suggestions == null) { - throw new NullPointerException(); + mSuggestions = EMPTY; + mSuggestionsAvailable = false; + } else { + mSuggestions = suggestions; + mSuggestionsAvailable = true; } mSuggestionsAttributes = suggestionsAttributes; - mSuggestions = suggestions; mCookie = cookie; mSequence = sequence; } @@ -85,6 +87,7 @@ public final class SuggestionsInfo implements Parcelable { mSuggestions = source.readStringArray(); mCookie = source.readInt(); mSequence = source.readInt(); + mSuggestionsAvailable = source.readInt() == 1; } /** @@ -99,6 +102,7 @@ public final class SuggestionsInfo implements Parcelable { dest.writeStringArray(mSuggestions); dest.writeInt(mCookie); dest.writeInt(mSequence); + dest.writeInt(mSuggestionsAvailable ? 1 : 0); } /** @@ -136,9 +140,15 @@ public final class SuggestionsInfo implements Parcelable { } /** - * @return the count of suggestions + * @return the count of the suggestions. If there's no suggestions at all, this method returns + * -1. Even if this method returns 0, it doesn't necessarily mean that there are no suggestions + * for the requested word. For instance, the caller could have been asked to limit the maximum + * number of suggestions returned. */ public int getSuggestionsCount() { + if (!mSuggestionsAvailable) { + return -1; + } return mSuggestions.length; } diff --git a/core/java/android/view/textservice/TextServicesManager.java b/core/java/android/view/textservice/TextServicesManager.java index 6fa7e4d..9749416 100644 --- a/core/java/android/view/textservice/TextServicesManager.java +++ b/core/java/android/view/textservice/TextServicesManager.java @@ -63,37 +63,31 @@ public final class TextServicesManager { return sInstance; } - /** - * Get the current spell checker service info for the specified locale. - * @param locale locale of a spell checker - * @return SpellCheckerInfo for the specified locale. + * Get a spell checker session for the specified spell checker + * @param locale the locale for the spell checker + * @param listener a spell checker session lister for getting results from a spell checker. + * @param referToSpellCheckerLanguageSettings if true, the session for one of enabled + * languages in settings will be returned. + * @return the spell checker session of the spell checker */ // TODO: Add a method to get enabled spell checkers. - public SpellCheckerInfo getCurrentSpellChecker(Locale locale) { - if (locale == null) { - throw new NullPointerException("locale is null"); + // TODO: Handle referToSpellCheckerLanguageSettings + public SpellCheckerSession newSpellCheckerSession(Locale locale, + SpellCheckerSessionListener listener, boolean referToSpellCheckerLanguageSettings) { + if (locale == null || listener == null) { + throw new NullPointerException(); } + final SpellCheckerInfo info; try { - return sService.getCurrentSpellChecker(locale.toString()); + info = sService.getCurrentSpellChecker(locale.toString()); } catch (RemoteException e) { return null; } - } - - /** - * Get a spell checker session for a specified spell checker - * @param info SpellCheckerInfo of the spell checker - * @param locale the locale for the spell checker - * @param listener a spell checker session lister for getting results from a spell checker. - * @return the spell checker session of the spell checker - */ - public SpellCheckerSession newSpellCheckerSession( - SpellCheckerInfo info, Locale locale, SpellCheckerSessionListener listener) { - if (info == null || locale == null || listener == null) { - throw new NullPointerException(); + if (info == null) { + return null; } - final SpellCheckerSession session = new SpellCheckerSession(sService, listener); + final SpellCheckerSession session = new SpellCheckerSession(info, sService, listener); try { sService.getSpellCheckerService( info, locale.toString(), session.getTextServicesSessionListener(), |