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
This commit is contained in:
parent
fd2f1a1677
commit
528be97fca
2 changed files with 23 additions and 21 deletions
|
@ -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<Key> 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];
|
||||
|
|
|
@ -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<Key> 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue