Skip to content

Commit

Permalink
fix: added api level 31 check
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamguptadream11 committed Aug 21, 2024
1 parent e65d05d commit c3caf4d
Showing 1 changed file with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,35 @@ public PlatformNumberFormatterICU setSignDisplay(
android.icu.text.DecimalFormat decimalFormat = (android.icu.text.DecimalFormat) mNumberFormat;
android.icu.text.DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols();

switch (signDisplay) {
case NEVER:
decimalFormat.setPositivePrefix("");
decimalFormat.setPositiveSuffix("");

decimalFormat.setNegativePrefix("");
decimalFormat.setNegativeSuffix("");

break;
case ALWAYS:
case EXCEPTZERO:
if (decimalFormat.getPositivePrefix().isEmpty()) {
decimalFormat.setPositivePrefix(new String(new char[]{symbols.getPlusSign()}));
} else {
// Preserve the existing prefix, which may include the currency symbol, and prepend the plus sign
decimalFormat.setPositivePrefix(new String(new char[]{symbols.getPlusSign()}) + decimalFormat.getPositivePrefix());
}
break;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
switch (signDisplay) {
case NEVER:
decimalFormat.setSignAlwaysShown(false);
break;
case ALWAYS:
case EXCEPTZERO:
decimalFormat.setSignAlwaysShown(true);
break;
}
} else {
switch (signDisplay) {
case NEVER:
decimalFormat.setPositivePrefix("");
decimalFormat.setPositiveSuffix("");

decimalFormat.setNegativePrefix("");
decimalFormat.setNegativeSuffix("");

break;
case ALWAYS:
case EXCEPTZERO:
if (!decimalFormat.getNegativePrefix().isEmpty())
decimalFormat.setPositivePrefix(new String(new char[] {symbols.getPlusSign()}));

if (!decimalFormat.getNegativeSuffix().isEmpty())
decimalFormat.setPositiveSuffix(new String(new char[] {symbols.getPlusSign()}));
break;
}
}
}

Expand Down

0 comments on commit c3caf4d

Please sign in to comment.