Merge "Override defaultActionKeyStyle to use non-blue action background" into jb-dev
diff --git a/java/res/values-sw600dp/dimens.xml b/java/res/values-sw600dp/dimens.xml
index cb2a861..e254c41 100644
--- a/java/res/values-sw600dp/dimens.xml
+++ b/java/res/values-sw600dp/dimens.xml
@@ -39,7 +39,7 @@
     <fraction name="key_horizontal_gap_gb">2.113%p</fraction>
 
     <fraction name="key_bottom_gap_ics">4.0%p</fraction>
-    <fraction name="keyboard_bottom_padding_ics">0.0%p</fraction>
+    <fraction name="keyboard_bottom_padding_ics">4.0%p</fraction>
 
     <dimen name="more_keys_keyboard_key_horizontal_padding">6dp</dimen>
     <!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. -->
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 0d78c39..4d7fe3d 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -33,12 +33,10 @@
 
 import com.android.inputmethod.keyboard.internal.KeySpecParser;
 import com.android.inputmethod.keyboard.internal.KeySpecParser.MoreKeySpec;
-import com.android.inputmethod.keyboard.internal.KeyStyles;
 import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
 import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.StringUtils;
-import com.android.inputmethod.latin.XmlParseUtils;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -201,7 +199,6 @@
      */
     public Key(Resources res, Keyboard.Params params, Keyboard.Builder.Row row,
             XmlPullParser parser) throws XmlPullParserException {
-        final KeyStyles keyStyles = params.mKeyStyles;
         final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
         final int keyHeight = row.mRowHeight;
         mVerticalGap = params.mVerticalGap;
@@ -210,17 +207,7 @@
         final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
                 R.styleable.Keyboard_Key);
 
-        final KeyStyle style;
-        if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyStyle)) {
-            String styleName = keyAttr.getString(R.styleable.Keyboard_Key_keyStyle);
-            style = keyStyles.getKeyStyle(styleName);
-            if (style == null) {
-                throw new XmlParseUtils.ParseException("Unknown key style: " + styleName, parser);
-            }
-        } else {
-            style = keyStyles.getEmptyKeyStyle();
-        }
-
+        final KeyStyle style = params.mKeyStyles.getKeyStyle(keyAttr, parser);
         final float keyXPos = row.getKeyX(keyAttr);
         final float keyWidth = row.getKeyWidth(keyAttr, keyXPos);
         final int keyYPos = row.getKeyY();
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
index b32172e..80f4f25 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
@@ -32,24 +32,19 @@
     private static final String TAG = KeyStyles.class.getSimpleName();
     private static final boolean DEBUG = false;
 
-    private final HashMap<String, DeclaredKeyStyle> mStyles =
-            new HashMap<String, DeclaredKeyStyle>();
+    final HashMap<String, KeyStyle> mStyles = new HashMap<String, KeyStyle>();
 
-    private final KeyboardTextsSet mTextsSet;
+    final KeyboardTextsSet mTextsSet;
     private final KeyStyle mEmptyKeyStyle;
+    private static final String EMPTY_STYLE_NAME = "<empty>";
 
     public KeyStyles(KeyboardTextsSet textsSet) {
         mTextsSet = textsSet;
-        mEmptyKeyStyle = new EmptyKeyStyle(textsSet);
+        mEmptyKeyStyle = new EmptyKeyStyle();
+        mStyles.put(EMPTY_STYLE_NAME, mEmptyKeyStyle);
     }
 
-    public static abstract class KeyStyle {
-        protected final KeyboardTextsSet mTextsSet;
-
-        public KeyStyle(KeyboardTextsSet textsSet) {
-            mTextsSet = textsSet;
-        }
-
+    public abstract class KeyStyle {
         public abstract String[] getStringArray(TypedArray a, int index);
         public abstract String getString(TypedArray a, int index);
         public abstract int getInt(TypedArray a, int index, int defaultValue);
@@ -70,11 +65,7 @@
         }
     }
 
