summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2020-05-09 00:35:34 +0200
committerByteHamster <info@bytehamster.com>2020-05-09 12:11:26 +0200
commit903cf94131ad51c29eb6689a825bdbbd3e401de6 (patch)
treed15e9dbe0c7a35efe449ba22995f430be99ad1c1 /core/src
parent63be7a97b82b74f2c9d57f29b208fcf3b60b00ec (diff)
downloadAntennaPod-903cf94131ad51c29eb6689a825bdbbd3e401de6.zip
Improved TalkBack accessibility
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/Converter.java74
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java8
-rw-r--r--core/src/main/res/values/strings.xml5
3 files changed, 56 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);
+ }
}
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 1c2db3a5b..db49538bf 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -217,6 +217,7 @@
<string name="deactivate_auto_download">Deactivate Auto Download</string>
<string name="reset_position">Reset Playback Position</string>
<string name="removed_item">Item removed</string>
+ <string name="no_items_selected">No items selected</string>
<!-- Download messages and labels -->
<string name="download_successful">successful</string>
@@ -676,8 +677,12 @@
<string name="navigate_upwards_label">Navigate upwards</string>
<string name="status_downloading_label">Episode is being downloaded</string>
<string name="in_queue_label">Episode is in the queue</string>
+ <string name="is_favorite_label">Episode is marked as favorite</string>
<string name="drag_handle_content_description">Drag to change the position of this item</string>
<string name="load_next_page_label">Load next page</string>
+ <string name="switch_pages">Switch pages</string>
+ <string name="position">Position: %1$s</string>
+ <string name="apply_action">Apply action</string>
<!-- Feed information screen -->
<string name="authentication_label">Authentication</string>