am 914d054e: Move logic of selecting key preview attribute to Key class

* commit '914d054ea26d18a1ba6a60f8c5e749136477bbf2':
  Move logic of selecting key preview attribute to Key class
main
Tadashi G. Takaoka 2013-03-08 11:24:13 +00:00 committed by Android Git Automerger
commit 60906d4d08
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?
if ((mLabelFlags & LABEL_FLAGS_FONT_NORMAL) != 0) {
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) {
@ -550,28 +550,51 @@ public class Key implements Comparable<Key> {
public final int selectHintTextSize(final KeyDrawParams params) {
if (hasHintLabel()) {
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) {
if (hasHintLabel()) {
return params.mHintLabelColor;
} else if (hasShiftedLetterHint()) {
}
if (hasShiftedLetterHint()) {
return isShiftedLetterActivated() ? params.mShiftedLetterHintActivatedColor
: params.mShiftedLetterHintInactivatedColor;
} else {
return params.mHintLetterColor;
}
return params.mHintLetterColor;
}
public final int selectMoreKeyTextSize(final KeyDrawParams params) {
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() {
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.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().
if (label != null) {
// TODO Should take care of temporaryShiftLabel here.
previewText.setCompoundDrawables(null, null, null, null);
if (StringUtils.codePointCount(label) > 1) {
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mLetterSize);
previewText.setTypeface(Typeface.DEFAULT_BOLD);
} else {
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mPreviewTextSize);
previewText.setTypeface(key.selectTypeface(drawParams));
}
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX,
key.selectPreviewTextSize(drawParams));
previewText.setTypeface(key.selectPreviewTypeface(drawParams));
previewText.setText(label);
} else {
previewText.setCompoundDrawables(null, null, null,