Merge "Change the name of AOSP LatinIME spell checker"
diff --git a/java/res/xml/key_styles_number.xml b/java/res/xml/key_styles_number.xml
index 3627836..1fc2169 100644
--- a/java/res/xml/key_styles_number.xml
+++ b/java/res/xml/key_styles_number.xml
@@ -41,14 +41,9 @@
         latin:styleName="numberKeyStyle"
         latin:keyLabelFlags="alignLeftOfCenter|hasHintLabel"
         latin:parentStyle="numKeyStyle" />
-    <!-- U+0030: "0" DIGIT ZERO
-         U+002B: "+" PLUS SIGN -->
     <key-style
         latin:styleName="num0KeyStyle"
-        latin:code="0x0030"
-        latin:altCode="0x002B"
-        latin:keyLabel="0 +"
-        latin:keyActionFlags="enableLongPress"
+        latin:keyLabel="0"
         latin:parentStyle="numberKeyStyle" />
     <key-style
         latin:styleName="num1KeyStyle"
diff --git a/java/res/xml/rows_number_normal.xml b/java/res/xml/rows_number_normal.xml
index 91b1fe9..6f9429c 100644
--- a/java/res/xml/rows_number_normal.xml
+++ b/java/res/xml/rows_number_normal.xml
@@ -111,13 +111,11 @@
             <case
                 latin:mode="datetime"
             >
-                <!-- U+002F: "/" SOLIDUS
-                     U+003A: ":" COLON -->
+                <!-- U+002F: "/" SOLIDUS -->
                 <Key
                     latin:code="0x002F"
-                    latin:altCode="0x003A"
                     latin:keyLabel="/ :"
-                    latin:keyActionFlags="enableLongPress"
+                    latin:moreKeys="!embeddedMoreKey!,:"
                     latin:keyStyle="numKeyStyle" />
             </case>
             <default>
diff --git a/java/res/xml/rows_phone.xml b/java/res/xml/rows_phone.xml
index 60296d0..630b24e 100644
--- a/java/res/xml/rows_phone.xml
+++ b/java/res/xml/rows_phone.xml
@@ -63,8 +63,12 @@
     <Row>
         <Key
             latin:keyStyle="numPhoneToSymbolKeyStyle" />
+        <!-- U+0030: "0" DIGIT ZERO -->
         <Key
-            latin:keyStyle="num0KeyStyle" />
+            latin:keyStyle="num0KeyStyle"
+            latin:code="0x0030"
+            latin:keyLabel="0 +"
+            latin:moreKeys="!embeddedMoreKey!,+" />
         <Key
             latin:keyStyle="numSpaceKeyStyle" />
         <Key
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index a719b4a..b8d04e0 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -109,10 +109,12 @@
     private static final int MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER = 0x80000000;
     private static final int MORE_KEYS_FLAGS_HAS_LABELS = 0x40000000;
     private static final int MORE_KEYS_FLAGS_NEEDS_DIVIDERS = 0x40000000;
+    private static final int MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY = 0x20000000;
     private static final String MORE_KEYS_AUTO_COLUMN_ORDER = "!autoColumnOrder!";
     private static final String MORE_KEYS_FIXED_COLUMN_ORDER = "!fixedColumnOrder!";
     private static final String MORE_KEYS_HAS_LABELS = "!hasLabels!";
     private static final String MORE_KEYS_NEEDS_DIVIDERS = "!needsDividers!";
+    private static final String MORE_KEYS_EMBEDDED_MORE_KEY = "!embeddedMoreKey!";
 
     /** Background type that represents different key background visual than normal one. */
     public final int mBackgroundType;
@@ -258,6 +260,9 @@
         if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_NEEDS_DIVIDERS)) {
             moreKeysColumn |= MORE_KEYS_FLAGS_NEEDS_DIVIDERS;
         }
+        if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_EMBEDDED_MORE_KEY)) {
+            moreKeysColumn |= MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY;
+        }
         mMoreKeysColumnAndFlags = moreKeysColumn;
 
         final String[] additionalMoreKeys = style.getStringArray(
@@ -548,6 +553,10 @@
         return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_NEEDS_DIVIDERS) != 0;
     }
 
+    public boolean hasEmbeddedMoreKey() {
+        return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY) != 0;
+    }
+
     public Drawable getIcon(KeyboardIconsSet iconSet) {
         return iconSet.getIconDrawable(mIconId);
     }
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index 0970fb5..8a2f892 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -41,6 +41,7 @@
 import com.android.inputmethod.deprecated.VoiceProxy;
 import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
 import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
+import com.android.inputmethod.keyboard.internal.KeySpecParser;
 import com.android.inputmethod.latin.LatinIME;
 import com.android.inputmethod.latin.LatinImeLogger;
 import com.android.inputmethod.latin.R;
@@ -480,13 +481,10 @@
      */
     protected boolean onLongPress(Key parentKey, PointerTracker tracker) {
         final int primaryCode = parentKey.mCode;
-        if (parentKey.mMoreKeys == null && !parentKey.altCodeWhileTyping()
-                && parentKey.mAltCode != Keyboard.CODE_UNSPECIFIED) {
-            // Long press on a key that has no more keys and is not altCodeWhileTyping, but altCode
-            // is defined, such as the "0 +" key on the phone layout and the "/ :" key on the
-            // datetime layout.
+        if (parentKey.hasEmbeddedMoreKey()) {
+            final int embeddedCode = KeySpecParser.getCode(getResources(), parentKey.mMoreKeys[0]);
             tracker.onLongPressed();
-            invokeCodeInput(parentKey.mAltCode);
+            invokeCodeInput(embeddedCode);
             invokeReleaseKey(primaryCode);
             KeyboardSwitcher.getInstance().hapticAndAudioFeedback(primaryCode);
             return true;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 0f9b983..59fa66d 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1827,18 +1827,18 @@
                 builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
             }
         }
+        final SuggestedWords suggestedWords = builder.build();
+        if (Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest)) {
+            suggestedWords.setShouldBlockAutoCorrectionBySatefyNet();
+        }
         showSuggestions(builder.build(), typedWord);
     }
 
     public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) {
-        final boolean shouldBlockAutoCorrectionBySafetyNet =
-                Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest);
-        if (shouldBlockAutoCorrectionBySafetyNet) {
-            suggestedWords.setShouldBlockAutoCorrectionBySatefyNet();
-        }
         final CharSequence autoCorrection;
         if (suggestedWords.size() > 0) {
-            if (!shouldBlockAutoCorrectionBySafetyNet && suggestedWords.hasAutoCorrectionWord()) {
+            if (!suggestedWords.shouldBlockAutoCorrectionBySafetyNet()
+                    && suggestedWords.hasAutoCorrectionWord()) {
                 autoCorrection = suggestedWords.getWord(1);
             } else {
                 autoCorrection = typedWord;
@@ -1847,7 +1847,7 @@
             autoCorrection = null;
         }
         mWordComposer.setAutoCorrection(autoCorrection);
-        final boolean isAutoCorrection = Utils.willAutoCorrect(suggestedWords);
+        final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
         setSuggestions(suggestedWords, isAutoCorrection);
         setAutoCorrectionIndicator(isAutoCorrection);
         setSuggestionStripShown(isSuggestionsStripVisible());
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 7892297..ff8945f 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -77,6 +77,11 @@
         return mShouldBlockAutoCorrectionBySafetyNet;
     }
 
+    public boolean willAutoCorrect() {
+        return !mTypedWordValid && mHasAutoCorrectionCandidate
+                && !shouldBlockAutoCorrectionBySafetyNet();
+    }
+
     public static class Builder {
         private List<CharSequence> mWords = new ArrayList<CharSequence>();
         private boolean mTypedWordValid;
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index f46352d..f6bc854 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -778,11 +778,6 @@
         return s.toUpperCase(locale).charAt(0) + s.substring(1);
     }
 
-    public static boolean willAutoCorrect(SuggestedWords suggestions) {
-        return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate
-                && !suggestions.shouldBlockAutoCorrectionBySafetyNet();
-    }
-
     public static class Stats {
         public static void onNonSeparator(final char code, final int x,
                 final int y) {
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
index 9ab8c01..e5638ef 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
@@ -62,7 +62,6 @@
 import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
 import com.android.inputmethod.latin.SuggestedWords;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
-import com.android.inputmethod.latin.Utils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -261,7 +260,7 @@
 
         private CharSequence getStyledSuggestionWord(SuggestedWords suggestions, int pos) {
             final CharSequence word = suggestions.getWord(pos);
-            final boolean isAutoCorrect = pos == 1 && Utils.willAutoCorrect(suggestions);
+            final boolean isAutoCorrect = pos == 1 && suggestions.willAutoCorrect();
             final boolean isTypedWordValid = pos == 0 && suggestions.mTypedWordValid;
             if (!isAutoCorrect && !isTypedWordValid)
                 return word;
@@ -282,7 +281,7 @@
         private int getWordPosition(int index, SuggestedWords suggestions) {
             // TODO: This works for 3 suggestions. Revisit this algorithm when there are 5 or more
             // suggestions.
-            final int centerPos = Utils.willAutoCorrect(suggestions) ? 1 : 0;
+            final int centerPos = suggestions.willAutoCorrect() ? 1 : 0;
             if (index == mCenterSuggestionIndex) {
                 return centerPos;
             } else if (index == centerPos) {
@@ -297,7 +296,7 @@
             final boolean isSuggested = (pos != 0);
 
             final int color;
-            if (index == mCenterSuggestionIndex && Utils.willAutoCorrect(suggestions)) {
+            if (index == mCenterSuggestionIndex && suggestions.willAutoCorrect()) {
                 color = mColorAutoCorrect;
             } else if (index == mCenterSuggestionIndex && suggestions.mTypedWordValid) {
                 color = mColorValidTypedWord;