[Android] Speed limit in navigation mode #8897

Merged
root merged 6 commits from android-speed-limit into master 2024-08-15 10:23:09 +00:00
3 changed files with 34 additions and 9 deletions

View file

@ -1253,7 +1253,7 @@ Java_app_organicmaps_Framework_nativeGetRouteFollowingInfo(JNIEnv * env, jclass)
jni::GetConstructorID(env, klass,
"(Lapp/organicmaps/util/Distance;Lapp/organicmaps/util/Distance;"
"Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DIIIII"
"[Lapp/organicmaps/routing/SingleLaneInfo;ZZ)V");
"[Lapp/organicmaps/routing/SingleLaneInfo;DZZ)V");
vector<routing::FollowingInfo::SingleLaneInfoClient> const & lanes = info.m_lanes;
jobjectArray jLanes = nullptr;
@ -1288,7 +1288,8 @@ Java_app_organicmaps_Framework_nativeGetRouteFollowingInfo(JNIEnv * env, jclass)
ToJavaDistance(env, info.m_distToTurn), jni::ToJavaString(env, info.m_currentStreetName),
jni::ToJavaString(env, info.m_nextStreetName), jni::ToJavaString(env, info.m_nextNextStreetName),
info.m_completionPercent, info.m_turn, info.m_nextTurn, info.m_pedestrianTurn, info.m_exitNum,
info.m_time, jLanes, static_cast<jboolean>(isSpeedCamLimitExceeded), static_cast<jboolean>(shouldPlaySignal));
info.m_time, jLanes, info.m_speedLimitMps, static_cast<jboolean>(isSpeedCamLimitExceeded),
static_cast<jboolean>(shouldPlaySignal));
ASSERT(result, (jni::DescribeException()));
return result;
}

View file

@ -34,7 +34,10 @@ public class RoutingInfo
public final SingleLaneInfo[] lanes;
// For pedestrian routing.
public final PedestrianTurnDirection pedestrianTurnDirection;
private final boolean speedLimitExceeded;
// Current speed limit in meters per second.
// If no info about speed limit then speedLimitMps < 0.
public final double speedLimitMps;
private final boolean speedCamLimitExceeded;
private final boolean shouldPlayWarningSignal;
/**
@ -140,7 +143,7 @@ public class RoutingInfo
public RoutingInfo(Distance distToTarget, Distance distToTurn, String currentStreet, String nextStreet, String nextNextStreet, double completionPercent,
int vehicleTurnOrdinal, int vehicleNextTurnOrdinal, int pedestrianTurnOrdinal, int exitNum,
int totalTime, SingleLaneInfo[] lanes, boolean speedLimitExceeded,
int totalTime, SingleLaneInfo[] lanes, double speedLimitMps, boolean speedLimitExceeded,
boolean shouldPlayWarningSignal)
{
this.distToTarget = distToTarget;
@ -155,13 +158,14 @@ public class RoutingInfo
this.lanes = lanes;
this.exitNum = exitNum;
this.pedestrianTurnDirection = PedestrianTurnDirection.values()[pedestrianTurnOrdinal];
this.speedLimitExceeded = speedLimitExceeded;
this.speedLimitMps = speedLimitMps;
this.speedCamLimitExceeded = speedLimitExceeded;
this.shouldPlayWarningSignal = shouldPlayWarningSignal;
}
public boolean isSpeedLimitExceeded()
public boolean isSpeedCamLimitExceeded()
{
return speedLimitExceeded;
return speedCamLimitExceeded;
}
public boolean shouldPlayWarningSignal()

View file

@ -9,6 +9,8 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import app.organicmaps.R;
import app.organicmaps.location.LocationHelper;
@ -16,6 +18,7 @@ import app.organicmaps.routing.RoutingInfo;
import app.organicmaps.sound.TtsPlayer;
import app.organicmaps.util.Graphics;
import app.organicmaps.util.StringUtils;
import app.organicmaps.util.ThemeUtils;
import app.organicmaps.util.UiUtils;
import com.google.android.material.progressindicator.LinearProgressIndicator;
@ -211,9 +214,26 @@ public class NavMenu
Pair<String, String> speedAndUnits = StringUtils.nativeFormatSpeedAndUnits(last.getSpeed());
biodranik commented 2024-08-09 07:13:04 +00:00 (Migrated from github.com)
Review

Would this narrow non-breaking space look better? https://www.compart.com/en/unicode/U+202F

Would this narrow non-breaking space look better? https://www.compart.com/en/unicode/U+202F
biodranik commented 2024-08-09 07:13:14 +00:00 (Migrated from github.com)
Review

It can also be used on iOS btw.

It can also be used on iOS btw.
Review

You mean replace " / " with "\u202F/\u202F"?

You mean replace `" / "` with `"\u202F/\u202F"`?
biodranik commented 2024-08-09 10:20:16 +00:00 (Migrated from github.com)
Review

Yes, or just copy the necessary space symbol and insert it directly into the string.

Yes, or just copy the necessary space symbol and insert it directly into the string.
if (info.speedLimitMps > 0.0)
{
Pair<String, String> speedLimitAndUnits = StringUtils.nativeFormatSpeedAndUnits(info.speedLimitMps);
mSpeedValue.setText(speedAndUnits.first + "\u202F/\u202F" + speedLimitAndUnits.first);
}
else
mSpeedValue.setText(speedAndUnits.first);
if (last.getSpeed() > info.speedLimitMps)
{
if (info.isSpeedCamLimitExceeded())
mSpeedValue.setTextColor(ContextCompat.getColor(mActivity, R.color.white_primary));
else
mSpeedValue.setTextColor(ContextCompat.getColor(mActivity, R.color.base_red));
}
else
mSpeedValue.setTextColor(ThemeUtils.getColor(mActivity, android.R.attr.textColorPrimary));
mSpeedUnits.setText(speedAndUnits.second);
mSpeedValue.setText(speedAndUnits.first);
mSpeedViewContainer.setActivated(info.isSpeedLimitExceeded());
mSpeedViewContainer.setActivated(info.isSpeedCamLimitExceeded());
}
public void update(@NonNull RoutingInfo info)