Merge "Explicitly specify that labels might be in more keys"

This commit is contained in:
Tadashi G. Takaoka 2012-03-01 03:56:32 -08:00 committed by Android (Google) Code Review
commit 961703841e
6 changed files with 58 additions and 23 deletions

View file

@ -64,12 +64,12 @@
<string name="more_keys_for_currency_euro">&#x00A2;,&#x00A3;,$,&#x00A5;,&#x20B1;</string>
<string name="more_keys_for_currency_pound">&#x00A2;,$,&#x20AC;,&#x00A5;,&#x20B1;</string>
<string name="more_keys_for_currency_general">&#x00A2;,$,&#x20AC;,&#x00A3;,&#x00A5;,&#x20B1;</string>
<string name="more_keys_for_smiley">"!fixedColumnOrder!5,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ "</string>
<string name="more_keys_for_smiley">"!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ "</string>
<string name="more_keys_for_punctuation">"!fixedColumnOrder!8,\",\',#,-,:,!,\\,,\?,\@,&amp;,\\%,+,;,/,(,)"</string>
<string name="keyhintlabel_for_punctuation"></string>
<string name="keylabel_for_popular_domain">".com"</string>
<!-- popular web domains for the locale - most popular, displayed on the keyboard -->
<string name="more_keys_for_popular_domain">".net,.org,.gov,.edu"</string>
<string name="more_keys_for_popular_domain">"!hasLabels!,.net,.org,.gov,.edu"</string>
<string name="keylabel_for_symbols_1">1</string>
<string name="keylabel_for_symbols_2">2</string>
<string name="keylabel_for_symbols_3">3</string>
@ -118,8 +118,8 @@
<string name="settings_as_more_key">\@icon/settingsKey|\@integer/key_settings</string>
<string name="keylabel_for_comma">,</string>
<string name="more_keys_for_comma"></string>
<string name="action_next_as_more_key">\@string/label_next_key|\@integer/key_action_next</string>
<string name="action_previous_as_more_key">\@string/label_previous_key|\@integer/key_action_previous</string>
<string name="action_next_as_more_key">!hasLabels!,\@string/label_next_key|\@integer/key_action_next</string>
<string name="action_previous_as_more_key">!hasLabels!,\@string/label_previous_key|\@integer/key_action_previous</string>
<string name="keylabel_for_symbols_question">\?</string>
<string name="keylabel_for_symbols_semicolon">;</string>
<string name="keylabel_for_symbols_percent">%</string>

View file

@ -49,7 +49,7 @@
<key-style
latin:styleName="navigateMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint|preserveCase"
latin:moreKeys="!fixedColumnOrder!2,\@string/action_previous_as_more_key,\@string/action_next_as_more_key" />
latin:moreKeys="!fixedColumnOrder!2,@string/action_previous_as_more_key,@string/action_next_as_more_key" />
</case>
<case
latin:navigateNext="true"

View file

@ -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);
}
}
}

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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);