Merge "Remove Row object from MiniKeyboardBuilder"
This commit is contained in:
commit
ca65332145
3 changed files with 20 additions and 36 deletions
|
@ -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.
|
* This constructor is being used only for key in mini popup keyboard.
|
||||||
*/
|
*/
|
||||||
public Key(Resources res, Row row, CharSequence popupCharacter, int x, int y) {
|
public Key(Resources res, Keyboard keyboard, CharSequence popupCharacter, int x, int y,
|
||||||
mKeyboard = row.getKeyboard();
|
int edgeFlags) {
|
||||||
mHeight = row.mDefaultHeight - row.mVerticalGap;
|
mKeyboard = keyboard;
|
||||||
mGap = row.mDefaultHorizontalGap;
|
mHeight = keyboard.getRowHeight() - keyboard.getVerticalGap();
|
||||||
mWidth = row.mDefaultWidth - mGap;
|
mGap = keyboard.getHorizontalGap();
|
||||||
mEdgeFlags = row.mRowEdgeFlags;
|
mWidth = keyboard.getKeyWidth() - mGap;
|
||||||
|
mEdgeFlags = edgeFlags;
|
||||||
mHintIcon = null;
|
mHintIcon = null;
|
||||||
mManualTemporaryUpperCaseHintIcon = null;
|
mManualTemporaryUpperCaseHintIcon = null;
|
||||||
mManualTemporaryUpperCaseCode = Keyboard.CODE_DUMMY;
|
mManualTemporaryUpperCaseCode = Keyboard.CODE_DUMMY;
|
||||||
|
|
|
@ -29,13 +29,13 @@ public class MiniKeyboardBuilder {
|
||||||
private final int mNumRows;
|
private final int mNumRows;
|
||||||
private int mColPos;
|
private int mColPos;
|
||||||
private int mRowPos;
|
private int mRowPos;
|
||||||
private Row mRow;
|
|
||||||
private int mX;
|
private int mX;
|
||||||
private int mY;
|
private int mY;
|
||||||
|
|
||||||
public MiniKeyboardBuilder(Context context, int layoutTemplateResId, Key popupKey) {
|
public MiniKeyboardBuilder(Context context, int layoutTemplateResId, Key popupKey) {
|
||||||
mRes = context.getResources();
|
mRes = context.getResources();
|
||||||
mKeyboard = new Keyboard(context, layoutTemplateResId, null);
|
final Keyboard keyboard = new Keyboard(context, layoutTemplateResId, null);
|
||||||
|
mKeyboard = keyboard;
|
||||||
mPopupCharacters = popupKey.mPopupCharacters;
|
mPopupCharacters = popupKey.mPopupCharacters;
|
||||||
final int numKeys = mPopupCharacters.length;
|
final int numKeys = mPopupCharacters.length;
|
||||||
final int maxColumns = popupKey.mMaxPopupColumn;
|
final int maxColumns = popupKey.mMaxPopupColumn;
|
||||||
|
@ -43,27 +43,28 @@ public class MiniKeyboardBuilder {
|
||||||
if (numKeys % maxColumns != 0) numRows++;
|
if (numKeys % maxColumns != 0) numRows++;
|
||||||
mMaxColumns = maxColumns;
|
mMaxColumns = maxColumns;
|
||||||
mNumRows = numRows;
|
mNumRows = numRows;
|
||||||
|
keyboard.setHeight((keyboard.getRowHeight() + keyboard.getVerticalGap()) * numRows
|
||||||
|
- keyboard.getVerticalGap());
|
||||||
// TODO: To determine key width we should pay attention to key label length.
|
// TODO: To determine key width we should pay attention to key label length.
|
||||||
mRow = new Row(mKeyboard, getRowFlags());
|
|
||||||
if (numRows > 1) {
|
if (numRows > 1) {
|
||||||
mColPos = numKeys % maxColumns;
|
mColPos = numKeys % maxColumns;
|
||||||
if (mColPos > 0) mColPos = maxColumns - mColPos;
|
if (mColPos > 0) mColPos = maxColumns - mColPos;
|
||||||
// Centering top-row keys.
|
// Centering top-row keys.
|
||||||
mX = mColPos * (mRow.mDefaultWidth + mRow.mDefaultHorizontalGap) / 2;
|
mX = mColPos * (keyboard.getKeyWidth() + keyboard.getHorizontalGap()) / 2;
|
||||||
}
|
}
|
||||||
mKeyboard.setMinWidth(0);
|
mKeyboard.setMinWidth(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Keyboard build() {
|
public Keyboard build() {
|
||||||
List<Key> keys = mKeyboard.getKeys();
|
final Keyboard keyboard = mKeyboard;
|
||||||
|
final List<Key> keys = keyboard.getKeys();
|
||||||
for (CharSequence label : mPopupCharacters) {
|
for (CharSequence label : mPopupCharacters) {
|
||||||
refresh();
|
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);
|
keys.add(key);
|
||||||
advance();
|
advance();
|
||||||
}
|
}
|
||||||
finish();
|
return keyboard;
|
||||||
return mKeyboard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getRowFlags() {
|
private int getRowFlags() {
|
||||||
|
@ -76,29 +77,21 @@ public class MiniKeyboardBuilder {
|
||||||
|
|
||||||
private void refresh() {
|
private void refresh() {
|
||||||
if (mColPos >= mMaxColumns) {
|
if (mColPos >= mMaxColumns) {
|
||||||
final Row row = mRow;
|
final Keyboard keyboard = mKeyboard;
|
||||||
// TODO: Allocate key position depending the precedence of popup characters.
|
// TODO: Allocate key position depending the precedence of popup characters.
|
||||||
mX = 0;
|
mX = 0;
|
||||||
mY += row.mDefaultHeight + row.mVerticalGap;
|
mY += keyboard.getRowHeight() + keyboard.getVerticalGap();
|
||||||
mColPos = 0;
|
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++;
|
mRowPos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void advance() {
|
private void advance() {
|
||||||
final Row row = mRow;
|
|
||||||
final Keyboard keyboard = mKeyboard;
|
final Keyboard keyboard = mKeyboard;
|
||||||
// TODO: Allocate key position depending the precedence of popup characters.
|
// TODO: Allocate key position depending the precedence of popup characters.
|
||||||
mX += row.mDefaultWidth + row.mDefaultHorizontalGap;
|
mX += keyboard.getKeyWidth() + keyboard.getHorizontalGap();
|
||||||
if (mX > keyboard.getMinWidth())
|
if (mX > keyboard.getMinWidth())
|
||||||
keyboard.setMinWidth(mX);
|
keyboard.setMinWidth(mX);
|
||||||
mColPos++;
|
mColPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finish() {
|
|
||||||
mKeyboard.setHeight(mY + mRow.mDefaultHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -45,15 +45,6 @@ public class Row {
|
||||||
|
|
||||||
private final Keyboard mKeyboard;
|
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) {
|
public Row(Resources res, Keyboard keyboard, XmlResourceParser parser) {
|
||||||
this.mKeyboard = keyboard;
|
this.mKeyboard = keyboard;
|
||||||
final int keyboardWidth = keyboard.getDisplayWidth();
|
final int keyboardWidth = keyboard.getDisplayWidth();
|
||||||
|
|
Loading…
Reference in a new issue