优化显示逻辑
This commit is contained in:
@@ -2,10 +2,8 @@ package com.mogo.module.common.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
@@ -13,6 +11,7 @@ import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -27,6 +26,8 @@ public
|
||||
*/
|
||||
class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
|
||||
private static final String TAG = "AdasRecognizedResultDrawer";
|
||||
|
||||
private static volatile AdasRecognizedResultDrawer sInstance;
|
||||
|
||||
private final Context mContext;
|
||||
@@ -105,8 +106,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
// }
|
||||
|
||||
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
|
||||
|
||||
ADASRecognizedResult lastPosition = mLastPositions.put( uniqueKey, recognizedListResult );
|
||||
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
marker = drawAdasRecognizedDataMarker( recognizedListResult );
|
||||
if ( marker == null ) {
|
||||
@@ -116,12 +117,9 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
newAdasRecognizedMarkersCaches.put( uniqueKey, marker );
|
||||
if ( lastPosition != null ) {
|
||||
MogoLatLng endLatLon = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon );
|
||||
long interval = recognizedListResult.systemTime - lastPosition.systemTime;
|
||||
if ( interval < 45 ) {
|
||||
interval = 45;
|
||||
}
|
||||
interval -= 25;
|
||||
long interval = computeAnimDuration( lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime );
|
||||
marker.addDynamicAnchorPosition( endLatLon, interval );
|
||||
Logger.d( TAG, "anim duration: %s", interval );
|
||||
} else {
|
||||
marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) );
|
||||
marker.setPosition( recognizedListResult.lat, recognizedListResult.lon );
|
||||
|
||||
@@ -196,4 +196,23 @@ class BaseDrawer {
|
||||
.getMapUIController()
|
||||
.matchRoad( lon, lat, angle, true, isRtk );
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用系统时间或卫星时间计算出动画的运动时间
|
||||
*
|
||||
* @param lastSystemTime
|
||||
* @param curSystemTime
|
||||
* @param lastSatelliteTime
|
||||
* @param curSatelliteTime
|
||||
* @return
|
||||
*/
|
||||
protected long computeAnimDuration( long lastSystemTime, long curSystemTime, long lastSatelliteTime, long curSatelliteTime ) {
|
||||
long systemTimeInterval = curSystemTime - lastSystemTime - 25;
|
||||
long satelliteTimeInterval = curSatelliteTime - lastSatelliteTime - 25;
|
||||
long interval = systemTimeInterval < satelliteTimeInterval || satelliteTimeInterval == 0 ? systemTimeInterval : satelliteTimeInterval;
|
||||
if ( interval < 45 ) {
|
||||
interval = 45;
|
||||
}
|
||||
return interval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
@@ -16,16 +15,17 @@ import com.mogo.module.common.MogoApisHandler;
|
||||
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.kt.ScopeManager;
|
||||
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;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.carchattingprovider.ICarsChattingProvider;
|
||||
import com.zhidao.carchattingprovider.MogoDriverInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -78,6 +78,8 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
|
||||
private final Map< String, CloudRoadData > mLastPositions = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map< String, Long > mLastPositionExecutionTime = new HashMap<>();
|
||||
|
||||
private boolean mIsVrMode = false;
|
||||
|
||||
@Override
|
||||
@@ -142,23 +144,6 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
prepareData( data.getAllList(), allDatumsList );
|
||||
Map< String, IMogoMarker > newAdasRecognizedMarkersCaches = new ConcurrentHashMap<>();
|
||||
for ( CloudRoadData cloudRoadData : allDatumsList ) {
|
||||
if ( cloudRoadData == null ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 暂时只显示车辆
|
||||
if ( TextUtils.isEmpty( cloudRoadData.getSn() ) ) {
|
||||
if ( !isCarType( cloudRoadData.getType() ) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
String uniqueKey = cloudRoadData.getUniqueKey();
|
||||
if ( TextUtils.isEmpty( uniqueKey )
|
||||
// 本地过滤重复下发的adas识别车辆
|
||||
|| AdasRecognizedResultDrawer.getInstance().hasCached( uniqueKey ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// double[] matchedPoint = matchRoad( cloudRoadData.getLon(),
|
||||
// cloudRoadData.getLat(),
|
||||
@@ -169,56 +154,75 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
|
||||
// cloudRoadData.setLon( matchedPoint[0] );
|
||||
// cloudRoadData.setLat( matchedPoint[1] );
|
||||
// }
|
||||
|
||||
IMogoMarker marker = mCloudSnapshotMarkersCaches.remove( uniqueKey );
|
||||
CloudRoadData lastPosition = mLastPositions.put( uniqueKey, cloudRoadData );
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
|
||||
marker = drawSnapshotDataMarker( cloudRoadData );
|
||||
if ( marker == null ) {
|
||||
continue;
|
||||
}
|
||||
if ( !TextUtils.isEmpty( cloudRoadData.getSn() ) ) {
|
||||
bindClickListener( marker );
|
||||
}
|
||||
}
|
||||
|
||||
newAdasRecognizedMarkersCaches.put( uniqueKey, marker );
|
||||
|
||||
if ( mChangeCarModeStatus ) {
|
||||
mIsVrMode = MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode();
|
||||
mChangeCarModeStatus = false;
|
||||
if ( mIsVrMode ) {
|
||||
marker.getMogoMarkerOptions().set3DMode( true );
|
||||
marker.use3DResource( getVrModelResId( cloudRoadData ) );
|
||||
} else {
|
||||
marker.getMogoMarkerOptions().set3DMode( false );
|
||||
marker.setIcon( ViewUtils.fromView( inflateView( cloudRoadData ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( lastPosition != null ) {
|
||||
if ( lastPosition.equals( cloudRoadData ) ) {
|
||||
marker.setRotateAngle( ( float ) cloudRoadData.getHeading() );
|
||||
marker.setPosition( cloudRoadData.getLat(), cloudRoadData.getLon() );
|
||||
} else {
|
||||
long interval = cloudRoadData.getSystemTime() - lastPosition.getSystemTime();
|
||||
long interval2 = cloudRoadData.getSatelliteTime() - lastPosition.getSatelliteTime();
|
||||
interval2 = interval < interval2 || interval2 == 0 ? interval : interval2;
|
||||
if ( interval2 < 45 ) {
|
||||
interval2 = 45;
|
||||
}
|
||||
interval2 -= 25;
|
||||
marker.addDynamicAnchorPosition( new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ), interval2 );
|
||||
}
|
||||
} else {
|
||||
marker.setRotateAngle( ( float ) cloudRoadData.getHeading() );
|
||||
marker.setPosition( cloudRoadData.getLat(), cloudRoadData.getLon() );
|
||||
}
|
||||
showSelfSpeed( mContext, marker, cloudRoadData.getSpeed(), MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() );
|
||||
ScopeManager.INSTANCE.mainScope( () -> {
|
||||
rendCarOneFrame( cloudRoadData, newAdasRecognizedMarkersCaches );
|
||||
} );
|
||||
}
|
||||
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mCloudSnapshotMarkersCaches );
|
||||
mCloudSnapshotMarkersCaches = newAdasRecognizedMarkersCaches;
|
||||
ScopeManager.INSTANCE.mainScope( () -> {
|
||||
sendMessage( MSG_REMOVE_DIRTY_MARKERS, mCloudSnapshotMarkersCaches );
|
||||
mCloudSnapshotMarkersCaches = newAdasRecognizedMarkersCaches;
|
||||
} );
|
||||
}
|
||||
|
||||
private void rendCarOneFrame( CloudRoadData cloudRoadData, Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) {
|
||||
|
||||
if ( cloudRoadData == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 暂时只显示车辆
|
||||
if ( TextUtils.isEmpty( cloudRoadData.getSn() ) ) {
|
||||
if ( !isCarType( cloudRoadData.getType() ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String uniqueKey = cloudRoadData.getUniqueKey();
|
||||
if ( TextUtils.isEmpty( uniqueKey )
|
||||
// 本地过滤重复下发的adas识别车辆
|
||||
|| AdasRecognizedResultDrawer.getInstance().hasCached( uniqueKey ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
IMogoMarker marker = mCloudSnapshotMarkersCaches.remove( uniqueKey );
|
||||
CloudRoadData lastPosition = mLastPositions.put( uniqueKey, cloudRoadData );
|
||||
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
marker = drawSnapshotDataMarker( cloudRoadData );
|
||||
if ( marker == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !TextUtils.isEmpty( cloudRoadData.getSn() ) ) {
|
||||
bindClickListener( marker );
|
||||
}
|
||||
}
|
||||
|
||||
newAdasRecognizedMarkersCaches.put( uniqueKey, marker );
|
||||
//
|
||||
// if ( mChangeCarModeStatus ) {
|
||||
// mIsVrMode = MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode();
|
||||
// mChangeCarModeStatus = false;
|
||||
// if ( mIsVrMode ) {
|
||||
// marker.getMogoMarkerOptions().set3DMode( true );
|
||||
// marker.use3DResource( getVrModelResId( cloudRoadData ) );
|
||||
// } else {
|
||||
// marker.getMogoMarkerOptions().set3DMode( false );
|
||||
// marker.setIcon( ViewUtils.fromView( inflateView( cloudRoadData ) ) );
|
||||
// }
|
||||
// }
|
||||
|
||||
if ( lastPosition != null && !lastPosition.equals( cloudRoadData ) ) {
|
||||
long interval = computeAnimDuration( lastPosition.getSystemTime(), cloudRoadData.getSystemTime(), lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime() );
|
||||
interval = System.currentTimeMillis() - mLastPositionExecutionTime.get( uniqueKey );
|
||||
marker.addDynamicAnchorPosition( new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ), interval );
|
||||
Logger.d( TAG, "anim duration: %s", interval );
|
||||
} else {
|
||||
marker.setRotateAngle( ( float ) cloudRoadData.getHeading() );
|
||||
marker.setPosition( cloudRoadData.getLat(), cloudRoadData.getLon() );
|
||||
Logger.d( TAG, "设置点位置" );
|
||||
}
|
||||
mLastPositionExecutionTime.put( uniqueKey, System.currentTimeMillis() );
|
||||
showSelfSpeed( mContext, marker, cloudRoadData.getSpeed(), MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.mogo.module.common.kt
|
||||
|
||||
import androidx.annotation.RestrictTo
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2021/3/3
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
object ScopeManager {
|
||||
|
||||
private var mScope = MainScope()
|
||||
private var mThreadScope: RestrictTo.Scope? = null
|
||||
|
||||
fun mainScope(runnable: Runnable?) {
|
||||
mScope.launch(Dispatchers.Default) {
|
||||
runnable?.apply {
|
||||
run()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user