am a7b81435: am 71b52a84: Move key label padding attributes back to KeyboardView

* commit 'a7b81435c569dc2ec34b9a5655d702720cb47d1c':
  Move key label padding attributes back to KeyboardView
main
Tadashi G. Takaoka 2012-08-30 22:15:29 -07:00 committed by Android Git Automerger
commit 2eddb3928b
3 changed files with 73 additions and 49 deletions

View File

@ -41,6 +41,15 @@
checkable+checked+pressed. --> checkable+checked+pressed. -->
<attr name="keyBackground" format="reference" /> <attr name="keyBackground" format="reference" />
<!-- Horizontal padding of left/right aligned key label to the edge of the key. -->
<attr name="keyLabelHorizontalPadding" format="dimension" />
<!-- Right padding of hint letter to the edge of the key.-->
<attr name="keyHintLetterPadding" format="dimension" />
<!-- Bottom padding of popup hint letter "..." to the edge of the key.-->
<attr name="keyPopupHintLetterPadding" format="dimension" />
<!-- Right padding of shifted letter hint to the edge of the key.-->
<attr name="keyShiftedLetterHintPadding" format="dimension" />
<!-- Layout resource for key press feedback.--> <!-- Layout resource for key press feedback.-->
<attr name="keyPreviewLayout" format="reference" /> <attr name="keyPreviewLayout" format="reference" />
<!-- The background for key press feedback. --> <!-- The background for key press feedback. -->
@ -307,15 +316,7 @@
<!-- Size of the text for hint label, in the proportion of key height. --> <!-- Size of the text for hint label, in the proportion of key height. -->
<attr name="keyHintLabelRatio" format="fraction" /> <attr name="keyHintLabelRatio" format="fraction" />
<!-- Size of the text for shifted letter hint, in the proportion of key height. --> <!-- Size of the text for shifted letter hint, in the proportion of key height. -->
<attr name="keyShiftedLetterHintRatio" format="dimension|fraction" /> <attr name="keyShiftedLetterHintRatio" format="fraction" />
<!-- Horizontal padding of left/right aligned key label to the edge of the key. -->
<attr name="keyLabelHorizontalPadding" format="dimension" />
<!-- Right padding of hint letter to the edge of the key.-->
<attr name="keyHintLetterPadding" format="dimension" />
<!-- Bottom padding of popup hint letter "..." to the edge of the key.-->
<attr name="keyPopupHintLetterPadding" format="dimension" />
<!-- Right padding of shifted letter hint to the edge of the key.-->
<attr name="keyShiftedLetterHintPadding" format="dimension" />
<!-- Color to use for the label in a key. --> <!-- Color to use for the label in a key. -->
<attr name="keyTextColor" format="color" /> <attr name="keyTextColor" format="color" />
<attr name="keyTextShadowColor" format="color" /> <attr name="keyTextShadowColor" format="color" />

View File

@ -55,31 +55,54 @@ import java.util.HashSet;
/** /**
* A view that renders a virtual {@link Keyboard}. * A view that renders a virtual {@link Keyboard}.
* *
* @attr ref R.styleable#KeyboardView_backgroundDimAlpha
* @attr ref R.styleable#KeyboardView_keyBackground * @attr ref R.styleable#KeyboardView_keyBackground
* @attr ref R.styleable#KeyboardView_keyLetterRatio * @attr ref R.styleable#KeyboardView_moreKeysLayout
* @attr ref R.styleable#KeyboardView_keyLargeLetterRatio * @attr ref R.styleable#KeyboardView_keyPreviewLayout
* @attr ref R.styleable#KeyboardView_keyLabelRatio * @attr ref R.styleable#KeyboardView_keyPreviewBackground
* @attr ref R.styleable#KeyboardView_keyHintLetterRatio * @attr ref R.styleable#KeyboardView_keyPreviewLeftBackground
* @attr ref R.styleable#KeyboardView_keyShiftedLetterHintRatio * @attr ref R.styleable#KeyboardView_keyPreviewRightBackground
* @attr ref R.styleable#KeyboardView_keyHintLabelRatio * @attr ref R.styleable#KeyboardView_keyPreviewOffset
* @attr ref R.styleable#KeyboardView_keyPreviewHeight
* @attr ref R.styleable#KeyboardView_keyPreviewLingerTimeout
* @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding * @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding
* @attr ref R.styleable#KeyboardView_keyHintLetterPadding * @attr ref R.styleable#KeyboardView_keyHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding * @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyShiftedLetterHintPadding * @attr ref R.styleable#KeyboardView_keyShiftedLetterHintPadding
* @attr ref R.styleable#KeyboardView_keyTypeface * @attr ref R.styleable#KeyboardView_backgroundDimAlpha
* @attr ref R.styleable#KeyboardView_keyPreviewLayout * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextSize
* @attr ref R.styleable#KeyboardView_keyPreviewTextRatio * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextColor
* @attr ref R.styleable#KeyboardView_keyPreviewOffset * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextOffset
* @attr ref R.styleable#KeyboardView_keyPreviewHeight * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextShadingColor
* @attr ref R.styleable#KeyboardView_keyTextColor * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextShadingBorder
* @attr ref R.styleable#KeyboardView_keyTextColorDisabled * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextShadowColor
* @attr ref R.styleable#KeyboardView_keyHintLetterColor * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextShadowBorder
* @attr ref R.styleable#KeyboardView_keyHintLabelColor * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextConnectorColor
* @attr ref R.styleable#KeyboardView_keyShiftedLetterHintInactivatedColor * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextConnectorWidth
* @attr ref R.styleable#KeyboardView_keyShiftedLetterHintActivatedColor * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextLingerTimeout
* @attr ref R.styleable#KeyboardView_shadowColor * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutStartDelay
* @attr ref R.styleable#KeyboardView_shadowRadius * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutDuration
* @attr ref R.styleable#KeyboardView_gesturePreviewTrailUpdateInterval
* @attr ref R.styleable#KeyboardView_gesturePreviewTrailColor
* @attr ref R.styleable#KeyboardView_gesturePreviewTrailWidth
* @attr ref R.styleable#KeyboardView_verticalCorrection
* @attr ref R.styleable#Keyboard_Key_keyTypeface
* @attr ref R.styleable#Keyboard_Key_keyLetterSize
* @attr ref R.styleable#Keyboard_Key_keyLabelSize
* @attr ref R.styleable#Keyboard_Key_keyLargeLetterRatio
* @attr ref R.styleable#Keyboard_Key_keyLargeLabelRatio
* @attr ref R.styleable#Keyboard_Key_keyHintLetterRatio
* @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintRatio
* @attr ref R.styleable#Keyboard_Key_keyHintLabelRatio
* @attr ref R.styleable#Keyboard_Key_keyPreviewTextRatio
* @attr ref R.styleable#Keyboard_Key_keyTextColor
* @attr ref R.styleable#Keyboard_Key_keyTextColorDisabled
* @attr ref R.styleable#Keyboard_Key_keyTextShadowColor
* @attr ref R.styleable#Keyboard_Key_keyTextShadowRadius
* @attr ref R.styleable#Keyboard_Key_keyHintLetterColor
* @attr ref R.styleable#Keyboard_Key_keyHintLabelColor
* @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintInactivatedColor
* @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintActivatedColor
* @attr ref R.styleable#Keyboard_Key_keyPreviewTextColor
*/ */
public class KeyboardView extends View implements PointerTracker.DrawingProxy { public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private static final String TAG = KeyboardView.class.getSimpleName(); private static final String TAG = KeyboardView.class.getSimpleName();
@ -88,6 +111,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable }; private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable };
// XML attributes // XML attributes
private final int mKeyLabelHorizontalPadding;
private final float mKeyHintLetterPadding;
private final float mKeyPopupHintLetterPadding;
private final float mKeyShiftedLetterHintPadding;
protected final float mVerticalCorrection; protected final float mVerticalCorrection;
protected final int mMoreKeysLayout; protected final int mMoreKeysLayout;
private final int mBackgroundDimAlpha; private final int mBackgroundDimAlpha;
@ -194,6 +221,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mKeyDrawParams = new KeyDrawParams(keyboardViewAttr, keyAttr); mKeyDrawParams = new KeyDrawParams(keyboardViewAttr, keyAttr);
mKeyPreviewDrawParams = new KeyPreviewDrawParams(keyboardViewAttr, keyAttr); mKeyPreviewDrawParams = new KeyPreviewDrawParams(keyboardViewAttr, keyAttr);
mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout; mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout;
mKeyLabelHorizontalPadding = keyAttr.getDimensionPixelOffset(
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
mKeyHintLetterPadding = keyAttr.getDimension(
R.styleable.KeyboardView_keyHintLetterPadding, 0);
mKeyPopupHintLetterPadding = keyAttr.getDimension(
R.styleable.KeyboardView_keyPopupHintLetterPadding, 0);
mKeyShiftedLetterHintPadding = keyAttr.getDimension(
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
mKeyPreviewLayoutId = keyboardViewAttr.getResourceId( mKeyPreviewLayoutId = keyboardViewAttr.getResourceId(
R.styleable.KeyboardView_keyPreviewLayout, 0); R.styleable.KeyboardView_keyPreviewLayout, 0);
if (mKeyPreviewLayoutId == 0) { if (mKeyPreviewLayoutId == 0) {
@ -468,10 +503,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
// Horizontal label text alignment // Horizontal label text alignment
float labelWidth = 0; float labelWidth = 0;
if (key.isAlignLeft()) { if (key.isAlignLeft()) {
positionX = (int)params.mKeyLabelHorizontalPadding; positionX = mKeyLabelHorizontalPadding;
paint.setTextAlign(Align.LEFT); paint.setTextAlign(Align.LEFT);
} else if (key.isAlignRight()) { } else if (key.isAlignRight()) {
positionX = keyWidth - (int)params.mKeyLabelHorizontalPadding; positionX = keyWidth - mKeyLabelHorizontalPadding;
paint.setTextAlign(Align.RIGHT); paint.setTextAlign(Align.RIGHT);
} else if (key.isAlignLeftOfCenter()) { } else if (key.isAlignLeftOfCenter()) {
// TODO: Parameterise this? // TODO: Parameterise this?
@ -562,14 +597,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
paint.setTextAlign(Align.LEFT); paint.setTextAlign(Align.LEFT);
} else if (key.hasShiftedLetterHint()) { } else if (key.hasShiftedLetterHint()) {
// The hint label is placed at top-right corner of the key. Used mainly on tablet. // The hint label is placed at top-right corner of the key. Used mainly on tablet.
hintX = keyWidth - params.mKeyShiftedLetterHintPadding hintX = keyWidth - mKeyShiftedLetterHintPadding
- getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2; - getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2;
paint.getFontMetrics(mFontMetrics); paint.getFontMetrics(mFontMetrics);
hintY = -mFontMetrics.top; hintY = -mFontMetrics.top;
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
} else { // key.hasHintLetter() } else { // key.hasHintLetter()
// The hint letter is placed at top-right corner of the key. Used mainly on phone. // The hint letter is placed at top-right corner of the key. Used mainly on phone.
hintX = keyWidth - params.mKeyHintLetterPadding hintX = keyWidth - mKeyHintLetterPadding
- getCharWidth(KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR, paint) / 2; - getCharWidth(KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR, paint) / 2;
hintY = -paint.ascent(); hintY = -paint.ascent();
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
@ -590,10 +625,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final int iconX, alignX; final int iconX, alignX;
final int iconY = (keyHeight - iconHeight) / 2; final int iconY = (keyHeight - iconHeight) / 2;
if (key.isAlignLeft()) { if (key.isAlignLeft()) {
iconX = (int)params.mKeyLabelHorizontalPadding; iconX = mKeyLabelHorizontalPadding;
alignX = iconX; alignX = iconX;
} else if (key.isAlignRight()) { } else if (key.isAlignRight()) {
iconX = keyWidth - (int)params.mKeyLabelHorizontalPadding - iconWidth; iconX = keyWidth - mKeyLabelHorizontalPadding - iconWidth;
alignX = iconX + iconWidth; alignX = iconX + iconWidth;
} else { // Align center } else { // Align center
iconX = (keyWidth - iconWidth) / 2; iconX = (keyWidth - iconWidth) / 2;
@ -622,9 +657,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
paint.setTextSize(params.mKeyHintLetterSize); paint.setTextSize(params.mKeyHintLetterSize);
paint.setColor(params.mKeyHintLabelColor); paint.setColor(params.mKeyHintLabelColor);
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
final float hintX = keyWidth - params.mKeyHintLetterPadding final float hintX = keyWidth - mKeyHintLetterPadding
- getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2; - getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2;
final float hintY = keyHeight - params.mKeyPopupHintLetterPadding; final float hintY = keyHeight - mKeyPopupHintLetterPadding;
canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint); canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint);
if (LatinImeLogger.sVISUALDEBUG) { if (LatinImeLogger.sVISUALDEBUG) {

View File

@ -32,10 +32,6 @@ public class KeyDrawParams {
// XML attributes // XML attributes
public final int mKeyTextColor; public final int mKeyTextColor;
public final int mKeyTextInactivatedColor; public final int mKeyTextInactivatedColor;
public final float mKeyLabelHorizontalPadding;
public final float mKeyHintLetterPadding;
public final float mKeyPopupHintLetterPadding;
public final float mKeyShiftedLetterHintPadding;
public final int mKeyTextShadowColor; public final int mKeyTextShadowColor;
public final float mKeyTextShadowRadius; public final float mKeyTextShadowRadius;
public final Drawable mKeyBackground; public final Drawable mKeyBackground;
@ -87,14 +83,6 @@ public class KeyDrawParams {
R.styleable.Keyboard_Key_keyShiftedLetterHintRatio); R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
mKeyHintLabelRatio = ResourceUtils.getFraction(keyAttr, mKeyHintLabelRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyHintLabelRatio); R.styleable.Keyboard_Key_keyHintLabelRatio);
mKeyLabelHorizontalPadding = keyAttr.getDimension(
R.styleable.Keyboard_Key_keyLabelHorizontalPadding, 0);
mKeyHintLetterPadding = keyAttr.getDimension(
R.styleable.Keyboard_Key_keyHintLetterPadding, 0);
mKeyPopupHintLetterPadding = keyAttr.getDimension(
R.styleable.Keyboard_Key_keyPopupHintLetterPadding, 0);
mKeyShiftedLetterHintPadding = keyAttr.getDimension(
R.styleable.Keyboard_Key_keyShiftedLetterHintPadding, 0);
mKeyTextColor = keyAttr.getColor( mKeyTextColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyTextColor, Color.WHITE); R.styleable.Keyboard_Key_keyTextColor, Color.WHITE);
mKeyTextInactivatedColor = keyAttr.getColor( mKeyTextInactivatedColor = keyAttr.getColor(