From 0dbf6ab53d53e4cb08052310f38ae41662e27c8d Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 2 Apr 2012 20:54:17 +0900 Subject: [PATCH] Remove InputMethodInfoCompatWrapper Bug: 6129704 Change-Id: I0eca1ee7d1769ddc44f93c50f0723196299bc6d6 --- .../compat/InputMethodInfoCompatWrapper.java | 77 ------------------- .../InputMethodManagerCompatWrapper.java | 34 +++----- .../inputmethod/latin/SubtypeSwitcher.java | 13 ++-- .../inputmethod/latin/SubtypeUtils.java | 18 ++--- 4 files changed, 26 insertions(+), 116 deletions(-) delete mode 100644 java/src/com/android/inputmethod/compat/InputMethodInfoCompatWrapper.java diff --git a/java/src/com/android/inputmethod/compat/InputMethodInfoCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodInfoCompatWrapper.java deleted file mode 100644 index 831559809..000000000 --- a/java/src/com/android/inputmethod/compat/InputMethodInfoCompatWrapper.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.inputmethod.compat; - -import android.content.pm.PackageManager; -import android.content.pm.ServiceInfo; -import android.view.inputmethod.InputMethodInfo; - -import java.lang.reflect.Method; - -public class InputMethodInfoCompatWrapper { - private final InputMethodInfo mImi; - private static final Method METHOD_getSubtypeAt = CompatUtils.getMethod( - InputMethodInfo.class, "getSubtypeAt", int.class); - private static final Method METHOD_getSubtypeCount = CompatUtils.getMethod( - InputMethodInfo.class, "getSubtypeCount"); - - public InputMethodInfoCompatWrapper(InputMethodInfo imi) { - mImi = imi; - } - - public InputMethodInfo getInputMethodInfo() { - return mImi; - } - - public String getId() { - return mImi.getId(); - } - - public String getPackageName() { - return mImi.getPackageName(); - } - - public ServiceInfo getServiceInfo() { - return mImi.getServiceInfo(); - } - - public int getSubtypeCount() { - return (Integer) CompatUtils.invoke(mImi, 0, METHOD_getSubtypeCount); - } - - public InputMethodSubtypeCompatWrapper getSubtypeAt(int index) { - return new InputMethodSubtypeCompatWrapper(CompatUtils.invoke(mImi, null, - METHOD_getSubtypeAt, index)); - } - - public CharSequence loadLabel(PackageManager pm) { - return mImi.loadLabel(pm); - } - - @Override - public boolean equals(Object o) { - if (o instanceof InputMethodInfoCompatWrapper) { - return mImi.equals(((InputMethodInfoCompatWrapper)o).mImi); - } - return false; - } - - @Override - public int hashCode() { - return mImi.hashCode(); - } -} diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java index 3df6bea4b..cf6b37979 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java @@ -16,11 +16,7 @@ package com.android.inputmethod.compat; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.IBinder; @@ -29,14 +25,12 @@ import android.util.Log; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; -import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeUtils; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -106,9 +100,9 @@ public class InputMethodManagerCompatWrapper { } public List getEnabledInputMethodSubtypeList( - InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) { + InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes) { Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList, - (imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes); + imi, allowsImplicitlySelectedSubtypes); if (retval == null || !(retval instanceof List) || ((List)retval).isEmpty()) { if (!FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES) { // Returns an empty list @@ -131,7 +125,7 @@ public class InputMethodManagerCompatWrapper { return CompatUtils.copyInputMethodSubtypeListToWrapper(retval); } - private InputMethodInfoCompatWrapper getLatinImeInputMethodInfo() { + private InputMethodInfo getLatinImeInputMethodInfo() { if (TextUtils.isEmpty(mLatinImePackageName)) return null; return SubtypeUtils.getInputMethodInfo(mLatinImePackageName); @@ -146,7 +140,7 @@ public class InputMethodManagerCompatWrapper { return new InputMethodSubtypeCompatWrapper(0, 0, inputLocale.toString(), mode, ""); } - public Map> + public Map> getShortcutInputMethodsAndSubtypes() { Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes); if (retval == null || !(retval instanceof Map) || ((Map)retval).isEmpty()) { @@ -156,12 +150,12 @@ public class InputMethodManagerCompatWrapper { } // Creates dummy subtypes @SuppressWarnings("unused") - InputMethodInfoCompatWrapper imi = getLatinImeInputMethodInfo(); + InputMethodInfo imi = getLatinImeInputMethodInfo(); InputMethodSubtypeCompatWrapper voiceSubtype = getLastResortSubtype(VOICE_MODE); if (imi != null && voiceSubtype != null) { - Map> + Map> shortcutMap = - new HashMap>(); List subtypeList = new ArrayList(); @@ -172,15 +166,15 @@ public class InputMethodManagerCompatWrapper { return Collections.emptyMap(); } } - Map> shortcutMap = - new HashMap>(); + Map> shortcutMap = + new HashMap>(); final Map retvalMap = (Map)retval; for (Object key : retvalMap.keySet()) { if (!(key instanceof InputMethodInfo)) { Log.e(TAG, "Class type error."); return null; } - shortcutMap.put(new InputMethodInfoCompatWrapper((InputMethodInfo)key), + shortcutMap.put((InputMethodInfo)key, CompatUtils.copyInputMethodSubtypeListToWrapper(retvalMap.get(key))); } return shortcutMap; @@ -207,13 +201,9 @@ public class InputMethodManagerCompatWrapper { onlyCurrentIme); } - public List getEnabledInputMethodList() { + public List getEnabledInputMethodList() { if (mImm == null) return null; - List imis = new ArrayList(); - for (InputMethodInfo imi : mImm.getEnabledInputMethodList()) { - imis.add(new InputMethodInfoCompatWrapper(imi)); - } - return imis; + return mImm.getEnabledInputMethodList(); } public void showInputMethodPicker() { diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index de2e8be3d..5cdee1435 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -29,14 +29,13 @@ import android.os.AsyncTask; import android.os.IBinder; import android.text.TextUtils; import android.util.Log; +import android.view.inputmethod.InputMethodInfo; -import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; import com.android.inputmethod.keyboard.KeyboardSwitcher; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Map; @@ -47,7 +46,6 @@ public class SubtypeSwitcher { public static final String KEYBOARD_MODE = "keyboard"; private static final char LOCALE_SEPARATOR = '_'; - private static final String VOICE_MODE = "voice"; private static final String SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY = "requireNetworkConnectivity"; @@ -68,7 +66,7 @@ public class SubtypeSwitcher { // Variants which should be changed only by reload functions. private boolean mNeedsToDisplayLanguage; private boolean mIsSystemLanguageSameAsInputLanguage; - private InputMethodInfoCompatWrapper mShortcutInputMethodInfo; + private InputMethodInfo mShortcutInputMethodInfo; private InputMethodSubtypeCompatWrapper mShortcutSubtype; private List mAllEnabledSubtypesOfCurrentInputMethod; private InputMethodSubtypeCompatWrapper mCurrentSubtype; @@ -168,11 +166,11 @@ public class SubtypeSwitcher { + ", " + mShortcutSubtype.getMode()))); } // TODO: Update an icon for shortcut IME - final Map> shortcuts = + final Map> shortcuts = mImm.getShortcutInputMethodsAndSubtypes(); mShortcutInputMethodInfo = null; mShortcutSubtype = null; - for (InputMethodInfoCompatWrapper imi : shortcuts.keySet()) { + for (InputMethodInfo imi : shortcuts.keySet()) { List subtypes = shortcuts.get(imi); // TODO: Returns the first found IMI for now. Should handle all shortcuts as // appropriate. @@ -320,8 +318,7 @@ public class SubtypeSwitcher { return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype); } - private Drawable getSubtypeIcon( - InputMethodInfoCompatWrapper imi, InputMethodSubtypeCompatWrapper subtype) { + private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtypeCompatWrapper subtype) { final PackageManager pm = mService.getPackageManager(); if (imi != null) { final String imiPackageName = imi.getPackageName(); diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java index cb2bcf43f..8beb71bf1 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeUtils.java +++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java @@ -17,8 +17,8 @@ package com.android.inputmethod.latin; import android.content.Context; +import android.view.inputmethod.InputMethodInfo; -import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; @@ -36,7 +36,7 @@ public class SubtypeUtils { final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); if (imm == null) return false; - final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName()); + final InputMethodInfo myImi = getInputMethodInfo(context.getPackageName()); final List subtypes = imm.getEnabledInputMethodSubtypeList(myImi, true); for (final InputMethodSubtypeCompatWrapper subtype : subtypes) { @@ -52,26 +52,26 @@ public class SubtypeUtils { final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); if (imm == null) return false; - final List enabledImis = imm.getEnabledInputMethodList(); + final List enabledImis = imm.getEnabledInputMethodList(); return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis); } public static boolean hasMultipleEnabledSubtypesInThisIme(Context context, final boolean shouldIncludeAuxiliarySubtypes) { - final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName()); - final List imiList = Collections.singletonList(myImi); + final InputMethodInfo myImi = getInputMethodInfo(context.getPackageName()); + final List imiList = Collections.singletonList(myImi); return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList); } private static boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes, - List imiList) { + List imiList) { final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); if (imm == null) return false; // Number of the filtered IMEs int filteredImisCount = 0; - for (InputMethodInfoCompatWrapper imi : imiList) { + for (InputMethodInfo imi : imiList) { // We can return true immediately after we find two or more filtered IMEs. if (filteredImisCount > 1) return true; final List subtypes = @@ -120,13 +120,13 @@ public class SubtypeUtils { return getInputMethodInfo(packageName).getId(); } - public static InputMethodInfoCompatWrapper getInputMethodInfo(String packageName) { + public static InputMethodInfo getInputMethodInfo(String packageName) { final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); if (imm == null) { throw new RuntimeException("Input method manager not found"); } - for (final InputMethodInfoCompatWrapper imi : imm.getEnabledInputMethodList()) { + for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) { if (imi.getPackageName().equals(packageName)) return imi; }