Refactor MoreKeysKeyboardView to use Key class

This can make MoreSuggestionsView to use extended Key class to hold
a index of a suggested word.

Change-Id: I54d03d2447b04e3caf3e19e7cadcd391cbf58dd5
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
index 65242dd..4a2b37e 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
@@ -130,7 +130,7 @@
     public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime) {
         if (mCurrentKey != null && mActivePointerId == pointerId) {
             updateReleaseKeyGraphics(mCurrentKey);
-            onCodeInput(mCurrentKey.getCode(), x, y);
+            onKeyInput(mCurrentKey, x, y);
             mCurrentKey = null;
         }
     }
@@ -138,7 +138,8 @@
     /**
      * Performs the specific action for this panel when the user presses a key on the panel.
      */
-    protected void onCodeInput(final int code, final int x, final int y) {
+    protected void onKeyInput(final Key key, final int x, final int y) {
+        final int code = key.getCode();
         if (code == Constants.CODE_OUTPUT_TEXT) {
             mListener.onTextInput(mCurrentKey.getOutputText());
         } else if (code != Constants.CODE_UNSPECIFIED) {
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
index 5a325ea..e90b15c 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
@@ -27,14 +27,13 @@
 import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
 import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
 import com.android.inputmethod.keyboard.internal.KeyboardParams;
+import com.android.inputmethod.latin.Constants;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.SuggestedWords;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 import com.android.inputmethod.latin.utils.TypefaceUtils;
 
 public final class MoreSuggestions extends Keyboard {
-    public static final int SUGGESTION_CODE_BASE = 1024;
-
     public final SuggestedWords mSuggestedWords;
 
     public static abstract class MoreSuggestionsListener extends KeyboardActionListener.Adapter {
@@ -178,7 +177,7 @@
         }
     }
 
-    private static boolean isIndexSubjectToAutoCorrection(final SuggestedWords suggestedWords,
+    static boolean isIndexSubjectToAutoCorrection(final SuggestedWords suggestedWords,
             final int index) {
         return suggestedWords.mWillAutoCorrect && index == SuggestedWords.INDEX_OF_AUTO_CORRECTION;
     }
@@ -226,11 +225,7 @@
                     word = mSuggestedWords.getLabel(index);
                     info = mSuggestedWords.getDebugString(index);
                 }
-                final int indexInMoreSuggestions = index + SUGGESTION_CODE_BASE;
-                final Key key = new Key(word, KeyboardIconsSet.ICON_UNDEFINED,
-                        indexInMoreSuggestions, null /* outputText */, info, 0 /* labelFlags */,
-                        Key.BACKGROUND_TYPE_NORMAL, x, y, width, params.mDefaultRowHeight,
-                        params.mHorizontalGap, params.mVerticalGap);
+                final Key key = new MoreSuggestionKey(word, info, index, params);
                 params.markAsEdgeKey(key, index);
                 params.onAddKey(key);
                 final int columnNumber = params.getColumnNumber(index);
@@ -245,6 +240,19 @@
         }
     }
 
+    static final class MoreSuggestionKey extends Key {
+        public final int mSuggestedWordIndex;
+
+        public MoreSuggestionKey(final String word, final String info, final int index,
+                final MoreSuggestionsParam params) {
+            super(word /* label */, KeyboardIconsSet.ICON_UNDEFINED, Constants.CODE_OUTPUT_TEXT,
+                    word /* outputText */, info, 0 /* labelFlags */, Key.BACKGROUND_TYPE_NORMAL,
+                    params.getX(index), params.getY(index), params.getWidth(index),
+                    params.mDefaultRowHeight, params.mHorizontalGap, params.mVerticalGap);
+            mSuggestedWordIndex = index;
+        }
+    }
+
     private static final class Divider extends Key.Spacer {
         private final Drawable mIcon;
 
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
index 549ff0d..7fd64c4 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
@@ -20,10 +20,12 @@
 import android.util.AttributeSet;
 import android.util.Log;
 
+import com.android.inputmethod.keyboard.Key;
 import com.android.inputmethod.keyboard.Keyboard;
 import com.android.inputmethod.keyboard.MoreKeysKeyboardView;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.SuggestedWords;
+import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionKey;
 import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
 
 /**
@@ -59,7 +61,12 @@
     }
 
     @Override
-    public void onCodeInput(final int code, final int x, final int y) {
+    protected void onKeyInput(final Key key, final int x, final int y) {
+        if (!(key instanceof MoreSuggestionKey)) {
+            Log.e(TAG, "Expected key is MoreSuggestionKey, but found "
+                    + key.getClass().getName());
+            return;
+        }
         final Keyboard keyboard = getKeyboard();
         if (!(keyboard instanceof MoreSuggestions)) {
             Log.e(TAG, "Expected keyboard is MoreSuggestions, but found "
@@ -67,7 +74,7 @@
             return;
         }
         final SuggestedWords suggestedWords = ((MoreSuggestions)keyboard).mSuggestedWords;
-        final int index = code - MoreSuggestions.SUGGESTION_CODE_BASE;
+        final int index = ((MoreSuggestionKey)key).mSuggestedWordIndex;
         if (index < 0 || index >= suggestedWords.size()) {
             Log.e(TAG, "Selected suggestion has an illegal index: " + index);
             return;