-    private static class EmptyKeyStyle extends KeyStyle {
-        public EmptyKeyStyle(KeyboardTextsSet textsSet) {
-            super(textsSet);
-        }
-
+    class EmptyKeyStyle extends KeyStyle {
         @Override
         public String[] getStringArray(TypedArray a, int index) {
             return parseStringArray(a, index);
@@ -96,11 +87,12 @@
         }
     }
 
-    private static class DeclaredKeyStyle extends KeyStyle {
+    private class DeclaredKeyStyle extends KeyStyle {
+        private final String mParentStyleName;
         private final HashMap<Integer, Object> mStyleAttributes = new HashMap<Integer, Object>();
 
-        public DeclaredKeyStyle(KeyboardTextsSet textsSet) {
-            super(textsSet);
+        public DeclaredKeyStyle(String parentStyleName) {
+            mParentStyleName = parentStyleName;
         }
 
         @Override
@@ -108,7 +100,11 @@
             if (a.hasValue(index)) {
                 return parseStringArray(a, index);
             }
-            return (String[])mStyleAttributes.get(index);
+            if (mStyleAttributes.containsKey(index)) {
+                return (String[])mStyleAttributes.get(index);
+            }
+            final KeyStyle parentStyle = mStyles.get(mParentStyleName);
+            return parentStyle.getStringArray(a, index);
         }
 
         @Override
@@ -116,7 +112,11 @@
             if (a.hasValue(index)) {
                 return parseString(a, index);
             }
-            return (String)mStyleAttributes.get(index);
+            if (mStyleAttributes.containsKey(index)) {
+                return (String)mStyleAttributes.get(index);
+            }
+            final KeyStyle parentStyle = mStyles.get(mParentStyleName);
+            return parentStyle.getString(a, index);
         }
 
         @Override
@@ -124,15 +124,21 @@
             if (a.hasValue(index)) {
                 return a.getInt(index, defaultValue);
             }
-            final Integer styleValue = (Integer)mStyleAttributes.get(index);
-            return styleValue != null ? styleValue : defaultValue;
+            if (mStyleAttributes.containsKey(index)) {
+                return (Integer)mStyleAttributes.get(index);
+            }
+            final KeyStyle parentStyle = mStyles.get(mParentStyleName);
+            return parentStyle.getInt(a, index, defaultValue);
         }
 
         @Override
         public int getFlag(TypedArray a, int index) {
-            final int value = a.getInt(index, 0);
-            final Integer styleValue = (Integer)mStyleAttributes.get(index);
-            return (styleValue != null ? styleValue : 0) | value;
+            int value = a.getInt(index, 0);
+            if (mStyleAttributes.containsKey(index)) {
+                value |= (Integer)mStyleAttributes.get(index);
+            }
+            final KeyStyle parentStyle = mStyles.get(mParentStyleName);
+            return value | parentStyle.getFlag(a, index);
         }
 
         void readKeyAttributes(TypedArray keyAttr) {
@@ -177,10 +183,6 @@
                 mStyleAttributes.put(index, parseStringArray(a, index));
             }
         }
-
-        void addParentStyleAttributes(DeclaredKeyStyle parentStyle) {
-            mStyleAttributes.putAll(parentStyle.mStyleAttributes);
-        }
     }
 
     public void parseKeyStyleAttributes(TypedArray keyStyleAttr, TypedArray keyAttrs,
@@ -195,26 +197,28 @@
             }
         }
 
-        final DeclaredKeyStyle style = new DeclaredKeyStyle(mTextsSet);
+        String parentStyleName = EMPTY_STYLE_NAME;
         if (keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_parentStyle)) {
-            final String parentStyle = keyStyleAttr.getString(
-                    R.styleable.Keyboard_KeyStyle_parentStyle);
-            final DeclaredKeyStyle parent = mStyles.get(parentStyle);
-            if (parent == null) {
+            parentStyleName = keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_parentStyle);
+            if (!mStyles.containsKey(parentStyleName)) {
                 throw new XmlParseUtils.ParseException(
-                        "Unknown parentStyle " + parentStyle, parser);
+                        "Unknown parentStyle " + parentStyleName, parser);
             }
