Support dividers in MoreKeysKeyboard
Bug: 6080806 Change-Id: Iacd78c6aab6abf948717d34da7489a79c41316d2main
parent
961703841e
commit
5ef4fccbb9
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
|
@ -49,7 +49,7 @@
|
||||||
<key-style
|
<key-style
|
||||||
latin:styleName="navigateMoreKeysStyle"
|
latin:styleName="navigateMoreKeysStyle"
|
||||||
latin:keyLabelFlags="hasPopupHint|preserveCase"
|
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>
|
||||||
<case
|
<case
|
||||||
latin:navigateNext="true"
|
latin:navigateNext="true"
|
||||||
|
|
|
@ -108,9 +108,11 @@ public class Key {
|
||||||
private static final int MORE_KEYS_COLUMN_MASK = 0x000000ff;
|
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_FIXED_COLUMN_ORDER = 0x80000000;
|
||||||
private static final int MORE_KEYS_FLAGS_HAS_LABELS = 0x40000000;
|
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_AUTO_COLUMN_ORDER = "!autoColumnOrder!";
|
||||||
private static final String MORE_KEYS_FIXED_COLUMN_ORDER = "!fixedColumnOrder!";
|
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_HAS_LABELS = "!hasLabels!";
|
||||||
|
private static final String MORE_KEYS_NEEDS_DIVIDERS = "!needsDividers!";
|
||||||
|
|
||||||
/** Background type that represents different key background visual than normal one. */
|
/** Background type that represents different key background visual than normal one. */
|
||||||
public final int mBackgroundType;
|
public final int mBackgroundType;
|
||||||
|
@ -253,6 +255,9 @@ public class Key {
|
||||||
if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_HAS_LABELS)) {
|
if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_HAS_LABELS)) {
|
||||||
moreKeysColumn |= MORE_KEYS_FLAGS_HAS_LABELS;
|
moreKeysColumn |= MORE_KEYS_FLAGS_HAS_LABELS;
|
||||||
}
|
}
|
||||||
|
if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_NEEDS_DIVIDERS)) {
|
||||||
|
moreKeysColumn |= MORE_KEYS_FLAGS_NEEDS_DIVIDERS;
|
||||||
|
}
|
||||||
mMoreKeysColumnAndFlags = moreKeysColumn;
|
mMoreKeysColumnAndFlags = moreKeysColumn;
|
||||||
|
|
||||||
final String[] additionalMoreKeys = style.getStringArray(
|
final String[] additionalMoreKeys = style.getStringArray(
|
||||||
|
@ -539,6 +544,10 @@ public class Key {
|
||||||
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_HAS_LABELS) != 0;
|
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_HAS_LABELS) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean needsDividersInMoreKeys() {
|
||||||
|
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_NEEDS_DIVIDERS) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
public Drawable getIcon(KeyboardIconsSet iconSet) {
|
public Drawable getIcon(KeyboardIconsSet iconSet) {
|
||||||
return iconSet.getIconDrawable(mIconId);
|
return iconSet.getIconDrawable(mIconId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.internal.KeySpecParser;
|
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.R;
|
||||||
import com.android.inputmethod.latin.Utils;
|
import com.android.inputmethod.latin.Utils;
|
||||||
|
|
||||||
|
@ -36,8 +38,10 @@ public class MoreKeysKeyboard extends Keyboard {
|
||||||
|
|
||||||
public static class Builder extends Keyboard.Builder<Builder.MoreKeysKeyboardParams> {
|
public static class Builder extends Keyboard.Builder<Builder.MoreKeysKeyboardParams> {
|
||||||
private final Key mParentKey;
|
private final Key mParentKey;
|
||||||
|
private final Drawable mDivider;
|
||||||
|
|
||||||
private static final float LABEL_PADDING_RATIO = 0.2f;
|
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 static class MoreKeysKeyboardParams extends Keyboard.Params {
|
||||||
public boolean mIsFixedOrder;
|
public boolean mIsFixedOrder;
|
||||||
|
@ -47,6 +51,8 @@ public class MoreKeysKeyboard extends Keyboard {
|
||||||
public int mTopKeys;
|
public int mTopKeys;
|
||||||
public int mLeftKeys;
|
public int mLeftKeys;
|
||||||
public int mRightKeys; // includes default key.
|
public int mRightKeys; // includes default key.
|
||||||
|
public int mDividerWidth;
|
||||||
|
public int mColumnWidth;
|
||||||
|
|
||||||
public MoreKeysKeyboardParams() {
|
public MoreKeysKeyboardParams() {
|
||||||
super();
|
super();
|
||||||
|
@ -62,9 +68,11 @@ public class MoreKeysKeyboard extends Keyboard {
|
||||||
* @param coordXInParent coordinate x of the key preview in parent keyboard.
|
* @param coordXInParent coordinate x of the key preview in parent keyboard.
|
||||||
* @param parentKeyboardWidth parent keyboard width in pixel.
|
* @param parentKeyboardWidth parent keyboard width in pixel.
|
||||||
* @param isFixedColumnOrder if true, more keys should be laid out in fixed order.
|
* @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,
|
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;
|
mIsFixedOrder = isFixedColumnOrder;
|
||||||
if (parentKeyboardWidth / keyWidth < maxColumns) {
|
if (parentKeyboardWidth / keyWidth < maxColumns) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -116,7 +124,9 @@ public class MoreKeysKeyboard extends Keyboard {
|
||||||
// Adjustment of the top row.
|
// Adjustment of the top row.
|
||||||
mTopRowAdjustment = mIsFixedOrder ? getFixedOrderTopRowAdjustment()
|
mTopRowAdjustment = mIsFixedOrder ? getFixedOrderTopRowAdjustment()
|
||||||
: getAutoOrderTopRowAdjustment();
|
: getAutoOrderTopRowAdjustment();
|
||||||
mBaseWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth;
|
mDividerWidth = dividerWidth;
|
||||||
|
mColumnWidth = mDefaultKeyWidth + mDividerWidth;
|
||||||
|
mBaseWidth = mOccupiedWidth = mNumColumns * mColumnWidth - mDividerWidth;
|
||||||
// Need to subtract the bottom row's gutter only.
|
// Need to subtract the bottom row's gutter only.
|
||||||
mBaseHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight - mVerticalGap
|
mBaseHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight - mVerticalGap
|
||||||
+ mTopPadding + mBottomPadding;
|
+ mTopPadding + mBottomPadding;
|
||||||
|
@ -214,13 +224,13 @@ public class MoreKeysKeyboard extends Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefaultKeyCoordX() {
|
public int getDefaultKeyCoordX() {
|
||||||
return mLeftKeys * mDefaultKeyWidth;
|
return mLeftKeys * mColumnWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX(int n, int row) {
|
public int getX(int n, int row) {
|
||||||
final int x = getColumnPos(n) * mDefaultKeyWidth + getDefaultKeyCoordX();
|
final int x = getColumnPos(n) * mColumnWidth + getDefaultKeyCoordX();
|
||||||
if (isTopRow(row)) {
|
if (isTopRow(row)) {
|
||||||
return x + mTopRowAdjustment * (mDefaultKeyWidth / 2);
|
return x + mTopRowAdjustment * (mColumnWidth / 2);
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -267,9 +277,19 @@ public class MoreKeysKeyboard extends Keyboard {
|
||||||
width = getMaxKeyWidth(view, parentKey, mParams.mDefaultKeyWidth);
|
width = getMaxKeyWidth(view, parentKey, mParams.mDefaultKeyWidth);
|
||||||
height = parentKeyboard.mMostCommonKeyHeight;
|
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(),
|
mParams.setParameters(parentKey.mMoreKeys.length, parentKey.getMoreKeysColumn(),
|
||||||
width, height, parentKey.mX + parentKey.mWidth / 2, view.getMeasuredWidth(),
|
width, height, parentKey.mX + parentKey.mWidth / 2, view.getMeasuredWidth(),
|
||||||
parentKey.isFixedColumnOrderMoreKeys());
|
parentKey.isFixedColumnOrderMoreKeys(), dividerWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getMaxKeyWidth(KeyboardView view, Key parentKey, int minKeyWidth) {
|
private static int getMaxKeyWidth(KeyboardView view, Key parentKey, int minKeyWidth) {
|
||||||
|
@ -295,6 +315,21 @@ public class MoreKeysKeyboard extends Keyboard {
|
||||||
return maxWidth;
|
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
|
@Override
|
||||||
public MoreKeysKeyboard build() {
|
public MoreKeysKeyboard build() {
|
||||||
final MoreKeysKeyboardParams params = mParams;
|
final MoreKeysKeyboardParams params = mParams;
|
||||||
|
@ -306,11 +341,22 @@ public class MoreKeysKeyboard extends Keyboard {
|
||||||
for (int n = 0; n < moreKeys.length; n++) {
|
for (int n = 0; n < moreKeys.length; n++) {
|
||||||
final String moreKeySpec = moreKeys[n];
|
final String moreKeySpec = moreKeys[n];
|
||||||
final int row = n / params.mNumColumns;
|
final int row = n / params.mNumColumns;
|
||||||
final Key key = new Key(mResources, params, moreKeySpec, params.getX(n, row),
|
final int x = params.getX(n, row);
|
||||||
params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight,
|
final int y = params.getY(row);
|
||||||
moreKeyFlags);
|
final Key key = new Key(mResources, params, moreKeySpec, x, y,
|
||||||
|
params.mDefaultKeyWidth, params.mDefaultRowHeight, moreKeyFlags);
|
||||||
params.markAsEdgeKey(key, row);
|
params.markAsEdgeKey(key, row);
|
||||||
params.onAddKey(key);
|
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);
|
return new MoreKeysKeyboard(params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
public class MoreSuggestions extends Keyboard {
|
public class MoreSuggestions extends Keyboard {
|
||||||
public static final int SUGGESTION_CODE_BASE = 1024;
|
public static final int SUGGESTION_CODE_BASE = 1024;
|
||||||
|
|
||||||
private MoreSuggestions(Builder.MoreSuggestionsParam params) {
|
MoreSuggestions(Builder.MoreSuggestionsParam params) {
|
||||||
super(params);
|
super(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class MoreSuggestions extends Keyboard {
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
final Resources res = view.getContext().getResources();
|
final Resources res = view.getContext().getResources();
|
||||||
mDivider = res.getDrawable(R.drawable.more_suggestions_divider);
|
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);
|
mDivider.setAlpha(128);
|
||||||
mDividerWidth = mDivider.getIntrinsicWidth();
|
mDividerWidth = mDivider.getIntrinsicWidth();
|
||||||
final int padding = (int) res.getDimension(
|
final int padding = (int) res.getDimension(
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class MoreKeysKeyboardBuilderFixedOrderTests extends AndroidTestCase {
|
||||||
int coordXInParnet) {
|
int coordXInParnet) {
|
||||||
final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams();
|
final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams();
|
||||||
params.setParameters(numKeys, columnNum, WIDTH, HEIGHT, coordXInParnet, KEYBOARD_WIDTH,
|
params.setParameters(numKeys, columnNum, WIDTH, HEIGHT, coordXInParnet, KEYBOARD_WIDTH,
|
||||||
/* isFixedOrderColumn */true);
|
/* isFixedOrderColumn */true, /* dividerWidth */0);
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class MoreKeysKeyboardBuilderTests extends AndroidTestCase {
|
||||||
int coordXInParnet) {
|
int coordXInParnet) {
|
||||||
final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams();
|
final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams();
|
||||||
params.setParameters(numKeys, maxColumns, WIDTH, HEIGHT, coordXInParnet, KEYBOARD_WIDTH,
|
params.setParameters(numKeys, maxColumns, WIDTH, HEIGHT, coordXInParnet, KEYBOARD_WIDTH,
|
||||||
/* isFixedOrderColumn */false);
|
/* isFixedOrderColumn */false, /* dividerWidth */0);
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue