diff options
author | ByteHamster <info@bytehamster.com> | 2020-05-09 00:35:34 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-05-09 12:11:26 +0200 |
commit | 903cf94131ad51c29eb6689a825bdbbd3e401de6 (patch) | |
tree | d15e9dbe0c7a35efe449ba22995f430be99ad1c1 /core/src/main/java/de/danoeh/antennapod | |
parent | 63be7a97b82b74f2c9d57f29b208fcf3b60b00ec (diff) | |
download | AntennaPod-903cf94131ad51c29eb6689a825bdbbd3e401de6.zip |
Improved TalkBack accessibility
Diffstat (limited to 'core/src/main/java/de/danoeh/antennapod')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/Converter.java | 74 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java | 8 |
2 files changed, 51 insertions, 31 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java index 4e7e6a6b6..e1e2818cb 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java @@ -14,47 +14,57 @@ public final class Converter { /** Logging tag. */ private static final String TAG = "Converter"; - + private static final int HOURS_MIL = 3600000; - private static final int MINUTES_MIL = 60000; - private static final int SECONDS_MIL = 1000; - - /** Converts milliseconds to a string containing hours, minutes and seconds */ - public static String getDurationStringLong(int duration) { - int h = duration / HOURS_MIL; - int rest = duration - h * HOURS_MIL; - int m = rest / MINUTES_MIL; - rest -= m * MINUTES_MIL; - int s = rest / SECONDS_MIL; - - return String.format(Locale.getDefault(), "%02d:%02d:%02d", h, m, s); + private static final int MINUTES_MIL = 60000; + private static final int SECONDS_MIL = 1000; + + /** + * Converts milliseconds to a string containing hours, minutes and seconds. + */ + public static String getDurationStringLong(int duration) { + int[] hms = millisecondsToHms(duration); + return String.format(Locale.getDefault(), "%02d:%02d:%02d", hms[0], hms[1], hms[2]); } - - /** Converts milliseconds to a string containing hours and minutes or minutes and seconds*/ + + private static int[] millisecondsToHms(long duration) { + int h = (int) (duration / HOURS_MIL); + long rest = duration - h * HOURS_MIL; + int m = (int) (rest / MINUTES_MIL); + rest -= m * MINUTES_MIL; + int s = (int) (rest / SECONDS_MIL); + return new int[] {h, m, s}; + } + + /** + * Converts milliseconds to a string containing hours and minutes or minutes and seconds. + */ public static String getDurationStringShort(int duration, boolean durationIsInHours) { int firstPartBase = durationIsInHours ? HOURS_MIL : MINUTES_MIL; int firstPart = duration / firstPartBase; int leftoverFromFirstPart = duration - firstPart * firstPartBase; int secondPart = leftoverFromFirstPart / (durationIsInHours ? MINUTES_MIL : SECONDS_MIL); - return String.format(Locale.getDefault(), "%02d:%02d", firstPart, secondPart); + return String.format(Locale.getDefault(), "%02d:%02d", firstPart, secondPart); } - /** Converts long duration string (HH:MM:SS) to milliseconds. */ + /** + * Converts long duration string (HH:MM:SS) to milliseconds. + */ public static int durationStringLongToMs(String input) { String[] parts = input.split(":"); if (parts.length != 3) { return 0; } - return Integer.parseInt(parts[0]) * 3600 * 1000 + - Integer.parseInt(parts[1]) * 60 * 1000 + - Integer.parseInt(parts[2]) * 1000; + return Integer.parseInt(parts[0]) * 3600 * 1000 + + Integer.parseInt(parts[1]) * 60 * 1000 + + Integer.parseInt(parts[2]) * 1000; } /** * Converts short duration string (XX:YY) to milliseconds. If durationIsInHours is true then the * format is HH:MM, otherwise it's MM:SS. - * */ + */ public static int durationStringShortToMs(String input, boolean durationIsInHours) { String[] parts = input.split(":"); if (parts.length != 2) { @@ -63,18 +73,20 @@ public final class Converter { int modifier = durationIsInHours ? 60 : 1; - return Integer.parseInt(parts[0]) * 60 * 1000 * modifier+ - Integer.parseInt(parts[1]) * 1000 * modifier; + return Integer.parseInt(parts[0]) * 60 * 1000 * modifier + + Integer.parseInt(parts[1]) * 1000 * modifier; } - /** Converts milliseconds to a localized string containing hours and minutes */ + /** + * Converts milliseconds to a localized string containing hours and minutes. + */ public static String getDurationStringLocalized(Context context, long duration) { - int h = (int)(duration / HOURS_MIL); - int rest = (int)(duration - h * HOURS_MIL); + int h = (int) (duration / HOURS_MIL); + int rest = (int) (duration - h * HOURS_MIL); int m = rest / MINUTES_MIL; String result = ""; - if(h > 0) { + if (h > 0) { String hours = context.getResources().getQuantityString(R.plurals.time_hours_quantified, h, h); result += hours + " "; } @@ -84,7 +96,7 @@ public final class Converter { } /** - * Converts seconds to a localized representation + * Converts seconds to a localized representation. * @param time The time in seconds * @return "HH:MM hours" */ @@ -93,16 +105,16 @@ public final class Converter { return String.format(Locale.getDefault(), "%.1f ", hours) + context.getString(R.string.time_hours); } - /** * Converts the volume as read as the progress from a SeekBar scaled to 100 and as saved in * UserPreferences to the format taken by setVolume methods. * @param progress integer between 0 to 100 taken from the SeekBar progress * @return the appropriate volume as float taken by setVolume methods */ - public static float getVolumeFromPercentage(int progress){ - if (progress==100) + public static float getVolumeFromPercentage(int progress) { + if (progress == 100) { return 1f; + } return (float) (1 - (Math.log(101 - progress) / Math.log(101))); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java index 2454b6a00..e15ab2fdc 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java @@ -5,6 +5,7 @@ import android.util.Log; import org.apache.commons.lang3.StringUtils; +import java.text.DateFormat; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -175,4 +176,11 @@ public class DateUtils { } return android.text.format.DateUtils.formatDateTime(context, date.getTime(), format); } + + public static String formatForAccessibility(final Context context, final Date date) { + if (date == null) { + return ""; + } + return DateFormat.getDateInstance(DateFormat.LONG).format(date); + } } |