am aa546072: Merge "Support per-Key and per-Keyboard key visual attributes" into jb-mr1-dev

* commit 'aa54607246fa9494537ece89b3d2a180c7778383':
  Support per-Key and per-Keyboard key visual attributes
main
Tadashi G. Takaoka 2012-08-31 05:00:31 -07:00 committed by Android Git Automerger
commit c92ac43850
11 changed files with 482 additions and 375 deletions

View File

@ -49,6 +49,8 @@
<attr name="keyPopupHintLetterPadding" format="dimension" /> <attr name="keyPopupHintLetterPadding" format="dimension" />
<!-- Right padding of shifted letter hint to the edge of the key.--> <!-- Right padding of shifted letter hint to the edge of the key.-->
<attr name="keyShiftedLetterHintPadding" format="dimension" /> <attr name="keyShiftedLetterHintPadding" format="dimension" />
<!-- Blur radius of key text shadow. -->
<attr name="keyTextShadowRadius" format="float" />
<!-- Layout resource for key press feedback.--> <!-- Layout resource for key press feedback.-->
<attr name="keyPreviewLayout" format="reference" /> <attr name="keyPreviewLayout" format="reference" />
@ -320,7 +322,6 @@
<!-- 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" />
<attr name="keyTextShadowRadius" format="float" />
<!-- Color to use for the label in a key when in inactivated state. --> <!-- Color to use for the label in a key when in inactivated state. -->
<attr name="keyTextInactivatedColor" format="color" /> <attr name="keyTextInactivatedColor" format="color" />
<!-- Key hint letter (= one character hint label) color --> <!-- Key hint letter (= one character hint label) color -->

View File

