am 817a66e7
: Merge "Support large label text ratio in KeyboardView" into jb-dev
* commit '817a66e7e6bc9eb0bc74bacf0431308f40185cb1': Support large label text ratio in KeyboardView
This commit is contained in:
commit
db8b3a1ecf
3 changed files with 24 additions and 12 deletions
|
@ -55,6 +55,8 @@
|
||||||
<attr name="keyLargeLetterRatio" format="float" />
|
<attr name="keyLargeLetterRatio" format="float" />
|
||||||
<!-- Size of the text for keys with multiple letters, in the proportion of key height. -->
|
<!-- Size of the text for keys with multiple letters, in the proportion of key height. -->
|
||||||
<attr name="keyLabelRatio" format="float" />
|
<attr name="keyLabelRatio" format="float" />
|
||||||
|
<!-- Large size of the text for keys with multiple letters, in the proportion of key height. -->
|
||||||
|
<attr name="keyLargeLabelRatio" format="float" />
|
||||||
<!-- Size of the text for hint letter (= one character hint label), in the proportion of
|
<!-- Size of the text for hint letter (= one character hint label), in the proportion of
|
||||||
key height. -->
|
key height. -->
|
||||||
<attr name="keyHintLetterRatio" format="float" />
|
<attr name="keyHintLetterRatio" format="float" />
|
||||||
|
@ -275,7 +277,8 @@
|
||||||
<flag name="followKeyLargeLetterRatio" value="0x40" />
|
<flag name="followKeyLargeLetterRatio" value="0x40" />
|
||||||
<flag name="followKeyLetterRatio" value="0x80" />
|
<flag name="followKeyLetterRatio" value="0x80" />
|
||||||
<flag name="followKeyLabelRatio" value="0xC0" />
|
<flag name="followKeyLabelRatio" value="0xC0" />
|
||||||
<flag name="followKeyHintLabelRatio" value="0x100" />
|
<flag name="followKeyLargeLabelRatio" value="0x100" />
|
||||||
|
<flag name="followKeyHintLabelRatio" value="0x140" />
|
||||||
<flag name="hasPopupHint" value="0x200" />
|
<flag name="hasPopupHint" value="0x200" />
|
||||||
<flag name="hasShiftedLetterHint" value="0x400" />
|
<flag name="hasShiftedLetterHint" value="0x400" />
|
||||||
<flag name="hasHintLabel" value="0x800" />
|
<flag name="hasHintLabel" value="0x800" />
|
||||||
|
|
|
@ -66,11 +66,14 @@ public class Key {
|
||||||
private static final int LABEL_FLAGS_ALIGN_LEFT_OF_CENTER = 0x08;
|
private static final int LABEL_FLAGS_ALIGN_LEFT_OF_CENTER = 0x08;
|
||||||
private static final int LABEL_FLAGS_FONT_NORMAL = 0x10;
|
private static final int LABEL_FLAGS_FONT_NORMAL = 0x10;
|
||||||
private static final int LABEL_FLAGS_FONT_MONO_SPACE = 0x20;
|
private static final int LABEL_FLAGS_FONT_MONO_SPACE = 0x20;
|
||||||
private static final int LABEL_FLAGS_FOLLOW_KEY_RATIO_MASK = 0x1C0;
|
// Start of key text ratio enum values
|
||||||
|
private static final int LABEL_FLAGS_FOLLOW_KEY_TEXT_RATIO_MASK = 0x1C0;
|
||||||
private static final int LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO = 0x40;
|
private static final int LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO = 0x40;
|
||||||
private static final int LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO = 0x80;
|
private static final int LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO = 0x80;
|
||||||
private static final int LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO = 0xC0;
|
private static final int LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO = 0xC0;
|
||||||
private static final int LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO = 0x100;
|
private static final int LABEL_FLAGS_FOLLOW_KEY_LARGE_LABEL_RATIO = 0x100;
|
||||||
|
private static final int LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO = 0x140;
|
||||||
|
// End of key text ratio mask enum values
|
||||||
private static final int LABEL_FLAGS_HAS_POPUP_HINT = 0x200;
|
private static final int LABEL_FLAGS_HAS_POPUP_HINT = 0x200;
|
||||||
private static final int LABEL_FLAGS_HAS_SHIFTED_LETTER_HINT = 0x400;
|
private static final int LABEL_FLAGS_HAS_SHIFTED_LETTER_HINT = 0x400;
|
||||||
private static final int LABEL_FLAGS_HAS_HINT_LABEL = 0x800;
|
private static final int LABEL_FLAGS_HAS_HINT_LABEL = 0x800;
|
||||||
|
@ -490,18 +493,21 @@ public class Key {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int selectTextSize(int letter, int largeLetter, int label, int hintLabel) {
|
public int selectTextSize(KeyboardView.KeyDrawParams params) {
|
||||||
switch (mLabelFlags & LABEL_FLAGS_FOLLOW_KEY_RATIO_MASK) {
|
switch (mLabelFlags & LABEL_FLAGS_FOLLOW_KEY_TEXT_RATIO_MASK) {
|
||||||
case LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO:
|
case LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO:
|
||||||
return largeLetter;
|
return params.mKeyLargeLetterSize;
|
||||||
case LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO:
|
case LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO:
|
||||||
return letter;
|
return params.mKeyLetterSize;
|
||||||
case LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO:
|
case LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO:
|
||||||
return label;
|
return params.mKeyLabelSize;
|
||||||
|
case LABEL_FLAGS_FOLLOW_KEY_LARGE_LABEL_RATIO:
|
||||||
|
return params.mKeyLargeLabelSize;
|
||||||
case LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO:
|
case LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO:
|
||||||
return hintLabel;
|
return params.mKeyHintLabelSize;
|
||||||
default: // No follow key ratio flag specified.
|
default: // No follow key ratio flag specified.
|
||||||
return StringUtils.codePointCount(mLabel) == 1 ? letter : label;
|
return StringUtils.codePointCount(mLabel) == 1
|
||||||
|
? params.mKeyLetterSize : params.mKeyLabelSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
/* package */ final float mKeyLetterRatio;
|
/* package */ final float mKeyLetterRatio;
|
||||||
private final float mKeyLargeLetterRatio;
|
private final float mKeyLargeLetterRatio;
|
||||||
private final float mKeyLabelRatio;
|
private final float mKeyLabelRatio;
|
||||||
|
private final float mKeyLargeLabelRatio;
|
||||||
private final float mKeyHintLetterRatio;
|
private final float mKeyHintLetterRatio;
|
||||||
private final float mKeyShiftedLetterHintRatio;
|
private final float mKeyShiftedLetterHintRatio;
|
||||||
private final float mKeyHintLabelRatio;
|
private final float mKeyHintLabelRatio;
|
||||||
|
@ -200,6 +201,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
public int mKeyLetterSize;
|
public int mKeyLetterSize;
|
||||||
public int mKeyLargeLetterSize;
|
public int mKeyLargeLetterSize;
|
||||||
public int mKeyLabelSize;
|
public int mKeyLabelSize;
|
||||||
|
public int mKeyLargeLabelSize;
|
||||||
public int mKeyHintLetterSize;
|
public int mKeyHintLetterSize;
|
||||||
public int mKeyShiftedLetterHintSize;
|
public int mKeyShiftedLetterHintSize;
|
||||||
public int mKeyHintLabelSize;
|
public int mKeyHintLabelSize;
|
||||||
|
@ -219,6 +221,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
} else {
|
} else {
|
||||||
mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio);
|
mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio);
|
||||||
}
|
}
|
||||||
|
mKeyLargeLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLabelRatio);
|
||||||
mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio);
|
mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio);
|
||||||
mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio);
|
mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio);
|
||||||
mKeyShiftedLetterHintRatio = getRatio(a,
|
mKeyShiftedLetterHintRatio = getRatio(a,
|
||||||
|
@ -254,6 +257,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
|
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
|
||||||
if (mKeyLabelRatio >= 0.0f)
|
if (mKeyLabelRatio >= 0.0f)
|
||||||
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
|
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
|
||||||
|
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
|
||||||
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio);
|
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio);
|
||||||
mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio);
|
mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio);
|
||||||
mKeyShiftedLetterHintSize = (int)(keyHeight * mKeyShiftedLetterHintRatio);
|
mKeyShiftedLetterHintSize = (int)(keyHeight * mKeyShiftedLetterHintRatio);
|
||||||
|
@ -569,8 +573,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
final String label = key.mLabel;
|
final String label = key.mLabel;
|
||||||
// For characters, use large font. For labels like "Done", use smaller font.
|
// For characters, use large font. For labels like "Done", use smaller font.
|
||||||
paint.setTypeface(key.selectTypeface(params.mKeyTextStyle));
|
paint.setTypeface(key.selectTypeface(params.mKeyTextStyle));
|
||||||
final int labelSize = key.selectTextSize(params.mKeyLetterSize,
|
final int labelSize = key.selectTextSize(params);
|
||||||
params.mKeyLargeLetterSize, params.mKeyLabelSize, params.mKeyHintLabelSize);
|
|
||||||
paint.setTextSize(labelSize);
|
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);
|
||||||
|
|
Loading…
Reference in a new issue