-            style.addParentStyleAttributes(parent);
         }
+        final DeclaredKeyStyle style = new DeclaredKeyStyle(parentStyleName);
         style.readKeyAttributes(keyAttrs);
         mStyles.put(styleName, style);
     }
 
-    public KeyStyle getKeyStyle(String styleName) {
+    public KeyStyle getKeyStyle(TypedArray keyAttr, XmlPullParser parser)
+            throws XmlParseUtils.ParseException {
+        if (!keyAttr.hasValue(R.styleable.Keyboard_Key_keyStyle)) {
+            return mEmptyKeyStyle;
+        }
+        final String styleName = keyAttr.getString(R.styleable.Keyboard_Key_keyStyle);
+        if (!mStyles.containsKey(styleName)) {
+            throw new XmlParseUtils.ParseException("Unknown key style: " + styleName, parser);
+        }
         return mStyles.get(styleName);
     }
-
-    public KeyStyle getEmptyKeyStyle() {
-        return mEmptyKeyStyle;
-    }
 }
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 7cbee4f..112bde6 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -385,6 +385,7 @@
         }
         // Don't auto-correct words with multiple capital letter
         autoCorrectionAvailable &= !wordComposer.isMostlyCaps();
+        autoCorrectionAvailable &= !wordComposer.isResumed();
         if (allowsToBeAutoCorrected && suggestionsList.size() > 1 && mAutoCorrectionThreshold > 0
                 && Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord,
                         suggestionsList.get(1).mWord)) {
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index bd8532e..e27a546 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -38,6 +38,7 @@
     private int[] mYCoordinates;
     private StringBuilder mTypedWord;
     private CharSequence mAutoCorrection;
+    private boolean mIsResumed;
 
     // Cache these values for performance
     private int mCapsCount;
@@ -57,6 +58,7 @@
         mYCoordinates = new int[N];
         mAutoCorrection = null;
         mTrailingSingleQuotesCount = 0;
+        mIsResumed = false;
         refreshSize();
     }
 
@@ -73,6 +75,7 @@
         mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
         mAutoCapitalized = source.mAutoCapitalized;
         mTrailingSingleQuotesCount = source.mTrailingSingleQuotesCount;
+        mIsResumed = source.mIsResumed;
         refreshSize();
     }
 
@@ -85,6 +88,7 @@
         mCapsCount = 0;
         mIsFirstCharCapitalized = false;
         mTrailingSingleQuotesCount = 0;
+        mIsResumed = false;
         refreshSize();
     }
 
@@ -193,6 +197,7 @@
             int codePoint = Character.codePointAt(word, i);
             addKeyInfo(codePoint, keyboard);
         }
+        mIsResumed = true;
     }
 
     /**
@@ -299,6 +304,13 @@
         return mAutoCorrection;
     }
 
+    /**
+     * @return whether we started composing this word by resuming suggestion on an existing string
+     */
+    public boolean isResumed() {
+        return mIsResumed;
+    }
+
     // `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above.
     public LastComposedWord commitWord(final int type, final String committedWord,
             final int separatorCode) {
@@ -320,6 +332,7 @@
         mTypedWord.setLength(0);
         refreshSize();
         mAutoCorrection = null;
+        mIsResumed = false;
         return lastComposedWord;
     }
 
@@ -331,5 +344,6 @@
         mTypedWord.append(lastComposedWord.mTypedWord);
         refreshSize();
         mAutoCorrection = null; // This will be filled by the next call to updateSuggestion.
+        mIsResumed = true;
     }
 }