michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko; michael@0: michael@0: import org.mozilla.gecko.mozglue.RobocopTarget; michael@0: michael@0: import android.content.Context; michael@0: import android.os.Build; michael@0: import android.provider.Settings.Secure; michael@0: import android.view.inputmethod.InputMethodInfo; michael@0: import android.view.inputmethod.InputMethodManager; michael@0: michael@0: import java.util.Collection; michael@0: import java.util.Locale; michael@0: michael@0: final public class InputMethods { michael@0: public static final String METHOD_ANDROID_LATINIME = "com.android.inputmethod.latin/.LatinIME"; michael@0: public static final String METHOD_ATOK = "com.justsystems.atokmobile.service/.AtokInputMethodService"; michael@0: public static final String METHOD_GOOGLE_JAPANESE_INPUT = "com.google.android.inputmethod.japanese/.MozcService"; michael@0: public static final String METHOD_GOOGLE_LATINIME = "com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME"; michael@0: public static final String METHOD_HTC_TOUCH_INPUT = "com.htc.android.htcime/.HTCIMEService"; michael@0: public static final String METHOD_IWNN = "jp.co.omronsoft.iwnnime.ml/.standardcommon.IWnnLanguageSwitcher"; michael@0: public static final String METHOD_OPENWNN_PLUS = "com.owplus.ime.openwnnplus/.OpenWnnJAJP"; michael@0: public static final String METHOD_SAMSUNG = "com.sec.android.inputmethod/.SamsungKeypad"; michael@0: public static final String METHOD_SIMEJI = "com.adamrocker.android.input.simeji/.OpenWnnSimeji"; michael@0: public static final String METHOD_SWIFTKEY = "com.touchtype.swiftkey/com.touchtype.KeyboardService"; michael@0: public static final String METHOD_SWYPE = "com.swype.android.inputmethod/.SwypeInputMethod"; michael@0: public static final String METHOD_SWYPE_BETA = "com.nuance.swype.input/.IME"; michael@0: public static final String METHOD_TOUCHPAL_KEYBOARD = "com.cootek.smartinputv5/com.cootek.smartinput5.TouchPalIME"; michael@0: michael@0: private InputMethods() {} michael@0: michael@0: public static String getCurrentInputMethod(Context context) { michael@0: String inputMethod = Secure.getString(context.getContentResolver(), Secure.DEFAULT_INPUT_METHOD); michael@0: return (inputMethod != null ? inputMethod : ""); michael@0: } michael@0: michael@0: public static InputMethodInfo getInputMethodInfo(Context context, String inputMethod) { michael@0: InputMethodManager imm = getInputMethodManager(context); michael@0: Collection infos = imm.getEnabledInputMethodList(); michael@0: for (InputMethodInfo info : infos) { michael@0: if (info.getId().equals(inputMethod)) { michael@0: return info; michael@0: } michael@0: } michael@0: return null; michael@0: } michael@0: michael@0: public static InputMethodManager getInputMethodManager(Context context) { michael@0: return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); michael@0: } michael@0: michael@0: public static boolean needsSoftResetWorkaround(String inputMethod) { michael@0: // Stock latin IME on Android 4.2 and above michael@0: return Build.VERSION.SDK_INT >= 17 && (METHOD_ANDROID_LATINIME.equals(inputMethod) || michael@0: METHOD_GOOGLE_LATINIME.equals(inputMethod)); michael@0: } michael@0: michael@0: public static boolean shouldCommitCharAsKey(String inputMethod) { michael@0: return METHOD_HTC_TOUCH_INPUT.equals(inputMethod); michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public static boolean shouldDisableUrlBarUpdate(Context context) { michael@0: String inputMethod = getCurrentInputMethod(context); michael@0: // HTC Touch Input does not react well to restarting during input (bug 909940) michael@0: return METHOD_HTC_TOUCH_INPUT.equals(inputMethod); michael@0: } michael@0: michael@0: public static boolean shouldDelayUrlBarUpdate(Context context) { michael@0: String inputMethod = getCurrentInputMethod(context); michael@0: return METHOD_SAMSUNG.equals(inputMethod) || michael@0: METHOD_SWIFTKEY.equals(inputMethod); michael@0: } michael@0: michael@0: public static boolean isGestureKeyboard(Context context) { michael@0: // SwiftKey is a gesture keyboard, but it doesn't seem to need any special-casing michael@0: // to do AwesomeBar auto-spacing. michael@0: String inputMethod = getCurrentInputMethod(context); michael@0: return (Build.VERSION.SDK_INT >= 17 && (METHOD_ANDROID_LATINIME.equals(inputMethod) || michael@0: METHOD_GOOGLE_LATINIME.equals(inputMethod))) || michael@0: METHOD_SWYPE.equals(inputMethod) || michael@0: METHOD_SWYPE_BETA.equals(inputMethod) || michael@0: METHOD_TOUCHPAL_KEYBOARD.equals(inputMethod); michael@0: } michael@0: }