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:
parent
eb26838afa
commit
914d054ea2
2 changed files with 38 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue