Merge "Support dividers in MoreKeysKeyboard"

This commit is contained in:
Tadashi G. Takaoka 2012-03-02 03:58:13 -08:00 committed by Android (Google) Code Review
commit 3a1844c33b
9 changed files with 69 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

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,!needsDividers!,@string/action_previous_as_more_key,@string/action_next_as_more_key" />
</case>
<case
latin:navigateNext="true"

View file

@ -108,9 +108,11 @@ public class Key {
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 int MORE_KEYS_FLAGS_NEEDS_DIVIDERS = 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!";
private static final String MORE_KEYS_NEEDS_DIVIDERS = "!needsDividers!";
/** Background type that represents different key background visual than normal one. */
public final int mBackgroundType;
@ -253,6 +255,9 @@ public class Key {
if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_HAS_LABELS)) {
moreKeysColumn |= MORE_KEYS_FLAGS_HAS_LABELS;
}
if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_NEEDS_DIVIDERS)) {
moreKeysColumn |= MORE_KEYS_FLAGS_NEEDS_DIVIDERS;
}
mMoreKeysColumnAndFlags = moreKeysColumn;
final String[] additionalMoreKeys = style.getStringArray(
@ -539,6 +544,10 @@ public class Key {
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_HAS_LABELS) != 0;
}
public boolean needsDividersInMoreKeys() {
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_NEEDS_DIVIDERS) != 0;
}
public Drawable getIcon(KeyboardIconsSet iconSet) {
return iconSet.getIconDrawable(mIconId);
}

View file

