mobile/android/base/InputMethods.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/InputMethods.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko;
    1.10 +
    1.11 +import org.mozilla.gecko.mozglue.RobocopTarget;
    1.12 +
    1.13 +import android.content.Context;
    1.14 +import android.os.Build;
    1.15 +import android.provider.Settings.Secure;
    1.16 +import android.view.inputmethod.InputMethodInfo;
    1.17 +import android.view.inputmethod.InputMethodManager;
    1.18 +
    1.19 +import java.util.Collection;
    1.20 +import java.util.Locale;
    1.21 +
    1.22 +final public class InputMethods {
    1.23 +    public static final String METHOD_ANDROID_LATINIME = "com.android.inputmethod.latin/.LatinIME";
    1.24 +    public static final String METHOD_ATOK = "com.justsystems.atokmobile.service/.AtokInputMethodService";
    1.25 +    public static final String METHOD_GOOGLE_JAPANESE_INPUT = "com.google.android.inputmethod.japanese/.MozcService";
    1.26 +    public static final String METHOD_GOOGLE_LATINIME = "com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME";
    1.27 +    public static final String METHOD_HTC_TOUCH_INPUT = "com.htc.android.htcime/.HTCIMEService";
    1.28 +    public static final String METHOD_IWNN = "jp.co.omronsoft.iwnnime.ml/.standardcommon.IWnnLanguageSwitcher";
    1.29 +    public static final String METHOD_OPENWNN_PLUS = "com.owplus.ime.openwnnplus/.OpenWnnJAJP";
    1.30 +    public static final String METHOD_SAMSUNG = "com.sec.android.inputmethod/.SamsungKeypad";
    1.31 +    public static final String METHOD_SIMEJI = "com.adamrocker.android.input.simeji/.OpenWnnSimeji";
    1.32 +    public static final String METHOD_SWIFTKEY = "com.touchtype.swiftkey/com.touchtype.KeyboardService";
    1.33 +    public static final String METHOD_SWYPE = "com.swype.android.inputmethod/.SwypeInputMethod";
    1.34 +    public static final String METHOD_SWYPE_BETA = "com.nuance.swype.input/.IME";
    1.35 +    public static final String METHOD_TOUCHPAL_KEYBOARD = "com.cootek.smartinputv5/com.cootek.smartinput5.TouchPalIME";
    1.36 +
    1.37 +    private InputMethods() {}
    1.38 +
    1.39 +    public static String getCurrentInputMethod(Context context) {
    1.40 +        String inputMethod = Secure.getString(context.getContentResolver(), Secure.DEFAULT_INPUT_METHOD);
    1.41 +        return (inputMethod != null ? inputMethod : "");
    1.42 +    }
    1.43 +
    1.44 +    public static InputMethodInfo getInputMethodInfo(Context context, String inputMethod) {
    1.45 +        InputMethodManager imm = getInputMethodManager(context);
    1.46 +        Collection<InputMethodInfo> infos = imm.getEnabledInputMethodList();
    1.47 +        for (InputMethodInfo info : infos) {
    1.48 +            if (info.getId().equals(inputMethod)) {
    1.49 +                return info;
    1.50 +            }
    1.51 +        }
    1.52 +        return null;
    1.53 +    }
    1.54 +
    1.55 +    public static InputMethodManager getInputMethodManager(Context context) {
    1.56 +        return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    1.57 +    }
    1.58 +
    1.59 +    public static boolean needsSoftResetWorkaround(String inputMethod) {
    1.60 +        // Stock latin IME on Android 4.2 and above
    1.61 +        return Build.VERSION.SDK_INT >= 17 && (METHOD_ANDROID_LATINIME.equals(inputMethod) ||
    1.62 +                                               METHOD_GOOGLE_LATINIME.equals(inputMethod));
    1.63 +    }
    1.64 +
    1.65 +    public static boolean shouldCommitCharAsKey(String inputMethod) {
    1.66 +        return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
    1.67 +    }
    1.68 +
    1.69 +    @RobocopTarget
    1.70 +    public static boolean shouldDisableUrlBarUpdate(Context context) {
    1.71 +        String inputMethod = getCurrentInputMethod(context);
    1.72 +        // HTC Touch Input does not react well to restarting during input (bug 909940)
    1.73 +        return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
    1.74 +    }
    1.75 +
    1.76 +    public static boolean shouldDelayUrlBarUpdate(Context context) {
    1.77 +        String inputMethod = getCurrentInputMethod(context);
    1.78 +        return METHOD_SAMSUNG.equals(inputMethod) ||
    1.79 +               METHOD_SWIFTKEY.equals(inputMethod);
    1.80 +    }
    1.81 +
    1.82 +    public static boolean isGestureKeyboard(Context context) {
    1.83 +        // SwiftKey is a gesture keyboard, but it doesn't seem to need any special-casing
    1.84 +        // to do AwesomeBar auto-spacing.
    1.85 +        String inputMethod = getCurrentInputMethod(context);
    1.86 +        return (Build.VERSION.SDK_INT >= 17 && (METHOD_ANDROID_LATINIME.equals(inputMethod) ||
    1.87 +                                                METHOD_GOOGLE_LATINIME.equals(inputMethod))) ||
    1.88 +               METHOD_SWYPE.equals(inputMethod) ||
    1.89 +               METHOD_SWYPE_BETA.equals(inputMethod) ||
    1.90 +               METHOD_TOUCHPAL_KEYBOARD.equals(inputMethod);
    1.91 +    }
    1.92 +}

mercurial