Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab45c768 authored by satok's avatar satok Committed by Android (Google) Code Review
Browse files

Merge "Tweak APIs for SpellChecker"

parents b54ac4ab 1bedd997
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -17956,6 +17956,7 @@ package android.service.textservice {
  public class SpellCheckerSession {
    method public void close();
    method public android.view.textservice.SpellCheckerInfo getSpellChecker();
    method public void getSuggestions(android.view.textservice.TextInfo, int);
    method public void getSuggestions(android.view.textservice.TextInfo[], int, boolean);
    method public boolean isSessionDisconnected();
@@ -24072,8 +24073,7 @@ package android.view.textservice {
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final int RESULT_ATTR_IN_THE_DICTIONARY = 1; // 0x1
    field public static final int RESULT_ATTR_LOOKS_TYPO = 4; // 0x4
    field public static final int RESULT_ATTR_SUGGESTIONS_AVAILABLE = 2; // 0x2
    field public static final int RESULT_ATTR_LOOKS_TYPO = 2; // 0x2
  }
  public final class TextInfo implements android.os.Parcelable {
@@ -24089,8 +24089,7 @@ package android.view.textservice {
  }
  public final class TextServicesManager {
    method public android.view.textservice.SpellCheckerInfo getCurrentSpellChecker(java.util.Locale);
    method public android.service.textservice.SpellCheckerSession newSpellCheckerSession(android.view.textservice.SpellCheckerInfo, java.util.Locale, android.service.textservice.SpellCheckerSession.SpellCheckerSessionListener);
    method public android.service.textservice.SpellCheckerSession newSpellCheckerSession(java.util.Locale, android.service.textservice.SpellCheckerSession.SpellCheckerSessionListener, boolean);
  }
}
+15 −2
Original line number Diff line number Diff line
@@ -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;
@@ -82,6 +87,14 @@ public class SpellCheckerSession {
        return mSpellCheckerSessionListenerImpl.isDisconnected();
    }

    /**
     * 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.
+24 −14
Original line number Diff line number Diff line
@@ -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) {
        if (suggestions == null) {
            throw new NullPointerException();
        }
        mSuggestionsAttributes = suggestionsAttributes;
        if (suggestions == null) {
            mSuggestions = EMPTY;
            mSuggestionsAvailable = false;
        } else {
            mSuggestions = suggestions;
            mSuggestionsAvailable = true;
        }
        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;
    }

+16 −22
Original line number Diff line number Diff line
@@ -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;
        }
        if (info == null) {
            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();
        }
        final SpellCheckerSession session = new SpellCheckerSession(sService, listener);
        final SpellCheckerSession session = new SpellCheckerSession(info, sService, listener);
        try {
            sService.getSpellCheckerService(
                    info, locale.toString(), session.getTextServicesSessionListener(),