Merge branch 'master' into dev_robo_240612_6.5.0_tmp

This commit is contained in:
yangyakun
2024-07-05 16:34:49 +08:00
82 changed files with 1643 additions and 251 deletions

View File

@@ -13,6 +13,7 @@ import com.mogo.eagle.core.function.business.ai.RomaManager.Companion.romaManage
import com.mogo.eagle.core.function.business.identify.MapIdentifySubscriber
import com.mogo.eagle.core.function.business.roadcross.RoadCrossCameraManager
import com.mogo.eagle.core.function.business.routeoverlay.MogoRouteOverlayManager
import com.mogo.eagle.core.function.business.trajectoryoverlay.MogoTrajectoryOverlayManager
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager
import com.mogo.eagle.core.utilcode.util.DeviceUtils
import com.mogo.map.MapDataWrapper
@@ -27,6 +28,7 @@ class MapBizProvider :IMoGoFunctionServerProvider, IMogoRoma {
MapDataWrapper.init()
MapIdentifySubscriber.instance
MogoRouteOverlayManager.getInstance().init()
MogoTrajectoryOverlayManager.getInstance().init()
MapPointCloudSubscriber.instance
RoadCrossCameraManager.instance.init(context)
SpeedLimitDataManager.getInstance().start()

View File

@@ -0,0 +1,16 @@
package com.mogo.eagle.core.function.business.routeoverlay
import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.function.api.map.route.IMapRouteProvider
@Route(path = MogoServicePaths.PATH_MAP_ROUTE_GUIDE)
class MapRouteProviderImpl: IMapRouteProvider {
override fun setRouteDynamicColorEnable(enable: Boolean) {
RouteStrategy.isEnable = enable
}
override fun init(context: Context?) { }
}

View File

@@ -81,7 +81,7 @@ public class RouteOverlayDrawer {
if (mRenderTask != null) {
mRenderHandler.removeCallbacks(mRenderTask);
}
mogoOverlayManager.removeAllLinesInLevel(Level.GUIDE_ROUTE_LINE);
mogoOverlayManager.hideAllLinesInLevel(Level.GUIDE_ROUTE_LINE);
}
}

View File

