mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Added InputMethodInfoCompatWrapper
Change-Id: I5f2970e986afbe3b0b24ccf819f57f524e83ef3f
This commit is contained in:
parent
6dd7778d22
commit
2e36fb68d0
@ -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 java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -68,26 +69,26 @@ public class InputMethodManagerCompatWrapper {
|
||||
}
|
||||
|
||||
public List<InputMethodSubtypeCompatWrapper> getEnabledInputMethodSubtypeList(
|
||||
InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes) {
|
||||
InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) {
|
||||
Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
|
||||
imi, allowsImplicitlySelectedSubtypes);
|
||||
(imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes);
|
||||
return CompatUtils.copyInputMethodSubtypeListToWrapper((List<?>)retval);
|
||||
}
|
||||
|
||||
public Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>
|
||||
public Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>>
|
||||
getShortcutInputMethodsAndSubtypes() {
|
||||
Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes);
|
||||
if (!(retval instanceof Map)) return null;
|
||||
Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcutMap =
|
||||
new HashMap<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>();
|
||||
Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>> shortcutMap =
|
||||
new HashMap<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>>();
|
||||
final Map<?, ?> retvalMap = (Map<?, ?>)retval;
|
||||
for (Object key: retvalMap.keySet()) {
|
||||
for (Object key : retvalMap.keySet()) {
|
||||
if (!(key instanceof InputMethodInfo)) {
|
||||
Log.e(TAG, "Class type error.");
|
||||
return null;
|
||||
}
|
||||
shortcutMap.put((InputMethodInfo)key, CompatUtils.copyInputMethodSubtypeListToWrapper(
|
||||
retvalMap.get(key)));
|
||||
shortcutMap.put(new InputMethodInfoCompatWrapper((InputMethodInfo)key),
|
||||
CompatUtils.copyInputMethodSubtypeListToWrapper(retvalMap.get(key)));
|
||||
}
|
||||
return shortcutMap;
|
||||
}
|
||||
@ -103,9 +104,13 @@ public class InputMethodManagerCompatWrapper {
|
||||
return mImm.switchToLastInputMethod(token);
|
||||
}
|
||||
|
||||
public List<InputMethodInfo> getEnabledInputMethodList() {
|
||||
public List<InputMethodInfoCompatWrapper> getEnabledInputMethodList() {
|
||||
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() {
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
|
||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
||||
import com.android.inputmethod.deprecated.VoiceConnector;
|
||||
@ -35,7 +36,6 @@ import android.os.AsyncTask;
|
||||
import android.os.IBinder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -71,7 +71,7 @@ public class SubtypeSwitcher {
|
||||
// Variants which should be changed only by reload functions.
|
||||
private boolean mNeedsToDisplayLanguage;
|
||||
private boolean mIsSystemLanguageSameAsInputLanguage;
|
||||
private InputMethodInfo mShortcutInputMethodInfo;
|
||||
private InputMethodInfoCompatWrapper mShortcutInputMethodInfo;
|
||||
private InputMethodSubtypeCompatWrapper mShortcutSubtype;
|
||||
private List<InputMethodSubtypeCompatWrapper> mAllEnabledSubtypesOfCurrentInputMethod;
|
||||
private InputMethodSubtypeCompatWrapper mCurrentSubtype;
|
||||
@ -184,9 +184,9 @@ public class SubtypeSwitcher {
|
||||
+ ", " + mShortcutSubtype.getMode())));
|
||||
}
|
||||
// TODO: Update an icon for shortcut IME
|
||||
Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcuts =
|
||||
final Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>> shortcuts =
|
||||
mImm.getShortcutInputMethodsAndSubtypes();
|
||||
for (InputMethodInfo imi: shortcuts.keySet()) {
|
||||
for (InputMethodInfoCompatWrapper imi : shortcuts.keySet()) {
|
||||
List<InputMethodSubtypeCompatWrapper> subtypes = shortcuts.get(imi);
|
||||
// TODO: Returns the first found IMI for now. Should handle all shortcuts as
|
||||
// appropriate.
|
||||
@ -333,7 +333,8 @@ public class SubtypeSwitcher {
|
||||
return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
|
||||
}
|
||||
|
||||
private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtypeCompatWrapper subtype) {
|
||||
private Drawable getSubtypeIcon(
|
||||
InputMethodInfoCompatWrapper imi, InputMethodSubtypeCompatWrapper subtype) {
|
||||
final PackageManager pm = mService.getPackageManager();
|
||||
if (imi != null) {
|
||||
final String imiPackageName = imi.getPackageName();
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
|
||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||
import com.android.inputmethod.keyboard.KeyboardId;
|
||||
|
||||
@ -29,7 +30,6 @@ import android.text.InputType;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -109,7 +109,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
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))
|
||||
return imi.getId();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user