diff --git a/java/res/layout-xlarge/candidates.xml b/java/res/layout-xlarge/candidates.xml
index 096a0adf1155eb166c6ecfb67f7bf041a367ffb6..e111acd5b6b98c11955c789662dffac39f12a5f2 100644
--- a/java/res/layout-xlarge/candidates.xml
+++ b/java/res/layout-xlarge/candidates.xml
@@ -20,6 +20,7 @@
 
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/candidates_container"
     android:orientation="horizontal"
     android:gravity="bottom"
     android:layout_width="match_parent"
diff --git a/java/res/layout/candidates.xml b/java/res/layout/candidates.xml
index 3d91c1d209c759621c008bb0014487feb5c9be43..5c29f737f55054bd21ace6d012840940d8791c2f 100644
--- a/java/res/layout/candidates.xml
+++ b/java/res/layout/candidates.xml
@@ -20,6 +20,7 @@
 
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/candidates_container"
     android:orientation="horizontal"
     android:gravity="bottom"
     android:layout_width="match_parent"
diff --git a/java/res/layout/input_basic.xml b/java/res/layout/input_basic.xml
index 8666daece8ef4ae3e2017c5799e48e66118a9124..ec2f60e9c670ce4691ab7572dba37833c39d46f7 100644
--- a/java/res/layout/input_basic.xml
+++ b/java/res/layout/input_basic.xml
@@ -18,15 +18,21 @@
 */
 -->
 
-<com.android.inputmethod.keyboard.LatinKeyboardView
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+>
+    <include
+        layout="@layout/candidates" />
+    <com.android.inputmethod.keyboard.LatinKeyboardView
         android:id="@+id/latin_keyboard_view"
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:padding="0dip"
         android:background="@drawable/keyboard_background"
-
-        latin:keyBackground="@drawable/btn_keyboard_key"
-        />
+        latin:keyBackground="@drawable/btn_keyboard_key" />
+</LinearLayout>
diff --git a/java/res/layout/input_basic_highcontrast.xml b/java/res/layout/input_basic_highcontrast.xml
index 4829c7d7c48a8d00ded819317e5ecbc342529df3..0a34b1fd7295e3491411b62318b6f3e158a516a8 100644
--- a/java/res/layout/input_basic_highcontrast.xml
+++ b/java/res/layout/input_basic_highcontrast.xml
@@ -18,15 +18,21 @@
 */
 -->
 
-<com.android.inputmethod.keyboard.LatinKeyboardView
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+>
+    <include
+        layout="@layout/candidates" />
+    <com.android.inputmethod.keyboard.LatinKeyboardView
         android:id="@+id/latin_keyboard_view"
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:padding="0dip"
         android:background="@android:color/black"
-
-        latin:keyBackground="@drawable/btn_keyboard_key3"
-        />
+        latin:keyBackground="@drawable/btn_keyboard_key3" />
+</LinearLayout>
diff --git a/java/res/layout/input_gingerbread.xml b/java/res/layout/input_gingerbread.xml
index ccca501af92aa159d5c2da0c425422d226cc8dd9..f620151cf34b34f03a74a7ef36bcd6c31dfde8bb 100644
--- a/java/res/layout/input_gingerbread.xml
+++ b/java/res/layout/input_gingerbread.xml
@@ -18,16 +18,22 @@
 */
 -->
 
-<com.android.inputmethod.keyboard.LatinKeyboardView
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+>
+    <include
+        layout="@layout/candidates" />
+    <com.android.inputmethod.keyboard.LatinKeyboardView
         android:id="@+id/latin_keyboard_view"
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:padding="0dip"
         android:background="@drawable/keyboard_dark_background"
-
         latin:keyBackground="@drawable/btn_keyboard_key_gingerbread"
