Merge "Remove shouldBlockAutoCorrectionBySafetyNet"
diff --git a/java-overridable/src/com/android/inputmethod/latin/accounts/LoginAccountUtils.java b/java-overridable/src/com/android/inputmethod/latin/accounts/LoginAccountUtils.java
index 70f152a..e07a9f3 100644
--- a/java-overridable/src/com/android/inputmethod/latin/accounts/LoginAccountUtils.java
+++ b/java-overridable/src/com/android/inputmethod/latin/accounts/LoginAccountUtils.java
@@ -16,16 +16,20 @@
 
 package com.android.inputmethod.latin.accounts;
 
-import android.accounts.Account;
 import android.content.Context;
 
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 
 /**
  * Utility class for retrieving accounts that may be used for login.
  */
 public class LoginAccountUtils {
+    /**
+     * This defines the type of account this class deals with.
+     * This account type is used when listing the accounts available on the device for login.
+     */
+    public static final String ACCOUNT_TYPE = "";
+
     private LoginAccountUtils() {
         // This utility class is not publicly instantiable.
     }
@@ -39,9 +43,4 @@
     public static String[] getAccountsForLogin(final Context context) {
         return new String[0];
     }
-
-    @Nullable
-    public static Account getCurrentAccount(final Context context) {
-        return null;
-    }
 }
diff --git a/java-overridable/src/com/android/inputmethod/latin/define/ProductionFlags.java b/java-overridable/src/com/android/inputmethod/latin/define/ProductionFlags.java
index 10fc612..99b9589 100644
--- a/java-overridable/src/com/android/inputmethod/latin/define/ProductionFlags.java
+++ b/java-overridable/src/com/android/inputmethod/latin/define/ProductionFlags.java
@@ -46,5 +46,5 @@
     /**
      * When {@code true}, personal dictionary sync feature is ready to be enabled.
      */
-    public static final boolean ENABLE_PERSONAL_DICTIONARY_SYNC = false;
+    public static final boolean ENABLE_PERSONAL_DICTIONARY_SYNC = ENABLE_ACCOUNT_SIGN_IN && false;
 }
diff --git a/java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java b/java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java
index 1c02d7d..747a3b0 100644
--- a/java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java
+++ b/java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java
@@ -19,6 +19,12 @@
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.preference.PreferenceFragment;
+import android.view.inputmethod.InputMethodSubtype;
+
+import com.android.inputmethod.latin.RichInputMethodSubtype;
+import com.android.inputmethod.latin.RichInputMethodManager;
+
+import javax.annotation.Nonnull;
 
 /**
  * Utility class for managing additional features settings.
@@ -39,4 +45,10 @@
             final SharedPreferences prefs, final int[] additionalFeaturesPreferences) {
         // do nothing.
     }
+
+    public static RichInputMethodSubtype createRichInputMethodSubtype(
+            @Nonnull final RichInputMethodManager imm,
+            @Nonnull final InputMethodSubtype subtype) {
+        return new RichInputMethodSubtype(subtype);
+    }
 }
diff --git a/java-overridable/src/com/android/inputmethod/latin/sync/BeanstalkManager.java b/java-overridable/src/com/android/inputmethod/latin/sync/BeanstalkManager.java
deleted file mode 100644
index 2242d92..0000000
--- a/java-overridable/src/com/android/inputmethod/latin/sync/BeanstalkManager.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 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.latin.sync;
-
-import android.content.Context;
-
-import javax.annotation.Nonnull;
-import javax.annotation.concurrent.GuardedBy;
-
-public class BeanstalkManager {
-    private static final Object sLock = new Object();
-
-    @GuardedBy("sLock")
-    private static BeanstalkManager sInstance;
-
-    /**
-     * @return the singleton instance of {@link BeanstalkManager}.
-     */
-    @Nonnull
-    public static BeanstalkManager getInstance(Context context) {
-        synchronized(sLock) {
-            if (sInstance == null) {
-                sInstance = new BeanstalkManager(context.getApplicationContext());
-            }
-        }
-        return sInstance;
-    }
-
-    private BeanstalkManager(final Context context) {
-        // Intentional private constructor for singleton.
-    }
-
-    public void onCreate() {
-    }
-
-    public void requestSync() {
-    }
-
-    public void onDestroy() {
-    }
-}
\ No newline at end of file
diff --git a/java/res/drawable-hdpi/ic_add_circle_wht_24dp.png b/java/res/drawable-hdpi/ic_add_circle_white_24dp.png
similarity index 100%
rename from java/res/drawable-hdpi/ic_add_circle_wht_24dp.png
rename to java/res/drawable-hdpi/ic_add_circle_white_24dp.png
Binary files differ
diff --git a/java/res/drawable-mdpi/ic_add_circle_wht_24dp.png b/java/res/drawable-mdpi/ic_add_circle_white_24dp.png
similarity index 100%
rename from java/res/drawable-mdpi/ic_add_circle_wht_24dp.png
rename to java/res/drawable-mdpi/ic_add_circle_white_24dp.png
Binary files differ
diff --git a/java/res/drawable-xhdpi/ic_add_circle_wht_24dp.png b/java/res/drawable-xhdpi/ic_add_circle_white_24dp.png
similarity index 100%
rename from java/res/drawable-xhdpi/ic_add_circle_wht_24dp.png
rename to java/res/drawable-xhdpi/ic_add_circle_white_24dp.png
Binary files differ
diff --git a/java/res/drawable-xxhdpi/ic_add_circle_wht_24dp.png b/java/res/drawable-xxhdpi/ic_add_circle_white_24dp.png
similarity index 100%
rename from java/res/drawable-xxhdpi/ic_add_circle_wht_24dp.png
rename to java/res/drawable-xxhdpi/ic_add_circle_white_24dp.png
Binary files differ
diff --git a/java/res/layout/input_view.xml b/java/res/layout/input_view.xml
index 46551f6..ae3c19d 100644
--- a/java/res/layout/input_view.xml
+++ b/java/res/layout/input_view.xml
@@ -21,7 +21,8 @@
 <com.android.inputmethod.latin.InputView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content">
+    android:layout_height="wrap_content"
+    style="?attr/inputViewStyle">
     <include
         android:id="@+id/main_keyboard_frame"
         layout="@layout/main_keyboard_frame" />
diff --git a/java/res/menu/add_style.xml b/java/res/menu/add_style.xml
index d1cab4b..befa3f2 100644
--- a/java/res/menu/add_style.xml
+++ b/java/res/menu/add_style.xml
@@ -20,7 +20,7 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
     <item
         android:id="@+id/action_add_style"
-        android:icon="@drawable/ic_add_circle_wht_24dp"
+        android:icon="@drawable/ic_add_circle_white_24dp"
         android:title="@string/add_style"
         android:showAsAction="always" />
-</menu>
\ No newline at end of file
+</menu>
diff --git a/java/res/values-km-rKH/strings-emoji-descriptions.xml b/java/res/values-km-rKH/strings-emoji-descriptions.xml
index 9f1d997..757df50 100644
--- a/java/res/values-km-rKH/strings-emoji-descriptions.xml
+++ b/java/res/values-km-rKH/strings-emoji-descriptions.xml
@@ -25,16 +25,16 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="spoken_emoji_00A9" msgid="2859822817116803638">"សញ្ញា​រក្សា​សិទ្ធ"</string>
+    <string name="spoken_emoji_00A9" msgid="2859822817116803638">"សញ្ញា​រក្សា​សិទ្ធ​"</string>
     <string name="spoken_emoji_00AE" msgid="7708335454134589027">"សញ្ញា​​​ចុះ​បញ្ជី"</string>
     <string name="spoken_emoji_203C" msgid="153340916701508663">"សញ្ញា​ឧទាន​​ពីរ"</string>
-    <string name="spoken_emoji_2049" msgid="4877256448299555371">"សញ្ញា​​ឧទាន​សញ្ញា​សួរ"</string>
+    <string name="spoken_emoji_2049" msgid="4877256448299555371">"សញ្ញា​​ឧទាន​សញ្ញា​សួរ​​"</string>
     <string name="spoken_emoji_2122" msgid="9188440722954720429">"សញ្ញា​​​និក្ខិត្តសញ្ញា"</string>
     <string name="spoken_emoji_2139" msgid="9114342638917304327">"ប្រភព​ព័ត៌មាន"</string>
     <string name="spoken_emoji_2194" msgid="8055202727034946680">"ព្រួញ​ឆ្វេងស្ដាំ"</string>
     <string name="spoken_emoji_2195" msgid="8028122253301087407">"ព្រួញ​ឡើង​លើ​ចុះក្រោម"</string>
     <string name="spoken_emoji_2196" msgid="4019164898967854363">"ព្រួញ​ទិសពាយព្យ"</string>
-    <string name="spoken_emoji_2197" msgid="4255723717709017801">"ព្រួញ​​ទិស​ឥសាន្ត​ឦសាន្ត"</string>
+    <string name="spoken_emoji_2197" msgid="4255723717709017801">"ព្រួញ​​ទិស​ឥសាន្ត​ឦសាន្ត​"</string>
     <string name="spoken_emoji_2198" msgid="1452063451313622090">"ព្រួញ​​ទិស​អាគ្នេយ៍"</string>
     <string name="spoken_emoji_2199" msgid="6942722693368807849">"ព្រួញ​​ទិស​និរតី"</string>
     <string name="spoken_emoji_21A9" msgid="5204750172335111188">"ព្រួញ​ទៅ​ឆ្វេង​មាន​ទំពក់"</string>
@@ -45,7 +45,7 @@
     <string name="spoken_emoji_23EA" msgid="2251396938087774944">"ត្រីកោណ​ខ្មៅ​ពីរ​ចង្អុល​ទៅ​ឆ្វេង"</string>
     <string name="spoken_emoji_23EB" msgid="3746885195641491865">"ត្រីកោណ​ខ្មៅ​ពីរ​ចង្អុល​​ឡើង​លើ"</string>
     <string name="spoken_emoji_23EC" msgid="7852372752901163416">"ត្រីកោណ​ខ្មៅ​ពីរ​ចង្អុល​​ចុះក្រោម"</string>
-    <string name="spoken_emoji_23F0" msgid="8474219588750627870">"នាឡិកា​រោទ៍"</string>
+    <string name="spoken_emoji_23F0" msgid="8474219588750627870">"នាឡិកា​រោទ៍​"</string>
     <string name="spoken_emoji_23F3" msgid="166900119581024371">"កែវ​ពិសោធន៍​មាន​ខ្សាច់ហូរ"</string>
     <string name="spoken_emoji_24C2" msgid="3948348737566038470">"អក្សរ​អឹម​ធំ​ក្នុង​រង្វង់"</string>
     <string name="spoken_emoji_25AA" msgid="7865181015100227349">"ការ៉េ​តូច​​ពណ៌ខ្មៅ"</string>
@@ -195,7 +195,7 @@
     <string name="spoken_emoji_1F312" msgid="4458575672576125401">"ព្រះ​ចន្ទ​មួយ​ចំណិត​ស្ដាំ"</string>
     <string name="spoken_emoji_1F313" msgid="7599181787989497294">"ព្រះ​ចន្ទ​ពាក់​កណ្ដាល"</string>
     <string name="spoken_emoji_1F314" msgid="4898293184964365413">"ព្រះ​ចន្ទ​មួយ​ចំណិត​ឆ្វេង"</string>
-    <string name="spoken_emoji_1F315" msgid="3218117051779496309">"ព្រះចន្ទ​ពេញ​វង់"</string>
+    <string name="spoken_emoji_1F315" msgid="3218117051779496309">"ព្រះចន្ទ​ពេញ​វង់​"</string>
     <string name="spoken_emoji_1F316" msgid="2061317145777689569">"ព្រះ​ចន្ទ​ភ្លឺ​មួយ​ចំហៀង"</string>
     <string name="spoken_emoji_1F317" msgid="2721090687319539049">"ព្រះ​ចន្ទ​ភ្លឺ​ពាក់​កណ្ដាល"</string>
     <string name="spoken_emoji_1F318" msgid="3814091755648887570">"ព្រះ​ចន្ទ​ភ្លឺ​មួយ​ចំណិត​ឆ្វេង"</string>
@@ -262,7 +262,7 @@
     <string name="spoken_emoji_1F365" msgid="4963815540953316307">"នំ​ត្រី​រាង​មូល"</string>
     <string name="spoken_emoji_1F366" msgid="7862401745277049404">"ការ៉េម​​បំពង់"</string>
     <string name="spoken_emoji_1F367" msgid="7447972978281980414">"ការ៉េម​កែវ"</string>
-    <string name="spoken_emoji_1F368" msgid="7790003146142724913">"ការ៉េម"</string>
+    <string name="spoken_emoji_1F368" msgid="7790003146142724913">"ការ៉េម​"</string>
     <string name="spoken_emoji_1F369" msgid="7383712944084857350">"ដូណាត់"</string>
     <string name="spoken_emoji_1F36A" msgid="2726271795913042295">"ខូគី"</string>
     <string name="spoken_emoji_1F36B" msgid="6342163604299875931">"​​សូកូឡា"</string>
@@ -280,7 +280,7 @@
     <string name="spoken_emoji_1F377" msgid="1762398562314172075">"កែវ​ស្រា"</string>
     <string name="spoken_emoji_1F378" msgid="5528234560590117516">"កែវ​ស្រា​ក្រឡុក"</string>
     <string name="spoken_emoji_1F379" msgid="790581290787943325">"ភេសជ្ជៈ​​​ត្រូពិក"</string>
-    <string name="spoken_emoji_1F37A" msgid="391966822450619516">"កែវ​​ស្រាបៀ"</string>
+    <string name="spoken_emoji_1F37A" msgid="391966822450619516">"កែវ​​ស្រាបៀ​"</string>
     <string name="spoken_emoji_1F37B" msgid="9015043286465670662">"ជល់​កែវ​ស្រាបៀ"</string>
     <string name="spoken_emoji_1F37C" msgid="2532113819464508894">"ដប​ទឹកដោះ​គោ"</string>
     <string name="spoken_emoji_1F380" msgid="3487363857092458827">"ខ្សែ​បូ"</string>
@@ -313,7 +313,7 @@
     <string name="spoken_emoji_1F3A7" msgid="837856608794094105">"កាស"</string>
     <string name="spoken_emoji_1F3A8" msgid="2332260356509244587">"ក្ដារ​លាយ​ពណ៌​វិចិត្រករ"</string>
     <string name="spoken_emoji_1F3A9" msgid="9045869366525115256">"មួក​​​សម្ដែង​សិល្បៈ"</string>
-    <string name="spoken_emoji_1F3AA" msgid="5728760354237132">"តង់​សៀក"</string>
+    <string name="spoken_emoji_1F3AA" msgid="5728760354237132">"តង់​សៀក​"</string>
     <string name="spoken_emoji_1F3AB" msgid="1657997517193216284">"សំបុត្រ"</string>
     <string name="spoken_emoji_1F3AC" msgid="4317366554314492152">"បន្ទះកណ្ដឹង"</string>
     <string name="spoken_emoji_1F3AD" msgid="607157286336130470">"សម្ដែង​សិល្បៈ"</string>
@@ -334,10 +334,10 @@
     <string name="spoken_emoji_1F3BC" msgid="1608424748821446230">"និមិត្តសញ្ញា​តន្ត្រី"</string>
     <string name="spoken_emoji_1F3BD" msgid="5490786111375627777">"អាវ​កីឡា​​មាន​ខ្សែ​ឆៀង"</string>
     <string name="spoken_emoji_1F3BE" msgid="1851613105691627931">"រ៉ាកែត និង​បាល់"</string>
-    <string name="spoken_emoji_1F3BF" msgid="6862405997423247921">"ជិះ​ស្គី ​និង​ក្ដារ​​ស្គី"</string>
+    <string name="spoken_emoji_1F3BF" msgid="6862405997423247921">"ជិះ​ស្គី ​និង​ក្ដារ​​ស្គី​"</string>
     <string name="spoken_emoji_1F3C0" msgid="7421420756115104085">"បាល់​បោះ​ និង​វណ្ណ​មូល"</string>
     <string name="spoken_emoji_1F3C1" msgid="6926537251677319922">"ទង់ជាតិ​ប្រណាំង​ម៉ូតូ"</string>
-    <string name="spoken_emoji_1F3C2" msgid="5708596929237987082">"អ្នក​ជិះ​​ក្ដារ​រំអិល​លើ​ព្រិល"</string>
+    <string name="spoken_emoji_1F3C2" msgid="5708596929237987082">"អ្នក​ជិះ​​ក្ដារ​រំអិល​លើ​ព្រិល​"</string>
     <string name="spoken_emoji_1F3C3" msgid="5850982999510115824">"អ្នក​រត់"</string>
     <string name="spoken_emoji_1F3C4" msgid="8468355585994639838">"អ្នក​ជិះ​ទូក​រអិល​លើ​ទឹក"</string>
     <string name="spoken_emoji_1F3C6" msgid="9094474706847545409">"ពាន​រង្វាន់"</string>
@@ -354,7 +354,7 @@
     <string name="spoken_emoji_1F3E6" msgid="342132788513806214">"ធនាគារ"</string>
     <string name="spoken_emoji_1F3E7" msgid="6322352038284944265">"ម៉ាស៊ីន​​អេធីអឹម"</string>
     <string name="spoken_emoji_1F3E8" msgid="5864918444350599907">"សណ្ឋាគារ"</string>
-    <string name="spoken_emoji_1F3E9" msgid="7830416185375326938">"សណ្ឋាគារ​ក្ដី​ស្រឡាញ់"</string>
+    <string name="spoken_emoji_1F3E9" msgid="7830416185375326938">"សណ្ឋាគារ​ក្ដី​ស្រឡាញ់​"</string>
     <string name="spoken_emoji_1F3EA" msgid="5081084413084360479">"ហាង​​ទំនិញ ២៤​ម៉ោង"</string>
     <string name="spoken_emoji_1F3EB" msgid="7010966528205150525">"សាលារៀន"</string>
     <string name="spoken_emoji_1F3EC" msgid="4845978861878295154">"ហាង​​ទំនិញធំៗ"</string>
@@ -439,12 +439,12 @@
     <string name="spoken_emoji_1F44D" msgid="6182553970602667815">"​មេដៃ​ឡើង​លើ"</string>
     <string name="spoken_emoji_1F44E" msgid="8030851867365111809">"​មេដៃ​ចុះ​ក្រោម"</string>
     <string name="spoken_emoji_1F44F" msgid="5148753662268213389">"ទះ​ដៃ"</string>
-    <string name="spoken_emoji_1F450" msgid="1012021072085157054">"លា​ដៃ"</string>
+    <string name="spoken_emoji_1F450" msgid="1012021072085157054">"លា​ដៃ​"</string>
     <string name="spoken_emoji_1F451" msgid="8257466714629051320">"មកុដ"</string>
     <string name="spoken_emoji_1F452" msgid="4567394011149905466">"មួក​​ស្ត្រី"</string>
     <string name="spoken_emoji_1F453" msgid="5978410551173163010">"វ៉ែនតា"</string>
-    <string name="spoken_emoji_1F454" msgid="348469036193323252">"ក្រ​វ៉ាត់​ករ"</string>
-    <string name="spoken_emoji_1F455" msgid="5665118831861433578">"អាវ​យឺត"</string>
+    <string name="spoken_emoji_1F454" msgid="348469036193323252">"ក្រ​វ៉ាត់​ករ​"</string>
+    <string name="spoken_emoji_1F455" msgid="5665118831861433578">"អាវ​យឺត​​"</string>
     <string name="spoken_emoji_1F456" msgid="1890991330923356408">"ខោ​ខោវប៊យ"</string>
     <string name="spoken_emoji_1F457" msgid="3904310482655702620">"សំលៀក​បំពាក់"</string>
     <string name="spoken_emoji_1F458" msgid="5704243858031107692">"គី​ម៉ូណូ"</string>
@@ -463,8 +463,8 @@
     <string name="spoken_emoji_1F465" msgid="4461307702499679879">"គណនី"</string>
     <string name="spoken_emoji_1F466" msgid="1938873085514108889">"ក្មេង​​ប្រុស"</string>
     <string name="spoken_emoji_1F467" msgid="8237080594860144998">"ក្មេង​ស្រី"</string>
-    <string name="spoken_emoji_1F468" msgid="6081300722526675382">"បុរស"</string>
-    <string name="spoken_emoji_1F469" msgid="1090140923076108158">"ស្ត្រី"</string>
+    <string name="spoken_emoji_1F468" msgid="6081300722526675382">"បុរស​"</string>
+    <string name="spoken_emoji_1F469" msgid="1090140923076108158">"ស្ត្រី​"</string>
     <string name="spoken_emoji_1F46A" msgid="5063570981942606595">"គ្រួសារ"</string>
     <string name="spoken_emoji_1F46B" msgid="6795882374287327952">"បុរស​​ និង​ស្ត្រី​កាន់ដៃ​គ្នា"</string>
     <string name="spoken_emoji_1F46C" msgid="6844464165783964495">"បុរស​ពីរ​នាក់​កាន់​ដៃ​គ្នា"</string>
@@ -490,16 +490,16 @@
     <string name="spoken_emoji_1F480" msgid="3696253485164878739">"លលាដ៍​ក្បាល"</string>
     <string name="spoken_emoji_1F481" msgid="320408708521966893">"អ្នក​ផ្ដល់​ព័ត៌មាន"</string>
     <string name="spoken_emoji_1F482" msgid="3424354860245608949">"អ្នក​យាម"</string>
-    <string name="spoken_emoji_1F483" msgid="3221113594843849083">"អ្នក​រាំ"</string>
+    <string name="spoken_emoji_1F483" msgid="3221113594843849083">"អ្នក​រាំ​"</string>
     <string name="spoken_emoji_1F484" msgid="7348014979080444885">"ក្រេម​លាប​បបូរ​មាត់"</string>
     <string name="spoken_emoji_1F485" msgid="6133507975565116339">"ថ្នាំ​លាប​​​ក្រចក"</string>
     <string name="spoken_emoji_1F486" msgid="9085459968247394155">"ម៉ាស្សា​មុខ"</string>
     <string name="spoken_emoji_1F487" msgid="1479113637259592150">"កាត់សក់"</string>
     <string name="spoken_emoji_1F488" msgid="6922559285234100252">"ស្លាក​សញ្ញា​កាត់សក់"</string>
     <string name="spoken_emoji_1F489" msgid="8114863680950147305">"ស៊ីរ៉ាំង"</string>
-    <string name="spoken_emoji_1F48A" msgid="8526843630145963032">"ថ្នាំ​គ្រាប់"</string>
+    <string name="spoken_emoji_1F48A" msgid="8526843630145963032">"ថ្នាំ​គ្រាប់​"</string>
     <string name="spoken_emoji_1F48B" msgid="2538528967897640292">"ស្នាម​ថើប"</string>
-    <string name="spoken_emoji_1F48C" msgid="1681173271652890232">"លិខិត​ស្នេហា"</string>
+    <string name="spoken_emoji_1F48C" msgid="1681173271652890232">"លិខិត​ស្នេហា​"</string>
     <string name="spoken_emoji_1F48D" msgid="8259886164999042373">"រោទ៍"</string>
     <string name="spoken_emoji_1F48E" msgid="8777981696011111101">"ត្បូង​ថ្ម"</string>
     <string name="spoken_emoji_1F48F" msgid="741593675183677907">"ថើប"</string>
@@ -525,7 +525,7 @@
     <string name="spoken_emoji_1F4A3" msgid="6378351742957821735">"គ្រាប់បែក"</string>
     <string name="spoken_emoji_1F4A4" msgid="7217736258870346625">"និមិត្ត​សញ្ញា​​ដេក"</string>
     <string name="spoken_emoji_1F4A5" msgid="5401995723541239858">"និមិត្ត​សញ្ញា​​ប៉ះ​ទង្គិច​គ្នា"</string>
-    <string name="spoken_emoji_1F4A6" msgid="3837802182716483848">"និមិត្ត​សញ្ញា​​ស្រក់​ញើស"</string>
+    <string name="spoken_emoji_1F4A6" msgid="3837802182716483848">"និមិត្ត​សញ្ញា​​ស្រក់​ញើស​"</string>
     <string name="spoken_emoji_1F4A7" msgid="5718438987757885141">"ដំណក់​ទឹក"</string>
     <string name="spoken_emoji_1F4A8" msgid="4472108229720006377">"និមិត្ត​សញ្ញា​​ដកឃ្លា"</string>
     <string name="spoken_emoji_1F4A9" msgid="1240958472788430032">"គំនរ​ធូលី"</string>
@@ -539,7 +539,7 @@
     <string name="spoken_emoji_1F4B1" msgid="8339494003418572905">"ប្ដូរ​​រូបិយប័ណ្ណ"</string>
     <string name="spoken_emoji_1F4B2" msgid="3179159430187243132">"សញ្ញា​ដុល្លារ"</string>
     <string name="spoken_emoji_1F4B3" msgid="5375412518221759596">"កាត​​ឥណទាន"</string>
-    <string name="spoken_emoji_1F4B4" msgid="1068592463669453204">"ក្រដាស​ប្រាក់​​ធនាគារ​មាន​សញ្ញា​​យ៉េន"</string>
+    <string name="spoken_emoji_1F4B4" msgid="1068592463669453204">"ក្រដាស​ប្រាក់​​ធនាគារ​មាន​សញ្ញា​​យ៉េន​​"</string>
     <string name="spoken_emoji_1F4B5" msgid="1426708699891832564">"លុយដុល្លារ"</string>
     <string name="spoken_emoji_1F4B6" msgid="8289249930736444837">"ក្រដាស​ប្រាក់​​ធនាគារ​មាន​សញ្ញា​អឺរ៉ូ"</string>
     <string name="spoken_emoji_1F4B7" msgid="5245100496860739429">"ក្រដាស​ប្រាក់​​ធនាគារ​មាន​សញ្ញា​​​ផោន"</string>
@@ -547,7 +547,7 @@
     <string name="spoken_emoji_1F4B9" msgid="647509393536679903">"ក្រាហ្វិក​និន្នាការ​ឡើង​​មាន​​សញ្ញា​យ៉េន"</string>
     <string name="spoken_emoji_1F4BA" msgid="1269737854891046321">"កៅអី"</string>
     <string name="spoken_emoji_1F4BB" msgid="6252883563347816451">"កុំព្យូទ័រ​ផ្ទាល់ខ្លួន"</string>
-    <string name="spoken_emoji_1F4BC" msgid="6182597732218446206">"វ៉ា​លី"</string>
+    <string name="spoken_emoji_1F4BC" msgid="6182597732218446206">"វ៉ា​លី​"</string>
     <string name="spoken_emoji_1F4BD" msgid="5820961044768829176">"ឌីស​​តូច"</string>
     <string name="spoken_emoji_1F4BE" msgid="4754542485835379808">"ថា​ស​​ទន់"</string>
     <string name="spoken_emoji_1F4BF" msgid="2237481756984721795">"ថាស"</string>
@@ -557,7 +557,7 @@
     <string name="spoken_emoji_1F4C3" msgid="3727274466173970142">"ទំព័រ​​កោង"</string>
     <string name="spoken_emoji_1F4C4" msgid="4382570710795501612">"ទំព័រ​បញ្ឈរ"</string>
     <string name="spoken_emoji_1F4C5" msgid="8693944622627762487">"ប្រតិទិន"</string>
-    <string name="spoken_emoji_1F4C6" msgid="8469908708708424640">"ហែក​ប្រតិទិន"</string>
+    <string name="spoken_emoji_1F4C6" msgid="8469908708708424640">"ហែក​ប្រតិទិន​"</string>
     <string name="spoken_emoji_1F4C7" msgid="2665313547987324495">"​កាត​រៀប​តាម​អក្សរ"</string>
     <string name="spoken_emoji_1F4C8" msgid="8007686702282833600">"ក្រាហ្វិក​មាន​និន្នាការ​ឡើង"</string>
     <string name="spoken_emoji_1F4C9" msgid="2271951411192893684">"ក្រាហ្វិក​មាន​និន្នាការ​ចុះ"</string>
@@ -573,11 +573,11 @@
     <string name="spoken_emoji_1F4D3" msgid="5873386492793610808">"សៀវភៅ"</string>
     <string name="spoken_emoji_1F4D4" msgid="4754469936418776360">"សៀវភៅ​មាន​ក្រប​ពណ៌"</string>
     <string name="spoken_emoji_1F4D5" msgid="4642713351802778905">"សៀវភៅ​​បិទ"</string>
-    <string name="spoken_emoji_1F4D6" msgid="6987347918381807186">"សៀវភៅ​បើក"</string>
+    <string name="spoken_emoji_1F4D6" msgid="6987347918381807186">"សៀវភៅ​បើក​​"</string>
     <string name="spoken_emoji_1F4D7" msgid="7813394163241379223">"សៀវភៅ​​ពណ៌​បៃតង"</string>
     <string name="spoken_emoji_1F4D8" msgid="7189799718984979521">"សៀវភៅ​​ពណ៌​ខៀវ"</string>
     <string name="spoken_emoji_1F4D9" msgid="3874664073186440225">"សៀវភៅ​​ពណ៌​ទឹកក្រូច"</string>
-    <string name="spoken_emoji_1F4DA" msgid="872212072924287762">"សៀវភៅ"</string>
+    <string name="spoken_emoji_1F4DA" msgid="872212072924287762">"សៀវភៅ​"</string>
     <string name="spoken_emoji_1F4DB" msgid="2015183603583392969">"ស្លាកឈ្មោះ"</string>
     <string name="spoken_emoji_1F4DC" msgid="5075845110932456783">"ក្រដាស​រមូរ"</string>
     <string name="spoken_emoji_1F4DD" msgid="2494006707147586786">"កំណត់ចំណាំ"</string>
@@ -589,7 +589,7 @@
     <string name="spoken_emoji_1F4E3" msgid="5588916572878599224">"ឧបករណ៍​បំពង​សំឡេង"</string>
     <string name="spoken_emoji_1F4E4" msgid="2063561529097749707">"ថា​ស​​​ចេញ"</string>
     <string name="spoken_emoji_1F4E5" msgid="3232462702926143576">"ថា​ស​ចូល"</string>
-    <string name="spoken_emoji_1F4E6" msgid="3399454337197561635">"កញ្ចប់"</string>
+    <string name="spoken_emoji_1F4E6" msgid="3399454337197561635">"កញ្ចប់​"</string>
     <string name="spoken_emoji_1F4E7" msgid="5557136988503873238">"និមិត្ត​សញ្ញា​អ៊ីមែល"</string>
     <string name="spoken_emoji_1F4E8" msgid="30698793974124123">"ស្រោម​​សំបុត្រ​ចូល"</string>
     <string name="spoken_emoji_1F4E9" msgid="5947550337678643166">"ស្រោម​សំបុត្រ​​មាន​សញ្ញា​ព្រួញ​ពី​លើ"</string>
@@ -626,7 +626,7 @@
     <string name="spoken_emoji_1F50C" msgid="7793219132036431680">"ដុយ​អគ្គិសនី"</string>
     <string name="spoken_emoji_1F50D" msgid="8140244710637926780">"កែវ​ពង្រីក​ចង្អុល​ខាង​ឆ្វេង"</string>
     <string name="spoken_emoji_1F50E" msgid="4751821352839693365">"កែវ​ពង្រីក​ចង្អុល​ខាង​ស្ដាំ"</string>
-    <string name="spoken_emoji_1F50F" msgid="915079280472199605">"ចាក់សោ​​​ដោយ​ប្រើ​​ប៊ិច"</string>
+    <string name="spoken_emoji_1F50F" msgid="915079280472199605">"ចាក់សោ​​​ដោយ​ប្រើ​​ប៊ិច​"</string>
     <string name="spoken_emoji_1F510" msgid="7658381761691758318">"បិទ​​សោ​ដោយ​ប្រើ​​​​កូនសោ"</string>
     <string name="spoken_emoji_1F511" msgid="262319867774655688">"សោ"</string>
     <string name="spoken_emoji_1F512" msgid="5628688337255115175">"ចាក់សោ"</string>
@@ -645,15 +645,15 @@
     <string name="spoken_emoji_1F51F" msgid="8673370823728653973">"គ្រាប់​ចុច​ ១០"</string>
     <string name="spoken_emoji_1F520" msgid="7335109890337048900">"និមិត្ត​សញ្ញា​បញ្ចូល​សម្រាប់​អក្សរ​ឡាតាំង​ធំ"</string>
     <string name="spoken_emoji_1F521" msgid="2693185864450925778">"និមិត្ត​សញ្ញា​បញ្ចូល​សម្រាប់​អក្សរ​ឡាតាំង​តូច"</string>
-    <string name="spoken_emoji_1F522" msgid="8419130286280673347">"និមិត្ត​សញ្ញា​បញ្ចូល​សម្រាប់​​លេខ"</string>
+    <string name="spoken_emoji_1F522" msgid="8419130286280673347">"និមិត្ត​សញ្ញា​បញ្ចូល​សម្រាប់​​លេខ​"</string>
     <string name="spoken_emoji_1F523" msgid="3318053476401719421">"ការ​បញ្ចូល​និមិត្តសញ្ញា"</string>
     <string name="spoken_emoji_1F524" msgid="1625073997522316331">"និមិត្ត​សញ្ញា​បញ្ចូល​សម្រាប់​អក្សរ​ឡាតាំង"</string>
     <string name="spoken_emoji_1F525" msgid="4083884189172963790">"ភ្លើង"</string>
     <string name="spoken_emoji_1F526" msgid="2035494936742643580">"ពិល​​អគ្គិសនី"</string>
     <string name="spoken_emoji_1F527" msgid="134257142354034271">"ម៉ាឡេត"</string>
     <string name="spoken_emoji_1F528" msgid="700627429570609375">"ញញួរ"</string>
-    <string name="spoken_emoji_1F529" msgid="7480548235904988573">"ឡោ​ស៊ី"</string>
-    <string name="spoken_emoji_1F52A" msgid="7613580031502317893">"កាំបិត"</string>
+    <string name="spoken_emoji_1F529" msgid="7480548235904988573">"ឡោ​ស៊ី​​"</string>
+    <string name="spoken_emoji_1F52A" msgid="7613580031502317893">"កាំបិត​​"</string>
     <string name="spoken_emoji_1F52B" msgid="4554906608328118613">"កាំភ្លើង​ខ្លី"</string>
     <string name="spoken_emoji_1F52C" msgid="1330294501371770790">"មីក្រូទស្សន៍"</string>
     <string name="spoken_emoji_1F52D" msgid="7549551775445177140">"កែវ​យឹត"</string>
