优化显示逻辑
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
@@ -15,6 +13,7 @@ import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.module.common.utils.SimpleHandlerThreadPool;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -22,6 +21,7 @@ import com.mogo.utils.logger.Logger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public
|
||||
@@ -39,31 +39,31 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private Handler mPointSettingHandler = null;
|
||||
public static final int MSG_POINTS_SETTING = 9;
|
||||
public static final int MSG_SET_POINT = 10;
|
||||
public static final int MSG_SET_SPEED = 11;
|
||||
private Handler mRenderThreadHandler = null;
|
||||
public static final int MSG_MOVE_POINTS = 9;
|
||||
public static final int MSG_MOVE_POINT = 10;
|
||||
public static final int MSG_DISPLAY_SPEED = 11;
|
||||
|
||||
private AdasRecognizedResultDrawer() {
|
||||
public AdasRecognizedResultDrawer() {
|
||||
super();
|
||||
mContext = AbsMogoApplication.getApp();
|
||||
initHandler();
|
||||
}
|
||||
|
||||
private void initHandler() {
|
||||
mPointSettingHandler = new Handler( WorkThreadHandler.newInstance( "moving-points-thread" ).getLooper() ) {
|
||||
mRenderThreadHandler = new Handler( WorkThreadHandler.newInstance( "render-thread-" + new Random().nextLong() ).getLooper() ) {
|
||||
@Override
|
||||
public void handleMessage( Message msg ) {
|
||||
super.handleMessage( msg );
|
||||
if ( msg.what == MSG_POINTS_SETTING ) {
|
||||
if ( msg.what == MSG_MOVE_POINTS ) {
|
||||
if ( msg.obj instanceof MovingPoints ) {
|
||||
startSettingPointLooper( ( ( MovingPoints ) msg.obj ) );
|
||||
}
|
||||
} else if ( msg.what == MSG_SET_POINT ) {
|
||||
} else if ( msg.what == MSG_MOVE_POINT ) {
|
||||
if ( msg.obj instanceof MovingPoint ) {
|
||||
moveMarker( ( ( MovingPoint ) msg.obj ), msg.arg1 );
|
||||
}
|
||||
} else if ( msg.what == MSG_SET_SPEED ) {
|
||||
} else if ( msg.what == MSG_DISPLAY_SPEED ) {
|
||||
if ( msg.obj instanceof SpeedData ) {
|
||||
showSpeed( ( SpeedData ) msg.obj );
|
||||
}
|
||||
@@ -81,14 +81,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
List< MovingPoint > points = data.points;
|
||||
for ( int i = 0; i < points.size(); i++ ) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MSG_SET_POINT;
|
||||
msg.what = MSG_MOVE_POINT;
|
||||
msg.obj = points.get( i );
|
||||
if ( i == 0 || i == points.size() - 1 ) {
|
||||
msg.arg1 = R.drawable.sr;
|
||||
} else {
|
||||
msg.arg1 = R.drawable.sy;
|
||||
}
|
||||
mPointSettingHandler.sendMessageDelayed( msg, points.get( i ).delay );
|
||||
mRenderThreadHandler.sendMessageDelayed( msg, points.get( i ).delay );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +151,11 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
|
||||
clearOldMarker();
|
||||
return;
|
||||
}
|
||||
|
||||
Map< String, IMogoMarker > newAdasRecognizedMarkersCaches = new HashMap<>();
|
||||
for ( ADASRecognizedResult recognizedListResult : resultList ) {
|
||||
if ( recognizedListResult == null ) {
|
||||
@@ -181,6 +186,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.lon,
|
||||
@@ -209,6 +215,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
recognizedListResult.lat = matchedPoint[1];
|
||||
}
|
||||
}
|
||||
Logger.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
|
||||
|
||||
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
|
||||
ADASRecognizedResult lastPosition = mLastPositions.put( uniqueKey, recognizedListResult );
|
||||
@@ -230,21 +237,30 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
startPoint.angle = ( float ) lastPosition.heading;
|
||||
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
MovingPoint endPoint = new MovingPoint();
|
||||
final MovingPoint endPoint = new MovingPoint();
|
||||
endPoint.point = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon );
|
||||
endPoint.marker = marker;
|
||||
endPoint.angle = ( float ) recognizedListResult.heading;
|
||||
interval -= cost;
|
||||
endPoint.delay = interval;
|
||||
|
||||
List< MovingPoint > points = interpolate( startPoint, endPoint, interval );
|
||||
Message msg = new Message();
|
||||
MovingPoints obj = new MovingPoints();
|
||||
obj.points = points;
|
||||
msg.obj = obj;
|
||||
msg.what = MSG_POINTS_SETTING;
|
||||
mPointSettingHandler.sendMessage( msg );
|
||||
Logger.d( TAG, "anim duration: %s, points size = %s", interval, points.size() );
|
||||
// method 1
|
||||
final IMogoMarker renderRef = marker;
|
||||
final long intervalRef = interval;
|
||||
SimpleHandlerThreadPool.getInstance().postRender( () -> {
|
||||
renderRef.addDynamicAnchorPosition( endPoint.point, intervalRef );
|
||||
} );
|
||||
|
||||
// method 2
|
||||
// List< MovingPoint > points = interpolate( startPoint, endPoint, interval );
|
||||
// Message msg = new Message();
|
||||
// MovingPoints obj = new MovingPoints();
|
||||
// obj.points = points;
|
||||
// msg.obj = obj;
|
||||
// msg.what = MSG_MOVE_POINTS;
|
||||
// mRenderThreadHandler.sendMessage( msg );
|
||||
// Logger.d( TAG, "anim duration: %s, points size = %s", interval, points.size() );
|
||||
|
||||
} else {
|
||||
marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) );
|
||||
marker.setPosition( recognizedListResult.lat, recognizedListResult.lon );
|
||||
@@ -255,8 +271,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
obj.marker = marker;
|
||||
obj.speed = recognizedListResult.speed;
|
||||
msg.obj = obj;
|
||||
msg.what = MSG_SET_SPEED;
|
||||
mPointSettingHandler.sendMessage( msg );
|
||||
msg.what = MSG_DISPLAY_SPEED;
|
||||
mRenderThreadHandler.sendMessage( msg );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,7 +323,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
/**
|
||||
* 清除旧的 marker 数据
|
||||
*/
|
||||
private void clearOldMarker() {
|
||||
public void clearOldMarker() {
|
||||
if ( mAdasRecognizedMarkersCaches != null ) {
|
||||
mAdasRecognizedMarkersCaches.clear();
|
||||
}
|
||||
@@ -316,5 +332,4 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
}
|
||||
sendMessage( MSG_REMOVE_DIRTY_MARKERS, DataTypes.TYPE_MARKER_ADAS );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,12 @@ class BaseDrawer {
|
||||
/**
|
||||
* 地图刷新频率
|
||||
*/
|
||||
public static final int MAP_RENDER_FRAME_FREQUENCY = 25;
|
||||
public static final int MAP_RENDER_FRAME_FREQUENCY = 30;
|
||||
|
||||
/**
|
||||
* 移动点的时间间隔
|
||||
*/
|
||||
public static final int MAP_MARKER_MOVE_INTERVAL = MAP_RENDER_FRAME_FREQUENCY;
|
||||
|
||||
/**
|
||||
* 地图内部资源md5缓存,便于资源复用
|
||||
@@ -113,7 +118,6 @@ class BaseDrawer {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private TextView mSpeedView = null;
|
||||
|
||||
/**
|
||||
@@ -160,7 +164,7 @@ class BaseDrawer {
|
||||
*
|
||||
* @param dirtyMarkers
|
||||
*/
|
||||
private static void removeDirtyMarkers( Map< String, IMogoMarker > dirtyMarkers ) {
|
||||
protected static void removeDirtyMarkers( Map< String, IMogoMarker > dirtyMarkers ) {
|
||||
if ( dirtyMarkers == null || dirtyMarkers.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
@@ -267,7 +271,7 @@ class BaseDrawer {
|
||||
double lat = start.point.lat + latStep * ( i + 1 );
|
||||
MovingPoint pd = new MovingPoint();
|
||||
pd.point = new MogoLatLng( lat, lon );
|
||||
pd.delay = ( i + i ) * MAP_RENDER_FRAME_FREQUENCY;
|
||||
pd.delay = ( i + i ) * MAP_MARKER_MOVE_INTERVAL;
|
||||
pd.angle = ( float ) _angle;
|
||||
pd.marker = start.marker;
|
||||
arrayList.add( pd );
|
||||
|
||||
Reference in New Issue
Block a user