From 703f9f3c7018cd5d43db2ad0245691c1c6dc89ce Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Fri, 7 Aug 2020 17:47:50 +0300 Subject: [PATCH] Squashed 'libs/utils/' changes from 40225ecccc..a28f653460 a28f653460 Merge pull request #33 from wordpress-mobile/merge/WordPress-Android/12569 6caa352edd Bumping utils version. 87167d8bbd Limit storage percentage to 100% git-subtree-dir: libs/utils git-subtree-split: a28f6534604076b152742b01d23d3c6d9b5a1d24 --- WordPressUtils/build.gradle | 2 +- .../wordpress/android/util/FormatUtils.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/WordPressUtils/build.gradle b/WordPressUtils/build.gradle index 0491f88b1e09..d182429e1547 100644 --- a/WordPressUtils/build.gradle +++ b/WordPressUtils/build.gradle @@ -53,7 +53,7 @@ android { buildToolsVersion '28.0.3' defaultConfig { - versionName "1.26" + versionName "1.27" minSdkVersion 18 targetSdkVersion 26 diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/FormatUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/FormatUtils.java index a9a3b4570e0b..c2850e58d11c 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/FormatUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/FormatUtils.java @@ -55,8 +55,25 @@ public static final String formatFileSize(long size, final String[] unitStrings) * returns the passed double percentage (0 to 1) formatted as an human readable percentage. Ex: 0.25 returns 25% */ public static final String formatPercentage(double value) { + return formatPercentageLimit100(value, false); + } + + /* + * returns the passed double percentage (0 to 1) formatted as an human readable percentage. Ex: 0.251 returns 25.1% + * if limit100 is true, it limits the percentage to 100% + */ + public static final String formatPercentageLimit100(double value, boolean limit100) { + double limit = 1.0001; + NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); - return percentFormat.format(value); + + if (limit100 && value > limit) { + value = limit; + } + + String percentage = percentFormat.format(value); + + return percentage; } }