@@ -662,7 +662,7 @@
     <string name="spoken_emoji_1F530" msgid="3572898444281774023">"និមិត្តសញ្ញា​ជប៉ុន​សម្រាប់​អ្នក​ចាប់ផ្ដើម"</string>
     <string name="spoken_emoji_1F531" msgid="5225633376450025396">"លំពែង​មុខ​បី"</string>
     <string name="spoken_emoji_1F532" msgid="9169568490485180779">"ប៊ូតុង​ការេ​ពណ៌​ខ្មៅ"</string>
-    <string name="spoken_emoji_1F533" msgid="6554193837201918598">"ប៊ូតុង​ការ៉េ​ពណ៌​ស"</string>
+    <string name="spoken_emoji_1F533" msgid="6554193837201918598">"ប៊ូតុង​ការ៉េ​ពណ៌​ស​"</string>
     <string name="spoken_emoji_1F534" msgid="8339298801331865340">"រង្វង់​ពណ៌​ក្រហម​​​ធំ"</string>
     <string name="spoken_emoji_1F535" msgid="1227403104835533512">"រង្វង់​ពណ៌​ខៀវ​ធំ"</string>
     <string name="spoken_emoji_1F536" msgid="5477372445510469331">"ពេជ្រ​ពណ៌​ទឹកក្រូច​ធំ"</string>
@@ -745,8 +745,8 @@
     <string name="spoken_emoji_1F628" msgid="8875777401624904224">"មុខ​ភ័យ​ខ្លាច"</string>
     <string name="spoken_emoji_1F629" msgid="1411538490319190118">"មុខ​​នឿយហត់"</string>
     <string name="spoken_emoji_1F62A" msgid="4726686726690289969">"មុខ​​ងងុយ​គេង"</string>
-    <string name="spoken_emoji_1F62B" msgid="3221980473921623613">"មុខ​អស់កម្លាំង"</string>
-    <string name="spoken_emoji_1F62C" msgid="4616356691941225182">"មុខ​ក្រញេវក្រញូវ"</string>
+    <string name="spoken_emoji_1F62B" msgid="3221980473921623613">"មុខ​អស់កម្លាំង​​"</string>
+    <string name="spoken_emoji_1F62C" msgid="4616356691941225182">"មុខ​ក្រញេវក្រញូវ​"</string>
     <string name="spoken_emoji_1F62D" msgid="4283677508698812232">"មុខ​យំ​លឺៗ"</string>
     <string name="spoken_emoji_1F62E" msgid="726083405284353894">"មុខ​បើក​មាត់"</string>
     <string name="spoken_emoji_1F62F" msgid="7746620088234710962">"មុខ​ស្ងៀមស្ងាត់"</string>
@@ -784,7 +784,7 @@
     <string name="spoken_emoji_1F683" msgid="8772750354339223092">"ទូរ​​រថភ្លើង"</string>
     <string name="spoken_emoji_1F684" msgid="346396777356203608">"រថភ្លើង​ល្បឿន​លឿន"</string>
     <string name="spoken_emoji_1F685" msgid="1237059817190832730">"រថភ្លើង​ល្បឿន​លឿន​​មាន​ច្រមុះ"</string>
-    <string name="spoken_emoji_1F686" msgid="3525197227223620343">"រថភ្លើង"</string>
+    <string name="spoken_emoji_1F686" msgid="3525197227223620343">"រថភ្លើង​"</string>
     <string name="spoken_emoji_1F687" msgid="5110143437960392837">"មេត្រូ"</string>
     <string name="spoken_emoji_1F688" msgid="4702085029871797965">"រថភ្លើង​ប្រើ​​​ពន្លឺ"</string>
     <string name="spoken_emoji_1F689" msgid="2375851019798817094">"ស្ថានីយ"</string>
@@ -803,7 +803,7 @@
     <string name="spoken_emoji_1F696" msgid="6391604457418285404">"តាក់ស៊ី​ខាង​មុខ"</string>
     <string name="spoken_emoji_1F697" msgid="7978399334396733790">"រថយន្ត"</string>
     <string name="spoken_emoji_1F698" msgid="7006050861129732018">"រថយន្ត​ខាង​មុខ"</string>
-    <string name="spoken_emoji_1F699" msgid="630317052666590607">"រថយន្ត​​​សម្រាប់​កម្សាន្ត"</string>
+    <string name="spoken_emoji_1F699" msgid="630317052666590607">"រថយន្ត​​​សម្រាប់​កម្សាន្ត​"</string>
     <string name="spoken_emoji_1F69A" msgid="4739797891735823577">"រថយន្ត​​ចែក​ចាយ"</string>
     <string name="spoken_emoji_1F69B" msgid="4715997280786620649">"ឡាន​កាមីយ៉ុង"</string>
     <string name="spoken_emoji_1F69C" msgid="5557395610750818161">"ត្រាក់ទ័រ"</string>
@@ -819,7 +819,7 @@
     <string name="spoken_emoji_1F6A6" msgid="485575967773793454">"ភ្លើង​ចរាចរណ៍​បញ្ឈរ"</string>
     <string name="spoken_emoji_1F6A7" msgid="6411048933816976794">"សញ្ញា​​សំណង់"</string>
     <string name="spoken_emoji_1F6A8" msgid="6345717218374788364">"រថយន្ត​​ប៉ូលិស​បើក​សារ៉ែន​វិល"</string>
-    <string name="spoken_emoji_1F6A9" msgid="6586380356807600412">"បង្គោល​ទង់ជាតិ​រាង​ត្រីកោណ"</string>
+    <string name="spoken_emoji_1F6A9" msgid="6586380356807600412">"បង្គោល​ទង់ជាតិ​រាង​ត្រីកោណ​"</string>
     <string name="spoken_emoji_1F6AA" msgid="8954448167261738885">"ទ្វារ"</string>
     <string name="spoken_emoji_1F6AB" msgid="5313946262888343544">"សញ្ញា​ហាម​ចូល"</string>
     <string name="spoken_emoji_1F6AC" msgid="6946858177965948288">"​សញ្ញា​ជក់​បារី"</string>
diff --git a/java/res/values-km-rKH/strings-talkback-descriptions.xml b/java/res/values-km-rKH/strings-talkback-descriptions.xml
index 29d3b95..f907832 100644
--- a/java/res/values-km-rKH/strings-talkback-descriptions.xml
+++ b/java/res/values-km-rKH/strings-talkback-descriptions.xml
@@ -78,7 +78,7 @@
     <string name="spoken_emoji_unknown" msgid="5981009928135394306">"មិន​ស្គាល់​សញ្ញា​អារម្មណ៍"</string>
     <string name="spoken_emoticon_3A_2D_21_20" msgid="2410905667389534573">"មុខ​អផ្សុក"</string>
     <string name="spoken_emoticon_3A_2D_24_20" msgid="2481260475945560438">"មុខ​ខ្មាស​​អៀន"</string>
-    <string name="spoken_emoticon_42_2D_29_20" msgid="1063205250387128068">"ពាក់​វ៉ែនតា"</string>
+    <string name="spoken_emoticon_42_2D_29_20" msgid="1063205250387128068">"ពាក់​វ៉ែនតា​"</string>
     <string name="spoken_emoticon_3A_4F_20" msgid="532695091593447238">"មុខ​ភ្ញាក់ផ្អើល"</string>
     <string name="spoken_emoticon_3A_2D_2A_20" msgid="5612342617244114291">"មុខ​ថើប"</string>
     <string name="spoken_emoticon_3A_2D_5B_20" msgid="2223507987759905920">"មុខ​ចង​ចិញ្ចើម"</string>
diff --git a/java/res/values-km-rKH/strings.xml b/java/res/values-km-rKH/strings.xml
index eb28194..e9a29af 100644
--- a/java/res/values-km-rKH/strings.xml
+++ b/java/res/values-km-rKH/strings.xml
@@ -39,7 +39,7 @@
     <string name="include_other_imes_in_language_switch_list_summary" msgid="840637129103317635">"គ្រាប់ចុច​ប្ដូរ​ភាសា​តាម​វិធីសាស្ត្រ​បញ្ចូល​ផ្សេងទៀត"</string>
     <string name="show_language_switch_key" msgid="5915478828318774384">"គ្រាប់​ចុច​ប្ដូរ​​ភាសា"</string>
     <string name="show_language_switch_key_summary" msgid="7343403647474265713">"បង្ហាញ​នៅ​ពេល​ដែល​បើក​ភាសា​បញ្ចូល​ច្រើន"</string>
-    <string name="key_preview_popup_dismiss_delay" msgid="6213164897443068248">"​សោ​លេចឡើង​បោះបង់​ការ​​ពន្យារពេល"</string>
+    <string name="key_preview_popup_dismiss_delay" msgid="6213164897443068248">"​សោ​លេចឡើង​បោះបង់​ការ​​ពន្យារពេល​"</string>
     <string name="key_preview_popup_dismiss_no_delay" msgid="2096123151571458064">"គ្មាន​ការ​ពន្យារពេល"</string>
     <string name="key_preview_popup_dismiss_default_delay" msgid="2166964333903906734">"លំនាំដើម"</string>
     <string name="abbreviation_unit_milliseconds" msgid="8700286094028323363">"<xliff:g id="MILLISECONDS">%s</xliff:g> មិល្លី​វិនាទី"</string>
@@ -50,7 +50,7 @@
     <string name="enable_metrics_logging" msgid="5506372337118822837">"ធ្វើឲ្យ <xliff:g id="APPLICATION_NAME">%s</xliff:g> ប្រសើរ​ឡើង"</string>
     <string name="use_double_space_period" msgid="8781529969425082860">"រយៈ​ពេល​ចុច​ដកឃ្លា​ពីរដង"</string>
     <string name="use_double_space_period_summary" msgid="6532892187247952799">"ប៉ះ​ដកឃ្លា​ពីរ​​ដង​បញ្ចូល​​​រយៈ​ពេល​ដែល​អនុវត្ត​តាម​ដកឃ្លា"</string>
-    <string name="auto_cap" msgid="1719746674854628252">"ការ​សរសេរ​ជា​អក្សរ​ធំ​​ស្វ័យប្រវត្តិ"</string>
+    <string name="auto_cap" msgid="1719746674854628252">"ការ​សរសេរ​ជា​អក្សរ​ធំ​​ស្វ័យប្រវត្តិ​"</string>
     <string name="auto_cap_summary" msgid="7934452761022946874">"សរសេរ​ពាក្យ​ដំបូង​​​ជា​អក្សរ​ធំ​​នៃ​ប្រយោគ​នីមួយ​ៗ"</string>
     <string name="edit_personal_dictionary" msgid="3996910038952940420">"វចនានុក្រម​ផ្ទាល់ខ្លួន"</string>
     <string name="configure_dictionaries_title" msgid="4238652338556902049">"ផ្នែក​បន្ថែម​វចនានុក្រម"</string>
@@ -58,7 +58,7 @@
     <string name="prefs_show_suggestions" msgid="8026799663445531637">"បង្ហាញ​ការ​ស្នើ​​កែ"</string>
     <string name="prefs_show_suggestions_summary" msgid="1583132279498502825">"បង្ហាញ​ពាក្យ​​បាន​​ផ្ដល់​​ស្នើ​​ខណៈ​ពេល​​​វាយ​បញ្ចូល"</string>
     <string name="prefs_block_potentially_offensive_title" msgid="5078480071057408934">"ទប់ស្កាត់​​ពាក្យ​​បំពាន"</string>
-    <string name="prefs_block_potentially_offensive_summary" msgid="2371835479734991364">"កុំ​ស្នើ​ឲ្យ​ពាក្យ​បំពាន​មាន​សក្ដានុពល"</string>
+    <string name="prefs_block_potentially_offensive_summary" msgid="2371835479734991364">"កុំ​ស្នើ​ឲ្យ​ពាក្យ​បំពាន​មាន​សក្ដានុពល​"</string>
     <string name="auto_correction" msgid="7630720885194996950">"ការ​កែ​​​ស្វ័យប្រវត្តិ"</string>
     <string name="auto_correction_summary" msgid="5625751551134658006">"ចន្លោះ​មិន​ឃើញ ​និង​សញ្ញា​​វណ្ណយុត្ត​កែ​ពាក្យ​ដែល​បាន​វាយ​ខុស​ស្វ័យប្រវត្តិ"</string>
     <string name="auto_correction_threshold_mode_off" msgid="8470882665417944026">"បិទ"</string>
@@ -147,7 +147,7 @@
     <string name="dictionary_provider_name" msgid="3027315045397363079">"កម្មវិធី​ផ្ដល់​វចនានុក្រម"</string>
     <string name="dictionary_service_name" msgid="6237472350693511448">"សេវាកម្ម​​វចនានុក្រម"</string>
     <string name="download_description" msgid="6014835283119198591">"ព័ត៌មាន​បច្ចុប្បន្នភាព​វចនានុក្រម"</string>
-    <string name="dictionary_settings_title" msgid="8091417676045693313">"ផ្នែក​បន្ថែម​វចនានុក្រម"</string>
+    <string name="dictionary_settings_title" msgid="8091417676045693313">"ផ្នែក​បន្ថែម​វចនានុក្រម​​"</string>
     <string name="dictionary_install_over_metered_network_prompt" msgid="3587517870006332980">"វចនានុក្រម​​​​​អាច​ប្រើ​បាន"</string>
     <string name="dictionary_settings_summary" msgid="5305694987799824349">"ការ​កំណត់​សម្រាប់​វចនានុក្រម"</string>
     <string name="user_dictionaries" msgid="3582332055892252845">"វចនានុក្រម​​​អ្នក​ប្រើ"</string>
@@ -163,10 +163,10 @@
     <string name="message_updating" msgid="4457761393932375219">"ពិនិត្យមើល​បច្ចុប្បន្នភាព"</string>
     <string name="message_loading" msgid="5638680861387748936">"កំពុង​ផ្ទុក..."</string>
     <string name="main_dict_description" msgid="3072821352793492143">"វចនានុក្រម​ចម្បង"</string>
-    <string name="cancel" msgid="6830980399865683324">"បោះ​បង់"</string>
+    <string name="cancel" msgid="6830980399865683324">"បោះ​បង់​"</string>
     <string name="go_to_settings" msgid="3876892339342569259">"ការ​កំណត់"</string>
     <string name="install_dict" msgid="180852772562189365">"ដំឡើង"</string>
-    <string name="cancel_download_dict" msgid="7843340278507019303">"បោះ​បង់"</string>
+    <string name="cancel_download_dict" msgid="7843340278507019303">"បោះ​បង់​"</string>
     <string name="delete_dict" msgid="756853268088330054">"លុប"</string>
     <string name="should_download_over_metered_prompt" msgid="1583881200688185508">"ភាសា​ដែល​បាន​ជ្រើស​នៅ​លើ​ឧបករណ៍​ចល័ត​មាន​វចនានុក្រម​អាច​ប្រើ​បាន។&lt;br/&gt; យើង​ផ្ដល់​អនុសាសន៍​ឲ្យ &lt;b&gt;ទាញ​យក&lt;/b&gt; វចនានុក្រម​ភាសា <xliff:g id="LANGUAGE_NAME">%1$s</xliff:g> ដើម្បី​បង្កើន​បទពិសោធន៍​វាយ​បញ្ចូល​របស់​អ្នក។&lt;br/&gt; &lt;br/&gt; ការ​ទាញ​យក​អាច​ចំណាយ​ពេល​ប្រហែល​ពីរ​នាទី​នៅ​តាម 3G។ ការ​គិត​ថ្លៃ​អាច​អនុវត្ត​ប្រសិន​បើ​អ្នក​មិន​ប្រើ &lt;b&gt;ផែនការ​ទិន្នន័យ​គ្មាន​ដែន​កំណត់&lt;/b&gt;.&lt;br/&gt; បើ​អ្នក​មិន​ប្រាកដ​​ថា​ផែនការ​ណា​មួយ​ដែល​អ្នក​មាន យើង​ផ្ដល់​អនុសាសន៍​ឲ្យ​​ភ្ជាប់​វ៉ាយហ្វាយ ដើម្បី​ចាប់ផ្ដើម​ទាញ​យក​ដោយ​ស្វ័យ​ប្រវត្តិ។&lt;br/&gt; &lt;br/&gt; ជំនួយ៖ អ្នក​អាច​ទាញ​យក និង​លុប​វចនានុក្រម​ដោយ​ចូល​ទៅ​ &lt;b&gt;ភាសា &amp; ការ​បញ្ចូល&lt;/b&gt; នៅ​ក្នុង​ម៉ឺនុយ &lt;b&gt;ការ​កំណត់&lt;/b&gt; សម្រាប់​ឧបករណ៍​ចល័ត។"</string>
     <string name="download_over_metered" msgid="1643065851159409546">"ទាញ​យក​ឥឡូវ​នេះ (<xliff:g id="SIZE_IN_MEGABYTES">%1$.1f</xliff:g> មេកាបៃ)"</string>
@@ -184,7 +184,7 @@
     <string name="user_dict_settings_add_word_option_name" msgid="6665558053408962865">"ពាក្យ៖"</string>
     <string name="user_dict_settings_add_shortcut_option_name" msgid="3094731590655523777">"ផ្លូវកាត់​៖"</string>
     <string name="user_dict_settings_add_locale_option_name" msgid="4738643440987277705">"ភាសា៖"</string>
-    <string name="user_dict_settings_add_word_hint" msgid="4902434148985906707">"វាយ​បញ្ចូល​ពាក្យ"</string>
+    <string name="user_dict_settings_add_word_hint" msgid="4902434148985906707">"វាយ​បញ្ចូល​ពាក្យ​"</string>
     <string name="user_dict_settings_add_shortcut_hint" msgid="2265453012555060178">"ផ្លូវកាត់​ជា​ជម្រើស"</string>
     <string name="user_dict_settings_edit_dialog_title" msgid="3765774633869590352">"កែ​ពាក្យ"</string>
     <string name="user_dict_settings_context_menu_edit_title" msgid="6812255903472456302">"កែ"</string>
diff --git a/java/res/values-lo-rLA/strings-emoji-descriptions.xml b/java/res/values-lo-rLA/strings-emoji-descriptions.xml
index 83a702e..0747fa6 100644
--- a/java/res/values-lo-rLA/strings-emoji-descriptions.xml
+++ b/java/res/values-lo-rLA/strings-emoji-descriptions.xml
@@ -210,7 +210,7 @@
     <string name="spoken_emoji_1F330" msgid="3115760035618051575">"​ລູກ​ເກົາ​ລັດ"</string>
     <string name="spoken_emoji_1F331" msgid="5658888205290008691">"​ກ້າ​ໄມ້"</string>
     <string name="spoken_emoji_1F332" msgid="2935650450421165938">"ຕົ້ນ​ໄມ້​ບໍ່​ຜັດ​ໃບ"</string>
-    <string name="spoken_emoji_1F333" msgid="5898847427062482675">"​ຕົ້ນ​ໄມ້​ຜັດໃບ"</string>
+    <string name="spoken_emoji_1F333" msgid="5898847427062482675">"​ຕົ້ນ​ໄມ້​ຜັດໃບ​"</string>
     <string name="spoken_emoji_1F334" msgid="6183375224678417894">"​ຕົ້ນ​ປາມ"</string>
     <string name="spoken_emoji_1F335" msgid="5352418412103584941">"​ກະ​ບອງ​ເພັດ"</string>
     <string name="spoken_emoji_1F337" msgid="3839107352363566289">"​ທິວ​ລິບ"</string>
@@ -450,7 +450,7 @@
     <string name="spoken_emoji_1F458" msgid="5704243858031107692">"​ກິ​ໂມ​ໂນ"</string>
     <string name="spoken_emoji_1F459" msgid="3553148747050035251">"​ບິ​ກີ​ນີ"</string>
     <string name="spoken_emoji_1F45A" msgid="1389654639484716101">"​ເສື້ອ​ຜ້າ​ຜູ່​ຍິງ"</string>
-    <string name="spoken_emoji_1F45B" msgid="1113293170254222904">"ກະ​ເປົາ"</string>
+    <string name="spoken_emoji_1F45B" msgid="1113293170254222904">"ກະ​ເປົາ​"</string>
     <string name="spoken_emoji_1F45C" msgid="3410257778598006936">"ກະ​ເປົາ"</string>
     <string name="spoken_emoji_1F45D" msgid="812176504300064819">"​ກະ​ເປົາ"</string>
     <string name="spoken_emoji_1F45E" msgid="2901741399934723562">"​ເກີບ​ຜູ່​ຊາຍ"</string>
diff --git a/java/res/values-lo-rLA/strings-letter-descriptions.xml b/java/res/values-lo-rLA/strings-letter-descriptions.xml
index 47f7cbc..ecc0b7a 100644
--- a/java/res/values-lo-rLA/strings-letter-descriptions.xml
+++ b/java/res/values-lo-rLA/strings-letter-descriptions.xml
@@ -186,7 +186,7 @@
     <string name="spoken_symbol_2019" msgid="8892530161598134083">"Right single quotation mark"</string>
     <string name="spoken_symbol_201A" msgid="2072987157683446644">"Single low-9 quotation mark"</string>
     <string name="spoken_symbol_201C" msgid="4588048378803665427">"​ເຄື່ອງ​ໝາຍ​ວົງ​ຢືມ​ຊ້າຍ"</string>
-    <string name="spoken_symbol_201D" msgid="1642776849495925895">"​ເຄື່ອງ​ໝາຍ​ວົງ​ຢືມ​ຂວາ"</string>
+    <string name="spoken_symbol_201D" msgid="1642776849495925895">"​ເຄື່ອງ​ໝາຍ​ວົງ​ຢືມ​ຂວາ​"</string>
     <string name="spoken_symbol_2020" msgid="9084628638189344431">"Dagger"</string>
     <string name="spoken_symbol_2021" msgid="5081396468559426475">"Double dagger"</string>
     <string name="spoken_symbol_2030" msgid="9068837172419431755">"​ເຄື່ອງ​ໝາຍ​ຕໍ່​ໄມລ໌"</string>
diff --git a/java/res/values-my-rMM/strings-action-keys.xml b/java/res/values-my-rMM/strings-action-keys.xml
index f7a2ca9..d15c9e5 100644
--- a/java/res/values-my-rMM/strings-action-keys.xml
+++ b/java/res/values-my-rMM/strings-action-keys.xml
@@ -27,5 +27,5 @@
     <string name="label_send_key" msgid="482252074224462163">"ပို့ရန်"</string>
     <string name="label_search_key" msgid="7965186050435796642">"ရှာဖွေရန်"</string>
     <string name="label_pause_key" msgid="2225922926459730642">"ဆိုင်းငံ့ရန်"</string>
-    <string name="label_wait_key" msgid="5891247853595466039">"စောင့်ဆိုင်းရန်"</string>
+    <string name="label_wait_key" msgid="5891247853595466039">"စောင့်ဆိုင်းရန်"</string>
 </resources>
diff --git a/java/res/values-my-rMM/strings-letter-descriptions.xml b/java/res/values-my-rMM/strings-letter-descriptions.xml
index d904f53..2d5338b 100644
--- a/java/res/values-my-rMM/strings-letter-descriptions.xml
+++ b/java/res/values-my-rMM/strings-letter-descriptions.xml
@@ -29,7 +29,7 @@
     <string name="spoken_accented_letter_00AA" msgid="4374325261868451570">"ဣထိလိင် အစဉ်ပြ အညွှန်း"</string>
     <string name="spoken_accented_letter_00B5" msgid="9031387673828823891">"မိုက်ခရို သင်္ကေတ"</string>
     <string name="spoken_accented_letter_00BA" msgid="5045198452071207437">"ပုလိင် အစဉ်ပြ အညွှန်း"</string>
-    <string name="spoken_accented_letter_00DF" msgid="2260098367028134281">"ပြတ်သားသည့် S"</string>
+    <string name="spoken_accented_letter_00DF" msgid="2260098367028134281">"ပြတ်သားသည့် S"</string>
     <string name="spoken_accented_letter_00E0" msgid="2234515772182387086">"A၊ တည်ငြိမ်သော"</string>
     <string name="spoken_accented_letter_00E1" msgid="7780174500802535063">"A၊ စူးရှသော"</string>
     <string name="spoken_accented_letter_00E2" msgid="7054108480488102631">"A၊ သရသံသင်္ကေတ"</string>
@@ -133,45 +133,45 @@
     <string name="spoken_accented_letter_0259" msgid="2464085263158415898">"Schwa"</string>
     <string name="spoken_accented_letter_1EA1" msgid="688124877202887630">"A၊ အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1EA3" msgid="327960130366386256">"A အပေါ်မှာ ချိတ်"</string>
-    <string name="spoken_accented_letter_1EA5" msgid="637406363453769610">"A၊ သရသံသင်္ကေတ နှင့် စူးရှသော"</string>
-    <string name="spoken_accented_letter_1EA7" msgid="1419591804181615409">"A၊ သရသံသင်္ကေတ နှင့် တည်ငြိမ်သော"</string>
-    <string name="spoken_accented_letter_1EA9" msgid="6068887382734896756">"A၊ သရသံသင်္ကေတ နှင့် အပေါ်မှာ ချိတ်"</string>
-    <string name="spoken_accented_letter_1EAB" msgid="7236523151662538333">"A၊ သရသံသင်္ကေတ နှင့် tilde"</string>
-    <string name="spoken_accented_letter_1EAD" msgid="2363364864106332076">"A,၊ သရသံသင်္ကေတ နှင့် အောက်မှာ အစက်"</string>
-    <string name="spoken_accented_letter_1EAF" msgid="1576329511464272935">"A၊ တည်ငြိမ်သော နှင့် စူးရှသော"</string>
-    <string name="spoken_accented_letter_1EB1" msgid="4634735072816076592">"A၊ breve နှင့် တည်ငြိမ်သော"</string>
-    <string name="spoken_accented_letter_1EB3" msgid="2325245849038771534">"A၊ breve နှင့် အပေါ်မှာ ချိတ်"</string>
-    <string name="spoken_accented_letter_1EB5" msgid="3720427596242746295">"A၊ breve နှင့် tilde"</string>
-    <string name="spoken_accented_letter_1EB7" msgid="700415535653646695">"A၊ breve နှင့် အောက်မှာ အစက်"</string>
+    <string name="spoken_accented_letter_1EA5" msgid="637406363453769610">"A၊ သရသံသင်္ကေတ နှင့် စူးရှသော"</string>
+    <string name="spoken_accented_letter_1EA7" msgid="1419591804181615409">"A၊ သရသံသင်္ကေတ နှင့် တည်ငြိမ်သော"</string>
+    <string name="spoken_accented_letter_1EA9" msgid="6068887382734896756">"A၊ သရသံသင်္ကေတ နှင့် အပေါ်မှာ ချိတ်"</string>
+    <string name="spoken_accented_letter_1EAB" msgid="7236523151662538333">"A၊ သရသံသင်္ကေတ နှင့် tilde"</string>
+    <string name="spoken_accented_letter_1EAD" msgid="2363364864106332076">"A,၊ သရသံသင်္ကေတ နှင့် အောက်မှာ အစက်"</string>
+    <string name="spoken_accented_letter_1EAF" msgid="1576329511464272935">"A၊ တည်ငြိမ်သော နှင့် စူးရှသော"</string>
+    <string name="spoken_accented_letter_1EB1" msgid="4634735072816076592">"A၊ breve နှင့် တည်ငြိမ်သော"</string>
+    <string name="spoken_accented_letter_1EB3" msgid="2325245849038771534">"A၊ breve နှင့် အပေါ်မှာ ချိတ်"</string>
+    <string name="spoken_accented_letter_1EB5" msgid="3720427596242746295">"A၊ breve နှင့် tilde"</string>
+    <string name="spoken_accented_letter_1EB7" msgid="700415535653646695">"A၊ breve နှင့် အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1EB9" msgid="3901338692305890487">"E၊ အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1EBB" msgid="4028688699415417302">"E၊ အပေါ်မှာ ချိတ်"</string>
     <string name="spoken_accented_letter_1EBD" msgid="181253633045931897">"E၊ tilde"</string>
-    <string name="spoken_accented_letter_1EBF" msgid="3309618845007944963">"E၊ သရသံသင်္ကေတ နှင့် စူးရှသော"</string>
-    <string name="spoken_accented_letter_1EC1" msgid="8139046749226332542">"E၊ သရသံသင်္ကေတ နှင့် တည်ငြိမ်သော"</string>
-    <string name="spoken_accented_letter_1EC3" msgid="3239674223053133383">"E၊ သရသံသင်္ကေတ နှင့် ချိတ် အပေါ်မှာ"</string>
-    <string name="spoken_accented_letter_1EC5" msgid="2216559244705714587">"E၊ သရသံသင်္ကေတ နှင့် tilde"</string>
-    <string name="spoken_accented_letter_1EC7" msgid="9012731468253986792">"E၊ သရသံသင်္ကေတ နှင့် အောက်မှာ အစက်"</string>
+    <string name="spoken_accented_letter_1EBF" msgid="3309618845007944963">"E၊ သရသံသင်္ကေတ နှင့် စူးရှသော"</string>
+    <string name="spoken_accented_letter_1EC1" msgid="8139046749226332542">"E၊ သရသံသင်္ကေတ နှင့် တည်ငြိမ်သော"</string>
+    <string name="spoken_accented_letter_1EC3" msgid="3239674223053133383">"E၊ သရသံသင်္ကေတ နှင့် ချိတ် အပေါ်မှာ"</string>
+    <string name="spoken_accented_letter_1EC5" msgid="2216559244705714587">"E၊ သရသံသင်္ကေတ နှင့် tilde"</string>
+    <string name="spoken_accented_letter_1EC7" msgid="9012731468253986792">"E၊ သရသံသင်္ကေတ နှင့် အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1EC9" msgid="2901917620195717034">"I၊ အပေါ်မှာ ချိတ်"</string>
     <string name="spoken_accented_letter_1ECB" msgid="5470387489820034621">"I၊ အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1ECD" msgid="1340122876914839806">"O၊ အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1ECF" msgid="2326921263882559755">"O၊ အပေါ်မှာ ချိတ်"</string>
-    <string name="spoken_accented_letter_1ED1" msgid="2885683296042774958">"O၊ သရသံသင်္ကေတ နှင့် စူးရှသော"</string>
-    <string name="spoken_accented_letter_1ED3" msgid="6857664926477376178">"O၊ သရသံသင်္ကေတ နှင့် တည်ငြိမ်သော"</string>
-    <string name="spoken_accented_letter_1ED5" msgid="2015209467290624062">"O၊ သရသံသင်္ကေတ နှင့် အပေါ်မှာ ချိတ်"</string>
-    <string name="spoken_accented_letter_1ED7" msgid="7924481354960306389">"O၊ သရသံသင်္ကေတ နှင့် tilde"</string>
-    <string name="spoken_accented_letter_1ED9" msgid="7023315590332365554">"O၊ သရသံသင်္ကေတ နှင့် အောက်မှာ အစက်"</string>
-    <string name="spoken_accented_letter_1EDB" msgid="2379438944917634496">"O၊ horn နှင့် စူးရှသော"</string>
-    <string name="spoken_accented_letter_1EDD" msgid="8107077534204404085">"O၊ horn နှင့် တည်ငြိမ်သော"</string>
-    <string name="spoken_accented_letter_1EDF" msgid="1846880105528347966">"O၊ horn နှင့် အပေါ်မှာ ချိတ်"</string>
-    <string name="spoken_accented_letter_1EE1" msgid="1520037313389776718">"O၊ horn နှင့် tilde"</string>
-    <string name="spoken_accented_letter_1EE3" msgid="907964027171008963">"O၊ horn နှင့် အောက်မှာ အစက်"</string>
+    <string name="spoken_accented_letter_1ED1" msgid="2885683296042774958">"O၊ သရသံသင်္ကေတ နှင့် စူးရှသော"</string>
+    <string name="spoken_accented_letter_1ED3" msgid="6857664926477376178">"O၊ သရသံသင်္ကေတ နှင့် တည်ငြိမ်သော"</string>
+    <string name="spoken_accented_letter_1ED5" msgid="2015209467290624062">"O၊ သရသံသင်္ကေတ နှင့် အပေါ်မှာ ချိတ်"</string>
+    <string name="spoken_accented_letter_1ED7" msgid="7924481354960306389">"O၊ သရသံသင်္ကေတ နှင့် tilde"</string>
+    <string name="spoken_accented_letter_1ED9" msgid="7023315590332365554">"O၊ သရသံသင်္ကေတ နှင့် အောက်မှာ အစက်"</string>
+    <string name="spoken_accented_letter_1EDB" msgid="2379438944917634496">"O၊ horn နှင့် စူးရှသော"</string>
+    <string name="spoken_accented_letter_1EDD" msgid="8107077534204404085">"O၊ horn နှင့် တည်ငြိမ်သော"</string>
+    <string name="spoken_accented_letter_1EDF" msgid="1846880105528347966">"O၊ horn နှင့် အပေါ်မှာ ချိတ်"</string>
+    <string name="spoken_accented_letter_1EE1" msgid="1520037313389776718">"O၊ horn နှင့် tilde"</string>
+    <string name="spoken_accented_letter_1EE3" msgid="907964027171008963">"O၊ horn နှင့် အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1EE5" msgid="1522024630360038700">"U၊ အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1EE7" msgid="7815412228302952637">"U၊ အပေါ်မှာ ချိတ်"</string>
-    <string name="spoken_accented_letter_1EE9" msgid="4219119671251485651">"U၊ horn နှင့် စူးရှသော"</string>
-    <string name="spoken_accented_letter_1EEB" msgid="4086009841269002231">"U၊ horn နှင့် တည်ငြိမ်သော"</string>
-    <string name="spoken_accented_letter_1EED" msgid="3528151733528719847">"U၊  horn နှင့် အပေါ်မှာ ချိတ်"</string>
-    <string name="spoken_accented_letter_1EEF" msgid="3508548229409072119">"U၊ horn နှင့် tilde"</string>
-    <string name="spoken_accented_letter_1EF1" msgid="1912816350401931115">"U၊ horn နှင့် အောက်မှာ အစက်"</string>
+    <string name="spoken_accented_letter_1EE9" msgid="4219119671251485651">"U၊ horn နှင့် စူးရှသော"</string>
+    <string name="spoken_accented_letter_1EEB" msgid="4086009841269002231">"U၊ horn နှင့် တည်ငြိမ်သော"</string>
+    <string name="spoken_accented_letter_1EED" msgid="3528151733528719847">"U၊  horn နှင့် အပေါ်မှာ ချိတ်"</string>
+    <string name="spoken_accented_letter_1EEF" msgid="3508548229409072119">"U၊ horn နှင့် tilde"</string>
+    <string name="spoken_accented_letter_1EF1" msgid="1912816350401931115">"U၊ horn နှင့် အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1EF3" msgid="7211760439435946494">"Y၊ တည်ငြိမ်သော"</string>
     <string name="spoken_accented_letter_1EF5" msgid="8998864482764007384">"Y၊ အောက်မှာ အစက်"</string>
     <string name="spoken_accented_letter_1EF7" msgid="922043627252869200">"Y၊ အပေါ်မှာ ချိတ်"</string>
