From b0e76724edcde33dbfa17b56c3f5858705cd06ee Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 19 Jul 2013 11:31:52 +0900 Subject: [PATCH] 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 --- .../keyboard/MoreKeysKeyboard.java | 25 ++++++++----------- ...oreKeysKeyboardBuilderFixedOrderTests.java | 2 +- .../MoreKeysKeyboardBuilderTests.java | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java index d29e6382c..3fd29dcfd 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java @@ -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; diff --git a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java index 01814ae13..6d9c3fdbb 100644 --- a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java +++ b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java @@ -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; } diff --git a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java index ce5573da9..b213721bd 100644 --- a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java +++ b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java @@ -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; }