-        latin:keyLetterStyle="bold"
-        />
+        latin:keyLetterStyle="bold" />
+</LinearLayout>
diff --git a/java/res/layout/input_honeycomb.xml b/java/res/layout/input_honeycomb.xml
index 8dadafd812774471bd144c9b65c2141321cdc9f5..5a7dcb034fab4a0564cf1c4f5ebb7e3f65695d73 100644
--- a/java/res/layout/input_honeycomb.xml
+++ b/java/res/layout/input_honeycomb.xml
@@ -18,16 +18,22 @@
 */
 -->
 
-<com.android.inputmethod.keyboard.LatinKeyboardView
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+>
+    <include
+        layout="@layout/candidates" />
+    <com.android.inputmethod.keyboard.LatinKeyboardView
         android:id="@+id/latin_keyboard_view"
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:padding="0dip"
         android:background="@drawable/keyboard_background_holo"
-
         latin:keyBackground="@drawable/btn_keyboard_key_honeycomb"
         latin:keyPreviewLayout="@layout/key_preview_honeycomb"
         latin:keyPreviewHeight="@dimen/key_preview_height_holo"
@@ -36,5 +42,5 @@
         latin:keyTextColorDisabled="#FF63666D"
         latin:keyLetterStyle="bold"
         latin:shadowColor="#00000000"
-        latin:shadowRadius="0.0"
-        />
+        latin:shadowRadius="0.0" />
+</LinearLayout>
diff --git a/java/res/layout/input_stone_bold.xml b/java/res/layout/input_stone_bold.xml
index a0b40684f0da310aebabd39bc91901492bd3cd26..ca0794cefcb018b38b61bb80e1783fa2fb76705d 100644
--- a/java/res/layout/input_stone_bold.xml
+++ b/java/res/layout/input_stone_bold.xml
@@ -18,21 +18,27 @@
 */
 -->
 
-<com.android.inputmethod.keyboard.LatinKeyboardView
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+>
+    <include
+        layout="@layout/candidates" />
+    <com.android.inputmethod.keyboard.LatinKeyboardView
         android:id="@+id/latin_keyboard_view"
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:padding="0dip"
         android:background="@drawable/keyboard_background"
-
         latin:keyBackground="@drawable/btn_keyboard_key_stone"
         latin:keyTextColor="@color/latinkeyboard_key_color_black"
         latin:keyTextColorDisabled="#FF808080"
         latin:shadowColor="@color/latinkeyboard_key_color_white"
         latin:keyLetterStyle="bold"
         latin:colorScheme="black"
-        latin:popupLayout="@layout/keyboard_popup_stone"
-        />
+        latin:popupLayout="@layout/keyboard_popup_stone" />
+</LinearLayout>
diff --git a/java/res/layout/input_stone_normal.xml b/java/res/layout/input_stone_normal.xml
index 41cbc16faada4c088e8638b7edb1d49995684dac..9d5afb68b401bfb81126579977360c2e546b9dd9 100644
--- a/java/res/layout/input_stone_normal.xml
+++ b/java/res/layout/input_stone_normal.xml
@@ -18,20 +18,26 @@
 */
 -->
 
-<com.android.inputmethod.keyboard.LatinKeyboardView
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+>
+    <include
+        layout="@layout/candidates" />
+    <com.android.inputmethod.keyboard.LatinKeyboardView
         android:id="@+id/latin_keyboard_view"
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:padding="0dip"
         android:background="@drawable/keyboard_background"
-
         latin:keyBackground="@drawable/btn_keyboard_key_stone"
         latin:keyTextColor="@color/latinkeyboard_key_color_black"
         latin:keyTextColorDisabled="#FF808080"
         latin:shadowColor="@color/latinkeyboard_key_color_white"
         latin:colorScheme="black"
-        latin:popupLayout="@layout/keyboard_popup_stone"
-        />
+        latin:popupLayout="@layout/keyboard_popup_stone" />
+</LinearLayout>
diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
index 7ea4165ba7c474903de8ac45159158f5b57b0d6c..85993ea4dd54638d879a372d5c1ab49f5621db21 100644
--- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
+++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
@@ -536,7 +536,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
                     ((ViewGroup) p).removeView(v);
                 }
 