diff --git a/java/res/values-my-rMM/strings-talkback-descriptions.xml b/java/res/values-my-rMM/strings-talkback-descriptions.xml
index a4f84a2..08fd190 100644
--- a/java/res/values-my-rMM/strings-talkback-descriptions.xml
+++ b/java/res/values-my-rMM/strings-talkback-descriptions.xml
@@ -79,7 +79,7 @@
     <string name="spoken_emoticon_3A_2D_21_20" msgid="2410905667389534573">"စိတ်ကုန်နေသော မျက်နှာ"</string>
     <string name="spoken_emoticon_3A_2D_24_20" msgid="2481260475945560438">"ကသိကအောက် မျက်နှာ"</string>
     <string name="spoken_emoticon_42_2D_29_20" msgid="1063205250387128068">"နေကာမျက်မှန်တပ် မျက်နှာ"</string>
-    <string name="spoken_emoticon_3A_4F_20" msgid="532695091593447238">"အံ့အားသင့်နေသော မျက်နှာ"</string>
+    <string name="spoken_emoticon_3A_4F_20" msgid="532695091593447238">"အံ့အားသင့်နေသော မျက်နှာ"</string>
     <string name="spoken_emoticon_3A_2D_2A_20" msgid="5612342617244114291">"နမ်းနေသော မျက်နှာ"</string>
     <string name="spoken_emoticon_3A_2D_5B_20" msgid="2223507987759905920">"မှုန်ကုပ်ကုပ် မျက်နှာ"</string>
     <string name="spoken_open_more_keys_keyboard" msgid="6832897688371903747">"အစားထိုးစရာ စာလုံးများ ရှိနိုင်"</string>
diff --git a/java/res/values-my-rMM/strings.xml b/java/res/values-my-rMM/strings.xml
index 93a74c5..31af8fa 100644
--- a/java/res/values-my-rMM/strings.xml
+++ b/java/res/values-my-rMM/strings.xml
@@ -30,11 +30,11 @@
     <string name="settings_screen_accounts" msgid="7570397912370223287">"အကောင့်များ &amp; ကိုယ်ပိုင်ကိစ္စ"</string>
     <string name="settings_screen_appearance" msgid="9153102634339912029">"အပြင်ပန်း &amp; အပြင်အဆင်များ"</string>
     <string name="settings_screen_multilingual" msgid="1391301621464509659">"ဘာသာစကားစုံ ရွေးချယ်စရာများ"</string>
-    <string name="settings_screen_gesture" msgid="8826372746901183556">"လှုပ်ရှားမှုဖြင့်စာရိုက်ခြင်း"</string>
+    <string name="settings_screen_gesture" msgid="8826372746901183556">"လှုပ်ရှားမှုဖြင့်စာရိုက်ခြင်း"</string>
     <string name="settings_screen_correction" msgid="1616818407747682955">"စာအမှားပြပြင်ခြင်း"</string>
-    <string name="settings_screen_advanced" msgid="7472408607625972994">"အဆင့်မြင့်"</string>
+    <string name="settings_screen_advanced" msgid="7472408607625972994">"အဆင့်မြင့်"</string>
     <string name="settings_screen_theme" msgid="2137262503543943871">"အပြင်အဆင်"</string>
-    <string name="enable_split_keyboard" msgid="4177264923999493614">"ကီးဘုတ် ခွဲခြမ်းမှု ဖွင့်ထားရန်"</string>
+    <string name="enable_split_keyboard" msgid="4177264923999493614">"ကီးဘုတ် ခွဲခြမ်းမှု ဖွင့်ထားရန်"</string>
     <string name="include_other_imes_in_language_switch_list" msgid="4533689960308565519">"အခြားထည့်သွင်းမည့် နည်းလမ်းများသို့ ပြောင်းရန်"</string>
     <string name="include_other_imes_in_language_switch_list_summary" msgid="840637129103317635">"ဘာသာပြောင်းသည့် ကီးသည် အခြားထည့်သွင်းရန် နည်းလမ်းများလည်း ပါဝင်သည်"</string>
     <string name="show_language_switch_key" msgid="5915478828318774384">"ဘာသာစကား ပြောင်းခလုတ်"</string>
@@ -47,7 +47,7 @@
     <string name="use_contacts_dict" msgid="4435317977804180815">"အဆယ်ကသွယ်အမည်များ အကြံပြုမည်"</string>
     <string name="use_contacts_dict_summary" msgid="6599983334507879959">"အကြံပြုချက်များနှင့် အမှားပြင်ခြင်းများအတွက် အဆက်သွယ်မှ အမည်များ အသုံးပြုမည်"</string>
     <string name="use_personalized_dicts" msgid="5167396352105467626">"ကိုယ်ရေးကိုယ်တာ အကြံပြုချက်များ"</string>
-    <string name="enable_metrics_logging" msgid="5506372337118822837">"မြှင့်တင်ပါ <xliff:g id="APPLICATION_NAME">%s</xliff:g>"</string>
+    <string name="enable_metrics_logging" msgid="5506372337118822837">"မြှင့်တင်ပါ <xliff:g id="APPLICATION_NAME">%s</xliff:g>"</string>
     <string name="use_double_space_period" msgid="8781529969425082860">"နှစ်နေရာခြား အဆုံးသတ်"</string>
     <string name="use_double_space_period_summary" msgid="6532892187247952799">"အချိန်ကာလ"</string>
     <string name="auto_cap" msgid="1719746674854628252">"အော်တိုစာလုံးကြီးပြောင်း"</string>
@@ -84,7 +84,7 @@
     <string name="hint_add_to_dictionary_without_word" msgid="3040385779511255101">"သိမ်းရန် ဤနေရာကို ထိပါ"</string>
     <string name="has_dictionary" msgid="6071847973466625007">"အဘိဓါန်ရနိုင်"</string>
     <string name="keyboard_layout" msgid="8451164783510487501">"ကီးဘုတ်အရောင်"</string>
-    <string name="switch_accounts" msgid="3321216593719006162">"အကောင့်များကို ပြောင်းရန်"</string>
+    <string name="switch_accounts" msgid="3321216593719006162">"အကောင့်များကို ပြောင်းရန်"</string>
     <string name="no_accounts_selected" msgid="2073821619103904330">"အကောင့်များ မရွေးရသေးပါ"</string>
     <string name="account_selected" msgid="2846876462199625974">"<xliff:g id="EMAIL_ADDRESS">%1$s</xliff:g>အား လတ်တလော သုံးန​ေ၏"</string>
     <string name="account_select_ok" msgid="9141195141763227797">"အိုကေ"</string>
@@ -154,7 +154,7 @@
     <string name="default_user_dict_pref_name" msgid="1625055720489280530">"သုံးစွဲသူ၏ အဘိဓာန်"</string>
     <string name="dictionary_available" msgid="4728975345815214218">"အဘိဓါန်ရရှိနိုင်"</string>
     <string name="dictionary_downloading" msgid="2982650524622620983">"လက်ရှိ ဒေါင်းလုပ်လုပ်နေသည်"</string>
-    <string name="dictionary_installed" msgid="8081558343559342962">"ထည့်သွင်းပြီး"</string>
+    <string name="dictionary_installed" msgid="8081558343559342962">"ထည့်သွင်းပြီး"</string>
     <string name="dictionary_disabled" msgid="8950383219564621762">"ထည့်သွင်းထားပြီး၊ ပိတ်ထားသည်"</string>
     <string name="cannot_connect_to_dict_service" msgid="9216933695765732398">"အဘိဓါန်ဝန်ဆောင်မှုသို့ ချိတ်ဆက်ရန် ပြဿနာရှိနေသည်"</string>
     <string name="no_dictionaries_available" msgid="8039920716566132611">"အဘိဓါန်မရှိ"</string>
@@ -168,7 +168,7 @@
     <string name="install_dict" msgid="180852772562189365">"တပ်ဆင်ပါ"</string>
     <string name="cancel_download_dict" msgid="7843340278507019303">"ထားတော့"</string>
     <string name="delete_dict" msgid="756853268088330054">"ဖျက်ရန်"</string>
-    <string name="should_download_over_metered_prompt" msgid="1583881200688185508">"သင့်ဖုန်းရှိ ရွေးချယ်ထားသည့် ဘာသာအတွက် အဘိဓါန်ရှိပါသည်။ &lt;br/&gt; အဘိဓါန်အား &lt;b&gt;ဒေါင်းလုပ်လုပ်ကာ&lt;/b&gt; the <xliff:g id="LANGUAGE_NAME">%1$s</xliff:g>  သင့်စာရိုက် အတွေ့အကြုံတိုးတက်စေရန် ကျွန်ုပ်တို့အကြံပြုပါသည်။ &lt;br/&gt; &lt;br/&gt; ဒေါင်းလုပ်လုပ်ရန် 3G ပေါ်တွင် ၁ မှ ၂ မိနစ်ခန့်ကြာနိုင်သည်။ သင့်တွင် &lt;b&gt;အကန့်သတ်မှရိ အချက်လက် သုံးစွဲမှု&lt;/b&gt;မရှိလျှင် ငွေကျသင့်နိုင်ပါသည်။ &lt;br/&gt; သင့်တွင် မည်သည့်အချက်လက်သုံးစွဲမှု ရှိနေသည်ကိုမသိလျှင်၊ အလိုအလျောက် ဒေါင်းလုပ်လုပ်ရန် Wi-Fi ကွန်ရက်တစ်ခု ရှာဖွေရန် တိုက်တွန်းပါသည်။ &lt;br/&gt; &lt;br/&gt; နည်းလမ်း: သင့်ဖုန်းကိရိယာရှိ &lt;b&gt;ဆက်တင်ထဲတွင်&lt;/b&gt; &lt;b&gt;ဘာသာ &amp; စာရိုက်ထည့်မှု&lt;/b&gt; သို့သွားကာ အဘိဓါန်များကို ဒေါင်းလုပ်လုပ်နိုင် ဖယ်ရှားနိုင်ပါသည်။"</string>
+    <string name="should_download_over_metered_prompt" msgid="1583881200688185508">"သင့်ဖုန်းရှိ ရွေးချယ်ထားသည့် ဘာသာအတွက် အဘိဓါန်ရှိပါသည်။ &lt;br/&gt; အဘိဓါန်အား &lt;b&gt;ဒေါင်းလုပ်လုပ်ကာ&lt;/b&gt; the <xliff:g id="LANGUAGE_NAME">%1$s</xliff:g>  သင့်စာရိုက် အတွေ့အကြုံတိုးတက်စေရန် ကျွန်ုပ်တို့အကြံပြုပါသည်။ &lt;br/&gt; &lt;br/&gt; ဒေါင်းလုပ်လုပ်ရန် 3G ပေါ်တွင် ၁ မှ ၂ မိနစ်ခန့်ကြာနိုင်သည်။ သင့်တွင် &lt;b&gt;အကန့်သတ်မှရိ အချက်လက် သုံးစွဲမှု&lt;/b&gt;မရှိလျှင် ငွေကျသင့်နိုင်ပါသည်။ &lt;br/&gt; သင့်တွင် မည်သည့်အချက်လက်သုံးစွဲမှု ရှိနေသည်ကိုမသိလျှင်၊ အလိုအလျောက် ဒေါင်းလုပ်လုပ်ရန် Wi-Fi ကွန်ရက်တစ်ခု ရှာဖွေရန် တိုက်တွန်းပါသည်။ &lt;br/&gt; &lt;br/&gt; နည်းလမ်း: သင့်ဖုန်းကိရိယာရှိ &lt;b&gt;ဆက်တင်ထဲတွင်&lt;/b&gt; &lt;b&gt;ဘာသာ &amp; စာရိုက်ထည့်မှု&lt;/b&gt; သို့သွားကာ အဘိဓါန်များကို ဒေါင်းလုပ်လုပ်နိုင် ဖယ်ရှားနိုင်ပါသည်။"</string>
     <string name="download_over_metered" msgid="1643065851159409546">"ယခုဒေါင်းလုပ်လုပ်မည် (<xliff:g id="SIZE_IN_MEGABYTES">%1$.1f</xliff:g>MB)"</string>
     <string name="do_not_download_over_metered" msgid="2176209579313941583">"Wi-Fi အသုံးပြု၍ ဒေါင်းလုပ်လုပ်ရန်"</string>
     <string name="dict_available_notification_title" msgid="4583842811218581658">"<xliff:g id="LANGUAGE_NAME">%1$s</xliff:g> အတွက် အဘိဓါန် ရနိုင်ပါသည်"</string>
@@ -189,7 +189,7 @@
     <string name="user_dict_settings_edit_dialog_title" msgid="3765774633869590352">"စာလုံးကို ပြင်ဆင်မည်"</string>
     <string name="user_dict_settings_context_menu_edit_title" msgid="6812255903472456302">"တည်းဖြတ်ရန်"</string>
     <string name="user_dict_settings_context_menu_delete_title" msgid="8142932447689461181">"ဖျက်ရန်"</string>
-    <string name="user_dict_settings_empty_text" msgid="558499587532668203">"သင့်အဘိဓာန်ထဲတွင် မည်သည့်စာလုံးမှမရှိပါ။ ထပ်ထည့်ခြင်း(+)ခလုတ်ကို ထိ၍ စာလုံးထည့်ပါ။"</string>
+    <string name="user_dict_settings_empty_text" msgid="558499587532668203">"သင့်အဘိဓာန်ထဲတွင် မည်သည့်စာလုံးမှမရှိပါ။ ထပ်ထည့်ခြင်း(+)ခလုတ်ကို ထိ၍ စာလုံးထည့်ပါ။"</string>
     <string name="user_dict_settings_all_languages" msgid="8276126583216298886">"ဘာသာစကားအားလုံးအတွက်"</string>
     <string name="user_dict_settings_more_languages" msgid="7131268499685180461">"ဘာသာစကားပိုများများ…"</string>
     <string name="user_dict_settings_delete" msgid="110413335187193859">"ဖျက်သိမ်းရန်"</string>
diff --git a/java/res/values-ne-rNP/strings-emoji-descriptions.xml b/java/res/values-ne-rNP/strings-emoji-descriptions.xml
index a3419b8..43f4d89 100644
--- a/java/res/values-ne-rNP/strings-emoji-descriptions.xml
+++ b/java/res/values-ne-rNP/strings-emoji-descriptions.xml
@@ -129,8 +129,8 @@
     <string name="spoken_emoji_27A1" msgid="3513434778263100580">"कालो दाँयातीर तीर"</string>
     <string name="spoken_emoji_27B0" msgid="203395646864662198">"घुम्रिएको फेरो"</string>
     <string name="spoken_emoji_27BF" msgid="4940514642375640510">"दोहोरो घुम्रिएको फेरो"</string>
-    <string name="spoken_emoji_2934" msgid="9062130477982973457">"दाँयातीर इशारा तीर त्यसपछि माथिको घुमाँइ"</string>
-    <string name="spoken_emoji_2935" msgid="6198710960720232074">"दाँयातीर इशारा तीर त्यसपछि तलको घुमाँइ"</string>
+    <string name="spoken_emoji_2934" msgid="9062130477982973457">"दाँया तिर  देखादने तीर त्यसपछि माथिको घुमाई"</string>
+    <string name="spoken_emoji_2935" msgid="6198710960720232074">"दाँया तिर देखाउने तीर त्यसपछि तलको घुमाँइ"</string>
     <string name="spoken_emoji_2B05" msgid="4813405635410707690">"कालोतीर बायाँतर्फ"</string>
     <string name="spoken_emoji_2B06" msgid="1223172079106250748">"कालो तीर माथि तर्फ"</string>
     <string name="spoken_emoji_2B07" msgid="1599124424746596150">"कालो तीर तल तर्फ"</string>
@@ -669,10 +669,10 @@
     <string name="spoken_emoji_1F537" msgid="3158915214347274626">"ठूलो नीलो हीरा"</string>
     <string name="spoken_emoji_1F538" msgid="4300084249474451991">"लघु सुन्तला हीरा"</string>
     <string name="spoken_emoji_1F539" msgid="6535159756325742275">"लघु नीलो हीरा"</string>
-    <string name="spoken_emoji_1F53A" msgid="3728196273988781389">"माथी-इशारा रातो त्रिकोण"</string>
-    <string name="spoken_emoji_1F53B" msgid="7182097039614128707">"तल-इशारा रातो त्रिकोण"</string>
+    <string name="spoken_emoji_1F53A" msgid="3728196273988781389">"माथि-देखाउने रातो त्रिकोण"</string>
+    <string name="spoken_emoji_1F53B" msgid="7182097039614128707">"तल-देखाउने रातो त्रिकोण"</string>
     <string name="spoken_emoji_1F53C" msgid="4077022046319615029">"माथी इशारा सानो रातो त्रिकोण"</string>
-    <string name="spoken_emoji_1F53D" msgid="3939112784894620713">"तल-इशारा सानो रातो त्रिकोण"</string>
+    <string name="spoken_emoji_1F53D" msgid="3939112784894620713">"तल-देखाउने सानो रातो त्रिकोण"</string>
     <string name="spoken_emoji_1F550" msgid="7761392621689986218">"घडी अनुहार एक बजे"</string>
     <string name="spoken_emoji_1F551" msgid="2699448504113431716">"घडी अनुहार दुई बजे"</string>
     <string name="spoken_emoji_1F552" msgid="5872107867411853750">"घडी अनुहार तीन बजे"</string>
diff --git a/java/res/values-ne-rNP/strings.xml b/java/res/values-ne-rNP/strings.xml
index 29f821a..9f486fd 100644
--- a/java/res/values-ne-rNP/strings.xml
+++ b/java/res/values-ne-rNP/strings.xml
@@ -50,7 +50,7 @@
     <string name="enable_metrics_logging" msgid="5506372337118822837">"<xliff:g id="APPLICATION_NAME">%s</xliff:g>सुधार गर्नुहोस्"</string>
     <string name="use_double_space_period" msgid="8781529969425082860">"डबल-स्पेस पूर्णविराम"</string>
     <string name="use_double_space_period_summary" msgid="6532892187247952799">"स्पेसबारमा डबल ट्याप गर्नाले पूर्णविरामपछि स्पेस राख्दछ"</string>
-    <string name="auto_cap" msgid="1719746674854628252">"स्वतः पूँजिकरण"</string>
+    <string name="auto_cap" msgid="1719746674854628252">"स्वतः क्यापिटलाइजेसन"</string>
     <string name="auto_cap_summary" msgid="7934452761022946874">"प्रत्येक वाक्यको पहिलो शब्द क्यापिटल गर्नुहोस्"</string>
     <string name="edit_personal_dictionary" msgid="3996910038952940420">"व्यक्तिगत शब्दकोश"</string>
     <string name="configure_dictionaries_title" msgid="4238652338556902049">"एड-अन शब्दकोश"</string>
diff --git a/java/res/values-nl/strings.xml b/java/res/values-nl/strings.xml
index 59b3a29..ec5fa06 100644
--- a/java/res/values-nl/strings.xml
+++ b/java/res/values-nl/strings.xml
@@ -39,7 +39,7 @@
     <string name="include_other_imes_in_language_switch_list_summary" msgid="840637129103317635">"Schakelknop voor taal ook van toepassing op andere invoermethoden"</string>
     <string name="show_language_switch_key" msgid="5915478828318774384">"Schakelknop voor taal"</string>
     <string name="show_language_switch_key_summary" msgid="7343403647474265713">"Weergeven wanneer meerdere invoertalen zijn geselecteerd"</string>
-    <string name="key_preview_popup_dismiss_delay" msgid="6213164897443068248">"Afwijz.vertr. toetspop-up"</string>
+    <string name="key_preview_popup_dismiss_delay" msgid="6213164897443068248">"Vertr.sluiten toetspop-up"</string>
     <string name="key_preview_popup_dismiss_no_delay" msgid="2096123151571458064">"Geen vertraging"</string>
     <string name="key_preview_popup_dismiss_default_delay" msgid="2166964333903906734">"Standaard"</string>
     <string name="abbreviation_unit_milliseconds" msgid="8700286094028323363">"<xliff:g id="MILLISECONDS">%s</xliff:g> ms"</string>
diff --git a/java/res/values-sr/strings.xml b/java/res/values-sr/strings.xml
index 98ece20..de2add4 100644
--- a/java/res/values-sr/strings.xml
+++ b/java/res/values-sr/strings.xml
@@ -95,12 +95,12 @@
     <string name="subtype_en_US" msgid="6160452336634534239">"енглески (САД)"</string>
     <string name="subtype_es_US" msgid="5583145191430180200">"шпански (САД)"</string>
     <string name="subtype_hi_ZZ" msgid="8860448146262798623">"хенглески"</string>
-    <string name="subtype_sr_ZZ" msgid="9059219552986034343">"српски (латиница)"</string>
+    <string name="subtype_sr_ZZ" msgid="9059219552986034343">"srpski"</string>
     <string name="subtype_with_layout_en_GB" msgid="1931018968641592304">"енглески (УК) (<xliff:g id="KEYBOARD_LAYOUT">%s</xliff:g>)"</string>
     <string name="subtype_with_layout_en_US" msgid="8809311287529805422">"енглески (САД) (<xliff:g id="KEYBOARD_LAYOUT">%s</xliff:g>)"</string>
     <string name="subtype_with_layout_es_US" msgid="510930471167541338">"шпански (САД) (<xliff:g id="KEYBOARD_LAYOUT">%s</xliff:g>)"</string>
     <string name="subtype_with_layout_hi_ZZ" msgid="6827402953860547044">"хенглески (<xliff:g id="KEYBOARD_LAYOUT">%s</xliff:g>)"</string>
-    <string name="subtype_with_layout_sr_ZZ" msgid="2859024772719772407">"српски (<xliff:g id="KEYBOARD_LAYOUT">%s</xliff:g>)"</string>
+    <string name="subtype_with_layout_sr_ZZ" msgid="2859024772719772407">"srpski (<xliff:g id="KEYBOARD_LAYOUT">%s</xliff:g>)"</string>
     <string name="subtype_generic_traditional" msgid="8584594350973800586">"<xliff:g id="LANGUAGE_NAME">%s</xliff:g> (традиционални)"</string>
     <string name="subtype_no_language" msgid="7137390094240139495">"Нема језика (абецеда)"</string>
     <string name="subtype_no_language_qwerty" msgid="244337630616742604">"Абецеда (QWERTY)"</string>
diff --git a/java/res/values-v21/themes-lxx.xml b/java/res/values-v21/themes-lxx.xml
new file mode 100644
index 0000000..5a6017c
--- /dev/null
+++ b/java/res/values-v21/themes-lxx.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2014, 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.
+*/
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+    <style
+        name="InputView.LXX"
+        parent="InputView"
+    >
+        <item name="android:elevation">8dp</item>
+    </style>
+</resources>
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index f2072fd..be35d13 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -20,6 +20,8 @@
 
 <resources>
     <declare-styleable name="KeyboardTheme">
+        <!-- InputView style -->
+        <attr name="inputViewStyle" format="reference" />
         <!-- Keyboard style -->
         <attr name="keyboardStyle" format="reference" />
         <!-- KeyboardView style -->
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index 6aea637..ed05e91 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -56,9 +56,11 @@
     <!--  Option for enabling or disabling the split keyboard layout. [CHAR LIMIT=65]-->
     <string name="enable_split_keyboard">Enable split keyboard</string>
 
-    <string name="sync_now_title" translatable="false">Sync Now</string>
-    <string name="sync_now_summary" translatable="false">Sync your personal dictionary</string>
-    <string name="sync_now_summary_disabled_signed_out" translatable="false">Select an account to enable sync</string>
+    <!-- TODO: Enable translation for user-visible strings -->
+    <string name="cloud_sync_title" translatable="false">Enable sync</string>
+    <string name="cloud_sync_summary" translatable="false">Sync your personal dictionary across devices</string>
+    <string name="cloud_sync_summary_disabled_signed_out" translatable="false">Select an account to enable sync</string>
+    <string name="sync_now_title" translatable="false">[DEBUG] Sync Now</string>
 
     <!-- Option name for including other IMEs in the language switch list [CHAR LIMIT=30] -->
     <string name="include_other_imes_in_language_switch_list">Switch to other input methods</string>
diff --git a/java/res/values/themes-common.xml b/java/res/values/themes-common.xml
index 110f6b7..f7cb10f 100644
--- a/java/res/values/themes-common.xml
+++ b/java/res/values/themes-common.xml
@@ -20,6 +20,7 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="KeyboardIcons" />
+    <style name="InputView" />
     <!-- Default theme values -->
     <style name="Keyboard">
         <item name="rowHeight">25%p</item>
diff --git a/java/res/values/themes-holo.xml b/java/res/values/themes-holo.xml
index 9f1bd2f..efac656 100644
--- a/java/res/values/themes-holo.xml
+++ b/java/res/values/themes-holo.xml
@@ -19,6 +19,10 @@
 -->
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
+    <style
+        name="InputView.Holo"
+        parent="InputView"
+    />
     <!-- Holo KeyboardView theme (ICS and KLP) -->
     <style
         name="KeyboardView.Holo"
diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml
index bfbac0a..ecf40e4 100644
--- a/java/res/values/themes-ics.xml
+++ b/java/res/values/themes-ics.xml
@@ -20,6 +20,7 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="KeyboardTheme.ICS" parent="KeyboardIcons.Holo">
+        <item name="inputViewStyle">@style/InputView.Holo</item>
         <item name="keyboardStyle">@style/Keyboard.ICS</item>
         <item name="keyboardViewStyle">@style/KeyboardView.ICS</item>
         <item name="mainKeyboardViewStyle">@style/MainKeyboardView.ICS</item>
diff --git a/java/res/values/themes-klp.xml b/java/res/values/themes-klp.xml
index 36b1fc1..de1cd9b 100644
--- a/java/res/values/themes-klp.xml
+++ b/java/res/values/themes-klp.xml
@@ -20,6 +20,7 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="KeyboardTheme.KLP" parent="KeyboardIcons.Holo">
+        <item name="inputViewStyle">@style/InputView.Holo</item>
         <item name="keyboardStyle">@style/Keyboard.KLP</item>
         <item name="keyboardViewStyle">@style/KeyboardView.KLP</item>
         <item name="mainKeyboardViewStyle">@style/MainKeyboardView.KLP</item>
diff --git a/java/res/values/themes-lxx-dark.xml b/java/res/values/themes-lxx-dark.xml
index 67f94f3..b081772 100644
--- a/java/res/values/themes-lxx-dark.xml
+++ b/java/res/values/themes-lxx-dark.xml
@@ -20,6 +20,7 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="KeyboardTheme.LXX_Dark" parent="KeyboardIcons.LXX_Dark">
+        <item name="inputViewStyle">@style/InputView.LXX</item>
         <item name="keyboardStyle">@style/Keyboard.LXX_Dark</item>
         <item name="keyboardViewStyle">@style/KeyboardView.LXX_Dark</item>
         <item name="mainKeyboardViewStyle">@style/MainKeyboardView.LXX_Dark</item>
diff --git a/java/res/values/themes-lxx-light.xml b/java/res/values/themes-lxx-light.xml
index be817f4..3d294e4 100644
--- a/java/res/values/themes-lxx-light.xml
+++ b/java/res/values/themes-lxx-light.xml
@@ -20,6 +20,7 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="KeyboardTheme.LXX_Light" parent="KeyboardIcons.LXX_Light">
+        <item name="inputViewStyle">@style/InputView.LXX</item>
         <item name="keyboardStyle">@style/Keyboard.LXX_Light</item>
         <item name="keyboardViewStyle">@style/KeyboardView.LXX_Light</item>
         <item name="mainKeyboardViewStyle">@style/MainKeyboardView.LXX_Light</item>
diff --git a/java/res/values/themes-lxx.xml b/java/res/values/themes-lxx.xml
index c721888..463306b 100644
--- a/java/res/values/themes-lxx.xml
+++ b/java/res/values/themes-lxx.xml
@@ -19,6 +19,10 @@
 -->
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
+    <style
+        name="InputView.LXX"
+        parent="InputView"
+    />
     <!-- LXX KeyboardView theme (LXX_Light and LXX_Dark) -->
     <style
         name="KeyboardView.LXX"
diff --git a/java/res/xml/prefs_screen_accounts.xml b/java/res/xml/prefs_screen_accounts.xml
index 003a37f..41642bf 100644
--- a/java/res/xml/prefs_screen_accounts.xml
+++ b/java/res/xml/prefs_screen_accounts.xml
@@ -28,7 +28,15 @@
         android:title="@string/switch_accounts"
         android:summary="@string/no_accounts_selected" />
 
-    <!-- title will be set programmatically to embed application name -->
+    <!-- Summary will be set programmatically to reflect the account status -->
+    <CheckBoxPreference
+        android:key="pref_enable_cloud_sync"
+        android:title="@string/cloud_sync_title"
+        android:defaultValue="false"
+        android:persistent="true"
+        android:disableDependentsState="false" />
+
+    <!-- Title will be set programmatically to embed application name -->
     <CheckBoxPreference
         android:key="pref_enable_metrics_logging"
         android:summary="@string/enable_metrics_logging_summary"
@@ -38,5 +46,6 @@
     <!-- This preference (acts like a button) enables the user to initiate an one time sync. -->
     <Preference android:key="pref_beanstalk"
         android:persistent="false"
-        android:title="@string/sync_now_title" />
+        android:title="@string/sync_now_title"
+        android:dependency="pref_enable_cloud_sync" />
 </PreferenceScreen>
diff --git a/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java b/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java
index 5af3179..f4f54b6 100644
--- a/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java
@@ -16,13 +16,20 @@
 
 package com.android.inputmethod.compat;
 
+import android.annotation.TargetApi;
 import android.graphics.Matrix;
 import android.graphics.RectF;
+import android.os.Build;
+import android.view.inputmethod.CursorAnchorInfo;
 
