1610f1dc8553cf2ed97e763a06a19380c4a6cd636satok/*
2610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * Copyright (C) 2011 The Android Open Source Project
3610f1dc8553cf2ed97e763a06a19380c4a6cd636satok *
4610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * Licensed under the Apache License, Version 2.0 (the "License");
5610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * you may not use this file except in compliance with the License.
6610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * You may obtain a copy of the License at
7610f1dc8553cf2ed97e763a06a19380c4a6cd636satok *
8610f1dc8553cf2ed97e763a06a19380c4a6cd636satok *      http://www.apache.org/licenses/LICENSE-2.0
9610f1dc8553cf2ed97e763a06a19380c4a6cd636satok *
10610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * Unless required by applicable law or agreed to in writing, software
11610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * distributed under the License is distributed on an "AS IS" BASIS,
12610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * See the License for the specific language governing permissions and
14610f1dc8553cf2ed97e763a06a19380c4a6cd636satok * limitations under the License.
15610f1dc8553cf2ed97e763a06a19380c4a6cd636satok */
16610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
17610f1dc8553cf2ed97e763a06a19380c4a6cd636satokpackage com.android.inputmethod.compat;
18610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
19610f1dc8553cf2ed97e763a06a19380c4a6cd636satokimport android.content.Context;
20610f1dc8553cf2ed97e763a06a19380c4a6cd636satokimport android.os.IBinder;
21610f1dc8553cf2ed97e763a06a19380c4a6cd636satokimport android.view.inputmethod.InputMethodManager;
229cc2c94c8b4bfd4e00e5d3478b9f6e520e791bc5Tadashi G. Takaokaimport android.view.inputmethod.InputMethodSubtype;
23610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
2455d28fd1b2631a63542a647f693d8a8ed749bcf7Tadashi G. Takaokaimport com.android.inputmethod.latin.ImfUtils;
2555d28fd1b2631a63542a647f693d8a8ed749bcf7Tadashi G. Takaoka
26610f1dc8553cf2ed97e763a06a19380c4a6cd636satokimport java.lang.reflect.Method;
27610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
28610f1dc8553cf2ed97e763a06a19380c4a6cd636satok// TODO: Override this class with the concrete implementation if we need to take care of the
29610f1dc8553cf2ed97e763a06a19380c4a6cd636satok// performance.
30610f1dc8553cf2ed97e763a06a19380c4a6cd636satokpublic class InputMethodManagerCompatWrapper {
31610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    private static final String TAG = InputMethodManagerCompatWrapper.class.getSimpleName();
3281d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka    private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod(
3381d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka            InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
34610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
35610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    private static final InputMethodManagerCompatWrapper sInstance =
36610f1dc8553cf2ed97e763a06a19380c4a6cd636satok            new InputMethodManagerCompatWrapper();
37610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
38610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    private InputMethodManager mImm;
3988fc9d44186120f9edc5cf7ec0e2af85260fed04satok
40fde7efd87710dcc9e8376e3ef6db287e254c65fcTadashi G. Takaoka    private InputMethodManagerCompatWrapper() {
41fde7efd87710dcc9e8376e3ef6db287e254c65fcTadashi G. Takaoka        // This wrapper class is not publicly instantiable.
42fde7efd87710dcc9e8376e3ef6db287e254c65fcTadashi G. Takaoka    }
43fde7efd87710dcc9e8376e3ef6db287e254c65fcTadashi G. Takaoka
44bf9d8348d89be257ccc3db75333bfd4cdf0a9b7eTadashi G. Takaoka    public static InputMethodManagerCompatWrapper getInstance() {
4555d28fd1b2631a63542a647f693d8a8ed749bcf7Tadashi G. Takaoka        if (sInstance.mImm == null) {
4655d28fd1b2631a63542a647f693d8a8ed749bcf7Tadashi G. Takaoka            throw new RuntimeException(TAG + ".getInstance() is called before initialization");
4755d28fd1b2631a63542a647f693d8a8ed749bcf7Tadashi G. Takaoka        }
48610f1dc8553cf2ed97e763a06a19380c4a6cd636satok        return sInstance;
49610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    }
50610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
518abde7db6bacbd5726a87e924ec8aea7fbb10d9aTadashi G. Takaoka    public static void init(Context context) {
5255d28fd1b2631a63542a647f693d8a8ed749bcf7Tadashi G. Takaoka        sInstance.mImm = ImfUtils.getInputMethodManager(context);
53610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    }
54610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
559cc2c94c8b4bfd4e00e5d3478b9f6e520e791bc5Tadashi G. Takaoka    public InputMethodSubtype getLastInputMethodSubtype() {
569cc2c94c8b4bfd4e00e5d3478b9f6e520e791bc5Tadashi G. Takaoka        return mImm.getLastInputMethodSubtype();
5781d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka    }
5881d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka
59610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    public boolean switchToLastInputMethod(IBinder token) {
609cc2c94c8b4bfd4e00e5d3478b9f6e520e791bc5Tadashi G. Takaoka        return mImm.switchToLastInputMethod(token);
61610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    }
62610f1dc8553cf2ed97e763a06a19380c4a6cd636satok
6381d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka    public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
6481d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka        return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToNextInputMethod, token,
6581d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka                onlyCurrentIme);
6681d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka    }
6781d4e3cd66a9388c47c7dba55240ddf849b31934Tadashi G. Takaoka
68610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    public void showInputMethodPicker() {
69911b8f9d19c1c4903eeef29b43176cfeaa0e5d0cKen Wakasa        mImm.showInputMethodPicker();
70610f1dc8553cf2ed97e763a06a19380c4a6cd636satok    }
71610f1dc8553cf2ed97e763a06a19380c4a6cd636satok}
72