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.view.inputmethod.InputMethodManager;
|
2012-04-02 12:31:52 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2011-03-18 05:49:06 +00:00
|
|
|
|
2012-04-18 08:39:57 +00:00
|
|
|
import com.android.inputmethod.latin.ImfUtils;
|
|
|
|
|
2011-03-18 05:49:06 +00:00
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
// 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() {
|
2012-04-18 08:39:57 +00:00
|
|
|
if (sInstance.mImm == null) {
|
|
|
|
throw new RuntimeException(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) {
|
2012-04-18 08:39:57 +00:00
|
|
|
sInstance.mImm = ImfUtils.getInputMethodManager(context);
|
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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-03-18 05:49:06 +00:00
|
|
|
public void showInputMethodPicker() {
|
2012-03-30 07:08:11 +00:00
|
|
|
mImm.showInputMethodPicker();
|
2011-03-18 05:49:06 +00:00
|
|
|
}
|
|
|
|
}
|