Fix IllegalArgumentException in MoreKeysKeyboard

It seems that MainKeyboardView.getMeasuredWidth() returns weird
value. Using KeyboardId.mWidth as main keyboard width may resolve the
issue.

Bug: 9684622
Change-Id: I975bfb934b8d2448e72555a3ccae0123341186b9
main
Tadashi G. Takaoka 2013-07-19 11:31:52 +09:00
parent 03a76a07e2
commit b0e76724ed
3 changed files with 13 additions and 16 deletions

View File

@ -17,7 +17,6 @@
package com.android.inputmethod.keyboard;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
@ -76,10 +75,8 @@ public final class MoreKeysKeyboard extends Keyboard {
final boolean isFixedColumnOrder, final int dividerWidth) {
mIsFixedOrder = isFixedColumnOrder;
if (parentKeyboardWidth / keyWidth < Math.min(numKeys, maxColumns)) {
throw new IllegalArgumentException(
"Keyboard is too small to hold more keys keyboard: "
+ parentKeyboardWidth + " " + keyWidth + " "
+ numKeys + " " + maxColumns);
throw new IllegalArgumentException("Keyboard is too small to hold more keys: "
+ parentKeyboardWidth + " " + keyWidth + " " + numKeys + " " + maxColumns);
}
mDefaultKeyWidth = keyWidth;
mDefaultRowHeight = rowHeight;
@ -299,8 +296,12 @@ public final class MoreKeysKeyboard extends Keyboard {
width = keyPreviewDrawParams.mPreviewVisibleWidth;
height = keyPreviewDrawParams.mPreviewVisibleHeight + mParams.mVerticalGap;
} else {
width = getMaxKeyWidth(parentKeyboardView, parentKey, mParams.mDefaultKeyWidth,
context.getResources());
final float padding = context.getResources().getDimension(
R.dimen.more_keys_keyboard_key_horizontal_padding)
+ (parentKey.hasLabelsInMoreKeys()
? mParams.mDefaultKeyWidth * LABEL_PADDING_RATIO : 0.0f);
width = getMaxKeyWidth(parentKey, mParams.mDefaultKeyWidth, padding,
parentKeyboardView.newLabelPaint(parentKey));
height = parentKeyboard.mMostCommonKeyHeight;
}
final int dividerWidth;
@ -313,16 +314,12 @@ public final class MoreKeysKeyboard extends Keyboard {
}
mParams.setParameters(parentKey.mMoreKeys.length, parentKey.getMoreKeysColumn(),
width, height, parentKey.mX + parentKey.mWidth / 2,
parentKeyboardView.getMeasuredWidth(), parentKey.isFixedColumnOrderMoreKeys(),
parentKeyboard.mId.mWidth, parentKey.isFixedColumnOrderMoreKeys(),
dividerWidth);
}
private static int getMaxKeyWidth(final KeyboardView view, final Key parentKey,
final int minKeyWidth, final Resources res) {
final float padding =
res.getDimension(R.dimen.more_keys_keyboard_key_horizontal_padding)
+ (parentKey.hasLabelsInMoreKeys() ? minKeyWidth * LABEL_PADDING_RATIO : 0.0f);
final Paint paint = view.newLabelPaint(parentKey);
private static int getMaxKeyWidth(final Key parentKey, final int minKeyWidth,
final float padding, final Paint paint) {
int maxWidth = minKeyWidth;
for (final MoreKeySpec spec : parentKey.mMoreKeys) {
final String label = spec.mLabel;

View File

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

View File

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