Merge "Added InputMethodInfoCompatWrapper"
commit
1ddf2a1808
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* 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.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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -68,26 +69,26 @@ public class InputMethodManagerCompatWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<InputMethodSubtypeCompatWrapper> getEnabledInputMethodSubtypeList(
|
public List<InputMethodSubtypeCompatWrapper> getEnabledInputMethodSubtypeList(
|
||||||
InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes) {
|
InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) {
|
||||||
Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
|
Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
|
||||||
imi, allowsImplicitlySelectedSubtypes);
|
(imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes);
|
||||||
return CompatUtils.copyInputMethodSubtypeListToWrapper((List<?>)retval);
|
return CompatUtils.copyInputMethodSubtypeListToWrapper((List<?>)retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>
|
public Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>>
|
||||||
getShortcutInputMethodsAndSubtypes() {
|
getShortcutInputMethodsAndSubtypes() {
|
||||||
Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes);
|
Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes);
|
||||||
if (!(retval instanceof Map)) return null;
|
if (!(retval instanceof Map)) return null;
|
||||||
Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcutMap =
|
Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>> shortcutMap =
|
||||||
new HashMap<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>();
|
new HashMap<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>>();
|
||||||
final Map<?, ?> retvalMap = (Map<?, ?>)retval;
|
final Map<?, ?> retvalMap = (Map<?, ?>)retval;
|
||||||
for (Object key: retvalMap.keySet()) {
|
for (Object key : retvalMap.keySet()) {
|
||||||
if (!(key instanceof InputMethodInfo)) {
|
if (!(key instanceof InputMethodInfo)) {
|
||||||
Log.e(TAG, "Class type error.");
|
Log.e(TAG, "Class type error.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
shortcutMap.put((InputMethodInfo)key, CompatUtils.copyInputMethodSubtypeListToWrapper(
|
shortcutMap.put(new InputMethodInfoCompatWrapper((InputMethodInfo)key),
|
||||||
retvalMap.get(key)));
|
CompatUtils.copyInputMethodSubtypeListToWrapper(retvalMap.get(key)));
|
||||||
}
|
}
|
||||||
return shortcutMap;
|
return shortcutMap;
|
||||||
}
|
}
|
||||||
|
@ -103,9 +104,13 @@ public class InputMethodManagerCompatWrapper {
|
||||||
return mImm.switchToLastInputMethod(token);
|
return mImm.switchToLastInputMethod(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<InputMethodInfo> getEnabledInputMethodList() {
|
public List<InputMethodInfoCompatWrapper> getEnabledInputMethodList() {
|
||||||
if (mImm == null) return null;
|
if (mImm == null) return null;
|
||||||
return mImm.getEnabledInputMethodList();
|
List<InputMethodInfoCompatWrapper> imis = new ArrayList<InputMethodInfoCompatWrapper>();
|
||||||
|
for (InputMethodInfo imi : mImm.getEnabledInputMethodList()) {
|
||||||
|
imis.add(new InputMethodInfoCompatWrapper(imi));
|
||||||
|
}
|
||||||
|
return imis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showInputMethodPicker() {
|
public void showInputMethodPicker() {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
||||||
import com.android.inputmethod.deprecated.VoiceProxy;
|
import com.android.inputmethod.deprecated.VoiceProxy;
|
||||||
|
@ -35,7 +36,6 @@ import android.os.AsyncTask;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -71,7 +71,7 @@ public class SubtypeSwitcher {
|
||||||
// Variants which should be changed only by reload functions.
|
// Variants which should be changed only by reload functions.
|
||||||
private boolean mNeedsToDisplayLanguage;
|
private boolean mNeedsToDisplayLanguage;
|
||||||
private boolean mIsSystemLanguageSameAsInputLanguage;
|
private boolean mIsSystemLanguageSameAsInputLanguage;
|
||||||
private InputMethodInfo mShortcutInputMethodInfo;
|
private InputMethodInfoCompatWrapper mShortcutInputMethodInfo;
|
||||||
private InputMethodSubtypeCompatWrapper mShortcutSubtype;
|
private InputMethodSubtypeCompatWrapper mShortcutSubtype;
|
||||||
private List<InputMethodSubtypeCompatWrapper> mAllEnabledSubtypesOfCurrentInputMethod;
|
private List<InputMethodSubtypeCompatWrapper> mAllEnabledSubtypesOfCurrentInputMethod;
|
||||||
private InputMethodSubtypeCompatWrapper mCurrentSubtype;
|
private InputMethodSubtypeCompatWrapper mCurrentSubtype;
|
||||||
|
@ -184,9 +184,9 @@ public class SubtypeSwitcher {
|
||||||
+ ", " + mShortcutSubtype.getMode())));
|
+ ", " + mShortcutSubtype.getMode())));
|
||||||
}
|
}
|
||||||
// TODO: Update an icon for shortcut IME
|
// TODO: Update an icon for shortcut IME
|
||||||
Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcuts =
|
final Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>> shortcuts =
|
||||||
mImm.getShortcutInputMethodsAndSubtypes();
|
mImm.getShortcutInputMethodsAndSubtypes();
|
||||||
for (InputMethodInfo imi: shortcuts.keySet()) {
|
for (InputMethodInfoCompatWrapper imi : shortcuts.keySet()) {
|
||||||
List<InputMethodSubtypeCompatWrapper> subtypes = shortcuts.get(imi);
|
List<InputMethodSubtypeCompatWrapper> subtypes = shortcuts.get(imi);
|
||||||
// TODO: Returns the first found IMI for now. Should handle all shortcuts as
|
// TODO: Returns the first found IMI for now. Should handle all shortcuts as
|
||||||
// appropriate.
|
// appropriate.
|
||||||
|
@ -333,7 +333,8 @@ public class SubtypeSwitcher {
|
||||||
return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
|
return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtypeCompatWrapper subtype) {
|
private Drawable getSubtypeIcon(
|
||||||
|
InputMethodInfoCompatWrapper imi, InputMethodSubtypeCompatWrapper subtype) {
|
||||||
final PackageManager pm = mService.getPackageManager();
|
final PackageManager pm = mService.getPackageManager();
|
||||||
if (imi != null) {
|
if (imi != null) {
|
||||||
final String imiPackageName = imi.getPackageName();
|
final String imiPackageName = imi.getPackageName();
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||||
import com.android.inputmethod.keyboard.KeyboardId;
|
import com.android.inputmethod.keyboard.KeyboardId;
|
||||||
|
|
||||||
|
@ -29,7 +30,6 @@ import android.text.InputType;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -109,7 +109,7 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getInputMethodId(InputMethodManagerCompatWrapper imm, String packageName) {
|
public static String getInputMethodId(InputMethodManagerCompatWrapper imm, String packageName) {
|
||||||
for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
|
for (final InputMethodInfoCompatWrapper imi : imm.getEnabledInputMethodList()) {
|
||||||
if (imi.getPackageName().equals(packageName))
|
if (imi.getPackageName().equals(packageName))
|
||||||
return imi.getId();
|
return imi.getId();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue