From e4c45c6ef920b9cd1754f345446f53c504a64c5f Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 29 Feb 2012 18:45:13 +0900 Subject: [PATCH] Explicitly specify that labels might be in more keys Bug: 6080806 Bug: 6081427 Change-Id: I455a0210e65ea2a7774e0e0071cea5f4a99577bd --- java/res/values/donottranslate-more-keys.xml | 8 +++--- java/res/xml/key_styles_enter.xml | 2 +- .../com/android/inputmethod/keyboard/Key.java | 26 ++++++++++++------ .../keyboard/MoreKeysKeyboard.java | 27 ++++++++++++------- .../keyboard/internal/KeySpecParser.java | 16 +++++++++++ .../latin/suggestions/MoreSuggestions.java | 2 +- 6 files changed, 58 insertions(+), 23 deletions(-) diff --git a/java/res/values/donottranslate-more-keys.xml b/java/res/values/donottranslate-more-keys.xml index 0581a6162..40d81177f 100644 --- a/java/res/values/donottranslate-more-keys.xml +++ b/java/res/values/donottranslate-more-keys.xml @@ -64,12 +64,12 @@ ¢,£,$,¥,₱ ¢,$,€,¥,₱ ¢,$,€,£,¥,₱ - "!fixedColumnOrder!5,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ " + "!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ " "!fixedColumnOrder!8,\",\',#,-,:,!,\\,,\?,\@,&,\\%,+,;,/,(,)" ".com" - ".net,.org,.gov,.edu" + "!hasLabels!,.net,.org,.gov,.edu" 1 2 3 @@ -118,8 +118,8 @@ \@icon/settingsKey|\@integer/key_settings , - \@string/label_next_key|\@integer/key_action_next - \@string/label_previous_key|\@integer/key_action_previous + !hasLabels!,\@string/label_next_key|\@integer/key_action_next + !hasLabels!,\@string/label_previous_key|\@integer/key_action_previous \? ; % diff --git a/java/res/xml/key_styles_enter.xml b/java/res/xml/key_styles_enter.xml index 4c31c3e5b..61efb89b6 100644 --- a/java/res/xml/key_styles_enter.xml +++ b/java/res/xml/key_styles_enter.xml @@ -49,7 +49,7 @@ + latin:moreKeys="!fixedColumnOrder!2,@string/action_previous_as_more_key,@string/action_next_as_more_key" /> 0) { moreKeysColumn = value & MORE_KEYS_COLUMN_MASK; @@ -247,6 +250,9 @@ public class Key { if ((value = KeySpecParser.getIntValue(moreKeys, MORE_KEYS_FIXED_COLUMN_ORDER, -1)) > 0) { moreKeysColumn = MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER | (value & MORE_KEYS_COLUMN_MASK); } + if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_HAS_LABELS)) { + moreKeysColumn |= MORE_KEYS_FLAGS_HAS_LABELS; + } mMoreKeysColumnAndFlags = moreKeysColumn; final String[] additionalMoreKeys = style.getStringArray( @@ -468,7 +474,7 @@ public class Key { } public int selectTextSize(int letter, int largeLetter, int label, int hintLabel) { - if (mLabel.length() > 1 + if (Utils.codePointCount(mLabel) > 1 && (mLabelFlags & (LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO | LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO)) == 0) { return label; @@ -529,6 +535,10 @@ public class Key { return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER) != 0; } + public boolean hasLabelsInMoreKeys() { + return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_HAS_LABELS) != 0; + } + public Drawable getIcon(KeyboardIconsSet iconSet) { return iconSet.getIconDrawable(mIconId); } @@ -679,7 +689,7 @@ public class Key { */ protected Spacer(Keyboard.Params params, int x, int y, int width, int height) { super(params, null, null, KeyboardIconsSet.ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED, - null, x, y, width, height); + null, x, y, width, height, 0); } } } diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java index a6dcd883d..abbdfddfe 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java @@ -20,6 +20,7 @@ import android.graphics.Paint; import com.android.inputmethod.keyboard.internal.KeySpecParser; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.Utils; public class MoreKeysKeyboard extends Keyboard { private final int mDefaultKeyCoordX; @@ -36,6 +37,8 @@ public class MoreKeysKeyboard extends Keyboard { public static class Builder extends Keyboard.Builder { private final Key mParentKey; + private static final float LABEL_PADDING_RATIO = 0.2f; + public static class MoreKeysKeyboardParams extends Keyboard.Params { public boolean mIsFixedOrder; /* package */int mTopRowAdjustment; @@ -253,15 +256,15 @@ public class MoreKeysKeyboard extends Keyboard { // Use pre-computed width and height if these values are available and more keys // keyboard has only one key to mitigate visual flicker between key preview and more // keys keyboard. - final boolean validKeyPreview = view.isKeyPreviewPopupEnabled() && (previewWidth > 0) - && (previewHeight > 0); + final boolean validKeyPreview = view.isKeyPreviewPopupEnabled() + && !parentKey.noKeyPreview() && (previewWidth > 0) && (previewHeight > 0); final boolean singleMoreKeyWithPreview = validKeyPreview && parentKey.mMoreKeys.length == 1; if (singleMoreKeyWithPreview) { width = previewWidth; height = previewHeight + mParams.mVerticalGap; } else { - width = getMaxKeyWidth(view, parentKey.mMoreKeys, mParams.mDefaultKeyWidth); + width = getMaxKeyWidth(view, parentKey, mParams.mDefaultKeyWidth); height = parentKeyboard.mMostCommonKeyHeight; } mParams.setParameters(parentKey.mMoreKeys.length, parentKey.getMoreKeysColumn(), @@ -269,15 +272,16 @@ public class MoreKeysKeyboard extends Keyboard { parentKey.isFixedColumnOrderMoreKeys()); } - private static int getMaxKeyWidth(KeyboardView view, String[] moreKeys, int minKeyWidth) { - final int padding = (int) view.getResources() - .getDimension(R.dimen.more_keys_keyboard_key_horizontal_padding); + private static int getMaxKeyWidth(KeyboardView view, Key parentKey, int minKeyWidth) { + final int padding = (int)(view.getResources() + .getDimension(R.dimen.more_keys_keyboard_key_horizontal_padding) + + (parentKey.hasLabelsInMoreKeys() ? minKeyWidth * LABEL_PADDING_RATIO : 0)); Paint paint = null; int maxWidth = minKeyWidth; - for (String moreKeySpec : moreKeys) { + for (String moreKeySpec : parentKey.mMoreKeys) { final String label = KeySpecParser.getLabel(moreKeySpec); // If the label is single letter, minKeyWidth is enough to hold the label. - if (label != null && label.length() > 1) { + if (label != null && Utils.codePointCount(label) > 1) { if (paint == null) { paint = new Paint(); paint.setAntiAlias(true); @@ -294,12 +298,17 @@ public class MoreKeysKeyboard extends Keyboard { @Override public MoreKeysKeyboard build() { final MoreKeysKeyboardParams params = mParams; + // moreKeyFlags == 0 means that the rendered text size will be determined by its + // label's code point count. + final int moreKeyFlags = mParentKey.hasLabelsInMoreKeys() ? 0 + : Key.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO; final String[] moreKeys = mParentKey.mMoreKeys; for (int n = 0; n < moreKeys.length; n++) { final String moreKeySpec = moreKeys[n]; final int row = n / params.mNumColumns; final Key key = new Key(mResources, params, moreKeySpec, params.getX(n, row), - params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight); + params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight, + moreKeyFlags); params.markAsEdgeKey(key, row); params.onAddKey(key); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index 32f5fbc47..e3fea3dce 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -450,4 +450,20 @@ public class KeySpecParser { } return value; } + + public static boolean getBooleanValue(String[] moreKeys, String key) { + if (moreKeys == null) { + return false; + } + boolean value = false; + for (int i = 0; i < moreKeys.length; i++) { + final String moreKeySpec = moreKeys[i]; + if (moreKeySpec == null || !moreKeySpec.equals(key)) { + continue; + } + moreKeys[i] = null; + value = true; + } + return value; + } } diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java index 4ef5bd386..0bd6abe09 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java @@ -227,7 +227,7 @@ public class MoreSuggestions extends Keyboard { final int index = pos + SUGGESTION_CODE_BASE; final Key key = new Key( params, word, info, KeyboardIconsSet.ICON_UNDEFINED, index, null, x, y, - width, params.mDefaultRowHeight); + width, params.mDefaultRowHeight, 0); params.markAsEdgeKey(key, pos); params.onAddKey(key); final int columnNumber = params.getColumnNumber(pos);