diff options
Diffstat (limited to 'java/src/com')
7 files changed, 74 insertions, 46 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index f56b52388..c3db1b318 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -26,10 +26,10 @@ import android.util.Xml; import com.android.inputmethod.keyboard.internal.KeyStyles; 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.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.Row; import com.android.inputmethod.latin.R; @@ -184,8 +184,8 @@ public class Key { sRtlParenthesisMap.put(right, left); } - public static int getRtlParenthesisCode(int code) { - if (sRtlParenthesisMap.containsKey(code)) { + public static int getRtlParenthesisCode(int code, boolean isRtl) { + if (isRtl && sRtlParenthesisMap.containsKey(code)) { return sRtlParenthesisMap.get(code); } else { return code; @@ -195,27 +195,35 @@ public class Key { /** * This constructor is being used only for key in popup mini keyboard. */ - public Key(Resources res, KeyboardParams params, CharSequence popupCharacter, int x, int y, - int width, int height, int edgeFlags) { + public Key(Resources res, KeyboardParams params, String popupSpec, + 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; mHorizontalGap = params.mHorizontalGap; mVerticalGap = params.mVerticalGap; mVisualInsetsLeft = mVisualInsetsRight = 0; mWidth = width - mHorizontalGap; mEdgeFlags = edgeFlags; - mHintLabel = null; + mHintLabel = hintLabel; mLabelOption = 0; mFunctional = false; mSticky = false; mRepeatable = false; mPopupCharacters = null; mMaxPopupColumn = 0; - final String popupSpecification = popupCharacter.toString(); - mLabel = PopupCharactersParser.getLabel(popupSpecification); - mOutputText = PopupCharactersParser.getOutputText(popupSpecification); - final int code = PopupCharactersParser.getCode(res, popupSpecification); - mCode = params.mIsRtlKeyboard ? getRtlParenthesisCode(code) : code; - mIcon = params.mIconsSet.getIcon(PopupCharactersParser.getIconId(popupSpecification)); + mLabel = PopupCharactersParser.getLabel(popupSpec); + mOutputText = PopupCharactersParser.getOutputText(popupSpec); + mCode = code; + mIcon = params.mIconsSet.getIcon(PopupCharactersParser.getIconId(popupSpec)); // Horizontal gap is divided equally to both sides of the key. mX = x + mHorizontalGap / 2; mY = y; @@ -344,7 +352,7 @@ public class Key { Keyboard.CODE_UNSPECIFIED); if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) { final int firstChar = mLabel.charAt(0); - mCode = params.mIsRtlKeyboard ? getRtlParenthesisCode(firstChar) : firstChar; + mCode = getRtlParenthesisCode(firstChar, params.mIsRtlKeyboard); } else if (code != Keyboard.CODE_UNSPECIFIED) { mCode = code; } else { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index bc021a690..5f824537e 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -211,6 +211,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { private final float mKeyHintLetterRatio; private final float mKeyUppercaseLetterRatio; private final float mKeyHintLabelRatio; + private static final float UNDEFINED_RATIO = -1.0f; public final Rect mPadding = new Rect(); public int mKeyLetterSize; @@ -222,9 +223,19 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { public KeyDrawParams(TypedArray a) { mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground); - mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio); + if (a.hasValue(R.styleable.KeyboardView_keyLetterSize)) { + mKeyLetterRatio = UNDEFINED_RATIO; + mKeyLetterSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLetterSize, 0); + } else { + mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio); + } + if (a.hasValue(R.styleable.KeyboardView_keyLabelSize)) { + mKeyLabelRatio = UNDEFINED_RATIO; + mKeyLabelSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLabelSize, 0); + } else { + mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio); + } mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio); - mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio); mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio); mKeyUppercaseLetterRatio = getRatio(a, R.styleable.KeyboardView_keyUppercaseLetterRatio); @@ -253,9 +264,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } public void updateKeyHeight(int keyHeight) { - mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio); + if (mKeyLetterRatio >= 0.0f) + mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio); + if (mKeyLabelRatio >= 0.0f) + mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio); mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio); - mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio); mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio); mKeyUppercaseLetterSize = (int)(keyHeight * mKeyUppercaseLetterRatio); mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio); @@ -681,15 +694,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } } - // This method is currently being used only by MiniKeyboardBuilder - public int getDefaultLabelSizeAndSetPaint(Paint paint) { - // For characters, use large font. For labels like "Done", use small font. - final int labelSize = mKeyDrawParams.mKeyLabelSize; - paint.setTextSize(labelSize); - paint.setTypeface(mKeyDrawParams.mKeyTextStyle); - return labelSize; - } - private static final Rect sTextBounds = new Rect(); private static float getCharHeight(Paint paint) { @@ -733,6 +737,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { return sTextBounds.width(); } + public float getDefaultLabelWidth(CharSequence label, Paint paint) { + paint.setTextSize(mKeyDrawParams.mKeyLabelSize); + paint.setTypeface(mKeyDrawParams.mKeyTextStyle); + return getLabelWidth(label, paint); + } + private static void drawIcon(Canvas canvas, Drawable icon, int x, int y, int width, int height) { canvas.translate(x, y); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 5fa9b8fc4..69cbcb154 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -463,7 +463,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke mPopupPanelPointerTrackerId = tracker.mPointerId; final Keyboard keyboard = getKeyboard(); - mPopupPanel.setShifted(keyboard.isShiftedOrShiftLocked()); + popupPanel.setShifted(keyboard.isShiftedOrShiftLocked()); final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX() : parentKey.mX + parentKey.mWidth / 2; final int pointY = parentKey.mY - keyboard.mVerticalGap; diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java index 17c253963..ff4e72853 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java @@ -17,7 +17,6 @@ package com.android.inputmethod.keyboard; import android.graphics.Paint; -import android.graphics.Rect; import com.android.inputmethod.keyboard.internal.KeyboardBuilder; import com.android.inputmethod.keyboard.internal.KeyboardParams; @@ -235,9 +234,10 @@ public class MiniKeyboard extends Keyboard { private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters, int minKeyWidth) { + final int padding = (int) view.getContext().getResources() + .getDimension(R.dimen.mini_keyboard_key_horizontal_padding); Paint paint = null; - Rect bounds = null; - int maxWidth = 0; + int maxWidth = minKeyWidth; for (CharSequence popupSpec : popupCharacters) { final CharSequence label = PopupCharactersParser.getLabel(popupSpec.toString()); // If the label is single letter, minKeyWidth is enough to hold @@ -247,18 +247,13 @@ public class MiniKeyboard extends Keyboard { paint = new Paint(); paint.setAntiAlias(true); } - final int labelSize = view.getDefaultLabelSizeAndSetPaint(paint); - paint.setTextSize(labelSize); - if (bounds == null) - bounds = new Rect(); - paint.getTextBounds(label.toString(), 0, label.length(), bounds); - if (maxWidth < bounds.width()) - maxWidth = bounds.width(); + final int width = (int)view.getDefaultLabelWidth(label, paint) + padding; + if (maxWidth < width) { + maxWidth = width; + } } } - final int horizontalPadding = (int) view.getContext().getResources() - .getDimension(R.dimen.mini_keyboard_key_horizontal_padding); - return Math.max(minKeyWidth, maxWidth + horizontalPadding); + return maxWidth; } @Override @@ -267,7 +262,7 @@ public class MiniKeyboard extends Keyboard { for (int n = 0; n < mPopupCharacters.length; n++) { final CharSequence label = mPopupCharacters[n]; 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.getRowFlags(row)); params.onAddKey(key); diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java index c4428dc60..7ace46cac 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java @@ -197,8 +197,8 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { @Override public void setShifted(boolean shifted) { - final MiniKeyboard miniKeyboard = (MiniKeyboard)getKeyboard(); - if (miniKeyboard.setShifted(shifted)) { + final Keyboard keyboard = getKeyboard(); + if (keyboard.setShifted(shifted)) { invalidateAllKeys(); } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java index 4ccaa72d2..980115200 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java @@ -64,6 +64,15 @@ public class KeyboardParams { public int mMostCommonKeyWidth = 0; + protected void clearKeys() { + mKeys.clear(); + mShiftKeys.clear(); + mShiftLockKeys.clear(); + mShiftedIcons.clear(); + mUnshiftedIcons.clear(); + clearHistogram(); + } + public void onAddKey(Key key) { mKeys.add(key); updateHistogram(key); @@ -83,6 +92,12 @@ public class KeyboardParams { private int mMaxCount = 0; private final Map<Integer, Integer> mHistogram = new HashMap<Integer, Integer>(); + private void clearHistogram() { + mMostCommonKeyWidth = 0; + mMaxCount = 0; + mHistogram.clear(); + } + private void updateHistogram(Key key) { final Integer width = key.mWidth + key.mHorizontalGap; final int count = (mHistogram.containsKey(width) ? mHistogram.get(width) : 0) + 1; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 229bf0f4c..7559108f3 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1708,8 +1708,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final int rawPrimaryCode = suggestion.charAt(0); // Maybe apply the "bidi mirrored" conversions for parentheses final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard(); - final int primaryCode = keyboard.mIsRtlKeyboard - ? Key.getRtlParenthesisCode(rawPrimaryCode) : rawPrimaryCode; + final int primaryCode = Key.getRtlParenthesisCode( + rawPrimaryCode, keyboard.mIsRtlKeyboard); final CharSequence beforeText = ic != null ? ic.getTextBeforeCursor(1, 0) : ""; final int toLeft = (ic == null || TextUtils.isEmpty(beforeText)) |