-                View keyboardView = KeyboardSwitcher.getInstance().getInputView();
+                View keyboardView = KeyboardSwitcher.getInstance().getKeyboardView();
 
                 // The full height of the keyboard is difficult to calculate
                 // as the dimension is expressed in "mm" and not in "pixel"
@@ -691,7 +691,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
         if (mSubtypeSwitcher.isVoiceMode() && windowToken != null) {
             // Close keyboard view if it is been shown.
             if (KeyboardSwitcher.getInstance().isInputViewShown())
-                KeyboardSwitcher.getInstance().getInputView().purgeKeyboardAndClosing();
+                KeyboardSwitcher.getInstance().getKeyboardView().purgeKeyboardAndClosing();
             startListening(false, windowToken);
         }
         // If we have no token, onAttachedToWindow will take care of showing dialog and start
diff --git a/java/src/com/android/inputmethod/deprecated/recorrection/RecorrectionSuggestionEntries.java b/java/src/com/android/inputmethod/deprecated/recorrection/RecorrectionSuggestionEntries.java
index 914e2cbc1c752ab14152854f68d15213ddb5dcad..5e6c8704450e351bf40a6e7e13a6e8fc9681d751 100644
--- a/java/src/com/android/inputmethod/deprecated/recorrection/RecorrectionSuggestionEntries.java
+++ b/java/src/com/android/inputmethod/deprecated/recorrection/RecorrectionSuggestionEntries.java
@@ -57,6 +57,6 @@ public class RecorrectionSuggestionEntries {
 
     private static SuggestedWords.Builder getTypedSuggestions(
             Suggest suggest, KeyboardSwitcher keyboardSwitcher, WordComposer word) {
-        return suggest.getSuggestedWordBuilder(keyboardSwitcher.getInputView(), word, null);
+        return suggest.getSuggestedWordBuilder(keyboardSwitcher.getKeyboardView(), word, null);
     }
 }
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 88823108fbddaeb2f10ab6d743f1f37440fb83a9..33e76d83f58d532695c64cfe5b58fb5a4374fb43 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -16,6 +16,15 @@
 
 package com.android.inputmethod.keyboard;
 
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.util.Log;
+import android.view.InflateException;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+
 import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
 import com.android.inputmethod.latin.LatinIME;
 import com.android.inputmethod.latin.LatinImeLogger;
@@ -24,13 +33,6 @@ import com.android.inputmethod.latin.Settings;
 import com.android.inputmethod.latin.SubtypeSwitcher;
 import com.android.inputmethod.latin.Utils;
 
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.util.Log;
-import android.view.InflateException;
-import android.view.inputmethod.EditorInfo;
-
 import java.lang.ref.SoftReference;
 import java.util.HashMap;
 import java.util.Locale;
@@ -54,7 +56,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     private SubtypeSwitcher mSubtypeSwitcher;
     private SharedPreferences mPrefs;
 
-    private LatinKeyboardView mInputView;
+    private View mInputView;
+    private LatinKeyboardView mKeyboardView;
     private LatinIME mInputMethodService;
 
     // TODO: Combine these key state objects with auto mode switch state.
