balabala~~~
This commit is contained in:
@@ -9,21 +9,21 @@ public
|
||||
*/
|
||||
enum AdasRecognizedType {
|
||||
//背景
|
||||
classIdBackground( "background",0 ),
|
||||
classIdBackground( "background", 0 ),
|
||||
//人
|
||||
classIdPerson( "person",1 ),
|
||||
classIdPerson( "person", 1 ),
|
||||
//自行车
|
||||
classIdBicycle( "bicycle",2 ),
|
||||
classIdBicycle( "bicycle", 2 ),
|
||||
//小轿车
|
||||
classIdCar( "car",3 ),
|
||||
classIdCar( "car", 3 ),
|
||||
//摩托车
|
||||
classIdMoto( "moto",4 ),
|
||||
classIdMoto( "moto", 4 ),
|
||||
//红绿灯
|
||||
classIdTrafficSign( "traffic_sign",5 ),
|
||||
classIdTrafficSign( "traffic_sign", 5 ),
|
||||
//bus
|
||||
classIdTrafficBus( "traffic_bus",6 ),
|
||||
classIdTrafficBus( "traffic_bus", 6 ),
|
||||
//track
|
||||
classIdTrafficTruck( "traffic_truck",8 );
|
||||
classIdTrafficTruck( "traffic_truck", 8 );
|
||||
|
||||
AdasRecognizedType( int code ) {
|
||||
this.code = code;
|
||||
@@ -42,6 +42,9 @@ enum AdasRecognizedType {
|
||||
}
|
||||
|
||||
public static AdasRecognizedType valueFrom( int code ) {
|
||||
if ( code == 0 ) {
|
||||
return classIdCar;
|
||||
}
|
||||
for ( AdasRecognizedType value : AdasRecognizedType.values() ) {
|
||||
if ( value.code == code ) {
|
||||
return value;
|
||||
|
||||
@@ -8,16 +8,22 @@ public
|
||||
* 描述
|
||||
*/
|
||||
enum SafeType {
|
||||
Normal( "安全" ),
|
||||
SpeedWarm( "注意/超速" ),
|
||||
DistanceWarm( "注意/保持车距" ),
|
||||
SpeedDangerous( "危险/严重超速" ),
|
||||
DistanceDangerous( "危险/距离过近" );
|
||||
Normal( "normal", "安全" ),
|
||||
SpeedWarm( "warm", "注意/超速" ),
|
||||
DistanceWarm( "warm", "注意/保持车距" ),
|
||||
SpeedDangerous( "dangerous", "危险/严重超速" ),
|
||||
DistanceDangerous( "dangerous", "危险/距离过近" );
|
||||
|
||||
private String msg;
|
||||
private String res;
|
||||
|
||||
SafeType( String msg ) {
|
||||
SafeType( String res, String msg ) {
|
||||
this.msg = msg;
|
||||
this.res = res;
|
||||
}
|
||||
|
||||
public String getRes() {
|
||||
return res;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
|
||||
@@ -9,7 +9,7 @@ public
|
||||
*/
|
||||
enum VisionMode {
|
||||
|
||||
Machine( "user" ),
|
||||
Machine( "machine" ),
|
||||
User( "user" );
|
||||
|
||||
private String res;
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.data.BaseData;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
@@ -36,7 +37,7 @@ public
|
||||
*
|
||||
* 绘制adas近景识别到的车辆
|
||||
*/
|
||||
class AdasRecognizedResultDrawer {
|
||||
class AdasRecognizedResultDrawer extends BaseDrawer {
|
||||
|
||||
private static volatile AdasRecognizedResultDrawer sInstance;
|
||||
|
||||
@@ -183,39 +184,17 @@ class AdasRecognizedResultDrawer {
|
||||
|
||||
private View inflateView( ADASRecognizedListResult data, boolean machineVision, double curSpeed ) {
|
||||
View rootView = LayoutInflater.from( AbsMogoApplication.getApp() ).inflate( R.layout.module_commons_layout_car, null );
|
||||
SafeType safeType = getSafeType( data, curSpeed );
|
||||
SafeType safeType = getSafeType( data.distanceX, data.distanceY, data.speed, curSpeed );
|
||||
TextView tv = rootView.findViewById( R.id.module_commons_marker_car_speed );
|
||||
tv.setText( safeType.getMsg() );
|
||||
ImageView iv = rootView.findViewById( R.id.module_commons_marker_car_model );
|
||||
iv.setImageResource( MarkerResourceManager.getMarkerDrawableResId(
|
||||
machineVision ? VisionMode.Machine : VisionMode.User,
|
||||
AdasRecognizedType.valueFrom( data.type ),
|
||||
getCarModelType()
|
||||
getCarModelType(),
|
||||
safeType
|
||||
) );
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private SafeType getSafeType( ADASRecognizedListResult data, double curSpeed ) {
|
||||
if ( data == null ) {
|
||||
return SafeType.Normal;
|
||||
}
|
||||
if ( data.distanceY < 0.5 || data.distanceY < 0.5 ) {
|
||||
return SafeType.DistanceDangerous;
|
||||
}
|
||||
if ( data.speed > curSpeed * 1.5 ) {
|
||||
return SafeType.SpeedDangerous;
|
||||
}
|
||||
if ( data.distanceY < 1 || data.distanceY < 1 ) {
|
||||
return SafeType.DistanceDangerous;
|
||||
}
|
||||
if ( data.speed > curSpeed * 1.1 ) {
|
||||
return SafeType.DistanceWarm;
|
||||
}
|
||||
return SafeType.Normal;
|
||||
}
|
||||
|
||||
private CarModelType getCarModelType() {
|
||||
return CarModelType.Self;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import com.mogo.module.common.constants.CarModelType;
|
||||
import com.mogo.module.common.constants.SafeType;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/30
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class BaseDrawer {
|
||||
|
||||
public static final double BOUND_DISTANCE_DANGEROUS = 0.5;
|
||||
public static final double BOUND_SPEED_DANGEROUS = 1.5;
|
||||
|
||||
public static final double BOUND_DISTANCE_WARM = 1;
|
||||
public static final double BOUND_SPEED_WARM = 1.1;
|
||||
|
||||
/**
|
||||
* 安全类型
|
||||
*
|
||||
* @param distance
|
||||
* @param speed
|
||||
* @param curSpeed
|
||||
* @return
|
||||
*/
|
||||
protected SafeType getSafeType( double distance, double speed, double curSpeed ) {
|
||||
if ( distance < BOUND_DISTANCE_DANGEROUS ) {
|
||||
return SafeType.DistanceDangerous;
|
||||
}
|
||||
if ( speed > curSpeed * BOUND_SPEED_DANGEROUS ) {
|
||||
return SafeType.SpeedDangerous;
|
||||
}
|
||||
if ( distance < BOUND_DISTANCE_WARM ) {
|
||||
return SafeType.DistanceDangerous;
|
||||
}
|
||||
if ( speed > curSpeed * BOUND_SPEED_WARM ) {
|
||||
return SafeType.DistanceWarm;
|
||||
}
|
||||
return SafeType.Normal;
|
||||
}
|
||||
|
||||
|
||||
protected SafeType getSafeType( double distanceX, double distanceY, double speed, double curSpeed ) {
|
||||
if ( distanceX < BOUND_DISTANCE_DANGEROUS || distanceY < BOUND_DISTANCE_DANGEROUS ) {
|
||||
return SafeType.DistanceDangerous;
|
||||
}
|
||||
if ( speed > curSpeed * BOUND_SPEED_DANGEROUS ) {
|
||||
return SafeType.SpeedDangerous;
|
||||
}
|
||||
if ( distanceX < BOUND_DISTANCE_WARM || distanceY < BOUND_DISTANCE_WARM ) {
|
||||
return SafeType.DistanceWarm;
|
||||
}
|
||||
if ( speed > curSpeed * BOUND_SPEED_WARM ) {
|
||||
return SafeType.SpeedWarm;
|
||||
}
|
||||
return SafeType.Normal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 车模
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected CarModelType getCarModelType() {
|
||||
// 根据车道、行驶方向等计算出选用哪个车模图片
|
||||
return CarModelType.Other;
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,9 @@ class MarkerDrawer {
|
||||
if ( !existMap.containsKey( sn ) ) {
|
||||
IMogoMarker dirtyMarker = allMap.get( sn );
|
||||
allCarsList.remove( dirtyMarker );
|
||||
dirtyMarker.destroy();
|
||||
if ( dirtyMarker != null ) {
|
||||
dirtyMarker.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
allMap.clear();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -37,7 +39,7 @@ public
|
||||
*
|
||||
* 云端数据绘制
|
||||
*/
|
||||
class SnapshotSetDataDrawer {
|
||||
class SnapshotSetDataDrawer extends BaseDrawer {
|
||||
|
||||
private static final String TAG = "SnapshotSetDataDrawer";
|
||||
|
||||
@@ -110,6 +112,8 @@ class SnapshotSetDataDrawer {
|
||||
continue;
|
||||
}
|
||||
mCloudSnapshotMarkersCaches.put( uniqueKey, marker );
|
||||
} else {
|
||||
marker.setIcon( fromView( inflateView( cloudRoadData, machineVision, data.curSpeed ) ) );
|
||||
}
|
||||
if ( marker.getObject() instanceof MogoLatLng ) {
|
||||
marker.setPosition( ( ( MogoLatLng ) marker.getObject() ).lat, ( ( MogoLatLng ) marker.getObject() ).lon );
|
||||
@@ -197,39 +201,41 @@ class SnapshotSetDataDrawer {
|
||||
|
||||
private View inflateView( CloudRoadData data, boolean machineVision, double curSpeed ) {
|
||||
View rootView = LayoutInflater.from( AbsMogoApplication.getApp() ).inflate( R.layout.module_commons_layout_car, null );
|
||||
SafeType safeType = getSafeType( data, curSpeed );
|
||||
SafeType safeType = getSafeType( data.getDistance(), data.getSpeed(), curSpeed );
|
||||
TextView tv = rootView.findViewById( R.id.module_commons_marker_car_speed );
|
||||
tv.setText( safeType.getMsg() );
|
||||
// 机器视觉展示速度,用户视觉展示安全类型
|
||||
tv.setText( machineVision ? String.valueOf( data.getSpeed() ) : safeType.getMsg() );
|
||||
ImageView iv = rootView.findViewById( R.id.module_commons_marker_car_model );
|
||||
iv.setImageResource( MarkerResourceManager.getMarkerDrawableResId(
|
||||
machineVision ? VisionMode.Machine : VisionMode.User,
|
||||
AdasRecognizedType.valueFrom( data.getType() ),
|
||||
getCarModelType()
|
||||
getCarModelType(),
|
||||
safeType
|
||||
) );
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private SafeType getSafeType( CloudRoadData data, double curSpeed ) {
|
||||
if ( data == null ) {
|
||||
return SafeType.Normal;
|
||||
}
|
||||
if ( data.getDistance() < 0.5 ) {
|
||||
return SafeType.DistanceDangerous;
|
||||
}
|
||||
if ( data.getSpeed() > curSpeed * 1.5 ) {
|
||||
return SafeType.SpeedDangerous;
|
||||
}
|
||||
if ( data.getDistance() < 1 ) {
|
||||
return SafeType.DistanceDangerous;
|
||||
}
|
||||
if ( data.getSpeed() > curSpeed * 1.1 ) {
|
||||
return SafeType.DistanceWarm;
|
||||
}
|
||||
return SafeType.Normal;
|
||||
private Bitmap fromView( View view ) {
|
||||
view.setDrawingCacheEnabled( true );
|
||||
processChildView( view );
|
||||
view.destroyDrawingCache();
|
||||
view.measure( View.MeasureSpec.makeMeasureSpec( 0, View.MeasureSpec.UNSPECIFIED ), View.MeasureSpec.makeMeasureSpec( 0, View.MeasureSpec.UNSPECIFIED ) );
|
||||
view.layout( 0, 0, view.getMeasuredWidth(), view.getMeasuredHeight() );
|
||||
Bitmap bitmap = null;
|
||||
return ( bitmap = view.getDrawingCache() ) != null ? bitmap.copy( Bitmap.Config.ARGB_8888, false ) : null;
|
||||
}
|
||||
|
||||
private CarModelType getCarModelType() {
|
||||
// 根据车道、行驶方向等计算出选用哪个车模图片
|
||||
return CarModelType.Other;
|
||||
private void processChildView( View view ) {
|
||||
if ( !( view instanceof ViewGroup ) ) {
|
||||
if ( view instanceof TextView ) {
|
||||
( ( TextView ) view ).setHorizontallyScrolling( false );
|
||||
}
|
||||
|
||||
} else {
|
||||
for ( int var1 = 0; var1 < ( ( ViewGroup ) view ).getChildCount(); ++var1 ) {
|
||||
processChildView( ( ( ViewGroup ) view ).getChildAt( var1 ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.constants.AdasRecognizedType;
|
||||
import com.mogo.module.common.constants.CarModelType;
|
||||
import com.mogo.module.common.constants.SafeType;
|
||||
import com.mogo.module.common.constants.VisionMode;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public
|
||||
/**
|
||||
@@ -15,6 +17,8 @@ public
|
||||
*/
|
||||
class MarkerResourceManager {
|
||||
|
||||
private static final String TAG = "MarkerResourceManager";
|
||||
|
||||
/**
|
||||
* @param mode
|
||||
* @param adasRecognizedType
|
||||
@@ -23,7 +27,8 @@ class MarkerResourceManager {
|
||||
*/
|
||||
public static int getMarkerDrawableResId( VisionMode mode,
|
||||
AdasRecognizedType adasRecognizedType,
|
||||
CarModelType type ) {
|
||||
CarModelType type,
|
||||
SafeType safeType ) {
|
||||
if ( mode == null ) {
|
||||
mode = VisionMode.User;
|
||||
}
|
||||
@@ -34,20 +39,31 @@ class MarkerResourceManager {
|
||||
type = CarModelType.Other;
|
||||
}
|
||||
|
||||
if ( mode == VisionMode.Machine ) {
|
||||
return R.drawable.module_common_online_car_vr_machine_middle;
|
||||
if ( safeType == null ) {
|
||||
safeType = SafeType.Normal;
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append( "module_commons" )
|
||||
.append( "_" ).append( mode.getRes() )
|
||||
.append( "_" ).append( adasRecognizedType.getRes() )
|
||||
.append( "_" ).append( type.getRes() );
|
||||
.append( "_" ).append( type.getRes() )
|
||||
.append( "_" ).append( safeType.getRes() );
|
||||
|
||||
Logger.d( TAG, "res name = %s", builder.toString() );
|
||||
|
||||
int id = AbsMogoApplication.getApp().getResources().getIdentifier(
|
||||
builder.toString(),
|
||||
"drawable",
|
||||
AbsMogoApplication.getApp().getPackageName() );
|
||||
|
||||
return id == 0 ? R.drawable.module_commons_user_car_other : id;
|
||||
if ( id == 0 ) {
|
||||
if ( mode == VisionMode.User ) {
|
||||
return R.drawable.module_commons_user_car_other_normal;
|
||||
} else {
|
||||
return R.drawable.module_commons_machine_car_other_normal;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user