From 528be97fca75513b81575ef64e4af6898656f5fb Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 31 May 2011 19:25:52 +0900 Subject: [PATCH] Fix mini keyboard position This change adjusts popup mini keyboard X-coordinate not to be clipped out of the display. Bug: 4442045 Change-Id: Ibdf4e2d0a79cddbeb89ed8ded81a2db9af9797b8 --- .../inputmethod/keyboard/KeyboardView.java | 28 +++++-------------- .../inputmethod/keyboard/MiniKeyboard.java | 16 +++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index e33e76251..5736b1ef7 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -52,7 +52,6 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.WeakHashMap; /** @@ -1117,19 +1116,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { return container; } - private static boolean isOneRowKeys(List keys) { - if (keys.size() == 0) return false; - final int edgeFlags = keys.get(0).mEdgeFlags; - // HACK: The first key of mini keyboard which was inflated from xml and has multiple rows, - // does not have both top and bottom edge flags on at the same time. On the other hand, - // the first key of mini keyboard that was created with popupCharacters must have both top - // and bottom edge flags on. - // When you want to use one row mini-keyboard from xml file, make sure that the row has - // both top and bottom edge flags set. - return (edgeFlags & Keyboard.EDGE_TOP) != 0 - && (edgeFlags & Keyboard.EDGE_BOTTOM) != 0; - } - /** * Called when a key is long pressed. By default this will open any popup keyboard associated * with this key through the attributes popupLayout and popupCharacters. @@ -1155,14 +1141,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX() : popupKey.mX + popupKey.mWidth / 2; - final int popupX = pointX - miniKeyboard.getDefaultCoordX() - - container.getPaddingLeft() - + getPaddingLeft() + mWindowOffset[0]; - final int popupY = popupKey.mY - mKeyboard.getVerticalGap() - - (container.getMeasuredHeight() - container.getPaddingBottom()) - + getPaddingTop() + mWindowOffset[1]; + final int keyboardLeft = pointX - miniKeyboard.getDefaultCoordX() + getPaddingLeft(); + final int popupX = Math.max(0, Math.min(keyboardLeft, + mMiniKeyboardParent.getWidth() - miniKeyboard.getMinWidth())) + - container.getPaddingLeft() + mWindowOffset[0]; + final int popupY = popupKey.mY - mKeyboard.getVerticalGap() + getPaddingTop() + - (container.getMeasuredHeight() - container.getPaddingBottom()) + mWindowOffset[1]; final int x = popupX; - final int y = mShowPreview && isOneRowKeys(miniKeyboard.getKeys()) + final int y = mShowPreview && miniKeyboard.isOneRowKeys() ? mPopupPreviewDisplayedY : popupY; mMiniKeyboardOriginX = x + container.getPaddingLeft() - mWindowOffset[0]; diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java index a45aaa4c6..8d243e0a7 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java @@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard; import android.content.Context; +import java.util.List; + public class MiniKeyboard extends Keyboard { private int mDefaultKeyCoordX; @@ -32,4 +34,18 @@ public class MiniKeyboard extends Keyboard { public int getDefaultCoordX() { return mDefaultKeyCoordX; } + + public boolean isOneRowKeys() { + final List keys = getKeys(); + if (keys.size() == 0) return false; + final int edgeFlags = keys.get(0).mEdgeFlags; + // HACK: The first key of mini keyboard which was inflated from xml and has multiple rows, + // does not have both top and bottom edge flags on at the same time. On the other hand, + // the first key of mini keyboard that was created with popupCharacters must have both top + // and bottom edge flags on. + // When you want to use one row mini-keyboard from xml file, make sure that the row has + // both top and bottom edge flags set. + return (edgeFlags & Keyboard.EDGE_TOP) != 0 + && (edgeFlags & Keyboard.EDGE_BOTTOM) != 0; + } }