Add Key constructor for suggestions pane
Bug: 5023981 Change-Id: I737bacb1a6bb40f70be65d6eff85614afe6c79ed
This commit is contained in:
parent
84b1284d01
commit
392276d73d
3 changed files with 25 additions and 17 deletions
|
@ -26,10 +26,10 @@ import android.util.Xml;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.internal.KeyStyles;
|
import com.android.inputmethod.keyboard.internal.KeyStyles;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
|
import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
|
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardParams;
|
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
|
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardBuilder.ParseException;
|
import com.android.inputmethod.keyboard.internal.KeyboardBuilder.ParseException;
|
||||||
|
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
|
||||||
|
import com.android.inputmethod.keyboard.internal.KeyboardParams;
|
||||||
import com.android.inputmethod.keyboard.internal.PopupCharactersParser;
|
import com.android.inputmethod.keyboard.internal.PopupCharactersParser;
|
||||||
import com.android.inputmethod.keyboard.internal.Row;
|
import com.android.inputmethod.keyboard.internal.Row;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
@ -184,8 +184,8 @@ public class Key {
|
||||||
sRtlParenthesisMap.put(right, left);
|
sRtlParenthesisMap.put(right, left);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getRtlParenthesisCode(int code) {
|
public static int getRtlParenthesisCode(int code, boolean isRtl) {
|
||||||
if (sRtlParenthesisMap.containsKey(code)) {
|
if (isRtl && sRtlParenthesisMap.containsKey(code)) {
|
||||||
return sRtlParenthesisMap.get(code);
|
return sRtlParenthesisMap.get(code);
|
||||||
} else {
|
} else {
|
||||||
return code;
|
return code;
|
||||||
|
@ -195,27 +195,35 @@ public class Key {
|
||||||
/**
|
/**
|
||||||
* This constructor is being used only for key in popup mini keyboard.
|
* This constructor is being used only for key in popup mini keyboard.
|
||||||
*/
|
*/
|
||||||
public Key(Resources res, KeyboardParams params, CharSequence popupCharacter, int x, int y,
|
public Key(Resources res, KeyboardParams params, String popupSpec,
|
||||||
int width, int height, int edgeFlags) {
|
int x, int y, int width, int height, int edgeFlags) {
|
||||||
|
this(params, getRtlParenthesisCode(PopupCharactersParser.getCode(res, popupSpec),
|
||||||
|
params.mIsRtlKeyboard),
|
||||||
|
popupSpec, null, x, y, width, height, edgeFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor is being used only for key in popup suggestions pane.
|
||||||
|
*/
|
||||||
|
public Key(KeyboardParams params, int code, String popupSpec, String hintLabel,
|
||||||
|
int x, int y, int width, int height, int edgeFlags) {
|
||||||
mHeight = height - params.mVerticalGap;
|
mHeight = height - params.mVerticalGap;
|
||||||
mHorizontalGap = params.mHorizontalGap;
|
mHorizontalGap = params.mHorizontalGap;
|
||||||
mVerticalGap = params.mVerticalGap;
|
mVerticalGap = params.mVerticalGap;
|
||||||
mVisualInsetsLeft = mVisualInsetsRight = 0;
|
mVisualInsetsLeft = mVisualInsetsRight = 0;
|
||||||
mWidth = width - mHorizontalGap;
|
mWidth = width - mHorizontalGap;
|
||||||
mEdgeFlags = edgeFlags;
|
mEdgeFlags = edgeFlags;
|
||||||
mHintLabel = null;
|
mHintLabel = hintLabel;
|
||||||
mLabelOption = 0;
|
mLabelOption = 0;
|
||||||
mFunctional = false;
|
mFunctional = false;
|
||||||
mSticky = false;
|
mSticky = false;
|
||||||
mRepeatable = false;
|
mRepeatable = false;
|
||||||
mPopupCharacters = null;
|
mPopupCharacters = null;
|
||||||
mMaxPopupColumn = 0;
|
mMaxPopupColumn = 0;
|
||||||
final String popupSpecification = popupCharacter.toString();
|
mLabel = PopupCharactersParser.getLabel(popupSpec);
|
||||||
mLabel = PopupCharactersParser.getLabel(popupSpecification);
|
mOutputText = PopupCharactersParser.getOutputText(popupSpec);
|
||||||
mOutputText = PopupCharactersParser.getOutputText(popupSpecification);
|
mCode = code;
|
||||||
final int code = PopupCharactersParser.getCode(res, popupSpecification);
|
mIcon = params.mIconsSet.getIcon(PopupCharactersParser.getIconId(popupSpec));
|
||||||
mCode = params.mIsRtlKeyboard ? getRtlParenthesisCode(code) : code;
|
|
||||||
mIcon = params.mIconsSet.getIcon(PopupCharactersParser.getIconId(popupSpecification));
|
|
||||||
// Horizontal gap is divided equally to both sides of the key.
|
// Horizontal gap is divided equally to both sides of the key.
|
||||||
mX = x + mHorizontalGap / 2;
|
mX = x + mHorizontalGap / 2;
|
||||||
mY = y;
|
mY = y;
|
||||||
|
@ -344,7 +352,7 @@ public class Key {
|
||||||
Keyboard.CODE_UNSPECIFIED);
|
Keyboard.CODE_UNSPECIFIED);
|
||||||
if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) {
|
if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) {
|
||||||
final int firstChar = mLabel.charAt(0);
|
final int firstChar = mLabel.charAt(0);
|
||||||
mCode = params.mIsRtlKeyboard ? getRtlParenthesisCode(firstChar) : firstChar;
|
mCode = getRtlParenthesisCode(firstChar, params.mIsRtlKeyboard);
|
||||||
} else if (code != Keyboard.CODE_UNSPECIFIED) {
|
} else if (code != Keyboard.CODE_UNSPECIFIED) {
|
||||||
mCode = code;
|
mCode = code;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -262,7 +262,7 @@ public class MiniKeyboard extends Keyboard {
|
||||||
for (int n = 0; n < mPopupCharacters.length; n++) {
|
for (int n = 0; n < mPopupCharacters.length; n++) {
|
||||||
final CharSequence label = mPopupCharacters[n];
|
final CharSequence label = mPopupCharacters[n];
|
||||||
final int row = n / params.mNumColumns;
|
final int row = n / params.mNumColumns;
|
||||||
final Key key = new Key(mResources, params, label, params.getX(n, row),
|
final Key key = new Key(mResources, params, label.toString(), params.getX(n, row),
|
||||||
params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight,
|
params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight,
|
||||||
params.getRowFlags(row));
|
params.getRowFlags(row));
|
||||||
params.onAddKey(key);
|
params.onAddKey(key);
|
||||||
|
|
|
@ -1708,8 +1708,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
final int rawPrimaryCode = suggestion.charAt(0);
|
final int rawPrimaryCode = suggestion.charAt(0);
|
||||||
// Maybe apply the "bidi mirrored" conversions for parentheses
|
// Maybe apply the "bidi mirrored" conversions for parentheses
|
||||||
final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
|
final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
|
||||||
final int primaryCode = keyboard.mIsRtlKeyboard
|
final int primaryCode = Key.getRtlParenthesisCode(
|
||||||
? Key.getRtlParenthesisCode(rawPrimaryCode) : rawPrimaryCode;
|
rawPrimaryCode, keyboard.mIsRtlKeyboard);
|
||||||
|
|
||||||
final CharSequence beforeText = ic != null ? ic.getTextBeforeCursor(1, 0) : "";
|
final CharSequence beforeText = ic != null ? ic.getTextBeforeCursor(1, 0) : "";
|
||||||
final int toLeft = (ic == null || TextUtils.isEmpty(beforeText))
|
final int toLeft = (ic == null || TextUtils.isEmpty(beforeText))
|
||||||
|
|
Loading…
Reference in a new issue