aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/InputView.java112
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java21
2 files changed, 132 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/latin/InputView.java b/java/src/com/android/inputmethod/latin/InputView.java
new file mode 100644
index 000000000..0dcb811b5
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/InputView.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2011 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 com.android.inputmethod.latin;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.LinearLayout;
+
+public class InputView extends LinearLayout {
+ private View mSuggestionsContainer;
+ private View mKeyboardView;
+ private int mKeyboardTopPadding;
+
+ private boolean mIsForwardingEvent;
+ private final Rect mInputViewRect = new Rect();
+ private final Rect mEventForwardingRect = new Rect();
+ private final Rect mEventReceivingRect = new Rect();
+
+ public InputView(Context context, AttributeSet attrs) {
+ super(context, attrs, 0);
+ }
+
+ public void setKeyboardGeometry(int keyboardTopPadding) {
+ mKeyboardTopPadding = keyboardTopPadding;
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ mSuggestionsContainer = findViewById(R.id.suggestions_container);
+ mKeyboardView = findViewById(R.id.keyboard_view);
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent me) {
+ if (mSuggestionsContainer.getVisibility() == VISIBLE
+ && mKeyboardView.getVisibility() == VISIBLE
+ && forwardTouchEvent(me)) {
+ return true;
+ }
+ return super.dispatchTouchEvent(me);
+ }
+
+ // The touch events that hit the top padding of keyboard should be forwarded to SuggestionsView.
+ private boolean forwardTouchEvent(MotionEvent me) {
+ final Rect rect = mInputViewRect;
+ this.getGlobalVisibleRect(rect);
+ final int x = (int)me.getX() + rect.left;
+ final int y = (int)me.getY() + rect.top;
+
+ final Rect forwardingRect = mEventForwardingRect;
+ mKeyboardView.getGlobalVisibleRect(forwardingRect);
+ if (!mIsForwardingEvent && !forwardingRect.contains(x, y)) {
+ return false;
+ }
+
+ final int forwardingLimitY = forwardingRect.top + mKeyboardTopPadding;
+ boolean sendToTarget = false;
+
+ switch (me.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ if (y < forwardingLimitY) {
+ // This down event and further move and up events should be forwarded to the target.
+ mIsForwardingEvent = true;
+ sendToTarget = true;
+ }
+ break;
+ case MotionEvent.ACTION_MOVE:
+ sendToTarget = mIsForwardingEvent;
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ sendToTarget = mIsForwardingEvent;
+ mIsForwardingEvent = false;
+ break;
+ }
+
+ if (!sendToTarget) {
+ return false;
+ }
+
+ final Rect receivingRect = mEventReceivingRect;
+ mSuggestionsContainer.getGlobalVisibleRect(receivingRect);
+ final int translatedX = x - receivingRect.left;
+ final int translatedY;
+ if (y < forwardingLimitY) {
+ // The forwarded event should have coordinates that are inside of the target.
+ translatedY = Math.min(y - receivingRect.top, receivingRect.height() - 1);
+ } else {
+ translatedY = y - receivingRect.top;
+ }
+ me.setLocation(translatedX, translatedY);
+ mSuggestionsContainer.dispatchTouchEvent(me);
+ return true;
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ddda184aa..32649d5a1 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -241,7 +241,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private static final int MSG_SET_BIGRAM_PREDICTIONS = 7;
private static final int MSG_START_ORIENTATION_CHANGE = 8;
private static final int MSG_START_INPUT_VIEW = 9;
- private static final int MSG_RESTORE_KEYBOARD_LAYOUT = 10;
+ private static final int MSG_DISPLAY_COMPLETIONS = 10;
+ private static final int MSG_RESTORE_KEYBOARD_LAYOUT = 11;
public UIHandler(LatinIME outerInstance) {
super(outerInstance);
@@ -293,6 +294,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case MSG_START_INPUT_VIEW:
latinIme.onStartInputView((EditorInfo)msg.obj, false);
break;
+ case MSG_DISPLAY_COMPLETIONS:
+ latinIme.onDisplayCompletions((CompletionInfo[])msg.obj);
+ break;
case MSG_RESTORE_KEYBOARD_LAYOUT:
removeMessages(MSG_UPDATE_SHIFT_STATE);
((KeyboardLayoutState)msg.obj).restore();
@@ -417,6 +421,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
return false;
}
+
+ public boolean postDisplayCompletions(CompletionInfo[] applicationSpecifiedCompletions) {
+ if (hasMessages(MSG_START_INPUT_VIEW) || hasMessages(MSG_DISPLAY_COMPLETIONS)) {
+ removeMessages(MSG_DISPLAY_COMPLETIONS);
+ // Postpone onDisplayCompletions by ACCUMULATE_START_INPUT_VIEW_DELAY.
+ sendMessageDelayed(
+ obtainMessage(MSG_DISPLAY_COMPLETIONS, applicationSpecifiedCompletions),
+ ACCUMULATE_START_INPUT_VIEW_DELAY);
+ return true;
+ }
+ return false;
+ }
}
@Override
@@ -923,6 +939,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void onDisplayCompletions(CompletionInfo[] applicationSpecifiedCompletions) {
+ if (mHandler.postDisplayCompletions(applicationSpecifiedCompletions)) {
+ return;
+ }
if (DEBUG) {
Log.i(TAG, "Received completions:");
if (applicationSpecifiedCompletions != null) {