Merge "Support automatic language"
diff --git a/java/res/layout/suggestions_strip.xml b/java/res/layout/suggestions_strip.xml
index 9252017..cbf31e6 100644
--- a/java/res/layout/suggestions_strip.xml
+++ b/java/res/layout/suggestions_strip.xml
@@ -22,16 +22,9 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
 >
-    <!-- Placer for debug information -->
-    <RelativeLayout
-        android:id="@+id/suggestions_placer"
+    <LinearLayout
+        android:id="@+id/suggestions_strip"
+        android:orientation="horizontal"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-    >
-        <LinearLayout
-            android:id="@+id/suggestions_strip"
-            android:orientation="horizontal"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent" />
-    </RelativeLayout>
+        android:layout_height="match_parent" />
 </merge>
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index fa6b2eb..2af2554 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -27,11 +27,11 @@
         <attr name="miniKeyboardPanelStyle" format="reference" />
         <!-- Suggestions strip style -->
         <attr name="suggestionsStripBackgroundStyle" format="reference" />
-        <attr name="suggestionsPaneViewStyle" format="reference" />
+        <attr name="suggestionsViewStyle" format="reference" />
+        <attr name="moreSuggestionsViewStyle" format="reference" />
         <attr name="suggestionBackgroundStyle" format="reference" />
         <attr name="suggestionPreviewBackgroundStyle" format="reference" />
-        <attr name="suggestionsViewStyle" format="reference" />
-    </declare-styleable>
+        </declare-styleable>
 
     <declare-styleable name="KeyboardView">
         <!-- Image for the key. This image needs to be a StateListDrawable, with the following
diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml
index c5c298d..0ec65e3 100644
--- a/java/res/values/dimens.xml
+++ b/java/res/values/dimens.xml
@@ -80,7 +80,7 @@
     <dimen name="more_suggestions_key_horizontal_padding">12dip</dimen>
     <dimen name="more_suggestions_row_height">40dip</dimen>
     <dimen name="more_suggestions_slide_allowance">0.2in</dimen>
-    <fraction name="more_suggestions_info_ratio">12%</fraction>
+    <fraction name="more_suggestions_info_ratio">18%</fraction>
     <dimen name="key_preview_backing_height">40dip</dimen>
     <dimen name="suggestions_strip_padding">0dip</dimen>
     <dimen name="suggestion_min_width">44dip</dimen>
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index 17b3d14..45b98ca 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -79,20 +79,9 @@
         <item name="android:paddingLeft">@dimen/mini_keyboard_horizontal_edges_padding</item>
         <item name="android:paddingRight">@dimen/mini_keyboard_horizontal_edges_padding</item>
     </style>
-    <style
-        name="SuggestionsPaneViewStyle"
-        parent="MiniKeyboardView"
-    >
-    </style>
     <style name="SuggestionsStripBackgroundStyle">
         <item name="android:background">@drawable/keyboard_suggest_strip</item>
     </style>
-    <style name="SuggestionBackgroundStyle">
-        <item name="android:background">@drawable/btn_suggestion</item>
-    </style>
-    <style name="SuggestionPreviewBackgroundStyle">
-        <item name="android:background">@drawable/suggestion_feedback_background</item>
-    </style>
     <style
         name="SuggestionsViewStyle"
         parent="SuggestionsStripBackgroundStyle"
@@ -104,6 +93,17 @@
         <item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</item>
         <item name="centerSuggestionPercentile">@integer/center_suggestion_percentile</item>
     </style>
+    <style
+        name="MoreSuggestionsViewStyle"
+        parent="MiniKeyboardView"
+    >
+    </style>
+    <style name="SuggestionBackgroundStyle">
+        <item name="android:background">@drawable/btn_suggestion</item>
+    </style>
+    <style name="SuggestionPreviewBackgroundStyle">
+        <item name="android:background">@drawable/suggestion_feedback_background</item>
+    </style>
     <!-- Theme "Basic high contrast" -->
     <style
         name="KeyboardView.HighContrast"
@@ -232,19 +232,6 @@
     <style name="SuggestionsStripBackgroundStyle.IceCreamSandwich">
         <item name="android:background">@drawable/keyboard_suggest_strip_holo</item>
     </style>
-    <style name="SuggestionBackgroundStyle.IceCreamSandwich">
-        <item name="android:background">@drawable/btn_suggestion_ics</item>
-    </style>
-    <style
-        name="SuggestionPreviewBackgroundStyle.IceCreamSandwich"
-        parent="MiniKeyboardPanelStyle.IceCreamSandwich"
-    >
-    </style>
-    <style
-        name="SuggestionsPaneViewStyle.IceCreamSandwich"
-        parent="MiniKeyboardView.IceCreamSandwich"
-    >
-    </style>
     <style
         name="SuggestionsViewStyle.IceCreamSandwich"
         parent="SuggestionsStripBackgroundStyle.IceCreamSandwich"
