remix the aiCloudSocketData

This commit is contained in:
zhongchao
2021-05-25 15:55:08 +08:00
parent 716e02a9cb
commit 4010c27dbe
40 changed files with 1127 additions and 854 deletions

View File

@@ -3,6 +3,7 @@ package com.mogo.module.common.drawer;
import android.os.Message;
import android.text.TextUtils;
import com.mogo.cloud.socket.entity.SocketDownData;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
@@ -10,8 +11,7 @@ import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.utils.SimpleHandlerThreadPool;
import com.mogo.realtime.entity.ADASRecognizedResult;
import com.mogo.utils.logger.Logger;
import com.mogo.service.adas.entity.ADASRecognizedResult;
import java.util.ArrayList;
import java.util.HashMap;
@@ -37,12 +37,12 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
super();
}
private final Map< String, ADASRecognizedResult > mLastPositions = new ConcurrentHashMap<>();
private final Map<String, ADASRecognizedResult> mLastPositions = new ConcurrentHashMap<>();
public static AdasRecognizedResultDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( AdasRecognizedResultDrawer.class ) {
if ( sInstance == null ) {
if (sInstance == null) {
synchronized (AdasRecognizedResultDrawer.class) {
if (sInstance == null) {
sInstance = new AdasRecognizedResultDrawer();
}
}
@@ -59,8 +59,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
return sInstance;
}
public boolean hasCached( String uniqueKey ) {
return mMarkersCaches.containsKey( uniqueKey );
public boolean hasCached(String uniqueKey) {
return mMarkersCaches.containsKey(uniqueKey);
}
/**
@@ -68,33 +68,33 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
*
* @param resultList
*/
public void renderAdasRecognizedResult( List< ADASRecognizedResult > resultList ) {
if ( resultList == null || resultList.isEmpty() || !DebugConfig.isUseAdasRecognize() ) {
public void renderAdasRecognizedResult(List<ADASRecognizedResult> resultList) {
if (resultList == null || resultList.isEmpty() || !DebugConfig.isUseAdasRecognize()) {
clearOldMarker();
return;
}
if ( !MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
if (!MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
clearOldMarker();
return;
}
Map< String, IMogoMarker > newAdasRecognizedMarkersCaches = new HashMap<>();
List< ADASRecognizedResult > newDiffSet = new ArrayList<>();
for ( ADASRecognizedResult recognizedListResult : resultList ) {
Map<String, IMogoMarker> newAdasRecognizedMarkersCaches = new HashMap<>();
List<ADASRecognizedResult> newDiffSet = new ArrayList<>();
for (ADASRecognizedResult recognizedListResult : resultList) {
if ( isUselessValue( recognizedListResult ) ) {
if (isUselessValue(recognizedListResult)) {
continue;
}
// 复用之前存在的 marker
String uniqueKey = recognizedListResult.uuid;
IMogoMarker marker = mMarkersCaches.remove( uniqueKey );
if ( marker != null && !marker.isDestroyed() ) {
renderAdasOneFrame( marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches );
IMogoMarker marker = mMarkersCaches.remove(uniqueKey);
if (marker != null && !marker.isDestroyed()) {
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
} else {
// 新增差集
newDiffSet.add( recognizedListResult );
newDiffSet.add(recognizedListResult);
}
}
@@ -108,66 +108,66 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
int size = cachedMarkerSize >= newDiffSetSize ? newDiffSetSize : cachedMarkerSize;
// 复用过期 marker
if ( newDiffSetSize > 0 ) {
Iterator< Map.Entry< String, IMogoMarker > > entryIterator = mMarkersCaches.entrySet().iterator();
for ( int i = 0; i < size; i++ ) {
ADASRecognizedResult recognizedListResult = newDiffSet.get( i );
if (newDiffSetSize > 0) {
Iterator<Map.Entry<String, IMogoMarker>> entryIterator = mMarkersCaches.entrySet().iterator();
for (int i = 0; i < size; i++) {
ADASRecognizedResult recognizedListResult = newDiffSet.get(i);
String uniqueKey = recognizedListResult.uuid;
Map.Entry< String, IMogoMarker > entry = entryIterator.next();
Map.Entry<String, IMogoMarker> entry = entryIterator.next();
entryIterator.remove();
ADASRecognizedResult old = mLastPositions.remove( entry.getKey() );
ADASRecognizedResult old = mLastPositions.remove(entry.getKey());
IMogoMarker marker = entry.getValue();
if ( marker == null ) {
if (marker == null) {
continue;
}
// 更新资源内容
if ( old == null || old.type != recognizedListResult.type ) {
if (old == null || old.type != recognizedListResult.type) {
String resIdVal = null;
int resId = getModelRes( recognizedListResult.type );
int resId = getModelRes(recognizedListResult.type);
resIdVal = resId + "";
String resName = mMarkerCachesResMd5Values.get( resIdVal );
if ( !TextUtils.isEmpty( resName ) ) {
if ( !TextUtils.equals( resName, marker.getMarkerResName() ) ) {
marker.use3DResource( resName );
String resName = mMarkerCachesResMd5Values.get(resIdVal);
if (!TextUtils.isEmpty(resName)) {
if (!TextUtils.equals(resName, marker.getMarkerResName())) {
marker.use3DResource(resName);
}
} else {
resName = marker.use3DResource( resId );
mMarkerCachesResMd5Values.put( resIdVal, resName );
resName = marker.use3DResource(resId);
mMarkerCachesResMd5Values.put(resIdVal, resName);
}
}
renderAdasOneFrame( marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches );
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
}
// 复用过后还需新增的 marker
for ( int i = size; i < newDiffSetSize; i++ ) {
ADASRecognizedResult recognizedListResult = newDiffSet.get( i );
for (int i = size; i < newDiffSetSize; i++) {
ADASRecognizedResult recognizedListResult = newDiffSet.get(i);
String uniqueKey = recognizedListResult.uuid;
IMogoMarker marker = drawAdasRecognizedDataMarker( recognizedListResult );
if ( marker == null ) {
IMogoMarker marker = drawAdasRecognizedDataMarker(recognizedListResult);
if (marker == null) {
continue;
}
renderAdasOneFrame( marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches );
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
}
}
if ( cachedMarkerSize - size > 0 ) {
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches );
if (cachedMarkerSize - size > 0) {
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
}
mMarkersCaches = newAdasRecognizedMarkersCaches;
}
private boolean isUselessValue( ADASRecognizedResult recognizedListResult ) {
if ( recognizedListResult == null ) {
private boolean isUselessValue(ADASRecognizedResult recognizedListResult) {
if (recognizedListResult == null) {
return true;
}
if ( !isRenderType( recognizedListResult.type ) ) {
if (!isRenderType(recognizedListResult.type)) {
return true;
}
String uniqueKey = recognizedListResult.uuid;
if ( TextUtils.isEmpty( uniqueKey ) ) {
if (TextUtils.isEmpty(uniqueKey)) {
return true;
}
return false;
@@ -179,49 +179,49 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
* @param recognizedListResult
* @param newAdasRecognizedMarkersCaches
*/
private void renderAdasOneFrame( IMogoMarker marker,
String uniqueKey,
ADASRecognizedResult recognizedListResult,
Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) {
private void renderAdasOneFrame(IMogoMarker marker,
String uniqueKey,
ADASRecognizedResult recognizedListResult,
Map<String, IMogoMarker> newAdasRecognizedMarkersCaches) {
final long start = System.currentTimeMillis();
ADASRecognizedResult lastPosition = mLastPositions.remove( uniqueKey );
ADASRecognizedResult lastPosition = mLastPositions.remove(uniqueKey);
double lastLon = -1;
double lastLat = -1;
if ( lastPosition != null ) {
if (lastPosition != null) {
lastLon = lastPosition.lon;
lastLat = lastPosition.lat;
}
double[] matchLonLat = getMatchLonLat( recognizedListResult.uuid, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading, lastLon, lastLat );
double[] matchLonLat = getMatchLonLat(recognizedListResult.uuid, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading, lastLon, lastLat);
recognizedListResult.lon = matchLonLat[0];
recognizedListResult.lat = matchLonLat[1];
mLastPositions.put( uniqueKey, recognizedListResult );
mLastPositions.put(uniqueKey, recognizedListResult);
// Logger.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
newAdasRecognizedMarkersCaches.put( uniqueKey, marker );
if ( lastPosition != null ) {
long interval = computeAnimDuration( lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime );
newAdasRecognizedMarkersCaches.put(uniqueKey, marker);
if (lastPosition != null) {
long interval = computeAnimDuration(lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime);
final MogoLatLng renderLoc = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon );
final MogoLatLng renderLoc = new MogoLatLng(recognizedListResult.lat, recognizedListResult.lon);
long cost = System.currentTimeMillis() - start;
final long intervalRef = interval - cost;
SimpleHandlerThreadPool.getInstance().postRender( () -> {
marker.addDynamicAnchorPosition( renderLoc, ( float ) recognizedListResult.heading, intervalRef );
} );
SimpleHandlerThreadPool.getInstance().postRender(() -> {
marker.addDynamicAnchorPosition(renderLoc, (float) recognizedListResult.heading, intervalRef);
});
} else {
marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) );
marker.setPosition( recognizedListResult.lat, recognizedListResult.lon );
marker.setRotateAngle(((float) recognizedListResult.heading));
marker.setPosition(recognizedListResult.lat, recognizedListResult.lon);
}
String carColor = recognizedListResult.color;
if ( TextUtils.isEmpty( carColor ) ) {
carColor = getModelRenderColor( recognizedListResult.type, recognizedListResult.speed, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading );
if (TextUtils.isEmpty(carColor)) {
carColor = getModelRenderColor(recognizedListResult.type, recognizedListResult.speed, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading);
}
marker.setAnchorColor( carColor );
marker.setAnchorColor(carColor);
if ( shouldShowSpeed( recognizedListResult.type ) ) {
if (shouldShowSpeed(recognizedListResult.type)) {
Message msg = mRenderThreadHandler.obtainMessage();
SpeedData obj = new SpeedData();
obj.context = mContext;
@@ -239,32 +239,32 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
* @param recognizedListResult
* @return
*/
private IMogoMarker drawAdasRecognizedDataMarker( ADASRecognizedResult recognizedListResult ) {
if ( recognizedListResult == null ) {
private IMogoMarker drawAdasRecognizedDataMarker(ADASRecognizedResult recognizedListResult) {
if (recognizedListResult == null) {
return null;
}
String resIdVal = null;
int resId = getModelRes( recognizedListResult.type );
int resId = getModelRes(recognizedListResult.type);
resIdVal = resId + "";
String carColor = recognizedListResult.color;
if ( TextUtils.isEmpty( carColor ) ) {
carColor = getModelRenderColor( recognizedListResult.type, recognizedListResult.speed, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading );
if (TextUtils.isEmpty(carColor)) {
carColor = getModelRenderColor(recognizedListResult.type, recognizedListResult.speed, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading);
}
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_ADAS )
.anchor( 0.5f, 0.5f )
.set3DMode( true )
.gps( true )
.anchorColor( carColor )
.controlAngle( true )
.resName( mMarkerCachesResMd5Values.get( resIdVal ) )
.icon3DRes( resId )
.rotate( ( float ) recognizedListResult.heading )
.position( new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon ) );
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( DataTypes.TYPE_MARKER_ADAS, options );
cacheMarkerIconResMd5Val( resIdVal, marker );
.owner(DataTypes.TYPE_MARKER_ADAS)
.anchor(0.5f, 0.5f)
.set3DMode(true)
.gps(true)
.anchorColor(carColor)
.controlAngle(true)
.resName(mMarkerCachesResMd5Values.get(resIdVal))
.icon3DRes(resId)
.rotate((float) recognizedListResult.heading)
.position(new MogoLatLng(recognizedListResult.lat, recognizedListResult.lon));
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(mContext).addMarker(DataTypes.TYPE_MARKER_ADAS, options);
cacheMarkerIconResMd5Val(resIdVal, marker);
return marker;
}
@@ -279,12 +279,12 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
* 清除旧的 marker 数据
*/
public void clearOldMarker() {
if ( mMarkersCaches != null ) {
if (mMarkersCaches != null) {
mMarkersCaches.clear();
}
if ( mLastPositions != null ) {
if (mLastPositions != null) {
mLastPositions.clear();
}
sendMessage( MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_ADAS );
sendMessage(MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_ADAS);
}
}

View File

@@ -6,6 +6,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import com.mogo.cloud.socket.entity.SocketDownData;
import com.mogo.cloud.socket.entity.SocketDownDataHelper;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
@@ -16,8 +18,6 @@ import com.mogo.module.common.R;
import com.mogo.module.common.api.CallChatApi;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.utils.SimpleHandlerThreadPool;
import com.mogo.realtime.entity.CloudRoadData;
import com.mogo.realtime.entity.MogoSnapshotSetData;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.StatusDescriptor;
import com.mogo.utils.ViewUtils;
@@ -50,13 +50,13 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
super();
MogoApisHandler.getInstance().getApis()
.getStatusManagerApi()
.registerStatusChangedListener( TAG, StatusDescriptor.VR_MODE, this );
.registerStatusChangedListener(TAG, StatusDescriptor.VR_MODE, this);
}
public static SnapshotSetDataDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( SnapshotSetDataDrawer.class ) {
if ( sInstance == null ) {
if (sInstance == null) {
synchronized (SnapshotSetDataDrawer.class) {
if (sInstance == null) {
sInstance = new SnapshotSetDataDrawer();
}
}
@@ -73,24 +73,23 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
return sInstance;
}
private final Map< String, CloudRoadData > mLastPositions = new ConcurrentHashMap<>();
private final Map<String, SocketDownData.CloudRoadDataProto> mLastPositions = new ConcurrentHashMap<>();
private boolean mIsVrMode = false;
/**
* 注册StatusDescriptor.VR_MODE类型VR_MODE状态改变回调
*
* @param descriptor 状态类型
* @param isTrue true - accOn、adas ui show、voice ui show、push ui show、v2x ui show
*/
@Override
public void onStatusChanged( StatusDescriptor descriptor, boolean isTrue ) {
Logger.d( TAG, "%s - %s", descriptor, isTrue );
public void onStatusChanged(StatusDescriptor descriptor, boolean isTrue) {
Logger.d(TAG, "%s - %s", descriptor, isTrue);
mChangeCarModeStatus = true;
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches );
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
mMarkersCaches = new HashMap<>();
if ( mLastPositions != null ) {
mLastPositions.clear();
}
mLastPositions.clear();
AdasRecognizedResultDrawer.getInstance().notifyVrModeChanged(); //清除ADAS old marker data
}
@@ -102,7 +101,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
return mChangeCarModeStatus;
}
public void setChangeCarModeStatus( boolean mChangeCarModeStatus ) {
public void setChangeCarModeStatus(boolean mChangeCarModeStatus) {
this.mChangeCarModeStatus = mChangeCarModeStatus;
}
@@ -112,30 +111,24 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param data 自车周边数据
* @return 清除结果
*/
private boolean clear( MogoSnapshotSetData data ) {
if ( !MogoApisHandler.getInstance().getApis().getStatusManagerApi().isMainPageLaunched() ) {
if ( mMarkersCaches == null ) {
private boolean clear(SocketDownData.LauncherSnapshotProto data) {
if (!MogoApisHandler.getInstance().getApis().getStatusManagerApi().isMainPageLaunched()) {
if (mMarkersCaches == null) {
return false;
}
if ( mMarkersCaches != null ) {
mMarkersCaches.clear();
}
if ( mLastPositions != null ) {
mLastPositions.clear();
}
sendMessage( MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_CLOUD_DATA );
mMarkersCaches.clear();
mLastPositions.clear();
sendMessage(MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_CLOUD_DATA);
return true;
}
if ( data == null || (
( data.getAllList() == null || data.getAllList().isEmpty() ) &&
( data.getNearList() == null || data.getNearList().isEmpty() ) ) ) {
if ( mMarkersCaches != null ) {
if (data == null || (
(data.getAllListList() == null || data.getAllListList().isEmpty()) &&
(data.getNearListList() == null || data.getNearListList().isEmpty()))) {
if (mMarkersCaches != null) {
mMarkersCaches.clear();
}
if ( mLastPositions != null ) {
mLastPositions.clear();
}
sendMessage( MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_CLOUD_DATA );
mLastPositions.clear();
sendMessage(MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_CLOUD_DATA);
return true;
}
return false;
@@ -146,28 +139,28 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
*
* @param data 自车周边数据
*/
public void renderSnapshotData( MogoSnapshotSetData data ) {
public void renderSnapshotData(SocketDownData.LauncherSnapshotProto data) {
if ( clear( data ) ) {
if (clear(data)) {
return;
}
List< CloudRoadData > allDatumsList = new ArrayList<>();
prepareData( data.getAllList(), allDatumsList );
List<SocketDownData.CloudRoadDataProto> allDatumsList = new ArrayList<>();
prepareData(data.getAllListList(), allDatumsList);
Map< String, IMogoMarker > newMarkersCaches = new HashMap<>( allDatumsList.size() );
List< CloudRoadData > newDiffSet = new ArrayList<>();
Map<String, IMogoMarker> newMarkersCaches = new HashMap<>(allDatumsList.size());
List<SocketDownData.CloudRoadDataProto> newDiffSet = new ArrayList<>();
for ( CloudRoadData cloudRoadData : allDatumsList ) {
if ( isUselessValue( cloudRoadData ) ) {
for (SocketDownData.CloudRoadDataProto cloudRoadData : allDatumsList) {
if (isUselessValue(cloudRoadData)) {
continue;
}
String uniqueKey = cloudRoadData.getUniqueKey();
IMogoMarker marker = mMarkersCaches.remove( uniqueKey );
if ( marker != null && !marker.isDestroyed() ) {
renderSnapshotOneFrame( marker, uniqueKey, cloudRoadData, newMarkersCaches );
String uniqueKey = cloudRoadData.getUuid();
IMogoMarker marker = mMarkersCaches.remove(uniqueKey);
if (marker != null && !marker.isDestroyed()) {
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
} else {
newDiffSet.add( cloudRoadData );
newDiffSet.add(cloudRoadData);
}
}
@@ -181,55 +174,55 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
int size = Math.min(cachedMarkerSize, newDiffSetSize);
// 复用过期 marker
if ( newDiffSetSize > 0 ) {
Iterator< Map.Entry< String, IMogoMarker > > entryIterator = mMarkersCaches.entrySet().iterator();
for ( int i = 0; i < size; i++ ) {
CloudRoadData cloudRoadData = newDiffSet.get( i );
String uniqueKey = cloudRoadData.getUniqueKey();
Map.Entry< String, IMogoMarker > entry = entryIterator.next();
if (newDiffSetSize > 0) {
Iterator<Map.Entry<String, IMogoMarker>> entryIterator = mMarkersCaches.entrySet().iterator();
for (int i = 0; i < size; i++) {
SocketDownData.CloudRoadDataProto cloudRoadData = newDiffSet.get(i);
String uniqueKey = cloudRoadData.getUuid();
Map.Entry<String, IMogoMarker> entry = entryIterator.next();
entryIterator.remove();
CloudRoadData old = mLastPositions.remove( entry.getKey() );
SocketDownData.CloudRoadDataProto old = mLastPositions.remove(entry.getKey());
IMogoMarker marker = entry.getValue();
if ( marker == null ) {
if (marker == null) {
continue;
}
// 更新资源内容
if ( old == null || old.getType() != cloudRoadData.getType() ) {
if (old == null || old.getType() != cloudRoadData.getType()) {
String resIdVal;
int resId = getModelRes( cloudRoadData.getType() );
int resId = getModelRes(cloudRoadData.getType());
resIdVal = resId + "";
String resName = mMarkerCachesResMd5Values.get( resIdVal );
if ( !TextUtils.isEmpty( resName ) ) {
if ( !TextUtils.equals( resName, marker.getMarkerResName() ) ) {
marker.use3DResource( resName );
String resName = mMarkerCachesResMd5Values.get(resIdVal);
if (!TextUtils.isEmpty(resName)) {
if (!TextUtils.equals(resName, marker.getMarkerResName())) {
marker.use3DResource(resName);
}
} else {
resName = marker.use3DResource( resId );
mMarkerCachesResMd5Values.put( resIdVal, resName );
resName = marker.use3DResource(resId);
mMarkerCachesResMd5Values.put(resIdVal, resName);
}
}
renderSnapshotOneFrame( marker, uniqueKey, cloudRoadData, newMarkersCaches );
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
}
// 复用过后还需新增的 marker
for ( int i = size; i < newDiffSetSize; i++ ) {
CloudRoadData cloudRoadData = newDiffSet.get( i );
String uniqueKey = cloudRoadData.getUniqueKey();
IMogoMarker marker = drawSnapshotDataMarker( cloudRoadData );
if ( marker == null ) {
for (int i = size; i < newDiffSetSize; i++) {
SocketDownData.CloudRoadDataProto cloudRoadData = newDiffSet.get(i);
String uniqueKey = cloudRoadData.getUuid();
IMogoMarker marker = drawSnapshotDataMarker(cloudRoadData);
if (marker == null) {
continue;
}
renderSnapshotOneFrame( marker, uniqueKey, cloudRoadData, newMarkersCaches );
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
}
}
if ( cachedMarkerSize - size > 0 ) {
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches );
if (cachedMarkerSize - size > 0) {
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
}
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches );
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
mMarkersCaches = newMarkersCaches;
}
@@ -237,62 +230,68 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
/**
* 判断类型、uuid 等
*
* @param cloudRoadData {@link CloudRoadData}
* @param cloudRoadData {@link SocketDownData.CloudRoadDataProto}
* @return isUselessValue
*/
private boolean isUselessValue( CloudRoadData cloudRoadData ) {
if ( cloudRoadData == null ) {
private boolean isUselessValue(SocketDownData.CloudRoadDataProto cloudRoadData) {
if (cloudRoadData == null) {
return true;
}
if ( !isRenderType( cloudRoadData.getType() ) ) {
if (!isRenderType(cloudRoadData.getType())) {
return true;
}
String uniqueKey = cloudRoadData.getUniqueKey();
String uniqueKey = cloudRoadData.getUuid();
return TextUtils.isEmpty(uniqueKey);
}
/**
* 绘制某个物体的一个数据
*
* @param cloudRoadData {@link CloudRoadData}
* @param cloudRoadData {@link SocketDownData.CloudRoadDataProto}
* @param newSnapshotCaches 缓存数据
*/
private void renderSnapshotOneFrame( IMogoMarker marker, String uniqueKey, final CloudRoadData cloudRoadData, Map< String, IMogoMarker > newSnapshotCaches ) {
private void renderSnapshotOneFrame(IMogoMarker marker, String uniqueKey, SocketDownData.CloudRoadDataProto cloudRoadData, Map<String, IMogoMarker> newSnapshotCaches) {
final long start = System.currentTimeMillis();
CloudRoadData lastPosition = mLastPositions.remove( uniqueKey );
SocketDownData.CloudRoadDataProto lastPosition = mLastPositions.remove(uniqueKey);
double lastLon = -1;
double lastLat = -1;
if ( lastPosition != null ) {
if (lastPosition != null) {
lastLon = lastPosition.getWgslon();
lastLat = lastPosition.getWgslat();
}
double[] matchLonLat = getMatchLonLat( cloudRoadData.getUniqueKey(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), lastLon, lastLat );
cloudRoadData.setWgslon( matchLonLat[0] );
cloudRoadData.setWgslat( matchLonLat[1] );
mLastPositions.put( uniqueKey, cloudRoadData );
double[] matchLonLat = getMatchLonLat(cloudRoadData.getUuid(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), lastLon, lastLat);
newSnapshotCaches.put( uniqueKey, marker );
if ( lastPosition != null ) {
long interval = computeAnimDuration( lastPosition.getSystemTime(), cloudRoadData.getSystemTime(), lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime() );
SocketDownData.CloudRoadDataProto.Builder builder = cloudRoadData.toBuilder();
builder.setWgslon(matchLonLat[0]);
builder.setWgslat(matchLonLat[1]);
final MogoLatLng point = new MogoLatLng( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() );
cloudRoadData = builder.build(); //todo 验证值是否改变
mLastPositions.put(uniqueKey, cloudRoadData);
newSnapshotCaches.put(uniqueKey, marker);
if (lastPosition != null) {
long interval = computeAnimDuration(lastPosition.getSystemTime(), cloudRoadData.getSystemTime(), lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime());
final MogoLatLng point = new MogoLatLng(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
long cost = System.currentTimeMillis() - start;
final long intervalRef = interval - cost;
SimpleHandlerThreadPool.getInstance().postRender( () -> marker.addDynamicAnchorPosition( point, ( float ) cloudRoadData.getHeading(), intervalRef ));
SocketDownData.CloudRoadDataProto finalCloudRoadData = cloudRoadData;
SimpleHandlerThreadPool.getInstance().postRender(() -> marker.addDynamicAnchorPosition(point, (float) finalCloudRoadData.getHeading(), intervalRef));
} else {
marker.setRotateAngle( ( ( float ) cloudRoadData.getHeading() ) );
marker.setPosition( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() );
marker.setRotateAngle(((float) cloudRoadData.getHeading()));
marker.setPosition(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
}
marker.setAnchorColor( getModelRenderColor( cloudRoadData.getType(), cloudRoadData.getSpeed(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading() ) );
marker.setAnchorColor(getModelRenderColor(cloudRoadData.getType(), cloudRoadData.getSpeed(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading()));
if ( shouldShowSpeed( cloudRoadData.getType() ) ) {
if (shouldShowSpeed(cloudRoadData.getType())) {
Message msg = mRenderThreadHandler.obtainMessage();
SpeedData obj = new SpeedData();
obj.context = mContext;
@@ -310,9 +309,9 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param in 输入集合
* @param out 输出集合
*/
private void prepareData( List< CloudRoadData > in, List< CloudRoadData > out ) {
filterData( in );
out.addAll( in );
private void prepareData(List<SocketDownData.CloudRoadDataProto> in, List<SocketDownData.CloudRoadDataProto> out) {
filterData(in);
out.addAll(in);
}
/**
@@ -320,32 +319,32 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
*
* @param data 道路数据集合
*/
private void filterData( List< CloudRoadData > data ) {
if ( data == null || data.isEmpty() ) {
private void filterData(List<SocketDownData.CloudRoadDataProto> data) {
if (data == null || data.isEmpty()) {
return;
}
if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
return;
}
List< CloudRoadData > newList = new ArrayList<>();
for ( CloudRoadData cloudRoadData : data ) {
if ( cloudRoadData.getFromType() != CloudRoadData.FROM_MY_LOCATION ) {
List<SocketDownData.CloudRoadDataProto> newList = new ArrayList<>();
for (SocketDownData.CloudRoadDataProto cloudRoadData : data) {
if (cloudRoadData.getFromType() != SocketDownDataHelper.FROM_MY_LOCATION) {
continue;
}
newList.add( cloudRoadData );
newList.add(cloudRoadData);
}
data.clear();
data.addAll( newList );
data.addAll(newList);
}
/**
* 绑定点击事件
*/
public void bindClickListener( IMogoMarker marker ) {
if ( marker == null || marker.isDestroyed() ) {
public void bindClickListener(IMogoMarker marker) {
if (marker == null || marker.isDestroyed()) {
return;
}
marker.setOnMarkerClickListener( this );
marker.setOnMarkerClickListener(this);
}
/**
@@ -354,45 +353,45 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param data 道路数据
* @return {@link IMogoMarker}
*/
public IMogoMarker drawSnapshotDataMarker( CloudRoadData data ) {
if ( data == null ) {
public IMogoMarker drawSnapshotDataMarker(SocketDownData.CloudRoadDataProto data) {
if (data == null) {
return null;
}
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_CLOUD_DATA )
.anchor( 0.5f, 0.5f )
.rotate( ( float ) data.getHeading() )
.object( data )
.gps( true )
.controlAngle( true )
.position( new MogoLatLng( data.getWgslat(), data.getWgslon() ) );
.owner(DataTypes.TYPE_MARKER_CLOUD_DATA)
.anchor(0.5f, 0.5f)
.rotate((float) data.getHeading())
.object(data)
.gps(true)
.controlAngle(true)
.position(new MogoLatLng(data.getWgslat(), data.getWgslon()));
String resIdVal;
if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
options.set3DMode( true );
options.anchorColor( getModelRenderColor( data.getType(), data.getSpeed(), data.getWgslon(), data.getWgslat(), data.getHeading() ) );
int resId = getModelRes( data.getType() );
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
options.set3DMode(true);
options.anchorColor(getModelRenderColor(data.getType(), data.getSpeed(), data.getWgslon(), data.getWgslat(), data.getHeading()));
int resId = getModelRes(data.getType());
resIdVal = resId + "";
options.resName( mMarkerCachesResMd5Values.get( resIdVal ) );
options.icon3DRes( resId );
options.resName(mMarkerCachesResMd5Values.get(resIdVal));
options.icon3DRes(resId);
} else {
options.set3DMode( false );
View view = inflateView( data );
options.icon( view );
options.set3DMode(false);
View view = inflateView(data);
options.icon(view);
resIdVal = view.getId() + "";
}
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( DataTypes.TYPE_MARKER_CLOUD_DATA, options );
cacheMarkerIconResMd5Val( resIdVal, marker );
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(mContext).addMarker(DataTypes.TYPE_MARKER_CLOUD_DATA, options);
cacheMarkerIconResMd5Val(resIdVal, marker);
if ( !TextUtils.isEmpty( data.getSn() ) ) {
bindClickListener( marker );
if (!TextUtils.isEmpty(data.getSn())) {
bindClickListener(marker);
}
return marker;
}
public String get3DCacheId( String resIdVal ) {
return mMarkerCachesResMd5Values.get( resIdVal );
public String get3DCacheId(String resIdVal) {
return mMarkerCachesResMd5Values.get(resIdVal);
}
/**
@@ -401,12 +400,12 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param data 道路数据
* @return marker
*/
public View inflateView( CloudRoadData data ) {
View rootView = LayoutInflater.from( AbsMogoApplication.getApp() ).inflate( R.layout.module_commons_layout_car, null );
ImageView iv = rootView.findViewById( R.id.module_commons_marker_car_model );
int viewIdLike = get2DModel( data );
iv.setImageResource( viewIdLike );
rootView.setId( viewIdLike );
public View inflateView(SocketDownData.CloudRoadDataProto data) {
View rootView = LayoutInflater.from(AbsMogoApplication.getApp()).inflate(R.layout.module_commons_layout_car, null);
ImageView iv = rootView.findViewById(R.id.module_commons_marker_car_model);
int viewIdLike = get2DModel(data);
iv.setImageResource(viewIdLike);
rootView.setId(viewIdLike);
return rootView;
}
@@ -416,21 +415,21 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param data 道路数据
* @return 2D贴图id
*/
private int get2DModel( CloudRoadData data ) {
switch ( data.getFromType() ) {
case CloudRoadData.FROM_ADAS:
case CloudRoadData.FROM_ROAD_UNIT:
case CloudRoadData.FROM_MY_LOCATION:
private int get2DModel(SocketDownData.CloudRoadDataProto data) {
switch (data.getFromType()) {
case SocketDownDataHelper.FROM_ADAS:
case SocketDownDataHelper.FROM_ROAD_UNIT:
case SocketDownDataHelper.FROM_MY_LOCATION:
default:
return R.drawable.icon_map_marker_car_gray;
}
}
@Override
public boolean onMarkerClicked( IMogoMarker marker ) {
if ( marker != null && !marker.isDestroyed() ) {
if ( marker.getObject() instanceof CloudRoadData ) {
showCarCallPanel( ( ( CloudRoadData ) marker.getObject() ) );
public boolean onMarkerClicked(IMogoMarker marker) {
if (marker != null && !marker.isDestroyed()) {
if (marker.getObject() instanceof SocketDownData.CloudRoadDataProto) {
showCarCallPanel(((SocketDownData.CloudRoadDataProto) marker.getObject()));
}
}
return true;
@@ -441,46 +440,46 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
*
* @param data 道路数据
*/
private void showCarCallPanel( CloudRoadData data ) {
private void showCarCallPanel(SocketDownData.CloudRoadDataProto data) {
MogoDriverInfo driverInfo = new MogoDriverInfo();
driverInfo.setLat( data.getLat() );
driverInfo.setLon( data.getLon() );
driverInfo.setSn( data.getSn() );
driverInfo.setLat(data.getLat());
driverInfo.setLon(data.getLon());
driverInfo.setSn(data.getSn());
ICarsChattingProvider carChatting = CallChatApi.getInstance().getApiProvider();
if ( carChatting != null ) {
if (carChatting != null) {
try {
carChatting.showUserWindow( TAG, driverInfo, mContext );
} catch ( Exception e ) {
Logger.e( TAG, e, "showCarCallPanel" );
carChatting.showUserWindow(TAG, driverInfo, mContext);
} catch (Exception e) {
Logger.e(TAG, e, "showCarCallPanel");
}
}
}
public void changeIconResourceIfNecessary( CloudRoadData cloudRoadData, IMogoMarker marker ) {
if ( isChangeCarModeStatus() ) {
setChangeCarModeStatus( false );
if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
marker.getMogoMarkerOptions().set3DMode( true );
int resId = getModelRes( cloudRoadData.getType() );
String resName = get3DCacheId( resId + "" );
if ( TextUtils.isEmpty( resName ) ) {
marker.use3DResource( resId );
cacheMarkerIconResMd5Val( resId + "", marker );
public void changeIconResourceIfNecessary(SocketDownData.CloudRoadDataProto cloudRoadData, IMogoMarker marker) {
if (isChangeCarModeStatus()) {
setChangeCarModeStatus(false);
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
marker.getMogoMarkerOptions().set3DMode(true);
int resId = getModelRes(cloudRoadData.getType());
String resName = get3DCacheId(resId + "");
if (TextUtils.isEmpty(resName)) {
marker.use3DResource(resId);
cacheMarkerIconResMd5Val(resId + "", marker);
} else {
marker.use3DResource( resName );
marker.use3DResource(resName);
}
} else {
marker.getMogoMarkerOptions().set3DMode( false );
View view = inflateView( cloudRoadData );
marker.getMogoMarkerOptions().set3DMode(false);
View view = inflateView(cloudRoadData);
int resId = view.getId();
String resName = get3DCacheId( resId + "" );
if ( TextUtils.isEmpty( resName ) ) {
marker.setIcon( ViewUtils.fromView( view ) );
cacheMarkerIconResMd5Val( resId + "", marker );
String resName = get3DCacheId(resId + "");
if (TextUtils.isEmpty(resName)) {
marker.setIcon(ViewUtils.fromView(view));
cacheMarkerIconResMd5Val(resId + "", marker);
} else {
marker.use2DResource( resName );
marker.use2DResource(resName);
}
}
}

View File

@@ -2,7 +2,7 @@ package com.mogo.module.common.uploadintime;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.realtime.entity.CloudLocationInfo;
import com.mogo.service.locationinfo.CloudLocationInfo;
import com.mogo.utils.logger.Logger;
import org.json.JSONObject;