OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.content.browser.input; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.os.Handler; |
| 9 import android.os.IBinder; |
| 10 import android.view.View; |
| 11 import android.view.inputmethod.EditorInfo; |
| 12 import android.view.inputmethod.InputConnection; |
| 13 |
| 14 import org.chromium.base.Log; |
| 15 import org.chromium.base.ThreadUtils; |
| 16 |
| 17 import java.util.concurrent.Callable; |
| 18 |
| 19 /** |
| 20 * This is a fake View that is only exposed to InputMethodManager. |
| 21 */ |
| 22 public class ThreadedInputConnectionProxyView extends View { |
| 23 private static final String TAG = "cr_Ime"; |
| 24 private static final boolean DEBUG_LOGS = false; |
| 25 |
| 26 private final Handler mHandler; |
| 27 private final View mContainerView; |
| 28 |
| 29 ThreadedInputConnectionProxyView(Context context, Handler handler, View cont
ainerView) { |
| 30 super(context); |
| 31 mHandler = handler; |
| 32 mContainerView = containerView; |
| 33 setFocusable(true); |
| 34 setFocusableInTouchMode(true); |
| 35 setVisibility(View.VISIBLE); |
| 36 if (DEBUG_LOGS) Log.w(TAG, "constructor"); |
| 37 } |
| 38 |
| 39 @Override |
| 40 public Handler getHandler() { |
| 41 if (DEBUG_LOGS) Log.w(TAG, "getHandler"); |
| 42 return mHandler; |
| 43 } |
| 44 |
| 45 @Override |
| 46 public boolean checkInputConnectionProxy(View view) { |
| 47 if (DEBUG_LOGS) Log.w(TAG, "checkInputConnectionProxy"); |
| 48 return mContainerView == view; |
| 49 } |
| 50 |
| 51 @Override |
| 52 public InputConnection onCreateInputConnection(final EditorInfo outAttrs) { |
| 53 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection"); |
| 54 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<InputCo
nnection>() { |
| 55 @Override |
| 56 public InputConnection call() throws Exception { |
| 57 return mContainerView.onCreateInputConnection(outAttrs); |
| 58 } |
| 59 }); |
| 60 } |
| 61 |
| 62 @Override |
| 63 public boolean hasFocus() { |
| 64 if (DEBUG_LOGS) Log.w(TAG, "hasFocus"); |
| 65 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { |
| 66 @Override |
| 67 public Boolean call() throws Exception { |
| 68 return mContainerView.hasFocus(); |
| 69 } |
| 70 }); |
| 71 } |
| 72 |
| 73 @Override |
| 74 public boolean hasWindowFocus() { |
| 75 if (DEBUG_LOGS) Log.w(TAG, "hasWindowFocus"); |
| 76 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { |
| 77 @Override |
| 78 public Boolean call() throws Exception { |
| 79 return mContainerView.hasWindowFocus(); |
| 80 } |
| 81 }); |
| 82 } |
| 83 |
| 84 @Override |
| 85 public View getRootView() { |
| 86 if (DEBUG_LOGS) Log.w(TAG, "getRootView"); |
| 87 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<View>()
{ |
| 88 @Override |
| 89 public View call() throws Exception { |
| 90 return mContainerView.getRootView(); |
| 91 } |
| 92 }); |
| 93 } |
| 94 |
| 95 @Override |
| 96 public boolean onCheckIsTextEditor() { |
| 97 if (DEBUG_LOGS) Log.w(TAG, "onCheckIsTextEditor"); |
| 98 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { |
| 99 @Override |
| 100 public Boolean call() throws Exception { |
| 101 return mContainerView.onCheckIsTextEditor(); |
| 102 } |
| 103 }); |
| 104 } |
| 105 |
| 106 @Override |
| 107 public boolean isFocused() { |
| 108 if (DEBUG_LOGS) Log.w(TAG, "isFocused"); |
| 109 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { |
| 110 @Override |
| 111 public Boolean call() throws Exception { |
| 112 return mContainerView.isFocused(); |
| 113 } |
| 114 }); |
| 115 } |
| 116 |
| 117 @Override |
| 118 public IBinder getWindowToken() { |
| 119 if (DEBUG_LOGS) Log.w(TAG, "getWindowToken"); |
| 120 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<IBinder
>() { |
| 121 @Override |
| 122 public IBinder call() throws Exception { |
| 123 return mContainerView.getWindowToken(); |
| 124 } |
| 125 }); |
| 126 } |
| 127 |
| 128 @Override |
| 129 public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 130 if (DEBUG_LOGS) Log.w(TAG, "onWindowFocusChanged:" + hasWindowFocus); |
| 131 super.onWindowFocusChanged(hasWindowFocus); |
| 132 } |
| 133 } |
OLD | NEW |