From e7d2ee3ec310a3991f07d20994871bb0dc84941a Mon Sep 17 00:00:00 2001
From: Jean Chalard <jchalard@google.com>
Date: Wed, 13 Jun 2012 01:10:18 +0900
Subject: [PATCH] Add a kind to the suggestion for bookkeeping (A1)

This will help for debug as well as serve as groundwork for
Bug: 6252660
Bug: 6166228
Bug: 2704000
Bug: 6225530

Change-Id: I74d0a7b943fb22c514ad79dc064d69ddf336d3ef
---
 .../inputmethod/latin/SettingsValues.java       |  7 +++----
 .../com/android/inputmethod/latin/Suggest.java  | 14 ++++++++------
 .../inputmethod/latin/SuggestedWords.java       | 17 ++++++++++++++---
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index f8a0a4df6a..da4acea50c 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -173,12 +173,11 @@ public class SettingsValues {
 
     // Helper functions to create member values.
     private static SuggestedWords createSuggestPuncList(final String[] puncs) {
-        final ArrayList<SuggestedWords.SuggestedWordInfo> puncList =
-                new ArrayList<SuggestedWords.SuggestedWordInfo>();
+        final ArrayList<SuggestedWordInfo> puncList = new ArrayList<SuggestedWordInfo>();
         if (puncs != null) {
             for (final String puncSpec : puncs) {
-                puncList.add(new SuggestedWords.SuggestedWordInfo(
-                        KeySpecParser.getLabel(puncSpec), SuggestedWordInfo.MAX_SCORE));
+                puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec),
+                        SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED));
             }
         }
         return new SuggestedWords(puncList,
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 68b7b913f8..5b9d4a949a 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -335,15 +335,16 @@ public class Suggest implements Dictionary.WordCallback {
                 for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
                     sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
                 }
-                mSuggestions.add(0, new SuggestedWordInfo(
-                        sb.toString(), SuggestedWordInfo.MAX_SCORE));
+                mSuggestions.add(0, new SuggestedWordInfo(sb.toString(),
+                        SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST));
             } else {
-                mSuggestions.add(0, new SuggestedWordInfo(
-                        whitelistedWord, SuggestedWordInfo.MAX_SCORE));
+                mSuggestions.add(0, new SuggestedWordInfo(whitelistedWord,
+                        SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST));
             }
         }
 
-        mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE));
+        mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
+                SuggestedWordInfo.KIND_TYPED));
         SuggestedWordInfo.removeDups(mSuggestions);
 
         final ArrayList<SuggestedWordInfo> suggestionsList;
@@ -495,7 +496,8 @@ public class Suggest implements Dictionary.WordCallback {
         for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
             sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
         }
-        suggestions.add(pos, new SuggestedWordInfo(sb, score));
+        // TODO: figure out what type of suggestion this is
+        suggestions.add(pos, new SuggestedWordInfo(sb, score, SuggestedWordInfo.KIND_CORRECTION));
         if (suggestions.size() > prefMaxSuggestions) {
             suggestions.remove(prefMaxSuggestions);
         } else {
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 497fd3bfa2..1ed91fe714 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -91,7 +91,8 @@ public class SuggestedWords {
         final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
         for (CompletionInfo info : infos) {
             if (null != info && info.getText() != null) {
-                result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE));
+                result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE,
+                        SuggestedWordInfo.KIND_APP_DEFINED));
             }
         }
         return result;
@@ -103,7 +104,8 @@ public class SuggestedWords {
             final CharSequence typedWord, final SuggestedWords previousSuggestions) {
         final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<SuggestedWordInfo>();
         final HashSet<String> alreadySeen = new HashSet<String>();
-        suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE));
+        suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
+                SuggestedWordInfo.KIND_TYPED));
         alreadySeen.add(typedWord.toString());
         final int previousSize = previousSuggestions.size();
         for (int pos = 1; pos < previousSize; pos++) {
@@ -120,16 +122,25 @@ public class SuggestedWords {
 
     public static class SuggestedWordInfo {
         public static final int MAX_SCORE = Integer.MAX_VALUE;
+        public static final int KIND_TYPED = 0; // What user typed
+        public static final int KIND_CORRECTION = 1; // Simple correction/suggestion
+        public static final int KIND_COMPLETION = 2; // Completion (suggestion with appended chars)
+        public static final int KIND_WHITELIST = 3; // Whitelisted word
+        public static final int KIND_BLACKLIST = 4; // Blacklisted word
+        public static final int KIND_HARDCODED = 5; // Hardcoded suggestion, e.g. punctuation
+        public static final int KIND_APP_DEFINED = 6; // Suggested by the application
         private final String mWordStr;
         public final CharSequence mWord;
         public final int mScore;
+        public final int mKind;
         public final int mCodePointCount;
         private String mDebugString = "";
 
-        public SuggestedWordInfo(final CharSequence word, final int score) {
+        public SuggestedWordInfo(final CharSequence word, final int score, final int kind) {
             mWordStr = word.toString();
             mWord = word;
             mScore = score;
+            mKind = kind;
             mCodePointCount = mWordStr.codePointCount(0, mWordStr.length());
         }
 
-- 
GitLab