Merge "Move current x coordinate value into Row class"
commit
3e0511e304
|
@ -243,14 +243,13 @@ public class Key {
|
||||||
* parser.
|
* parser.
|
||||||
* @param res resources associated with the caller's context
|
* @param res resources associated with the caller's context
|
||||||
* @param params the keyboard building parameters.
|
* @param params the keyboard building parameters.
|
||||||
* @param row the row that this key belongs to.
|
* @param row the row that this key belongs to. row's x-coordinate will be the right edge of
|
||||||
* @param x the x coordinate of the top-left
|
* this key.
|
||||||
* @param y the y coordinate of the top-left
|
|
||||||
* @param parser the XML parser containing the attributes for this key
|
* @param parser the XML parser containing the attributes for this key
|
||||||
* @param keyStyles active key styles set
|
* @param keyStyles active key styles set
|
||||||
*/
|
*/
|
||||||
public Key(Resources res, KeyboardParams params, Row row, int x, int y,
|
public Key(Resources res, KeyboardParams params, Row row, XmlResourceParser parser,
|
||||||
XmlResourceParser parser, KeyStyles keyStyles) {
|
KeyStyles keyStyles) {
|
||||||
|
|
||||||
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard);
|
R.styleable.Keyboard);
|
||||||
|
@ -284,6 +283,7 @@ public class Key {
|
||||||
}
|
}
|
||||||
|
|
||||||
final int keyboardWidth = params.mOccupiedWidth;
|
final int keyboardWidth = params.mOccupiedWidth;
|
||||||
|
final int x = row.mCurrentX;
|
||||||
int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x);
|
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x);
|
||||||
if (keyXPos < 0) {
|
if (keyXPos < 0) {
|
||||||
|
@ -309,9 +309,12 @@ public class Key {
|
||||||
|
|
||||||
// Horizontal gap is divided equally to both sides of the key.
|
// Horizontal gap is divided equally to both sides of the key.
|
||||||
mX = keyXPos + mHorizontalGap / 2;
|
mX = keyXPos + mHorizontalGap / 2;
|
||||||
mY = y;
|
mY = row.mCurrentY;
|
||||||
mWidth = keyWidth - mHorizontalGap;
|
mWidth = keyWidth - mHorizontalGap;
|
||||||
|
|
||||||
|
// Update row to have x-coordinate of the right edge of this key.
|
||||||
|
row.mCurrentX = keyXPos + keyWidth;
|
||||||
|
|
||||||
final CharSequence[] moreKeys = style.getTextArray(
|
final CharSequence[] moreKeys = style.getTextArray(
|
||||||
keyAttr, R.styleable.Keyboard_Key_moreKeys);
|
keyAttr, R.styleable.Keyboard_Key_moreKeys);
|
||||||
// In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
|
// In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
|
||||||
|
|
|
@ -128,7 +128,6 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
protected final Resources mResources;
|
protected final Resources mResources;
|
||||||
private final DisplayMetrics mDisplayMetrics;
|
private final DisplayMetrics mDisplayMetrics;
|
||||||
|
|
||||||
private int mCurrentX = 0;
|
|
||||||
private int mCurrentY = 0;
|
private int mCurrentY = 0;
|
||||||
private Row mCurrentRow = null;
|
private Row mCurrentRow = null;
|
||||||
private boolean mLeftEdge;
|
private boolean mLeftEdge;
|
||||||
|
@ -314,7 +313,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
throw new IllegalAttribute(parser, "horizontalGap");
|
throw new IllegalAttribute(parser, "horizontalGap");
|
||||||
if (a.hasValue(R.styleable.Keyboard_verticalGap))
|
if (a.hasValue(R.styleable.Keyboard_verticalGap))
|
||||||
throw new IllegalAttribute(parser, "verticalGap");
|
throw new IllegalAttribute(parser, "verticalGap");
|
||||||
return new Row(mResources, mParams, parser);
|
return new Row(mResources, mParams, parser, mCurrentY);
|
||||||
} finally {
|
} finally {
|
||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
@ -344,7 +343,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
if (TAG_ROW.equals(tag)) {
|
if (TAG_ROW.equals(tag)) {
|
||||||
if (DEBUG) Log.d(TAG, String.format("</%s>", TAG_ROW));
|
if (DEBUG) Log.d(TAG, String.format("</%s>", TAG_ROW));
|
||||||
if (!skip)
|
if (!skip)
|
||||||
endRow();
|
endRow(row);
|
||||||
break;
|
break;
|
||||||
} else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)
|
} else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)
|
||||||
|| TAG_MERGE.equals(tag)) {
|
|| TAG_MERGE.equals(tag)) {
|
||||||
|
@ -364,7 +363,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
if (skip) {
|
if (skip) {
|
||||||
checkEndTag(TAG_KEY, parser);
|
checkEndTag(TAG_KEY, parser);
|
||||||
} else {
|
} else {
|
||||||
Key key = new Key(mResources, mParams, row, mCurrentX, mCurrentY, parser, mKeyStyles);
|
Key key = new Key(mResources, mParams, row, parser, mKeyStyles);
|
||||||
if (DEBUG) Log.d(TAG, String.format("<%s%s keyLabel=%s code=%d moreKeys=%s />",
|
if (DEBUG) Log.d(TAG, String.format("<%s%s keyLabel=%s code=%d moreKeys=%s />",
|
||||||
TAG_KEY, (key.isEnabled() ? "" : " disabled"), key.mLabel, key.mCode,
|
TAG_KEY, (key.isEnabled() ? "" : " disabled"), key.mLabel, key.mCode,
|
||||||
Arrays.toString(key.mMoreKeys)));
|
Arrays.toString(key.mMoreKeys)));
|
||||||
|
@ -392,14 +391,14 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
|
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard_Key);
|
R.styleable.Keyboard_Key);
|
||||||
int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, mCurrentX);
|
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, row.mCurrentX);
|
||||||
if (keyXPos < 0) {
|
if (keyXPos < 0) {
|
||||||
// If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos.
|
// If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos.
|
||||||
keyXPos += keyboardWidth;
|
keyXPos += keyboardWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEndTag(TAG_SPACER, parser);
|
checkEndTag(TAG_SPACER, parser);
|
||||||
setSpacer(keyXPos, keyWidth);
|
setSpacer(keyXPos, keyWidth, row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,28 +654,27 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startRow(Row row) {
|
private void startRow(Row row) {
|
||||||
mCurrentX = 0;
|
row.mCurrentX = 0;
|
||||||
setSpacer(mCurrentX, mParams.mHorizontalEdgesPadding);
|
setSpacer(row.mCurrentX, mParams.mHorizontalEdgesPadding, row);
|
||||||
mCurrentRow = row;
|
mCurrentRow = row;
|
||||||
mLeftEdge = true;
|
mLeftEdge = true;
|
||||||
mRightEdgeKey = null;
|
mRightEdgeKey = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endRow() {
|
private void endRow(Row row) {
|
||||||
if (mCurrentRow == null)
|
if (mCurrentRow == null)
|
||||||
throw new InflateException("orphant end row tag");
|
throw new InflateException("orphant end row tag");
|
||||||
if (mRightEdgeKey != null) {
|
if (mRightEdgeKey != null) {
|
||||||
mRightEdgeKey.addEdgeFlags(Keyboard.EDGE_RIGHT);
|
mRightEdgeKey.addEdgeFlags(Keyboard.EDGE_RIGHT);
|
||||||
mRightEdgeKey = null;
|
mRightEdgeKey = null;
|
||||||
}
|
}
|
||||||
setSpacer(mCurrentX, mParams.mHorizontalEdgesPadding);
|
setSpacer(row.mCurrentX, mParams.mHorizontalEdgesPadding, row);
|
||||||
mCurrentY += mCurrentRow.mRowHeight;
|
mCurrentY += mCurrentRow.mRowHeight;
|
||||||
mCurrentRow = null;
|
mCurrentRow = null;
|
||||||
mTopEdge = false;
|
mTopEdge = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endKey(Key key) {
|
private void endKey(Key key) {
|
||||||
mCurrentX = key.mX - key.mHorizontalGap / 2 + key.mWidth + key.mHorizontalGap;
|
|
||||||
if (mLeftEdge) {
|
if (mLeftEdge) {
|
||||||
key.addEdgeFlags(Keyboard.EDGE_LEFT);
|
key.addEdgeFlags(Keyboard.EDGE_LEFT);
|
||||||
mLeftEdge = false;
|
mLeftEdge = false;
|
||||||
|
@ -690,8 +688,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
private void endKeyboard() {
|
private void endKeyboard() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSpacer(int keyXPos, int width) {
|
private void setSpacer(int keyXPos, int width, Row row) {
|
||||||
mCurrentX = keyXPos + width;
|
row.mCurrentX = keyXPos + width;
|
||||||
mLeftEdge = false;
|
mLeftEdge = false;
|
||||||
mRightEdgeKey = null;
|
mRightEdgeKey = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,11 @@ public class Row {
|
||||||
/** Default height of a key in this row. */
|
/** Default height of a key in this row. */
|
||||||
public final int mRowHeight;
|
public final int mRowHeight;
|
||||||
|
|
||||||
public Row(Resources res, KeyboardParams params, XmlResourceParser parser) {
|
public final int mCurrentY;
|
||||||
|
// Will be updated by {@link Key}'s constructor.
|
||||||
|
public int mCurrentX;
|
||||||
|
|
||||||
|
public Row(Resources res, KeyboardParams params, XmlResourceParser parser, int y) {
|
||||||
final int keyboardWidth = params.mWidth;
|
final int keyboardWidth = params.mWidth;
|
||||||
final int keyboardHeight = params.mHeight;
|
final int keyboardHeight = params.mHeight;
|
||||||
TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
|
TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
|
@ -45,5 +49,8 @@ public class Row {
|
||||||
mRowHeight = KeyboardBuilder.getDimensionOrFraction(a,
|
mRowHeight = KeyboardBuilder.getDimensionOrFraction(a,
|
||||||
R.styleable.Keyboard_rowHeight, keyboardHeight, params.mDefaultRowHeight);
|
R.styleable.Keyboard_rowHeight, keyboardHeight, params.mDefaultRowHeight);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
|
mCurrentY = y;
|
||||||
|
mCurrentX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue