1a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.org// Copyright 2013 The Chromium Authors. All rights reserved.
2a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.org// Use of this source code is governed by a BSD-style license that can be
3a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.org// found in the LICENSE file.
4a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.org
5a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.orgpackage org.chromium.content.browser.input;
6a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.org
7a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.orgimport android.content.Context;
8a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.orgimport android.os.IBinder;
9a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.orgimport android.os.ResultReceiver;
10a908a27056e1931a1726b9c55d9f4e96aec2bffescottmg@chromium.orgimport android.view.View;
11import android.view.inputmethod.InputMethodManager;
12
13/**
14 * Wrapper around Android's InputMethodManager
15 */
16public class InputMethodManagerWrapper {
17    private final Context mContext;
18
19    public InputMethodManagerWrapper(Context context) {
20        mContext = context;
21    }
22
23    private InputMethodManager getInputMethodManager() {
24        return (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
25    }
26
27    /**
28     * @see android.view.inputmethod.InputMethodManager#restartInput(View)
29     */
30    public void restartInput(View view) {
31        getInputMethodManager().restartInput(view);
32    }
33
34    /**
35     * @see android.view.inputmethod.InputMethodManager#showSoftInput(View, int, ResultReceiver)
36     */
37    public void showSoftInput(View view, int flags, ResultReceiver resultReceiver) {
38        getInputMethodManager().showSoftInput(view, flags, resultReceiver);
39    }
40
41    /**
42     * @see android.view.inputmethod.InputMethodManager#isActive(View)
43     */
44    public boolean isActive(View view) {
45        return getInputMethodManager().isActive(view);
46    }
47
48    /**
49     * @see InputMethodManager#hideSoftInputFromWindow(IBinder, int, ResultReceiver)
50     */
51    public boolean hideSoftInputFromWindow(IBinder windowToken, int flags,
52            ResultReceiver resultReceiver) {
53        return getInputMethodManager().hideSoftInputFromWindow(windowToken, flags, resultReceiver);
54    }
55
56    /**
57     * @see android.view.inputmethod.InputMethodManager#updateSelection(View, int, int, int, int)
58     */
59    public void updateSelection(View view, int selStart, int selEnd,
60            int candidatesStart, int candidatesEnd) {
61        getInputMethodManager().updateSelection(view, selStart, selEnd, candidatesStart,
62                candidatesEnd);
63    }
64
65    /**
66     * @see android.view.inputmethod.InputMethodManager#isWatchingCursor(View)
67     */
68    @SuppressWarnings("deprecation")
69    public boolean isWatchingCursor(View view) {
70        // TODO(aurimas): InputMethodManager.isWatchingCursor() was deprecated in L. Fix
71        // this once the final Android L SDK is released.
72        return getInputMethodManager().isWatchingCursor(view);
73    }
74
75    /**
76     * @see android.view.inputmethod.InputMethodManager#updateCursor(View, int, int, int, int)
77     */
78    @SuppressWarnings("deprecation")
79    public void updateCursor(View view, int left, int top, int right, int bottom) {
80        // TODO(aurimas): InputMethodManager.updateCursor() was deprecated in L. Fix
81        // this once the final Android L SDK is released.
82        getInputMethodManager().updateCursor(view, left, top, right, bottom);
83    }
84}
85