-import com.android.inputmethod.annotations.UsedForTesting;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
-@UsedForTesting
-public final class CursorAnchorInfoCompatWrapper {
+/**
+ * A wrapper for {@link CursorAnchorInfo}, which has been introduced in API Level 21. You can use
+ * this wrapper to avoid direct dependency on newly introduced types.
+ */
+public class CursorAnchorInfoCompatWrapper {
 
     /**
      * The insertion marker or character bounds have at least one visible region.
@@ -39,123 +46,138 @@
      */
     public static final int FLAG_IS_RTL = 0x04;
 
-    // Note that CursorAnchorInfo has been introduced in API level XX (Build.VERSION_CODE.LXX).
-    private static final CompatUtils.ClassWrapper sCursorAnchorInfoClass;
-    private static final CompatUtils.ToIntMethodWrapper sGetSelectionStartMethod;
-    private static final CompatUtils.ToIntMethodWrapper sGetSelectionEndMethod;
-    private static final CompatUtils.ToObjectMethodWrapper<RectF> sGetCharacterBoundsMethod;
-    private static final CompatUtils.ToIntMethodWrapper sGetCharacterBoundsFlagsMethod;
-    private static final CompatUtils.ToObjectMethodWrapper<CharSequence> sGetComposingTextMethod;
-    private static final CompatUtils.ToIntMethodWrapper sGetComposingTextStartMethod;
-    private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerBaselineMethod;
-    private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerBottomMethod;
-    private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerHorizontalMethod;
-    private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerTopMethod;
-    private static final CompatUtils.ToObjectMethodWrapper<Matrix> sGetMatrixMethod;
-    private static final CompatUtils.ToIntMethodWrapper sGetInsertionMarkerFlagsMethod;
-
-    private static int INVALID_TEXT_INDEX = -1;
-    static {
-        sCursorAnchorInfoClass = CompatUtils.getClassWrapper(
-                "android.view.inputmethod.CursorAnchorInfo");
-        sGetSelectionStartMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getSelectionStart", INVALID_TEXT_INDEX);
-        sGetSelectionEndMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getSelectionEnd", INVALID_TEXT_INDEX);
-        sGetCharacterBoundsMethod = sCursorAnchorInfoClass.getMethod(
-                "getCharacterBounds", (RectF)null, int.class);
-        sGetCharacterBoundsFlagsMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getCharacterBoundsFlags", 0, int.class);
-        sGetComposingTextMethod = sCursorAnchorInfoClass.getMethod(
-                "getComposingText", (CharSequence)null);
-        sGetComposingTextStartMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getComposingTextStart", INVALID_TEXT_INDEX);
-        sGetInsertionMarkerBaselineMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getInsertionMarkerBaseline", 0.0f);
-        sGetInsertionMarkerBottomMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getInsertionMarkerBottom", 0.0f);
-        sGetInsertionMarkerHorizontalMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getInsertionMarkerHorizontal", 0.0f);
-        sGetInsertionMarkerTopMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getInsertionMarkerTop", 0.0f);
-        sGetMatrixMethod = sCursorAnchorInfoClass.getMethod("getMatrix", (Matrix)null);
-        sGetInsertionMarkerFlagsMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
-                "getInsertionMarkerFlags", 0);
+    private CursorAnchorInfoCompatWrapper() {
+        // This class is not publicly instantiable.
     }
 
-    @UsedForTesting
-    public boolean isAvailable() {
-        return sCursorAnchorInfoClass.exists() && mInstance != null;
-    }
-
-    private Object mInstance;
-
-    private CursorAnchorInfoCompatWrapper(final Object instance) {
-        mInstance = instance;
-    }
-
-    @UsedForTesting
-    public static CursorAnchorInfoCompatWrapper fromObject(final Object instance) {
-        if (!sCursorAnchorInfoClass.exists()) {
-            return new CursorAnchorInfoCompatWrapper(null);
+    @TargetApi(BuildCompatUtils.VERSION_CODES_LXX)
+    @Nullable
+    public static CursorAnchorInfoCompatWrapper wrap(@Nullable final CursorAnchorInfo instance) {
+        if (Build.VERSION.SDK_INT < BuildCompatUtils.VERSION_CODES_LXX) {
+            return null;
         }
-        return new CursorAnchorInfoCompatWrapper(instance);
-    }
-
-    private static final class FakeHolder {
-        static CursorAnchorInfoCompatWrapper sInstance = new CursorAnchorInfoCompatWrapper(null);
-    }
-
-    @UsedForTesting
-    public static CursorAnchorInfoCompatWrapper getFake() {
-        return FakeHolder.sInstance;
+        if (instance == null) {
+            return null;
+        }
+        return new RealWrapper(instance);
     }
 
     public int getSelectionStart() {
-        return sGetSelectionStartMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public int getSelectionEnd() {
-        return sGetSelectionEndMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public CharSequence getComposingText() {
-        return sGetComposingTextMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public int getComposingTextStart() {
-        return sGetComposingTextStartMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public Matrix getMatrix() {
-        return sGetMatrixMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public RectF getCharacterBounds(final int index) {
-        return sGetCharacterBoundsMethod.invoke(mInstance, index);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public int getCharacterBoundsFlags(final int index) {
-        return sGetCharacterBoundsFlagsMethod.invoke(mInstance, index);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public float getInsertionMarkerBaseline() {
-        return sGetInsertionMarkerBaselineMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public float getInsertionMarkerBottom() {
-        return sGetInsertionMarkerBottomMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public float getInsertionMarkerHorizontal() {
-        return sGetInsertionMarkerHorizontalMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public float getInsertionMarkerTop() {
-        return sGetInsertionMarkerTopMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
     }
 
     public int getInsertionMarkerFlags() {
-        return sGetInsertionMarkerFlagsMethod.invoke(mInstance);
+        throw new UnsupportedOperationException("not supported.");
+    }
+
+    @TargetApi(BuildCompatUtils.VERSION_CODES_LXX)
+    private static final class RealWrapper extends CursorAnchorInfoCompatWrapper {
+
+        @Nonnull
+        private final CursorAnchorInfo mInstance;
+
+        public RealWrapper(@Nonnull final CursorAnchorInfo info) {
+            mInstance = info;
+        }
+
+        @Override
+        public int getSelectionStart() {
+            return mInstance.getSelectionStart();
+        }
+
+        @Override
+        public int getSelectionEnd() {
+            return mInstance.getSelectionEnd();
+        }
+
+        @Override
+        public CharSequence getComposingText() {
+            return mInstance.getComposingText();
+        }
+
+        @Override
+        public int getComposingTextStart() {
+            return mInstance.getComposingTextStart();
+        }
+
+        @Override
+        public Matrix getMatrix() {
+            return mInstance.getMatrix();
+        }
+
+        @Override
+        public RectF getCharacterBounds(final int index) {
+            return mInstance.getCharacterBounds(index);
+        }
+
+        @Override
+        public int getCharacterBoundsFlags(final int index) {
+            return mInstance.getCharacterBoundsFlags(index);
+        }
+
+        @Override
+        public float getInsertionMarkerBaseline() {
+            return mInstance.getInsertionMarkerBaseline();
+        }
+
+        @Override
+        public float getInsertionMarkerBottom() {
+            return mInstance.getInsertionMarkerBottom();
+        }
+
+        @Override
+        public float getInsertionMarkerHorizontal() {
+            return mInstance.getInsertionMarkerHorizontal();
+        }
+
+        @Override
+        public float getInsertionMarkerTop() {
+            return mInstance.getInsertionMarkerTop();
+        }
+
+        @Override
+        public int getInsertionMarkerFlags() {
+            return mInstance.getInsertionMarkerFlags();
+        }
     }
 }
diff --git a/java/src/com/android/inputmethod/compat/ViewCompatUtils.java b/java/src/com/android/inputmethod/compat/ViewCompatUtils.java
index 0f00be1..16260ab 100644
--- a/java/src/com/android/inputmethod/compat/ViewCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/ViewCompatUtils.java
@@ -31,9 +31,6 @@
     private static final Method METHOD_setPaddingRelative = CompatUtils.getMethod(
             View.class, "setPaddingRelative",
             int.class, int.class, int.class, int.class);
-    // Note that View.setElevation(float) has been introduced in API level 21.
-    private static final Method METHOD_setElevation = CompatUtils.getMethod(
-            View.class, "setElevation", float.class);
     // Note that View.setTextAlignment(int) has been introduced in API level 17.
     private static final Method METHOD_setTextAlignment = CompatUtils.getMethod(
             View.class, "setTextAlignment", int.class);
@@ -58,10 +55,6 @@
         CompatUtils.invoke(view, null, METHOD_setPaddingRelative, start, top, end, bottom);
     }
 
-    public static void setElevation(final View view, final float elevation) {
-        CompatUtils.invoke(view, null, METHOD_setElevation, elevation);
-    }
-
     // These TEXT_ALIGNMENT_* constants have been introduced in API 17.
     public static final int TEXT_ALIGNMENT_INHERIT = 0;
     public static final int TEXT_ALIGNMENT_GRAVITY = 1;
diff --git a/java/src/com/android/inputmethod/compat/ViewOutlineProviderCompatUtils.java b/java/src/com/android/inputmethod/compat/ViewOutlineProviderCompatUtils.java
new file mode 100644
index 0000000..52b8b74
--- /dev/null
+++ b/java/src/com/android/inputmethod/compat/ViewOutlineProviderCompatUtils.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 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.inputmethodservice.InputMethodService;
+import android.view.View;
+
+public class ViewOutlineProviderCompatUtils {
+    private ViewOutlineProviderCompatUtils() {
+        // This utility class is not publicly instantiable.
+    }
+
+    public interface InsetsUpdater {
+        public void setInsets(final InputMethodService.Insets insets);
+    }
+
+    private static final InsetsUpdater EMPTY_INSETS_UPDATER = new InsetsUpdater() {
+        @Override
+        public void setInsets(final InputMethodService.Insets insets) {}
+    };
+
+    public static InsetsUpdater setInsetsOutlineProvider(final View view) {
+        if (BuildCompatUtils.EFFECTIVE_SDK_INT < BuildCompatUtils.VERSION_CODES_LXX) {
+            return EMPTY_INSETS_UPDATER;
+        }
+        return ViewOutlineProviderCompatUtilsLXX.setInsetsOutlineProvider(view);
+    }
+}
diff --git a/java/src/com/android/inputmethod/compat/ViewOutlineProviderCompatUtilsLXX.java b/java/src/com/android/inputmethod/compat/ViewOutlineProviderCompatUtilsLXX.java
new file mode 100644
index 0000000..f9917ac
--- /dev/null
+++ b/java/src/com/android/inputmethod/compat/ViewOutlineProviderCompatUtilsLXX.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2014 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.annotation.TargetApi;
+import android.graphics.Outline;
+import android.inputmethodservice.InputMethodService;
+import android.os.Build;
+import android.view.View;
+import android.view.ViewOutlineProvider;
+
+import com.android.inputmethod.compat.ViewOutlineProviderCompatUtils.InsetsUpdater;
+
+@TargetApi(Build.VERSION_CODES.L)
+class ViewOutlineProviderCompatUtilsLXX {
+    private ViewOutlineProviderCompatUtilsLXX() {
+        // This utility class is not publicly instantiable.
+    }
+
+    static InsetsUpdater setInsetsOutlineProvider(final View view) {
+        final InsetsOutlineProvider provider = new InsetsOutlineProvider(view);
+        view.setOutlineProvider(provider);
+        return provider;
+    }
+
+    private static class InsetsOutlineProvider extends ViewOutlineProvider
+            implements InsetsUpdater {
+        private final View mView;
+        private static final int NO_DATA = -1;
+        private int mLastVisibleTopInsets = NO_DATA;
+
+        public InsetsOutlineProvider(final View view) {
+            mView = view;
+            view.setOutlineProvider(this);
+        }
+
+        @Override
+        public void setInsets(final InputMethodService.Insets insets) {
+            final int visibleTopInsets = insets.visibleTopInsets;
+            if (mLastVisibleTopInsets != visibleTopInsets) {
+                mLastVisibleTopInsets = visibleTopInsets;
+                mView.invalidateOutline();
+            }
+        }
+
+        @Override
+        public void getOutline(final View view, final Outline outline) {
+            if (mLastVisibleTopInsets == NO_DATA) {
+                // Call default implementation.
+                ViewOutlineProvider.BACKGROUND.getOutline(view, outline);
+                return;
+            }
+            // TODO: Revisit this when floating/resize keyboard is supported.
+            outline.setRect(
+                    view.getLeft(), mLastVisibleTopInsets, view.getRight(), view.getBottom());
+        }
+    }
+}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
index 6d8c8b7..8a9688a 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
@@ -22,7 +22,6 @@
 import android.preference.PreferenceManager;
 import android.util.Log;
 
-import com.android.inputmethod.annotations.UsedForTesting;
 import com.android.inputmethod.compat.BuildCompatUtils;
 import com.android.inputmethod.latin.R;
 
@@ -45,7 +44,7 @@
 
     private static KeyboardTheme[] AVAILABLE_KEYBOARD_THEMES;
 
-    @UsedForTesting
+    /* package private for testing */
     static final KeyboardTheme[] KEYBOARD_THEMES = {
         new KeyboardTheme(THEME_ID_ICS, "ICS", R.style.KeyboardTheme_ICS,
                 // This has never been selected because we support ICS or later.
@@ -57,6 +56,7 @@
                 // Default theme for LXX.
                 BuildCompatUtils.VERSION_CODES_LXX),
         new KeyboardTheme(THEME_ID_LXX_DARK, "LXXDark", R.style.KeyboardTheme_LXX_Dark,
+                // This has never been selected as default theme.
                 VERSION_CODES.BASE),
     };
 
@@ -68,7 +68,7 @@
     public final int mThemeId;
     public final int mStyleId;
     public final String mThemeName;
-    private final int mMinApiVersion;
+    public final int mMinApiVersion;
 
     // Note: The themeId should be aligned with "themeId" attribute of Keyboard style
     // in values/themes-<style>.xml.
@@ -98,7 +98,7 @@
         return mThemeId;
     }
 
-    @UsedForTesting
+    /* package private for testing */
     static KeyboardTheme searchKeyboardThemeById(final int themeId,
             final KeyboardTheme[] availableThemeIds) {
         // TODO: This search algorithm isn't optimal if there are many themes.
@@ -110,7 +110,7 @@
         return null;
     }
 
-    @UsedForTesting
+    /* package private for testing */
     static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
             final int sdkVersion, final KeyboardTheme[] availableThemeArray) {
         final String klpThemeIdString = prefs.getString(KLP_KEYBOARD_THEME_KEY, null);
@@ -150,7 +150,7 @@
         saveKeyboardThemeId(themeId, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
     }
 
-    @UsedForTesting
+    /* package private for testing */
     static String getPreferenceKey(final int sdkVersion) {
         if (sdkVersion <= VERSION_CODES.KITKAT) {
             return KLP_KEYBOARD_THEME_KEY;
@@ -158,7 +158,7 @@
         return LXX_KEYBOARD_THEME_KEY;
     }
 
-    @UsedForTesting
+    /* package private for testing */
     static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs,
             final int sdkVersion) {
         final String prefKey = getPreferenceKey(sdkVersion);
@@ -171,6 +171,7 @@
         return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT, availableThemeArray);
     }
 
+    /* package private for testing */
     static KeyboardTheme[] getAvailableThemeArray(final Context context) {
         if (AVAILABLE_KEYBOARD_THEMES == null) {
             final int[] availableThemeIdStringArray = context.getResources().getIntArray(
@@ -184,11 +185,12 @@
             }
             AVAILABLE_KEYBOARD_THEMES = availableThemeList.toArray(
                     new KeyboardTheme[availableThemeList.size()]);
+            Arrays.sort(AVAILABLE_KEYBOARD_THEMES);
         }
         return AVAILABLE_KEYBOARD_THEMES;
     }
 
-    @UsedForTesting
+    /* package private for testing */
     static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion,
             final KeyboardTheme[] availableThemeArray) {
         final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null);
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index ad30b74..06f9ced 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -28,6 +28,7 @@
 import android.graphics.Paint.Align;
 import android.graphics.Typeface;
 import android.preference.PreferenceManager;
+import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
@@ -57,8 +58,10 @@
 import com.android.inputmethod.latin.SuggestedWords;
 import com.android.inputmethod.latin.settings.DebugSettings;
 import com.android.inputmethod.latin.utils.CoordinateUtils;
+import com.android.inputmethod.latin.utils.StringUtils;
 import com.android.inputmethod.latin.utils.TypefaceUtils;
 
+import java.util.Locale;
 import java.util.WeakHashMap;
 
 /**
@@ -146,7 +149,6 @@
 
     // More keys keyboard
     private final Paint mBackgroundDimAlphaPaint = new Paint();
-    private boolean mNeedsToDimEntireKeyboard;
     private final View mMoreKeysKeyboardContainer;
     private final View mMoreKeysKeyboardForActionContainer;
     private final WeakHashMap<Key, Keyboard> mMoreKeysKeyboardCache = new WeakHashMap<>();
@@ -673,7 +675,6 @@
         locatePreviewPlacerView();
         panel.showInParent(mDrawingPreviewPlacerView);
         mMoreKeysPanel = panel;
-        dimEntireKeyboard(true /* dimmed */);
     }
 
     public boolean isShowingMoreKeysPanel() {
@@ -687,7 +688,6 @@
 
     @Override
     public void onDismissMoreKeysPanel() {
-        dimEntireKeyboard(false /* dimmed */);
         if (isShowingMoreKeysPanel()) {
             mMoreKeysPanel.removeFromParent();
             mMoreKeysPanel = null;
@@ -815,24 +815,6 @@
         invalidateKey(mSpaceKey);
     }
 
-    private void dimEntireKeyboard(final boolean dimmed) {
-        final boolean needsRedrawing = mNeedsToDimEntireKeyboard != dimmed;
-        mNeedsToDimEntireKeyboard = dimmed;
-        if (needsRedrawing) {
-            invalidateAllKeys();
-        }
-    }
-
-    @Override
-    protected void onDraw(final Canvas canvas) {
-        super.onDraw(canvas);
-
-        // Overlay a dark rectangle to dim.
-        if (mNeedsToDimEntireKeyboard) {
-            canvas.drawRect(0.0f, 0.0f, getWidth(), getHeight(), mBackgroundDimAlphaPaint);
-        }
-    }
-
     @Override
     protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
             final KeyDrawParams params) {
@@ -876,8 +858,13 @@
     private String layoutLanguageOnSpacebar(final Paint paint,
             final RichInputMethodSubtype subtype, final int width) {
         if (mLanguageOnSpacebarFormatType == LanguageOnSpacebarHelper.FORMAT_TYPE_MULTIPLE) {
-            // TODO: return an appropriate string
-            return "";
+            final Locale[] locales = subtype.getLocales();
+            final String[] languages = new String[locales.length];
+            for (int i = 0; i < locales.length; ++i) {
+                languages[i] = StringUtils.toUpperCaseOfStringForLocale(
+                        locales[i].getLanguage(), true /* needsToUpperCase */, Locale.ROOT);
+            }
+            return TextUtils.join(" / ", languages);
         }
 
         // Choose appropriate language name to fit into the width.
diff --git a/java/src/com/android/inputmethod/keyboard/TextDecorator.java b/java/src/com/android/inputmethod/keyboard/TextDecorator.java
index c22717f..ddc65bf 100644
--- a/java/src/com/android/inputmethod/keyboard/TextDecorator.java
+++ b/java/src/com/android/inputmethod/keyboard/TextDecorator.java
@@ -30,6 +30,7 @@
 import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 /**
  * A controller class of the add-to-dictionary indicator (a.k.a. TextDecorator). This class
@@ -56,6 +57,7 @@
     private String mWaitingWord = null;
     private int mWaitingCursorStart = INVALID_CURSOR_INDEX;
     private int mWaitingCursorEnd = INVALID_CURSOR_INDEX;
+    @Nullable
     private CursorAnchorInfoCompatWrapper mCursorAnchorInfoWrapper = null;
 
     @Nonnull
@@ -150,7 +152,7 @@
      * mode.</p>
      * @param info the compatibility wrapper object for the received {@link CursorAnchorInfo}.
      */
-    public void onUpdateCursorAnchorInfo(final CursorAnchorInfoCompatWrapper info) {
+    public void onUpdateCursorAnchorInfo(@Nullable final CursorAnchorInfoCompatWrapper info) {
         mCursorAnchorInfoWrapper = info;
         // Do not use layoutLater() to minimize the latency.
         layoutImmediately();
@@ -182,7 +184,7 @@
     private void layoutMain() {
         final CursorAnchorInfoCompatWrapper info = mCursorAnchorInfoWrapper;
 
-        if (info == null || !info.isAvailable()) {
+        if (info == null) {
             cancelLayoutInternalExpectedly("CursorAnchorInfo isn't available.");
             return;
         }
diff --git a/java/src/com/android/inputmethod/latin/BackupAgent.java b/java/src/com/android/inputmethod/latin/BackupAgent.java
index 1f04461..b2d92b3 100644
--- a/java/src/com/android/inputmethod/latin/BackupAgent.java
+++ b/java/src/com/android/inputmethod/latin/BackupAgent.java
@@ -17,15 +17,41 @@
 package com.android.inputmethod.latin;
 
 import android.app.backup.BackupAgentHelper;
+import android.app.backup.BackupDataInput;
 import android.app.backup.SharedPreferencesBackupHelper;
+import android.content.SharedPreferences;
+import android.os.ParcelFileDescriptor;
+
+import com.android.inputmethod.latin.settings.LocalSettingsConstants;
+
+import java.io.IOException;
 
 /**
- * Backs up the Latin IME shared preferences.
+ * Backup/restore agent for LatinIME.
+ * Currently it backs up the default shared preferences.
  */
 public final class BackupAgent extends BackupAgentHelper {
+    private static final String PREF_SUFFIX = "_preferences";
+
     @Override
     public void onCreate() {
         addHelper("shared_pref", new SharedPreferencesBackupHelper(this,
-                getPackageName() + "_preferences"));
+                getPackageName() + PREF_SUFFIX));
+    }
+
+    @Override
+    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
+            throws IOException {
+        // Let the restore operation go through
+        super.onRestore(data, appVersionCode, newState);
+
+        // Remove the preferences that we don't want restored.
+        final SharedPreferences.Editor prefEditor = getSharedPreferences(
+                getPackageName() + PREF_SUFFIX, MODE_PRIVATE).edit();
+        for (final String key : LocalSettingsConstants.PREFS_TO_SKIP_RESTORING) {
+            prefEditor.remove(key);
+        }
+        // Flush the changes to disk.
+        prefEditor.commit();
     }
 }
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 10dea74..2fece7c 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -70,7 +70,7 @@
     private static final int FORMAT_WORD_PROPERTY_OUTPUT_FLAG_COUNT = 5;
     private static final int FORMAT_WORD_PROPERTY_IS_NOT_A_WORD_INDEX = 0;
     private static final int FORMAT_WORD_PROPERTY_IS_BLACKLISTED_INDEX = 1;
-    private static final int FORMAT_WORD_PROPERTY_HAS_BIGRAMS_INDEX = 2;
+    private static final int FORMAT_WORD_PROPERTY_HAS_NGRAMS_INDEX = 2;
     private static final int FORMAT_WORD_PROPERTY_HAS_SHORTCUTS_INDEX = 3;
     private static final int FORMAT_WORD_PROPERTY_IS_BEGINNING_OF_SENTENCE_INDEX = 4;
 
@@ -179,9 +179,10 @@
             boolean[] isBeginningOfSentenceArray, int[] word);
     private static native void getWordPropertyNative(long dict, int[] word,
             boolean isBeginningOfSentence, int[] outCodePoints, boolean[] outFlags,
-            int[] outProbabilityInfo, ArrayList<int[]> outBigramTargets,
-            ArrayList<int[]> outBigramProbabilityInfo, ArrayList<int[]> outShortcutTargets,
-            ArrayList<Integer> outShortcutProbabilities);
+            int[] outProbabilityInfo, ArrayList<int[][]> outNgramPrevWordsArray,
+            ArrayList<boolean[]> outNgramPrevWordIsBeginningOfSentenceArray,
+            ArrayList<int[]> outNgramTargets, ArrayList<int[]> outNgramProbabilityInfo,
+            ArrayList<int[]> outShortcutTargets, ArrayList<Integer> outShortcutProbabilities);
     private static native int getNextWordNative(long dict, int token, int[] outCodePoints,
             boolean[] outIsBeginningOfSentence);
     private static native void getSuggestionsNative(long dict, long proximityInfo,
@@ -201,8 +202,7 @@
             int[] word, int probability, int timestamp);
     private static native boolean removeNgramEntryNative(long dict,
             int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray, int[] word);
-    // TODO: Rename to updateEntriesForWordWithNgramContextNative.
-    private static native boolean updateCounterNative(long dict,
+    private static native boolean updateEntriesForWordWithNgramContextNative(long dict,
             int[][] prevWordCodePointArrays, boolean[] isBeginningOfSentenceArray,
             int[] word, boolean isValidWord, int count, int timestamp);
     private static native int addMultipleDictionaryEntriesNative(long dict,
@@ -292,6 +292,7 @@
                 settingsValuesForSuggestion.mSpaceAwareGestureEnabled);
         session.mNativeSuggestOptions.setAdditionalFeaturesOptions(
                 settingsValuesForSuggestion.mAdditionalFeaturesSettingValues);
+        session.mNativeSuggestOptions.setWeightForLocale(weightForLocale);
         if (inOutWeightOfLangModelVsSpatialModel != null) {
             session.mInputOutputWeightOfLangModelVsSpatialModel[0] =
                     inOutWeightOfLangModelVsSpatialModel[0];
@@ -388,20 +389,25 @@
         final boolean[] outFlags = new boolean[FORMAT_WORD_PROPERTY_OUTPUT_FLAG_COUNT];
         final int[] outProbabilityInfo =
                 new int[FORMAT_WORD_PROPERTY_OUTPUT_PROBABILITY_INFO_COUNT];
-        final ArrayList<int[]> outBigramTargets = new ArrayList<>();
-        final ArrayList<int[]> outBigramProbabilityInfo = new ArrayList<>();
+        final ArrayList<int[][]> outNgramPrevWordsArray = new ArrayList<>();
+        final ArrayList<boolean[]> outNgramPrevWordIsBeginningOfSentenceArray =
+                new ArrayList<>();
+        final ArrayList<int[]> outNgramTargets = new ArrayList<>();
+        final ArrayList<int[]> outNgramProbabilityInfo = new ArrayList<>();
         final ArrayList<int[]> outShortcutTargets = new ArrayList<>();
         final ArrayList<Integer> outShortcutProbabilities = new ArrayList<>();
         getWordPropertyNative(mNativeDict, codePoints, isBeginningOfSentence, outCodePoints,
-                outFlags, outProbabilityInfo, outBigramTargets, outBigramProbabilityInfo,
-                outShortcutTargets, outShortcutProbabilities);
+                outFlags, outProbabilityInfo, outNgramPrevWordsArray,
+                outNgramPrevWordIsBeginningOfSentenceArray, outNgramTargets,
+                outNgramProbabilityInfo, outShortcutTargets, outShortcutProbabilities);
         return new WordProperty(codePoints,
                 outFlags[FORMAT_WORD_PROPERTY_IS_NOT_A_WORD_INDEX],
                 outFlags[FORMAT_WORD_PROPERTY_IS_BLACKLISTED_INDEX],
-                outFlags[FORMAT_WORD_PROPERTY_HAS_BIGRAMS_INDEX],
+                outFlags[FORMAT_WORD_PROPERTY_HAS_NGRAMS_INDEX],
                 outFlags[FORMAT_WORD_PROPERTY_HAS_SHORTCUTS_INDEX],
                 outFlags[FORMAT_WORD_PROPERTY_IS_BEGINNING_OF_SENTENCE_INDEX], outProbabilityInfo,
-                outBigramTargets, outBigramProbabilityInfo, outShortcutTargets,
+                outNgramPrevWordsArray, outNgramPrevWordIsBeginningOfSentenceArray,
+                outNgramTargets, outNgramProbabilityInfo, outShortcutTargets,
                 outShortcutProbabilities);
     }
 
@@ -506,7 +512,7 @@
         final boolean[] isBeginningOfSentenceArray = new boolean[ngramContext.getPrevWordCount()];
         ngramContext.outputToArray(prevWordCodePointArrays, isBeginningOfSentenceArray);
         final int[] wordCodePoints = StringUtils.toCodePointArray(word);
-        if (!updateCounterNative(mNativeDict, prevWordCodePointArrays,
+        if (!updateEntriesForWordWithNgramContextNative(mNativeDict, prevWordCodePointArrays,
                 isBeginningOfSentenceArray, wordCodePoints, isValidWord, count, timestamp)) {
             return false;
         }
diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java
index 43561ba..e66847b 100644
--- a/java/src/com/android/inputmethod/latin/Dictionary.java
+++ b/java/src/com/android/inputmethod/latin/Dictionary.java
@@ -16,6 +16,7 @@
 
 package com.android.inputmethod.latin;
 
+import com.android.inputmethod.annotations.UsedForTesting;
 import com.android.inputmethod.keyboard.ProximityInfo;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
@@ -36,19 +37,19 @@
     // The following types do not actually come from real dictionary instances, so we create
     // corresponding instances.
     public static final String TYPE_USER_TYPED = "user_typed";
-    public static final Dictionary DICTIONARY_USER_TYPED = new PhonyDictionary(TYPE_USER_TYPED);
+    public static final PhonyDictionary DICTIONARY_USER_TYPED = new PhonyDictionary(TYPE_USER_TYPED);
 
     public static final String TYPE_APPLICATION_DEFINED = "application_defined";
-    public static final Dictionary DICTIONARY_APPLICATION_DEFINED =
+    public static final PhonyDictionary DICTIONARY_APPLICATION_DEFINED =
             new PhonyDictionary(TYPE_APPLICATION_DEFINED);
 
     public static final String TYPE_HARDCODED = "hardcoded"; // punctuation signs and such
-    public static final Dictionary DICTIONARY_HARDCODED =
+    public static final PhonyDictionary DICTIONARY_HARDCODED =
             new PhonyDictionary(TYPE_HARDCODED);
 
     // Spawned by resuming suggestions. Comes from a span that was in the TextView.
     public static final String TYPE_RESUMED = "resumed";
-    public static final Dictionary DICTIONARY_RESUMED =
+    public static final PhonyDictionary DICTIONARY_RESUMED =
             new PhonyDictionary(TYPE_RESUMED);
 
     // The following types of dictionary have actual functional instances. We don't need final
@@ -182,9 +183,10 @@
      * Not a true dictionary. A placeholder used to indicate suggestions that don't come from any
      * real dictionary.
      */
-    private static class PhonyDictionary extends Dictionary {
-        // This class is not publicly instantiable.
-        private PhonyDictionary(final String type) {
+    @UsedForTesting
+    static class PhonyDictionary extends Dictionary {
+        @UsedForTesting
+        PhonyDictionary(final String type) {
             super(type, null);
         }
 
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
index 6a63bfd..08035df 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
@@ -257,6 +257,12 @@
     }
 
     public void switchMostProbableLanguage(final Locale locale) {
+        if (null == locale) {
+            // In many cases, there is no locale to a committed word. For example, a typed word
+            // that does not auto-correct has no locale. In this case we simply do not change
+            // the most probable language.
+            return;
+        }
         final DictionaryGroup newMostProbableDictionaryGroup =
                 findDictionaryGroupWithLocale(mDictionaryGroups, locale);
         mMostProbableDictionaryGroup.mWeightForTypingInLocale =
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 77477d2..77016cb 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -60,6 +60,8 @@
 import com.android.inputmethod.annotations.UsedForTesting;
 import com.android.inputmethod.compat.CursorAnchorInfoCompatWrapper;
 import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
+import com.android.inputmethod.compat.ViewOutlineProviderCompatUtils;
+import com.android.inputmethod.compat.ViewOutlineProviderCompatUtils.InsetsUpdater;
 import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
 import com.android.inputmethod.event.Event;
 import com.android.inputmethod.event.HardwareEventDecoder;
@@ -85,7 +87,6 @@
 import com.android.inputmethod.latin.settings.SettingsValues;
 import com.android.inputmethod.latin.suggestions.SuggestionStripView;
 import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor;
-import com.android.inputmethod.latin.sync.BeanstalkManager;
 import com.android.inputmethod.latin.touchinputconsumer.GestureConsumer;
 import com.android.inputmethod.latin.utils.ApplicationUtils;
 import com.android.inputmethod.latin.utils.CapsModeUtils;
@@ -154,6 +155,7 @@
 
     // TODO: Move these {@link View}s to {@link KeyboardSwitcher}.
     private View mInputView;
+    private InsetsUpdater mInsetsUpdater;
     private SuggestionStripView mSuggestionStripView;
     private TextView mExtractEditText;
 
@@ -558,7 +560,6 @@
         AudioAndHapticFeedbackManager.init(this);
         AccessibilityUtils.init(this);
         mStatsUtilsManager.onCreate(this /* context */);
-        BeanstalkManager.getInstance(this /* context */).onCreate();
         super.onCreate();
 
         mHandler.onCreate();
@@ -567,6 +568,7 @@
         // TODO: Resolve mutual dependencies of {@link #loadSettings()} and
         // {@link #resetDictionaryFacilitatorIfNecessary()}.
         loadSettings();
+        mSubtypeSwitcher.onSubtypeChanged(mRichImm.getCurrentRawSubtype());
         resetDictionaryFacilitatorIfNecessary();
 
         // Register to receive ringer mode change and network state change.
@@ -706,7 +708,6 @@
         unregisterReceiver(mDictionaryPackInstallReceiver);
         unregisterReceiver(mDictionaryDumpBroadcastReceiver);
         mStatsUtilsManager.onDestroy();
-        BeanstalkManager.getInstance(this /* context */).onDestroy();
         super.onDestroy();
     }
 
@@ -754,6 +755,7 @@
     public void setInputView(final View view) {
         super.setInputView(view);
         mInputView = view;
+        mInsetsUpdater = ViewOutlineProviderCompatUtils.setInsetsOutlineProvider(view);
         updateSoftInputWindowLayoutParameters();
         mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view);
         if (hasSuggestionStripView()) {
@@ -791,23 +793,17 @@
             new ViewTreeObserver.OnPreDrawListener() {
                 @Override
                 public boolean onPreDraw() {
-                    onExtractTextViewPreDraw();
+                    // CursorAnchorInfo is used on L and later.
+                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.L) {
+                        if (isFullscreenMode() && mExtractEditText != null) {
+                            mInputLogic.onUpdateCursorAnchorInfo(
+                                    CursorAnchorInfoUtils.extractFromTextView(mExtractEditText));
+                        }
+                    }
                     return true;
                 }
             };
 
-    private void onExtractTextViewPreDraw() {
-        // CursorAnchorInfo is available on L and later.
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.L) {
-            return;
-        }
-        if (!isFullscreenMode() || mExtractEditText == null) {
-            return;
-        }
-        final CursorAnchorInfo info = CursorAnchorInfoUtils.getCursorAnchorInfo(mExtractEditText);
-        mInputLogic.onUpdateCursorAnchorInfo(CursorAnchorInfoCompatWrapper.fromObject(info));
-    }
-
     @Override
     public void setCandidatesView(final View view) {
         // To ensure that CandidatesView will never be set.
@@ -842,8 +838,7 @@
     public void onCurrentInputMethodSubtypeChanged(final InputMethodSubtype subtype) {
         // Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged()
         // is not guaranteed. It may even be called at the same time on a different thread.
-        final RichInputMethodSubtype richSubtype = new RichInputMethodSubtype(subtype);
-        mSubtypeSwitcher.onSubtypeChanged(richSubtype);
+        mSubtypeSwitcher.onSubtypeChanged(subtype);
         mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype),
                 mSettings.getCurrent());
         loadKeyboard();
@@ -1090,7 +1085,7 @@
         if (isFullscreenMode()) {
             return;
         }
-        mInputLogic.onUpdateCursorAnchorInfo(CursorAnchorInfoCompatWrapper.fromObject(info));
+        mInputLogic.onUpdateCursorAnchorInfo(CursorAnchorInfoCompatWrapper.wrap(info));
     }
 
     /**
@@ -1191,6 +1186,7 @@
             // no visual element will be shown on the screen.
             outInsets.touchableInsets = inputHeight;
             outInsets.visibleTopInsets = inputHeight;
+            mInsetsUpdater.setInsets(outInsets);
             return;
         }
         final int suggestionsHeight = (!mKeyboardSwitcher.isShowingEmojiPalettes()
@@ -1211,6 +1207,7 @@
         }
         outInsets.contentTopInsets = visibleTopY;
         outInsets.visibleTopInsets = visibleTopY;
+        mInsetsUpdater.setInsets(outInsets);
     }
 
     public void startShowingInputView(final boolean needsToLoadKeyboard) {
@@ -1539,7 +1536,7 @@
 
     private void setSuggestedWords(final SuggestedWords suggestedWords) {
         final SettingsValues currentSettingsValues = mSettings.getCurrent();
-        mInputLogic.setSuggestedWords(suggestedWords, currentSettingsValues, mHandler);
+        mInputLogic.setSuggestedWords(suggestedWords);
         // TODO: Modify this when we support suggestions with hard keyboard
         if (!hasSuggestionStripView()) {
             return;
@@ -1627,7 +1624,7 @@
     }
 
     @Override
-    public void showAddToDictionaryHint(final String word) {
+    public void suggestAddingToDictionary(final String word, final boolean isFromSuggestionStrip) {
         if (!hasSuggestionStripView()) {
             return;
         }
@@ -1637,7 +1634,8 @@
         } else {
             wordToShow = word;
         }
-        mSuggestionStripView.showAddToDictionaryHint(wordToShow);
+        mSuggestionStripView.showAddToDictionaryHint(wordToShow,
+                isFromSuggestionStrip /* shouldShowWordToSave */);
     }
 
     // This will show either an empty suggestion strip (if prediction is enabled) or
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 62a258b..a3f7bb4 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -860,9 +860,10 @@
      * than it really is.
      */
     public void tryFixLyingCursorPosition() {
+        mIC = mParent.getCurrentInputConnection();
         final CharSequence textBeforeCursor = getTextBeforeCursor(
                 Constants.EDITOR_CONTENTS_CACHE_SIZE, 0);
-        final CharSequence selectedText = mIC.getSelectedText(0 /* flags */);
+        final CharSequence selectedText = null == mIC ? null : mIC.getSelectedText(0 /* flags */);
         if (null == textBeforeCursor ||
                 (!TextUtils.isEmpty(selectedText) && mExpectedSelEnd == mExpectedSelStart)) {
             // If textBeforeCursor is null, we have no idea what kind of text field we have or if
diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index 0d5ce7d..3fcae58 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -29,6 +29,7 @@
 import android.view.inputmethod.InputMethodSubtype;
 
 import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.latin.settings.AdditionalFeaturesSettingUtils;
 import com.android.inputmethod.latin.settings.Settings;
 import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
 import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
@@ -298,14 +299,13 @@
         return INDEX_NOT_FOUND;
     }
 
-    public RichInputMethodSubtype getCurrentInputMethodSubtype(
-            final RichInputMethodSubtype defaultSubtype) {
-        final InputMethodSubtype currentSubtype = mImmWrapper.mImm.getCurrentInputMethodSubtype();
-        if (currentSubtype == null) {
-            return defaultSubtype;
-        }
-        // TODO: Determine locales to use for multi-lingual use.
-        return new RichInputMethodSubtype(currentSubtype);
+    public InputMethodSubtype getCurrentRawSubtype() {
+        return mImmWrapper.mImm.getCurrentInputMethodSubtype();
+    }
+
+    public RichInputMethodSubtype createCurrentRichInputMethodSubtype(
+            final InputMethodSubtype rawSubtype) {
+        return AdditionalFeaturesSettingUtils.createRichInputMethodSubtype(this, rawSubtype);
     }
 
     public boolean hasMultipleEnabledIMEsOrSubtypes(final boolean shouldIncludeAuxiliarySubtypes) {
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index c339e96..0d742e9 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -58,6 +58,7 @@
             new LanguageOnSpacebarHelper();
     private InputMethodInfo mShortcutInputMethodInfo;
     private InputMethodSubtype mShortcutSubtype;
+    private RichInputMethodSubtype mCurrentRichInputMethodSubtype;
     private RichInputMethodSubtype mNoLanguageSubtype;
     private RichInputMethodSubtype mEmojiSubtype;
     private boolean mIsNetworkConnected;
@@ -117,7 +118,7 @@
         final NetworkInfo info = connectivityManager.getActiveNetworkInfo();
         mIsNetworkConnected = (info != null && info.isConnected());
 
-        onSubtypeChanged(getCurrentSubtype());
+        onSubtypeChanged(mRichImm.getCurrentRawSubtype());
         updateParametersOnStartInputView();
     }
 
@@ -165,12 +166,14 @@
     }
 
     // Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
-    public void onSubtypeChanged(final RichInputMethodSubtype newSubtype) {
+    public void onSubtypeChanged(final InputMethodSubtype newSubtype) {
+        final RichInputMethodSubtype richSubtype =
+                mRichImm.createCurrentRichInputMethodSubtype(newSubtype);
         if (DBG) {
-            Log.w(TAG, "onSubtypeChanged: " + newSubtype.getNameForLogging());
+            Log.w(TAG, "onSubtypeChanged: " + richSubtype.getNameForLogging());
         }
-
-        final Locale[] newLocales = newSubtype.getLocales();
+        mCurrentRichInputMethodSubtype = richSubtype;
+        final Locale[] newLocales = richSubtype.getLocales();
         if (newLocales.length > 1) {
             // In multi-locales mode, the system language is never the same as the input language
             // because there is no single input language.
@@ -181,7 +184,7 @@
             final boolean sameLocale = systemLocale.equals(newLocale);
             final boolean sameLanguage = systemLocale.getLanguage().equals(newLocale.getLanguage());
             final boolean implicitlyEnabled = mRichImm
-                    .checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype.getRawSubtype());
+                    .checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype);
             mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(
                     sameLocale || (sameLanguage && implicitlyEnabled));
         }
@@ -301,7 +304,7 @@
         if (null != sForcedSubtypeForTesting) {
             return sForcedSubtypeForTesting;
         }
-        return mRichImm.getCurrentInputMethodSubtype(getNoLanguageSubtype());
+        return mCurrentRichInputMethodSubtype;
     }
 
     public RichInputMethodSubtype getNoLanguageSubtype() {
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 4665764..e5bf25d 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -243,7 +243,8 @@
         return candidate.isEligibleForAutoCommit() ? candidate : null;
     }
 
-    public static final class SuggestedWordInfo {
+    // non-final for testability.
+    public static class SuggestedWordInfo {
         public static final int NOT_AN_INDEX = -1;
         public static final int NOT_A_CONFIDENCE = -1;
         public static final int MAX_SCORE = Integer.MAX_VALUE;
@@ -413,28 +414,6 @@
         return isPrediction(mInputStyle);
     }
 
-    // SuggestedWords is an immutable object, as much as possible. We must not just remove
-    // words from the member ArrayList as some other parties may expect the object to never change.
-    // This is only ever called by recorrection at the moment, hence the ForRecorrection moniker.
-    public SuggestedWords getSuggestedWordsExcludingTypedWordForRecorrection() {
-        final ArrayList<SuggestedWordInfo> newSuggestions = new ArrayList<>();
-        String typedWord = null;
-        for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) {
-            final SuggestedWordInfo info = mSuggestedWordInfoList.get(i);
-            if (!info.isKindOf(SuggestedWordInfo.KIND_TYPED)) {
-                newSuggestions.add(info);
-            } else {
-                assert(null == typedWord);
-                typedWord = info.mWord;
-            }
-        }
-        // We should never autocorrect, so we say the typed word is valid. Also, in this case,
-        // no auto-correction should take place hence willAutoCorrect = false.
-        return new SuggestedWords(newSuggestions, null /* rawSuggestions */, typedWord,
-                true /* typedWordValid */, false /* willAutoCorrect */, mIsObsoleteSuggestions,
-                SuggestedWords.INPUT_STYLE_RECORRECTION, NOT_A_SEQUENCE_NUMBER);
-    }
-
     // Creates a new SuggestedWordInfo from the currently suggested words that removes all but the
     // last word of all suggestions, separated by a space. This is necessary because when we commit
     // a multiple-word suggestion, the IME only retains the last word as the composing word, and
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 157bd15..5eb338e 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -18,6 +18,7 @@
 
 import com.android.inputmethod.event.CombinerChain;
 import com.android.inputmethod.event.Event;
+import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 import com.android.inputmethod.latin.define.DebugFlags;
 import com.android.inputmethod.latin.utils.CoordinateUtils;
 import com.android.inputmethod.latin.utils.StringUtils;
@@ -48,8 +49,7 @@
     // The list of events that served to compose this string.
     private final ArrayList<Event> mEvents;
     private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH);
-    private String mAutoCorrection;
-    private String mAutoCorrectionDictionaryType;
+    private SuggestedWordInfo mAutoCorrection;
     private boolean mIsResumed;
     private boolean mIsBatchMode;
     // A memory of the last rejected batch mode suggestion, if any. This goes like this: the user
@@ -418,26 +418,18 @@
     /**
      * Sets the auto-correction for this word.
      */
-    public void setAutoCorrection(final String correction, String dictType) {
-        mAutoCorrection = correction;
-        mAutoCorrectionDictionaryType = dictType;
+    public void setAutoCorrection(final SuggestedWordInfo autoCorrection) {
+        mAutoCorrection = autoCorrection;
     }
 
     /**
      * @return the auto-correction for this word, or null if none.
      */
-    public String getAutoCorrectionOrNull() {
+    public SuggestedWordInfo getAutoCorrectionOrNull() {
         return mAutoCorrection;
     }
 
     /**
-     * @return the auto-correction dictionary type or null if none.
-     */
-    public String getAutoCorrectionDictionaryTypeOrNull() {
-        return mAutoCorrectionDictionaryType;
-    }
-
-    /**
      * @return whether we started composing this word by resuming suggestion on an existing string
      */
     public boolean isResumed() {
diff --git a/java/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiver.java b/java/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiver.java
index 9445ce4..00bcecf 100644
--- a/java/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiver.java
+++ b/java/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiver.java
@@ -26,7 +26,7 @@
 import android.util.Log;
 
 import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.settings.Settings;
+import com.android.inputmethod.latin.settings.LocalSettingsConstants;
 
 /**
  * {@link BroadcastReceiver} for {@link AccountManager#LOGIN_ACCOUNTS_CHANGED_ACTION}.
@@ -41,25 +41,14 @@
             return;
         }
 
+        // Ideally the account preference could live in a different preferences file
+        // that wasn't being backed up and restored, however the preference fragments
+        // currently only deal with the default shared preferences which is why
+        // separating this out into a different file is not trivial currently.
         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
-        final String currentAccount = prefs.getString(Settings.PREF_ACCOUNT_NAME, null);
-        if (currentAccount != null) {
-            final String[] accounts = getAccountsForLogin(context);
-            boolean accountFound = false;
-            for (String account : accounts) {
-                if (TextUtils.equals(currentAccount, account)) {
-                    accountFound = true;
-                    break;
-                }
-            }
-            // The current account was not found in the list of accounts, remove it.
-            if (!accountFound) {
-                Log.i(TAG, "The current account was removed from the system: " + currentAccount);
-                prefs.edit()
-                        .remove(Settings.PREF_ACCOUNT_NAME)
-                        .apply();
-            }
-        }
+        final String currentAccount = prefs.getString(
+                LocalSettingsConstants.PREF_ACCOUNT_NAME, null);
+        removeUnknownAccountFromPreference(prefs, getAccountsForLogin(context), currentAccount);
     }
 
     /**
@@ -69,4 +58,24 @@
     protected String[] getAccountsForLogin(Context context) {
         return LoginAccountUtils.getAccountsForLogin(context);
     }
+
+    /**
+     * Removes the currentAccount from preferences if it's not found
+     * in the list of current accounts.
+     */
+    private static void removeUnknownAccountFromPreference(final SharedPreferences prefs,
+            final String[] accounts, final String currentAccount) {
+        if (currentAccount == null) {
+            return;
+        }
+        for (final String account : accounts) {
+            if (TextUtils.equals(currentAccount, account)) {
+                return;
+            }
+        }
+        Log.i(TAG, "The current account was removed from the system: " + currentAccount);
+        prefs.edit()
+                .remove(LocalSettingsConstants.PREF_ACCOUNT_NAME)
+                .apply();
+    }
 }
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 07bfd0d..f67b8de 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -305,6 +305,7 @@
                     currentKeyboardScriptId, handler);
         }
 
+        mDictionaryFacilitator.switchMostProbableLanguage(suggestionInfo.mSourceDict.mLocale);
         final Event event = Event.createSuggestionPickedEvent(suggestionInfo);
         final InputTransaction inputTransaction = new InputTransaction(settingsValues,
                 event, SystemClock.uptimeMillis(), mSpaceState, keyboardShiftState);
@@ -348,7 +349,8 @@
         inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
 
         if (shouldShowAddToDictionaryHint) {
-            mSuggestionStripViewAccessor.showAddToDictionaryHint(suggestion);
+            mSuggestionStripViewAccessor.suggestAddingToDictionary(suggestion,
+                    true /* isFromSuggestionStrip */);
         } else {
             // If we're not showing the "Touch again to save", then update the suggestion strip.
             // That's going to be predictions (or punctuation suggestions), so INPUT_STYLE_NONE.
@@ -607,25 +609,21 @@
 
     // TODO: on the long term, this method should become private, but it will be difficult.
     // Especially, how do we deal with InputMethodService.onDisplayCompletions?
-    public void setSuggestedWords(final SuggestedWords suggestedWords,
-            final SettingsValues settingsValues, final LatinIME.UIHandler handler) {
+    public void setSuggestedWords(final SuggestedWords suggestedWords) {
         if (!suggestedWords.isEmpty()) {
-            final String autoCorrection;
-            final String dictType;
+            final SuggestedWordInfo suggestedWordInfo;
             if (suggestedWords.mWillAutoCorrect) {
-                SuggestedWordInfo info = suggestedWords.getInfo(
-                        SuggestedWords.INDEX_OF_AUTO_CORRECTION);
-                autoCorrection = info.mWord;
-                dictType = info.mSourceDict.mDictType;
+                suggestedWordInfo = suggestedWords.getInfo(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
             } else {
                 // We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)
                 // because it may differ from mWordComposer.mTypedWord.
-                autoCorrection = suggestedWords.mTypedWord;
-                dictType = Dictionary.TYPE_USER_TYPED;
+                suggestedWordInfo = new SuggestedWordInfo(suggestedWords.mTypedWord,
+                        SuggestedWordInfo.MAX_SCORE,
+                        SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED,
+                        SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
+                        SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */);
             }
-            // TODO: Use the SuggestedWordInfo to set the auto correction when
-            // user typed word is available via SuggestedWordInfo.
-            mWordComposer.setAutoCorrection(autoCorrection, dictType);
+            mWordComposer.setAutoCorrection(suggestedWordInfo);
         }
         mSuggestedWords = suggestedWords;
         final boolean newAutoCorrectionIndicator = suggestedWords.mWillAutoCorrect;
@@ -1488,6 +1486,11 @@
         if (numberOfCharsInWordBeforeCursor > expectedCursorPosition) return;
         final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>();
         final String typedWord = range.mWord.toString();
+        suggestions.add(new SuggestedWordInfo(typedWord,
+                SuggestedWords.MAX_SUGGESTIONS + 1,
+                SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED,
+                SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
+                SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
         if (!isResumableWord(settingsValues, typedWord)) {
             mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
             return;
@@ -1520,30 +1523,14 @@
         mConnection.maybeMoveTheCursorAroundAndRestoreToWorkaroundABug();
         mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
                 expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
-        if (suggestions.size() <= 0) {
+        if (suggestions.size() <= 1) {
             // If there weren't any suggestion spans on this word, suggestions#size() will be 1
             // if shouldIncludeResumedWordInSuggestions is true, 0 otherwise. In this case, we
             // have no useful suggestions, so we will try to compute some for it instead.
             mInputLogicHandler.getSuggestedWords(Suggest.SESSION_ID_TYPING,
                     SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
                         @Override
-                        public void onGetSuggestedWords(
-                                final SuggestedWords suggestedWordsIncludingTypedWord) {
-                            final SuggestedWords suggestedWords;
-                            if (suggestedWordsIncludingTypedWord.size() > 1) {
-                                // We were able to compute new suggestions for this word.
-                                // Remove the typed word, since we don't want to display it in this
-                                // case. The #getSuggestedWordsExcludingTypedWordForRecorrection()
-                                // method sets willAutoCorrect to false.
-                                suggestedWords = suggestedWordsIncludingTypedWord
-                                        .getSuggestedWordsExcludingTypedWordForRecorrection();
-                            } else {
-                                // No saved suggestions, and we were unable to compute any good one
-                                // either. Rather than displaying an empty suggestion strip, we'll
-                                // display the original word alone in the middle.
-                                // Since there is only one word, willAutoCorrect is false.
-                                suggestedWords = suggestedWordsIncludingTypedWord;
-                            }
+                        public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
                             mIsAutoCorrectionIndicatorOn = false;
                             mLatinIME.mHandler.showSuggestionStrip(suggestedWords);
                         }});
@@ -1687,7 +1674,8 @@
                         mConnection.getExpectedSelectionStart(),
                         mConnection.getExpectedSelectionEnd());
             }
-            mSuggestionStripViewAccessor.showAddToDictionaryHint(originallyTypedWordString);
+            mSuggestionStripViewAccessor.suggestAddingToDictionary(originallyTypedWordString,
+                    false /* isFromSuggestionStrip */);
         } else {
             // We have a separator between the word and the cursor: we should show predictions.
             inputTransaction.setRequiresUpdateSuggestions();
@@ -2092,19 +2080,23 @@
             // INPUT_STYLE_TYPING.
             performUpdateSuggestionStripSync(settingsValues, SuggestedWords.INPUT_STYLE_TYPING);
         }
-        final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
+        final SuggestedWordInfo autoCorrectionOrNull = mWordComposer.getAutoCorrectionOrNull();
         final String typedWord = mWordComposer.getTypedWord();
-        final String autoCorrection = (typedAutoCorrection != null)
-                ? typedAutoCorrection : typedWord;
-        if (autoCorrection != null) {
+        final String stringToCommit = (autoCorrectionOrNull != null)
+                ? autoCorrectionOrNull.mWord : typedWord;
+        if (stringToCommit != null) {
             if (TextUtils.isEmpty(typedWord)) {
                 throw new RuntimeException("We have an auto-correction but the typed word "
                         + "is empty? Impossible! I must commit suicide.");
             }
             final boolean isBatchMode = mWordComposer.isBatchMode();
-            commitChosenWord(settingsValues, autoCorrection,
+            commitChosenWord(settingsValues, stringToCommit,
                     LastComposedWord.COMMIT_TYPE_DECIDED_WORD, separator);
-            if (!typedWord.equals(autoCorrection)) {
+            if (null != autoCorrectionOrNull) {
+                mDictionaryFacilitator.switchMostProbableLanguage(
+                        autoCorrectionOrNull.mSourceDict.mLocale);
+            }
+            if (!typedWord.equals(stringToCommit)) {
                 // This will make the correction flash for a short while as a visual clue
                 // to the user that auto-correction happened. It has no other effect; in particular
                 // note that this won't affect the text inside the text field AT ALL: it only makes
@@ -2112,13 +2104,14 @@
                 // of the auto-correction flash. At this moment, the "typedWord" argument is
                 // ignored by TextView.
                 mConnection.commitCorrection(new CorrectionInfo(
-                        mConnection.getExpectedSelectionEnd() - autoCorrection.length(),
-                        typedWord, autoCorrection));
-                StatsUtils.onAutoCorrection(typedWord, autoCorrection, isBatchMode,
-                        mWordComposer.getAutoCorrectionDictionaryTypeOrNull());
-                StatsUtils.onWordCommitAutoCorrect(autoCorrection, isBatchMode);
+                        mConnection.getExpectedSelectionEnd() - stringToCommit.length(),
+                        typedWord, stringToCommit));
+                StatsUtils.onAutoCorrection(typedWord, stringToCommit, isBatchMode,
+                        null == autoCorrectionOrNull
+                                ? null : autoCorrectionOrNull.mSourceDict.mDictType);
+                StatsUtils.onWordCommitAutoCorrect(stringToCommit, isBatchMode);
             } else {
-                StatsUtils.onWordCommitUserTyped(autoCorrection, isBatchMode);
+                StatsUtils.onWordCommitUserTyped(stringToCommit, isBatchMode);
             }
         }
     }
diff --git a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
index a180d06..1e6cadf 100644
--- a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
+++ b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
@@ -26,6 +26,8 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 
+import javax.annotation.Nullable;
+
 /**
  * Utility class for a word with a probability.
  *
@@ -49,7 +51,7 @@
     @UsedForTesting
     public WordProperty(final String word, final ProbabilityInfo probabilityInfo,
             final ArrayList<WeightedString> shortcutTargets,
-            final ArrayList<WeightedString> bigrams,
+            @Nullable final ArrayList<WeightedString> bigrams,
             final boolean isNotAWord, final boolean isBlacklistEntry) {
         mWord = word;
         mProbabilityInfo = probabilityInfo;
@@ -85,7 +87,9 @@
     public WordProperty(final int[] codePoints, final boolean isNotAWord,
             final boolean isBlacklisted, final boolean hasBigram, final boolean hasShortcuts,
             final boolean isBeginningOfSentence, final int[] probabilityInfo,
-            final ArrayList<int[]> bigramTargets, final ArrayList<int[]> bigramProbabilityInfo,
+            final ArrayList<int[][]> ngramPrevWordsArray,
+            final ArrayList<boolean[]> outNgramPrevWordIsBeginningOfSentenceArray,
+            final ArrayList<int[]> ngramTargets, final ArrayList<int[]> ngramProbabilityInfo,
             final ArrayList<int[]> shortcutTargets,
             final ArrayList<Integer> shortcutProbabilities) {
         mWord = StringUtils.getStringFromNullTerminatedCodePointArray(codePoints);
@@ -98,15 +102,15 @@
         mHasShortcuts = hasShortcuts;
         mHasNgrams = hasBigram;
 
-        final int relatedNgramCount = bigramTargets.size();
+        final int relatedNgramCount = ngramTargets.size();
         final WordInfo currentWordInfo =
                 mIsBeginningOfSentence ? WordInfo.BEGINNING_OF_SENTENCE : new WordInfo(mWord);
         final NgramContext ngramContext = new NgramContext(currentWordInfo);
         for (int i = 0; i < relatedNgramCount; i++) {
             final String ngramTargetString =
-                    StringUtils.getStringFromNullTerminatedCodePointArray(bigramTargets.get(i));
+                    StringUtils.getStringFromNullTerminatedCodePointArray(ngramTargets.get(i));
             final WeightedString ngramTarget = new WeightedString(ngramTargetString,
-                    createProbabilityInfoFromArray(bigramProbabilityInfo.get(i)));
+                    createProbabilityInfoFromArray(ngramProbabilityInfo.get(i)));
             // TODO: Support n-gram.
             ngrams.add(new NgramProperty(ngramTarget, ngramContext));
         }
@@ -180,7 +184,8 @@
                 && mHasNgrams == w.mHasNgrams && mHasShortcuts && w.mHasNgrams;
     }
 
-    private <T> boolean equals(final ArrayList<T> a, final ArrayList<T> b) {
+    // TDOO: Have a utility method like java.util.Objects.equals.
+    private static <T> boolean equals(final ArrayList<T> a, final ArrayList<T> b) {
         if (null == a) {
             return null == b;
         }
diff --git a/java/src/com/android/inputmethod/latin/network/AuthException.java b/java/src/com/android/inputmethod/latin/network/AuthException.java
new file mode 100644
index 0000000..1bce4c1
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/network/AuthException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 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.latin.network;
+
+/**
+ * Authentication exception. When this exception is thrown, the client may
+ * try to refresh the authentication token and try again.
+ */
+public class AuthException extends Exception {
+    public AuthException() {
+        super();
+    }
+
+    public AuthException(Throwable throwable) {
+        super(throwable);
+    }
+
+    public AuthException(String detailMessage) {
+        super(detailMessage);
+    }
+}
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/latin/network/BlockingHttpClient.java b/java/src/com/android/inputmethod/latin/network/BlockingHttpClient.java
index 0d0cbe1..e2d24fd 100644
--- a/java/src/com/android/inputmethod/latin/network/BlockingHttpClient.java
+++ b/java/src/com/android/inputmethod/latin/network/BlockingHttpClient.java
@@ -16,7 +16,7 @@
 
 package com.android.inputmethod.latin.network;
 
-import com.android.inputmethod.annotations.UsedForTesting;
+import android.util.Log;
 
 import java.io.BufferedOutputStream;
 import java.io.IOException;
@@ -30,25 +30,17 @@
 /**
  * A client for executing HTTP requests synchronously.
  * This must never be called from the main thread.
- *
- * TODO: Remove @UsedForTesting after this is actually used.
  */
-@UsedForTesting
 public class BlockingHttpClient {
+    private static final boolean DEBUG = false;
+    private static final String TAG = BlockingHttpClient.class.getSimpleName();
+
     private final HttpURLConnection mConnection;
 
     /**
      * Interface that handles processing the response for a request.
      */
-    public interface ResponseProcessor {
-        /**
-         * Called when the HTTP request fails with an error.
-         *
-         * @param httpStatusCode The status code of the HTTP response.
-         * @param message The HTTP response message, if any, or null.
-         */
-        void onError(int httpStatusCode, @Nullable String message);
-
+    public interface ResponseProcessor<T> {
         /**
          * Called when the HTTP request finishes successfully.
          * The {@link InputStream} is closed by the client after the method finishes,
@@ -56,13 +48,9 @@
          *
          * @param response An input stream that can be used to read the HTTP response.
          */
-        void onSuccess(InputStream response);
+         T onSuccess(InputStream response) throws IOException;
     }
 
-    /**
-     * TODO: Remove @UsedForTesting after this is actually used.
-     */
-    @UsedForTesting
     public BlockingHttpClient(HttpURLConnection connection) {
         mConnection = connection;
     }
@@ -70,16 +58,19 @@
     /**
      * Executes the request on the underlying {@link HttpURLConnection}.
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
-     *
      * @param request The request payload, if any, or null.
-     * @param responeProcessor A processor for the HTTP response.
+     * @param responseProcessor A processor for the HTTP response.
      */
-    @UsedForTesting
-    public void execute(@Nullable byte[] request, @Nonnull ResponseProcessor responseProcessor)
-            throws IOException {
+    public <T> T execute(@Nullable byte[] request, @Nonnull ResponseProcessor<T> responseProcessor)
+            throws IOException, AuthException, HttpException {
+        if (DEBUG) {
+            Log.d(TAG, "execute: " + mConnection.getURL());
+        }
         try {
             if (request != null) {
+                if (DEBUG) {
+                    Log.d(TAG, "request size: " + request.length);
+                }
                 OutputStream out = new BufferedOutputStream(mConnection.getOutputStream());
                 out.write(request);
                 out.flush();
@@ -88,9 +79,17 @@
 
             final int responseCode = mConnection.getResponseCode();
             if (responseCode != HttpURLConnection.HTTP_OK) {
-                responseProcessor.onError(responseCode, mConnection.getResponseMessage());
+                Log.w(TAG, "Response error: " +  responseCode + ", Message: "
+                        + mConnection.getResponseMessage());
+                if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
+                    throw new AuthException(mConnection.getResponseMessage());
+                }
+                throw new HttpException(responseCode);
             } else {
-                responseProcessor.onSuccess(mConnection.getInputStream());
+                if (DEBUG) {
+                    Log.d(TAG, "request executed successfully");
+                }
+                return responseProcessor.onSuccess(mConnection.getInputStream());
             }
         } finally {
             mConnection.disconnect();
diff --git a/java/src/com/android/inputmethod/latin/network/HttpException.java b/java/src/com/android/inputmethod/latin/network/HttpException.java
new file mode 100644
index 0000000..b9d8b63
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/network/HttpException.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 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.latin.network;
+
+import com.android.inputmethod.annotations.UsedForTesting;
+
+/**
+ * The HttpException exception represents a XML/HTTP fault with a HTTP status code.
+ */
+public class HttpException extends Exception {
+
+    /**
+     * The HTTP status code.
+     */
+    private final int mStatusCode;
+
+    /**
+     * @param statusCode int HTTP status code.
+     */
+    public HttpException(int statusCode) {
+        super("Response Code: " + statusCode);
+        mStatusCode = statusCode;
+    }
+
+    /**
+     * @return the HTTP status code related to this exception.
+     */
+    @UsedForTesting
+    public int getHttpStatusCode() {
+        return mStatusCode;
+    }
+}
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilder.java b/java/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilder.java
index 35b65be..502f72f 100644
--- a/java/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilder.java
+++ b/java/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilder.java
@@ -37,6 +37,11 @@
     private static final int DEFAULT_TIMEOUT_MILLIS = 5 * 1000;
 
     /**
+     * Request header key for authentication.
+     */
+    public static final String HTTP_HEADER_AUTHORIZATION = "Authorization";
+
+    /**
      * Request header key for cache control.
      */
     public static final String KEY_CACHE_CONTROL = "Cache-Control";
@@ -78,7 +83,7 @@
      * Sets the URL that'll be used for the request.
      * This *must* be set before calling {@link #build()}
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
+     * TODO: Remove @UsedForTesting after this method is actually used.
      */
     @UsedForTesting
     public HttpUrlConnectionBuilder setUrl(String url) throws MalformedURLException {
@@ -92,7 +97,7 @@
     /**
      * Sets the connect timeout. Defaults to {@value #DEFAULT_TIMEOUT} milliseconds.
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
+     * TODO: Remove @UsedForTesting after this method is actually used.
      */
     @UsedForTesting
     public HttpUrlConnectionBuilder setConnectTimeout(int timeoutMillis) {
@@ -107,7 +112,7 @@
     /**
      * Sets the read timeout. Defaults to {@value #DEFAULT_TIMEOUT} milliseconds.
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
+     * TODO: Remove @UsedForTesting after this method is actually used.
      */
     @UsedForTesting
     public HttpUrlConnectionBuilder setReadTimeout(int timeoutMillis) {
@@ -122,7 +127,7 @@
     /**
      * Adds an entry to the request header.
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
+     * TODO: Remove @UsedForTesting after this method is actually used.
      */
     @UsedForTesting
     public HttpUrlConnectionBuilder addHeader(String key, String value) {
@@ -131,10 +136,21 @@
     }
 
     /**
+     * Sets an authentication token.
+     *
+     * TODO: Remove @UsedForTesting after this method is actually used.
+     */
+    @UsedForTesting
+    public HttpUrlConnectionBuilder setAuthToken(String value) {
+        mHeaderMap.put(HTTP_HEADER_AUTHORIZATION, value);
+        return this;
+    }
+
+    /**
      * Sets the request to be executed such that the input is not buffered.
      * This may be set when the request size is known beforehand.
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
+     * TODO: Remove @UsedForTesting after this method is actually used.
      */
     @UsedForTesting
     public HttpUrlConnectionBuilder setFixedLengthForStreaming(int length) {
@@ -145,7 +161,7 @@
     /**
      * Indicates if the request can use cached responses or not.
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
+     * TODO: Remove @UsedForTesting after this method is actually used.
      */
     @UsedForTesting
     public HttpUrlConnectionBuilder setUseCache(boolean useCache) {
@@ -161,7 +177,7 @@
      * @see #MODE_DOWNLOAD_ONLY
      * @see #MODE_BI_DIRECTIONAL
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
+     * TODO: Remove @UsedForTesting after this method is actually used
      */
     @UsedForTesting
     public HttpUrlConnectionBuilder setMode(int mode) {
@@ -177,7 +193,7 @@
     /**
      * Builds the {@link HttpURLConnection} instance that can be used to execute the request.
      *
-     * TODO: Remove @UsedForTesting after this is actually used.
+     * TODO: Remove @UsedForTesting after this method is actually used.
      */
     @UsedForTesting
     public HttpURLConnection build() throws IOException {
@@ -210,4 +226,4 @@
         }
         return connection;
     }
-}
+}
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
index a02cb55..5e6521f 100644
--- a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java
@@ -16,7 +16,12 @@
 
 package com.android.inputmethod.latin.settings;
 
+import static com.android.inputmethod.latin.settings.LocalSettingsConstants.PREF_ACCOUNT_NAME;
+import static com.android.inputmethod.latin.settings.LocalSettingsConstants.PREF_ENABLE_CLOUD_SYNC;
+
+import android.accounts.Account;
 import android.app.AlertDialog;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
@@ -28,11 +33,11 @@
 import android.widget.ListView;
 import android.widget.Toast;
 
+import com.android.inputmethod.annotations.UsedForTesting;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.SubtypeSwitcher;
 import com.android.inputmethod.latin.accounts.LoginAccountUtils;
 import com.android.inputmethod.latin.define.ProductionFlags;
-import com.android.inputmethod.latin.sync.BeanstalkManager;
 
 import javax.annotation.Nullable;
 
@@ -40,19 +45,18 @@
  * "Accounts & Privacy" settings sub screen.
  *
  * This settings sub screen handles the following preferences:
- * <li> Account selection/management for IME
- * <li> TODO: Sync preferences
- * <li> TODO: Privacy preferences
- * <li> Sync now
+ * <li> Account selection/management for IME </li>
+ * <li> Sync preferences </li>
+ * <li> Privacy preferences </li>
  */
 public final class AccountsSettingsFragment extends SubScreenFragment {
-    static final String PREF_ACCCOUNT_SWITCHER = "account_switcher";
-    static final String PREF_SYNC_NOW = "pref_beanstalk";
+    private static final String PREF_SYNC_NOW = "pref_beanstalk";
 
-    private final DialogInterface.OnClickListener mAccountSelectedListener =
-            new AccountSelectedListener();
-    private final DialogInterface.OnClickListener mAccountSignedOutListener =
-            new AccountSignedOutListener();
+    @UsedForTesting static final String AUTHORITY = "com.android.inputmethod.latin.provider";
+    static final String PREF_ACCCOUNT_SWITCHER = "account_switcher";
+
+    private final DialogInterface.OnClickListener mAccountChangedListener =
+            new AccountChangedListener();
     private final Preference.OnPreferenceClickListener mSyncNowListener = new SyncNowListener();
 
     @Override
@@ -80,47 +84,55 @@
             removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
         }
 
+        if (!ProductionFlags.ENABLE_ACCOUNT_SIGN_IN) {
+            removePreference(PREF_ACCCOUNT_SWITCHER);
+            removePreference(PREF_ENABLE_CLOUD_SYNC);
+            removePreference(PREF_SYNC_NOW);
+        }
         if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
+            removePreference(PREF_ENABLE_CLOUD_SYNC);
             removePreference(PREF_SYNC_NOW);
         } else {
             final Preference syncNowPreference = findPreference(PREF_SYNC_NOW);
-            if (syncNowPreference != null) {
-                syncNowPreference.setOnPreferenceClickListener(mSyncNowListener);
-            }
+            syncNowPreference.setOnPreferenceClickListener(mSyncNowListener);
         }
     }
 
     @Override
     public void onResume() {
         super.onResume();
-        refreshUi();
+        refreshAccountAndDependentPreferences(getSignedInAccountName());
     }
 
     @Override
     public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
-        // TODO: Look at the preference that changed before refreshing the view.
-        refreshUi();
+        if (TextUtils.equals(key, PREF_ACCOUNT_NAME)) {
+            refreshAccountAndDependentPreferences(
+                    prefs.getString(PREF_ACCOUNT_NAME, null));
+        } else if (TextUtils.equals(key, PREF_ENABLE_CLOUD_SYNC)) {
+            final boolean syncEnabled = prefs.getBoolean(PREF_ENABLE_CLOUD_SYNC, false);
+            updateSyncPolicy(syncEnabled, getSignedInAccountName());
+        }
     }
 
-    private void refreshUi() {
-        refreshAccountSelection();
-        refreshSyncNow();
-    }
-
-    private void refreshAccountSelection() {
+    private void refreshAccountAndDependentPreferences(@Nullable final String currentAccount) {
         if (!ProductionFlags.ENABLE_ACCOUNT_SIGN_IN) {
             return;
         }
 
-        final String currentAccount = getCurrentlySelectedAccount();
         final Preference accountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
         if (currentAccount == null) {
             // No account is currently selected.
             accountSwitcher.setSummary(getString(R.string.no_accounts_selected));
+            // Disable the sync preference UI.
+            disableSyncPreference();
         } else {
             // Set the currently selected account.
             accountSwitcher.setSummary(getString(R.string.account_selected, currentAccount));
+            // Enable the sync preference UI.
+            enableSyncPreference();
         }
+        // Set up onClick listener for the account picker preference.
         final Context context = getActivity();
         final String[] accountsForLogin = LoginAccountUtils.getAccountsForLogin(context);
         accountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -128,45 +140,80 @@
             public boolean onPreferenceClick(Preference preference) {
                 if (accountsForLogin.length == 0) {
                     // TODO: Handle account addition.
-                    Toast.makeText(getActivity(),
-                            getString(R.string.account_select_cancel), Toast.LENGTH_SHORT).show();
+                    Toast.makeText(getActivity(), getString(R.string.account_select_cancel),
+                            Toast.LENGTH_SHORT).show();
                 } else {
                     createAccountPicker(accountsForLogin, currentAccount).show();
                 }
                 return true;
             }
         });
-
-        // TODO: Depending on the account selection, enable/disable preferences that
-        // depend on an account.
     }
 
     /**
-     * Refreshes the "Sync Now" feature
+     * Enables the Sync preference UI and updates its summary.
      */
-    private void refreshSyncNow() {
+    private void enableSyncPreference() {
         if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
             return;
         }
 
-        final Preference syncNowPreference = findPreference(PREF_SYNC_NOW);
-        if (syncNowPreference == null) {
+        final Preference syncPreference = findPreference(PREF_ENABLE_CLOUD_SYNC);
+        syncPreference.setEnabled(true);
+        syncPreference.setSummary(R.string.cloud_sync_summary);
+    }
+
+    /**
+     * Disables the Sync preference UI and updates its summary to indicate
+     * the fact that an account needs to be selected for sync.
+     */
+    private void disableSyncPreference() {
+        if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
             return;
         }
 
-        final String currentAccount = getCurrentlySelectedAccount();
-        if (currentAccount == null) {
-            syncNowPreference.setEnabled(false);
-            syncNowPreference.setSummary(R.string.sync_now_summary);
+        final Preference syncPreference = findPreference(PREF_ENABLE_CLOUD_SYNC);
+        syncPreference.setEnabled(false);
+        syncPreference.setSummary(R.string.cloud_sync_summary_disabled_signed_out);
+    }
+
+    /**
+     * Given a non-null accountToUse, this method looks at the enabled value to either
+     * set or unset the syncable property of the sync authority.
+     * If the account is null, this method is a no-op currently, but we may want
+     * to perform some cleanup in the future.
+     *
+     * @param enabled indicates whether the sync preference is enabled or not.
+     * @param accountToUse indicaes the account to be used for sync, or null if the user
+     *        is not logged in.
+     */
+    @UsedForTesting
+    void updateSyncPolicy(boolean enabled, @Nullable String accountToUse) {
+        if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
+            return;
+        }
+
+        if (accountToUse != null) {
+            final int syncable = enabled ? 1 : 0;
+            ContentResolver.setIsSyncable(
+                    new Account(accountToUse, LoginAccountUtils.ACCOUNT_TYPE),
+                    AUTHORITY, syncable);
+            // TODO: Also add a periodic sync here.
+            // See ContentResolver.addPeriodicSync
         } else {
-            syncNowPreference.setEnabled(true);
-            syncNowPreference.setSummary(R.string.sync_now_summary_disabled_signed_out);
+            // Without an account, we cannot really set the sync to off.
+            // Hopefully the account sign-out listener would have taken care of that for us.
+            // But cases such as clear data are still not handled cleanly.
         }
     }
 
     @Nullable
-    private String getCurrentlySelectedAccount() {
-        return getSharedPreferences().getString(Settings.PREF_ACCOUNT_NAME, null);
+    String getSignedInAccountName() {
+        return getSharedPreferences().getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null);
+    }
+
+    boolean isSyncEnabled() {
+        return getSharedPreferences().getBoolean(PREF_ENABLE_CLOUD_SYNC, false);
     }
 
     /**
@@ -176,6 +223,7 @@
      *
      * Package-private for testing.
      */
+    @UsedForTesting
     AlertDialog createAccountPicker(final String[] accounts,
             final String selectedAccount) {
         if (accounts == null || accounts.length == 0) {
@@ -198,51 +246,55 @@
         final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
                 .setTitle(R.string.account_select_title)
                 .setSingleChoiceItems(accounts, index, null)
-                .setPositiveButton(R.string.account_select_ok, mAccountSelectedListener)
+                .setPositiveButton(R.string.account_select_ok, mAccountChangedListener)
                 .setNegativeButton(R.string.account_select_cancel, null);
         if (isSignedIn) {
-            builder.setNeutralButton(R.string.account_select_sign_out, mAccountSignedOutListener);
+            builder.setNeutralButton(R.string.account_select_sign_out, mAccountChangedListener);
         }
         return builder.create();
     }
 
     /**
-     * Listener for an account being selected from the picker.
-     * Persists the account to shared preferences.
+     * Listener for a account selection changes from the picker.
+     * Persists/removes the account to/from shared preferences and sets up sync if required.
      */
-    class AccountSelectedListener implements DialogInterface.OnClickListener {
+    class AccountChangedListener implements DialogInterface.OnClickListener {
         @Override
         public void onClick(DialogInterface dialog, int which) {
-            final ListView lv = ((AlertDialog)dialog).getListView();
-            final Object selectedItem = lv.getItemAtPosition(lv.getCheckedItemPosition());
-            getSharedPreferences()
-                    .edit()
-                    .putString(Settings.PREF_ACCOUNT_NAME, (String) selectedItem)
-                    .apply();
+            switch (which) {
+                case DialogInterface.BUTTON_POSITIVE: // Signed in
+                    final ListView lv = ((AlertDialog)dialog).getListView();
+                    final Object selectedItem = lv.getItemAtPosition(lv.getCheckedItemPosition());
+                    getSharedPreferences()
+                            .edit()
+                            .putString(PREF_ACCOUNT_NAME, (String) selectedItem)
+                            .apply();
+                    // Attempt starting sync for the new account if sync was
+                    // previously enabled.
+                    // If not, stop it.
+                    updateSyncPolicy(isSyncEnabled(), getSignedInAccountName());
+                    break;
+                case DialogInterface.BUTTON_NEUTRAL: // Signed out
+                    // Stop sync for the account that's being signed out of.
+                    updateSyncPolicy(false, getSignedInAccountName());
+                    getSharedPreferences()
+                            .edit()
+                            .remove(PREF_ACCOUNT_NAME)
+                            .apply();
+                    break;
+            }
         }
     }
 
     /**
-     * Listener for sign-out being initiated from from the picker.
-     * Removed the account from shared preferences.
-     */
-    class AccountSignedOutListener implements DialogInterface.OnClickListener {
-        @Override
-        public void onClick(DialogInterface dialog, int which) {
-            getSharedPreferences()
-                    .edit()
-                    .remove(Settings.PREF_ACCOUNT_NAME)
-                    .apply();
-        }
-    }
-
-    /**
-     * Listener that initates the process of sync in the background.
+     * Listener that initiates the process of sync in the background.
      */
     class SyncNowListener implements Preference.OnPreferenceClickListener {
         @Override
         public boolean onPreferenceClick(final Preference preference) {
-            BeanstalkManager.getInstance(getActivity() /* context */).requestSync();
+            ContentResolver.requestSync(
+                    new Account(getSignedInAccountName(), LoginAccountUtils.ACCOUNT_TYPE),
+                    AUTHORITY, Bundle.EMPTY);
             return true;
         }
     }
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
index 091ca43..df0378e 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
@@ -16,29 +16,37 @@
 
 package com.android.inputmethod.latin.settings;
 
+/**
+ * Debug settings for the application.
+ *
+ * Note: Even though these settings are stored in the default shared preferences file,
+ * they shouldn't be restored across devices.
+ * If a new key is added here, it should also be blacklisted for restore in
+ * {@link LocalSettingsConstants}.
+ */
 public final class DebugSettings {
     public static final String PREF_DEBUG_MODE = "debug_mode";
     public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch";
     public static final String PREF_FORCE_PHYSICAL_KEYBOARD_SPECIAL_KEY =
             "force_physical_keyboard_special_key";
-    public static final String PREF_SHOULD_SHOW_LXX_SUGGESTION_UI =
-            "pref_should_show_lxx_suggestion_ui";
     public static final String PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS =
             "pref_has_custom_key_preview_animation_params";
-    public static final String PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE =
-            "pref_key_preview_show_up_start_x_scale";
-    public static final String PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE =
-            "pref_key_preview_show_up_start_y_scale";
+    public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout";
+    public static final String PREF_KEY_PREVIEW_DISMISS_DURATION =
+            "pref_key_preview_dismiss_duration";
     public static final String PREF_KEY_PREVIEW_DISMISS_END_X_SCALE =
             "pref_key_preview_dismiss_end_x_scale";
     public static final String PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE =
             "pref_key_preview_dismiss_end_y_scale";
     public static final String PREF_KEY_PREVIEW_SHOW_UP_DURATION =
             "pref_key_preview_show_up_duration";
-    public static final String PREF_KEY_PREVIEW_DISMISS_DURATION =
-            "pref_key_preview_dismiss_duration";
+    public static final String PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE =
+            "pref_key_preview_show_up_start_x_scale";
+    public static final String PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE =
+            "pref_key_preview_show_up_start_y_scale";
+    public static final String PREF_SHOULD_SHOW_LXX_SUGGESTION_UI =
+            "pref_should_show_lxx_suggestion_ui";
     public static final String PREF_SLIDING_KEY_INPUT_PREVIEW = "pref_sliding_key_input_preview";
-    public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout";
 
     private DebugSettings() {
         // This class is not publicly instantiable.
diff --git a/java/src/com/android/inputmethod/latin/settings/LocalSettingsConstants.java b/java/src/com/android/inputmethod/latin/settings/LocalSettingsConstants.java
new file mode 100644
index 0000000..c171104
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/settings/LocalSettingsConstants.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 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.latin.settings;
+
+/**
+ * Collection of device specific preference constants.
+ */
+public class LocalSettingsConstants {
+    // Preference file for storing preferences that are tied to a device
+    // and are not backed up.
+    public static final String PREFS_FILE = "local_prefs";
+
+    // Preference key for the current account.
+    // Do not restore.
+    public static final String PREF_ACCOUNT_NAME = "pref_account_name";
+    // Preference key for enabling cloud sync feature.
+    // Do not restore.
+    public static final String PREF_ENABLE_CLOUD_SYNC = "pref_enable_cloud_sync";
+
+    // List of preference keys to skip from being restored by backup agent.
+    // These preferences are tied to a device and hence should not be restored.
+    // e.g. account name.
+    // Ideally they could have been kept in a separate file that wasn't backed up
+    // however the preference UI currently only deals with the default
+    // shared preferences which makes it non-trivial to move these out to
+    // a different shared preferences file.
+    public static final String[] PREFS_TO_SKIP_RESTORING = new String[] {
+        PREF_ACCOUNT_NAME,
+        PREF_ENABLE_CLOUD_SYNC,
+        // The debug settings are not restored on a new device.
+        // If a feature relies on these, it should ensure that the defaults are
+        // correctly set for it to work on a new device.
+        DebugSettings.PREF_DEBUG_MODE,
+        DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH,
+        DebugSettings.PREF_FORCE_PHYSICAL_KEYBOARD_SPECIAL_KEY,
+        DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS,
+        DebugSettings.PREF_KEY_LONGPRESS_TIMEOUT,
+        DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION,
+        DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_X_SCALE,
+        DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE,
+        DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION,
+        DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE,
+        DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE,
+        DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI,
+        DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW
+    };
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/NativeSuggestOptions.java b/java/src/com/android/inputmethod/latin/settings/NativeSuggestOptions.java
index 31a20c4..7603dbb 100644
--- a/java/src/com/android/inputmethod/latin/settings/NativeSuggestOptions.java
+++ b/java/src/com/android/inputmethod/latin/settings/NativeSuggestOptions.java
@@ -22,7 +22,8 @@
     private static final int USE_FULL_EDIT_DISTANCE = 1;
     private static final int BLOCK_OFFENSIVE_WORDS = 2;
     private static final int SPACE_AWARE_GESTURE_ENABLED = 3;
-    private static final int OPTIONS_SIZE = 4;
+    private static final int WEIGHT_FOR_LOCALE_IN_THOUSANDS = 4;
+    private static final int OPTIONS_SIZE = 5;
 
     private final int[] mOptions = new int[OPTIONS_SIZE
             + AdditionalFeaturesSettingUtils.ADDITIONAL_FEATURES_SETTINGS_SIZE];
@@ -43,6 +44,12 @@
         setBooleanOption(SPACE_AWARE_GESTURE_ENABLED, value);
     }
 
+    public void setWeightForLocale(final float value) {
+        // We're passing this option as a fixed point value, in thousands. This is decoded in
+        // native code by SuggestOptions#weightForLocale().
+        setIntegerOption(WEIGHT_FOR_LOCALE_IN_THOUSANDS, (int) (value * 1000));
+    }
+
     public void setAdditionalFeaturesOptions(final int[] additionalOptions) {
         if (additionalOptions == null) {
             return;
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 84596b4..103033c 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -106,8 +106,6 @@
     public static final String PREF_KEY_IS_INTERNAL = "pref_key_is_internal";
 
     public static final String PREF_ENABLE_METRICS_LOGGING = "pref_enable_metrics_logging";
-    public static final String PREF_ACCOUNT_NAME = "pref_account_name";
-
     // This preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead.
     // This is being used only for the backward compatibility.
     private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY =
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index ce8a0ab..660b4e0 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -64,7 +64,6 @@
     public final boolean mSoundOn;
     public final boolean mKeyPreviewPopupOn;
     public final boolean mShowsVoiceInputKey;
-    public final String mAccountName;
     public final boolean mIncludesOtherImesInLanguageSwitchList;
     public final boolean mShowsLanguageSwitchKey;
     public final boolean mUseContactsDict;
@@ -141,7 +140,6 @@
         mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs, res)
                 && mInputAttributes.mShouldShowVoiceInputKey
                 && SubtypeSwitcher.getInstance().isShortcutImeEnabled();
-        mAccountName = prefs.getString(Settings.PREF_ACCOUNT_NAME, null);
         final String autoCorrectionThresholdRawValue = prefs.getString(
                 Settings.PREF_AUTO_CORRECTION_THRESHOLD,
                 res.getString(R.string.auto_correction_threshold_mode_index_modest));
@@ -385,8 +383,6 @@
         sb.append("" + mKeyPreviewPopupOn);
         sb.append("\n   mShowsVoiceInputKey = ");
         sb.append("" + mShowsVoiceInputKey);
-        sb.append("\n   mAccountName = ");
-        sb.append("" + mAccountName);
         sb.append("\n   mIncludesOtherImesInLanguageSwitchList = ");
         sb.append("" + mIncludesOtherImesInLanguageSwitchList);
         sb.append("\n   mShowsLanguageSwitchKey = ");
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
index 2b3c14f..7b66bbb 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
@@ -541,12 +541,12 @@
         return countInStrip;
     }
 
-    public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) {
-        final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance().getCurrent()
-                .mShouldShowLxxSuggestionUi;
+    public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip,
+            final boolean shouldShowWordToSave) {
+        final boolean showsHintWithWord = shouldShowWordToSave
+                || !Settings.getInstance().getCurrent().mShouldShowLxxSuggestionUi;
         final int stripWidth = addToDictionaryStrip.getWidth();
-        final int width = shouldShowUiToAcceptTypedWord ? stripWidth
-                : stripWidth - mDividerWidth - mPadding * 2;
+        final int width = stripWidth - (showsHintWithWord ? mDividerWidth + mPadding * 2 : 0);
 
         final TextView wordView = (TextView)addToDictionaryStrip.findViewById(R.id.word_to_save);
         wordView.setTextColor(mColorTypedWord);
@@ -557,7 +557,7 @@
         wordView.setText(wordToSave);
         wordView.setTextScaleX(wordScaleX);
         setLayoutWeight(wordView, mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
-        final int wordVisibility = shouldShowUiToAcceptTypedWord ? View.GONE : View.VISIBLE;
+        final int wordVisibility = showsHintWithWord ? View.VISIBLE : View.GONE;
         wordView.setVisibility(wordVisibility);
         addToDictionaryStrip.findViewById(R.id.word_to_save_divider).setVisibility(wordVisibility);
 
@@ -567,12 +567,7 @@
         final float hintWeight;
         final TextView hintView = (TextView)addToDictionaryStrip.findViewById(
                 R.id.hint_add_to_dictionary);
-        if (shouldShowUiToAcceptTypedWord) {
-            hintText = res.getText(R.string.hint_add_to_dictionary_without_word);
-            hintWidth = width;
-            hintWeight = 1.0f;
-            hintView.setGravity(Gravity.CENTER);
-        } else {
+        if (showsHintWithWord) {
             final boolean isRtlLanguage = (ViewCompat.getLayoutDirection(addToDictionaryStrip)
                     == ViewCompat.LAYOUT_DIRECTION_RTL);
             final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW;
@@ -583,6 +578,11 @@
             hintWidth = width - wordWidth;
             hintWeight = 1.0f - mCenterSuggestionWeight;
             hintView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
+        } else {
+            hintText = res.getText(R.string.hint_add_to_dictionary_without_word);
+            hintWidth = width;
+            hintWeight = 1.0f;
+            hintView.setGravity(Gravity.CENTER);
         }
         hintView.setTextColor(mColorAutoCorrect);
         final float hintScaleX = getTextScaleX(hintText, hintWidth, hintView.getPaint());
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
index e40fd88..789d549 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -231,8 +231,8 @@
         return mStripVisibilityGroup.isShowingAddToDictionaryStrip();
     }
 
-    public void showAddToDictionaryHint(final String word) {
-        mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip);
+    public void showAddToDictionaryHint(final String word, final boolean shouldShowWordToSave) {
+        mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip, shouldShowWordToSave);
         // {@link TextView#setTag()} is used to hold the word to be added to dictionary. The word
         // will be extracted at {@link #onClick(View)}.
         mAddToDictionaryStrip.setTag(word);
@@ -501,7 +501,7 @@
             return;
         }
         final Object tag = view.getTag();
-        // {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}.
+        // {@link String} tag is set at {@link #suggestAddingToDictionary(String,CharSequence)}.
         if (tag instanceof String) {
             final String wordToSave = (String)tag;
             mListener.addWordToUserDictionary(wordToSave);
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java
index 5270845..5c86a02 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java
@@ -22,7 +22,7 @@
  * An object that gives basic control of a suggestion strip and some info on it.
  */
 public interface SuggestionStripViewAccessor {
-    public void showAddToDictionaryHint(final String word);
+    public void suggestAddingToDictionary(final String word, final boolean isFromSuggestionStrip);
     public boolean isShowingAddToDictionaryHint();
     public void dismissAddToDictionaryHint();
     public void setNeutralSuggestionStrip();
diff --git a/java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java
index 9dc0524..e056189 100644
--- a/java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java
@@ -16,10 +16,12 @@
 
 package com.android.inputmethod.latin.utils;
 
+import android.annotation.TargetApi;
 import android.graphics.Matrix;
 import android.graphics.Rect;
 import android.inputmethodservice.ExtractEditText;
 import android.inputmethodservice.InputMethodService;
+import android.os.Build;
 import android.text.Layout;
 import android.text.Spannable;
 import android.view.View;
@@ -27,6 +29,12 @@
 import android.view.inputmethod.CursorAnchorInfo;
 import android.widget.TextView;
 
+import com.android.inputmethod.compat.BuildCompatUtils;
+import com.android.inputmethod.compat.CursorAnchorInfoCompatWrapper;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 /**
  * This class allows input methods to extract {@link CursorAnchorInfo} directly from the given
  * {@link TextView}. This is useful and even necessary to support full-screen mode where the default
@@ -77,13 +85,32 @@
     }
 
     /**
+     * Extracts {@link CursorAnchorInfoCompatWrapper} from the given {@link TextView}.
+     * @param textView the target text view from which {@link CursorAnchorInfoCompatWrapper} is to
+     * be extracted.
+     * @return the {@link CursorAnchorInfoCompatWrapper} object based on the current layout.
+     * {@code null} if {@code Build.VERSION.SDK_INT} is 20 or prior or {@link TextView} is not
+     * ready to provide layout information.
+     */
+    @Nullable
+    public static CursorAnchorInfoCompatWrapper extractFromTextView(
+            @Nonnull final TextView textView) {
+        if (Build.VERSION.SDK_INT < BuildCompatUtils.VERSION_CODES_LXX) {
+            return null;
+        }
+        return CursorAnchorInfoCompatWrapper.wrap(extractFromTextViewInternal(textView));
+    }
+
+    /**
      * Returns {@link CursorAnchorInfo} from the given {@link TextView}.
      * @param textView the target text view from which {@link CursorAnchorInfo} is to be extracted.
      * @return the {@link CursorAnchorInfo} object based on the current layout. {@code null} if it
      * is not feasible.
      */
-    public static CursorAnchorInfo getCursorAnchorInfo(final TextView textView) {
-        Layout layout = textView.getLayout();
+    @TargetApi(BuildCompatUtils.VERSION_CODES_LXX)
+    @Nullable
+    private static CursorAnchorInfo extractFromTextViewInternal(@Nonnull final TextView textView) {
+        final Layout layout = textView.getLayout();
         if (layout == null) {
             return null;
         }
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index 76c7fdd..f8dadb4 100644
--- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -28,7 +28,7 @@
 #include "suggest/core/dictionary/property/unigram_property.h"
 #include "suggest/core/dictionary/property/word_property.h"
 #include "suggest/core/result/suggestion_results.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 #include "suggest/core/suggest_options.h"
 #include "suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h"
 #include "utils/char_utils.h"
@@ -242,15 +242,15 @@
     env->GetFloatArrayRegion(inOutWeightOfLangModelVsSpatialModel, 0, 1 /* len */,
             &weightOfLangModelVsSpatialModel);
     SuggestionResults suggestionResults(MAX_RESULTS);
-    const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
+    const NgramContext ngramContext = JniDataUtils::constructNgramContext(env,
             prevWordCodePointArrays, isBeginningOfSentenceArray, prevWordCount);
     if (givenSuggestOptions.isGesture() || inputSize > 0) {
         // TODO: Use SuggestionResults to return suggestions.
         dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
-                times, pointerIds, inputCodePoints, inputSize, &prevWordsInfo,
+                times, pointerIds, inputCodePoints, inputSize, &ngramContext,
                 &givenSuggestOptions, weightOfLangModelVsSpatialModel, &suggestionResults);
     } else {
-        dictionary->getPredictions(&prevWordsInfo, &suggestionResults);
+        dictionary->getPredictions(&ngramContext, &suggestionResults);
     }
     if (DEBUG_DICT) {
         suggestionResults.dumpSuggestions();
@@ -289,10 +289,10 @@
     const jsize wordLength = env->GetArrayLength(word);
     int wordCodePoints[wordLength];
     env->GetIntArrayRegion(word, 0, wordLength, wordCodePoints);
-    const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
+    const NgramContext ngramContext = JniDataUtils::constructNgramContext(env,
             prevWordCodePointArrays, isBeginningOfSentenceArray,
             env->GetArrayLength(prevWordCodePointArrays));
-    return dictionary->getNgramProbability(&prevWordsInfo,
+    return dictionary->getNgramProbability(&ngramContext,
             CodePointArrayView(wordCodePoints, wordLength));
 }
 
@@ -327,8 +327,9 @@
 
 static void latinime_BinaryDictionary_getWordProperty(JNIEnv *env, jclass clazz,
         jlong dict, jintArray word, jboolean isBeginningOfSentence, jintArray outCodePoints,
-        jbooleanArray outFlags, jintArray outProbabilityInfo, jobject outBigramTargets,
-        jobject outBigramProbabilityInfo, jobject outShortcutTargets,
+        jbooleanArray outFlags, jintArray outProbabilityInfo, jobject /* outNgramPrevWordsArray */,
+        jobject /* outNgramPrevWordIsBeginningOfSentenceArray */, jobject outNgramTargets,
+        jobject outNgramProbabilityInfo, jobject outShortcutTargets,
         jobject outShortcutProbabilities) {
     Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
     if (!dictionary) return;
@@ -351,7 +352,7 @@
     const WordProperty wordProperty = dictionary->getWordProperty(
             CodePointArrayView(wordCodePoints, codePointCount));
     wordProperty.outputProperties(env, outCodePoints, outFlags, outProbabilityInfo,
-            outBigramTargets, outBigramProbabilityInfo, outShortcutTargets,
+            outNgramTargets, outNgramProbabilityInfo, outShortcutTargets,
             outShortcutProbabilities);
 }
 
@@ -401,7 +402,7 @@
     if (!dictionary) {
         return false;
     }
-    const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
+    const NgramContext ngramContext = JniDataUtils::constructNgramContext(env,
             prevWordCodePointArrays, isBeginningOfSentenceArray,
             env->GetArrayLength(prevWordCodePointArrays));
     jsize wordLength = env->GetArrayLength(word);
@@ -410,7 +411,7 @@
     // Use 1 for count to indicate the ngram has inputted.
     const NgramProperty ngramProperty(CodePointArrayView(wordCodePoints, wordLength).toVector(),
             probability, HistoricalInfo(timestamp, 0 /* level */, 1 /* count */));
-    return dictionary->addNgramEntry(&prevWordsInfo, &ngramProperty);
+    return dictionary->addNgramEntry(&ngramContext, &ngramProperty);
 }
 
 static bool latinime_BinaryDictionary_removeNgramEntry(JNIEnv *env, jclass clazz, jlong dict,
@@ -420,31 +421,32 @@
     if (!dictionary) {
         return false;
     }
-    const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
+    const NgramContext ngramContext = JniDataUtils::constructNgramContext(env,
             prevWordCodePointArrays, isBeginningOfSentenceArray,
             env->GetArrayLength(prevWordCodePointArrays));
     jsize codePointCount = env->GetArrayLength(word);
     int wordCodePoints[codePointCount];
     env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints);
-    return dictionary->removeNgramEntry(&prevWordsInfo,
+    return dictionary->removeNgramEntry(&ngramContext,
             CodePointArrayView(wordCodePoints, codePointCount));
 }
 
-static bool latinime_BinaryDictionary_updateCounter(JNIEnv *env, jclass clazz, jlong dict,
-        jobjectArray prevWordCodePointArrays, jbooleanArray isBeginningOfSentenceArray,
-        jintArray word, jboolean isValidWord, jint count, jint timestamp) {
+static bool latinime_BinaryDictionary_updateEntriesForWordWithNgramContext(JNIEnv *env,
+        jclass clazz, jlong dict, jobjectArray prevWordCodePointArrays,
+        jbooleanArray isBeginningOfSentenceArray, jintArray word, jboolean isValidWord, jint count,
+        jint timestamp) {
     Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
     if (!dictionary) {
         return false;
     }
-    const PrevWordsInfo prevWordsInfo = JniDataUtils::constructPrevWordsInfo(env,
+    const NgramContext ngramContext = JniDataUtils::constructNgramContext(env,
             prevWordCodePointArrays, isBeginningOfSentenceArray,
             env->GetArrayLength(prevWordCodePointArrays));
     jsize codePointCount = env->GetArrayLength(word);
     int wordCodePoints[codePointCount];
     env->GetIntArrayRegion(word, 0, codePointCount, wordCodePoints);
     const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count);
-    return dictionary->updateCounter(&prevWordsInfo,
+    return dictionary->updateEntriesForWordWithNgramContext(&ngramContext,
             CodePointArrayView(wordCodePoints, codePointCount), isValidWord == JNI_TRUE,
             historicalInfo);
 }
@@ -527,9 +529,9 @@
             const NgramProperty ngramProperty(
                     CodePointArrayView(word1CodePoints, word1Length).toVector(),
                     bigramProbability, HistoricalInfo(timestamp, 0 /* level */, 1 /* count */));
-            const PrevWordsInfo prevWordsInfo(word0CodePoints, word0Length,
+            const NgramContext ngramContext(word0CodePoints, word0Length,
                     false /* isBeginningOfSentence */);
-            dictionary->addNgramEntry(&prevWordsInfo, &ngramProperty);
+            dictionary->addNgramEntry(&ngramContext, &ngramProperty);
         }
         if (dictionary->needsToRunGC(true /* mindsBlockByGC */)) {
             return i + 1;
@@ -639,10 +641,10 @@
                 return false;
             }
         }
-        const PrevWordsInfo prevWordsInfo(wordCodePoints, wordCodePointCount,
+        const NgramContext ngramContext(wordCodePoints, wordCodePointCount,
                 wordProperty.getUnigramProperty()->representsBeginningOfSentence());
         for (const NgramProperty &ngramProperty : *wordProperty.getNgramProperties()) {
-            if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&prevWordsInfo,
+            if (!dictionaryStructureWithBufferPolicy->addNgramEntry(&ngramContext,
                     &ngramProperty)) {
                 LogUtils::logToJava(env, "Cannot add ngram to the new dict.");
                 return false;
@@ -718,7 +720,8 @@
     {
         const_cast<char *>("getWordPropertyNative"),
         const_cast<char *>("(J[IZ[I[Z[ILjava/util/ArrayList;Ljava/util/ArrayList;"
-                "Ljava/util/ArrayList;Ljava/util/ArrayList;)V"),
+                "Ljava/util/ArrayList;Ljava/util/ArrayList;Ljava/util/ArrayList;"
+                "Ljava/util/ArrayList;)V"),
         reinterpret_cast<void *>(latinime_BinaryDictionary_getWordProperty)
     },
     {
@@ -747,9 +750,9 @@
         reinterpret_cast<void *>(latinime_BinaryDictionary_removeNgramEntry)
     },
     {
-        const_cast<char *>("updateCounterNative"),
+        const_cast<char *>("updateEntriesForWordWithNgramContextNative"),
         const_cast<char *>("(J[[I[Z[IZII)Z"),
-        reinterpret_cast<void *>(latinime_BinaryDictionary_updateCounter)
+        reinterpret_cast<void *>(latinime_BinaryDictionary_updateEntriesForWordWithNgramContext)
     },
     {
         const_cast<char *>("addMultipleDictionaryEntriesNative"),
diff --git a/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp b/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp
index 7660641..3c6bff3 100644
--- a/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp
+++ b/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp
@@ -22,7 +22,7 @@
 #include "jni.h"
 #include "jni_common.h"
 #include "suggest/core/session/dic_traverse_session.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 
 namespace latinime {
 class Dictionary;
@@ -40,14 +40,14 @@
     }
     Dictionary *dict = reinterpret_cast<Dictionary *>(dictionary);
     if (!previousWord) {
-        PrevWordsInfo prevWordsInfo;
-        ts->init(dict, &prevWordsInfo, 0 /* suggestOptions */);
+        NgramContext emptyNgramContext;
+        ts->init(dict, &emptyNgramContext, 0 /* suggestOptions */);
         return;
     }
     int prevWord[previousWordLength];
     env->GetIntArrayRegion(previousWord, 0, previousWordLength, prevWord);
-    PrevWordsInfo prevWordsInfo(prevWord, previousWordLength, false /* isStartOfSentence */);
-    ts->init(dict, &prevWordsInfo, 0 /* suggestOptions */);
+    NgramContext ngramContext(prevWord, previousWordLength, false /* isStartOfSentence */);
+    ts->init(dict, &ngramContext, 0 /* suggestOptions */);
 }
 
 static void latinime_releaseDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession) {
diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp
index 7a69d3c..697e99f 100644
--- a/native/jni/src/suggest/core/dictionary/dictionary.cpp
+++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp
@@ -23,7 +23,7 @@
 #include "suggest/core/policy/dictionary_header_structure_policy.h"
 #include "suggest/core/result/suggestion_results.h"
 #include "suggest/core/session/dic_traverse_session.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 #include "suggest/core/suggest.h"
 #include "suggest/core/suggest_options.h"
 #include "suggest/policyimpl/gesture/gesture_suggest_policy_factory.h"
@@ -46,11 +46,11 @@
 
 void Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
         int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
-        int inputSize, const PrevWordsInfo *const prevWordsInfo,
+        int inputSize, const NgramContext *const ngramContext,
         const SuggestOptions *const suggestOptions, const float weightOfLangModelVsSpatialModel,
         SuggestionResults *const outSuggestionResults) const {
     TimeKeeper::setCurrentTime();
-    traverseSession->init(this, prevWordsInfo, suggestOptions);
+    traverseSession->init(this, ngramContext, suggestOptions);
     const auto &suggest = suggestOptions->isGesture() ? mGestureSuggest : mTypingSuggest;
     suggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
             ycoordinates, times, pointerIds, inputCodePoints, inputSize,
@@ -58,10 +58,10 @@
 }
 
 Dictionary::NgramListenerForPrediction::NgramListenerForPrediction(
-        const PrevWordsInfo *const prevWordsInfo, const WordIdArrayView prevWordIds,
+        const NgramContext *const ngramContext, const WordIdArrayView prevWordIds,
         SuggestionResults *const suggestionResults,
         const DictionaryStructureWithBufferPolicy *const dictStructurePolicy)
-    : mPrevWordsInfo(prevWordsInfo), mPrevWordIds(prevWordIds),
+    : mNgramContext(ngramContext), mPrevWordIds(prevWordIds),
       mSuggestionResults(suggestionResults), mDictStructurePolicy(dictStructurePolicy) {}
 
 void Dictionary::NgramListenerForPrediction::onVisitEntry(const int ngramProbability,
@@ -69,7 +69,7 @@
     if (targetWordId == NOT_A_WORD_ID) {
         return;
     }
-    if (mPrevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
+    if (mNgramContext->isNthPrevWordBeginningOfSentence(1 /* n */)
             && ngramProbability == NOT_A_PROBABILITY) {
         return;
     }
@@ -85,20 +85,20 @@
             wordAttributes.getProbability());
 }
 
-void Dictionary::getPredictions(const PrevWordsInfo *const prevWordsInfo,
+void Dictionary::getPredictions(const NgramContext *const ngramContext,
         SuggestionResults *const outSuggestionResults) const {
     TimeKeeper::setCurrentTime();
     WordIdArray<MAX_PREV_WORD_COUNT_FOR_N_GRAM> prevWordIdArray;
-    const WordIdArrayView prevWordIds = prevWordsInfo->getPrevWordIds(
+    const WordIdArrayView prevWordIds = ngramContext->getPrevWordIds(
             mDictionaryStructureWithBufferPolicy.get(), &prevWordIdArray,
             true /* tryLowerCaseSearch */);
-    NgramListenerForPrediction listener(prevWordsInfo, prevWordIds, outSuggestionResults,
+    NgramListenerForPrediction listener(ngramContext, prevWordIds, outSuggestionResults,
             mDictionaryStructureWithBufferPolicy.get());
     mDictionaryStructureWithBufferPolicy->iterateNgramEntries(prevWordIds, &listener);
 }
 
 int Dictionary::getProbability(const CodePointArrayView codePoints) const {
-    return getNgramProbability(nullptr /* prevWordsInfo */, codePoints);
+    return getNgramProbability(nullptr /* ngramContext */, codePoints);
 }
 
 int Dictionary::getMaxProbabilityOfExactMatches(const CodePointArrayView codePoints) const {
@@ -107,18 +107,18 @@
             mDictionaryStructureWithBufferPolicy.get(), codePoints);
 }
 
-int Dictionary::getNgramProbability(const PrevWordsInfo *const prevWordsInfo,
+int Dictionary::getNgramProbability(const NgramContext *const ngramContext,
         const CodePointArrayView codePoints) const {
     TimeKeeper::setCurrentTime();
     const int wordId = mDictionaryStructureWithBufferPolicy->getWordId(codePoints,
             false /* forceLowerCaseSearch */);
     if (wordId == NOT_A_WORD_ID) return NOT_A_PROBABILITY;
-    if (!prevWordsInfo) {
+    if (!ngramContext) {
         return getDictionaryStructurePolicy()->getProbabilityOfWord(WordIdArrayView(), wordId);
     }
     WordIdArray<MAX_PREV_WORD_COUNT_FOR_N_GRAM> prevWordIdArray;
-    const WordIdArrayView prevWordIds = prevWordsInfo->getPrevWordIds
-            (mDictionaryStructureWithBufferPolicy.get(), &prevWordIdArray,
+    const WordIdArrayView prevWordIds = ngramContext->getPrevWordIds(
+            mDictionaryStructureWithBufferPolicy.get(), &prevWordIdArray,
             true /* tryLowerCaseSearch */);
     return getDictionaryStructurePolicy()->getProbabilityOfWord(prevWordIds, wordId);
 }
@@ -140,24 +140,24 @@
     return mDictionaryStructureWithBufferPolicy->removeUnigramEntry(codePoints);
 }
 
-bool Dictionary::addNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+bool Dictionary::addNgramEntry(const NgramContext *const ngramContext,
         const NgramProperty *const ngramProperty) {
     TimeKeeper::setCurrentTime();
-    return mDictionaryStructureWithBufferPolicy->addNgramEntry(prevWordsInfo, ngramProperty);
+    return mDictionaryStructureWithBufferPolicy->addNgramEntry(ngramContext, ngramProperty);
 }
 
-bool Dictionary::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+bool Dictionary::removeNgramEntry(const NgramContext *const ngramContext,
         const CodePointArrayView codePoints) {
     TimeKeeper::setCurrentTime();
-    return mDictionaryStructureWithBufferPolicy->removeNgramEntry(prevWordsInfo, codePoints);
+    return mDictionaryStructureWithBufferPolicy->removeNgramEntry(ngramContext, codePoints);
 }
 
-bool Dictionary::updateCounter(const PrevWordsInfo *const prevWordsInfo,
+bool Dictionary::updateEntriesForWordWithNgramContext(const NgramContext *const ngramContext,
         const CodePointArrayView codePoints, const bool isValidWord,
         const HistoricalInfo historicalInfo) {
     TimeKeeper::setCurrentTime();
-    return mDictionaryStructureWithBufferPolicy->updateCounter(prevWordsInfo, codePoints,
-            isValidWord, historicalInfo);
+    return mDictionaryStructureWithBufferPolicy->updateEntriesForWordWithNgramContext(ngramContext,
+            codePoints, isValidWord, historicalInfo);
 }
 
 bool Dictionary::flush(const char *const filePath) {
diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h
index a58dbfb..843aec4 100644
--- a/native/jni/src/suggest/core/dictionary/dictionary.h
+++ b/native/jni/src/suggest/core/dictionary/dictionary.h
@@ -33,7 +33,7 @@
 
 class DictionaryStructureWithBufferPolicy;
 class DicTraverseSession;
-class PrevWordsInfo;
+class NgramContext;
 class ProximityInfo;
 class SuggestionResults;
 class SuggestOptions;
@@ -66,18 +66,18 @@
 
     void getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
             int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
-            int inputSize, const PrevWordsInfo *const prevWordsInfo,
+            int inputSize, const NgramContext *const ngramContext,
             const SuggestOptions *const suggestOptions, const float weightOfLangModelVsSpatialModel,
             SuggestionResults *const outSuggestionResults) const;
 
-    void getPredictions(const PrevWordsInfo *const prevWordsInfo,
+    void getPredictions(const NgramContext *const ngramContext,
             SuggestionResults *const outSuggestionResults) const;
 
     int getProbability(const CodePointArrayView codePoints) const;
 
     int getMaxProbabilityOfExactMatches(const CodePointArrayView codePoints) const;
 
-    int getNgramProbability(const PrevWordsInfo *const prevWordsInfo,
+    int getNgramProbability(const NgramContext *const ngramContext,
             const CodePointArrayView codePoints) const;
 
     bool addUnigramEntry(const CodePointArrayView codePoints,
@@ -85,13 +85,13 @@
 
     bool removeUnigramEntry(const CodePointArrayView codePoints);
 
-    bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    bool addNgramEntry(const NgramContext *const ngramContext,
             const NgramProperty *const ngramProperty);
 
-    bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    bool removeNgramEntry(const NgramContext *const ngramContext,
             const CodePointArrayView codePoints);
 
-    bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
+    bool updateEntriesForWordWithNgramContext(const NgramContext *const ngramContext,
             const CodePointArrayView codePoints, const bool isValidWord,
             const HistoricalInfo historicalInfo);
 
@@ -123,7 +123,7 @@
 
     class NgramListenerForPrediction : public NgramListener {
      public:
-        NgramListenerForPrediction(const PrevWordsInfo *const prevWordsInfo,
+        NgramListenerForPrediction(const NgramContext *const ngramContext,
                 const WordIdArrayView prevWordIds, SuggestionResults *const suggestionResults,
                 const DictionaryStructureWithBufferPolicy *const dictStructurePolicy);
         virtual void onVisitEntry(const int ngramProbability, const int targetWordId);
@@ -131,7 +131,7 @@
      private:
         DISALLOW_IMPLICIT_CONSTRUCTORS(NgramListenerForPrediction);
 
-        const PrevWordsInfo *const mPrevWordsInfo;
+        const NgramContext *const mNgramContext;
         const WordIdArrayView mPrevWordIds;
         SuggestionResults *const mSuggestionResults;
         const DictionaryStructureWithBufferPolicy *const mDictStructurePolicy;
diff --git a/native/jni/src/suggest/core/dictionary/dictionary_utils.cpp b/native/jni/src/suggest/core/dictionary/dictionary_utils.cpp
index b85f362..9573c37 100644
--- a/native/jni/src/suggest/core/dictionary/dictionary_utils.cpp
+++ b/native/jni/src/suggest/core/dictionary/dictionary_utils.cpp
@@ -21,7 +21,7 @@
 #include "suggest/core/dicnode/dic_node_vector.h"
 #include "suggest/core/dictionary/dictionary.h"
 #include "suggest/core/dictionary/digraph_utils.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 #include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
 #include "utils/int_array_view.h"
 
@@ -33,10 +33,10 @@
     std::vector<DicNode> current;
     std::vector<DicNode> next;
 
-    // No prev words information.
-    PrevWordsInfo emptyPrevWordsInfo;
+    // No ngram context.
+    NgramContext emptyNgramContext;
     WordIdArray<MAX_PREV_WORD_COUNT_FOR_N_GRAM> prevWordIdArray;
-    const WordIdArrayView prevWordIds = emptyPrevWordsInfo.getPrevWordIds(
+    const WordIdArrayView prevWordIds = emptyNgramContext.getPrevWordIds(
             dictionaryStructurePolicy, &prevWordIdArray, false /* tryLowerCaseSearch */);
     current.emplace_back();
     DicNodeUtils::initAsRoot(dictionaryStructurePolicy, prevWordIds, &current.front());
diff --git a/native/jni/src/suggest/core/dictionary/property/historical_info.h b/native/jni/src/suggest/core/dictionary/property/historical_info.h
index 5ed9ebf..f9bd6fd 100644
--- a/native/jni/src/suggest/core/dictionary/property/historical_info.h
+++ b/native/jni/src/suggest/core/dictionary/property/historical_info.h
@@ -47,12 +47,12 @@
     }
 
  private:
-    // Default copy constructor and assign operator are used for using in std::vector.
+    // Default copy constructor is used for using in std::vector.
+    DISALLOW_ASSIGNMENT_OPERATOR(HistoricalInfo);
 
-    // TODO: Make members const.
-    int mTimestamp;
-    int mLevel;
-    int mCount;
+    const int mTimestamp;
+    const int mLevel;
+    const int mCount;
 };
 } // namespace latinime
 #endif /* LATINIME_HISTORICAL_INFO_H */
diff --git a/native/jni/src/suggest/core/dictionary/property/ngram_property.h b/native/jni/src/suggest/core/dictionary/property/ngram_property.h
index dce4600..8709799 100644
--- a/native/jni/src/suggest/core/dictionary/property/ngram_property.h
+++ b/native/jni/src/suggest/core/dictionary/property/ngram_property.h
@@ -44,13 +44,13 @@
     }
 
  private:
-    // Default copy constructor and assign operator are used for using in std::vector.
+    // Default copy constructor is used for using in std::vector.
     DISALLOW_DEFAULT_CONSTRUCTOR(NgramProperty);
+    DISALLOW_ASSIGNMENT_OPERATOR(NgramProperty);
 
-    // TODO: Make members const.
-    std::vector<int> mTargetCodePoints;
-    int mProbability;
-    HistoricalInfo mHistoricalInfo;
+    const std::vector<int> mTargetCodePoints;
+    const int mProbability;
+    const HistoricalInfo mHistoricalInfo;
 };
 } // namespace latinime
 #endif // LATINIME_NGRAM_PROPERTY_H
diff --git a/native/jni/src/suggest/core/dictionary/property/unigram_property.h b/native/jni/src/suggest/core/dictionary/property/unigram_property.h
index d1f0ab4..5ed2e26 100644
--- a/native/jni/src/suggest/core/dictionary/property/unigram_property.h
+++ b/native/jni/src/suggest/core/dictionary/property/unigram_property.h
@@ -41,12 +41,11 @@
         }
 
      private:
-        // Default copy constructor and assign operator are used for using in std::vector.
+        // Default copy constructor is used for using in std::vector.
         DISALLOW_DEFAULT_CONSTRUCTOR(ShortcutProperty);
 
-        // TODO: Make members const.
-        std::vector<int> mTargetCodePoints;
-        int mProbability;
+        const std::vector<int> mTargetCodePoints;
+        const int mProbability;
     };
 
     UnigramProperty()
@@ -104,13 +103,12 @@
     // Default copy constructor is used for using as a return value.
     DISALLOW_ASSIGNMENT_OPERATOR(UnigramProperty);
 
-    // TODO: Make members const.
-    bool mRepresentsBeginningOfSentence;
-    bool mIsNotAWord;
-    bool mIsBlacklisted;
-    int mProbability;
-    HistoricalInfo mHistoricalInfo;
-    std::vector<ShortcutProperty> mShortcuts;
+    const bool mRepresentsBeginningOfSentence;
+    const bool mIsNotAWord;
+    const bool mIsBlacklisted;
+    const int mProbability;
+    const HistoricalInfo mHistoricalInfo;
+    const std::vector<ShortcutProperty> mShortcuts;
 };
 } // namespace latinime
 #endif // LATINIME_UNIGRAM_PROPERTY_H
diff --git a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h
index 6624b79..ceda5c0 100644
--- a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h
+++ b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h
@@ -33,7 +33,7 @@
 class DictionaryHeaderStructurePolicy;
 class MultiBigramMap;
 class NgramListener;
-class PrevWordsInfo;
+class NgramContext;
 class UnigramProperty;
 
 /*
@@ -81,15 +81,15 @@
     virtual bool removeUnigramEntry(const CodePointArrayView wordCodePoints) = 0;
 
     // Returns whether the update was success or not.
-    virtual bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    virtual bool addNgramEntry(const NgramContext *const ngramContext,
             const NgramProperty *const ngramProperty) = 0;
 
     // Returns whether the update was success or not.
-    virtual bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    virtual bool removeNgramEntry(const NgramContext *const ngramContext,
             const CodePointArrayView wordCodePoints) = 0;
 
     // Returns whether the update was success or not.
-    virtual bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
+    virtual bool updateEntriesForWordWithNgramContext(const NgramContext *const ngramContext,
             const CodePointArrayView wordCodePoints, const bool isValidWord,
             const HistoricalInfo historicalInfo) = 0;
 
diff --git a/native/jni/src/suggest/core/policy/traversal.h b/native/jni/src/suggest/core/policy/traversal.h
index 6dfa7e3..5b6616d 100644
--- a/native/jni/src/suggest/core/policy/traversal.h
+++ b/native/jni/src/suggest/core/policy/traversal.h
@@ -44,7 +44,7 @@
     virtual bool needsToTraverseAllUserInput() const = 0;
     virtual float getMaxSpatialDistance() const = 0;
     virtual int getDefaultExpandDicNodeSize() const = 0;
-    virtual int getMaxCacheSize(const int inputSize) const = 0;
+    virtual int getMaxCacheSize(const int inputSize, const float weightForLocale) const = 0;
     virtual int getTerminalCacheSize() const = 0;
     virtual bool isPossibleOmissionChildNode(const DicTraverseSession *const traverseSession,
             const DicNode *const parentDicNode, const DicNode *const dicNode) const = 0;
diff --git a/native/jni/src/suggest/core/session/dic_traverse_session.cpp b/native/jni/src/suggest/core/session/dic_traverse_session.cpp
index b4d01d0..52dc2f8 100644
--- a/native/jni/src/suggest/core/session/dic_traverse_session.cpp
+++ b/native/jni/src/suggest/core/session/dic_traverse_session.cpp
@@ -20,7 +20,7 @@
 #include "suggest/core/dictionary/dictionary.h"
 #include "suggest/core/policy/dictionary_header_structure_policy.h"
 #include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 
 namespace latinime {
 
@@ -30,12 +30,12 @@
         256 * 1024;
 
 void DicTraverseSession::init(const Dictionary *const dictionary,
-        const PrevWordsInfo *const prevWordsInfo, const SuggestOptions *const suggestOptions) {
+        const NgramContext *const ngramContext, const SuggestOptions *const suggestOptions) {
     mDictionary = dictionary;
     mMultiWordCostMultiplier = getDictionaryStructurePolicy()->getHeaderStructurePolicy()
             ->getMultiWordCostMultiplier();
     mSuggestOptions = suggestOptions;
-    mPrevWordIdCount = prevWordsInfo->getPrevWordIds(getDictionaryStructurePolicy(),
+    mPrevWordIdCount = ngramContext->getPrevWordIds(getDictionaryStructurePolicy(),
             &mPrevWordIdArray, true /* tryLowerCaseSearch */).size();
 }
 
diff --git a/native/jni/src/suggest/core/session/dic_traverse_session.h b/native/jni/src/suggest/core/session/dic_traverse_session.h
index 9f841aa..bc53167 100644
--- a/native/jni/src/suggest/core/session/dic_traverse_session.h
+++ b/native/jni/src/suggest/core/session/dic_traverse_session.h
@@ -30,7 +30,7 @@
 
 class Dictionary;
 class DictionaryStructureWithBufferPolicy;
-class PrevWordsInfo;
+class NgramContext;
 class ProximityInfo;
 class SuggestOptions;
 
@@ -61,7 +61,7 @@
     // Non virtual inline destructor -- never inherit this class
     AK_FORCE_INLINE ~DicTraverseSession() {}
 
-    void init(const Dictionary *dictionary, const PrevWordsInfo *const prevWordsInfo,
+    void init(const Dictionary *dictionary, const NgramContext *const ngramContext,
             const SuggestOptions *const suggestOptions);
     // TODO: Remove and merge into init
     void setupForGetSuggestions(const ProximityInfo *pInfo, const int *inputCodePoints,
diff --git a/native/jni/src/suggest/core/session/prev_words_info.h b/native/jni/src/suggest/core/session/ngram_context.h
similarity index 85%
rename from native/jni/src/suggest/core/session/prev_words_info.h
rename to native/jni/src/suggest/core/session/ngram_context.h
index 553d5ad..64c7141 100644
--- a/native/jni/src/suggest/core/session/prev_words_info.h
+++ b/native/jni/src/suggest/core/session/ngram_context.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef LATINIME_PREV_WORDS_INFO_H
-#define LATINIME_PREV_WORDS_INFO_H
+#ifndef LATINIME_NGRAM_CONTEXT_H
+#define LATINIME_NGRAM_CONTEXT_H
 
 #include <array>
 
@@ -26,25 +26,26 @@
 
 namespace latinime {
 
-class PrevWordsInfo {
+// Rename to NgramContext.
+class NgramContext {
  public:
     // No prev word information.
-    PrevWordsInfo() : mPrevWordCount(0) {
+    NgramContext() : mPrevWordCount(0) {
         clear();
     }
 
-    PrevWordsInfo(const PrevWordsInfo &prevWordsInfo)
-            : mPrevWordCount(prevWordsInfo.mPrevWordCount) {
+    NgramContext(const NgramContext &ngramContext)
+            : mPrevWordCount(ngramContext.mPrevWordCount) {
         for (size_t i = 0; i < mPrevWordCount; ++i) {
-            mPrevWordCodePointCount[i] = prevWordsInfo.mPrevWordCodePointCount[i];
-            memmove(mPrevWordCodePoints[i], prevWordsInfo.mPrevWordCodePoints[i],
+            mPrevWordCodePointCount[i] = ngramContext.mPrevWordCodePointCount[i];
+            memmove(mPrevWordCodePoints[i], ngramContext.mPrevWordCodePoints[i],
                     sizeof(mPrevWordCodePoints[i][0]) * mPrevWordCodePointCount[i]);
-            mIsBeginningOfSentence[i] = prevWordsInfo.mIsBeginningOfSentence[i];
+            mIsBeginningOfSentence[i] = ngramContext.mIsBeginningOfSentence[i];
         }
     }
 
     // Construct from previous words.
-    PrevWordsInfo(const int prevWordCodePoints[][MAX_WORD_LENGTH],
+    NgramContext(const int prevWordCodePoints[][MAX_WORD_LENGTH],
             const int *const prevWordCodePointCount, const bool *const isBeginningOfSentence,
             const size_t prevWordCount)
             : mPrevWordCount(std::min(NELEMS(mPrevWordCodePoints), prevWordCount)) {
@@ -61,7 +62,7 @@
     }
 
     // Construct from a previous word.
-    PrevWordsInfo(const int *const prevWordCodePoints, const int prevWordCodePointCount,
+    NgramContext(const int *const prevWordCodePoints, const int prevWordCodePointCount,
             const bool isBeginningOfSentence) : mPrevWordCount(1) {
         clear();
         if (prevWordCodePointCount > MAX_WORD_LENGTH || !prevWordCodePoints) {
@@ -78,8 +79,8 @@
     }
 
     // TODO: Remove.
-    const PrevWordsInfo getTrimmedPrevWordsInfo(const size_t maxPrevWordCount) const {
-        return PrevWordsInfo(mPrevWordCodePoints, mPrevWordCodePointCount, mIsBeginningOfSentence,
+    const NgramContext getTrimmedNgramContext(const size_t maxPrevWordCount) const {
+        return NgramContext(mPrevWordCodePoints, mPrevWordCodePointCount, mIsBeginningOfSentence,
                 std::min(mPrevWordCount, maxPrevWordCount));
     }
 
@@ -122,7 +123,7 @@
     }
 
  private:
-    DISALLOW_ASSIGNMENT_OPERATOR(PrevWordsInfo);
+    DISALLOW_ASSIGNMENT_OPERATOR(NgramContext);
 
     static int getWordId(const DictionaryStructureWithBufferPolicy *const dictStructurePolicy,
             const int *const wordCodePoints, const int wordCodePointCount,
@@ -165,4 +166,4 @@
     bool mIsBeginningOfSentence[MAX_PREV_WORD_COUNT_FOR_N_GRAM];
 };
 } // namespace latinime
-#endif // LATINIME_PREV_WORDS_INFO_H
+#endif // LATINIME_NGRAM_CONTEXT_H
diff --git a/native/jni/src/suggest/core/suggest.cpp b/native/jni/src/suggest/core/suggest.cpp
index 457414f..cf2df86 100644
--- a/native/jni/src/suggest/core/suggest.cpp
+++ b/native/jni/src/suggest/core/suggest.cpp
@@ -28,6 +28,7 @@
 #include "suggest/core/policy/weighting.h"
 #include "suggest/core/result/suggestions_output_utils.h"
 #include "suggest/core/session/dic_traverse_session.h"
+#include "suggest/core/suggest_options.h"
 
 namespace latinime {
 
@@ -88,7 +89,8 @@
         traverseSession->getDicTraverseCache()->continueSearch();
     } else {
         // Restart recognition at the root.
-        traverseSession->resetCache(TRAVERSAL->getMaxCacheSize(traverseSession->getInputSize()),
+        traverseSession->resetCache(TRAVERSAL->getMaxCacheSize(traverseSession->getInputSize(),
+                traverseSession->getSuggestOptions()->weightForLocale()),
                 TRAVERSAL->getTerminalCacheSize());
         // Create a new dic node here
         DicNode rootNode;
diff --git a/native/jni/src/suggest/core/suggest_options.h b/native/jni/src/suggest/core/suggest_options.h
index d456680..4d33129 100644
--- a/native/jni/src/suggest/core/suggest_options.h
+++ b/native/jni/src/suggest/core/suggest_options.h
@@ -42,6 +42,12 @@
         return getBoolOption(SPACE_AWARE_GESTURE_ENABLED);
     }
 
+    AK_FORCE_INLINE float weightForLocale() const {
+        // The weight is in thousands and we want the real value, so we divide by 1000.
+        // NativeSuggestOptions#setWeightForLocale does the opposite processing in Java.
+        return static_cast<float>(getIntOption(WEIGHT_FOR_LOCALE_IN_THOUSANDS)) / 1000.0f;
+    }
+
     AK_FORCE_INLINE bool getAdditionalFeaturesBoolOption(const int key) const {
         return getBoolOption(key + ADDITIONAL_FEATURES_OPTIONS);
     }
@@ -55,9 +61,10 @@
     static const int USE_FULL_EDIT_DISTANCE = 1;
     static const int BLOCK_OFFENSIVE_WORDS = 2;
     static const int SPACE_AWARE_GESTURE_ENABLED = 3;
+    static const int WEIGHT_FOR_LOCALE_IN_THOUSANDS = 4;
     // Additional features options are stored after the other options and used as setting values of
     // experimental features.
-    static const int ADDITIONAL_FEATURES_OPTIONS = 4;
+    static const int ADDITIONAL_FEATURES_OPTIONS = 5;
 
     const int *const mOptions;
     const int mLength;
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_node_writer.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_node_writer.cpp
index 8d16974..6243f14 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_node_writer.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_node_writer.cpp
@@ -310,7 +310,7 @@
         const int shortcutProbability) {
     if (!mShortcutPolicy->addNewShortcut(ptNodeParams->getTerminalId(),
             targetCodePoints, targetCodePointCount, shortcutProbability)) {
-        AKLOGE("Cannot add new shortuct entry. terminalId: %d", ptNodeParams->getTerminalId());
+        AKLOGE("Cannot add new shortcut entry. terminalId: %d", ptNodeParams->getTerminalId());
         return false;
     }
     if (!ptNodeParams->hasShortcutTargets()) {
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp
index 36eafa1..0eae934 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp
@@ -33,7 +33,7 @@
 #include "suggest/core/dictionary/property/ngram_property.h"
 #include "suggest/core/dictionary/property/unigram_property.h"
 #include "suggest/core/dictionary/property/word_property.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 #include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h"
 #include "suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_node_reader.h"
 #include "suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h"
@@ -186,7 +186,9 @@
         if (bigramsIt.getBigramPos() == ptNodePos
                 && bigramsIt.getProbability() != NOT_A_PROBABILITY) {
             const int bigramConditionalProbability = getBigramConditionalProbability(
-                    prevWordPtNodeParams.getProbability(), bigramsIt.getProbability());
+                    prevWordPtNodeParams.getProbability(),
+                    prevWordPtNodeParams.representsBeginningOfSentence(),
+                    bigramsIt.getProbability());
             return getProbability(ptNodeParams.getProbability(), bigramConditionalProbability);
         }
     }
@@ -209,15 +211,19 @@
     while (bigramsIt.hasNext()) {
         bigramsIt.next();
         const int bigramConditionalProbability = getBigramConditionalProbability(
-                prevWordPtNodeParams.getProbability(), bigramsIt.getProbability());
+                prevWordPtNodeParams.getProbability(),
+                prevWordPtNodeParams.representsBeginningOfSentence(), bigramsIt.getProbability());
         listener->onVisitEntry(bigramConditionalProbability,
                 getWordIdFromTerminalPtNodePos(bigramsIt.getBigramPos()));
     }
 }
 
 int Ver4PatriciaTriePolicy::getBigramConditionalProbability(const int prevWordUnigramProbability,
-        const int bigramProbability) const {
+        const bool isInBeginningOfSentenceContext, const int bigramProbability) const {
     if (mHeaderPolicy->hasHistoricalInfoOfWords()) {
+        if (isInBeginningOfSentenceContext) {
+            return bigramProbability;
+        }
         // Calculate conditional probability.
         return std::min(MAX_PROBABILITY - prevWordUnigramProbability + bigramProbability,
                 MAX_PROBABILITY);
@@ -338,7 +344,7 @@
     return mNodeWriter.suppressUnigramEntry(&ptNodeParams);
 }
 
-bool Ver4PatriciaTriePolicy::addNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+bool Ver4PatriciaTriePolicy::addNgramEntry(const NgramContext *const ngramContext,
         const NgramProperty *const ngramProperty) {
     if (!mBuffers->isUpdatable()) {
         AKLOGI("Warning: addNgramEntry() is called for non-updatable dictionary.");
@@ -349,8 +355,8 @@
                 mDictBuffer->getTailPosition());
         return false;
     }
-    if (!prevWordsInfo->isValid()) {
-        AKLOGE("prev words info is not valid for adding n-gram entry to the dictionary.");
+    if (!ngramContext->isValid()) {
+        AKLOGE("Ngram context is not valid for adding n-gram entry to the dictionary.");
         return false;
     }
     if (ngramProperty->getTargetCodePoints()->size() > MAX_WORD_LENGTH) {
@@ -359,23 +365,23 @@
         return false;
     }
     WordIdArray<MAX_PREV_WORD_COUNT_FOR_N_GRAM> prevWordIdArray;
-    const WordIdArrayView prevWordIds = prevWordsInfo->getPrevWordIds(this, &prevWordIdArray,
+    const WordIdArrayView prevWordIds = ngramContext->getPrevWordIds(this, &prevWordIdArray,
             false /* tryLowerCaseSearch */);
     if (prevWordIds.empty()) {
         return false;
     }
     if (prevWordIds[0] == NOT_A_WORD_ID) {
-        if (prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)) {
+        if (ngramContext->isNthPrevWordBeginningOfSentence(1 /* n */)) {
             const UnigramProperty beginningOfSentenceUnigramProperty(
                     true /* representsBeginningOfSentence */, true /* isNotAWord */,
                     false /* isBlacklisted */, MAX_PROBABILITY /* probability */, HistoricalInfo());
-            if (!addUnigramEntry(prevWordsInfo->getNthPrevWordCodePoints(1 /* n */),
+            if (!addUnigramEntry(ngramContext->getNthPrevWordCodePoints(1 /* n */),
                     &beginningOfSentenceUnigramProperty)) {
                 AKLOGE("Cannot add unigram entry for the beginning-of-sentence.");
                 return false;
             }
             // Refresh word ids.
-            prevWordsInfo->getPrevWordIds(this, &prevWordIdArray, false /* tryLowerCaseSearch */);
+            ngramContext->getPrevWordIds(this, &prevWordIdArray, false /* tryLowerCaseSearch */);
         } else {
             return false;
         }
@@ -399,7 +405,7 @@
     }
 }
 
-bool Ver4PatriciaTriePolicy::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+bool Ver4PatriciaTriePolicy::removeNgramEntry(const NgramContext *const ngramContext,
         const CodePointArrayView wordCodePoints) {
     if (!mBuffers->isUpdatable()) {
         AKLOGI("Warning: removeNgramEntry() is called for non-updatable dictionary.");
@@ -410,8 +416,8 @@
                 mDictBuffer->getTailPosition());
         return false;
     }
-    if (!prevWordsInfo->isValid()) {
-        AKLOGE("prev words info is not valid for removing n-gram entry form the dictionary.");
+    if (!ngramContext->isValid()) {
+        AKLOGE("Ngram context is not valid for removing n-gram entry form the dictionary.");
         return false;
     }
     if (wordCodePoints.size() > MAX_WORD_LENGTH) {
@@ -419,7 +425,7 @@
                 wordCodePoints.size());
     }
     WordIdArray<MAX_PREV_WORD_COUNT_FOR_N_GRAM> prevWordIdArray;
-    const WordIdArrayView prevWordIds = prevWordsInfo->getPrevWordIds(this, &prevWordIdArray,
+    const WordIdArrayView prevWordIds = ngramContext->getPrevWordIds(this, &prevWordIdArray,
             false /* tryLowerCaseSerch */);
     if (prevWordIds.firstOrDefault(NOT_A_WORD_ID) == NOT_A_WORD_ID) {
         return false;
@@ -440,26 +446,27 @@
 }
 
 
-bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsInfo,
-        const CodePointArrayView wordCodePoints, const bool isValidWord,
-        const HistoricalInfo historicalInfo) {
+bool Ver4PatriciaTriePolicy::updateEntriesForWordWithNgramContext(
+        const NgramContext *const ngramContext, const CodePointArrayView wordCodePoints,
+        const bool isValidWord, const HistoricalInfo historicalInfo) {
     if (!mBuffers->isUpdatable()) {
-        AKLOGI("Warning: updateCounter() is called for non-updatable dictionary.");
+        AKLOGI("Warning: updateEntriesForWordWithNgramContext() is called for non-updatable "
+                "dictionary.");
         return false;
     }
     const int probability = isValidWord ? DUMMY_PROBABILITY_FOR_VALID_WORDS : NOT_A_PROBABILITY;
     const UnigramProperty unigramProperty(false /* representsBeginningOfSentence */,
             false /* isNotAWord */, false /*isBlacklisted*/, probability, historicalInfo);
     if (!addUnigramEntry(wordCodePoints, &unigramProperty)) {
-        AKLOGE("Cannot update unigarm entry in updateCounter().");
+        AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext().");
         return false;
     }
-    const int probabilityForNgram = prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
+    const int probabilityForNgram = ngramContext->isNthPrevWordBeginningOfSentence(1 /* n */)
             ? NOT_A_PROBABILITY : probability;
     const NgramProperty ngramProperty(wordCodePoints.toVector(), probabilityForNgram,
             historicalInfo);
-    if (!addNgramEntry(prevWordsInfo, &ngramProperty)) {
-        AKLOGE("Cannot update unigarm entry in updateCounter().");
+    if (!addNgramEntry(ngramContext, &ngramProperty)) {
+        AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext().");
         return false;
     }
     return true;
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.h b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.h
index b82563e..1ad5e7e 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.h
@@ -112,13 +112,13 @@
 
     bool removeUnigramEntry(const CodePointArrayView wordCodePoints);
 
-    bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    bool addNgramEntry(const NgramContext *const ngramContext,
             const NgramProperty *const ngramProperty);
 
-    bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    bool removeNgramEntry(const NgramContext *const ngramContext,
             const CodePointArrayView wordCodePoints);
 
-    bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
+    bool updateEntriesForWordWithNgramContext(const NgramContext *const ngramContext,
             const CodePointArrayView wordCodePoints, const bool isValidWord,
             const HistoricalInfo historicalInfo);
 
@@ -175,7 +175,7 @@
     const WordAttributes getWordAttributes(const int probability,
             const PtNodeParams &ptNodeParams) const;
     int getBigramConditionalProbability(const int prevWordUnigramProbability,
-            const int bigramProbability) const;
+            const bool isInBeginningOfSentenceContext, const int bigramProbability) const;
 };
 } // namespace v402
 } // namespace backward
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
index d3d684b..b7f1199 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
@@ -23,7 +23,7 @@
 #include "suggest/core/dictionary/binary_dictionary_bigrams_iterator.h"
 #include "suggest/core/dictionary/multi_bigram_map.h"
 #include "suggest/core/dictionary/ngram_listener.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 #include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h"
 #include "suggest/policyimpl/dictionary/structure/pt_common/patricia_trie_reading_utils.h"
 #include "suggest/policyimpl/dictionary/utils/probability_utils.h"
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h
index 32a95bb..b176813 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h
@@ -93,25 +93,26 @@
         return false;
     }
 
-    bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    bool addNgramEntry(const NgramContext *const ngramContext,
             const NgramProperty *const ngramProperty) {
         // This method should not be called for non-updatable dictionary.
         AKLOGI("Warning: addNgramEntry() is called for non-updatable dictionary.");
         return false;
     }
 
-    bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    bool removeNgramEntry(const NgramContext *const ngramContext,
             const CodePointArrayView wordCodePoints) {
         // This method should not be called for non-updatable dictionary.
         AKLOGI("Warning: removeNgramEntry() is called for non-updatable dictionary.");
         return false;
     }
 
-    bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
+    bool updateEntriesForWordWithNgramContext(const NgramContext *const ngramContext,
             const CodePointArrayView wordCodePoints, const bool isValidWord,
             const HistoricalInfo historicalInfo) {
         // This method should not be called for non-updatable dictionary.
-        AKLOGI("Warning: updateCounter() is called for non-updatable dictionary.");
+        AKLOGI("Warning: updateEntriesForWordWithNgramContext() is called for non-updatable "
+                "dictionary.");
         return false;
     }
 
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.cpp
index dc0ed96..90d4687 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.cpp
@@ -37,7 +37,7 @@
     int shortcutPos = NOT_A_DICT_POS;
     int bigramPos = NOT_A_DICT_POS;
     int siblingPos = NOT_A_DICT_POS;
-    PatriciaTrieReadingUtils::readPtNodeInfo(mBuffer.data(), ptNodePos, mShortuctPolicy,
+    PatriciaTrieReadingUtils::readPtNodeInfo(mBuffer.data(), ptNodePos, mShortcutPolicy,
             mBigramPolicy, mCodePointTable, &flags, &mergedNodeCodePointCount, mergedNodeCodePoints,
             &probability, &childrenPos, &shortcutPos, &bigramPos, &siblingPos);
     if (mergedNodeCodePointCount <= 0) {
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.h
index 24ec5bc..838d373 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.h
@@ -35,7 +35,7 @@
             const DictionaryBigramsStructurePolicy *const bigramPolicy,
             const DictionaryShortcutsStructurePolicy *const shortcutPolicy,
             const int *const codePointTable)
-            : mBuffer(buffer), mBigramPolicy(bigramPolicy), mShortuctPolicy(shortcutPolicy),
+            : mBuffer(buffer), mBigramPolicy(bigramPolicy), mShortcutPolicy(shortcutPolicy),
               mCodePointTable(codePointTable) {}
 
     virtual const PtNodeParams fetchPtNodeParamsInBufferFromPtNodePos(const int ptNodePos) const;
@@ -45,7 +45,7 @@
 
     const ReadOnlyByteArrayView mBuffer;
     const DictionaryBigramsStructurePolicy *const mBigramPolicy;
-    const DictionaryShortcutsStructurePolicy *const mShortuctPolicy;
+    const DictionaryShortcutsStructurePolicy *const mShortcutPolicy;
     const int *const mCodePointTable;
 };
 } // namespace latinime
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_writer.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_writer.cpp
index f13512d..d28006a 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_writer.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_writer.cpp
@@ -285,7 +285,7 @@
         const int shortcutProbability) {
     if (!mShortcutPolicy->addNewShortcut(ptNodeParams->getTerminalId(),
             targetCodePoints, targetCodePointCount, shortcutProbability)) {
-        AKLOGE("Cannot add new shortuct entry. terminalId: %d", ptNodeParams->getTerminalId());
+        AKLOGE("Cannot add new shortcut entry. terminalId: %d", ptNodeParams->getTerminalId());
         return false;
     }
     return true;
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
index 036197c..445bbe0 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
@@ -26,7 +26,7 @@
 #include "suggest/core/dictionary/property/ngram_property.h"
 #include "suggest/core/dictionary/property/unigram_property.h"
 #include "suggest/core/dictionary/property/word_property.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 #include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h"
 #include "suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_reader.h"
 #include "suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h"
@@ -266,7 +266,7 @@
     return true;
 }
 
-bool Ver4PatriciaTriePolicy::addNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+bool Ver4PatriciaTriePolicy::addNgramEntry(const NgramContext *const ngramContext,
         const NgramProperty *const ngramProperty) {
     if (!mBuffers->isUpdatable()) {
         AKLOGI("Warning: addNgramEntry() is called for non-updatable dictionary.");
@@ -277,8 +277,8 @@
                 mDictBuffer->getTailPosition());
         return false;
     }
-    if (!prevWordsInfo->isValid()) {
-        AKLOGE("prev words info is not valid for adding n-gram entry to the dictionary.");
+    if (!ngramContext->isValid()) {
+        AKLOGE("Ngram context is not valid for adding n-gram entry to the dictionary.");
         return false;
     }
     if (ngramProperty->getTargetCodePoints()->size() > MAX_WORD_LENGTH) {
@@ -287,7 +287,7 @@
         return false;
     }
     WordIdArray<MAX_PREV_WORD_COUNT_FOR_N_GRAM> prevWordIdArray;
-    const WordIdArrayView prevWordIds = prevWordsInfo->getPrevWordIds(this, &prevWordIdArray,
+    const WordIdArrayView prevWordIds = ngramContext->getPrevWordIds(this, &prevWordIdArray,
             false /* tryLowerCaseSearch */);
     if (prevWordIds.empty()) {
         return false;
@@ -296,19 +296,19 @@
         if (prevWordIds[i] != NOT_A_WORD_ID) {
             continue;
         }
-        if (!prevWordsInfo->isNthPrevWordBeginningOfSentence(i + 1 /* n */)) {
+        if (!ngramContext->isNthPrevWordBeginningOfSentence(i + 1 /* n */)) {
             return false;
         }
         const UnigramProperty beginningOfSentenceUnigramProperty(
                 true /* representsBeginningOfSentence */, true /* isNotAWord */,
                 false /* isBlacklisted */, MAX_PROBABILITY /* probability */, HistoricalInfo());
-        if (!addUnigramEntry(prevWordsInfo->getNthPrevWordCodePoints(1 /* n */),
+        if (!addUnigramEntry(ngramContext->getNthPrevWordCodePoints(1 /* n */),
                 &beginningOfSentenceUnigramProperty)) {
             AKLOGE("Cannot add unigram entry for the beginning-of-sentence.");
             return false;
         }
         // Refresh word ids.
-        prevWordsInfo->getPrevWordIds(this, &prevWordIdArray, false /* tryLowerCaseSearch */);
+        ngramContext->getPrevWordIds(this, &prevWordIdArray, false /* tryLowerCaseSearch */);
     }
     const int wordId = getWordId(CodePointArrayView(*ngramProperty->getTargetCodePoints()),
             false /* forceLowerCaseSearch */);
@@ -326,7 +326,7 @@
     }
 }
 
-bool Ver4PatriciaTriePolicy::removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+bool Ver4PatriciaTriePolicy::removeNgramEntry(const NgramContext *const ngramContext,
         const CodePointArrayView wordCodePoints) {
     if (!mBuffers->isUpdatable()) {
         AKLOGI("Warning: removeNgramEntry() is called for non-updatable dictionary.");
@@ -337,8 +337,8 @@
                 mDictBuffer->getTailPosition());
         return false;
     }
-    if (!prevWordsInfo->isValid()) {
-        AKLOGE("prev words info is not valid for removing n-gram entry form the dictionary.");
+    if (!ngramContext->isValid()) {
+        AKLOGE("Ngram context is not valid for removing n-gram entry form the dictionary.");
         return false;
     }
     if (wordCodePoints.size() > MAX_WORD_LENGTH) {
@@ -346,7 +346,7 @@
                 wordCodePoints.size());
     }
     WordIdArray<MAX_PREV_WORD_COUNT_FOR_N_GRAM> prevWordIdArray;
-    const WordIdArrayView prevWordIds = prevWordsInfo->getPrevWordIds(this, &prevWordIdArray,
+    const WordIdArrayView prevWordIds = ngramContext->getPrevWordIds(this, &prevWordIdArray,
             false /* tryLowerCaseSerch */);
     if (prevWordIds.empty() || prevWordIds.contains(NOT_A_WORD_ID)) {
         return false;
@@ -363,29 +363,30 @@
     }
 }
 
-bool Ver4PatriciaTriePolicy::updateCounter(const PrevWordsInfo *const prevWordsInfo,
-        const CodePointArrayView wordCodePoints, const bool isValidWord,
-        const HistoricalInfo historicalInfo) {
+bool Ver4PatriciaTriePolicy::updateEntriesForWordWithNgramContext(
+        const NgramContext *const ngramContext, const CodePointArrayView wordCodePoints,
+        const bool isValidWord, const HistoricalInfo historicalInfo) {
     if (!mBuffers->isUpdatable()) {
-        AKLOGI("Warning: updateCounter() is called for non-updatable dictionary.");
+        AKLOGI("Warning: updateEntriesForWordWithNgramContext() is called for non-updatable "
+                "dictionary.");
         return false;
     }
     // TODO: Have count up method in language model dict content.
     const int probability = isValidWord ? DUMMY_PROBABILITY_FOR_VALID_WORDS : NOT_A_PROBABILITY;
     const UnigramProperty unigramProperty(false /* representsBeginningOfSentence */,
-            false /* isNotAWord */, false /*isBlacklisted*/, probability, historicalInfo);
+            false /* isNotAWord */, false /* isBlacklisted */, probability, historicalInfo);
     if (!addUnigramEntry(wordCodePoints, &unigramProperty)) {
-        AKLOGE("Cannot update unigarm entry in updateCounter().");
+        AKLOGE("Cannot update unigarm entry in updateEntriesForWordWithNgramContext().");
         return false;
     }
-    const int probabilityForNgram = prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
+    const int probabilityForNgram = ngramContext->isNthPrevWordBeginningOfSentence(1 /* n */)
             ? NOT_A_PROBABILITY : probability;
     const NgramProperty ngramProperty(wordCodePoints.toVector(), probabilityForNgram,
             historicalInfo);
-    for (size_t i = 1; i <= prevWordsInfo->getPrevWordCount(); ++i) {
-        const PrevWordsInfo trimmedPrevWordsInfo(prevWordsInfo->getTrimmedPrevWordsInfo(i));
-        if (!addNgramEntry(&trimmedPrevWordsInfo, &ngramProperty)) {
-            AKLOGE("Cannot update ngram entry in updateCounter().");
+    for (size_t i = 1; i <= ngramContext->getPrevWordCount(); ++i) {
+        const NgramContext trimmedNgramContext(ngramContext->getTrimmedNgramContext(i));
+        if (!addNgramEntry(&trimmedNgramContext, &ngramProperty)) {
+            AKLOGE("Cannot update ngram entry in updateEntriesForWordWithNgramContext().");
             return false;
         }
     }
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.h
index 662bb8d..60e30f2 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.h
@@ -92,13 +92,13 @@
 
     bool removeUnigramEntry(const CodePointArrayView wordCodePoints);
 
-    bool addNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    bool addNgramEntry(const NgramContext *const ngramContext,
             const NgramProperty *const ngramProperty);
 
-    bool removeNgramEntry(const PrevWordsInfo *const prevWordsInfo,
+    bool removeNgramEntry(const NgramContext *const ngramContext,
             const CodePointArrayView wordCodePoints);
 
-    bool updateCounter(const PrevWordsInfo *const prevWordsInfo,
+    bool updateEntriesForWordWithNgramContext(const NgramContext *const ngramContext,
             const CodePointArrayView wordCodePoints, const bool isValidWord,
             const HistoricalInfo historicalInfo);
 
diff --git a/native/jni/src/suggest/policyimpl/typing/scoring_params.cpp b/native/jni/src/suggest/policyimpl/typing/scoring_params.cpp
index 3fc566e..b621eef 100644
--- a/native/jni/src/suggest/policyimpl/typing/scoring_params.cpp
+++ b/native/jni/src/suggest/policyimpl/typing/scoring_params.cpp
@@ -31,6 +31,7 @@
 // TODO: Unlimit max cache dic node size
 const int ScoringParams::MAX_CACHE_DIC_NODE_SIZE = 170;
 const int ScoringParams::MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT = 310;
+const int ScoringParams::MAX_CACHE_DIC_NODE_SIZE_FOR_LOW_PROBABILITY_LOCALE = 50;
 const int ScoringParams::THRESHOLD_SHORT_WORD_LENGTH = 4;
 
 const float ScoringParams::DISTANCE_WEIGHT_LENGTH = 0.1524f;
@@ -61,4 +62,7 @@
 const float ScoringParams::TYPING_BASE_OUTPUT_SCORE = 1.0f;
 const float ScoringParams::TYPING_MAX_OUTPUT_SCORE_PER_INPUT = 0.1f;
 const float ScoringParams::NORMALIZED_SPATIAL_DISTANCE_THRESHOLD_FOR_EDIT = 0.095f;
+const float ScoringParams::LOCALE_WEIGHT_THRESHOLD_FOR_SPACE_SUBSTITUTION = 0.99f;
+const float ScoringParams::LOCALE_WEIGHT_THRESHOLD_FOR_SPACE_OMISSION = 0.99f;
+const float ScoringParams::LOCALE_WEIGHT_THRESHOLD_FOR_SMALL_CACHE_SIZE = 0.99f;
 } // namespace latinime
diff --git a/native/jni/src/suggest/policyimpl/typing/scoring_params.h b/native/jni/src/suggest/policyimpl/typing/scoring_params.h
index b12de6d..731424f 100644
--- a/native/jni/src/suggest/policyimpl/typing/scoring_params.h
+++ b/native/jni/src/suggest/policyimpl/typing/scoring_params.h
@@ -30,6 +30,7 @@
     static const float AUTOCORRECT_OUTPUT_THRESHOLD;
     static const int MAX_CACHE_DIC_NODE_SIZE;
     static const int MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT;
+    static const int MAX_CACHE_DIC_NODE_SIZE_FOR_LOW_PROBABILITY_LOCALE;
     static const int THRESHOLD_SHORT_WORD_LENGTH;
 
     static const float EXACT_MATCH_PROMOTION;
@@ -68,6 +69,9 @@
     static const float TYPING_BASE_OUTPUT_SCORE;
     static const float TYPING_MAX_OUTPUT_SCORE_PER_INPUT;
     static const float NORMALIZED_SPATIAL_DISTANCE_THRESHOLD_FOR_EDIT;
+    static const float LOCALE_WEIGHT_THRESHOLD_FOR_SPACE_SUBSTITUTION;
+    static const float LOCALE_WEIGHT_THRESHOLD_FOR_SPACE_OMISSION;
+    static const float LOCALE_WEIGHT_THRESHOLD_FOR_SMALL_CACHE_SIZE;
 
  private:
     DISALLOW_IMPLICIT_CONSTRUCTORS(ScoringParams);
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_traversal.h b/native/jni/src/suggest/policyimpl/typing/typing_traversal.h
index b64ee8b..b9b6314 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_traversal.h
+++ b/native/jni/src/suggest/policyimpl/typing/typing_traversal.h
@@ -26,6 +26,7 @@
 #include "suggest/core/layout/proximity_info_utils.h"
 #include "suggest/core/policy/traversal.h"
 #include "suggest/core/session/dic_traverse_session.h"
+#include "suggest/core/suggest_options.h"
 #include "suggest/policyimpl/typing/scoring_params.h"
 #include "utils/char_utils.h"
 
@@ -77,6 +78,13 @@
         if (!CORRECT_NEW_WORD_SPACE_SUBSTITUTION) {
             return false;
         }
+        if (traverseSession->getSuggestOptions()->weightForLocale()
+                < ScoringParams::LOCALE_WEIGHT_THRESHOLD_FOR_SPACE_SUBSTITUTION) {
+            // Space substitution is heavy, so we skip doing it if the weight for this language
+            // is low because we anticipate the suggestions out of this dictionary are not for
+            // the language the user intends to type in.
+            return false;
+        }
         if (!canDoLookAheadCorrection(traverseSession, dicNode)) {
             return false;
         }
@@ -91,6 +99,13 @@
         if (!CORRECT_NEW_WORD_SPACE_OMISSION) {
             return false;
         }
+        if (traverseSession->getSuggestOptions()->weightForLocale()
+                < ScoringParams::LOCALE_WEIGHT_THRESHOLD_FOR_SPACE_OMISSION) {
+            // Space omission is heavy, so we skip doing it if the weight for this language
+            // is low because we anticipate the suggestions out of this dictionary are not for
+            // the language the user intends to type in.
+            return false;
+        }
         const int inputSize = traverseSession->getInputSize();
         // TODO: Don't refer to isCompletion?
         if (dicNode->isCompletion(inputSize)) {
@@ -141,9 +156,14 @@
         return DicNodeVector::DEFAULT_NODES_SIZE_FOR_OPTIMIZATION;
     }
 
-    AK_FORCE_INLINE int getMaxCacheSize(const int inputSize) const {
-        return (inputSize <= 1) ? ScoringParams::MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT
-                : ScoringParams::MAX_CACHE_DIC_NODE_SIZE;
+    AK_FORCE_INLINE int getMaxCacheSize(const int inputSize, const float weightForLocale) const {
+        if (inputSize <= 1) {
+            return ScoringParams::MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT;
+        }
+        if (weightForLocale < ScoringParams::LOCALE_WEIGHT_THRESHOLD_FOR_SMALL_CACHE_SIZE) {
+            return ScoringParams::MAX_CACHE_DIC_NODE_SIZE_FOR_LOW_PROBABILITY_LOCALE;
+        }
+        return ScoringParams::MAX_CACHE_DIC_NODE_SIZE;
     }
 
     AK_FORCE_INLINE int getTerminalCacheSize() const {
diff --git a/native/jni/src/utils/jni_data_utils.h b/native/jni/src/utils/jni_data_utils.h
index 235a03b..25cc417 100644
--- a/native/jni/src/utils/jni_data_utils.h
+++ b/native/jni/src/utils/jni_data_utils.h
@@ -21,7 +21,7 @@
 
 #include "defines.h"
 #include "jni.h"
-#include "suggest/core/session/prev_words_info.h"
+#include "suggest/core/session/ngram_context.h"
 #include "suggest/core/policy/dictionary_header_structure_policy.h"
 #include "suggest/policyimpl/dictionary/header/header_read_write_utils.h"
 #include "utils/char_utils.h"
@@ -96,7 +96,7 @@
         }
     }
 
-    static PrevWordsInfo constructPrevWordsInfo(JNIEnv *env, jobjectArray prevWordCodePointArrays,
+    static NgramContext constructNgramContext(JNIEnv *env, jobjectArray prevWordCodePointArrays,
             jbooleanArray isBeginningOfSentenceArray, const size_t prevWordCount) {
         int prevWordCodePoints[MAX_PREV_WORD_COUNT_FOR_N_GRAM][MAX_WORD_LENGTH];
         int prevWordCodePointCount[MAX_PREV_WORD_COUNT_FOR_N_GRAM];
@@ -119,7 +119,7 @@
                     &isBeginningOfSentenceBoolean);
             isBeginningOfSentence[i] = isBeginningOfSentenceBoolean == JNI_TRUE;
         }
-        return PrevWordsInfo(prevWordCodePoints, prevWordCodePointCount, isBeginningOfSentence,
+        return NgramContext(prevWordCodePoints, prevWordCodePointCount, isBeginningOfSentence,
                 prevWordCount);
     }
 
diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java
index 34cf407..d642a10 100644
--- a/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java
@@ -348,6 +348,31 @@
     }
 
     /*
+     * Test that KeyboardTheme array should be sorted by descending order of
+     * {@link KeyboardTheme#mMinApiVersion}.
+     */
+    private static void assertSortedKeyboardThemeArray(final KeyboardTheme[] array) {
+        assertNotNull(array);
+        final int length = array.length;
+        assertTrue("array length=" + length, length > 0);
+        for (int index = 0; index < length - 1; index++) {
+            final KeyboardTheme theme = array[index];
+            final KeyboardTheme nextTheme = array[index + 1];
+            assertTrue("sorted MinApiVersion: "
+                    + theme.mThemeName + ": minApiVersion=" + theme.mMinApiVersion,
+                    theme.mMinApiVersion >= nextTheme.mMinApiVersion);
+        }
+    }
+
+    public void testSortedKeyboardTheme() {
+        assertSortedKeyboardThemeArray(KeyboardTheme.KEYBOARD_THEMES);
+    }
+
+    public void testSortedAvailableKeyboardTheme() {
+        assertSortedKeyboardThemeArray(KeyboardTheme.getAvailableThemeArray(getContext()));
+    }
+
+    /*
      * Test for missing selected theme.
      */
     private static KeyboardTheme[] LIMITED_THEMES = {
@@ -356,6 +381,7 @@
     };
     static {
         Arrays.sort(LIMITED_THEMES);
+        assertSortedKeyboardThemeArray(LIMITED_THEMES);
     }
 
     public void testMissingSelectedThemeIcs() {
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index 6860bea..ee79424 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -39,6 +39,8 @@
 import com.android.inputmethod.event.Event;
 import com.android.inputmethod.keyboard.Key;
 import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.latin.Dictionary;
+import com.android.inputmethod.latin.Dictionary.PhonyDictionary;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 import com.android.inputmethod.latin.settings.DebugSettings;
 import com.android.inputmethod.latin.settings.Settings;
@@ -61,6 +63,10 @@
     protected static final int DELAY_TO_WAIT_FOR_PREDICTIONS = 200;
     private final int TIMEOUT_TO_WAIT_FOR_LOADING_MAIN_DICTIONARY_IN_SECONDS = 60;
 
+    // Type for a test phony dictionary
+    private static final String TYPE_TEST = "test";
+    private static final PhonyDictionary DICTIONARY_TEST = new PhonyDictionary(TYPE_TEST);
+
     protected LatinIME mLatinIME;
     protected Keyboard mKeyboard;
     protected MyEditText mEditText;
@@ -353,7 +359,7 @@
 
     protected void pickSuggestionManually(final String suggestion) {
         mLatinIME.pickSuggestionManually(new SuggestedWordInfo(suggestion, 1,
-                SuggestedWordInfo.KIND_CORRECTION, null /* sourceDict */,
+                SuggestedWordInfo.KIND_CORRECTION, DICTIONARY_TEST,
                 SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
                 SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
     }
diff --git a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
index 563261f..221541e 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
@@ -59,40 +59,6 @@
                 SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */);
     }
 
-    public void testGetSuggestedWordsExcludingTypedWord() {
-        final String TYPED_WORD = "typed";
-        final int NUMBER_OF_ADDED_SUGGESTIONS = 5;
-        final int KIND_OF_SECOND_CORRECTION = SuggestedWordInfo.KIND_CORRECTION;
-        final ArrayList<SuggestedWordInfo> list = new ArrayList<>();
-        list.add(createTypedWordInfo(TYPED_WORD));
-        for (int i = 0; i < NUMBER_OF_ADDED_SUGGESTIONS; ++i) {
-            list.add(createCorrectionWordInfo(Integer.toString(i)));
-        }
-
-        final SuggestedWords words = new SuggestedWords(
-                list, null /* rawSuggestions */,
-                false /* typedWordValid */,
-                false /* willAutoCorrect */,
-                false /* isObsoleteSuggestions */,
-                SuggestedWords.INPUT_STYLE_NONE);
-        assertEquals(NUMBER_OF_ADDED_SUGGESTIONS + 1, words.size());
-        assertEquals("typed", words.getWord(0));
-        assertTrue(words.getInfo(0).isKindOf(SuggestedWordInfo.KIND_TYPED));
-        assertEquals("0", words.getWord(1));
-        assertTrue(words.getInfo(1).isKindOf(KIND_OF_SECOND_CORRECTION));
-        assertEquals("4", words.getWord(5));
-        assertTrue(words.getInfo(5).isKindOf(KIND_OF_SECOND_CORRECTION));
-
-        final SuggestedWords wordsWithoutTyped =
-                words.getSuggestedWordsExcludingTypedWordForRecorrection();
-        // Make sure that the typed word has indeed been excluded, by testing the size of the
-        // suggested words, the string and the kind of the top suggestion, which should match
-        // the string and kind of what we inserted after the typed word.
-        assertEquals(words.size() - 1, wordsWithoutTyped.size());
-        assertEquals("0", wordsWithoutTyped.getWord(0));
-        assertTrue(wordsWithoutTyped.getInfo(0).isKindOf(KIND_OF_SECOND_CORRECTION));
-    }
-
     // Helper for testGetTransformedWordInfo
     private SuggestedWordInfo transformWordInfo(final String info,
             final int trailingSingleQuotesCount) {
@@ -141,9 +107,14 @@
         assertNotNull(typedWord);
         assertEquals(TYPED_WORD, typedWord.mWord);
 
-        // Make sure getTypedWordInfoOrNull() returns null.
-        final SuggestedWords wordsWithoutTypedWord =
-                wordsWithTypedWord.getSuggestedWordsExcludingTypedWordForRecorrection();
+        // Make sure getTypedWordInfoOrNull() returns null when no typed word.
+        list.remove(0);
+        final SuggestedWords wordsWithoutTypedWord = new SuggestedWords(
+                list, null /* rawSuggestions */,
+                false /* typedWordValid */,
+                false /* willAutoCorrect */,
+                false /* isObsoleteSuggestions */,
+                SuggestedWords.INPUT_STYLE_NONE);
         assertNull(wordsWithoutTypedWord.getTypedWordInfoOrNull());
 
         // Make sure getTypedWordInfoOrNull() returns null.
diff --git a/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java b/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java
index 00857e5..8328179 100644
--- a/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java
+++ b/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java
@@ -23,7 +23,7 @@
 import android.preference.PreferenceManager;
 import android.test.AndroidTestCase;
 
-import com.android.inputmethod.latin.settings.Settings;
+import com.android.inputmethod.latin.settings.LocalSettingsConstants;
 
 /**
  * Tests for {@link AccountsChangedReceiver}.
@@ -40,7 +40,7 @@
         super.setUp();
         mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
         // Keep track of the current account so that we restore it when the test finishes.
-        mLastKnownAccount = mPrefs.getString(Settings.PREF_ACCOUNT_NAME, null);
+        mLastKnownAccount = mPrefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null);
     }
 
     @Override
@@ -99,13 +99,14 @@
 
     private void updateAccountName(String accountName) {
         if (accountName == null) {
-            mPrefs.edit().remove(Settings.PREF_ACCOUNT_NAME).apply();
+            mPrefs.edit().remove(LocalSettingsConstants.PREF_ACCOUNT_NAME).apply();
         } else {
-            mPrefs.edit().putString(Settings.PREF_ACCOUNT_NAME, accountName).apply();
+            mPrefs.edit().putString(LocalSettingsConstants.PREF_ACCOUNT_NAME, accountName).apply();
         }
     }
 
     private void assertAccountName(String expectedAccountName) {
-        assertEquals(expectedAccountName, mPrefs.getString(Settings.PREF_ACCOUNT_NAME, null));
+        assertEquals(expectedAccountName,
+                mPrefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null));
     }
 }
diff --git a/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java b/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java
index d151732..fed8be9 100644
--- a/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java
+++ b/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java
@@ -16,8 +16,8 @@
 
 package com.android.inputmethod.latin.network;
 
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.eq;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -53,41 +53,52 @@
         MockitoAnnotations.initMocks(this);
     }
 
-    public void testError_badGateway() throws IOException {
+    public void testError_badGateway() throws IOException, AuthException {
         when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_BAD_GATEWAY);
         final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection);
-        final FakeErrorResponseProcessor processor =
-                new FakeErrorResponseProcessor(HttpURLConnection.HTTP_BAD_GATEWAY);
+        final FakeErrorResponseProcessor processor = new FakeErrorResponseProcessor();
 
-        client.execute(null /* empty request */, processor);
-        assertTrue("ResponseProcessor was not invoked", processor.mInvoked);
+        try {
+            client.execute(null /* empty request */, processor);
+            fail("Expecting an HttpException");
+        } catch (HttpException e) {
+            // expected HttpException
+            assertEquals(HttpURLConnection.HTTP_BAD_GATEWAY, e.getHttpStatusCode());
+        }
     }
 
-    public void testError_clientTimeout() throws IOException {
+    public void testError_clientTimeout() throws Exception {
         when(mMockHttpConnection.getResponseCode()).thenReturn(
                 HttpURLConnection.HTTP_CLIENT_TIMEOUT);
         final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection);
-        final FakeErrorResponseProcessor processor =
-                new FakeErrorResponseProcessor(HttpURLConnection.HTTP_CLIENT_TIMEOUT);
+        final FakeErrorResponseProcessor processor = new FakeErrorResponseProcessor();
 
-        client.execute(null /* empty request */, processor);
-        assertTrue("ResponseProcessor was not invoked", processor.mInvoked);
+        try {
+            client.execute(null /* empty request */, processor);
+            fail("Expecting an HttpException");
+        } catch (HttpException e) {
+            // expected HttpException
+            assertEquals(HttpURLConnection.HTTP_CLIENT_TIMEOUT, e.getHttpStatusCode());
+        }
     }
 
-    public void testError_forbiddenWithRequest() throws IOException {
+    public void testError_forbiddenWithRequest() throws Exception {
         final OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
         when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN);
         when(mMockHttpConnection.getOutputStream()).thenReturn(mockOutputStream);
         final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection);
-        final FakeErrorResponseProcessor processor =
-                new FakeErrorResponseProcessor(HttpURLConnection.HTTP_FORBIDDEN);
+        final FakeErrorResponseProcessor processor = new FakeErrorResponseProcessor();
 
-        client.execute(new byte[100], processor);
+        try {
+            client.execute(new byte[100], processor);
+            fail("Expecting an HttpException");
+        } catch (HttpException e) {
+            assertEquals(HttpURLConnection.HTTP_FORBIDDEN, e.getHttpStatusCode());
+        }
         verify(mockOutputStream).write(any(byte[].class), eq(0), eq(100));
-        assertTrue("ResponseProcessor was not invoked", processor.mInvoked);
     }
 
-    public void testSuccess_emptyRequest() throws IOException {
+    public void testSuccess_emptyRequest() throws Exception {
         final Random rand = new Random();
         byte[] response = new byte[100];
         rand.nextBytes(response);
@@ -101,7 +112,7 @@
         assertTrue("ResponseProcessor was not invoked", processor.mInvoked);
     }
 
-    public void testSuccess() throws IOException {
+    public void testSuccess() throws Exception {
         final OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
         final Random rand = new Random();
         byte[] response = new byte[100];
@@ -117,28 +128,15 @@
         assertTrue("ResponseProcessor was not invoked", processor.mInvoked);
     }
 
-    private static class FakeErrorResponseProcessor implements ResponseProcessor {
-        private final int mExpectedStatusCode;
-
-        boolean mInvoked;
-
-        FakeErrorResponseProcessor(int expectedStatusCode) {
-            mExpectedStatusCode = expectedStatusCode;
-        }
-
+    private static class FakeErrorResponseProcessor implements ResponseProcessor<Void> {
         @Override
-        public void onError(int httpStatusCode, String message) {
-            mInvoked = true;
-            assertEquals("onError:", mExpectedStatusCode, httpStatusCode);
-        }
-
-        @Override
-        public void onSuccess(InputStream response) {
+        public Void onSuccess(InputStream response) {
             fail("Expected an error but received success");
+            return null;
         }
     }
 
-    private static class FakeSuccessResponseProcessor implements ResponseProcessor {
+    private static class FakeSuccessResponseProcessor implements ResponseProcessor<Void> {
         private final byte[] mExpectedResponse;
 
         boolean mInvoked;
@@ -148,12 +146,7 @@
         }
 
         @Override
-        public void onError(int httpStatusCode, String message) {
-            fail("Expected a response but received an error");
-        }
-
-        @Override
-        public void onSuccess(InputStream response) {
+        public Void onSuccess(InputStream response) {
             try {
                 mInvoked = true;
                 BufferedInputStream in = new BufferedInputStream(response);
@@ -169,6 +162,7 @@
             } catch (IOException ex) {
                 fail("IOException in onSuccess");
             }
+            return null;
         }
     }
 }
diff --git a/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java b/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java
index 2b43d5b..5b3e78e 100644
--- a/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java
+++ b/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java
@@ -142,4 +142,13 @@
         assertTrue(connection.getDoInput());
         assertTrue(connection.getDoOutput());
     }
+
+    public void testSetAuthToken() throws IOException {
+        HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
+        builder.setUrl("https://www.example.com");
+        builder.setAuthToken("some-random-auth-token");
+        HttpURLConnection connection = builder.build();
+        assertEquals("some-random-auth-token",
+                connection.getRequestProperty(HttpUrlConnectionBuilder.HTTP_HEADER_AUTHORIZATION));
+    }
 }
diff --git a/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java b/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java
index 2ef8b54..273d7fa 100644
--- a/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java
+++ b/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java
@@ -16,14 +16,21 @@
 
 package com.android.inputmethod.latin.settings;
 
+import static com.android.inputmethod.latin.settings.AccountsSettingsFragment.AUTHORITY;
+
+import android.accounts.Account;
 import android.app.AlertDialog;
 import android.app.Dialog;
+import android.content.ContentResolver;
 import android.content.Intent;
 import android.test.ActivityInstrumentationTestCase2;
 import android.test.suitebuilder.annotation.MediumTest;
 import android.view.View;
 import android.widget.ListView;
 
+import com.android.inputmethod.latin.accounts.LoginAccountUtils;
+import com.android.inputmethod.latin.define.ProductionFlags;
+
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -32,6 +39,9 @@
         extends ActivityInstrumentationTestCase2<TestFragmentActivity> {
     private static final String FRAG_NAME = AccountsSettingsFragment.class.getName();
     private static final long TEST_TIMEOUT_MILLIS = 5000;
+    private static final String TEST_ACCOUNT_NAME = "AccountsSettingsFragmentTests";
+    private static final Account TEST_ACCOUNT =
+            new Account(TEST_ACCOUNT_NAME, LoginAccountUtils.ACCOUNT_TYPE);
 
     private AlertDialog mDialog;
 
@@ -47,6 +57,13 @@
         setActivityIntent(intent);
     }
 
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        // reset the syncable state to unknown
+        ContentResolver.setIsSyncable(TEST_ACCOUNT, AUTHORITY, -1);
+    }
+
     public void testEmptyAccounts() {
         final AccountsSettingsFragment fragment =
                 (AccountsSettingsFragment) getActivity().mFragment;
@@ -129,4 +146,57 @@
         assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_NEGATIVE).getVisibility());
         assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_POSITIVE).getVisibility());
     }
+
+    public void testUpdateSyncPolicy_enable() {
+        // This test is a no-op when ENABLE_PERSONAL_DICTIONARY_SYNC is not enabled
+        if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
+            return;
+        }
+        // Should be unknown by default.
+        assertTrue(ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY) < 0);
+
+        final AccountsSettingsFragment fragment =
+                (AccountsSettingsFragment) getActivity().mFragment;
+        fragment.updateSyncPolicy(true, TEST_ACCOUNT_NAME);
+
+        // Should be syncable now.
+        assertEquals(1, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY));
+    }
+
+    public void testUpdateSyncPolicy_disable() {
+        // This test is a no-op when ENABLE_PERSONAL_DICTIONARY_SYNC is not enabled
+        if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
+            return;
+        }
+        // Should be unknown by default.
+        assertTrue(ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY) < 0);
+
+        final AccountsSettingsFragment fragment =
+                (AccountsSettingsFragment) getActivity().mFragment;
+        fragment.updateSyncPolicy(false, TEST_ACCOUNT_NAME);
+
+        // Should not be syncable now.
+        assertEquals(0, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY));
+    }
+
+    public void testUpdateSyncPolicy_enableDisable() {
+        // This test is a no-op when ENABLE_PERSONAL_DICTIONARY_SYNC is not enabled
+        if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
+            return;
+        }
+        // Should be unknown by default.
+        assertTrue(ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY) < 0);
+
+        final AccountsSettingsFragment fragment =
+                (AccountsSettingsFragment) getActivity().mFragment;
+        fragment.updateSyncPolicy(true, TEST_ACCOUNT_NAME);
+
+        // Should be syncable now.
+        assertEquals(1, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY));
+
+        fragment.updateSyncPolicy(false, TEST_ACCOUNT_NAME);
+
+        // Should not be syncable now.
+        assertEquals(0, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY));
+    }
 }