@@ -143,7 +146,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
 
     private void loadKeyboardInternal(EditorInfo attribute, boolean voiceButtonEnabled,
             boolean voiceButtonOnPrimary, boolean isSymbols) {
-        if (mInputView == null) return;
+        if (mKeyboardView == null) return;
 
         mAttribute = attribute;
         mVoiceKeyEnabled = voiceButtonEnabled;
@@ -178,11 +181,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     }
 
     private void setKeyboard(final Keyboard newKeyboard) {
-        final Keyboard oldKeyboard = mInputView.getKeyboard();
-        mInputView.setKeyboard(newKeyboard);
+        final Keyboard oldKeyboard = mKeyboardView.getKeyboard();
+        mKeyboardView.setKeyboard(newKeyboard);
         mCurrentId = newKeyboard.mId;
         final Resources res = mInputMethodService.getResources();
-        mInputView.setKeyPreviewPopupEnabled(
+        mKeyboardView.setKeyPreviewPopupEnabled(
                 Settings.Values.isKeyPreviewPopupEnabled(mPrefs, res),
                 Settings.Values.getKeyPreviewPopupDismissDelay(mPrefs, res));
         final boolean localeChanged = (oldKeyboard == null)
@@ -291,18 +294,18 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     }
 
     public boolean isInputViewShown() {
-        return mInputView != null && mInputView.isShown();
+        return mKeyboardView != null && mKeyboardView.isShown();
     }
 
     public boolean isKeyboardAvailable() {
-        if (mInputView != null)
-            return mInputView.getKeyboard() != null;
+        if (mKeyboardView != null)
+            return mKeyboardView.getKeyboard() != null;
         return false;
     }
 
     public LatinKeyboard getLatinKeyboard() {
-        if (mInputView != null) {
-            final Keyboard keyboard = mInputView.getKeyboard();
+        if (mKeyboardView != null) {
+            final Keyboard keyboard = mKeyboardView.getKeyboard();
             if (keyboard instanceof LatinKeyboard)
                 return (LatinKeyboard)keyboard;
         }
@@ -355,7 +358,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
                 latinKeyboard.setShiftLocked(false);
             }
             if (latinKeyboard.setShifted(shifted)) {
-                mInputView.invalidateAllKeys();
+                mKeyboardView.invalidateAllKeys();
             }
         }
     }
@@ -363,7 +366,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     private void setShiftLocked(boolean shiftLocked) {
         LatinKeyboard latinKeyboard = getLatinKeyboard();
         if (latinKeyboard != null && latinKeyboard.setShiftLocked(shiftLocked)) {
-            mInputView.invalidateAllKeys();
+            mKeyboardView.invalidateAllKeys();
         }
     }
 
@@ -405,7 +408,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
         LatinKeyboard latinKeyboard = getLatinKeyboard();
         if (latinKeyboard != null) {
             latinKeyboard.setAutomaticTemporaryUpperCase();
-            mInputView.invalidateAllKeys();
+            mKeyboardView.invalidateAllKeys();
         }
     }
 
@@ -500,7 +503,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
                 // To be able to turn off caps lock by "double tap" on shift key, we should ignore
                 // the second tap of the "double tap" from now for a while because we just have
                 // already turned off caps lock above.
-                mInputView.startIgnoringDoubleTap();
+                mKeyboardView.startIgnoringDoubleTap();
             } else if (isShiftedOrShiftLocked() && shiftKeyState.isPressingOnShifted()
                     && !withSliding) {
                 // Shift has been pressed without chording while shifted state.
@@ -589,11 +592,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     }
 
     public boolean isVibrateAndSoundFeedbackRequired() {
-        return mInputView == null || !mInputView.isInSlidingKeyInput();
+        return mKeyboardView == null || !mKeyboardView.isInSlidingKeyInput();
     }
 
     private int getPointerCount() {
-        return mInputView == null ? 0 : mInputView.getPointerCount();
+        return mKeyboardView == null ? 0 : mKeyboardView.getPointerCount();
     }
 
     private void toggleKeyboardMode() {
@@ -606,7 +609,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     }
 
     public boolean hasDistinctMultitouch() {
-        return mInputView != null && mInputView.hasDistinctMultitouch();
+        return mKeyboardView != null && mKeyboardView.hasDistinctMultitouch();
     }
 
     private static boolean isSpaceCharacter(int c) {
@@ -703,20 +706,20 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
         }
     }
 
