aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java26
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java27
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java16
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java2
4 files changed, 53 insertions, 18 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 8c71237f6..f1611d9ee 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -62,7 +62,7 @@ public class Key {
private static final int LABEL_FLAGS_LARGE_LETTER = 0x10;
private static final int LABEL_FLAGS_FONT_NORMAL = 0x20;
private static final int LABEL_FLAGS_FONT_MONO_SPACE = 0x40;
- private static final int LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO = 0x80;
+ public static final int LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO = 0x80;
private static final int LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO = 0x100;
private static final int LABEL_FLAGS_HAS_POPUP_HINT = 0x200;
private static final int LABEL_FLAGS_HAS_SHIFTED_LETTER_HINT = 0x400;
@@ -107,8 +107,10 @@ public class Key {
private final int mMoreKeysColumnAndFlags;
private static final int MORE_KEYS_COLUMN_MASK = 0x000000ff;
private static final int MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER = 0x80000000;
+ private static final int MORE_KEYS_FLAGS_HAS_LABELS = 0x40000000;
private static final String MORE_KEYS_AUTO_COLUMN_ORDER = "!autoColumnOrder!";
private static final String MORE_KEYS_FIXED_COLUMN_ORDER = "!fixedColumnOrder!";
+ private static final String MORE_KEYS_HAS_LABELS = "!hasLabels!";
/** Background type that represents different key background visual than normal one. */
public final int mBackgroundType;
@@ -135,26 +137,26 @@ public class Key {
* This constructor is being used only for key in more keys keyboard.
*/
public Key(Resources res, Keyboard.Params params, String moreKeySpec,
- int x, int y, int width, int height) {
+ int x, int y, int width, int height, int labelFlags) {
this(params, KeySpecParser.getLabel(moreKeySpec), null,
KeySpecParser.getIconId(moreKeySpec),
KeySpecParser.getCode(res, moreKeySpec),
KeySpecParser.getOutputText(moreKeySpec),
- x, y, width, height);
+ x, y, width, height, labelFlags);
}
/**
* This constructor is being used only for key in popup suggestions pane.
*/
public Key(Keyboard.Params params, String label, String hintLabel, int iconId,
- int code, String outputText, int x, int y, int width, int height) {
+ int code, String outputText, int x, int y, int width, int height, int labelFlags) {
mHeight = height - params.mVerticalGap;
mHorizontalGap = params.mHorizontalGap;
mVerticalGap = params.mVerticalGap;
mVisualInsetsLeft = mVisualInsetsRight = 0;
mWidth = width - mHorizontalGap;
mHintLabel = hintLabel;
- mLabelFlags = 0;
+ mLabelFlags = labelFlags;
mBackgroundType = BACKGROUND_TYPE_NORMAL;
mActionFlags = 0;
mMoreKeys = null;
@@ -162,6 +164,7 @@ public class Key {
mLabel = label;
mOutputText = outputText;
mCode = code;
+ mEnabled = (code != Keyboard.CODE_UNSPECIFIED);
mAltCode = Keyboard.CODE_UNSPECIFIED;
mIconId = iconId;
mDisabledIconId = KeyboardIconsSet.ICON_UNDEFINED;
@@ -239,7 +242,7 @@ public class Key {
String[] moreKeys = style.getStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
int moreKeysColumn = style.getInt(keyAttr,
- R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMoreKeysKeyboardColumn);
+ R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMoreKeysKeyboardColumn);
int value;
if ((value = KeySpecParser.getIntValue(moreKeys, MORE_KEYS_AUTO_COLUMN_ORDER, -1)) > 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<Builder.MoreKeysKeyboardParams> {
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);