mobile/android/base/InputMethods.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 package org.mozilla.gecko;
     8 import org.mozilla.gecko.mozglue.RobocopTarget;
    10 import android.content.Context;
    11 import android.os.Build;
    12 import android.provider.Settings.Secure;
    13 import android.view.inputmethod.InputMethodInfo;
    14 import android.view.inputmethod.InputMethodManager;
    16 import java.util.Collection;
    17 import java.util.Locale;
    19 final public class InputMethods {
    20     public static final String METHOD_ANDROID_LATINIME = "com.android.inputmethod.latin/.LatinIME";
    21     public static final String METHOD_ATOK = "com.justsystems.atokmobile.service/.AtokInputMethodService";
    22     public static final String METHOD_GOOGLE_JAPANESE_INPUT = "com.google.android.inputmethod.japanese/.MozcService";
    23     public static final String METHOD_GOOGLE_LATINIME = "com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME";
    24     public static final String METHOD_HTC_TOUCH_INPUT = "com.htc.android.htcime/.HTCIMEService";
    25     public static final String METHOD_IWNN = "jp.co.omronsoft.iwnnime.ml/.standardcommon.IWnnLanguageSwitcher";
    26     public static final String METHOD_OPENWNN_PLUS = "com.owplus.ime.openwnnplus/.OpenWnnJAJP";
    27     public static final String METHOD_SAMSUNG = "com.sec.android.inputmethod/.SamsungKeypad";
    28     public static final String METHOD_SIMEJI = "com.adamrocker.android.input.simeji/.OpenWnnSimeji";
    29     public static final String METHOD_SWIFTKEY = "com.touchtype.swiftkey/com.touchtype.KeyboardService";
    30     public static final String METHOD_SWYPE = "com.swype.android.inputmethod/.SwypeInputMethod";
    31     public static final String METHOD_SWYPE_BETA = "com.nuance.swype.input/.IME";
    32     public static final String METHOD_TOUCHPAL_KEYBOARD = "com.cootek.smartinputv5/com.cootek.smartinput5.TouchPalIME";
    34     private InputMethods() {}
    36     public static String getCurrentInputMethod(Context context) {
    37         String inputMethod = Secure.getString(context.getContentResolver(), Secure.DEFAULT_INPUT_METHOD);
    38         return (inputMethod != null ? inputMethod : "");
    39     }
    41     public static InputMethodInfo getInputMethodInfo(Context context, String inputMethod) {
    42         InputMethodManager imm = getInputMethodManager(context);
    43         Collection<InputMethodInfo> infos = imm.getEnabledInputMethodList();
    44         for (InputMethodInfo info : infos) {
    45             if (info.getId().equals(inputMethod)) {
    46                 return info;
    47             }
    48         }
    49         return null;
    50     }
    52     public static InputMethodManager getInputMethodManager(Context context) {
    53         return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    54     }
    56     public static boolean needsSoftResetWorkaround(String inputMethod) {
    57         // Stock latin IME on Android 4.2 and above
    58         return Build.VERSION.SDK_INT >= 17 && (METHOD_ANDROID_LATINIME.equals(inputMethod) ||
    59                                                METHOD_GOOGLE_LATINIME.equals(inputMethod));
    60     }
    62     public static boolean shouldCommitCharAsKey(String inputMethod) {
    63         return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
    64     }
    66     @RobocopTarget
    67     public static boolean shouldDisableUrlBarUpdate(Context context) {
    68         String inputMethod = getCurrentInputMethod(context);
    69         // HTC Touch Input does not react well to restarting during input (bug 909940)
    70         return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
    71     }
    73     public static boolean shouldDelayUrlBarUpdate(Context context) {
    74         String inputMethod = getCurrentInputMethod(context);
    75         return METHOD_SAMSUNG.equals(inputMethod) ||
    76                METHOD_SWIFTKEY.equals(inputMethod);
    77     }
    79     public static boolean isGestureKeyboard(Context context) {
    80         // SwiftKey is a gesture keyboard, but it doesn't seem to need any special-casing
    81         // to do AwesomeBar auto-spacing.
    82         String inputMethod = getCurrentInputMethod(context);
    83         return (Build.VERSION.SDK_INT >= 17 && (METHOD_ANDROID_LATINIME.equals(inputMethod) ||
    84                                                 METHOD_GOOGLE_LATINIME.equals(inputMethod))) ||
    85                METHOD_SWYPE.equals(inputMethod) ||
    86                METHOD_SWYPE_BETA.equals(inputMethod) ||
    87                METHOD_TOUCHPAL_KEYBOARD.equals(inputMethod);
    88     }
    89 }

mercurial