Merge "Remove Row object from MiniKeyboardBuilder"

This commit is contained in:
Tadashi G. Takaoka 2011-01-05 21:20:18 -08:00 committed by Android (Google) Code Review
commit ca65332145
3 changed files with 20 additions and 36 deletions

View file

@ -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;

View file

@ -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<Key> keys = mKeyboard.getKeys();
final Keyboard keyboard = mKeyboard;
final List<Key> 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);
}
}

View file

@ -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();