diff --git a/android/app/src/main/java/app/organicmaps/widget/menu/NavMenu.java b/android/app/src/main/java/app/organicmaps/widget/menu/NavMenu.java index 8b781d660..b503cf812 100644 --- a/android/app/src/main/java/app/organicmaps/widget/menu/NavMenu.java +++ b/android/app/src/main/java/app/organicmaps/widget/menu/NavMenu.java @@ -1,20 +1,14 @@ package app.organicmaps.widget.menu; -import android.location.Location; -import android.util.Pair; import android.view.View; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; -import androidx.core.content.ContextCompat; -import app.organicmaps.MwmApplication; import app.organicmaps.R; import app.organicmaps.sdk.routing.RoutingInfo; import app.organicmaps.sdk.sound.TtsPlayer; -import app.organicmaps.sdk.util.Config; -import app.organicmaps.sdk.util.StringUtils; +import app.organicmaps.sdk.util.DateUtils; import app.organicmaps.util.Graphics; -import app.organicmaps.util.ThemeUtils; import app.organicmaps.util.UiUtils; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.button.MaterialButton; @@ -32,14 +26,12 @@ public class NavMenu private final View mHeaderFrame; private final ShapeableImageView mTts; - private final View mSpeedViewContainer; - private final MaterialTextView mSpeedValue; - private final MaterialTextView mSpeedUnits; + private final MaterialTextView mEtaValue; + private final MaterialTextView mEtaAmPm; private final MaterialTextView mTimeHourValue; private final MaterialTextView mTimeHourUnits; private final MaterialTextView mTimeMinuteValue; private final MaterialTextView mTimeMinuteUnits; - private final MaterialTextView mTimeEstimate; private final MaterialTextView mDistanceValue; private final MaterialTextView mDistanceUnits; private final LinearProgressIndicator mRouteProgress; @@ -94,14 +86,12 @@ public class NavMenu }); // Bottom frame - mSpeedViewContainer = bottomFrame.findViewById(R.id.speed_view_container); - mSpeedValue = bottomFrame.findViewById(R.id.speed_value); - mSpeedUnits = bottomFrame.findViewById(R.id.speed_dimen); + mEtaValue = bottomFrame.findViewById(R.id.eta_value); + mEtaAmPm = bottomFrame.findViewById(R.id.eta_am_pm); mTimeHourValue = bottomFrame.findViewById(R.id.time_hour_value); mTimeHourUnits = bottomFrame.findViewById(R.id.time_hour_dimen); mTimeMinuteValue = bottomFrame.findViewById(R.id.time_minute_value); mTimeMinuteUnits = bottomFrame.findViewById(R.id.time_minute_dimen); - mTimeEstimate = bottomFrame.findViewById(R.id.time_estimate); mDistanceValue = bottomFrame.findViewById(R.id.distance_value); mDistanceUnits = bottomFrame.findViewById(R.id.distance_dimen); mRouteProgress = bottomFrame.findViewById(R.id.navigation_progress); @@ -199,38 +189,34 @@ public class NavMenu private void updateTimeEstimate(int seconds) { - final String format = - android.text.format.DateFormat.is24HourFormat(mTimeMinuteValue.getContext()) ? "HH:mm" : "h:mm a"; + // Calculate ETA from current local time and remaining seconds. final LocalTime localTime = LocalTime.now().plusSeconds(seconds); - mTimeEstimate.setText(localTime.format(DateTimeFormatter.ofPattern(format))); - } - private void updateSpeedView(@NonNull RoutingInfo info) - { - final Location last = MwmApplication.from(mActivity).getLocationHelper().getSavedLocation(); - if (last == null) - return; + // String to set the format of the ETA value (24h or AM/PM). + final String etaValueFormat; - Pair speedAndUnits = StringUtils.nativeFormatSpeedAndUnits(last.getSpeed()); - mSpeedValue.setText(speedAndUnits.first); + // Text of the AM/PM view. + final String etaAmPmText; - if (info.speedLimitMps > 0.0 && last.getSpeed() > info.speedLimitMps) + if (DateUtils.is24HourFormat(mTimeMinuteValue.getContext())) { - if (info.isSpeedCamLimitExceeded()) - mSpeedValue.setTextColor(ContextCompat.getColor(mActivity, R.color.white_primary)); - else - mSpeedValue.setTextColor(ContextCompat.getColor(mActivity, R.color.base_red)); + // 24 hours time format. + etaValueFormat = "HH:mm"; + etaAmPmText = ""; } else - mSpeedValue.setTextColor(ThemeUtils.getColor(mActivity, android.R.attr.textColorPrimary)); + { + // AM/PM time format. + etaValueFormat = "h:mm"; + etaAmPmText = localTime.format(DateTimeFormatter.ofPattern("a")); + } - mSpeedUnits.setText(speedAndUnits.second); - mSpeedViewContainer.setActivated(info.isSpeedCamLimitExceeded()); + mEtaValue.setText(localTime.format(DateTimeFormatter.ofPattern(etaValueFormat))); + mEtaAmPm.setText(etaAmPmText); } public void update(@NonNull RoutingInfo info) { - updateSpeedView(info); updateTime(info.totalTimeInSeconds); mDistanceValue.setText(info.distToTarget.mDistanceStr); mDistanceUnits.setText(info.distToTarget.getUnitsStr(mActivity.getApplicationContext())); diff --git a/android/app/src/main/res/layout/layout_nav_bottom_numbers.xml b/android/app/src/main/res/layout/layout_nav_bottom_numbers.xml index b89a8bbe5..eed0f1e79 100644 --- a/android/app/src/main/res/layout/layout_nav_bottom_numbers.xml +++ b/android/app/src/main/res/layout/layout_nav_bottom_numbers.xml @@ -13,35 +13,35 @@ android:layout_height="match_parent" android:layout_weight="0.5"/> - + + + tools:text="99:99" /> - + + tools:text="AM/PM" /> + tools:text="----" />