@@ -256,6 +243,19 @@
         <item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</item>
         <item name="centerSuggestionPercentile">@integer/center_suggestion_percentile</item>
     </style>
+    <style
+        name="MoreSuggestionsViewStyle.IceCreamSandwich"
+        parent="MiniKeyboardView.IceCreamSandwich"
+    >
+    </style>
+    <style name="SuggestionBackgroundStyle.IceCreamSandwich">
+        <item name="android:background">@drawable/btn_suggestion_ics</item>
+    </style>
+    <style
+        name="SuggestionPreviewBackgroundStyle.IceCreamSandwich"
+        parent="MiniKeyboardPanelStyle.IceCreamSandwich"
+    >
+    </style>
     <style name="MiniKeyboardAnimation">
         <item name="android:windowEnterAnimation">@anim/mini_keyboard_fadein</item>
         <item name="android:windowExitAnimation">@anim/mini_keyboard_fadeout</item>
diff --git a/java/res/values/themes-basic-highcontrast.xml b/java/res/values/themes-basic-highcontrast.xml
index ee41093..a45fa52 100644
--- a/java/res/values/themes-basic-highcontrast.xml
+++ b/java/res/values/themes-basic-highcontrast.xml
@@ -22,9 +22,9 @@
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
-        <item name="suggestionsPaneViewStyle">@style/SuggestionsPaneViewStyle</item>
+        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
+        <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
         <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
         <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
-        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
     </style>
 </resources>
diff --git a/java/res/values/themes-basic.xml b/java/res/values/themes-basic.xml
index ff7f9ed..4f75484 100644
--- a/java/res/values/themes-basic.xml
+++ b/java/res/values/themes-basic.xml
@@ -22,9 +22,9 @@
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
-        <item name="suggestionsPaneViewStyle">@style/SuggestionsPaneViewStyle</item>
+        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
+        <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
         <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
         <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
-        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
     </style>
 </resources>
diff --git a/java/res/values/themes-gingerbread.xml b/java/res/values/themes-gingerbread.xml
index af91c3b..f3a74f3 100644
--- a/java/res/values/themes-gingerbread.xml
+++ b/java/res/values/themes-gingerbread.xml
@@ -22,9 +22,9 @@
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView.Gingerbread</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
-        <item name="suggestionsPaneViewStyle">@style/SuggestionsPaneViewStyle</item>
+        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
+        <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
         <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
         <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
-        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
     </style>
 </resources>
diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml
index 341afcc..4b5ae6d 100644
--- a/java/res/values/themes-ics.xml
+++ b/java/res/values/themes-ics.xml
@@ -22,9 +22,9 @@
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView.IceCreamSandwich</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle.IceCreamSandwich</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle.IceCreamSandwich</item>
-        <item name="suggestionsPaneViewStyle">@style/SuggestionsPaneViewStyle.IceCreamSandwich</item>
+        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle.IceCreamSandwich</item>
+        <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle.IceCreamSandwich</item>
         <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle.IceCreamSandwich</item>
         <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle.IceCreamSandwich</item>
-        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle.IceCreamSandwich</item>
     </style>
 </resources>
diff --git a/java/res/values/themes-stone-bold.xml b/java/res/values/themes-stone-bold.xml
index 915f226..3cff0f1 100644
--- a/java/res/values/themes-stone-bold.xml
+++ b/java/res/values/themes-stone-bold.xml
@@ -22,9 +22,9 @@
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView.Stone</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
-        <item name="suggestionsPaneViewStyle">@style/SuggestionsPaneViewStyle</item>
-            <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
-        <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
         <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
+        <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
+        <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
+        <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
     </style>
 </resources>
diff --git a/java/res/values/themes-stone.xml b/java/res/values/themes-stone.xml
index 6d5b9db..785f410 100644
--- a/java/res/values/themes-stone.xml
+++ b/java/res/values/themes-stone.xml
@@ -22,9 +22,9 @@
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView.Stone</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
-        <item name="suggestionsPaneViewStyle">@style/SuggestionsPaneViewStyle</item>
+        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
+        <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
         <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
         <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
-        <item name="suggestionsViewStyle">@style/SuggestionsViewStyle</item>
     </style>
 </resources>