-    public LatinKeyboardView getInputView() {
-        return mInputView;
+    public LatinKeyboardView getKeyboardView() {
+        return mKeyboardView;
     }
 
-    public LatinKeyboardView onCreateInputView() {
+    public View onCreateInputView() {
         createInputViewInternal(mLayoutId, true);
         return mInputView;
     }
 
     private void createInputViewInternal(int newLayout, boolean forceReset) {
         int layoutId = newLayout;
-        if (mLayoutId != layoutId || mInputView == null || forceReset) {
-            if (mInputView != null) {
-                mInputView.closing();
+        if (mLayoutId != layoutId || mKeyboardView == null || forceReset) {
+            if (mKeyboardView != null) {
+                mKeyboardView.closing();
             }
             if (KEYBOARD_THEMES.length <= layoutId) {
                 layoutId = Integer.valueOf(sConfigDefaultKeyboardThemeId);
@@ -726,8 +729,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
             boolean tryGC = true;
             for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
                 try {
-                    mInputView = (LatinKeyboardView) mInputMethodService.getLayoutInflater(
-                            ).inflate(KEYBOARD_THEMES[layoutId], null);
+                    mInputView = LayoutInflater.from(mInputMethodService).inflate(
+                            KEYBOARD_THEMES[layoutId], null);
                     tryGC = false;
                 } catch (OutOfMemoryError e) {
                     Log.w(TAG, "load keyboard failed: " + e);
@@ -739,7 +742,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
                             mLayoutId + "," + layoutId, e);
                 }
             }
-            mInputView.setOnKeyboardActionListener(mInputMethodService);
+            mKeyboardView = (LatinKeyboardView)mInputView.findViewById(R.id.latin_keyboard_view);
+            mKeyboardView.setOnKeyboardActionListener(mInputMethodService);
             mLayoutId = layoutId;
         }
     }
@@ -748,8 +752,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
         mInputMethodService.mHandler.post(new Runnable() {
             @Override
             public void run() {
-                if (mInputView != null) {
-                    mInputMethodService.setInputView(mInputView);
+                if (mKeyboardView != null) {
+                    mInputMethodService.setInputView(mKeyboardView);
                 }
                 mInputMethodService.updateInputViewShown();
             }
@@ -772,13 +776,13 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     }
 
     private int getColorScheme() {
-        return (mInputView != null)
-                ? mInputView.getColorScheme() : KeyboardView.COLOR_SCHEME_WHITE;
+        return (mKeyboardView != null)
+                ? mKeyboardView.getColorScheme() : KeyboardView.COLOR_SCHEME_WHITE;
     }
 
     public void onAutoCorrectionStateChanged(boolean isAutoCorrection) {
         if (isAutoCorrection != mIsAutoCorrectionActive) {
-            LatinKeyboardView keyboardView = getInputView();
+            LatinKeyboardView keyboardView = getKeyboardView();
             mIsAutoCorrectionActive = isAutoCorrection;
             keyboardView.invalidateKey(((LatinKeyboard) keyboardView.getKeyboard())
                     .onAutoCorrectionStateChanged(isAutoCorrection));
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index edf84e435446dd64bc711c5f3a906178eb7e79d1..6cb928321ec68d325b7d98e5c13952b89701bfd3 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -16,22 +16,6 @@
 
 package com.android.inputmethod.latin;
 
-import com.android.inputmethod.compat.CompatUtils;
-import com.android.inputmethod.compat.EditorInfoCompatUtils;
-import com.android.inputmethod.compat.InputConnectionCompatUtils;
-import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
-import com.android.inputmethod.compat.InputTypeCompatUtils;
-import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
-import com.android.inputmethod.deprecated.VoiceProxy;
-import com.android.inputmethod.deprecated.recorrection.Recorrection;
-import com.android.inputmethod.keyboard.Keyboard;
-import com.android.inputmethod.keyboard.KeyboardActionListener;
-import com.android.inputmethod.keyboard.KeyboardSwitcher;
-import com.android.inputmethod.keyboard.KeyboardView;
-import com.android.inputmethod.keyboard.LatinKeyboard;
-import com.android.inputmethod.keyboard.LatinKeyboardView;
-
 import android.app.AlertDialog;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -59,7 +43,6 @@ import android.util.PrintWriterPrinter;
 import android.util.Printer;
 import android.view.HapticFeedbackConstants;
 import android.view.KeyEvent;
-import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewParent;
@@ -69,7 +52,22 @@ import android.view.inputmethod.CompletionInfo;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.ExtractedText;
 import android.view.inputmethod.InputConnection;
-import android.widget.LinearLayout;
+
+import com.android.inputmethod.compat.CompatUtils;
+import com.android.inputmethod.compat.EditorInfoCompatUtils;
+import com.android.inputmethod.compat.InputConnectionCompatUtils;
+import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
+import com.android.inputmethod.compat.InputTypeCompatUtils;
+import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
+import com.android.inputmethod.deprecated.VoiceProxy;
+import com.android.inputmethod.deprecated.recorrection.Recorrection;
+import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.keyboard.KeyboardActionListener;
+import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.keyboard.KeyboardView;
+import com.android.inputmethod.keyboard.LatinKeyboard;
+import com.android.inputmethod.keyboard.LatinKeyboardView;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
@@ -217,7 +215,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         @Override
         public void handleMessage(Message msg) {
             final KeyboardSwitcher switcher = mKeyboardSwitcher;
-            final LatinKeyboardView inputView = switcher.getInputView();
+            final LatinKeyboardView inputView = switcher.getKeyboardView();
             switch (msg.what) {
             case MSG_UPDATE_SUGGESTIONS:
                 updateSuggestions();
@@ -307,7 +305,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         public void startDisplayLanguageOnSpacebar(boolean localeChanged) {
             removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR);
             removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
-            final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
+            final LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
             if (inputView != null) {
                 final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
                 // The language is always displayed when the delay is negative.
@@ -483,25 +481,23 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
 
     @Override
     public View onCreateInputView() {
-        return mKeyboardSwitcher.onCreateInputView();
+        final View inputView = mKeyboardSwitcher.onCreateInputView();
+        mCandidateViewContainer = inputView.findViewById(R.id.candidates_container);
+        mCandidateView = (CandidateView) inputView.findViewById(R.id.candidates);
+        mCandidateStripHeight = (int)mResources.getDimension(R.dimen.candidate_strip_height);
+        return inputView;
     }
 
     @Override
-    public View onCreateCandidatesView() {
-        LayoutInflater inflater = getLayoutInflater();
-        LinearLayout container = (LinearLayout)inflater.inflate(R.layout.candidates, null);
-        mCandidateViewContainer = container;
-        mCandidateStripHeight = (int)mResources.getDimension(R.dimen.candidate_strip_height);
-        mCandidateView = (CandidateView) container.findViewById(R.id.candidates);
-        mCandidateView.setService(this);
-        setCandidatesViewShown(true);
-        return container;
+    public void setCandidatesView(View view) {
+        // To ensure that CandidatesView will never be set.
+        return;
     }
 
     @Override
     public void onStartInputView(EditorInfo attribute, boolean restarting) {
         final KeyboardSwitcher switcher = mKeyboardSwitcher;
-        LatinKeyboardView inputView = switcher.getInputView();
+        LatinKeyboardView inputView = switcher.getKeyboardView();
 
         if (DEBUG) {
             Log.d(TAG, "onStartInputView: " + inputView);
@@ -550,7 +546,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
             switcher.updateShiftState();
         }
 
-        setCandidatesViewShownInternal(isCandidateStripVisible(), false /* needsInputViewShown */ );
+        setSuggestionStripShownInternal(isCandidateStripVisible(), /* needsInputViewShown */ false);
         // Delay updating suggestions because keyboard input view may not be shown at this point.
         mHandler.postUpdateSuggestions();
 
@@ -626,7 +622,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
     @Override
     public void onWindowHidden() {
         super.onWindowHidden();
-        KeyboardView inputView = mKeyboardSwitcher.getInputView();
+        KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
         if (inputView != null) inputView.closing();
     }
 
@@ -639,7 +635,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
 
         mVoiceProxy.flushVoiceInputLogs(mConfigurationChanging);
 
-        KeyboardView inputView = mKeyboardSwitcher.getInputView();
+        KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
         if (inputView != null) inputView.closing();
         if (mAutoDictionary != null) mAutoDictionary.flushPendingWrites();
         if (mUserBigramDictionary != null) mUserBigramDictionary.flushPendingWrites();
@@ -648,7 +644,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
     @Override
     public void onFinishInputView(boolean finishingInput) {
         super.onFinishInputView(finishingInput);
-        KeyboardView inputView = mKeyboardSwitcher.getInputView();
+        KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
         if (inputView != null) inputView.setForeground(false);
         // Remove pending messages related to update suggestions
         mHandler.cancelUpdateSuggestions();
@@ -804,11 +800,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
             // When in fullscreen mode, show completions generated by the application
             setSuggestions(builder.build());
             mBestWord = null;
-            setCandidatesViewShown(true);
+            setSuggestionStripShown(true);
         }
     }
 
-    private void setCandidatesViewShownInternal(boolean shown, boolean needsInputViewShown) {
+    private void setSuggestionStripShownInternal(boolean shown, boolean needsInputViewShown) {
         // TODO: Modify this if we support candidates with hard keyboard
         if (onEvaluateInputViewShown()) {
             final boolean shouldShowCandidates = shown
@@ -816,26 +812,25 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
             if (isExtractViewShown()) {
                 // No need to have extra space to show the key preview.
                 mCandidateViewContainer.setMinimumHeight(0);
-                super.setCandidatesViewShown(shouldShowCandidates);
+                mCandidateViewContainer.setVisibility(
+                        shouldShowCandidates ? View.VISIBLE : View.GONE);
             } else {
                 // We must control the visibility of the suggestion strip in order to avoid clipped
                 // key previews, even when we don't show the suggestion strip.
                 mCandidateViewContainer.setVisibility(
                         shouldShowCandidates ? View.VISIBLE : View.INVISIBLE);
-                super.setCandidatesViewShown(true);
             }
         }
     }
 
-    @Override
-    public void setCandidatesViewShown(boolean shown) {
-        setCandidatesViewShownInternal(shown, true /* needsInputViewShown */ );
+    private void setSuggestionStripShown(boolean shown) {
+        setSuggestionStripShownInternal(shown, /* needsInputViewShown */true);
     }
 
     @Override
     public void onComputeInsets(InputMethodService.Insets outInsets) {
         super.onComputeInsets(outInsets);
-        final KeyboardView inputView = mKeyboardSwitcher.getInputView();
+        final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
         if (inputView == null)
             return;
         final int containerHeight = mCandidateViewContainer.getHeight();
@@ -877,8 +872,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
     public boolean onKeyDown(int keyCode, KeyEvent event) {
         switch (keyCode) {
         case KeyEvent.KEYCODE_BACK:
-            if (event.getRepeatCount() == 0 && mKeyboardSwitcher.getInputView() != null) {
-                if (mKeyboardSwitcher.getInputView().handleBack()) {
+            if (event.getRepeatCount() == 0 && mKeyboardSwitcher.getKeyboardView() != null) {
+                if (mKeyboardSwitcher.getKeyboardView().handleBack()) {
                     return true;
                 }
             }
@@ -1365,7 +1360,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         commitTyped(getCurrentInputConnection());
         mVoiceProxy.handleClose();
         requestHideSelf(0);
-        LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
+        LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
         if (inputView != null)
             inputView.closing();
     }
@@ -1401,7 +1396,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         if (DEBUG) {
             Log.d(TAG, "Switch to keyboard view.");
         }
-        View v = mKeyboardSwitcher.getInputView();
+        View v = mKeyboardSwitcher.getKeyboardView();
         if (v != null) {
             // Confirms that the keyboard view doesn't have parent view.
             ViewParent p = v.getParent();
@@ -1410,7 +1405,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
             }
             setInputView(v);
         }
-        setCandidatesViewShown(isCandidateStripVisible());
+        setSuggestionStripShown(isCandidateStripVisible());
         updateInputViewShown();
         mHandler.postUpdateSuggestions();
     }
@@ -1452,7 +1447,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
                 mSettingsValues.mWordSeparators);
         SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
-                mKeyboardSwitcher.getInputView(), word, prevWord);
+                mKeyboardSwitcher.getKeyboardView(), word, prevWord);
 
         boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
         final CharSequence typedWord = word.getTypedWord();
@@ -1501,7 +1496,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         } else {
             mBestWord = null;
         }
-        setCandidatesViewShown(isCandidateStripVisible());
+        setSuggestionStripShown(isCandidateStripVisible());
     }
 
     private boolean pickDefaultSuggestion(int separatorCode) {
@@ -1664,7 +1659,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(),
                 mSettingsValues.mWordSeparators);
         SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
-                mKeyboardSwitcher.getInputView(), sEmptyWordComposer, prevWord);
+                mKeyboardSwitcher.getKeyboardView(), sEmptyWordComposer, prevWord);
 
         if (builder.size() > 0) {
             // Explicitly supply an empty typed word (the no-second-arg version of
@@ -1677,7 +1672,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
 
     public void setPunctuationSuggestions() {
         setSuggestions(mSettingsValues.mSuggestPuncList);
-        setCandidatesViewShown(isCandidateStripVisible());
+        setSuggestionStripShown(isCandidateStripVisible());
     }
 
     private void addToAutoAndUserBigramDictionaries(CharSequence suggestion, int frequencyDelta) {
@@ -1886,7 +1881,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         // if mAudioManager is null, we don't have the ringer state yet
         // mAudioManager will be set by updateRingerMode
         if (mAudioManager == null) {
-            if (mKeyboardSwitcher.getInputView() != null) {
+            if (mKeyboardSwitcher.getKeyboardView() != null) {
                 updateRingerMode();
             }
         }
@@ -1913,7 +1908,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
         if (!mSettingsValues.mVibrateOn) {
             return;
         }
-        LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
+        LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
         if (inputView != null) {
             inputView.performHapticFeedback(
                     HapticFeedbackConstants.KEYBOARD_TAP,
@@ -2037,7 +2032,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
 
     private void showOptionsMenuInternal(CharSequence title, CharSequence[] items,
             DialogInterface.OnClickListener listener) {
-        final IBinder windowToken = mKeyboardSwitcher.getInputView().getWindowToken();
+        final IBinder windowToken = mKeyboardSwitcher.getKeyboardView().getWindowToken();
         if (windowToken == null) return;
         AlertDialog.Builder builder = new AlertDialog.Builder(this);
         builder.setCancelable(true);
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 50128430d29f8d6383940ca769a116c73be34455..8b51af880ea054ecf4b3fca2a7b8ce8927f7ca62 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -413,7 +413,7 @@ public class SubtypeSwitcher {
         final KeyboardSwitcher switcher = KeyboardSwitcher.getInstance();
         final LatinKeyboard keyboard = switcher.getLatinKeyboard();
         if (keyboard != null) {
-            keyboard.updateShortcutKey(isShortcutImeReady(), switcher.getInputView());
+            keyboard.updateShortcutKey(isShortcutImeReady(), switcher.getKeyboardView());
         }
     }
 
@@ -503,7 +503,7 @@ public class SubtypeSwitcher {
     private void triggerVoiceIME() {
         if (!mService.isInputViewShown()) return;
         VoiceProxy.getInstance().startListening(false,
-                KeyboardSwitcher.getInstance().getInputView().getWindowToken());
+                KeyboardSwitcher.getInstance().getKeyboardView().getWindowToken());
     }
 
     //////////////////////////////////////