| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser.input; | 5 package org.chromium.content.browser.input; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.os.Build; | 9 import android.os.Build; |
| 10 import android.os.IBinder; | 10 import android.os.IBinder; |
| 11 import android.os.ResultReceiver; | 11 import android.os.ResultReceiver; |
| 12 import android.view.View; | 12 import android.view.View; |
| 13 import android.view.inputmethod.CursorAnchorInfo; | 13 import android.view.inputmethod.CursorAnchorInfo; |
| 14 import android.view.inputmethod.InputMethodManager; | 14 import android.view.inputmethod.InputMethodManager; |
| 15 | 15 |
| 16 import org.chromium.base.Log; | 16 import org.chromium.base.Log; |
| 17 | 17 |
| 18 import java.lang.reflect.InvocationTargetException; |
| 19 import java.lang.reflect.Method; |
| 20 |
| 18 /** | 21 /** |
| 19 * Wrapper around Android's InputMethodManager | 22 * Wrapper around Android's InputMethodManager |
| 20 */ | 23 */ |
| 21 public class InputMethodManagerWrapper { | 24 public class InputMethodManagerWrapper { |
| 22 private static final String TAG = "cr_Ime"; | 25 private static final String TAG = "cr_Ime"; |
| 23 | 26 |
| 24 private final Context mContext; | 27 private final Context mContext; |
| 25 | 28 |
| 26 public InputMethodManagerWrapper(Context context) { | 29 public InputMethodManagerWrapper(Context context) { |
| 27 Log.d(TAG, "Constructor"); | 30 Log.d(TAG, "Constructor"); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 * @see android.view.inputmethod.InputMethodManager#updateCursorAnchorInfo(V
iew, | 84 * @see android.view.inputmethod.InputMethodManager#updateCursorAnchorInfo(V
iew, |
| 82 * CursorAnchorInfo) | 85 * CursorAnchorInfo) |
| 83 */ | 86 */ |
| 84 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 87 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 85 public void updateCursorAnchorInfo(View view, CursorAnchorInfo cursorAnchorI
nfo) { | 88 public void updateCursorAnchorInfo(View view, CursorAnchorInfo cursorAnchorI
nfo) { |
| 86 Log.d(TAG, "updateCursorAnchorInfo"); | 89 Log.d(TAG, "updateCursorAnchorInfo"); |
| 87 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 90 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 88 getInputMethodManager().updateCursorAnchorInfo(view, cursorAnchorInf
o); | 91 getInputMethodManager().updateCursorAnchorInfo(view, cursorAnchorInf
o); |
| 89 } | 92 } |
| 90 } | 93 } |
| 94 |
| 95 /** |
| 96 * Notify that a user took some action with the current input method. Withou
t this call |
| 97 * an input method app may wait longer when the user switches methods within
the app. |
| 98 */ |
| 99 public void notifyUserAction() { |
| 100 // On N and above, this is not needed. |
| 101 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) return; |
| 102 Log.d(TAG, "notifyUserAction"); |
| 103 InputMethodManager manager = getInputMethodManager(); |
| 104 try { |
| 105 Method method = InputMethodManager.class.getMethod("notifyUserAction
"); |
| 106 method.invoke(manager); |
| 107 } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumen
tException |
| 108 | InvocationTargetException e) { |
| 109 Log.d(TAG, "notifyUserAction failed"); |
| 110 return; |
| 111 } |
| 112 } |
| 91 } | 113 } |
| OLD | NEW |