mobile/android/base/InputMethods.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial