From 3d925646f8790266369461b2f0f738b969287a31 Mon Sep 17 00:00:00 2001 From: cepprice Date: Thu, 14 Jan 2021 18:11:02 +0500 Subject: [PATCH 1/3] Update UI of announcement time --- .../seekbar_progress_announcement_time.xml | 19 ++ .../seekbar_thumb_announcement_time.xml | 12 + .../seekbar_tickmark_announcement_time.xml | 8 + .../layout/bottom_sheet_announcement_time.xml | 140 ++++++++++++ OsmAnd/res/values/strings.xml | 12 +- .../routing/data/AnnounceTimeDistances.java | 157 +++++++++---- .../AnnouncementTimeBottomSheet.java | 209 ++++++++++++++++++ .../fragments/VoiceAnnouncesFragment.java | 34 ++- 8 files changed, 538 insertions(+), 53 deletions(-) create mode 100644 OsmAnd/res/drawable/seekbar_progress_announcement_time.xml create mode 100644 OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml create mode 100644 OsmAnd/res/drawable/seekbar_tickmark_announcement_time.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_announcement_time.xml create mode 100644 OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java diff --git a/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml b/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml new file mode 100644 index 0000000000..84e6587248 --- /dev/null +++ b/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml b/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml new file mode 100644 index 0000000000..718b10c081 --- /dev/null +++ b/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/seekbar_tickmark_announcement_time.xml b/OsmAnd/res/drawable/seekbar_tickmark_announcement_time.xml new file mode 100644 index 0000000000..d6662da81f --- /dev/null +++ b/OsmAnd/res/drawable/seekbar_tickmark_announcement_time.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_announcement_time.xml b/OsmAnd/res/layout/bottom_sheet_announcement_time.xml new file mode 100644 index 0000000000..630decba92 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_announcement_time.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index c499d54b5c..943aa25210 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,7 +11,17 @@ Thx - Hardy --> - + Announcement time + Announcement time of different voice prompts depends on prompt type, current navigation speed and default navigation speed. + Time and distance intervals + Turn + Arrive at destination + Off route + Prepare + Long Prepare + Approach + Passing + sec Empty Select folder or add new one Select folder diff --git a/OsmAnd/src/net/osmand/plus/routing/data/AnnounceTimeDistances.java b/OsmAnd/src/net/osmand/plus/routing/data/AnnounceTimeDistances.java index 497f237158..f8b71b677b 100644 --- a/OsmAnd/src/net/osmand/plus/routing/data/AnnounceTimeDistances.java +++ b/OsmAnd/src/net/osmand/plus/routing/data/AnnounceTimeDistances.java @@ -1,7 +1,13 @@ package net.osmand.plus.routing.data; +import android.graphics.Typeface; +import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.style.StyleSpan; + import net.osmand.Location; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.voice.AbstractPrologCommandPlayer; @@ -42,6 +48,10 @@ public class AnnounceTimeDistances { private int LONG_ALARM_ANNOUNCE_RADIUS; private int SHORT_ALARM_ANNOUNCE_RADIUS; + private String format; + private String meter; + private String second; + public AnnounceTimeDistances(ApplicationMode appMode, OsmandSettings settings) { if (appMode.isDerivedRoutingFrom(ApplicationMode.CAR)) { // keep it as minimum 30 km/h for voice announcement @@ -51,6 +61,7 @@ public class AnnounceTimeDistances { DEFAULT_SPEED = (float) Math.max(0.3, appMode.getDefaultSpeed()); } + // 300 s: car 3750 m (113 s @ 120 km/h) PREPARE_LONG_DISTANCE = (int) (DEFAULT_SPEED * 300); // 250 s: car 3125 m (94 s @ 120 km/h) @@ -79,28 +90,7 @@ public class AnnounceTimeDistances { } float ARRIVAL_DISTANCE_FACTOR = Math.max(settings.ARRIVAL_DISTANCE_FACTOR.getModeValue(appMode), 0.1f); - - // Turn now: 3.5 s normal speed, 7 s for half speed (default) - // float TURN_NOW_TIME = 7; - // ** #8749 to keep 1m / 1 sec precision (POSITIONING_TOLERANCE = 12 m) - // car 50 km/h - 7 s, bicycle 10 km/h - 3 s, pedestrian 4 km/h - 2 s, 1 km/h - 1 s - float TURN_NOW_TIME = (float) Math.min(Math.sqrt(DEFAULT_SPEED * 3.6), 8); - - // 3.6 s: car 45 m, bicycle 10 m -> 12 m, pedestrian 4 m -> 12 m (capped by POSITIONING_TOLERANCE) - TURN_NOW_DISTANCE = (int) (Math.max(POSITIONING_TOLERANCE, DEFAULT_SPEED * 3.6) * ARRIVAL_DISTANCE_FACTOR); - TURN_NOW_SPEED = TURN_NOW_DISTANCE / TURN_NOW_TIME; - - // 5 s: car 63 m, bicycle 14 m, pedestrian 6 m -> 12 m (capped by POSITIONING_TOLERANCE) - ARRIVAL_DISTANCE = (int) (Math.max(POSITIONING_TOLERANCE, DEFAULT_SPEED * 5.) * ARRIVAL_DISTANCE_FACTOR); - - // 20 s: car 250 m, bicycle 56 m, pedestrian 22 m - OFF_ROUTE_DISTANCE = DEFAULT_SPEED * 20 * ARRIVAL_DISTANCE_FACTOR; // 20 seconds - - // assume for backward compatibility speed - 10 m/s - SHORT_ALARM_ANNOUNCE_RADIUS = (int) (7 * DEFAULT_SPEED * ARRIVAL_DISTANCE_FACTOR); // 70 m - LONG_ALARM_ANNOUNCE_RADIUS = (int) (12 * DEFAULT_SPEED * ARRIVAL_DISTANCE_FACTOR); // 120 m - SHORT_PNT_ANNOUNCE_RADIUS = (int) (15 * DEFAULT_SPEED * ARRIVAL_DISTANCE_FACTOR); // 150 m - LONG_PNT_ANNOUNCE_RADIUS = (int) (60 * DEFAULT_SPEED * ARRIVAL_DISTANCE_FACTOR); // 600 m + setArrivalDistances(ARRIVAL_DISTANCE_FACTOR); // Trigger close prompts earlier to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types int ams = settings.AUDIO_MANAGER_STREAM.getModeValue(appMode); @@ -111,6 +101,31 @@ public class AnnounceTimeDistances { } } + public void setArrivalDistances(float arrivalDistanceFactor) { + arrivalDistanceFactor = Math.max(arrivalDistanceFactor, 0.1f); + // Turn now: 3.5 s normal speed, 7 s for half speed (default) + // float TURN_NOW_TIME = 7; + // ** #8749 to keep 1m / 1 sec precision (POSITIONING_TOLERANCE = 12 m) + // car 50 km/h - 7 s, bicycle 10 km/h - 3 s, pedestrian 4 km/h - 2 s, 1 km/h - 1 s + float TURN_NOW_TIME = (float) Math.min(Math.sqrt(DEFAULT_SPEED * 3.6), 8); + + // 3.6 s: car 45 m, bicycle 10 m -> 12 m, pedestrian 4 m -> 12 m (capped by POSITIONING_TOLERANCE) + TURN_NOW_DISTANCE = (int) (Math.max(POSITIONING_TOLERANCE, DEFAULT_SPEED * 3.6) * arrivalDistanceFactor); + TURN_NOW_SPEED = TURN_NOW_DISTANCE / TURN_NOW_TIME; + + // 5 s: car 63 m, bicycle 14 m, pedestrian 6 m -> 12 m (capped by POSITIONING_TOLERANCE) + ARRIVAL_DISTANCE = (int) (Math.max(POSITIONING_TOLERANCE, DEFAULT_SPEED * 5.) * arrivalDistanceFactor); + + // 20 s: car 250 m, bicycle 56 m, pedestrian 22 m + OFF_ROUTE_DISTANCE = DEFAULT_SPEED * 20 * arrivalDistanceFactor; // 20 seconds + + // assume for backward compatibility speed - 10 m/s + SHORT_ALARM_ANNOUNCE_RADIUS = (int) (7 * DEFAULT_SPEED * arrivalDistanceFactor); // 70 m + LONG_ALARM_ANNOUNCE_RADIUS = (int) (12 * DEFAULT_SPEED * arrivalDistanceFactor); // 120 m + SHORT_PNT_ANNOUNCE_RADIUS = (int) (15 * DEFAULT_SPEED * arrivalDistanceFactor); // 150 m + LONG_PNT_ANNOUNCE_RADIUS = (int) (60 * DEFAULT_SPEED * arrivalDistanceFactor); // 600 m + } + public int getImminentTurnStatus(float dist, Location loc) { float speed = getSpeed(loc); if (isTurnStateActive(speed, dist, STATE_TURN_NOW)) { @@ -199,38 +214,90 @@ public class AnnounceTimeDistances { return (int) (dist - voicePromptDelayTimeSec * speed); } - private void appendTurnDesc(StringBuilder s, String name, int dist) { - appendTurnDesc(s, name, dist, DEFAULT_SPEED); + public Spannable getIntervalsDescription(OsmandApplication app) { + format = "\n%s: %d - %d %s, %d %s."; + meter = app.getString(R.string.m); + second = app.getString(R.string.shared_string_sec); + + String turn = app.getString(R.string.announcement_time_turn); + String arrive = app.getString(R.string.announcement_time_arrive); + String offRoute = app.getString(R.string.announcement_time_off_route); + String traffic = "\n" + app.getString(R.string.way_alarms); + String point = "\n" + String.format( + "%s / %s / %s", app.getString(R.string.shared_string_waypoint), + app.getString(R.string.favorite), app.getString(R.string.poi) + ); + + String prepare = " • " + app.getString(R.string.announcement_time_prepare); + String longPrepare = " • " + app.getString(R.string.announcement_time_prepare_long); + String approach = " • " + app.getString(R.string.announcement_time_approach); + String passing = " • " + app.getString(R.string.announcement_time_passing); + + SpannableStringBuilder builder = new SpannableStringBuilder(); + + // Turn + builder.append(turn); + makeBold(builder, turn); + if (PREPARE_DISTANCE_END <= PREPARE_DISTANCE) { + appendDescr(builder, prepare, PREPARE_DISTANCE);; + } + if (PREPARE_LONG_DISTANCE_END <= PREPARE_LONG_DISTANCE) { + appendDescr(builder, longPrepare, PREPARE_LONG_DISTANCE); + } + appendDescr(builder, approach, TURN_IN_DISTANCE); + appendDescr(builder, passing, TURN_NOW_DISTANCE, TURN_NOW_SPEED); + + // Arrive at destination + appendDescr(builder, arrive, (int) (getArrivalDistance())); + makeBoldFormatted(builder, arrive); + + // Off-route + if (getOffRouteDistance() > 0) { + appendDescr(builder, offRoute, (int) getOffRouteDistance()); + makeBoldFormatted(builder, offRoute); + } + + // Traffic warnings + builder.append(traffic); + makeBold(builder, traffic); + appendDescr(builder, approach, LONG_ALARM_ANNOUNCE_RADIUS); + appendDescr(builder, passing, SHORT_ALARM_ANNOUNCE_RADIUS); + + // Waypoint / Favorite / POI + builder.append(point); + makeBold(builder, point); + appendDescr(builder, approach, LONG_PNT_ANNOUNCE_RADIUS); + appendDescr(builder, passing, SHORT_PNT_ANNOUNCE_RADIUS); + + return builder; } - private void appendTurnDesc(StringBuilder s, String name, int dist, float speed) { + private void appendDescr(SpannableStringBuilder b, String word, int dist) { + appendDescr(b, word, dist, DEFAULT_SPEED); + } + + private void appendDescr(SpannableStringBuilder b, String word, int dist, float speed) { int minDist = (dist / 5) * 5; int time = (int) (dist / speed); if(time > 15) { // round to 5 time = (time / 5) * 5; } - s.append(String.format("%s: %d - %d m, %d sec\n", name, minDist, minDist + 5, time)); + b.append(String.format(format, word, minDist, minDist + 5, meter, time, second)); } - public String getTurnsDescription() { - StringBuilder turnDescriptions = new StringBuilder(); - appendTurnDesc(turnDescriptions, "Turn (now)", TURN_NOW_DISTANCE, TURN_NOW_SPEED); - appendTurnDesc(turnDescriptions, "Turn (approach)", TURN_IN_DISTANCE); - if (PREPARE_DISTANCE_END <= PREPARE_DISTANCE) { - appendTurnDesc(turnDescriptions, "Turn (prepare)", PREPARE_DISTANCE); - } - if (PREPARE_LONG_DISTANCE_END <= PREPARE_LONG_DISTANCE) { - appendTurnDesc(turnDescriptions, "Turn (early prepare)", PREPARE_LONG_DISTANCE); - } - appendTurnDesc(turnDescriptions, "Arrival", (int) getArrivalDistance()); - if (getOffRouteDistance() > 0) { - appendTurnDesc(turnDescriptions, "Off-route", (int) getOffRouteDistance()); - } - appendTurnDesc(turnDescriptions, "Alarm (close)", SHORT_ALARM_ANNOUNCE_RADIUS); - appendTurnDesc(turnDescriptions, "Alarm (standard)", LONG_ALARM_ANNOUNCE_RADIUS); - appendTurnDesc(turnDescriptions, "Waypoint / fav / POI (passing)", SHORT_PNT_ANNOUNCE_RADIUS); - appendTurnDesc(turnDescriptions, "Waypoint / fav / POI (approaching)", LONG_PNT_ANNOUNCE_RADIUS); - return turnDescriptions.toString(); + private void makeBold(SpannableStringBuilder b, String word) { + int end = b.length(); + int start = end - word.length(); + b.setSpan(new StyleSpan(Typeface.BOLD), start, end, + SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE); } + + private void makeBoldFormatted(SpannableStringBuilder b, String word) { + int start = b.toString().indexOf(word); + int end = start + word.length() + 1; + b.setSpan(new StyleSpan(Typeface.BOLD), start, end, + SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE); + } + } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java new file mode 100644 index 0000000000..d7261a2368 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java @@ -0,0 +1,209 @@ +package net.osmand.plus.settings.bottomsheets; + +import android.os.Bundle; +import android.view.View; +import android.widget.ImageView; +import android.widget.SeekBar; + +import net.osmand.PlatformUtil; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.routing.data.AnnounceTimeDistances; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.fragments.OnPreferenceChanged; +import net.osmand.plus.settings.preferences.ListPreferenceEx; +import net.osmand.plus.widgets.TextViewEx; + +import org.apache.commons.logging.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + + +public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet + implements SeekBar.OnSeekBarChangeListener { + + public static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key"; + public static final String TAG = AnnouncementTimeBottomSheet.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(AnnouncementTimeBottomSheet.class); + + private OsmandApplication app; + + private AnnounceTimeDistances announceTimeDistances; + + private ListPreferenceEx listPreference; + private int selectedEntryIndex = -1; + + private View rootView; + private TextViewEx tvSeekBarLabel; + private SeekBar seekBarArrival; + private ImageView ivArrow; + private TextViewEx tvIntervalsDescr; + + private boolean collapsed = false; + + @Override + public void createMenuItems(Bundle savedInstanceState) { + app = getMyApplication(); + if (app == null) { + return; + } + + announceTimeDistances = new AnnounceTimeDistances(getAppMode(), app.getSettings()); + + listPreference = getListPreference(); + + if (listPreference == null || listPreference.getEntries() == null || + listPreference.getEntryValues() == null) { + return; + } + + if (savedInstanceState != null) { + selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY); + } else { + selectedEntryIndex = listPreference.findIndexOfValue(listPreference.getValue()); + } + + items.add(createBottomSheetItem()); + } + + @Override + public void onResume() { + super.onResume(); + updateViews(); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(SELECTED_ENTRY_INDEX_KEY, selectedEntryIndex); + } + + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_cancel; + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_apply; + } + + @Override + protected void onRightBottomButtonClick() { + Object[] entryValues = listPreference.getEntryValues(); + if (entryValues != null && selectedEntryIndex >= 0) { + Object value = entryValues[selectedEntryIndex]; + if (listPreference.callChangeListener(value)) { + listPreference.setValue(value); + } + Fragment target = getTargetFragment(); + if (target instanceof OnPreferenceChanged) { + ((OnPreferenceChanged) target).onPreferenceChanged(listPreference.getKey()); + } + } + + dismiss(); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (progress != selectedEntryIndex) { + selectedEntryIndex = progress; + updateViews(); + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + + private ListPreferenceEx getListPreference() { + return (ListPreferenceEx) getPreference(); + } + + private BaseBottomSheetItem createBottomSheetItem() { + rootView = UiUtilities.getInflater(getContext(), nightMode) + .inflate(R.layout.bottom_sheet_announcement_time, null); + + tvSeekBarLabel = rootView.findViewById(R.id.tv_seek_bar_label); + seekBarArrival = rootView.findViewById(R.id.seek_bar_arrival); + ivArrow = rootView.findViewById(R.id.iv_arrow); + tvIntervalsDescr = rootView.findViewById(R.id.tv_interval_descr); + + seekBarArrival.setOnSeekBarChangeListener(this); + ivArrow.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + toggleViews(); + } + }); + + setupIvIllustration(); + setDividerColor(); + + return new BaseBottomSheetItem.Builder() + .setCustomView(rootView) + .create(); + } + + private void setupIvIllustration() { + int drawableId = nightMode ? R.drawable.img_help_announcement_time_night + : R.drawable.img_help_announcement_time_day; + + ImageView ivIllustration = rootView.findViewById(R.id.iv_illustration); + ivIllustration.setImageResource(drawableId); + } + + private void setDividerColor() { + int colorId = nightMode ? R.color.divider_color_dark : R.color.divider_color_light; + View divider = rootView.findViewById(R.id.divider); + divider.setBackgroundColor(getResources().getColor(colorId)); + } + + private void updateViews() { + seekBarArrival.setProgress(selectedEntryIndex); + tvSeekBarLabel.setText(listPreference.getEntries()[selectedEntryIndex]); + + float value = (float) listPreference.getEntryValues()[selectedEntryIndex]; + announceTimeDistances.setArrivalDistances(value); + tvIntervalsDescr.setText(announceTimeDistances.getIntervalsDescription(app)); + } + + private void toggleViews() { + int drawableId = collapsed ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up; + collapsed = !collapsed; + ivArrow.setImageResource(drawableId); + + if (tvIntervalsDescr.getVisibility() == View.VISIBLE) { + tvIntervalsDescr.setVisibility(View.GONE); + } else { + tvIntervalsDescr.setVisibility(View.VISIBLE); + } + } + + public static void showInstance(@NonNull FragmentManager fm, String prefKey, Fragment target, + @Nullable ApplicationMode appMode) { + try { + if (!fm.isStateSaved()) { + Bundle args = new Bundle(); + args.putString(PREFERENCE_ID, prefKey); + AnnouncementTimeBottomSheet fragment = new AnnouncementTimeBottomSheet(); + fragment.setArguments(args); + fragment.setAppMode(appMode); + fragment.setTargetFragment(target, 0); + fragment.show(fm, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java index 83cc191a02..18d5d0b713 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java @@ -12,6 +12,7 @@ import android.widget.TextView; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; +import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import androidx.preference.SwitchPreferenceCompat; @@ -30,6 +31,7 @@ import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.routing.data.AnnounceTimeDistances; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.bottomsheets.AnnouncementTimeBottomSheet; import net.osmand.plus.settings.preferences.ListPreferenceEx; import java.util.Set; @@ -42,8 +44,25 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr public static final String TAG = VoiceAnnouncesFragment.class.getSimpleName(); private static final String MORE_VALUE = "MORE_VALUE"; + private static final String ARRIVAL_DISTANCE_FACTOR = "arrival_distance_factor"; private static final String VOICE_PROMPTS_TIMETABLE = "voice_prompts_timetable"; + @Override + public void onDisplayPreferenceDialog(Preference preference) { + String prefId = preference.getKey(); + + if (prefId.equals(ARRIVAL_DISTANCE_FACTOR)) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + AnnouncementTimeBottomSheet.showInstance( + fragmentManager, preference.getKey(), this, getSelectedAppMode() + ); + } + } else { + super.onDisplayPreferenceDialog(preference); + } + } + @Override protected void createToolbar(LayoutInflater inflater, View view) { super.createToolbar(inflater, view); @@ -110,13 +129,14 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr private void updateVoicePromptsTimes() { Preference pref = findPreference(VOICE_PROMPTS_TIMETABLE); - if (OsmandPlugin.isDevelopment()) { - AnnounceTimeDistances atd = new AnnounceTimeDistances(getSelectedAppMode(), settings); - pref.setSummary(atd.getTurnsDescription().trim()); - pref.setVisible(true); - } else { - pref.setVisible(false); - } +// if (OsmandPlugin.isDevelopment()) { +// AnnounceTimeDistances atd = new AnnounceTimeDistances(getSelectedAppMode(), settings); +// pref.setSummary(atd.getTurnsDescription().trim()); +// pref.setVisible(true); +// } else { +// pref.setVisible(false); +// } + pref.setVisible(false); } private void setupSpeedLimitExceedPref() { From 7a279eae76785bc83bd94a613f57c02b3b9a173f Mon Sep 17 00:00:00 2001 From: cepprice Date: Thu, 14 Jan 2021 19:06:03 +0500 Subject: [PATCH 2/3] Remove unneeded code --- OsmAnd/res/xml/voice_announces.xml | 6 ------ .../fragments/VoiceAnnouncesFragment.java | 21 ------------------- 2 files changed, 27 deletions(-) diff --git a/OsmAnd/res/xml/voice_announces.xml b/OsmAnd/res/xml/voice_announces.xml index 154574399c..df7d47b8c3 100644 --- a/OsmAnd/res/xml/voice_announces.xml +++ b/OsmAnd/res/xml/voice_announces.xml @@ -91,12 +91,6 @@ android:layout="@layout/preference_with_descr" android:title="@string/arrival_distance" /> - - diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java index 18d5d0b713..c72c946313 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java @@ -18,7 +18,6 @@ import androidx.preference.PreferenceViewHolder; import androidx.preference.SwitchPreferenceCompat; import net.osmand.AndroidUtils; -import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; @@ -28,7 +27,6 @@ import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.enums.MetricsConstants; -import net.osmand.plus.routing.data.AnnounceTimeDistances; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.bottomsheets.AnnouncementTimeBottomSheet; @@ -45,7 +43,6 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr private static final String MORE_VALUE = "MORE_VALUE"; private static final String ARRIVAL_DISTANCE_FACTOR = "arrival_distance_factor"; - private static final String VOICE_PROMPTS_TIMETABLE = "voice_prompts_timetable"; @Override public void onDisplayPreferenceDialog(Preference preference) { @@ -115,7 +112,6 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr setupKeepInformingPref(); setupArrivalAnnouncementPref(); - updateVoicePromptsTimes(); setupVoiceProviderPref(); if (!Version.isBlackberry(app)) { @@ -127,18 +123,6 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr setupSpeedCamerasAlert(); } - private void updateVoicePromptsTimes() { - Preference pref = findPreference(VOICE_PROMPTS_TIMETABLE); -// if (OsmandPlugin.isDevelopment()) { -// AnnounceTimeDistances atd = new AnnounceTimeDistances(getSelectedAppMode(), settings); -// pref.setSummary(atd.getTurnsDescription().trim()); -// pref.setVisible(true); -// } else { -// pref.setVisible(false); -// } - pref.setVisible(false); - } - private void setupSpeedLimitExceedPref() { //array size must be equal! Float[] valuesKmh = new Float[] {-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f}; @@ -294,9 +278,6 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR); } } - if (prefId.equals(settings.ARRIVAL_DISTANCE_FACTOR.getId())) { - updateVoicePromptsTimes(); - } if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) { return onConfirmPreferenceChange( settings.AUDIO_MANAGER_STREAM.getId(), newValue, ApplyQueryType.SNACK_BAR); @@ -334,8 +315,6 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr String prefId = preference.getKey(); if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(prefId)) { SpeedCamerasBottomSheet.showInstance(requireActivity().getSupportFragmentManager(), this); - } else if (VOICE_PROMPTS_TIMETABLE.equals(prefId)) { - app.showToastMessage(String.valueOf(preference.getSummary())); } return super.onPreferenceClick(preference); } From 56d869389fa99c563ec199982ecd2caa10efabe3 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sun, 17 Jan 2021 01:25:22 +0200 Subject: [PATCH 3/3] Minor fixes --- .../layout/bottom_sheet_announcement_time.xml | 235 +++++++------- OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/strings.xml | 4 +- OsmAnd/res/values/styles.xml | 2 + .../routing/data/AnnounceTimeDistances.java | 65 ++-- .../AnnouncementTimeBottomSheet.java | 293 ++++++++---------- .../fragments/VoiceAnnouncesFragment.java | 31 +- 7 files changed, 299 insertions(+), 332 deletions(-) diff --git a/OsmAnd/res/layout/bottom_sheet_announcement_time.xml b/OsmAnd/res/layout/bottom_sheet_announcement_time.xml index 630decba92..682cde0a66 100644 --- a/OsmAnd/res/layout/bottom_sheet_announcement_time.xml +++ b/OsmAnd/res/layout/bottom_sheet_announcement_time.xml @@ -1,130 +1,132 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:osmand="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingBottom="@dimen/bottom_sheet_exit_button_margin"> - + - + - + - + - + - + - + - + - - + - + \n • Passing: 20 - 25 m, 7 sec. " + tools:visibility="visible" /> \ No newline at end of file diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index fbcfe713fb..caf08aef6a 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -140,6 +140,7 @@ + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ddce561af7..bbb71f001a 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -15,11 +15,11 @@ Announcement time Announcement time of different voice prompts depends on prompt type, current navigation speed and default navigation speed. Time and distance intervals - Turn + Turn Arrive at destination Off route Prepare - Long Prepare + Long prepare Approach Passing sec diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 330dda3311..5945485c19 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -247,6 +247,7 @@ @style/CheckboxStyle @style/RadioButtonStyle @color/text_input_background_light + @drawable/img_help_announcement_time_day