@ -17,8 +17,10 @@
package com.android.inputmethod.keyboard;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
@ -36,8 +38,10 @@ public class MoreKeysKeyboard extends Keyboard {
public static class Builder extends Keyboard.Builder<Builder.MoreKeysKeyboardParams> {
private final Key mParentKey;
private final Drawable mDivider;
private static final float LABEL_PADDING_RATIO = 0.2f;
private static final float DIVIDER_RATIO = 0.2f;
public static class MoreKeysKeyboardParams extends Keyboard.Params {
public boolean mIsFixedOrder;
@ -47,6 +51,8 @@ public class MoreKeysKeyboard extends Keyboard {
public int mTopKeys;
public int mLeftKeys;
public int mRightKeys; // includes default key.
public int mDividerWidth;
public int mColumnWidth;
public MoreKeysKeyboardParams() {
super();
@ -62,9 +68,11 @@ public class MoreKeysKeyboard extends Keyboard {
* @param coordXInParent coordinate x of the key preview in parent keyboard.
* @param parentKeyboardWidth parent keyboard width in pixel.
* @param isFixedColumnOrder if true, more keys should be laid out in fixed order.
* @param dividerWidth width of divider, zero for no dividers.
*/
public void setParameters(int numKeys, int maxColumns, int keyWidth, int rowHeight,
int coordXInParent, int parentKeyboardWidth, boolean isFixedColumnOrder) {
int coordXInParent, int parentKeyboardWidth, boolean isFixedColumnOrder,
int dividerWidth) {
mIsFixedOrder = isFixedColumnOrder;
if (parentKeyboardWidth / keyWidth < maxColumns) {
throw new IllegalArgumentException(
@ -116,7 +124,9 @@ public class MoreKeysKeyboard extends Keyboard {
// Adjustment of the top row.
mTopRowAdjustment = mIsFixedOrder ? getFixedOrderTopRowAdjustment()
: getAutoOrderTopRowAdjustment();
mBaseWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth;
mDividerWidth = dividerWidth;
mColumnWidth = mDefaultKeyWidth + mDividerWidth;
mBaseWidth = mOccupiedWidth = mNumColumns * mColumnWidth - mDividerWidth;
// Need to subtract the bottom row's gutter only.
mBaseHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight - mVerticalGap
+ mTopPadding + mBottomPadding;
@ -214,13 +224,13 @@ public class MoreKeysKeyboard extends Keyboard {
}
public int getDefaultKeyCoordX() {
return mLeftKeys * mDefaultKeyWidth;
return mLeftKeys * mColumnWidth;
}
public int getX(int n, int row) {
final int x = getColumnPos(n) * mDefaultKeyWidth + getDefaultKeyCoordX();
final int x = getColumnPos(n) * mColumnWidth + getDefaultKeyCoordX();
if (isTopRow(row)) {
return x + mTopRowAdjustment * (mDefaultKeyWidth / 2);
return x + mTopRowAdjustment * (mColumnWidth / 2);
}
return x;
}
@ -267,9 +277,19 @@ public class MoreKeysKeyboard extends Keyboard {
width = getMaxKeyWidth(view, parentKey, mParams.mDefaultKeyWidth);
height = parentKeyboard.mMostCommonKeyHeight;
}
final int dividerWidth;
if (parentKey.needsDividersInMoreKeys()) {
mDivider = mResources.getDrawable(R.drawable.more_keys_divider);
// TODO: Drawable itself should have an alpha value.
mDivider.setAlpha(128);
dividerWidth = (int)(width * DIVIDER_RATIO);
} else {
mDivider = null;
dividerWidth = 0;
}
mParams.setParameters(parentKey.mMoreKeys.length, parentKey.getMoreKeysColumn(),
width, height, parentKey.mX + parentKey.mWidth / 2, view.getMeasuredWidth(),
parentKey.isFixedColumnOrderMoreKeys());
parentKey.isFixedColumnOrderMoreKeys(), dividerWidth);
}
private static int getMaxKeyWidth(KeyboardView view, Key parentKey, int minKeyWidth) {
@ -295,6 +315,21 @@ public class MoreKeysKeyboard extends Keyboard {
return maxWidth;
}
private static class MoreKeyDivider extends Key.Spacer {
private final Drawable mIcon;
public MoreKeyDivider(MoreKeysKeyboardParams params, Drawable icon, int x, int y) {
super(params, x, y, params.mDividerWidth, params.mDefaultRowHeight);
mIcon = icon;
}
@Override
public Drawable getIcon(KeyboardIconsSet iconSet) {
// KeyboardIconsSet is unused. Use the icon that has been passed to the constructor.
return mIcon;
}
}
@Override
public MoreKeysKeyboard build() {
final MoreKeysKeyboardParams params = mParams;
@ -306,11 +341,22 @@ public class MoreKeysKeyboard extends Keyboard {
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,
moreKeyFlags);
final int x = params.getX(n, row);
final int y = params.getY(row);
final Key key = new Key(mResources, params, moreKeySpec, x, y,
params.mDefaultKeyWidth, params.mDefaultRowHeight, moreKeyFlags);
params.markAsEdgeKey(key, row);
params.onAddKey(key);
final int pos = params.getColumnPos(n);
// The "pos" value represents the offset from the default position. Negative means
// left of the default position.
if (params.mDividerWidth > 0 && pos != 0) {
final int dividerX = (pos > 0) ? x - params.mDividerWidth
: x + params.mDefaultKeyWidth;
final Key divider = new MoreKeyDivider(params, mDivider, dividerX, y);
params.onAddKey(divider);
}
}
return new MoreKeysKeyboard(params);
}

View file

@ -34,7 +34,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
public class MoreSuggestions extends Keyboard {
public static final int SUGGESTION_CODE_BASE = 1024;
private MoreSuggestions(Builder.MoreSuggestionsParam params) {
MoreSuggestions(Builder.MoreSuggestionsParam params) {
super(params);
}
@ -63,7 +63,7 @@ public class MoreSuggestions extends Keyboard {
paint.setAntiAlias(true);
final Resources res = view.getContext().getResources();
mDivider = res.getDrawable(R.drawable.more_suggestions_divider);
// TODO: Drawable itself should has an alpha value.
// TODO: Drawable itself should have an alpha value.
mDivider.setAlpha(128);
mDividerWidth = mDivider.getIntrinsicWidth();
final int padding = (int) res.getDimension(

View file

@ -45,7 +45,7 @@ public class MoreKeysKeyboardBuilderFixedOrderTests extends AndroidTestCase {
int coordXInParnet) {
final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams();
params.setParameters(numKeys, columnNum, WIDTH, HEIGHT, coordXInParnet, KEYBOARD_WIDTH,
/* isFixedOrderColumn */true);
/* isFixedOrderColumn */true, /* dividerWidth */0);
return params;
}

View file

@ -45,7 +45,7 @@ public class MoreKeysKeyboardBuilderTests extends AndroidTestCase {
int coordXInParnet) {
final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams();
params.setParameters(numKeys, maxColumns, WIDTH, HEIGHT, coordXInParnet, KEYBOARD_WIDTH,
/* isFixedOrderColumn */false);
/* isFixedOrderColumn */false, /* dividerWidth */0);
return params;
}