summaryrefslogtreecommitdiffstats
path: root/core/java/android/view/inputmethod/BaseInputConnection.java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:43 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:43 -0800
commitf013e1afd1e68af5e3b868c26a653bbfb39538f8 (patch)
tree7ad6c8fd9c7b55f4b4017171dec1cb760bbd26bf /core/java/android/view/inputmethod/BaseInputConnection.java
parente70cfafe580c6f2994c4827cd8a534aabf3eb05c (diff)
downloadframeworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.zip
frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.gz
frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'core/java/android/view/inputmethod/BaseInputConnection.java')
-rw-r--r--core/java/android/view/inputmethod/BaseInputConnection.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java
new file mode 100644
index 0000000..4416ee5
--- /dev/null
+++ b/core/java/android/view/inputmethod/BaseInputConnection.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2008 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 android.view.inputmethod;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Message;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.ViewRoot;
+
+/**
+ * Base class for implementors of the InputConnection interface, taking care
+ * of implementing common system-oriented parts of the functionality.
+ */
+public abstract class BaseInputConnection implements InputConnection {
+ final InputMethodManager mIMM;
+ final Handler mH;
+ final View mTargetView;
+
+ BaseInputConnection(InputMethodManager mgr) {
+ mIMM = mgr;
+ mTargetView = null;
+ mH = null;
+ }
+
+ public BaseInputConnection(View targetView) {
+ mIMM = (InputMethodManager)targetView.getContext().getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ mH = targetView.getHandler();
+ mTargetView = targetView;
+ }
+
+ /**
+ * Provides standard implementation for sending a key event to the window
+ * attached to the input connection's view.
+ */
+ public boolean sendKeyEvent(KeyEvent event) {
+ synchronized (mIMM.mH) {
+ Handler h = mH;
+ if (h == null) {
+ if (mIMM.mServedView != null) {
+ h = mIMM.mServedView.getHandler();
+ }
+ }
+ if (h != null && mTargetView != null) {
+ h.post(new DispatchKey(event, mTargetView.getRootView()));
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Provides standard implementation for hiding the status icon associated
+ * with the current input method.
+ */
+ public boolean hideStatusIcon() {
+ mIMM.updateStatusIcon(0, null);
+ return true;
+ }
+
+ /**
+ * Provides standard implementation for showing the status icon associated
+ * with the current input method.
+ */
+ public boolean showStatusIcon(String packageName, int resId) {
+ mIMM.updateStatusIcon(resId, packageName);
+ return true;
+ }
+
+ static class DispatchKey implements Runnable {
+ KeyEvent mEvent;
+ View mView;
+
+ DispatchKey(KeyEvent event, View v) {
+ mEvent = event;
+ mView = v;
+ }
+
+ public void run() {
+ mView.dispatchKeyEvent(mEvent);
+ }
+ }
+} \ No newline at end of file