@@ -3,13 +3,11 @@ package com.mogo.eagle.core.function.business.routeoverlay
import android.animation.ArgbEvaluator
import android.graphics.Color
import android.view.animation.AccelerateInterpolator
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.config.HmiBuildConfig
import com.mogo.eagle.core.function.business.routeoverlay.Colors.Companion.COLOR_BLUE
import com.mogo.eagle.core.function.business.routeoverlay.Colors.Companion.COLOR_BLUE_DARK
import com.mogo.eagle.core.function.business.routeoverlay.Colors.Companion.COLOR_RED_DARK
import com.mogo.eagle.core.function.business.routeoverlay.Colors.Companion.COLOR_TRANSPARENT
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import java.util.*
import kotlin.properties.Delegates
@@ -42,7 +40,7 @@ class ColorfulStrategy(private val colors: List<Int> = emptyList(), var isLightO
object RouteStrategy {
private var isEnable by Delegates.observable(HmiBuildConfig.isShowRouteStrategy) { _, _, newValue ->
internal var isEnable by Delegates.observable(HmiBuildConfig.isShowRouteStrategy) { _, _, newValue ->
if (!newValue) {
strategy = null
colors.clear()

View File

@@ -0,0 +1,106 @@
package com.mogo.eagle.core.function.business.trajectoryoverlay;
import android.util.Log;
import android.util.Pair;
import androidx.annotation.Nullable;
import com.mogo.commons.utils.MogoAnalyticUtils;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener;
import com.mogo.eagle.core.function.api.autopilot.IMoGoPlanningRottingListener;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerPlanningRottingListenerManager;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mogo.telematics.pad.MessagePad;
public class MogoTrajectoryOverlayManager implements IMoGoPlanningRottingListener, IMoGoChassisLocationGCJ02Listener {
private static volatile MogoTrajectoryOverlayManager sInstance;
private static final String TAG = "MogoTrajectoryOverlayManager";
private static final String ANALYTICS_KEY = "mogo_map_trajectory_overlay_manager";
private final List<MessagePad.Location> queue = new ArrayList<>();
private MogoTrajectoryOverlayManager() {
}
public void init() {
CallerPlanningRottingListenerManager.INSTANCE.addListener(TAG, this);
CallerChassisLocationGCJ02ListenerManager.INSTANCE.addListener(TAG, 1, this);
}
public static MogoTrajectoryOverlayManager getInstance() {
if (sInstance == null) {
synchronized (MogoTrajectoryOverlayManager.class) {
if (sInstance == null) {
sInstance = new MogoTrajectoryOverlayManager();
//需要先初始化否则第一次调用drawTrajectoryOverlayOnce()会因为mRenderHandler=null实际不会绘制
TrajectoryOverlayDrawer.getInstance();
}
}
}
return sInstance;
}
@Override
public void onAutopilotRotting(@Nullable MessagePad.GlobalPathResp globalPathResp) {
if (globalPathResp != null) {
CallerLogger.i(TAG, "onAutopilotRotting size=" + globalPathResp.getWayPointsList().size());
synchronized (queue) {
queue.clear();
queue.addAll(globalPathResp.getWayPointsList());
}
trackEvent("onAutopilotRotting", "接收到全局轨迹规划, size=" + globalPathResp.getWayPointsList().size());
}
}
@Override
public void onChassisLocationGCJ02(@Nullable MogoLocation gnssInfo) {
}
public Pair<Boolean, String> drawTrajectoryOverlayOnce() {
CallerLogger.i(TAG, "drawTrajectoryOverlayOnce");
trackEvent("drawTrajectoryOverlayOnce", "开始执行");
synchronized (queue) {
if (queue != null && !queue.isEmpty()) {
double heading = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getHeading();
TrajectoryOverlayDrawer.getInstance().drawTrajectoryList(queue, heading);
trackEvent("drawTrajectoryOverlayOnce", "执行结果(result=true, msg=success)");
return new Pair(true, "success");
}
trackEvent("drawTrajectoryOverlayOnce", "执行结果(result=false, msg=全局轨迹未就绪或为空)");
return new Pair(false, "全局轨迹未就绪或为空");
}
}
public void clearTrajectoryOverlay(boolean isClearData) {
CallerLogger.i(TAG, "clearTrajectoryOverlay");
trackEvent("clearTrajectoryOverlay", "开始执行");
TrajectoryOverlayDrawer.getInstance().clearMogoTrajectoryOverlay();
if (isClearData) {
queue.clear();
}
trackEvent("clearTrajectoryOverlay", "success");
}
public void trackEvent(String eventKey, String eventValue) {
ThreadUtils.getIoPool().submit(new Runnable() {
@Override
public void run() {
Log.i(TAG, eventKey + "-->" + eventValue);
Map map = new HashMap();
map.put(eventKey, eventValue);
MogoAnalyticUtils.INSTANCE.track(ANALYTICS_KEY, map);
}
});
}
}

View File

@@ -0,0 +1,43 @@
package com.mogo.eagle.core.function.business.trajectoryoverlay
import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.function.api.map.trajectory.IMoGoGlobalTrajectoryDrawListener
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import java.util.concurrent.atomic.AtomicReference
@Route(path = MogoServicePaths.PATH_MAP_GLOBAL_TRAJECTORY)
class MogoTrajectoryOverlayProvider : IMoGoGlobalTrajectoryDrawListener {
companion object {
private const val TAG = "MogoTrajectoryOverlayProvider"
}
private var hasDrawn = AtomicReference<Boolean>(false)
override fun init(context: Context?) {
CallerLogger.i(TAG, "---init---")
}
override fun hasDrawnGlobalTrajectory(): Boolean {
val result = hasDrawn.get()
CallerLogger.i(TAG, "hasDrawnGlobalTrajectory --> hasDrawn=$result")
return result
}
override fun drawGlobalTrajectory(): Pair<Boolean, String> {
val result = MogoTrajectoryOverlayManager.getInstance().drawTrajectoryOverlayOnce()
if (result.first) {
hasDrawn.set(result.first)
}
CallerLogger.i(TAG, "drawGlobalTrajectory --> hasDrawn=$hasDrawn, result.first=${result.first}, result.second=${result.second}")
return Pair(result.first, result.second)
}
override fun clearGlobalTrajectory(isClearData: Boolean) {
MogoTrajectoryOverlayManager.getInstance().clearTrajectoryOverlay(isClearData)
hasDrawn.set(false)
CallerLogger.i(TAG, "clearGlobalTrajectory --> hasDrawn=$hasDrawn")
}
}

View File

@@ -0,0 +1,288 @@
package com.mogo.eagle.core.function.business.trajectoryoverlay;
import static com.mogo.map.MogoMap.DEFAULT;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
import androidx.core.util.Pools;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager;
import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils;
import com.mogo.map.overlay.IMoGoOverlayManager;
import com.mogo.map.overlay.core.Level;
import com.mogo.map.overlay.line.Polyline;
import com.zhidaoauto.map.sdk.open.common.tools.MapTools;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import kotlin.Pair;
import mogo.telematics.pad.MessagePad;
public class TrajectoryOverlayDrawer {
private static final String TAG = "TrajectoryOverlayDrawer";
// 连接线参数
private Handler mRenderHandler;
private final IMoGoOverlayManager mogoOverlayManager;
private static volatile TrajectoryOverlayDrawer sInstance;
private static final byte[] obj = new byte[0];
private Polyline.Options mPolylineOptions;
private static final int COLOR_LIGHT = Color.parseColor("#BAEBF5");
private static final int mPolylineWidth = 50;
//用于taxi乘客屏渐变颜色集合
private static List<Integer> colors = null;
private TrajectoryOverlayDrawer() {
// 渐变色
mogoOverlayManager = CallerMapUIServiceManager.INSTANCE.getOverlayManager();
if (mogoOverlayManager != null) {
mPolylineOptions = new Polyline.Options.Builder("trajectory_overlay", Level.TRAJECTORY_LINE)
.setUseGps(true)
.setWidth(mPolylineWidth)
.setIsGradient(true)
.build();
// 线条粗细,渐变,渐变色值
HandlerThread renderTask = new HandlerThread("trajectory_render") {
@Override
protected void onLooperPrepared() {
super.onLooperPrepared();
mRenderHandler = new Handler(getLooper());
}
};
renderTask.start();
}
}
public static TrajectoryOverlayDrawer getInstance() {
if (sInstance == null) {
synchronized (obj) {
if (sInstance == null) {
sInstance = new TrajectoryOverlayDrawer();
}
}
}
return sInstance;
}
public void clearMogoTrajectoryOverlay() {
if (mogoOverlayManager != null) {
if (mRenderTask != null) {
mRenderHandler.removeCallbacks(mRenderTask);
}
mogoOverlayManager.hideAllLinesInLevel(Level.TRAJECTORY_LINE);
}
}
private class RenderTask implements Runnable {
private volatile List<MessagePad.Location> routeList;
private final Pools.Pool<MogoLatLng> pools;
private final LinkedList<MogoLatLng> points;
private double bearing;
public RenderTask() {
this.pools = new Pools.SimplePool<>(500);
this.points = new LinkedList<>();
}
public void setData(List<MessagePad.Location> routeList, double bearing) {
this.routeList = routeList;
this.bearing = bearing;
}
@SuppressLint("LongLogTag")
@Override
public void run() {
IMoGoOverlayManager overlayManager = mogoOverlayManager;
if (overlayManager == null) {
return;
}
LinkedList<MogoLatLng> pps = this.points;
boolean isExcept = false;
int total;
try {
pps.clear();
List<MessagePad.Location> routes = this.routeList;
if (routes == null || (total = routes.size()) < 2) {
isExcept = true;
return;
}
//boolean isColorfulStrategy = !AppIdentityModeUtils.isTaxi(FunctionBuildConfig.appIdentityMode) || !AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode);
//全局轨迹线 没有颜色策略,使用固定颜色
boolean isColorfulStrategy = false;
if (isColorfulStrategy) {
TrajectoryStrategy.INSTANCE.start();
} else {
if (colors == null) {
ArrayList<Pair<Integer, Integer>> temps = new ArrayList<>();
temps.add(new Pair<>(0, 70));
temps.add(new Pair<>(2, 100));
temps.add(new Pair<>(98, 100));
temps.add(new Pair<>(100, 70));
List<Integer> alphas = MapTools.INSTANCE.getColorAlpha(temps);
if (alphas != null && !alphas.isEmpty()) {
colors = new ArrayList<>();
for (int i : alphas) {
colors.add(Color.argb(i, 48,163,255));
}
}
}
}
for (int i = 0; i < total; i++) {
MessagePad.Location route = null;
try {
route = routes.get(i);
if (route == null) {
continue;
}
} catch (Throwable t) {
Log.d("Trajectory", "render-error:" + t.getMessage());
}
if (route == null) {
//数组越界了,结束循环
break;
}
MogoLatLng acquire = pools.acquire();
double latitude = route.getLatitude();
double longitude = route.getLongitude();
if (acquire == null) {
acquire = new MogoLatLng(latitude, longitude);
} else {
acquire.lon = longitude;
acquire.lat = latitude;
}
pps.add(acquire);
}
// double lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
// double lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
if (points.size() > 0) {
// MogoLatLng top = null;
// while (points.size() != 0) {
// MogoLatLng first = points.peek();
// if (first == null) {
// continue;
// }
// if (first == top) {
// break;
// }
// lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
// lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
// long angle = isPointOnCarFront(lon, lat, bearing, first.lon, first.lat);
// if (angle >= 90) {
// if (isColorfulStrategy) {
// TrajectoryStrategy.INSTANCE.remove(first.acc);
// }
// pools.release(first);
// points.poll();
// }
// top = first;
// }
// if (points.size() == 0) {
// isExcept = true;
// return;
// }
// MogoLatLng self = pools.acquire();
// if (self == null) {
// self = new MogoLatLng(lat, lon);
// } else {
// self.lat = lat;
// self.lon = lon;
// }
// points.addFirst(self);
Polyline.Options.Builder builder;
if (mPolylineOptions == null) {
builder = new Polyline.Options.Builder("trajectory_overlay", Level.TRAJECTORY_LINE)
.setUseGps(true)
.setWidth(mPolylineWidth)
.setIsGradient(false);
} else {
builder = mPolylineOptions.builder();
}
if (isColorfulStrategy) {
TrajectoryStrategy.INSTANCE.end();
Strategy strategy = TrajectoryStrategy.INSTANCE.getStrategy();
List<Integer> colors = strategy.getColors();
boolean isLightOn = strategy instanceof ColorfulStrategy && ((ColorfulStrategy) strategy).isLightOn();
builder.colors(colors);
builder.setLightOn(isLightOn);
//builder.setLightColor(COLOR_LIGHT);
//builder.setLightSpeed(0.3f);
} else {
if (colors != null && !colors.isEmpty()) {
builder.colors(colors);
builder.setIsGradient(true);
builder.setLightOn(false);
//builder.setLightColor(COLOR_LIGHT);
//builder.setLightSpeed(0.3f);
}
}
builder.points(points);
builder.setVisible(true);
Polyline.Options options = builder.build();
if (mPolylineOptions == null) {
mPolylineOptions = options;
}
overlayManager.showOrUpdateLine(options,DEFAULT);
} else {
isExcept = true;
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (isExcept) {
setVisible(false);
}
if (points.size() > 0) {
for (int i = 0; i < points.size(); i++) {
MogoLatLng latLng = points.get(i);
if (latLng == null) {
continue;
}
pools.release(latLng);
}
}
}
}
private long isPointOnCarFront(double car_lon, double car_lat, double car_head, double lon, double lat) {
return DrivingDirectionUtils.getDegreeOfCar2Poi2(car_lon, car_lat, lon, lat, car_head);
}
}
private volatile RenderTask mRenderTask;
public void drawTrajectoryList(List<MessagePad.Location> routeList, double bearing) {
if (mogoOverlayManager != null) {
if (mRenderTask == null) {
mRenderTask = new RenderTask();
}
mRenderTask.setData(routeList, bearing);
if (mRenderHandler != null) {
mRenderHandler.removeCallbacks(mRenderTask);
mRenderHandler.post(mRenderTask);
}
}
}
private void setVisible(boolean isVisible) {
if (mogoOverlayManager != null) {
if (isVisible) {
mogoOverlayManager.showAllLinesInLevel(Level.TRAJECTORY_LINE);
} else {
mogoOverlayManager.hideAllLinesInLevel(Level.TRAJECTORY_LINE);
}
}
}
}

View File

@@ -0,0 +1,170 @@
package com.mogo.eagle.core.function.business.trajectoryoverlay
import android.animation.ArgbEvaluator
import android.graphics.Color
import android.view.animation.AccelerateInterpolator
import com.mogo.eagle.core.data.config.HmiBuildConfig
import com.mogo.eagle.core.function.business.trajectoryoverlay.Colors.Companion.COLOR_BLUE
import com.mogo.eagle.core.function.business.trajectoryoverlay.Colors.Companion.COLOR_BLUE_DARK
import com.mogo.eagle.core.function.business.trajectoryoverlay.Colors.Companion.COLOR_RED_DARK
import com.mogo.eagle.core.function.business.trajectoryoverlay.Colors.Companion.COLOR_TRANSPARENT
import java.util.NavigableMap
import java.util.TreeMap
import kotlin.properties.Delegates
interface IStrategy {
fun getColors(): List<Int>
}
class Colors {
companion object {
val COLOR_BLUE = Color.parseColor("#FF2ABAD9")
val COLOR_BLUE_DARK = Color.parseColor("#FF074EFF")
val COLOR_RED_DARK = Color.parseColor("#FF0FF5F0")
val COLOR_TRANSPARENT = Color.parseColor("#002ABAD9")
}
}
sealed class Strategy : IStrategy
class DefaultStrategy(private val colors: List<Int>? = null) : Strategy() {
override fun getColors(): List<Int> = colors ?: listOf(COLOR_BLUE, COLOR_TRANSPARENT)
}
class ColorfulStrategy(private val colors: List<Int> = emptyList(), var isLightOn: Boolean) :
Strategy() {
override fun getColors(): List<Int> = colors
}
object TrajectoryStrategy {
private var isEnable by Delegates.observable(HmiBuildConfig.isShowRouteStrategy) { _, _, newValue ->
if (!newValue) {
strategy = null
colors.clear()
}
}
private var strategy: Strategy? = null
private val colors: ArrayList<Int> = ArrayList()
private var index = 0
private val sorted: NavigableMap<Double, Int> by lazy { TreeMap() }
private var endEvaluator: ArgbEvaluator? = null
private var startColor = Int.MAX_VALUE
private var hasLessThan0 = false
fun start() {
if (sorted.isEmpty()) {
fill()
}
strategy = null
index = 0
startColor = Int.MAX_VALUE
colors.clear()
endEvaluator = null
hasLessThan0 = false
}
fun end() {
if (isEnable) {
if (colors.isEmpty()) {
return
}
val first = colors[0]
colors.add(0, first)
strategy = ColorfulStrategy(colors, true)
}
}
fun check(speed: Double, acc: Double, total: Int) {
if (!isEnable) {
return
}
if (sorted.isEmpty()) {
return
}
if (acc < 0) {
hasLessThan0 = true
}
val delta = (total * 0.35).toInt()
val last = total - delta
val entry = sorted.floorEntry(acc)
if (entry != null) {
if (index >= last - 1) {
if (startColor == Int.MAX_VALUE) {
startColor = entry.value
if (endEvaluator == null) {
endEvaluator = ArgbEvaluator()
}
colors += entry.value
} else {
if (endEvaluator != null) {
val fraction = (index - last) * 1.0f / delta
colors += endEvaluator!!.evaluate(
fraction,
startColor,
COLOR_TRANSPARENT
) as Int
}
}
} else {
colors += entry.value
}
}
index++
}
fun remove(acc: Double): List<Int> {
if (!isEnable) {
return emptyList()
}
if (sorted.isEmpty()) {
throw AssertionError("sorted map must not be null.")
}
val entry = sorted.floorEntry(acc)
if (entry != null) {
colors.remove(entry.value)
}
return ArrayList(colors)
}
private fun fill() {
var startValue = -4.0
var endValue = 0.0
val step = 0.01
var current = startValue
val evaluator = ArgbEvaluator()
val interceptor = AccelerateInterpolator()
var total = endValue - startValue
while (current <= endValue) {
val fraction = interceptor.getInterpolation(((current - startValue) / total).toFloat())
val colorValue = evaluator.evaluate(fraction, COLOR_RED_DARK, COLOR_BLUE) as Int
sorted[current] = colorValue
current += step
}
startValue = 0.01
endValue = 3.0
current = startValue
total = endValue - startValue
while (current <= endValue) {
val fraction = (current - startValue) / total
val colorValue =
evaluator.evaluate(fraction.toFloat(), COLOR_BLUE, COLOR_BLUE_DARK) as Int
sorted[current] = colorValue
current += step
}
}
fun getStrategy(): Strategy = if (isEnable) {
(strategy ?: DefaultStrategy())
} else DefaultStrategy()
}