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

Commit c972b602 authored by Jean Chalard's avatar Jean Chalard Committed by Android Git Automerger
Browse files

am c10d76f2: Merge "[AC2] Reference a dict rather than a string in suggestion infos"

* commit 'c10d76f2':
  [AC2] Reference a dict rather than a string in suggestion infos
parents 197a883f c10d76f2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ public final class BinaryDictionary extends Dictionary {
                // TODO: check that all users of the `kind' parameter are ready to accept
                // flags too and pass mOutputTypes[j] instead of kind
                suggestions.add(new SuggestedWordInfo(new String(mOutputCodePoints, start, len),
                        score, kind, mDictType,
                        score, kind, this /* sourceDict */,
                        mSpaceIndices[0] /* indexOfTouchPointOfSecondWord */));
            }
        }
+41 −4
Original line number Diff line number Diff line
@@ -28,9 +28,26 @@ import java.util.ArrayList;
public abstract class Dictionary {
    public static final int NOT_A_PROBABILITY = -1;

    // The following types do not actually come from real dictionary instances, so we create
    // corresponding instances.
    public static final String TYPE_USER_TYPED = "user_typed";
    public static final Dictionary DICTIONARY_USER_TYPED = new PhonyDictionary(TYPE_USER_TYPED);

    public static final String TYPE_APPLICATION_DEFINED = "application_defined";
    public static final Dictionary DICTIONARY_APPLICATION_DEFINED =
            new PhonyDictionary(TYPE_APPLICATION_DEFINED);

    public static final String TYPE_HARDCODED = "hardcoded"; // punctuation signs and such
    public static final Dictionary DICTIONARY_HARDCODED =
            new PhonyDictionary(TYPE_HARDCODED);

    // Spawned by resuming suggestions. Comes from a span that was in the TextView.
    public static final String TYPE_RESUMED = "resumed";
    public static final Dictionary DICTIONARY_RESUMED =
            new PhonyDictionary(TYPE_RESUMED);

    // The following types of dictionary have actual functional instances. We don't need final
    // phony dictionary instances for them.
    public static final String TYPE_MAIN = "main";
    public static final String TYPE_CONTACTS = "contacts";
    // User dictionary, the system-managed one.
@@ -42,9 +59,7 @@ public abstract class Dictionary {
    // Personalization prediction dictionary internal to LatinIME's Java code.
    public static final String TYPE_PERSONALIZATION_PREDICTION_IN_JAVA =
            "personalization_prediction_in_java";
    // Spawned by resuming suggestions. Comes from a span that was in the TextView.
    public static final String TYPE_RESUMED = "resumed";
    protected final String mDictType;
    public final String mDictType;

    public Dictionary(final String dictType) {
        mDictType = dictType;
@@ -114,8 +129,30 @@ public abstract class Dictionary {
    /**
     * Subclasses may override to indicate that this Dictionary is not yet properly initialized.
     */

    public boolean isInitialized() {
        return true;
    }

    /**
     * Not a true dictionary. A placeholder used to indicate suggestions that don't come from any
     * real dictionary.
     */
    private static class PhonyDictionary extends Dictionary {
        // This class is not publicly instantiable.
        private PhonyDictionary(final String type) {
            super(type);
        }

        @Override
        public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
                final String prevWord, final ProximityInfo proximityInfo,
                final boolean blockOffensiveWords) {
            return null;
        }

        @Override
        public boolean isValidWord(String word) {
            return false;
        }
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -403,7 +403,7 @@ public class ExpandableDictionary extends Dictionary {
            // the respective size of the typed word and the suggestion if it matters sometime
            // in the future.
            suggestions.add(new SuggestedWordInfo(new String(word, 0, depth + 1), finalFreq,
                    SuggestedWordInfo.KIND_CORRECTION, mDictType,
                    SuggestedWordInfo.KIND_CORRECTION, this /* sourceDict */,
                    SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
            if (suggestions.size() >= Suggest.MAX_SUGGESTIONS) return false;
        }
@@ -412,7 +412,7 @@ public class ExpandableDictionary extends Dictionary {
            for (int shortcutIndex = 0; shortcutIndex < length; ++shortcutIndex) {
                final char[] shortcut = node.mShortcutTargets.get(shortcutIndex);
                suggestions.add(new SuggestedWordInfo(new String(shortcut, 0, shortcut.length),
                        finalFreq, SuggestedWordInfo.KIND_SHORTCUT, mDictType,
                        finalFreq, SuggestedWordInfo.KIND_SHORTCUT, this /* sourceDict */,
                        SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
                if (suggestions.size() > Suggest.MAX_SUGGESTIONS) return false;
            }
@@ -659,8 +659,8 @@ public class ExpandableDictionary extends Dictionary {
            if (freq >= 0 && node == null) {
                suggestions.add(new SuggestedWordInfo(new String(mLookedUpString, index,
                        Constants.DICTIONARY_MAX_WORD_LENGTH - index),
                        freq, SuggestedWordInfo.KIND_CORRECTION, mDictType,
                        SuggestedWordInfo.NOT_AN_INDEX));
                        freq, SuggestedWordInfo.KIND_CORRECTION, this /* sourceDict */,
                        SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
            }
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -2485,7 +2485,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
            ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion,
                    mWordComposer.isBatchMode(), suggestionInfo.mScore, suggestionInfo.mKind,
                    suggestionInfo.mSourceDict);
                    suggestionInfo.mSourceDict.mDictType);
        }
        mConnection.endBatchEdit();
        // Don't allow cancellation of manual pick
@@ -2614,7 +2614,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
                if (!TextUtils.equals(s, typedWord)) {
                    suggestions.add(new SuggestedWordInfo(s,
                            SuggestionStripView.MAX_SUGGESTIONS - i,
                            SuggestedWordInfo.KIND_RESUMED, Dictionary.TYPE_RESUMED,
                            SuggestedWordInfo.KIND_RESUMED, Dictionary.DICTIONARY_RESUMED,
                            SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
                }
            }
+4 −3
Original line number Diff line number Diff line
@@ -303,13 +303,14 @@ public final class Suggest {

        for (int i = 0; i < suggestionsCount; ++i) {
            final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
            LatinImeLogger.onAddSuggestedWord(wordInfo.mWord.toString(), wordInfo.mSourceDict);
            LatinImeLogger.onAddSuggestedWord(wordInfo.mWord.toString(),
                    wordInfo.mSourceDict.mDictType);
        }

        if (!TextUtils.isEmpty(typedWord)) {
            suggestionsContainer.add(0, new SuggestedWordInfo(typedWord,
                    SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED,
                    Dictionary.TYPE_USER_TYPED,
                    Dictionary.DICTIONARY_USER_TYPED,
                    SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */));
        }
        SuggestedWordInfo.removeDups(suggestionsContainer);
@@ -353,7 +354,7 @@ public final class Suggest {
        }

        for (SuggestedWordInfo wordInfo : suggestionsSet) {
            LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict);
            LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict.mDictType);
        }

        final ArrayList<SuggestedWordInfo> suggestionsContainer =
Loading