diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index af510b8b7..3b35c93d3 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -133,15 +133,15 @@ public class Key { }; /** - * Create an empty key with no attributes. * This constructor is being used only for key in mini popup keyboard. */ - public Key(Resources res, Row row, CharSequence popupCharacter, int x, int y) { - mKeyboard = row.getKeyboard(); - mHeight = row.mDefaultHeight - row.mVerticalGap; - mGap = row.mDefaultHorizontalGap; - mWidth = row.mDefaultWidth - mGap; - mEdgeFlags = row.mRowEdgeFlags; + public Key(Resources res, Keyboard keyboard, CharSequence popupCharacter, int x, int y, + int edgeFlags) { + mKeyboard = keyboard; + mHeight = keyboard.getRowHeight() - keyboard.getVerticalGap(); + mGap = keyboard.getHorizontalGap(); + mWidth = keyboard.getKeyWidth() - mGap; + mEdgeFlags = edgeFlags; mHintIcon = null; mManualTemporaryUpperCaseHintIcon = null; mManualTemporaryUpperCaseCode = Keyboard.CODE_DUMMY; diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java index 1eb0c3f37..33d19602d 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java @@ -29,13 +29,13 @@ public class MiniKeyboardBuilder { private final int mNumRows; private int mColPos; private int mRowPos; - private Row mRow; private int mX; private int mY; public MiniKeyboardBuilder(Context context, int layoutTemplateResId, Key popupKey) { mRes = context.getResources(); - mKeyboard = new Keyboard(context, layoutTemplateResId, null); + final Keyboard keyboard = new Keyboard(context, layoutTemplateResId, null); + mKeyboard = keyboard; mPopupCharacters = popupKey.mPopupCharacters; final int numKeys = mPopupCharacters.length; final int maxColumns = popupKey.mMaxPopupColumn; @@ -43,27 +43,28 @@ public class MiniKeyboardBuilder { if (numKeys % maxColumns != 0) numRows++; mMaxColumns = maxColumns; mNumRows = numRows; + keyboard.setHeight((keyboard.getRowHeight() + keyboard.getVerticalGap()) * numRows + - keyboard.getVerticalGap()); // TODO: To determine key width we should pay attention to key label length. - mRow = new Row(mKeyboard, getRowFlags()); if (numRows > 1) { mColPos = numKeys % maxColumns; if (mColPos > 0) mColPos = maxColumns - mColPos; // Centering top-row keys. - mX = mColPos * (mRow.mDefaultWidth + mRow.mDefaultHorizontalGap) / 2; + mX = mColPos * (keyboard.getKeyWidth() + keyboard.getHorizontalGap()) / 2; } mKeyboard.setMinWidth(0); } public Keyboard build() { - List keys = mKeyboard.getKeys(); + final Keyboard keyboard = mKeyboard; + final List keys = keyboard.getKeys(); for (CharSequence label : mPopupCharacters) { refresh(); - final Key key = new Key(mRes, mRow, label, mX, mY); + final Key key = new Key(mRes, keyboard, label, mX, mY, getRowFlags()); keys.add(key); advance(); } - finish(); - return mKeyboard; + return keyboard; } private int getRowFlags() { @@ -76,29 +77,21 @@ public class MiniKeyboardBuilder { private void refresh() { if (mColPos >= mMaxColumns) { - final Row row = mRow; + final Keyboard keyboard = mKeyboard; // TODO: Allocate key position depending the precedence of popup characters. mX = 0; - mY += row.mDefaultHeight + row.mVerticalGap; + mY += keyboard.getRowHeight() + keyboard.getVerticalGap(); mColPos = 0; - // TODO: To determine key width we should pay attention to key label length from - // bottom to up for rows. - mRow = new Row(mKeyboard, getRowFlags()); mRowPos++; } } private void advance() { - final Row row = mRow; final Keyboard keyboard = mKeyboard; // TODO: Allocate key position depending the precedence of popup characters. - mX += row.mDefaultWidth + row.mDefaultHorizontalGap; + mX += keyboard.getKeyWidth() + keyboard.getHorizontalGap(); if (mX > keyboard.getMinWidth()) keyboard.setMinWidth(mX); mColPos++; } - - private void finish() { - mKeyboard.setHeight(mY + mRow.mDefaultHeight); - } -} \ No newline at end of file +} diff --git a/java/src/com/android/inputmethod/keyboard/Row.java b/java/src/com/android/inputmethod/keyboard/Row.java index 198f02ca8..3618c0448 100644 --- a/java/src/com/android/inputmethod/keyboard/Row.java +++ b/java/src/com/android/inputmethod/keyboard/Row.java @@ -45,15 +45,6 @@ public class Row { private final Keyboard mKeyboard; - public Row(Keyboard keyboard, int rowFlags) { - this.mKeyboard = keyboard; - mDefaultHeight = keyboard.getRowHeight(); - mDefaultWidth = keyboard.getKeyWidth(); - mDefaultHorizontalGap = keyboard.getHorizontalGap(); - mVerticalGap = keyboard.getVerticalGap(); - mRowEdgeFlags = rowFlags; - } - public Row(Resources res, Keyboard keyboard, XmlResourceParser parser) { this.mKeyboard = keyboard; final int keyboardWidth = keyboard.getDisplayWidth();