diff --git a/java/res/drawable-hdpi/more_keys_divider.png b/java/res/drawable-hdpi/more_keys_divider.png
new file mode 100644
index 000000000..a5912f95c
Binary files /dev/null and b/java/res/drawable-hdpi/more_keys_divider.png differ
diff --git a/java/res/drawable-mdpi/more_keys_divider.png b/java/res/drawable-mdpi/more_keys_divider.png
new file mode 100644
index 000000000..a46284f21
Binary files /dev/null and b/java/res/drawable-mdpi/more_keys_divider.png differ
diff --git a/java/res/drawable-xhdpi/more_keys_divider.png b/java/res/drawable-xhdpi/more_keys_divider.png
new file mode 100644
index 000000000..178594bf0
Binary files /dev/null and b/java/res/drawable-xhdpi/more_keys_divider.png differ
diff --git a/java/res/xml/key_styles_enter.xml b/java/res/xml/key_styles_enter.xml
index 61efb89b6..03bcb8620 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,!needsDividers!,@string/action_previous_as_more_key,@string/action_next_as_more_key" />
{
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);
}
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
index 0bd6abe09..cb1b49c67 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
@@ -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(
diff --git a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java
index afd3df40b..5c6c83432 100644
--- a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java
@@ -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;
}
diff --git a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java
index 456247bae..31f0e0fef 100644
--- a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java
@@ -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;
}