diff --git a/java/src/com/android/inputmethod/compat/LinearLayoutCompatUtils.java b/java/src/com/android/inputmethod/compat/LinearLayoutCompatUtils.java
deleted file mode 100644
index 674cbe7..0000000
--- a/java/src/com/android/inputmethod/compat/LinearLayoutCompatUtils.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.compat;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.util.AttributeSet;
-import android.util.Log;
-
-import java.lang.reflect.Field;
-
-public class LinearLayoutCompatUtils {
-    private static final String TAG = LinearLayoutCompatUtils.class.getSimpleName();
-
-    private static final Class<?> CLASS_R_STYLEABLE = CompatUtils.getClass(
-            "com.android.internal.R$styleable");
-    private static final Field STYLEABLE_VIEW = CompatUtils.getField(
-            CLASS_R_STYLEABLE, "View");
-    private static final Field STYLEABLE_VIEW_BACKGROUND = CompatUtils.getField(
-            CLASS_R_STYLEABLE, "View_background");
-    private static final Object VALUE_STYLEABLE_VIEW = CompatUtils.getFieldValue(
-            null, null, STYLEABLE_VIEW);
-    private static final Integer VALUE_STYLEABLE_VIEW_BACKGROUND =
-            (Integer)CompatUtils.getFieldValue(null, null, STYLEABLE_VIEW_BACKGROUND);
-
-    public static Drawable getBackgroundDrawable(Context context, AttributeSet attrs,
-            int defStyleAttr, int defStyleRes) {
-        if (!(VALUE_STYLEABLE_VIEW instanceof int[]) || VALUE_STYLEABLE_VIEW_BACKGROUND == null) {
-            Log.w(TAG, "Can't get View background attribute using reflection");
-            return null;
-        }
-
-        final int[] styleableView = (int[])VALUE_STYLEABLE_VIEW;
-        final TypedArray a = context.obtainStyledAttributes(
-                attrs, styleableView, defStyleAttr, defStyleRes);
-        final Drawable background = a.getDrawable(VALUE_STYLEABLE_VIEW_BACKGROUND);
-        a.recycle();
-        return background;
-    }
-}
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
index 9fd9024..0f8192b 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
@@ -73,7 +73,7 @@
     };
 
     public MoreSuggestionsView(Context context, AttributeSet attrs) {
-        this(context, attrs, R.attr.suggestionsPaneViewStyle);
+        this(context, attrs, R.attr.moreSuggestionsViewStyle);
     }
 
     public MoreSuggestionsView(Context context, AttributeSet attrs, int defStyle) {
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 10cd73d..f11ac1d 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -45,10 +45,10 @@
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
+import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 import com.android.inputmethod.compat.FrameLayoutCompatUtils;
-import com.android.inputmethod.compat.LinearLayoutCompatUtils;
 import com.android.inputmethod.keyboard.KeyboardActionListener;
 import com.android.inputmethod.keyboard.KeyboardView;
 import com.android.inputmethod.keyboard.MoreKeysPanel;
@@ -58,7 +58,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-public class SuggestionsView extends LinearLayout implements OnClickListener, OnLongClickListener {
+public class SuggestionsView extends RelativeLayout implements OnClickListener,
+        OnLongClickListener {
     public interface Listener {
         public boolean addWordToDictionary(String word);
         public void pickSuggestionManually(int index, CharSequence word);
@@ -69,7 +70,6 @@
 
     private static final boolean DBG = LatinImeLogger.sDBG;
 
-    private final ViewGroup mSuggestionsPlacer;
     private final ViewGroup mSuggestionsStrip;
     private KeyboardView mKeyboardView;
 
@@ -451,18 +451,7 @@
     }
 
     public SuggestionsView(Context context, AttributeSet attrs, int defStyle) {
-        // Note: Up to version 10 (Gingerbread) of the API, LinearLayout doesn't have 3-argument
-        // constructor.
-        // TODO: Call 3-argument constructor, super(context, attrs, defStyle), when we abandon
-        // backward compatibility with the version 10 or earlier of the API.
-        super(context, attrs);
-        if (defStyle != R.attr.suggestionsViewStyle) {
-            throw new IllegalArgumentException(
-                    "can't accept defStyle other than R.attr.suggestionsViewStyle: defStyle="
-                    + defStyle);
-        }
-        setBackgroundDrawable(LinearLayoutCompatUtils.getBackgroundDrawable(
-                context, attrs, defStyle, R.style.SuggestionsViewStyle));
+        super(context, attrs, defStyle);
 
         final LayoutInflater inflater = LayoutInflater.from(context);
         inflater.inflate(R.layout.suggestions_strip, this);
@@ -474,7 +463,6 @@
         mPreviewPopup.setContentView(mPreviewText);
         mPreviewPopup.setBackgroundDrawable(null);
 
-        mSuggestionsPlacer = (ViewGroup)findViewById(R.id.suggestions_placer);
         mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip);
         for (int pos = 0; pos < MAX_SUGGESTIONS; pos++) {
             final TextView word = (TextView)inflater.inflate(R.layout.suggestion_word, null);
@@ -527,7 +515,7 @@
         if (mSuggestions.size() == 0)
             return;
 
-        mParams.layout(mSuggestions, mSuggestionsStrip, mSuggestionsPlacer, getWidth());
+        mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth());
     }
 
     private static CharSequence getDebugInfo(SuggestedWords suggestions, int pos) {
@@ -648,9 +636,9 @@
 
     public void clear() {
         mShowingAutoCorrectionInverted = false;
-        mSuggestionsPlacer.removeAllViews();
-        mSuggestionsPlacer.addView(mSuggestionsStrip);
         mSuggestionsStrip.removeAllViews();
+        removeAllViews();
+        addView(mSuggestionsStrip);
         dismissMoreSuggestions();
     }