Make Spacer as extended Key class
Bug: 5275003 Change-Id: I809a8ca363ba72b22ac5cfd926414990f7e8467c
This commit is contained in:
parent
2be872555c
commit
18453d69e0
7 changed files with 69 additions and 57 deletions
|
@ -150,8 +150,8 @@
|
||||||
area between the nearest key on the left hand side and the right edge of the keyboard.
|
area between the nearest key on the left hand side and the right edge of the keyboard.
|
||||||
-->
|
-->
|
||||||
<attr name="keyWidth" format="dimension|fraction|enum">
|
<attr name="keyWidth" format="dimension|fraction|enum">
|
||||||
<enum name="fillRight" value="0" />
|
<enum name="fillRight" value="-1" />
|
||||||
<enum name="fillBoth" value="-1" />
|
<enum name="fillBoth" value="-2" />
|
||||||
</attr>
|
</attr>
|
||||||
<!-- Default height of a row (key height + vertical gap), in pixels or percentage of
|
<!-- Default height of a row (key height + vertical gap), in pixels or percentage of
|
||||||
keyboard height. -->
|
keyboard height. -->
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="nonSpecialBackgroundSpaceKeyStyle"
|
latin:keyStyle="nonSpecialBackgroundSpaceKeyStyle"
|
||||||
latin:keyXPos="15.625%p"
|
latin:keyXPos="15.625%p"
|
||||||
latin:keyWidth="18.67%p" />
|
latin:keyWidth="18.50%p" />
|
||||||
<Key
|
<Key
|
||||||
latin:keyStyle="numStarKeyStyle"
|
latin:keyStyle="numStarKeyStyle"
|
||||||
latin:keyXPos="38.867%p" />
|
latin:keyXPos="38.867%p" />
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
</switch>
|
</switch>
|
||||||
<Spacer
|
<Spacer
|
||||||
latin:keyXPos="15.157%p"
|
latin:keyXPos="15.157%p"
|
||||||
latin:keyWidth="fillRight" />
|
latin:keyWidth="0%p" />
|
||||||
<switch>
|
<switch>
|
||||||
<case
|
<case
|
||||||
latin:mode="url"
|
latin:mode="url"
|
||||||
|
|
|
@ -115,9 +115,10 @@ public class Key {
|
||||||
/** Whether this key needs to show the "..." popup hint for special purposes */
|
/** Whether this key needs to show the "..." popup hint for special purposes */
|
||||||
private boolean mNeedsSpecialPopupHint;
|
private boolean mNeedsSpecialPopupHint;
|
||||||
|
|
||||||
// keyWidth constants
|
// keyWidth enum constants
|
||||||
private static final int KEYWIDTH_FILL_RIGHT = 0;
|
private static final int KEYWIDTH_NOT_ENUM = 0;
|
||||||
private static final int KEYWIDTH_FILL_BOTH = -1;
|
private static final int KEYWIDTH_FILL_RIGHT = -1;
|
||||||
|
private static final int KEYWIDTH_FILL_BOTH = -2;
|
||||||
|
|
||||||
private final static int[] KEY_STATE_NORMAL_ON = {
|
private final static int[] KEY_STATE_NORMAL_ON = {
|
||||||
android.R.attr.state_checkable,
|
android.R.attr.state_checkable,
|
||||||
|
@ -249,15 +250,17 @@ public class Key {
|
||||||
*/
|
*/
|
||||||
public Key(Resources res, KeyboardParams params, KeyboardBuilder.Row row,
|
public Key(Resources res, KeyboardParams params, KeyboardBuilder.Row row,
|
||||||
XmlResourceParser parser, KeyStyles keyStyles) {
|
XmlResourceParser parser, KeyStyles keyStyles) {
|
||||||
|
|
||||||
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
|
||||||
R.styleable.Keyboard);
|
R.styleable.Keyboard);
|
||||||
mHeight = (int)KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
mHeight = (int)KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_rowHeight, params.mHeight, row.mRowHeight)
|
R.styleable.Keyboard_rowHeight, params.mHeight, row.mRowHeight)
|
||||||
- params.mVerticalGap;
|
- params.mVerticalGap;
|
||||||
final float horizontalGap = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
final float horizontalGap = isSpacer() ? 0
|
||||||
|
: KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_horizontalGap, params.mWidth, params.mHorizontalGap);
|
R.styleable.Keyboard_horizontalGap, params.mWidth, params.mHorizontalGap);
|
||||||
mVerticalGap = params.mVerticalGap;
|
mVerticalGap = params.mVerticalGap;
|
||||||
|
final int widthType = KeyboardBuilder.getEnumValue(keyboardAttr,
|
||||||
|
R.styleable.Keyboard_keyWidth, KEYWIDTH_NOT_ENUM);
|
||||||
float keyWidth = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
float keyWidth = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
|
||||||
R.styleable.Keyboard_keyWidth, params.mWidth, row.mDefaultKeyWidth);
|
R.styleable.Keyboard_keyWidth, params.mWidth, row.mDefaultKeyWidth);
|
||||||
keyboardAttr.recycle();
|
keyboardAttr.recycle();
|
||||||
|
@ -288,11 +291,11 @@ public class Key {
|
||||||
keyXPos = x;
|
keyXPos = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (keyWidth == KEYWIDTH_FILL_RIGHT) {
|
if (widthType == KEYWIDTH_FILL_RIGHT) {
|
||||||
// If keyWidth is zero, the actual key width will be determined to fill out the
|
// If keyWidth is zero, the actual key width will be determined to fill out the
|
||||||
// area up to the right edge of the keyboard.
|
// area up to the right edge of the keyboard.
|
||||||
keyWidth = keyboardWidth - keyXPos;
|
keyWidth = keyboardWidth - keyXPos;
|
||||||
} else if (keyWidth <= KEYWIDTH_FILL_BOTH) {
|
} else if (widthType == KEYWIDTH_FILL_BOTH) {
|
||||||
// If keyWidth is negative, the actual key width will be determined to fill out the
|
// If keyWidth is negative, the actual key width will be determined to fill out the
|
||||||
// area between the nearest key on the left hand side and the right edge of the
|
// area between the nearest key on the left hand side and the right edge of the
|
||||||
// keyboard.
|
// keyboard.
|
||||||
|
@ -367,6 +370,10 @@ public class Key {
|
||||||
mEdgeFlags |= flags;
|
mEdgeFlags |= flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSpacer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public Typeface selectTypeface(Typeface defaultTypeface) {
|
public Typeface selectTypeface(Typeface defaultTypeface) {
|
||||||
// TODO: Handle "bold" here too?
|
// TODO: Handle "bold" here too?
|
||||||
if ((mLabelOption & LABEL_OPTION_FONT_NORMAL) != 0) {
|
if ((mLabelOption & LABEL_OPTION_FONT_NORMAL) != 0) {
|
||||||
|
@ -559,4 +566,16 @@ public class Key {
|
||||||
}
|
}
|
||||||
return states;
|
return states;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Spacer extends Key {
|
||||||
|
public Spacer(Resources res, KeyboardParams params, KeyboardBuilder.Row row,
|
||||||
|
XmlResourceParser parser, KeyStyles keyStyles) {
|
||||||
|
super(res, params, row, parser, keyStyles);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpacer() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,6 +510,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
Paint paint, KeyDrawParams params, boolean isManualTemporaryUpperCase) {
|
Paint paint, KeyDrawParams params, boolean isManualTemporaryUpperCase) {
|
||||||
final boolean debugShowAlign = LatinImeLogger.sVISUALDEBUG;
|
final boolean debugShowAlign = LatinImeLogger.sVISUALDEBUG;
|
||||||
// Draw key background.
|
// Draw key background.
|
||||||
|
if (!key.isSpacer()) {
|
||||||
final int bgWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight
|
final int bgWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight
|
||||||
+ params.mPadding.left + params.mPadding.right;
|
+ params.mPadding.left + params.mPadding.right;
|
||||||
final int bgHeight = key.mHeight + params.mPadding.top + params.mPadding.bottom;
|
final int bgHeight = key.mHeight + params.mPadding.top + params.mPadding.bottom;
|
||||||
|
@ -528,6 +529,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
drawRectangle(canvas, 0, 0, bgWidth, bgHeight, 0x80c00000, new Paint());
|
drawRectangle(canvas, 0, 0, bgWidth, bgHeight, 0x80c00000, new Paint());
|
||||||
}
|
}
|
||||||
canvas.translate(-bgX, -bgY);
|
canvas.translate(-bgX, -bgY);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw key top visuals.
|
// Draw key top visuals.
|
||||||
final int keyWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
|
final int keyWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
|
||||||
|
|
|
@ -122,6 +122,7 @@ public class ProximityInfo {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < keys.size(); i++) {
|
for (int i = 0; i < keys.size(); i++) {
|
||||||
final Key key = keys.get(i);
|
final Key key = keys.get(i);
|
||||||
|
if (key.isSpacer()) continue;
|
||||||
if (key.squaredDistanceToEdge(centerX, centerY) < threshold)
|
if (key.squaredDistanceToEdge(centerX, centerY) < threshold)
|
||||||
indices[count++] = i;
|
indices[count++] = i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,12 +394,11 @@ 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, parser, mKeyStyles);
|
final 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)));
|
||||||
checkEndTag(TAG_KEY, parser);
|
checkEndTag(TAG_KEY, parser);
|
||||||
mParams.onAddKey(key);
|
|
||||||
endKey(key);
|
endKey(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,27 +408,10 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
if (skip) {
|
if (skip) {
|
||||||
checkEndTag(TAG_SPACER, parser);
|
checkEndTag(TAG_SPACER, parser);
|
||||||
} else {
|
} else {
|
||||||
|
final Key.Spacer spacer = new Key.Spacer(mResources, mParams, row, parser, mKeyStyles);
|
||||||
if (DEBUG) Log.d(TAG, String.format("<%s />", TAG_SPACER));
|
if (DEBUG) Log.d(TAG, String.format("<%s />", TAG_SPACER));
|
||||||
final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
|
|
||||||
R.styleable.Keyboard);
|
|
||||||
if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap))
|
|
||||||
throw new IllegalAttribute(parser, "horizontalGap");
|
|
||||||
final int keyboardWidth = mParams.mWidth;
|
|
||||||
final float keyWidth = getDimensionOrFraction(keyboardAttr,
|
|
||||||
R.styleable.Keyboard_keyWidth, keyboardWidth, row.mDefaultKeyWidth);
|
|
||||||
keyboardAttr.recycle();
|
|
||||||
|
|
||||||
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
|
|
||||||
R.styleable.Keyboard_Key);
|
|
||||||
float keyXPos = getDimensionOrFraction(keyAttr,
|
|
||||||
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, row.mCurrentX);
|
|
||||||
if (keyXPos < 0) {
|
|
||||||
// If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos.
|
|
||||||
keyXPos += keyboardWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkEndTag(TAG_SPACER, parser);
|
checkEndTag(TAG_SPACER, parser);
|
||||||
setSpacer(keyXPos, keyWidth, row);
|
endKey(spacer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +668,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
|
|
||||||
private void startRow(Row row) {
|
private void startRow(Row row) {
|
||||||
row.mCurrentX = 0;
|
row.mCurrentX = 0;
|
||||||
setSpacer(row.mCurrentX, mParams.mHorizontalEdgesPadding, row);
|
addEdgeSpace(mParams.mHorizontalEdgesPadding, row);
|
||||||
mCurrentRow = row;
|
mCurrentRow = row;
|
||||||
mLeftEdge = true;
|
mLeftEdge = true;
|
||||||
mRightEdgeKey = null;
|
mRightEdgeKey = null;
|
||||||
|
@ -699,13 +681,14 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
mRightEdgeKey.addEdgeFlags(Keyboard.EDGE_RIGHT);
|
mRightEdgeKey.addEdgeFlags(Keyboard.EDGE_RIGHT);
|
||||||
mRightEdgeKey = null;
|
mRightEdgeKey = null;
|
||||||
}
|
}
|
||||||
setSpacer(row.mCurrentX, mParams.mHorizontalEdgesPadding, row);
|
addEdgeSpace(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) {
|
||||||
|
mParams.onAddKey(key);
|
||||||
if (mLeftEdge) {
|
if (mLeftEdge) {
|
||||||
key.addEdgeFlags(Keyboard.EDGE_LEFT);
|
key.addEdgeFlags(Keyboard.EDGE_LEFT);
|
||||||
mLeftEdge = false;
|
mLeftEdge = false;
|
||||||
|
@ -719,8 +702,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
private void endKeyboard() {
|
private void endKeyboard() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSpacer(float keyXPos, float width, Row row) {
|
private void addEdgeSpace(float width, Row row) {
|
||||||
row.mCurrentX = keyXPos + width;
|
row.mCurrentX += width;
|
||||||
mLeftEdge = false;
|
mLeftEdge = false;
|
||||||
mRightEdgeKey = null;
|
mRightEdgeKey = null;
|
||||||
}
|
}
|
||||||
|
@ -733,9 +716,16 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
return a.getFraction(index, base, base, defValue);
|
return a.getFraction(index, base, base, defValue);
|
||||||
} else if (isDimensionValue(value)) {
|
} else if (isDimensionValue(value)) {
|
||||||
return a.getDimension(index, defValue);
|
return a.getDimension(index, defValue);
|
||||||
} else if (isIntegerValue(value)) {
|
}
|
||||||
// For enum value.
|
return defValue;
|
||||||
return a.getInt(index, 0);
|
}
|
||||||
|
|
||||||
|
public static int getEnumValue(TypedArray a, int index, int defValue) {
|
||||||
|
final TypedValue value = a.peekValue(index);
|
||||||
|
if (value == null)
|
||||||
|
return defValue;
|
||||||
|
if (isIntegerValue(value)) {
|
||||||
|
return a.getInt(index, defValue);
|
||||||
}
|
}
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue