Move logic of selecting key preview attribute to Key class

This change also fixes the size of a key preview letter to follow a
keyLabelFlags specification.

Change-Id: Ie13790788a16c5a053c1a2cbcac3d38314b14b7f
This commit is contained in:
Tadashi G. Takaoka 2013-03-08 18:57:55 +09:00
parent eb26838afa
commit 914d054ea2
2 changed files with 38 additions and 19 deletions

View file

@ -519,11 +519,11 @@ public class Key implements Comparable<Key> {
// 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) {
return Typeface.MONOSPACE;
} else {
return params.mTypeface;
} }
if ((mLabelFlags & LABEL_FLAGS_FONT_MONO_SPACE) != 0) {
return Typeface.MONOSPACE;
}
return params.mTypeface;
} }
public final int selectTextSize(final KeyDrawParams params) { public final int selectTextSize(final KeyDrawParams params) {
@ -550,28 +550,51 @@ public class Key implements Comparable<Key> {
public final int selectHintTextSize(final KeyDrawParams params) { public final int selectHintTextSize(final KeyDrawParams params) {
if (hasHintLabel()) { if (hasHintLabel()) {
return params.mHintLabelSize; return params.mHintLabelSize;
} else if (hasShiftedLetterHint()) {
return params.mShiftedLetterHintSize;
} else {
return params.mHintLetterSize;
} }
if (hasShiftedLetterHint()) {
return params.mShiftedLetterHintSize;
}
return params.mHintLetterSize;
} }
public final int selectHintTextColor(final KeyDrawParams params) { public final int selectHintTextColor(final KeyDrawParams params) {
if (hasHintLabel()) { if (hasHintLabel()) {
return params.mHintLabelColor; return params.mHintLabelColor;
} else if (hasShiftedLetterHint()) { }
if (hasShiftedLetterHint()) {
return isShiftedLetterActivated() ? params.mShiftedLetterHintActivatedColor return isShiftedLetterActivated() ? params.mShiftedLetterHintActivatedColor
: params.mShiftedLetterHintInactivatedColor; : params.mShiftedLetterHintInactivatedColor;
} else {
return params.mHintLetterColor;
} }
return params.mHintLetterColor;
} }
public final int selectMoreKeyTextSize(final KeyDrawParams params) { public final int selectMoreKeyTextSize(final KeyDrawParams params) {
return hasLabelsInMoreKeys() ? params.mLabelSize : params.mLetterSize; return hasLabelsInMoreKeys() ? params.mLabelSize : params.mLetterSize;
} }
public final String getPreviewLabel() {
return isShiftedLetterActivated() ? mHintLabel : mLabel;
}
private boolean previewHasLetterSize() {
return (mLabelFlags & LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO) != 0
|| StringUtils.codePointCount(getPreviewLabel()) == 1;
}
public final int selectPreviewTextSize(final KeyDrawParams params) {
if (previewHasLetterSize()) {
return params.mPreviewTextSize;
}
return params.mLetterSize;
}
public Typeface selectPreviewTypeface(final KeyDrawParams params) {
if (previewHasLetterSize()) {
return selectTypeface(params);
}
return Typeface.DEFAULT_BOLD;
}
public final boolean isAlignLeft() { public final boolean isAlignLeft() {
return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT) != 0; return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT) != 0;
} }

View file

@ -811,18 +811,14 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
background.setState(KEY_PREVIEW_BACKGROUND_DEFAULT_STATE); background.setState(KEY_PREVIEW_BACKGROUND_DEFAULT_STATE);
background.setAlpha(PREVIEW_ALPHA); background.setAlpha(PREVIEW_ALPHA);
} }
final String label = key.isShiftedLetterActivated() ? key.mHintLabel : key.mLabel; final String label = key.getPreviewLabel();
// 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) { previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX,
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mLetterSize); key.selectPreviewTextSize(drawParams));
previewText.setTypeface(Typeface.DEFAULT_BOLD); previewText.setTypeface(key.selectPreviewTypeface(drawParams));
} else {
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mPreviewTextSize);
previewText.setTypeface(key.selectTypeface(drawParams));
}
previewText.setText(label); previewText.setText(label);
} else { } else {
previewText.setCompoundDrawables(null, null, null, previewText.setCompoundDrawables(null, null, null,