Merge "Remove InputMethodInfoCompatWrapper"

main
Tadashi G. Takaoka 2012-04-02 07:14:20 -07:00 committed by Android (Google) Code Review
commit b1904ec235
4 changed files with 26 additions and 116 deletions

View File

@ -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();
}
}

View File

@ -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<InputMethodSubtypeCompatWrapper> 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<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>>
public Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>
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<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>>
Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>
shortcutMap =
new HashMap<InputMethodInfoCompatWrapper,
new HashMap<InputMethodInfo,
List<InputMethodSubtypeCompatWrapper>>();
List<InputMethodSubtypeCompatWrapper> subtypeList =
new ArrayList<InputMethodSubtypeCompatWrapper>();
@ -172,15 +166,15 @@ public class InputMethodManagerCompatWrapper {
return Collections.emptyMap();
}
}
Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>> shortcutMap =
new HashMap<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>>();
Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcutMap =
new HashMap<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>();
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<InputMethodInfoCompatWrapper> getEnabledInputMethodList() {
public List<InputMethodInfo> getEnabledInputMethodList() {
if (mImm == null) return null;
List<InputMethodInfoCompatWrapper> imis = new ArrayList<InputMethodInfoCompatWrapper>();
for (InputMethodInfo imi : mImm.getEnabledInputMethodList()) {
imis.add(new InputMethodInfoCompatWrapper(imi));
}
return imis;
return mImm.getEnabledInputMethodList();
}
public void showInputMethodPicker() {

View File

@ -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<InputMethodSubtypeCompatWrapper> mAllEnabledSubtypesOfCurrentInputMethod;
private InputMethodSubtypeCompatWrapper mCurrentSubtype;
@ -168,11 +166,11 @@ public class SubtypeSwitcher {
+ ", " + mShortcutSubtype.getMode())));
}
// TODO: Update an icon for shortcut IME
final Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>> shortcuts =
final Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcuts =
mImm.getShortcutInputMethodsAndSubtypes();
mShortcutInputMethodInfo = null;
mShortcutSubtype = null;
for (InputMethodInfoCompatWrapper imi : shortcuts.keySet()) {
for (InputMethodInfo imi : shortcuts.keySet()) {
List<InputMethodSubtypeCompatWrapper> 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();

View File

@ -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<InputMethodSubtypeCompatWrapper> 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<InputMethodInfoCompatWrapper> enabledImis = imm.getEnabledInputMethodList();
final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis);
}
public static boolean hasMultipleEnabledSubtypesInThisIme(Context context,
final boolean shouldIncludeAuxiliarySubtypes) {
final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName());
final List<InputMethodInfoCompatWrapper> imiList = Collections.singletonList(myImi);
final InputMethodInfo myImi = getInputMethodInfo(context.getPackageName());
final List<InputMethodInfo> imiList = Collections.singletonList(myImi);
return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList);
}
private static boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes,
List<InputMethodInfoCompatWrapper> imiList) {
List<InputMethodInfo> 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<InputMethodSubtypeCompatWrapper> 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;
}