Skip to content

Commit 2b0ba5b

Browse files
committed
LatinIME: Support overriding the uppercase version of a key on a per-key basis
Change-Id: I6e5b4121a6b5ea2c552cf8716fe64f384a40f8f8
1 parent 175e396 commit 2b0ba5b

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

java/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@
326326
</attr>
327327
<!-- The label, icon to display on the key. And code, outputText of the key. -->
328328
<attr name="keySpec" format="string" />
329+
<!-- Overrides the uppercase format of keySpec. -->
330+
<attr name="keySpecUpper" format="string" />
329331
<!-- The hint label to display on the key in conjunction with the label. -->
330332
<attr name="keyHintLabel" format="string" />
331333
<!-- The vertical adjustment of key hint label in proportion to its height. -->

java/src/com/android/inputmethod/keyboard/Key.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ public Key(@Nullable final String keySpec, @Nonnull final TypedArray keyAttr,
340340
final int disabledIconId = KeySpecParser.getIconId(style.getString(keyAttr,
341341
R.styleable.Keyboard_Key_keyIconDisabled));
342342

343-
final int code = KeySpecParser.getCode(keySpec);
343+
final String keySpecUpper = style.getString(keyAttr, R.styleable.Keyboard_Key_keySpecUpper);
344+
final int code = KeySpecParser.getCode(
345+
(needsToUpcase && keySpecUpper != null) ? keySpecUpper : keySpec);
344346
if ((mLabelFlags & LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL) != 0) {
345347
mLabel = params.mId.mCustomActionLabel;
346348
} else if (code >= Character.MIN_SUPPLEMENTARY_CODE_POINT) {
@@ -351,7 +353,9 @@ public Key(@Nullable final String keySpec, @Nonnull final TypedArray keyAttr,
351353
} else {
352354
final String label = KeySpecParser.getLabel(keySpec);
353355
mLabel = needsToUpcase
354-
? StringUtils.toTitleCaseOfKeyLabel(label, localeForUpcasing)
356+
? keySpecUpper != null
357+
? KeySpecParser.getLabel(keySpecUpper)
358+
: StringUtils.toTitleCaseOfKeyLabel(label, localeForUpcasing)
355359
: label;
356360
}
357361
if ((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) {
@@ -365,7 +369,9 @@ public Key(@Nullable final String keySpec, @Nonnull final TypedArray keyAttr,
365369
}
366370
String outputText = KeySpecParser.getOutputText(keySpec);
367371
if (needsToUpcase) {
368-
outputText = StringUtils.toTitleCaseOfKeyLabel(outputText, localeForUpcasing);
372+
outputText = keySpecUpper != null
373+
? KeySpecParser.getOutputText(keySpecUpper)
374+
: StringUtils.toTitleCaseOfKeyLabel(outputText, localeForUpcasing);
369375
}
370376
// Choose the first letter of the label as primary code if not specified.
371377
if (code == CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
@@ -392,7 +398,9 @@ public Key(@Nullable final String keySpec, @Nonnull final TypedArray keyAttr,
392398
mCode = CODE_OUTPUT_TEXT;
393399
}
394400
} else {
395-
mCode = needsToUpcase ? StringUtils.toTitleCaseOfKeyCode(code, localeForUpcasing)
401+
// If keySpecUpper is not null, we've already upcased the code if required
402+
mCode = (needsToUpcase && keySpecUpper == null)
403+
? StringUtils.toTitleCaseOfKeyCode(code, localeForUpcasing)
396404
: code;
397405
}
398406
final int altCodeInAttr = KeySpecParser.parseCode(

0 commit comments

Comments
 (0)