Skip to content

Commit

Permalink
fix(android): decimal comma TextField handling
Browse files Browse the repository at this point in the history
Fixes TIMOB-28312
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Jan 19, 2021
1 parent d1079c3 commit 5bfa46a
Showing 1 changed file with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1196,15 +1196,6 @@ public CharSequence filter(CharSequence source, int start, int end, Spanned dest
// Was heavily modified to fix locale issues and to back-port it for older OS versions.
// ------------------------------------------------------------------------------------------

// First let base class attempt filter the entered text.
// We normally use this string for English locales where period is used for decimal separator.
CharSequence defaultFilteredString = super.filter(source, start, end, dest, dstart, dend);
if (defaultFilteredString != null) {
source = defaultFilteredString;
start = 0;
end = defaultFilteredString.length();
}

// Find the decimal separator and sign characters if they exist.
int signIndex = -1;
int decimalIndex = -1;
Expand All @@ -1226,6 +1217,29 @@ public CharSequence filter(CharSequence source, int start, int end, Spanned dest
}
}

// Some Android devices like Samsung/Huawei do not have localized keyboards and only have a '.' character.
// Replace it with a localized decimal separator. Unfortunately, there is no other solution.
// Note: Only do this if 1 character was received which assumes it comes from the virtual keyboard.
// If multiple characters were received, then it was probably pasted or assigned programmatically.
if ((this.localizedDecimalSeparatorChar != '.') && ((end - start) == 1) && (source.charAt(start) == '.')) {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(source, start, end);
if (decimalIndex < 0) {
stringBuilder.replace(0, 1, Character.toString(this.localizedDecimalSeparatorChar));
} else {
stringBuilder.clear();
}
return stringBuilder;
}

// Let base class attempt to filter the entered text first.
// We normally use this string for English locales where period is used for decimal separator.
CharSequence defaultFilteredString = super.filter(source, start, end, dest, dstart, dend);
if (defaultFilteredString != null) {
source = defaultFilteredString;
start = 0;
end = defaultFilteredString.length();
}

// Create a new stripped string if any invalid characters were found.
SpannableStringBuilder strippedStringBuilder = null;
for (int index = end - 1; index >= start; index--) {
Expand Down

0 comments on commit 5bfa46a

Please sign in to comment.