@ -31,8 +31,10 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.Xml; import android.util.Xml;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeySpecParser; import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.keyboard.internal.KeyStyle; import com.android.inputmethod.keyboard.internal.KeyStyle;
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeyboardParams; import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.keyboard.internal.KeyboardRow; import com.android.inputmethod.keyboard.internal.KeyboardRow;
@ -132,6 +134,8 @@ public class Key {
private static final int ACTION_FLAGS_ALT_CODE_WHILE_TYPING = 0x04; private static final int ACTION_FLAGS_ALT_CODE_WHILE_TYPING = 0x04;
private static final int ACTION_FLAGS_ENABLE_LONG_PRESS = 0x08; private static final int ACTION_FLAGS_ENABLE_LONG_PRESS = 0x08;
public final KeyVisualAttributes mKeyVisualAttributes;
private final OptionalAttributes mOptionalAttributes; private final OptionalAttributes mOptionalAttributes;
private static class OptionalAttributes { private static class OptionalAttributes {
@ -202,6 +206,7 @@ public class Key {
mX = x + params.mHorizontalGap / 2; mX = x + params.mHorizontalGap / 2;
mY = y; mY = y;
mHitBox.set(x, y, x + width + 1, y + height); mHitBox.set(x, y, x + width + 1, y + height);
mKeyVisualAttributes = null;
mHashCode = computeHashCode(this); mHashCode = computeHashCode(this);
} }
@ -357,11 +362,9 @@ public class Key {
disabledIconId, previewIconId, disabledIconId, previewIconId,
visualInsetsLeft, visualInsetsRight); visualInsetsLeft, visualInsetsRight);
} }
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
mHashCode = computeHashCode(this);
keyAttr.recycle(); keyAttr.recycle();
mHashCode = computeHashCode(this);
if (hasShiftedLetterHint() && TextUtils.isEmpty(mHintLabel)) { if (hasShiftedLetterHint() && TextUtils.isEmpty(mHintLabel)) {
Log.w(TAG, "hasShiftedLetterHint specified without keyHintLabel: " + this); Log.w(TAG, "hasShiftedLetterHint specified without keyHintLabel: " + this);
} }
@ -478,133 +481,161 @@ public class Key {
return this instanceof Spacer; return this instanceof Spacer;
} }
public boolean isShift() { public final boolean isShift() {
return mCode == CODE_SHIFT; return mCode == CODE_SHIFT;
} }
public boolean isModifier() { public final boolean isModifier() {
return mCode == CODE_SHIFT || mCode == CODE_SWITCH_ALPHA_SYMBOL; return mCode == CODE_SHIFT || mCode == CODE_SWITCH_ALPHA_SYMBOL;
} }
public boolean isRepeatable() { public final boolean isRepeatable() {
return (mActionFlags & ACTION_FLAGS_IS_REPEATABLE) != 0; return (mActionFlags & ACTION_FLAGS_IS_REPEATABLE) != 0;
} }
public boolean noKeyPreview() { public final boolean noKeyPreview() {
return (mActionFlags & ACTION_FLAGS_NO_KEY_PREVIEW) != 0; return (mActionFlags & ACTION_FLAGS_NO_KEY_PREVIEW) != 0;
} }
public boolean altCodeWhileTyping() { public final boolean altCodeWhileTyping() {
return (mActionFlags & ACTION_FLAGS_ALT_CODE_WHILE_TYPING) != 0; return (mActionFlags & ACTION_FLAGS_ALT_CODE_WHILE_TYPING) != 0;
} }
public boolean isLongPressEnabled() { public final boolean isLongPressEnabled() {
// We need not start long press timer on the key which has activated shifted letter. // We need not start long press timer on the key which has activated shifted letter.
return (mActionFlags & ACTION_FLAGS_ENABLE_LONG_PRESS) != 0 return (mActionFlags & ACTION_FLAGS_ENABLE_LONG_PRESS) != 0
&& (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) == 0; && (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) == 0;
} }
public Typeface selectTypeface(final Typeface defaultTypeface) { public final Typeface selectTypeface(final KeyDrawParams params) {
// TODO: Handle "bold" here too? // TODO: Handle "bold" here too?
if ((mLabelFlags & LABEL_FLAGS_FONT_NORMAL) != 0) { if ((mLabelFlags & LABEL_FLAGS_FONT_NORMAL) != 0) {
return Typeface.DEFAULT; return Typeface.DEFAULT;
} else if ((mLabelFlags & LABEL_FLAGS_FONT_MONO_SPACE) != 0) { } else if ((mLabelFlags & LABEL_FLAGS_FONT_MONO_SPACE) != 0) {
return Typeface.MONOSPACE; return Typeface.MONOSPACE;
} else { } else {
return defaultTypeface; return params.mTypeface;
} }
} }
public int selectTextSize(final int letterSize, final int largeLetterSize, final int labelSize, public final int selectTextSize(final KeyDrawParams params) {
final int largeLabelSize, final int hintLabelSize) {
switch (mLabelFlags & LABEL_FLAGS_FOLLOW_KEY_TEXT_RATIO_MASK) { switch (mLabelFlags & LABEL_FLAGS_FOLLOW_KEY_TEXT_RATIO_MASK) {
case LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO: case LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO:
return letterSize; return params.mLetterSize;
case LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO: case LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO:
return largeLetterSize; return params.mLargeLetterSize;
case LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO: case LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO:
return labelSize; return params.mLabelSize;
case LABEL_FLAGS_FOLLOW_KEY_LARGE_LABEL_RATIO: case LABEL_FLAGS_FOLLOW_KEY_LARGE_LABEL_RATIO:
return largeLabelSize; return params.mLargeLabelSize;
case LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO: case LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO:
return hintLabelSize; return params.mHintLabelSize;
default: // No follow key ratio flag specified. default: // No follow key ratio flag specified.
return StringUtils.codePointCount(mLabel) == 1 ? letterSize : labelSize; return StringUtils.codePointCount(mLabel) == 1 ? params.mLetterSize : params.mLabelSize;
} }
} }
public boolean isAlignLeft() { public final int selectTextColor(final KeyDrawParams params) {
return isShiftedLetterActivated() ? params.mTextInactivatedColor : params.mTextColor;
}
public final int selectHintTextSize(final KeyDrawParams params) {
if (hasHintLabel()) {
return params.mHintLabelSize;
} else if (hasShiftedLetterHint()) {
return params.mShiftedLetterHintSize;
} else {
return params.mHintLetterSize;
}
}
public final int selectHintTextColor(final KeyDrawParams params) {
if (hasHintLabel()) {
return params.mHintLabelColor;
} else if (hasShiftedLetterHint()) {
return isShiftedLetterActivated() ? params.mShiftedLetterHintActivatedColor
: params.mShiftedLetterHintInactivatedColor;
} else {
return params.mHintLetterColor;
}
}
public final int selectMoreKeyTextSize(final KeyDrawParams params) {
return hasLabelsInMoreKeys() ? params.mLabelSize : params.mLetterSize;
}
public final boolean isAlignLeft() {
return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT) != 0; return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT) != 0;
} }
public boolean isAlignRight() { public final boolean isAlignRight() {
return (mLabelFlags & LABEL_FLAGS_ALIGN_RIGHT) != 0; return (mLabelFlags & LABEL_FLAGS_ALIGN_RIGHT) != 0;
} }
public boolean isAlignLeftOfCenter() { public final boolean isAlignLeftOfCenter() {
return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT_OF_CENTER) != 0; return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT_OF_CENTER) != 0;
} }
public boolean hasPopupHint() { public final boolean hasPopupHint() {
return (mLabelFlags & LABEL_FLAGS_HAS_POPUP_HINT) != 0; return (mLabelFlags & LABEL_FLAGS_HAS_POPUP_HINT) != 0;
} }
public boolean hasShiftedLetterHint() { public final boolean hasShiftedLetterHint() {
return (mLabelFlags & LABEL_FLAGS_HAS_SHIFTED_LETTER_HINT) != 0; return (mLabelFlags & LABEL_FLAGS_HAS_SHIFTED_LETTER_HINT) != 0;
} }
public boolean hasHintLabel() { public final boolean hasHintLabel() {
return (mLabelFlags & LABEL_FLAGS_HAS_HINT_LABEL) != 0; return (mLabelFlags & LABEL_FLAGS_HAS_HINT_LABEL) != 0;
} }
public boolean hasLabelWithIconLeft() { public final boolean hasLabelWithIconLeft() {
return (mLabelFlags & LABEL_FLAGS_WITH_ICON_LEFT) != 0; return (mLabelFlags & LABEL_FLAGS_WITH_ICON_LEFT) != 0;
} }
public boolean hasLabelWithIconRight() { public final boolean hasLabelWithIconRight() {
return (mLabelFlags & LABEL_FLAGS_WITH_ICON_RIGHT) != 0; return (mLabelFlags & LABEL_FLAGS_WITH_ICON_RIGHT) != 0;
} }
public boolean needsXScale() { public final boolean needsXScale() {
return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0; return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0;
} }
public boolean isShiftedLetterActivated() { public final boolean isShiftedLetterActivated() {
return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0; return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0;
} }
public int getMoreKeysColumn() { public final int getMoreKeysColumn() {
return mMoreKeysColumnAndFlags & MORE_KEYS_COLUMN_MASK; return mMoreKeysColumnAndFlags & MORE_KEYS_COLUMN_MASK;
} }
public boolean isFixedColumnOrderMoreKeys() { public final boolean isFixedColumnOrderMoreKeys() {
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER) != 0; return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER) != 0;
} }
public boolean hasLabelsInMoreKeys() { public final boolean hasLabelsInMoreKeys() {
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_HAS_LABELS) != 0; return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_HAS_LABELS) != 0;
} }
public int getMoreKeyLabelFlags() { public final int getMoreKeyLabelFlags() {
return hasLabelsInMoreKeys() return hasLabelsInMoreKeys()
? LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO ? LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO
: LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO; : LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO;
} }
public boolean needsDividersInMoreKeys() { public final boolean needsDividersInMoreKeys() {
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_NEEDS_DIVIDERS) != 0; return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_NEEDS_DIVIDERS) != 0;
} }
public boolean hasEmbeddedMoreKey() { public final boolean hasEmbeddedMoreKey() {
return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY) != 0; return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY) != 0;
} }
public String getOutputText() { public final String getOutputText() {
final OptionalAttributes attrs = mOptionalAttributes; final OptionalAttributes attrs = mOptionalAttributes;
return (attrs != null) ? attrs.mOutputText : null; return (attrs != null) ? attrs.mOutputText : null;
} }
public int getAltCode() { public final int getAltCode() {
final OptionalAttributes attrs = mOptionalAttributes; final OptionalAttributes attrs = mOptionalAttributes;
return (attrs != null) ? attrs.mAltCode : CODE_UNSPECIFIED; return (attrs != null) ? attrs.mAltCode : CODE_UNSPECIFIED;
} }
@ -627,12 +658,12 @@ public class Key {
? iconSet.getIconDrawable(previewIconId) : iconSet.getIconDrawable(mIconId); ? iconSet.getIconDrawable(previewIconId) : iconSet.getIconDrawable(mIconId);
} }
public int getDrawX() { public final int getDrawX() {
final OptionalAttributes attrs = mOptionalAttributes; final OptionalAttributes attrs = mOptionalAttributes;
return (attrs == null) ? mX : mX + attrs.mVisualInsetsLeft; return (attrs == null) ? mX : mX + attrs.mVisualInsetsLeft;
} }
public int getDrawWidth() { public final int getDrawWidth() {
final OptionalAttributes attrs = mOptionalAttributes; final OptionalAttributes attrs = mOptionalAttributes;
return (attrs == null) ? mWidth return (attrs == null) ? mWidth
: mWidth - attrs.mVisualInsetsLeft - attrs.mVisualInsetsRight; : mWidth - attrs.mVisualInsetsLeft - attrs.mVisualInsetsRight;
@ -656,7 +687,7 @@ public class Key {
mPressed = false; mPressed = false;
} }
public boolean isEnabled() { public final boolean isEnabled() {
return mEnabled; return mEnabled;
} }
@ -748,7 +779,7 @@ public class Key {
* @return the drawable state of the key. * @return the drawable state of the key.
* @see android.graphics.drawable.StateListDrawable#setState(int[]) * @see android.graphics.drawable.StateListDrawable#setState(int[])
*/ */
public int[] getCurrentDrawableState() { public final int[] getCurrentDrawableState() {
switch (mBackgroundType) { switch (mBackgroundType) {
case BACKGROUND_TYPE_FUNCTIONAL: case BACKGROUND_TYPE_FUNCTIONAL:
return mPressed ? KEY_STATE_FUNCTIONAL_PRESSED : KEY_STATE_FUNCTIONAL_NORMAL; return mPressed ? KEY_STATE_FUNCTIONAL_PRESSED : KEY_STATE_FUNCTIONAL_NORMAL;

View File

@ -16,10 +16,10 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import android.graphics.Typeface;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeyboardParams; import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.CollectionUtils;
@ -97,11 +97,7 @@ public class Keyboard {
public final int mVerticalGap; public final int mVerticalGap;
/** Per keyboard key visual parameters */ /** Per keyboard key visual parameters */
public final Typeface mKeyTypeface; public final KeyVisualAttributes mKeyVisualAttributes;
public final float mKeyLetterRatio;
public final int mKeyLetterSize;
public final float mKeyHintLetterRatio;
public final float mKeyShiftedLetterHintRatio;
public final int mMostCommonKeyHeight; public final int mMostCommonKeyHeight;
public final int mMostCommonKeyWidth; public final int mMostCommonKeyWidth;
@ -132,13 +128,7 @@ public class Keyboard {
mMostCommonKeyWidth = params.mMostCommonKeyWidth; mMostCommonKeyWidth = params.mMostCommonKeyWidth;
mMoreKeysTemplate = params.mMoreKeysTemplate; mMoreKeysTemplate = params.mMoreKeysTemplate;
mMaxMoreKeysKeyboardColumn = params.mMaxMoreKeysKeyboardColumn; mMaxMoreKeysKeyboardColumn = params.mMaxMoreKeysKeyboardColumn;
mKeyVisualAttributes = params.mKeyVisualAttributes;
mKeyTypeface = params.mKeyTypeface;
mKeyLetterRatio = params.mKeyLetterRatio;
mKeyLetterSize = params.mKeyLetterSize;
mKeyHintLetterRatio = params.mKeyHintLetterRatio;
mKeyShiftedLetterHintRatio = params.mKeyShiftedLetterHintRatio;
mTopPadding = params.mTopPadding; mTopPadding = params.mTopPadding;
mVerticalGap = params.mVerticalGap; mVerticalGap = params.mVerticalGap;

View File

@ -40,6 +40,7 @@ import android.widget.TextView;
import com.android.inputmethod.keyboard.internal.KeyDrawParams; import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams; import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
import com.android.inputmethod.keyboard.internal.PreviewPlacerView; import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
@ -68,6 +69,7 @@ import java.util.HashSet;
* @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_keyTextShadowRadius
* @attr ref R.styleable#KeyboardView_backgroundDimAlpha * @attr ref R.styleable#KeyboardView_backgroundDimAlpha
* @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextSize * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextSize
* @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextColor * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextColor
@ -97,7 +99,6 @@ import java.util.HashSet;
* @attr ref R.styleable#Keyboard_Key_keyTextColor * @attr ref R.styleable#Keyboard_Key_keyTextColor
* @attr ref R.styleable#Keyboard_Key_keyTextColorDisabled * @attr ref R.styleable#Keyboard_Key_keyTextColorDisabled
* @attr ref R.styleable#Keyboard_Key_keyTextShadowColor * @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_keyHintLetterColor
* @attr ref R.styleable#Keyboard_Key_keyHintLabelColor * @attr ref R.styleable#Keyboard_Key_keyHintLabelColor
* @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintInactivatedColor * @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintInactivatedColor
@ -111,12 +112,16 @@ 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 KeyVisualAttributes mKeyVisualAttributes;
private final int mKeyLabelHorizontalPadding; private final int mKeyLabelHorizontalPadding;
private final float mKeyHintLetterPadding; private final float mKeyHintLetterPadding;
private final float mKeyPopupHintLetterPadding; private final float mKeyPopupHintLetterPadding;
private final float mKeyShiftedLetterHintPadding; private final float mKeyShiftedLetterHintPadding;
private final float mKeyTextShadowRadius;
protected final float mVerticalCorrection; protected final float mVerticalCorrection;
protected final int mMoreKeysLayout; protected final int mMoreKeysLayout;
protected final Drawable mKeyBackground;
protected final Rect mKeyBackgroundPadding = new Rect();
private final int mBackgroundDimAlpha; private final int mBackgroundDimAlpha;
// HORIZONTAL ELLIPSIS "...", character for popup hint. // HORIZONTAL ELLIPSIS "...", character for popup hint.
@ -132,12 +137,19 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
// Main keyboard // Main keyboard
private Keyboard mKeyboard; private Keyboard mKeyboard;
protected final KeyDrawParams mKeyDrawParams; protected final KeyDrawParams mKeyDrawParams = new KeyDrawParams();
// Key preview // Key preview
private static final int PREVIEW_ALPHA = 240;
private final int mKeyPreviewLayoutId; private final int mKeyPreviewLayoutId;
private final Drawable mPreviewBackground;
private final Drawable mPreviewLeftBackground;
private final Drawable mPreviewRightBackground;
private final int mPreviewOffset;
private final int mPreviewHeight;
private final int mPreviewLingerTimeout;
private final SparseArray<TextView> mKeyPreviewTexts = CollectionUtils.newSparseArray(); private final SparseArray<TextView> mKeyPreviewTexts = CollectionUtils.newSparseArray();
protected final KeyPreviewDrawParams mKeyPreviewDrawParams; protected final KeyPreviewDrawParams mKeyPreviewDrawParams = new KeyPreviewDrawParams();
private boolean mShowKeyPreviewPopup = true; private boolean mShowKeyPreviewPopup = true;
private int mDelayAfterPreview; private int mDelayAfterPreview;
private final PreviewPlacerView mPreviewPlacerView; private final PreviewPlacerView mPreviewPlacerView;
@ -171,12 +183,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
public static class DrawingHandler extends StaticInnerHandlerWrapper<KeyboardView> { public static class DrawingHandler extends StaticInnerHandlerWrapper<KeyboardView> {
private static final int MSG_DISMISS_KEY_PREVIEW = 0; private static final int MSG_DISMISS_KEY_PREVIEW = 0;
public DrawingHandler(KeyboardView outerInstance) { public DrawingHandler(final KeyboardView outerInstance) {
super(outerInstance); super(outerInstance);
} }
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(final Message msg) {
final KeyboardView keyboardView = getOuterInstance(); final KeyboardView keyboardView = getOuterInstance();
if (keyboardView == null) return; if (keyboardView == null) return;
final PointerTracker tracker = (PointerTracker) msg.obj; final PointerTracker tracker = (PointerTracker) msg.obj;
@ -190,11 +202,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
} }
public void dismissKeyPreview(long delay, PointerTracker tracker) { public void dismissKeyPreview(final long delay, final PointerTracker tracker) {
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay); sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay);
} }
public void cancelDismissKeyPreview(PointerTracker tracker) { public void cancelDismissKeyPreview(final PointerTracker tracker) {
removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker); removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker);
} }
@ -207,20 +219,33 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
} }
public KeyboardView(Context context, AttributeSet attrs) { public KeyboardView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.keyboardViewStyle); this(context, attrs, R.attr.keyboardViewStyle);
} }
public KeyboardView(Context context, AttributeSet attrs, int defStyle) { public KeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs, final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardView, defStyle, R.style.KeyboardView); R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
final TypedArray keyAttr = context.obtainStyledAttributes(attrs, mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground);
R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView); mKeyBackground.getPadding(mKeyBackgroundPadding);
mKeyDrawParams = new KeyDrawParams(keyboardViewAttr, keyAttr); mPreviewBackground = keyboardViewAttr.getDrawable(
mKeyPreviewDrawParams = new KeyPreviewDrawParams(keyboardViewAttr, keyAttr); R.styleable.KeyboardView_keyPreviewBackground);
mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout; mPreviewLeftBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_keyPreviewLeftBackground);
mPreviewRightBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_keyPreviewRightBackground);
setAlpha(mPreviewBackground, PREVIEW_ALPHA);
setAlpha(mPreviewLeftBackground, PREVIEW_ALPHA);
setAlpha(mPreviewRightBackground, PREVIEW_ALPHA);
mPreviewOffset = keyboardViewAttr.getDimensionPixelOffset(
R.styleable.KeyboardView_keyPreviewOffset, 0);
mPreviewHeight = keyboardViewAttr.getDimensionPixelSize(
R.styleable.KeyboardView_keyPreviewHeight, 80);
mPreviewLingerTimeout = keyboardViewAttr.getInt(
R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
mDelayAfterPreview = mPreviewLingerTimeout;
mKeyLabelHorizontalPadding = keyboardViewAttr.getDimensionPixelOffset( mKeyLabelHorizontalPadding = keyboardViewAttr.getDimensionPixelOffset(
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0); R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
mKeyHintLetterPadding = keyboardViewAttr.getDimension( mKeyHintLetterPadding = keyboardViewAttr.getDimension(
@ -229,24 +254,41 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
R.styleable.KeyboardView_keyPopupHintLetterPadding, 0); R.styleable.KeyboardView_keyPopupHintLetterPadding, 0);
mKeyShiftedLetterHintPadding = keyboardViewAttr.getDimension( mKeyShiftedLetterHintPadding = keyboardViewAttr.getDimension(
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0); R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
mKeyTextShadowRadius = keyboardViewAttr.getFloat(
R.styleable.KeyboardView_keyTextShadowRadius, 0.0f);
mKeyPreviewLayoutId = keyboardViewAttr.getResourceId( mKeyPreviewLayoutId = keyboardViewAttr.getResourceId(
R.styleable.KeyboardView_keyPreviewLayout, 0); R.styleable.KeyboardView_keyPreviewLayout, 0);
if (mKeyPreviewLayoutId == 0) { if (mKeyPreviewLayoutId == 0) {
mShowKeyPreviewPopup = false; mShowKeyPreviewPopup = false;
} }
mVerticalCorrection = keyboardViewAttr.getDimensionPixelOffset( mVerticalCorrection = keyboardViewAttr.getDimension(
R.styleable.KeyboardView_verticalCorrection, 0); R.styleable.KeyboardView_verticalCorrection, 0);
mMoreKeysLayout = keyboardViewAttr.getResourceId( mMoreKeysLayout = keyboardViewAttr.getResourceId(
R.styleable.KeyboardView_moreKeysLayout, 0); R.styleable.KeyboardView_moreKeysLayout, 0);
mBackgroundDimAlpha = keyboardViewAttr.getInt( mBackgroundDimAlpha = keyboardViewAttr.getInt(
R.styleable.KeyboardView_backgroundDimAlpha, 0); R.styleable.KeyboardView_backgroundDimAlpha, 0);
keyboardViewAttr.recycle(); keyboardViewAttr.recycle();
final TypedArray keyAttr = context.obtainStyledAttributes(attrs,
R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView);
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
keyAttr.recycle(); keyAttr.recycle();
mPreviewPlacerView = new PreviewPlacerView(context, attrs); mPreviewPlacerView = new PreviewPlacerView(context, attrs);
mPaint.setAntiAlias(true); mPaint.setAntiAlias(true);
} }
private static void setAlpha(final Drawable drawable, final int alpha) {
if (drawable == null) return;
drawable.setAlpha(alpha);
}
private static void blendAlpha(final Paint paint, final int alpha) {
final int color = paint.getColor();
paint.setARGB((paint.getAlpha() * alpha) / Constants.Color.ALPHA_OPAQUE,
Color.red(color), Color.green(color), Color.blue(color));
}
/** /**
* Attaches a keyboard to this view. The keyboard can be switched at any time and the * Attaches a keyboard to this view. The keyboard can be switched at any time and the
* view will re-layout itself to accommodate the keyboard. * view will re-layout itself to accommodate the keyboard.
@ -254,13 +296,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
* @see #getKeyboard() * @see #getKeyboard()
* @param keyboard the keyboard to display in this view * @param keyboard the keyboard to display in this view
*/ */
public void setKeyboard(Keyboard keyboard) { public void setKeyboard(final Keyboard keyboard) {
mKeyboard = keyboard; mKeyboard = keyboard;
LatinImeLogger.onSetKeyboard(keyboard); LatinImeLogger.onSetKeyboard(keyboard);
requestLayout(); requestLayout();
invalidateAllKeys(); invalidateAllKeys();
mKeyDrawParams.updateParams(keyboard); final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
mKeyPreviewDrawParams.updateParams(keyboard, mKeyDrawParams); mKeyDrawParams.updateParams(keyHeight, mKeyVisualAttributes);
mKeyDrawParams.updateParams(keyHeight, keyboard.mKeyVisualAttributes);
} }
/** /**
@ -279,7 +322,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
* @param delay the delay after which the preview is dismissed * @param delay the delay after which the preview is dismissed
* @see #isKeyPreviewPopupEnabled() * @see #isKeyPreviewPopupEnabled()
*/ */
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
mShowKeyPreviewPopup = previewEnabled; mShowKeyPreviewPopup = previewEnabled;
mDelayAfterPreview = delay; mDelayAfterPreview = delay;
} }
@ -293,14 +336,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
return mShowKeyPreviewPopup; return mShowKeyPreviewPopup;
} }
public void setGesturePreviewMode(boolean drawsGesturePreviewTrail, public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
boolean drawsGestureFloatingPreviewText) { final boolean drawsGestureFloatingPreviewText) {
mPreviewPlacerView.setGesturePreviewMode( mPreviewPlacerView.setGesturePreviewMode(
drawsGesturePreviewTrail, drawsGestureFloatingPreviewText); drawsGesturePreviewTrail, drawsGestureFloatingPreviewText);
} }
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
if (mKeyboard != null) { if (mKeyboard != null) {
// The main keyboard expands to the display width. // The main keyboard expands to the display width.
final int height = mKeyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom(); final int height = mKeyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom();
@ -311,7 +354,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(final Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
if (canvas.isHardwareAccelerated()) { if (canvas.isHardwareAccelerated()) {
onDrawKeyboard(canvas); onDrawKeyboard(canvas);
@ -366,7 +409,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final int width = getWidth(); final int width = getWidth();
final int height = getHeight(); final int height = getHeight();
final Paint paint = mPaint; final Paint paint = mPaint;
final KeyDrawParams params = mKeyDrawParams;
// Calculate clip region and set. // Calculate clip region and set.
final boolean drawAllKeys = mInvalidateAllKeys || mInvalidatedKeys.isEmpty(); final boolean drawAllKeys = mInvalidateAllKeys || mInvalidatedKeys.isEmpty();
@ -399,13 +441,13 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
if (drawAllKeys || isHardwareAccelerated) { if (drawAllKeys || isHardwareAccelerated) {
// Draw all keys. // Draw all keys.
for (final Key key : mKeyboard.mKeys) { for (final Key key : mKeyboard.mKeys) {
onDrawKey(key, canvas, paint, params); onDrawKey(key, canvas, paint);
} }
} else { } else {
// Draw invalidated keys. // Draw invalidated keys.
for (final Key key : mInvalidatedKeys) { for (final Key key : mInvalidatedKeys) {
if (mKeyboard.hasKey(key)) { if (mKeyboard.hasKey(key)) {
onDrawKey(key, canvas, paint, params); onDrawKey(key, canvas, paint);
} }
} }
} }
@ -429,7 +471,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mInvalidateAllKeys = false; mInvalidateAllKeys = false;
} }
public void dimEntireKeyboard(boolean dimmed) { public void dimEntireKeyboard(final boolean dimmed) {
final boolean needsRedrawing = mNeedsToDimEntireKeyboard != dimmed; final boolean needsRedrawing = mNeedsToDimEntireKeyboard != dimmed;
mNeedsToDimEntireKeyboard = dimmed; mNeedsToDimEntireKeyboard = dimmed;
if (needsRedrawing) { if (needsRedrawing) {
@ -437,14 +479,18 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
} }
private void onDrawKey(Key key, Canvas canvas, Paint paint, KeyDrawParams params) { private void onDrawKey(final Key key, final Canvas canvas, final Paint paint) {
final int keyDrawX = key.getDrawX() + getPaddingLeft(); final int keyDrawX = key.getDrawX() + getPaddingLeft();
final int keyDrawY = key.mY + getPaddingTop(); final int keyDrawY = key.mY + getPaddingTop();
canvas.translate(keyDrawX, keyDrawY); canvas.translate(keyDrawX, keyDrawY);
final int keyHeight = mKeyboard.mMostCommonKeyHeight - mKeyboard.mVerticalGap;
final KeyVisualAttributes attr = key.mKeyVisualAttributes;
final KeyDrawParams params = mKeyDrawParams.mayCloneAndUpdateParams(keyHeight, attr);
params.mAnimAlpha = Constants.Color.ALPHA_OPAQUE; params.mAnimAlpha = Constants.Color.ALPHA_OPAQUE;
if (!key.isSpacer()) { if (!key.isSpacer()) {
onDrawKeyBackground(key, canvas, params); onDrawKeyBackground(key, canvas);
} }
onDrawKeyTopVisuals(key, canvas, paint, params); onDrawKeyTopVisuals(key, canvas, paint, params);
@ -452,13 +498,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
// Draw key background. // Draw key background.
protected void onDrawKeyBackground(Key key, Canvas canvas, KeyDrawParams params) { protected void onDrawKeyBackground(Key key, Canvas canvas) {
final int bgWidth = key.getDrawWidth() + params.mPadding.left + params.mPadding.right; final Rect padding = mKeyBackgroundPadding;
final int bgHeight = key.mHeight + params.mPadding.top + params.mPadding.bottom; final int bgWidth = key.getDrawWidth() + padding.left + padding.right;
final int bgX = -params.mPadding.left; final int bgHeight = key.mHeight + padding.top + padding.bottom;
final int bgY = -params.mPadding.top; final int bgX = -padding.left;
final int bgY = -padding.top;
final int[] drawableState = key.getCurrentDrawableState(); final int[] drawableState = key.getCurrentDrawableState();
final Drawable background = params.mKeyBackground; final Drawable background = mKeyBackground;
background.setState(drawableState); background.setState(drawableState);
final Rect bounds = background.getBounds(); final Rect bounds = background.getBounds();
if (bgWidth != bounds.right || bgHeight != bounds.bottom) { if (bgWidth != bounds.right || bgHeight != bounds.bottom) {
@ -488,12 +535,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
float positionX = centerX; float positionX = centerX;
if (key.mLabel != null) { if (key.mLabel != null) {
final String label = key.mLabel; final String label = key.mLabel;
// For characters, use large font. For labels like "Done", use smaller font. paint.setTypeface(key.selectTypeface(params));
paint.setTypeface(key.selectTypeface(params.mKeyTypeface)); paint.setTextSize(key.selectTextSize(params));
final int labelSize = key.selectTextSize(params.mKeyLetterSize,
params.mKeyLargeLetterSize, params.mKeyLabelSize, params.mKeyLargeLabelSize,
params.mKeyHintLabelSize);
paint.setTextSize(labelSize);
final float labelCharHeight = getCharHeight(KEY_LABEL_REFERENCE_CHAR, paint); final float labelCharHeight = getCharHeight(KEY_LABEL_REFERENCE_CHAR, paint);
final float labelCharWidth = getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint); final float labelCharWidth = getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint);
@ -531,16 +574,15 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint))); Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint)));
} }
paint.setColor(key.isShiftedLetterActivated() paint.setColor(key.selectTextColor(params));
? params.mKeyTextInactivatedColor : params.mKeyTextColor);
if (key.isEnabled()) { if (key.isEnabled()) {
// Set a drop shadow for the text // Set a drop shadow for the text
paint.setShadowLayer(params.mKeyTextShadowRadius, 0, 0, params.mKeyTextShadowColor); paint.setShadowLayer(mKeyTextShadowRadius, 0, 0, params.mTextShadowColor);
} else { } else {
// Make label invisible // Make label invisible
paint.setColor(Color.TRANSPARENT); paint.setColor(Color.TRANSPARENT);
} }
params.blendAlpha(paint); blendAlpha(paint, params.mAnimAlpha);
canvas.drawText(label, 0, label.length(), positionX, baseline, paint); canvas.drawText(label, 0, label.length(), positionX, baseline, paint);
// Turn off drop shadow and reset x-scale. // Turn off drop shadow and reset x-scale.
paint.setShadowLayer(0, 0, 0, 0); paint.setShadowLayer(0, 0, 0, 0);
@ -568,25 +610,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
// Draw hint label. // Draw hint label.
if (key.mHintLabel != null) { if (key.mHintLabel != null) {
final String hint = key.mHintLabel; final String hintLabel = key.mHintLabel;
final int hintColor; paint.setTextSize(key.selectHintTextSize(params));
final int hintSize; paint.setColor(key.selectHintTextColor(params));
if (key.hasHintLabel()) { blendAlpha(paint, params.mAnimAlpha);
hintColor = params.mKeyHintLabelColor;
hintSize = params.mKeyHintLabelSize;
paint.setTypeface(Typeface.DEFAULT);
} else if (key.hasShiftedLetterHint()) {
hintColor = key.isShiftedLetterActivated()
? params.mKeyShiftedLetterHintActivatedColor
: params.mKeyShiftedLetterHintInactivatedColor;
hintSize = params.mKeyShiftedLetterHintSize;
} else { // key.hasHintLetter()
hintColor = params.mKeyHintLetterColor;
hintSize = params.mKeyHintLetterSize;
}
paint.setColor(hintColor);
params.blendAlpha(paint);
paint.setTextSize(hintSize);
final float hintX, hintY; final float hintX, hintY;
if (key.hasHintLabel()) { if (key.hasHintLabel()) {
// The hint label is placed just right of the key label. Used mainly on // The hint label is placed just right of the key label. Used mainly on
@ -609,7 +636,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
hintY = -paint.ascent(); hintY = -paint.ascent();
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
} }
canvas.drawText(hint, 0, hint.length(), hintX, hintY, paint); canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintY, paint);
if (LatinImeLogger.sVISUALDEBUG) { if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint(); final Paint line = new Paint();
@ -653,9 +680,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final int keyWidth = key.getDrawWidth(); final int keyWidth = key.getDrawWidth();
final int keyHeight = key.mHeight; final int keyHeight = key.mHeight;
paint.setTypeface(params.mKeyTypeface); paint.setTypeface(params.mTypeface);
paint.setTextSize(params.mKeyHintLetterSize); paint.setTextSize(params.mHintLetterSize);
paint.setColor(params.mKeyHintLabelColor); paint.setColor(params.mHintLabelColor);
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
final float hintX = keyWidth - mKeyHintLetterPadding final float hintX = keyWidth - mKeyHintLetterPadding
- getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2; - getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2;
@ -752,8 +779,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
public Paint newDefaultLabelPaint() { public Paint newDefaultLabelPaint() {
final Paint paint = new Paint(); final Paint paint = new Paint();
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setTypeface(mKeyDrawParams.mKeyTypeface); paint.setTypeface(mKeyDrawParams.mTypeface);
paint.setTextSize(mKeyDrawParams.mKeyLabelSize); paint.setTextSize(mKeyDrawParams.mLabelSize);
return paint; return paint;
} }
@ -791,11 +818,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
@Override @Override
public void dismissKeyPreview(PointerTracker tracker) { public void dismissKeyPreview(final PointerTracker tracker) {
mDrawingHandler.dismissKeyPreview(mDelayAfterPreview, tracker); mDrawingHandler.dismissKeyPreview(mDelayAfterPreview, tracker);
} }
private void addKeyPreview(TextView keyPreview) { private void addKeyPreview(final TextView keyPreview) {
locatePreviewPlacerView(); locatePreviewPlacerView();
mPreviewPlacerView.addView( mPreviewPlacerView.addView(
keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacerView, 0, 0)); keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacerView, 0, 0));
@ -833,17 +860,17 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
@Override @Override
public void showGesturePreviewTrail(PointerTracker tracker) { public void showGesturePreviewTrail(final PointerTracker tracker) {
locatePreviewPlacerView(); locatePreviewPlacerView();
mPreviewPlacerView.invalidatePointer(tracker); mPreviewPlacerView.invalidatePointer(tracker);
} }
@SuppressWarnings("deprecation") // setBackgroundDrawable is replaced by setBackground in API16 @SuppressWarnings("deprecation") // setBackgroundDrawable is replaced by setBackground in API16
@Override @Override
public void showKeyPreview(PointerTracker tracker) { public void showKeyPreview(final PointerTracker tracker) {
final KeyPreviewDrawParams params = mKeyPreviewDrawParams; final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
if (!mShowKeyPreviewPopup) { if (!mShowKeyPreviewPopup) {
params.mPreviewVisibleOffset = -mKeyboard.mVerticalGap; previewParams.mPreviewVisibleOffset = -mKeyboard.mVerticalGap;
return; return;
} }
@ -862,17 +889,18 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
if (key == null) if (key == null)
return; return;
final KeyDrawParams drawParams = mKeyDrawParams;
final String label = key.isShiftedLetterActivated() ? key.mHintLabel : key.mLabel; final String label = key.isShiftedLetterActivated() ? key.mHintLabel : key.mLabel;
// What we show as preview should match what we show on a key top in onDraw(). // What we show as preview should match what we show on a key top in onDraw().
if (label != null) { if (label != null) {
// TODO Should take care of temporaryShiftLabel here. // TODO Should take care of temporaryShiftLabel here.
previewText.setCompoundDrawables(null, null, null, null); previewText.setCompoundDrawables(null, null, null, null);
if (StringUtils.codePointCount(label) > 1) { if (StringUtils.codePointCount(label) > 1) {
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mKeyLetterSize); previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mLetterSize);
previewText.setTypeface(Typeface.DEFAULT_BOLD); previewText.setTypeface(Typeface.DEFAULT_BOLD);
} else { } else {
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mPreviewTextSize); previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mPreviewTextSize);
previewText.setTypeface(params.mKeyTypeface); previewText.setTypeface(key.selectTypeface(drawParams));
} }
previewText.setText(label); previewText.setText(label);
} else { } else {
@ -880,47 +908,48 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
key.getPreviewIcon(mKeyboard.mIconsSet)); key.getPreviewIcon(mKeyboard.mIconsSet));
previewText.setText(null); previewText.setText(null);
} }
previewText.setBackgroundDrawable(params.mPreviewBackground); previewText.setBackgroundDrawable(mPreviewBackground);
previewText.measure( previewText.measure(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int keyDrawWidth = key.getDrawWidth(); final int keyDrawWidth = key.getDrawWidth();
final int previewWidth = previewText.getMeasuredWidth(); final int previewWidth = previewText.getMeasuredWidth();
final int previewHeight = params.mPreviewHeight; final int previewHeight = mPreviewHeight;
// The width and height of visible part of the key preview background. The content marker // The width and height of visible part of the key preview background. The content marker
// of the background 9-patch have to cover the visible part of the background. // of the background 9-patch have to cover the visible part of the background.
params.mPreviewVisibleWidth = previewWidth - previewText.getPaddingLeft() previewParams.mPreviewVisibleWidth = previewWidth - previewText.getPaddingLeft()
- previewText.getPaddingRight(); - previewText.getPaddingRight();
params.mPreviewVisibleHeight = previewHeight - previewText.getPaddingTop() previewParams.mPreviewVisibleHeight = previewHeight - previewText.getPaddingTop()
- previewText.getPaddingBottom(); - previewText.getPaddingBottom();
// The distance between the top edge of the parent key and the bottom of the visible part // The distance between the top edge of the parent key and the bottom of the visible part
// of the key preview background. // of the key preview background.
params.mPreviewVisibleOffset = params.mPreviewOffset - previewText.getPaddingBottom(); previewParams.mPreviewVisibleOffset = mPreviewOffset - previewText.getPaddingBottom();
getLocationInWindow(params.mCoordinates); getLocationInWindow(previewParams.mCoordinates);
// The key preview is horizontally aligned with the center of the visible part of the // The key preview is horizontally aligned with the center of the visible part of the
// parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and // parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and
// the left/right background is used if such background is specified. // the left/right background is used if such background is specified.
int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 + params.mCoordinates[0]; int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2
+ previewParams.mCoordinates[0];
if (previewX < 0) { if (previewX < 0) {
previewX = 0; previewX = 0;
if (params.mPreviewLeftBackground != null) { if (mPreviewLeftBackground != null) {
previewText.setBackgroundDrawable(params.mPreviewLeftBackground); previewText.setBackgroundDrawable(mPreviewLeftBackground);
} }
} else if (previewX > getWidth() - previewWidth) { } else if (previewX > getWidth() - previewWidth) {
previewX = getWidth() - previewWidth; previewX = getWidth() - previewWidth;
if (params.mPreviewRightBackground != null) { if (mPreviewRightBackground != null) {
previewText.setBackgroundDrawable(params.mPreviewRightBackground); previewText.setBackgroundDrawable(mPreviewRightBackground);
} }
} }
// The key preview is placed vertically above the top edge of the parent key with an // The key preview is placed vertically above the top edge of the parent key with an
// arbitrary offset. // arbitrary offset.
final int previewY = key.mY - previewHeight + params.mPreviewOffset final int previewY = key.mY - previewHeight + mPreviewOffset
+ params.mCoordinates[1]; + previewParams.mCoordinates[1];
// Set the preview background state // Set the preview background state
previewText.getBackground().setState( previewText.getBackground().setState(
key.mMoreKeys != null ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET); key.mMoreKeys != null ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
previewText.setTextColor(params.mPreviewTextColor); previewText.setTextColor(drawParams.mPreviewTextColor);
ViewLayoutUtils.placeViewAt( ViewLayoutUtils.placeViewAt(
previewText, previewX, previewY, previewWidth, previewHeight); previewText, previewX, previewY, previewWidth, previewHeight);
previewText.setVisibility(VISIBLE); previewText.setVisibility(VISIBLE);

View File

@ -63,9 +63,25 @@ import java.util.WeakHashMap;
/** /**
* A view that is responsible for detecting key presses and touch movements. * A view that is responsible for detecting key presses and touch movements.
* *
* @attr ref R.styleable#KeyboardView_keyHysteresisDistance * @attr ref R.styleable#MainKeyboardView_autoCorrectionSpacebarLedEnabled
* @attr ref R.styleable#KeyboardView_verticalCorrection * @attr ref R.styleable#MainKeyboardView_autoCorrectionSpacebarLedIcon
* @attr ref R.styleable#KeyboardView_popupLayout * @attr ref R.styleable#MainKeyboardView_spacebarTextRatio
* @attr ref R.styleable#MainKeyboardView_spacebarTextColor
* @attr ref R.styleable#MainKeyboardView_spacebarTextShadowColor
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFadeoutAnimator
* @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator
* @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator
* @attr ref R.styleable#MainKeyboardView_keyHysteresisDistance
* @attr ref R.styleable#MainKeyboardView_touchNoiseThresholdTime
* @attr ref R.styleable#MainKeyboardView_touchNoiseThresholdDistance
* @attr ref R.styleable#MainKeyboardView_slidingKeyInputEnable
* @attr ref R.styleable#MainKeyboardView_keyRepeatStartTimeout
* @attr ref R.styleable#MainKeyboardView_keyRepeatInterval
* @attr ref R.styleable#MainKeyboardView_longPressKeyTimeout
* @attr ref R.styleable#MainKeyboardView_longPressShiftKeyTimeout
* @attr ref R.styleable#MainKeyboardView_ignoreAltCodeKeyTimeout
* @attr ref R.styleable#MainKeyboardView_showMoreKeysKeyboardAtTouchPoint
*/ */
public class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler, public class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler,
SuddenJumpingTouchEventHandler.ProcessMotionEvent { SuddenJumpingTouchEventHandler.ProcessMotionEvent {
@ -150,7 +166,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(final Message msg) {
final MainKeyboardView keyboardView = getOuterInstance(); final MainKeyboardView keyboardView = getOuterInstance();
final PointerTracker tracker = (PointerTracker) msg.obj; final PointerTracker tracker = (PointerTracker) msg.obj;
switch (msg.what) { switch (msg.what) {
@ -174,14 +190,14 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
} }
private void startKeyRepeatTimer(PointerTracker tracker, long delay) { private void startKeyRepeatTimer(final PointerTracker tracker, final long delay) {
final Key key = tracker.getKey(); final Key key = tracker.getKey();
if (key == null) return; if (key == null) return;
sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, key.mCode, 0, tracker), delay); sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, key.mCode, 0, tracker), delay);
} }
@Override @Override
public void startKeyRepeatTimer(PointerTracker tracker) { public void startKeyRepeatTimer(final PointerTracker tracker) {
startKeyRepeatTimer(tracker, mKeyRepeatStartTimeout); startKeyRepeatTimer(tracker, mKeyRepeatStartTimeout);
} }
@ -195,7 +211,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
@Override @Override
public void startLongPressTimer(int code) { public void startLongPressTimer(final int code) {
cancelLongPressTimer(); cancelLongPressTimer();
final int delay; final int delay;
switch (code) { switch (code) {
@ -212,7 +228,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
@Override @Override
public void startLongPressTimer(PointerTracker tracker) { public void startLongPressTimer(final PointerTracker tracker) {
cancelLongPressTimer(); cancelLongPressTimer();
if (tracker == null) { if (tracker == null) {
return; return;
@ -266,7 +282,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
@Override @Override
public void startTypingStateTimer(Key typedKey) { public void startTypingStateTimer(final Key typedKey) {
if (typedKey.isModifier() || typedKey.altCodeWhileTyping()) { if (typedKey.isModifier() || typedKey.altCodeWhileTyping()) {
return; return;
} }
@ -322,11 +338,11 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
} }
public MainKeyboardView(Context context, AttributeSet attrs) { public MainKeyboardView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.mainKeyboardViewStyle); this(context, attrs, R.attr.mainKeyboardViewStyle);
} }
public MainKeyboardView(Context context, AttributeSet attrs, int defStyle) { public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
mTouchScreenRegulator = new SuddenJumpingTouchEventHandler(getContext(), this); mTouchScreenRegulator = new SuddenJumpingTouchEventHandler(getContext(), this);
@ -377,7 +393,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
altCodeKeyWhileTypingFadeinAnimatorResId, this); altCodeKeyWhileTypingFadeinAnimatorResId, this);
} }
private ObjectAnimator loadObjectAnimator(int resId, Object target) { private ObjectAnimator loadObjectAnimator(final int resId, final Object target) {
if (resId == 0) return null; if (resId == 0) return null;
final ObjectAnimator animator = (ObjectAnimator)AnimatorInflater.loadAnimator( final ObjectAnimator animator = (ObjectAnimator)AnimatorInflater.loadAnimator(
getContext(), resId); getContext(), resId);
@ -392,7 +408,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
return mLanguageOnSpacebarAnimAlpha; return mLanguageOnSpacebarAnimAlpha;
} }
public void setLanguageOnSpacebarAnimAlpha(int alpha) { public void setLanguageOnSpacebarAnimAlpha(final int alpha) {
mLanguageOnSpacebarAnimAlpha = alpha; mLanguageOnSpacebarAnimAlpha = alpha;
invalidateKey(mSpaceKey); invalidateKey(mSpaceKey);
} }
@ -401,12 +417,12 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
return mAltCodeKeyWhileTypingAnimAlpha; return mAltCodeKeyWhileTypingAnimAlpha;
} }
public void setAltCodeKeyWhileTypingAnimAlpha(int alpha) { public void setAltCodeKeyWhileTypingAnimAlpha(final int alpha) {
mAltCodeKeyWhileTypingAnimAlpha = alpha; mAltCodeKeyWhileTypingAnimAlpha = alpha;
updateAltCodeKeyWhileTyping(); updateAltCodeKeyWhileTyping();
} }
public void setKeyboardActionListener(KeyboardActionListener listener) { public void setKeyboardActionListener(final KeyboardActionListener listener) {
mKeyboardActionListener = listener; mKeyboardActionListener = listener;
PointerTracker.setKeyboardActionListener(listener); PointerTracker.setKeyboardActionListener(listener);
} }
@ -443,7 +459,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
* @param keyboard the keyboard to display in this view * @param keyboard the keyboard to display in this view
*/ */
@Override @Override
public void setKeyboard(Keyboard keyboard) { public void setKeyboard(final Keyboard keyboard) {
// Remove any pending messages, except dismissing preview and key repeat. // Remove any pending messages, except dismissing preview and key repeat.
mKeyTimerHandler.cancelLongPressTimer(); mKeyTimerHandler.cancelLongPressTimer();
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
@ -468,11 +484,11 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
// Note that this method is called from a non-UI thread. // Note that this method is called from a non-UI thread.
public void setMainDictionaryAvailability(boolean mainDictionaryAvailable) { public void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
PointerTracker.setMainDictionaryAvailability(mainDictionaryAvailable); PointerTracker.setMainDictionaryAvailability(mainDictionaryAvailable);
} }
public void setGestureHandlingEnabledByUser(boolean gestureHandlingEnabledByUser) { public void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) {
PointerTracker.setGestureHandlingEnabledByUser(gestureHandlingEnabledByUser); PointerTracker.setGestureHandlingEnabledByUser(gestureHandlingEnabledByUser);
} }
@ -484,7 +500,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
return mHasDistinctMultitouch; return mHasDistinctMultitouch;
} }
public void setDistinctMultitouch(boolean hasDistinctMultitouch) { public void setDistinctMultitouch(final boolean hasDistinctMultitouch) {
mHasDistinctMultitouch = hasDistinctMultitouch; mHasDistinctMultitouch = hasDistinctMultitouch;
} }
@ -515,7 +531,8 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
super.cancelAllMessages(); super.cancelAllMessages();
} }
private boolean openMoreKeysKeyboardIfRequired(Key parentKey, PointerTracker tracker) { private boolean openMoreKeysKeyboardIfRequired(final Key parentKey,
final PointerTracker tracker) {
// Check if we have a popup layout specified first. // Check if we have a popup layout specified first.
if (mMoreKeysLayout == 0) { if (mMoreKeysLayout == 0) {
return false; return false;
@ -530,7 +547,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
// This default implementation returns a more keys panel. // This default implementation returns a more keys panel.
protected MoreKeysPanel onCreateMoreKeysPanel(Key parentKey) { protected MoreKeysPanel onCreateMoreKeysPanel(final Key parentKey) {
if (parentKey.mMoreKeys == null) if (parentKey.mMoreKeys == null)
return null; return null;
@ -556,7 +573,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
* @return true if the long press is handled, false otherwise. Subclasses should call the * @return true if the long press is handled, false otherwise. Subclasses should call the
* method on the base class if the subclass doesn't wish to handle the call. * method on the base class if the subclass doesn't wish to handle the call.
*/ */
protected boolean onLongPress(Key parentKey, PointerTracker tracker) { protected boolean onLongPress(final Key parentKey, final PointerTracker tracker) {
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.mainKeyboardView_onLongPress(); ResearchLogger.mainKeyboardView_onLongPress();
} }
@ -580,20 +597,20 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
return openMoreKeysPanel(parentKey, tracker); return openMoreKeysPanel(parentKey, tracker);
} }
private boolean invokeCustomRequest(int code) { private boolean invokeCustomRequest(final int code) {
return mKeyboardActionListener.onCustomRequest(code); return mKeyboardActionListener.onCustomRequest(code);
} }
private void invokeCodeInput(int primaryCode) { private void invokeCodeInput(final int primaryCode) {
mKeyboardActionListener.onCodeInput( mKeyboardActionListener.onCodeInput(
primaryCode, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); primaryCode, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
} }
private void invokeReleaseKey(int primaryCode) { private void invokeReleaseKey(final int primaryCode) {
mKeyboardActionListener.onReleaseKey(primaryCode, false); mKeyboardActionListener.onReleaseKey(primaryCode, false);
} }
private boolean openMoreKeysPanel(Key parentKey, PointerTracker tracker) { private boolean openMoreKeysPanel(final Key parentKey, final PointerTracker tracker) {
MoreKeysPanel moreKeysPanel = mMoreKeysPanelCache.get(parentKey); MoreKeysPanel moreKeysPanel = mMoreKeysPanelCache.get(parentKey);
if (moreKeysPanel == null) { if (moreKeysPanel == null) {
moreKeysPanel = onCreateMoreKeysPanel(parentKey); moreKeysPanel = onCreateMoreKeysPanel(parentKey);
@ -644,7 +661,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
@Override @Override
public boolean onTouchEvent(MotionEvent me) { public boolean onTouchEvent(final MotionEvent me) {
if (getKeyboard() == null) { if (getKeyboard() == null) {
return false; return false;
} }
@ -652,7 +669,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
@Override @Override
public boolean processMotionEvent(MotionEvent me) { public boolean processMotionEvent(final MotionEvent me) {
final boolean nonDistinctMultitouch = !mHasDistinctMultitouch; final boolean nonDistinctMultitouch = !mHasDistinctMultitouch;
final int action = me.getActionMasked(); final int action = me.getActionMasked();
final int pointerCount = me.getPointerCount(); final int pointerCount = me.getPointerCount();
@ -819,7 +836,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
* otherwise * otherwise
*/ */
@Override @Override
public boolean dispatchHoverEvent(MotionEvent event) { public boolean dispatchHoverEvent(final MotionEvent event) {
if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
final PointerTracker tracker = PointerTracker.getPointerTracker(0, this); final PointerTracker tracker = PointerTracker.getPointerTracker(0, this);
return AccessibleKeyboardViewProxy.getInstance().dispatchHoverEvent(event, tracker); return AccessibleKeyboardViewProxy.getInstance().dispatchHoverEvent(event, tracker);
@ -829,7 +846,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
return false; return false;
} }
public void updateShortcutKey(boolean available) { public void updateShortcutKey(final boolean available) {
final Keyboard keyboard = getKeyboard(); final Keyboard keyboard = getKeyboard();
if (keyboard == null) return; if (keyboard == null) return;
final Key shortcutKey = keyboard.getKey(Keyboard.CODE_SHORTCUT); final Key shortcutKey = keyboard.getKey(Keyboard.CODE_SHORTCUT);
@ -846,8 +863,8 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
} }
public void startDisplayLanguageOnSpacebar(boolean subtypeChanged, public void startDisplayLanguageOnSpacebar(final boolean subtypeChanged,
boolean needsToDisplayLanguage, boolean hasMultipleEnabledIMEsOrSubtypes) { final boolean needsToDisplayLanguage, final boolean hasMultipleEnabledIMEsOrSubtypes) {
mNeedsToDisplayLanguage = needsToDisplayLanguage; mNeedsToDisplayLanguage = needsToDisplayLanguage;
mHasMultipleEnabledIMEsOrSubtypes = hasMultipleEnabledIMEsOrSubtypes; mHasMultipleEnabledIMEsOrSubtypes = hasMultipleEnabledIMEsOrSubtypes;
final ObjectAnimator animator = mLanguageOnSpacebarFadeoutAnimator; final ObjectAnimator animator = mLanguageOnSpacebarFadeoutAnimator;
@ -869,14 +886,15 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
invalidateKey(mSpaceKey); invalidateKey(mSpaceKey);
} }
public void updateAutoCorrectionState(boolean isAutoCorrection) { public void updateAutoCorrectionState(final boolean isAutoCorrection) {
if (!mAutoCorrectionSpacebarLedEnabled) return; if (!mAutoCorrectionSpacebarLedEnabled) return;
mAutoCorrectionSpacebarLedOn = isAutoCorrection; mAutoCorrectionSpacebarLedOn = isAutoCorrection;
invalidateKey(mSpaceKey); invalidateKey(mSpaceKey);
} }
@Override @Override
protected void onDrawKeyTopVisuals(Key key, Canvas canvas, Paint paint, KeyDrawParams params) { protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
final KeyDrawParams params) {
if (key.altCodeWhileTyping() && key.isEnabled()) { if (key.altCodeWhileTyping() && key.isEnabled()) {
params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha; params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha;
} }
@ -894,7 +912,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
} }
private boolean fitsTextIntoWidth(final int width, String text, Paint paint) { private boolean fitsTextIntoWidth(final int width, final String text, final Paint paint) {
paint.setTextScaleX(1.0f); paint.setTextScaleX(1.0f);
final float textWidth = getLabelWidth(text, paint); final float textWidth = getLabelWidth(text, paint);
if (textWidth < width) return true; if (textWidth < width) return true;
@ -907,7 +925,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
// Layout language name on spacebar. // Layout language name on spacebar.
private String layoutLanguageOnSpacebar(Paint paint, InputMethodSubtype subtype, private String layoutLanguageOnSpacebar(final Paint paint, final InputMethodSubtype subtype,
final int width) { final int width) {
// Choose appropriate language name to fit into the width. // Choose appropriate language name to fit into the width.
String text = getFullDisplayName(subtype, getResources()); String text = getFullDisplayName(subtype, getResources());
@ -928,7 +946,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
return ""; return "";
} }
private void drawSpacebar(Key key, Canvas canvas, Paint paint) { private void drawSpacebar(final Key key, final Canvas canvas, final Paint paint) {
final int width = key.mWidth; final int width = key.mWidth;
final int height = key.mHeight; final int height = key.mHeight;
@ -983,7 +1001,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
// zz azerty T AZERTY AZERTY // zz azerty T AZERTY AZERTY
// Get InputMethodSubtype's full display name in its locale. // Get InputMethodSubtype's full display name in its locale.
static String getFullDisplayName(InputMethodSubtype subtype, Resources res) { static String getFullDisplayName(final InputMethodSubtype subtype, final Resources res) {
if (SubtypeLocale.isNoLanguage(subtype)) { if (SubtypeLocale.isNoLanguage(subtype)) {
return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype); return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype);
} }
@ -992,7 +1010,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
// Get InputMethodSubtype's short display name in its locale. // Get InputMethodSubtype's short display name in its locale.
static String getShortDisplayName(InputMethodSubtype subtype) { static String getShortDisplayName(final InputMethodSubtype subtype) {
if (SubtypeLocale.isNoLanguage(subtype)) { if (SubtypeLocale.isNoLanguage(subtype)) {
return ""; return "";
} }
@ -1001,7 +1019,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
// Get InputMethodSubtype's middle display name in its locale. // Get InputMethodSubtype's middle display name in its locale.
static String getMiddleDisplayName(InputMethodSubtype subtype) { static String getMiddleDisplayName(final InputMethodSubtype subtype) {
if (SubtypeLocale.isNoLanguage(subtype)) { if (SubtypeLocale.isNoLanguage(subtype)) {
return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype); return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype);
} }

View File

@ -311,9 +311,8 @@ public class MoreKeysKeyboard extends Keyboard {
.getDimension(R.dimen.more_keys_keyboard_key_horizontal_padding) .getDimension(R.dimen.more_keys_keyboard_key_horizontal_padding)
+ (parentKey.hasLabelsInMoreKeys() ? minKeyWidth * LABEL_PADDING_RATIO : 0)); + (parentKey.hasLabelsInMoreKeys() ? minKeyWidth * LABEL_PADDING_RATIO : 0));
final Paint paint = view.newDefaultLabelPaint(); final Paint paint = view.newDefaultLabelPaint();
paint.setTextSize(parentKey.hasLabelsInMoreKeys() paint.setTypeface(parentKey.selectTypeface(view.mKeyDrawParams));
? view.mKeyDrawParams.mKeyLabelSize paint.setTextSize(parentKey.selectMoreKeyTextSize(view.mKeyDrawParams));
: view.mKeyDrawParams.mKeyLetterSize);
int maxWidth = minKeyWidth; int maxWidth = minKeyWidth;
for (final MoreKeySpec spec : parentKey.mMoreKeys) { for (final MoreKeySpec spec : parentKey.mMoreKeys) {
final String label = spec.mLabel; final String label = spec.mLabel;

View File

@ -16,113 +16,98 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.ResourceUtils; import com.android.inputmethod.latin.ResourceUtils;
public class KeyDrawParams { public class KeyDrawParams {
// XML attributes public Typeface mTypeface;
public final int mKeyTextColor;
public final int mKeyTextInactivatedColor;
public final int mKeyTextShadowColor;
public final float mKeyTextShadowRadius;
public final Drawable mKeyBackground;
public final int mKeyHintLetterColor;
public final int mKeyHintLabelColor;
public final int mKeyShiftedLetterHintInactivatedColor;
public final int mKeyShiftedLetterHintActivatedColor;
private final Typeface mKeyTypefaceFromKeyboardView; public int mLetterSize;
private final float mKeyLetterRatio; public int mLabelSize;
private final int mKeyLetterSizeFromKeyboardView; public int mLargeLetterSize;
private final float mKeyLargeLetterRatio; public int mLargeLabelSize;
private final float mKeyLabelRatio; public int mHintLetterSize;
private final float mKeyLargeLabelRatio; public int mShiftedLetterHintSize;
private final float mKeyHintLetterRatio; public int mHintLabelSize;
private final float mKeyShiftedLetterHintRatio; public int mPreviewTextSize;
private final float mKeyHintLabelRatio;
public int mTextColor;
public int mTextInactivatedColor;
public int mTextShadowColor;
public int mHintLetterColor;
public int mHintLabelColor;
public int mShiftedLetterHintInactivatedColor;
public int mShiftedLetterHintActivatedColor;
public int mPreviewTextColor;
public final Rect mPadding = new Rect();
public Typeface mKeyTypeface;
public int mKeyLetterSize;
public int mKeyLargeLetterSize;
public int mKeyLabelSize;
public int mKeyLargeLabelSize;
public int mKeyHintLetterSize;
public int mKeyShiftedLetterHintSize;
public int mKeyHintLabelSize;
public int mAnimAlpha; public int mAnimAlpha;
public KeyDrawParams(final TypedArray keyboardViewAttr, final TypedArray keyAttr) { private KeyDrawParams(final KeyDrawParams copyFrom) {
mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground); mTypeface = copyFrom.mTypeface;
mKeyBackground.getPadding(mPadding);
mKeyLetterRatio = ResourceUtils.getFraction(keyAttr, mLetterSize = copyFrom.mLetterSize;
R.styleable.Keyboard_Key_keyLetterSize); mLabelSize = copyFrom.mLabelSize;
mKeyLetterSizeFromKeyboardView = ResourceUtils.getDimensionPixelSize(keyAttr, mLargeLetterSize = copyFrom.mLargeLetterSize;
R.styleable.Keyboard_Key_keyLetterSize); mLargeLabelSize = copyFrom.mLargeLabelSize;
mKeyLabelRatio = ResourceUtils.getFraction(keyAttr, mHintLetterSize = copyFrom.mHintLetterSize;
R.styleable.Keyboard_Key_keyLabelSize); mShiftedLetterHintSize = copyFrom.mShiftedLetterHintSize;
mKeyLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr, mHintLabelSize = copyFrom.mHintLabelSize;
R.styleable.Keyboard_Key_keyLabelSize); mPreviewTextSize = copyFrom.mPreviewTextSize;
mKeyLargeLabelRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyLargeLabelRatio); mTextColor = copyFrom.mTextColor;
mKeyLargeLetterRatio = ResourceUtils.getFraction(keyAttr, mTextInactivatedColor = copyFrom.mTextInactivatedColor;
R.styleable.Keyboard_Key_keyLargeLetterRatio); mTextShadowColor = copyFrom.mTextShadowColor;
mKeyHintLetterRatio = ResourceUtils.getFraction(keyAttr, mHintLetterColor = copyFrom.mHintLetterColor;
R.styleable.Keyboard_Key_keyHintLetterRatio); mHintLabelColor = copyFrom.mHintLabelColor;
mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr, mShiftedLetterHintInactivatedColor = copyFrom.mShiftedLetterHintInactivatedColor;
R.styleable.Keyboard_Key_keyShiftedLetterHintRatio); mShiftedLetterHintActivatedColor = copyFrom.mShiftedLetterHintActivatedColor;
mKeyHintLabelRatio = ResourceUtils.getFraction(keyAttr, mPreviewTextColor = copyFrom.mPreviewTextColor;
R.styleable.Keyboard_Key_keyHintLabelRatio);
mKeyTextColor = keyAttr.getColor( mAnimAlpha = copyFrom.mAnimAlpha;
R.styleable.Keyboard_Key_keyTextColor, Color.WHITE);
mKeyTextInactivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyTextInactivatedColor, Color.WHITE);
mKeyHintLetterColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyHintLetterColor, Color.TRANSPARENT);
mKeyHintLabelColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyHintLabelColor, Color.TRANSPARENT);
mKeyShiftedLetterHintInactivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, Color.TRANSPARENT);
mKeyShiftedLetterHintActivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, Color.TRANSPARENT);
mKeyTypefaceFromKeyboardView = Typeface.defaultFromStyle(
keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
mKeyTextShadowColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyTextShadowColor, Color.TRANSPARENT);
mKeyTextShadowRadius = keyAttr.getFloat(
R.styleable.Keyboard_Key_keyTextShadowRadius, 0f);
} }
public void updateParams(final Keyboard keyboard) { public void updateParams(final int keyHeight, final KeyVisualAttributes attr) {
mKeyTypeface = (keyboard.mKeyTypeface != null) if (attr == null) {
? keyboard.mKeyTypeface : mKeyTypefaceFromKeyboardView; return;
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
mKeyLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight,
mKeyLetterSizeFromKeyboardView, mKeyLetterRatio,
mKeyLetterSizeFromKeyboardView);
// Override if size/ratio is specified in Keyboard.
mKeyLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight, keyboard.mKeyLetterSize,
keyboard.mKeyLetterRatio, mKeyLetterSize);
if (ResourceUtils.isValidFraction(mKeyLabelRatio)) {
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
} }
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio); if (attr.mTypeface != null) {
mKeyHintLetterSize = selectTextSizeFromKeyboardOrView(keyHeight, mTypeface = attr.mTypeface;
keyboard.mKeyHintLetterRatio, mKeyHintLetterRatio); }
mKeyShiftedLetterHintSize = selectTextSizeFromKeyboardOrView(keyHeight,
keyboard.mKeyShiftedLetterHintRatio, mKeyShiftedLetterHintRatio); mLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight,
mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio); attr.mLetterSize, attr.mLetterRatio, mLetterSize);
mLabelSize = selectTextSizeFromDimensionOrRatio(keyHeight,
attr.mLabelSize, attr.mLabelRatio, mLabelSize);
mLargeLabelSize = selectTextSize(keyHeight, attr.mLargeLabelRatio, mLargeLabelSize);
mLargeLetterSize = selectTextSize(keyHeight, attr.mLargeLetterRatio, mLargeLetterSize);
mHintLetterSize = selectTextSize(keyHeight, attr.mHintLetterRatio, mHintLetterSize);
mShiftedLetterHintSize = selectTextSize(keyHeight,
attr.mShiftedLetterHintRatio, mShiftedLetterHintSize);
mHintLabelSize = selectTextSize(keyHeight, attr.mHintLabelRatio, mHintLabelSize);
mPreviewTextSize = selectTextSize(keyHeight, attr.mPreviewTextRatio, mPreviewTextSize);
mTextColor = selectColor(attr.mTextColor, mTextColor);
mTextInactivatedColor = selectColor(attr.mTextInactivatedColor, mTextInactivatedColor);
mTextShadowColor = selectColor(attr.mTextShadowColor, mTextShadowColor);
mHintLetterColor = selectColor(attr.mHintLetterColor, mHintLetterColor);
mHintLabelColor = selectColor(attr.mHintLabelColor, mHintLabelColor);
mShiftedLetterHintInactivatedColor = selectColor(
attr.mShiftedLetterHintInactivatedColor, mShiftedLetterHintInactivatedColor);
mShiftedLetterHintActivatedColor = selectColor(
attr.mShiftedLetterHintActivatedColor, mShiftedLetterHintActivatedColor);
mPreviewTextColor = selectColor(attr.mPreviewTextColor, mPreviewTextColor);
}
public KeyDrawParams mayCloneAndUpdateParams(final int keyHeight,
final KeyVisualAttributes attr) {
if (attr == null) {
return this;
}
final KeyDrawParams newParams = new KeyDrawParams(this);
newParams.updateParams(keyHeight, attr);
return newParams;
} }
private static final int selectTextSizeFromDimensionOrRatio(final int keyHeight, private static final int selectTextSizeFromDimensionOrRatio(final int keyHeight,
@ -136,16 +121,18 @@ public class KeyDrawParams {
return defaultDimens; return defaultDimens;
} }
private static final int selectTextSizeFromKeyboardOrView(final int keyHeight, private static final int selectTextSize(final int keyHeight, final float ratio,
final float ratioFromKeyboard, final float ratioFromView) { final int defaultSize) {
final float ratio = ResourceUtils.isValidFraction(ratioFromKeyboard) if (ResourceUtils.isValidFraction(ratio)) {
? ratioFromKeyboard : ratioFromView; return (int)(keyHeight * ratio);
return (int)(keyHeight * ratio); }
return defaultSize;
} }
public void blendAlpha(final Paint paint) { private static final int selectColor(final int attrColor, final int defaultColor) {
final int color = paint.getColor(); if (attrColor != 0) {
paint.setARGB((paint.getAlpha() * mAnimAlpha) / Constants.Color.ALPHA_OPAQUE, return attrColor;
Color.red(color), Color.green(color), Color.blue(color)); }
return defaultColor;
} }
} }

View File

@ -16,26 +16,7 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.ResourceUtils;
public class KeyPreviewDrawParams { public class KeyPreviewDrawParams {
// XML attributes.
public final Drawable mPreviewBackground;
public final Drawable mPreviewLeftBackground;
public final Drawable mPreviewRightBackground;
public final int mPreviewTextColor;
public final int mPreviewOffset;
public final int mPreviewHeight;
public final int mLingerTimeout;
private final float mPreviewTextRatio;
// The graphical geometry of the key preview. // The graphical geometry of the key preview.
// <-width-> // <-width->
// +-------+ ^ // +-------+ ^
@ -61,46 +42,5 @@ public class KeyPreviewDrawParams {
// preview background. // preview background.
public int mPreviewVisibleOffset; public int mPreviewVisibleOffset;
public Typeface mKeyTypeface;
public int mPreviewTextSize;
public int mKeyLetterSize;
public final int[] mCoordinates = new int[2]; public final int[] mCoordinates = new int[2];
private static final int PREVIEW_ALPHA = 240;
public KeyPreviewDrawParams(final TypedArray keyboardViewAttr, final TypedArray keyAttr) {
mPreviewBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_keyPreviewBackground);
mPreviewLeftBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_keyPreviewLeftBackground);
mPreviewRightBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_keyPreviewRightBackground);
setAlpha(mPreviewBackground, PREVIEW_ALPHA);
setAlpha(mPreviewLeftBackground, PREVIEW_ALPHA);
setAlpha(mPreviewRightBackground, PREVIEW_ALPHA);
mPreviewOffset = keyboardViewAttr.getDimensionPixelOffset(
R.styleable.KeyboardView_keyPreviewOffset, 0);
mPreviewHeight = keyboardViewAttr.getDimensionPixelSize(
R.styleable.KeyboardView_keyPreviewHeight, 80);
mLingerTimeout = keyboardViewAttr.getInt(
R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyPreviewTextRatio);
mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
}
public void updateParams(final Keyboard keyboard, final KeyDrawParams keyDrawParams) {
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
if (ResourceUtils.isValidFraction(mPreviewTextRatio)) {
mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio);
}
mKeyLetterSize = keyDrawParams.mKeyLetterSize;
mKeyTypeface = keyDrawParams.mKeyTypeface;
}
private static void setAlpha(final Drawable drawable, final int alpha) {
if (drawable == null) return;
drawable.setAlpha(alpha);
}
} }

View File

@ -0,0 +1,130 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.keyboard.internal;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.SparseIntArray;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.ResourceUtils;
public class KeyVisualAttributes {
public final Typeface mTypeface;
public final float mLetterRatio;
public final int mLetterSize;
public final float mLabelRatio;
public final int mLabelSize;
public final float mLargeLetterRatio;
public final float mLargeLabelRatio;
public final float mHintLetterRatio;
public final float mShiftedLetterHintRatio;
public final float mHintLabelRatio;
public final float mPreviewTextRatio;
public final int mTextColor;
public final int mTextInactivatedColor;
public final int mTextShadowColor;
public final int mHintLetterColor;
public final int mHintLabelColor;
public final int mShiftedLetterHintInactivatedColor;
public final int mShiftedLetterHintActivatedColor;
public final int mPreviewTextColor;
private static final int[] VISUAL_ATTRIBUTE_IDS = {
R.styleable.Keyboard_Key_keyTypeface,
R.styleable.Keyboard_Key_keyLetterSize,
R.styleable.Keyboard_Key_keyLabelSize,
R.styleable.Keyboard_Key_keyLargeLetterRatio,
R.styleable.Keyboard_Key_keyLargeLabelRatio,
R.styleable.Keyboard_Key_keyHintLetterRatio,
R.styleable.Keyboard_Key_keyShiftedLetterHintRatio,
R.styleable.Keyboard_Key_keyHintLabelRatio,
R.styleable.Keyboard_Key_keyPreviewTextRatio,
R.styleable.Keyboard_Key_keyTextColor,
R.styleable.Keyboard_Key_keyTextInactivatedColor,
R.styleable.Keyboard_Key_keyTextShadowColor,
R.styleable.Keyboard_Key_keyHintLetterColor,
R.styleable.Keyboard_Key_keyHintLabelColor,
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor,
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor,
R.styleable.Keyboard_Key_keyPreviewTextColor,
};
private static final SparseIntArray sVisualAttributeIds = new SparseIntArray();
private static final int ATTR_DEFINED = 1;
private static final int ATTR_NOT_FOUND = 0;
static {
for (final int attrId : VISUAL_ATTRIBUTE_IDS) {
sVisualAttributeIds.put(attrId, ATTR_DEFINED);
}
}
public static KeyVisualAttributes newInstance(final TypedArray keyAttr) {
final int indexCount = keyAttr.getIndexCount();
for (int i = 0; i < indexCount; i++) {
final int attrId = keyAttr.getIndex(i);
if (sVisualAttributeIds.get(attrId, ATTR_NOT_FOUND) == ATTR_NOT_FOUND) {
continue;
}
return new KeyVisualAttributes(keyAttr);
}
return null;
}
private KeyVisualAttributes(final TypedArray keyAttr) {
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
mTypeface = Typeface.defaultFromStyle(
keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
} else {
mTypeface = null;
}
mLetterRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyLetterSize);
mLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
R.styleable.Keyboard_Key_keyLetterSize);
mLabelRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyLabelSize);
mLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
R.styleable.Keyboard_Key_keyLabelSize);
mLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyLargeLetterRatio);
mLargeLabelRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyLargeLabelRatio);
mHintLetterRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyHintLetterRatio);
mShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
mHintLabelRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyHintLabelRatio);
mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyPreviewTextRatio);
mTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
mTextInactivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);
mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0);
mHintLetterColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
mHintLabelColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
mShiftedLetterHintInactivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
mShiftedLetterHintActivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
}
}

View File

@ -20,7 +20,6 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.graphics.Typeface;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
@ -289,18 +288,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
R.styleable.Keyboard_rowHeight, params.mBaseHeight, R.styleable.Keyboard_rowHeight, params.mBaseHeight,
params.mBaseHeight / DEFAULT_KEYBOARD_ROWS); params.mBaseHeight / DEFAULT_KEYBOARD_ROWS);
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) { params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
params.mKeyTypeface = Typeface.defaultFromStyle(keyAttr.getInt(
R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
}
params.mKeyLetterRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyLetterSize);
params.mKeyLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
R.styleable.Keyboard_Key_keyLetterSize);
params.mKeyHintLetterRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyHintLetterRatio);
params.mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
params.mMoreKeysTemplate = keyboardAttr.getResourceId( params.mMoreKeysTemplate = keyboardAttr.getResourceId(
R.styleable.Keyboard_moreKeysTemplate, 0); R.styleable.Keyboard_moreKeysTemplate, 0);

View File

@ -16,14 +16,12 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import android.graphics.Typeface;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.ResourceUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -47,11 +45,7 @@ public class KeyboardParams {
public int mHorizontalEdgesPadding; public int mHorizontalEdgesPadding;
public int mHorizontalCenterPadding; public int mHorizontalCenterPadding;
public Typeface mKeyTypeface = null; public KeyVisualAttributes mKeyVisualAttributes;
public float mKeyLetterRatio = ResourceUtils.UNDEFINED_RATIO;
public int mKeyLetterSize = ResourceUtils.UNDEFINED_DIMENSION;
public float mKeyHintLetterRatio = ResourceUtils.UNDEFINED_RATIO;
public float mKeyShiftedLetterHintRatio = ResourceUtils.UNDEFINED_RATIO;
public int mDefaultRowHeight; public int mDefaultRowHeight;
public int mDefaultKeyWidth; public int mDefaultKeyWidth;