2011-03-18 05:49:06 +00:00
|
|
|
/*
|
|
|
|
* 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.Context;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.inputmethod.InputMethodInfo;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2012-04-02 12:31:52 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2011-03-18 05:49:06 +00:00
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
// TODO: Override this class with the concrete implementation if we need to take care of the
|
|
|
|
// performance.
|
|
|
|
public class InputMethodManagerCompatWrapper {
|
|
|
|
private static final String TAG = InputMethodManagerCompatWrapper.class.getSimpleName();
|
2012-02-18 01:46:01 +00:00
|
|
|
private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod(
|
|
|
|
InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
|
2011-03-18 05:49:06 +00:00
|
|
|
|
|
|
|
private static final InputMethodManagerCompatWrapper sInstance =
|
|
|
|
new InputMethodManagerCompatWrapper();
|
|
|
|
|
|
|
|
private InputMethodManager mImm;
|
2011-04-08 10:57:13 +00:00
|
|
|
|
2012-04-03 09:01:04 +00:00
|
|
|
private InputMethodManagerCompatWrapper() {
|
|
|
|
// This wrapper class is not publicly instantiable.
|
|
|
|
}
|
|
|
|
|
2011-07-18 04:18:47 +00:00
|
|
|
public static InputMethodManagerCompatWrapper getInstance() {
|
|
|
|
if (sInstance.mImm == null)
|
|
|
|
Log.w(TAG, "getInstance() is called before initialization");
|
2011-03-18 05:49:06 +00:00
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
2012-04-13 04:07:28 +00:00
|
|
|
public static void init(Context context) {
|
|
|
|
sInstance.mImm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 09:21:10 +00:00
|
|
|
public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
|
|
|
|
mImm.setAdditionalInputMethodSubtypes(imiId, subtypes);
|
|
|
|
}
|
|
|
|
|
2012-04-02 12:31:52 +00:00
|
|
|
public InputMethodSubtype getCurrentInputMethodSubtype() {
|
|
|
|
return mImm.getCurrentInputMethodSubtype();
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 12:31:52 +00:00
|
|
|
public InputMethodSubtype getLastInputMethodSubtype() {
|
|
|
|
return mImm.getLastInputMethodSubtype();
|
2012-02-18 01:46:01 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 12:31:52 +00:00
|
|
|
public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(
|
2012-04-02 11:54:17 +00:00
|
|
|
InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes) {
|
2012-04-02 12:31:52 +00:00
|
|
|
return mImm.getEnabledInputMethodSubtypeList(imi, allowsImplicitlySelectedSubtypes);
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 12:31:52 +00:00
|
|
|
public Map<InputMethodInfo, List<InputMethodSubtype>> getShortcutInputMethodsAndSubtypes() {
|
|
|
|
return mImm.getShortcutInputMethodsAndSubtypes();
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
|
2011-07-18 04:18:47 +00:00
|
|
|
// We don't call this method when we switch between subtypes within this IME.
|
2012-04-02 12:31:52 +00:00
|
|
|
public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
|
|
|
|
mImm.setInputMethodAndSubtype(token, id, subtype);
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean switchToLastInputMethod(IBinder token) {
|
2012-04-02 12:31:52 +00:00
|
|
|
return mImm.switchToLastInputMethod(token);
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 01:46:01 +00:00
|
|
|
public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
|
|
|
|
return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToNextInputMethod, token,
|
|
|
|
onlyCurrentIme);
|
|
|
|
}
|
|
|
|
|
2012-04-13 04:07:28 +00:00
|
|
|
public List<InputMethodInfo> getInputMethodList() {
|
|
|
|
if (mImm == null) return null;
|
|
|
|
return mImm.getInputMethodList();
|
|
|
|
}
|
|
|
|
|
2012-04-02 11:54:17 +00:00
|
|
|
public List<InputMethodInfo> getEnabledInputMethodList() {
|
2011-03-18 05:49:06 +00:00
|
|
|
if (mImm == null) return null;
|
2012-04-02 11:54:17 +00:00
|
|
|
return mImm.getEnabledInputMethodList();
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void showInputMethodPicker() {
|
|
|
|
if (mImm == null) return;
|
2012-03-30 07:08:11 +00:00
|
|
|
mImm.showInputMethodPicker();
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
}
|