Bug 827325 - Delay calling restartInput in AwesomeBar to avoid specific IME quirks; r=cpeterson
authorJim Chen <nchen@mozilla.com>
Wed, 30 Jan 2013 10:46:58 -0500
changeset 130252 920d24c1a157dbf3a05fc598cf0342ef8798d934
parent 130251 daa83b83531cd5d54886244f4564cdfbb8bbe14c
child 130253 cabffed38cccabd04d4ee5e4238f5142ee6d7cf3
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpeterson
bugs827325
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 827325 - Delay calling restartInput in AwesomeBar to avoid specific IME quirks; r=cpeterson
mobile/android/base/AwesomeBar.java
mobile/android/base/InputMethods.java
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -67,16 +67,17 @@ public class AwesomeBar extends GeckoAct
 
     private String mTarget;
     private AwesomeBarTabs mAwesomeTabs;
     private CustomEditText mText;
     private ImageButton mGoButton;
     private ContentResolver mResolver;
     private ContextMenuSubject mContextMenuSubject;
     private boolean mIsUsingSwype;
+    private boolean mDelayRestartInput;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         Log.d(LOGTAG, "creating awesomebar");
 
         mResolver = Tabs.getInstance().getContentResolver();
@@ -321,21 +322,34 @@ public class AwesomeBar extends GeckoAct
         if (StringUtils.isSearchQuery(text)) {
             imageResource = R.drawable.ic_awesomebar_search;
             contentDescription = getString(R.string.search);
             imeAction = EditorInfo.IME_ACTION_SEARCH;
         }
         mGoButton.setImageResource(imageResource);
         mGoButton.setContentDescription(contentDescription);
 
+        InputMethodManager imm = InputMethods.getInputMethodManager(mText.getContext());
+        if (imm == null) {
+            return;
+        }
         int actionBits = mText.getImeOptions() & EditorInfo.IME_MASK_ACTION;
         if (actionBits != imeAction) {
-            InputMethodManager imm = (InputMethodManager) mText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
             int optionBits = mText.getImeOptions() & ~EditorInfo.IME_MASK_ACTION;
             mText.setImeOptions(optionBits | imeAction);
+
+            mDelayRestartInput = InputMethods.shouldDelayAwesomebarUpdate(mText.getContext());
+            if (!mDelayRestartInput) {
+                imm.restartInput(mText);
+            }
+        } else if (mDelayRestartInput) {
+            // Only call delayed restartInput when actionBits == imeAction
+            // so if there are two restarts in a row, the first restarts will
+            // be discarded and the second restart will be properly delayed
+            mDelayRestartInput = false;
             imm.restartInput(mText);
         }
     }
 
     private void cancelAndFinish() {
         setResult(Activity.RESULT_CANCELED);
         finish();
         overridePendingTransition(R.anim.awesomebar_hold_still, R.anim.awesomebar_fade_out);
--- a/mobile/android/base/InputMethods.java
+++ b/mobile/android/base/InputMethods.java
@@ -16,18 +16,20 @@ import java.util.Collection;
 import java.util.Locale;
 
 final class InputMethods {
 
     public static final String METHOD_ATOK = "com.justsystems.atokmobile.service/.AtokInputMethodService";
     public static final String METHOD_GOOGLE_JAPANESE_INPUT = "com.google.android.inputmethod.japanese/.MozcService";
     public static final String METHOD_IWNN = "jp.co.omronsoft.iwnnime.ml/.standardcommon.IWnnLanguageSwitcher";
     public static final String METHOD_OPENWNN_PLUS = "com.owplus.ime.openwnnplus/.OpenWnnJAJP";
+    public static final String METHOD_SAMSUNG = "com.sec.android.inputmethod/.SamsungKeypad";
     public static final String METHOD_SIMEJI = "com.adamrocker.android.input.simeji/.OpenWnnSimeji";
     public static final String METHOD_STOCK_LATINIME = "com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME";
+    public static final String METHOD_SWIFTKEY = "com.touchtype.swiftkey/com.touchtype.KeyboardService";
     public static final String METHOD_SWYPE = "com.swype.android.inputmethod/.SwypeInputMethod";
     public static final String METHOD_SWYPE_BETA = "com.nuance.swype.input/.IME";
 
     /* These input method names are currently unused, but kept here for future reference:
     public static final String METHOD_EYES_FREE_KEYBOARD = "com.googlecode.eyesfree.inputmethod.latin/.LatinIME";
     public static final String METHOD_GO_KEYBOARD = "com.jb.gokeyboard/.GoKeyboard";
     public static final String METHOD_GOOGLE_PINYIN = "com.google.android.inputmethod.pinyin/.PinyinIME";
     public static final String METHOD_GOOGLE_TALKBACK = "com.google.android.marvin.talkback/com.googlecode.eyesfree.inputmethod.latin.LatinIME";
@@ -86,9 +88,15 @@ final class InputMethods {
         return sIsPreJellyBeanAsusTransformer && !Locale.getDefault().equals(Locale.US);
     }
 
     public static boolean needsSoftResetWorkaround(String inputMethod) {
         // Stock latin IME on Android 4.2 and above
         return Build.VERSION.SDK_INT >= 17 &&
                METHOD_STOCK_LATINIME.equals(inputMethod);
     }
+
+    public static boolean shouldDelayAwesomebarUpdate(Context context) {
+        String inputMethod = getCurrentInputMethod(context);
+        return METHOD_SAMSUNG.equals(inputMethod) ||
+               METHOD_SWIFTKEY.equals(inputMethod);
+    }
 }