From 1772edd374662e7b33699da509aee092ba428452 Mon Sep 17 00:00:00 2001 From: "Igor B. Poretsky" Date: Thu, 3 Apr 2014 06:12:20 +0400 Subject: [PATCH] Better accessibility feedback in the route description screen. Distance information is not duplicated by the accessibility feedback. Added particular items for arrival points. Fully qualified time format is used in accessibility mode since it is treated by speech synthesizers more correctly. --- .../src/net/osmand/util/Algorithms.java | 4 +-- .../net/osmand/plus/GpxSelectionHelper.java | 6 ++-- .../activities/ShowRouteInfoActivity.java | 28 +++++++++++++------ .../AudioVideoNoteMenuController.java | 7 +++-- .../AudioVideoNoteRecordingMenu.java | 4 +-- .../audionotes/AudioVideoNotesPlugin.java | 6 ++-- .../net/osmand/plus/helpers/GpxUiHelper.java | 6 ++-- .../builders/GpxItemMenuBuilder.java | 2 +- .../plus/myplaces/AvailableGPXFragment.java | 4 +-- .../plus/osmo/SettingsOsMoActivity.java | 2 +- .../osmand/plus/routing/RoutingHelper.java | 2 +- 11 files changed, 41 insertions(+), 30 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index 0a73250337..9ce93b9aea 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -514,7 +514,7 @@ public class Algorithms { } - public static String formatDuration(int seconds) { + public static String formatDuration(int seconds, boolean fullForm) { String sec; if (seconds % 60 < 10) { sec = "0" + (seconds % 60); @@ -522,7 +522,7 @@ public class Algorithms { sec = (seconds % 60) + ""; } int minutes = seconds / 60; - if (minutes < 60) { + if ((!fullForm) && (minutes < 60)) { return minutes + ":" + sec; } else { String min; diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 1f557455a2..e5b91cedbc 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -227,7 +227,7 @@ public class GpxSelectionHelper { } if (name.length() != 0) name += ", "; - name += GpxUiHelper.getColorValue(timeSpanClr, Algorithms.formatDuration((int) (tm / 1000))); + name += GpxUiHelper.getColorValue(timeSpanClr, Algorithms.formatDuration((int) (tm / 1000), app.accessibilityEnabled())); } if (analysis.isSpeedSpecified()) { if (name.length() != 0) @@ -265,7 +265,7 @@ public class GpxSelectionHelper { private static String formatSecondarySplitName(double metricEnd, GpxDisplayGroup group, OsmandApplication app) { if (group.isSplitDistance()) { - return Algorithms.formatDuration((int) metricEnd); + return Algorithms.formatDuration((int) metricEnd, app.accessibilityEnabled()); } else { return OsmAndFormatter.getFormattedDistance((float) metricEnd, app); } @@ -290,7 +290,7 @@ public class GpxSelectionHelper { return OsmAndFormatter.getFormattedDistance((float) metricEnd, app); } } else { - return Algorithms.formatDuration((int) metricEnd); + return Algorithms.formatDuration((int) metricEnd, app.accessibilityEnabled()); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java index e7b5a0e263..7f4f053306 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java @@ -165,8 +165,11 @@ public class ShowRouteInfoActivity extends OsmandListActivity { } } + private final int lastItemIndex; + RouteInfoAdapter(List list) { super(ShowRouteInfoActivity.this, R.layout.route_info_list_item, list); + lastItemIndex = list.size() - 1; this.setNotifyOnChange(false); } @@ -190,14 +193,24 @@ public class ShowRouteInfoActivity extends OsmandListActivity { drawable.setRouteType(model.getTurnType()); icon.setImageDrawable(drawable); - distanceLabel.setText(OsmAndFormatter.getFormattedDistance( - model.distance, getMyApplication())); - timeLabel.setText(getTimeDescription(model)); label.setText(model.getDescriptionRoutePart()); + if (model.distance > 0) { + distanceLabel.setText(OsmAndFormatter.getFormattedDistance( + model.distance, getMyApplication())); + timeLabel.setText(getTimeDescription(model)); + row.setContentDescription(label.getText() + " " + timeLabel.getText()); //$NON-NLS-1$ + } else { + if (label.getText().length() == 0) { + label.setText(getString((position != lastItemIndex) ? R.string.arrived_at_intermediate_point : R.string.arrived_at_destination)); + } + distanceLabel.setText(""); //$NON-NLS-1$ + timeLabel.setText(""); //$NON-NLS-1$ + row.setContentDescription(""); //$NON-NLS-1$ + } CumulativeInfo cumulativeInfo = getRouteDirectionCumulativeInfo(position); cumulativeDistanceLabel.setText(OsmAndFormatter.getFormattedDistance( cumulativeInfo.distance, getMyApplication())); - cumulativeTimeLabel.setText(Algorithms.formatDuration(cumulativeInfo.time)); + cumulativeTimeLabel.setText(Algorithms.formatDuration(cumulativeInfo.time, getMyApplication().accessibilityEnabled())); return row; } @@ -214,7 +227,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity { private String getTimeDescription(RouteDirectionInfo model) { final int timeInSeconds = model.getExpectedTime(); - return Algorithms.formatDuration(timeInSeconds); + return Algorithms.formatDuration(timeInSeconds, getMyApplication().accessibilityEnabled()); } void print() { @@ -296,10 +309,10 @@ public class ShowRouteInfoActivity extends OsmandListActivity { cumulativeInfo.distance + routeDirectionInfo.distance, getMyApplication())); sb.append(BR); - sb.append(Algorithms.formatDuration(cumulativeInfo.time)); + sb.append(Algorithms.formatDuration(cumulativeInfo.time, getMyApplication().accessibilityEnabled())); sb.append(" - "); sb.append(Algorithms.formatDuration(cumulativeInfo.time - + routeDirectionInfo.getExpectedTime())); + + routeDirectionInfo.getExpectedTime(), getMyApplication().accessibilityEnabled())); String cumulativeTimeAndDistance = sb.toString().replaceAll("\\s", NBSP); html.append(cumulativeTimeAndDistance); html.append(""); @@ -331,4 +344,3 @@ public class ShowRouteInfoActivity extends OsmandListActivity { } } - diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java index 05028c0371..0729070567 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java @@ -114,6 +114,7 @@ public class AudioVideoNoteMenuController extends MenuController { @Override public void updateData() { + boolean accessibilityEnabled = getMapActivity().getMyApplication().accessibilityEnabled(); rightTitleButtonController.visible = true; if (!recording.isPhoto()) { if (plugin.isPlaying(recording)) { @@ -122,9 +123,9 @@ public class AudioVideoNoteMenuController extends MenuController { int pos = plugin.getPlayingPosition(); String durationStr; if (pos == -1) { - durationStr = recording.getPlainDuration(); + durationStr = recording.getPlainDuration(accessibilityEnabled); } else { - durationStr = Algorithms.formatDuration(pos / 1000); + durationStr = Algorithms.formatDuration(pos / 1000, accessibilityEnabled); } leftTitleButtonController.needRightText = true; leftTitleButtonController.rightTextCaption = "— " + durationStr; @@ -132,7 +133,7 @@ public class AudioVideoNoteMenuController extends MenuController { } else { leftTitleButtonController.caption = getMapActivity().getString(R.string.recording_context_menu_play); leftTitleButtonController.leftIconId = R.drawable.ic_play_dark; - String durationStr = recording.getPlainDuration(); + String durationStr = recording.getPlainDuration(accessibilityEnabled); leftTitleButtonController.needRightText = true; leftTitleButtonController.rightTextCaption = "— " + durationStr; } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenu.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenu.java index b6ef3e258d..6fa8af8e48 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenu.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenu.java @@ -196,7 +196,7 @@ public class AudioVideoNoteRecordingMenu { if (plugin.getCurrentRecording() != null) { TextView timeText = (TextView) view.findViewById(R.id.timeText); int duration = (int) ((System.currentTimeMillis() - startTime) / 1000); - timeText.setText(Algorithms.formatDuration(duration)); + timeText.setText(Algorithms.formatDuration(duration, getMapActivity().getMyApplication().accessibilityEnabled())); } } @@ -332,4 +332,4 @@ public class AudioVideoNoteRecordingMenu { public void hideFinalPhoto() { } -} \ No newline at end of file +} diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index e7b7c51011..8641db9ba2 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -441,11 +441,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } - public String getPlainDuration() { + public String getPlainDuration(boolean accessibilityEnabled) { updateInternalDescription(); if (duration > 0) { int d = (int) (duration / 1000); - return Algorithms.formatDuration(d); + return Algorithms.formatDuration(d, accessibilityEnabled); } else { return ""; } @@ -455,7 +455,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { String additional = ""; if (duration > 0) { int d = (int) (duration / 1000); - additional += "(" + Algorithms.formatDuration(d) + ")"; + additional += "(" + Algorithms.formatDuration(d, ((OsmandApplication)ctx.getApplicationContext()).accessibilityEnabled()) + ")"; } if (!available) { additional += "[" + ctx.getString(R.string.recording_unavailable) + "]"; diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 1f8df017ab..b56cd795a9 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -93,16 +93,14 @@ public class GpxUiHelper { // 2. Time span if (analysis.timeSpan > 0 && analysis.timeSpan / 1000 != analysis.timeMoving / 1000) { - final String formatDuration = Algorithms.formatDuration((int) (analysis.timeSpan / 1000) - ); + final String formatDuration = Algorithms.formatDuration((int) (analysis.timeSpan / 1000), app.accessibilityEnabled()); description.append(nl).append(app.getString(R.string.gpx_timespan, getColorValue(timeSpanClr, formatDuration, html))); } // 3. Time moving, if any if (analysis.isTimeMoving()) { - final String formatDuration = Algorithms.formatDuration((int) (analysis.timeMoving / 1000) - ); + final String formatDuration = Algorithms.formatDuration((int) (analysis.timeMoving / 1000), app.accessibilityEnabled()); description.append(nl).append(app.getString(R.string.gpx_timemoving, getColorValue(timeSpanClr, formatDuration, html))); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java index d9d567df94..bec6206b23 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java @@ -56,7 +56,7 @@ public class GpxItemMenuBuilder extends MenuBuilder { buildTextView(ll, gpxSmallTextMargin, gpxTextSize, textColor, OsmAndFormatter.getFormattedDistance(item.analysis.totalDistance, app)); buildIcon(ll, gpxSmallIconMargin, R.drawable.ic_small_time); - buildTextView(ll, gpxSmallTextMargin, gpxTextSize, textColor, Algorithms.formatDuration((int) (item.analysis.timeSpan / 1000)) + ""); + buildTextView(ll, gpxSmallTextMargin, gpxTextSize, textColor, Algorithms.formatDuration((int) (item.analysis.timeSpan / 1000), app.accessibilityEnabled()) + ""); } private void buildIcon(LinearLayout ll, int gpxSmallIconMargin, int iconId) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 544b847152..a1176864be 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -1350,7 +1350,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { // if (analysis.isTimeMoving()) { // time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + ""); // } else { - time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000)) + ""); + time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000), app.accessibilityEnabled()) + ""); // } } else { time.setText(""); @@ -1362,4 +1362,4 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { v.findViewById(R.id.toggle_item).setVisibility(View.GONE); } -} \ No newline at end of file +} diff --git a/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java b/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java index fb6f58d0f1..5fde2f08ed 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java @@ -86,7 +86,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity { StringBuilder s = new StringBuilder(); if(service.isConnected()) { int seconds = (int) ((System.currentTimeMillis() - service.getConnectionTime()) / 1000); - s.append(getString(R.string.osmo_conn_successfull, Algorithms.formatDuration(seconds))).append("\n"); + s.append(getString(R.string.osmo_conn_successfull, Algorithms.formatDuration(seconds, getMyApplication().accessibilityEnabled()))).append("\n"); SessionInfo si = service.getCurrentSessionInfo(); if(si == null) { s.append(getString(R.string.osmo_auth_pending)).append("\n"); diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 212ca56b17..dfa8c83bd3 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -657,7 +657,7 @@ public class RoutingHelper { String msg = app.getString(R.string.new_route_calculated_dist) + ": " + OsmAndFormatter.getFormattedDistance(res.getWholeDistance(), app); if (OsmandPlugin.isDevelopment() && res.getRoutingTime() != 0f) { - msg += " (" + Algorithms.formatDuration((int) res.getRoutingTime()) + ")"; + msg += " (" + Algorithms.formatDuration((int) res.getRoutingTime(), app.accessibilityEnabled()) + ")"; } app.showToastMessage(msg); }