diff options
| author | Tadashi G. Takaoka <takaoka@google.com> | 2011-04-20 16:02:37 +0900 |
|---|---|---|
| committer | Tadashi G. Takaoka <takaoka@google.com> | 2011-04-20 16:09:12 +0900 |
| commit | 21334fdbbe9f2e6890fb9877b9ef3d441f3eb6fb (patch) | |
| tree | 56bfcb7c2acae78edb01e7d93578043d5b96e73c /core/java/android/inputmethodservice/KeyboardView.java | |
| parent | 6f026b0fbc776b833566002e1d775c91f33de1ca (diff) | |
Fix key preview coordinates calculation
Bug: 4310526
Change-Id: I67be4e69056faea9bdf4157ada9435dd326e52f0
Diffstat (limited to 'core/java/android/inputmethodservice/KeyboardView.java')
| -rw-r--r-- | core/java/android/inputmethodservice/KeyboardView.java | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/core/java/android/inputmethodservice/KeyboardView.java b/core/java/android/inputmethodservice/KeyboardView.java index ab5c78a92078..dfc70ef416af 100644 --- a/core/java/android/inputmethodservice/KeyboardView.java +++ b/core/java/android/inputmethodservice/KeyboardView.java @@ -142,7 +142,8 @@ public class KeyboardView extends View implements View.OnClickListener { private int mPreviewTextSizeLarge; private int mPreviewOffset; private int mPreviewHeight; - private int[] mOffsetInWindow; + // Working variable + private final int[] mCoordinates = new int[2]; private PopupWindow mPopupKeyboard; private View mMiniKeyboardContainer; @@ -152,7 +153,6 @@ public class KeyboardView extends View implements View.OnClickListener { private int mMiniKeyboardOffsetX; private int mMiniKeyboardOffsetY; private Map<Key,View> mMiniKeyboardCache; - private int[] mWindowOffset; private Key[] mKeys; /** Listener for {@link OnKeyboardActionListener}. */ @@ -905,23 +905,19 @@ public class KeyboardView extends View implements View.OnClickListener { mPopupPreviewY = - mPreviewText.getMeasuredHeight(); } mHandler.removeMessages(MSG_REMOVE_PREVIEW); - if (mOffsetInWindow == null) { - mOffsetInWindow = new int[2]; - getLocationInWindow(mOffsetInWindow); - mOffsetInWindow[0] += mMiniKeyboardOffsetX; // Offset may be zero - mOffsetInWindow[1] += mMiniKeyboardOffsetY; // Offset may be zero - int[] mWindowLocation = new int[2]; - getLocationOnScreen(mWindowLocation); - mWindowY = mWindowLocation[1]; - } + getLocationInWindow(mCoordinates); + mCoordinates[0] += mMiniKeyboardOffsetX; // Offset may be zero + mCoordinates[1] += mMiniKeyboardOffsetY; // Offset may be zero + // Set the preview background state mPreviewText.getBackground().setState( key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET); - mPopupPreviewX += mOffsetInWindow[0]; - mPopupPreviewY += mOffsetInWindow[1]; + mPopupPreviewX += mCoordinates[0]; + mPopupPreviewY += mCoordinates[1]; // If the popup cannot be shown above the key, put it on the side - if (mPopupPreviewY + mWindowY < 0) { + getLocationOnScreen(mCoordinates); + if (mPopupPreviewY + mCoordinates[1] < 0) { // If the key you're pressing is on the left side of the keyboard, show the popup on // the right, offset by enough to see at least one key to the left/right. if (key.x + key.width <= getWidth() / 2) { @@ -1057,16 +1053,13 @@ public class KeyboardView extends View implements View.OnClickListener { mMiniKeyboard = (KeyboardView) mMiniKeyboardContainer.findViewById( com.android.internal.R.id.keyboardView); } - if (mWindowOffset == null) { - mWindowOffset = new int[2]; - getLocationInWindow(mWindowOffset); - } + getLocationInWindow(mCoordinates); mPopupX = popupKey.x + mPaddingLeft; mPopupY = popupKey.y + mPaddingTop; mPopupX = mPopupX + popupKey.width - mMiniKeyboardContainer.getMeasuredWidth(); mPopupY = mPopupY - mMiniKeyboardContainer.getMeasuredHeight(); - final int x = mPopupX + mMiniKeyboardContainer.getPaddingRight() + mWindowOffset[0]; - final int y = mPopupY + mMiniKeyboardContainer.getPaddingBottom() + mWindowOffset[1]; + final int x = mPopupX + mMiniKeyboardContainer.getPaddingRight() + mCoordinates[0]; + final int y = mPopupY + mMiniKeyboardContainer.getPaddingBottom() + mCoordinates[1]; mMiniKeyboard.setPopupOffset(x < 0 ? 0 : x, y); mMiniKeyboard.setShifted(isShifted()); mPopupKeyboard.setContentView(mMiniKeyboardContainer); |
