This commit is contained in:
wangcongtao
2020-12-07 16:30:37 +08:00
parent 1557af276b
commit e1082ac994
15 changed files with 197 additions and 72 deletions

View File

@@ -110,6 +110,9 @@ public class AppUtils {
* @return true 表示正在运行false 表示没有运行
*/
public static boolean isProcessRunning( Context context, int uid ) {
if ( context == null ) {
return false;
}
ActivityManager am = ( ActivityManager ) context.getSystemService( Context.ACTIVITY_SERVICE );
List< ActivityManager.RunningServiceInfo > runningServiceInfos = am.getRunningServices( 200 );
if ( runningServiceInfos.size() > 0 ) {

View File

@@ -16,14 +16,23 @@ public class WorkThreadHandler {
private Handler mHandler;
private HandlerThread mThread;
private WorkThreadHandler() {
public static WorkThreadHandler newInstance( String name ) {
return new WorkThreadHandler( name );
}
private WorkThreadHandler( String name ) {
// private constructor
mThread = new HandlerThread( "work-thread-handler" );
mThread = new HandlerThread( name );
mThread.start();
mThreadLooper = mThread.getLooper();
mHandler = new Handler( mThreadLooper );
}
private WorkThreadHandler() {
// private constructor
this( "work-thread-handler" );
}
private static final class InstanceHolder {
private static final WorkThreadHandler INSTANCE = new WorkThreadHandler();
}

View File

@@ -171,7 +171,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
mMapView.setRouteOverlayVisible( false );
mMapView.setCarOverlayVisible( false );
setUIMode( EnumMapUI.CarUp_2D, null );
setUIMode( EnumMapUI.NorthUP_2D, null );
}
private void initListeners() {

View File

@@ -16,6 +16,7 @@ import com.amap.api.maps.model.animation.AnimationSet;
import com.amap.api.maps.model.animation.ScaleAnimation;
import com.amap.api.maps.model.animation.TranslateAnimation;
import com.amap.api.maps.utils.overlay.MovingPointOverlay;
import com.autonavi.amap.mapcore.IPoint;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.impl.amap.AMapWrapper;
@@ -517,4 +518,11 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
}
return mMarker.isInfoWindowShown();
}
@Override
public void setGps( boolean isGps ) {
MarkerOptions options = mMarker.getOptions();
options.setGps( isGps );
mMarker.setMarkerOptions( options );
}
}

View File

@@ -485,4 +485,11 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
public boolean isInfoWindowShowing() {
return mMarker.isInfoWindowShown();
}
@Override
public void setGps( boolean isGps ) {
if ( mMarker != null ) {
mMarker.setGps( isGps );
}
}
}

View File

@@ -3,6 +3,8 @@ package com.mogo.map;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Objects;
/**
* @author congtaowang
* @since 2019-12-18
@@ -40,6 +42,21 @@ public class MogoLatLng implements Parcelable {
return lon;
}
@Override
public boolean equals( Object o ) {
if ( this == o ) return true;
if ( o == null || getClass() != o.getClass() ) return false;
MogoLatLng latLng = ( MogoLatLng ) o;
return Double.compare( latLng.lat, lat ) == 0 &&
Double.compare( latLng.lon, lon ) == 0;
}
@Override
public int hashCode() {
return Objects.hash( lat, lng, lon );
}
@Override
public String toString() {
return "MogoLatLng{" +

View File

@@ -324,4 +324,10 @@ public interface IMogoMarker {
* @return
*/
boolean isInfoWindowShowing();
/**
* 设置是否是gps
* @param isGps
*/
void setGps(boolean isGps);
}

View File

@@ -1,7 +1,6 @@
package com.mogo.module.common.drawer;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@@ -9,19 +8,17 @@ 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;
import com.mogo.module.common.MogoApisHandler;
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.DataTypes;
import com.mogo.module.common.constants.SafeType;
import com.mogo.module.common.constants.VisionMode;
import com.mogo.module.common.drawer.marker.MarkerResourceManager;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.module.common.utils.CoordinateUtils;
import com.mogo.service.adas.entity.ADASRecognizedListResult;
import java.util.ArrayList;
@@ -108,7 +105,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
if ( latLon == null ) {
continue;
}
points.add( endLatLon = new MogoLatLng( latLon.lat, latLon.lon ) );
double targetPos[] = CoordinateUtils.transformFromWGSToGCJ( latLon.lat, latLon.lon );
points.add( endLatLon = new MogoLatLng( targetPos[POS_LAT], targetPos[POS_LON] ) );
}
} else if ( recognizedListResult.latLonList != null
@@ -176,24 +174,28 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_ADAS )
.gps( true )
.icon( inflateView( recognizedListResult, machineVision, curSpeed ) )
.gps( true )
.anchor( 0.5f, 0.5f )
.rotate( ( float ) recognizedListResult.heading )
.position( new MogoLatLng( recognizedListResult.latLonList.get( 0 ).lat, recognizedListResult.latLonList.get( 0 ).lon ) );
return MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( DataTypes.TYPE_MARKER_ADAS, options );
}
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.distanceX, data.distanceY, data.speed, curSpeed );
TextView tv = rootView.findViewById( R.id.module_commons_marker_car_speed );
tv.setText( safeType.getMsg() );
// 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(),
safeType
) );
// iv.setImageResource( MarkerResourceManager.getMarkerDrawableResId(
// machineVision ? VisionMode.Machine : VisionMode.User,
// AdasRecognizedType.valueFrom( data.type ),
// getCarModelType(),
// safeType
// ) );
iv.setImageResource( R.drawable.icon_map_marker_car_gray );
return rootView;
}

View File

@@ -12,6 +12,9 @@ public
*/
class BaseDrawer {
public static final int POS_LON = 1;
public static final int POS_LAT = 0;
public static final double BOUND_DISTANCE_DANGEROUS = 0.5;
public static final double BOUND_SPEED_DANGEROUS = 1.5;

View File

@@ -24,6 +24,8 @@ import com.mogo.module.common.drawer.marker.MarkerResourceManager;
import com.mogo.module.common.entity.CloudLocationInfo;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.module.common.entity.MogoSnapshotSetData;
import com.mogo.module.common.utils.CoordinateUtils;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
@@ -74,6 +76,9 @@ class SnapshotSetDataDrawer extends BaseDrawer {
// 云端 marker 缓存
private Map< String, IMogoMarker > mCloudSnapshotMarkersCaches = new ConcurrentHashMap<>();
private int mPurseCounter = 0;
private Map< String, MogoLatLng > mLastPositions = new ConcurrentHashMap<>();
/**
* 其他车辆、rsu 车辆数据
@@ -82,16 +87,25 @@ class SnapshotSetDataDrawer extends BaseDrawer {
*/
public void renderSnapshotData( MogoSnapshotSetData data,
boolean machineVision ) {
if ( data == null || data.getAllList() == null || data.getAllList().isEmpty() ) {
if ( data == null || (
( data.getAllList() == null || data.getAllList().isEmpty() ) &&
( data.getNearList() == null || data.getNearList().isEmpty() )
) ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( AbsMogoApplication.getApp() ).removeMarkers( DataTypes.TYPE_MARKER_CLOUD_DATA );
return;
}
List< CloudRoadData > allDatumsList = new ArrayList<>();
if ( machineVision ) {
allDatumsList.addAll( data.getAllList() );
allDatumsList.addAll( data.getNearList() );
} else {
allDatumsList.addAll( data.getAllList() );
allDatumsList.addAll( data.getAllList() );
// allDatumsList.addAll( data.getNearList() );
// if ( machineVision ) {
// allDatumsList.addAll( data.getAllList() );
// allDatumsList.addAll( data.getNearList() );
// } else {
// allDatumsList.addAll( data.getAllList() );
// }
mPurseCounter++;
if ( mPurseCounter >= 100 ) {
mPurseCounter = 0;
}
purgeCloudSnapshotData( allDatumsList );
for ( CloudRoadData cloudRoadData : allDatumsList ) {
@@ -106,6 +120,7 @@ class SnapshotSetDataDrawer extends BaseDrawer {
if ( mCloudSnapshotMarkersCaches.containsKey( uniqueKey ) ) {
marker = mCloudSnapshotMarkersCaches.get( uniqueKey );
}
MogoLatLng target = new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() );
if ( marker == null || marker.isDestroyed() ) {
marker = drawSnapshotDataMarker( cloudRoadData, machineVision, data.curSpeed );
if ( marker == null ) {
@@ -113,35 +128,26 @@ class SnapshotSetDataDrawer extends BaseDrawer {
}
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 );
}
MogoLatLng endLatLon = null;
List< MogoLatLng > points = new ArrayList<>();
if ( cloudRoadData.getCoordinates() != null
&& cloudRoadData.getCoordinates().size() > 1 ) {
points.add( new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ) );
for ( int j = 0; j < cloudRoadData.getCoordinates().size(); j++ ) {
CloudLocationInfo poi = cloudRoadData.getCoordinates().get( j );
if ( poi == null ) {
continue;
marker.setGps( false );
MogoLatLng lastPosition = mLastPositions.get( uniqueKey );
double targetPos[] = CoordinateUtils.transformFromWGSToGCJ( target.lat, target.lon );
if ( lastPosition != null ) {
if ( lastPosition.equals( target ) ) {
marker.setRotateAngle( 360 - ( float ) cloudRoadData.getHeading() );
marker.setPosition( targetPos[POS_LAT], targetPos[POS_LON] );
} else {
List< MogoLatLng > points = new ArrayList<>();
double lastPos[] = CoordinateUtils.transformFromWGSToGCJ( lastPosition.lat, lastPosition.lon );
points.add( new MogoLatLng( lastPos[POS_LAT], lastPos[POS_LON] ) );
points.add( new MogoLatLng( targetPos[POS_LAT], targetPos[POS_LON] ) );
marker.startSmooth( points, 1 );
}
double lat = poi.getLat();
double lng = poi.getLon();
points.add( endLatLon = new MogoLatLng( lat, lng ) );
} else {
marker.setRotateAngle( 360 - ( float ) cloudRoadData.getHeading() );
marker.setPosition( targetPos[POS_LAT], targetPos[POS_LON] );
}
} else {
points.add( marker.getPosition() );
points.add( endLatLon = new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ) );
}
if ( endLatLon != null ) {
marker.setObject( endLatLon );
}
if ( points.size() >= 1 ) {
marker.startSmooth( points, 1 );
}
mLastPositions.put( uniqueKey, target );
}
}
@@ -174,6 +180,7 @@ class SnapshotSetDataDrawer extends BaseDrawer {
if ( !existMarker.isEmpty() ) {
for ( String key : mCloudSnapshotMarkersCaches.keySet() ) {
if ( !existMarker.containsKey( key ) ) {
mLastPositions.remove( key );
try {
IMogoMarker marker = mCloudSnapshotMarkersCaches.remove( key );
marker.destroy();
@@ -195,6 +202,8 @@ class SnapshotSetDataDrawer extends BaseDrawer {
.owner( DataTypes.TYPE_MARKER_CLOUD_DATA )
.icon( inflateView( data, machineVision, curSpeed ) )
.gps( true )
.anchor( 0.5f, 0.5f )
.rotate( ( float ) data.getHeading() )
.position( new MogoLatLng( data.getLat(), data.getLon() ) );
return MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( DataTypes.TYPE_MARKER_CLOUD_DATA, options );
}

View File

@@ -21,6 +21,7 @@ public class CloudRoadData implements Parcelable {
private String sn;
private double speed;
private double heading;
private long systemTime;
@@ -124,6 +125,14 @@ public class CloudRoadData implements Parcelable {
return sn;
}
public double getHeading() {
return heading;
}
public void setHeading( double heading ) {
this.heading = heading;
}
public String getUniqueKey(){
if (! TextUtils.isEmpty( uuid ) ) {
return uuid;
@@ -131,6 +140,9 @@ public class CloudRoadData implements Parcelable {
return sn;
}
public CloudRoadData() {
}
@Override
public int describeContents() {
return 0;
@@ -144,6 +156,7 @@ public class CloudRoadData implements Parcelable {
dest.writeString( this.uuid );
dest.writeString( this.sn );
dest.writeDouble( this.speed );
dest.writeDouble( this.heading );
dest.writeLong( this.systemTime );
dest.writeInt( this.lightStatus );
dest.writeInt( this.lightLeftTime );
@@ -152,9 +165,6 @@ public class CloudRoadData implements Parcelable {
dest.writeTypedList( this.coordinates );
}
public CloudRoadData() {
}
protected CloudRoadData( Parcel in ) {
this.type = in.readInt();
this.lat = in.readDouble();
@@ -162,6 +172,7 @@ public class CloudRoadData implements Parcelable {
this.uuid = in.readString();
this.sn = in.readString();
this.speed = in.readDouble();
this.heading = in.readDouble();
this.systemTime = in.readLong();
this.lightStatus = in.readInt();
this.lightLeftTime = in.readInt();

View File

@@ -195,7 +195,7 @@ public class MapFragment extends MvpFragment< MapView, MapPresenter > implements
//设置双指缩放手势是否可用。
uiSettings.setZoomGesturesEnabled( true );
if ( mMogoMap.getUIController() != null ) {
mMogoMap.getUIController().changeMapMode( EnumMapUI.NorthUP_2D );
mMogoMap.getUIController().changeMapMode( EnumMapUI.CarUp_2D );
}
}
}

View File

@@ -29,6 +29,7 @@ import com.mogo.map.MogoLatLng;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.map.navi.IMogoAimlessModeListener;
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
@@ -44,6 +45,8 @@ import com.mogo.module.common.entity.CloudLocationInfo;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.common.map.MapCenterPointStrategy;
import com.mogo.module.common.map.Scene;
import com.mogo.module.common.utils.CoordinateSystemTransformationUtil;
import com.mogo.module.common.utils.CoordinateUtils;
import com.mogo.module.service.autopilot.AutoPilotRemoteController;
import com.mogo.module.service.intent.IntentHandlerFactory;
import com.mogo.module.service.launchercard.LauncherCardRefresher;
@@ -453,9 +456,9 @@ public class MogoServices implements IMogoMapListener,
AutoPilotRemoteController.getInstance().start();
MogoRTKLocation.getInstance().registerRTKLocationListener( cloudLocationInfos -> {
Logger.i(TAG,"cloudLocationInfos size : " + cloudLocationInfos.size());
startSendCarLocationAndAdasRecognizedResult2Server(cloudLocationInfos);
});
Logger.i( TAG, "cloudLocationInfos size : " + cloudLocationInfos.size() );
startSendCarLocationAndAdasRecognizedResult2Server( cloudLocationInfos );
} );
// SimpleLocationCorrectStrategy.getInstance().setRecordLocationListener((history, correct,valid,err) -> {
// // todo 打点
@@ -510,31 +513,45 @@ public class MogoServices implements IMogoMapListener,
}
}
private void startSendCarLocationAndAdasRecognizedResult2Server(List<CloudLocationInfo> cloudLocationInfo) {
private List< List< Double > > coors = new ArrayList<>();
private CloudLocationInfo mLastInfo;
private void startSendCarLocationAndAdasRecognizedResult2Server( List< CloudLocationInfo > cloudLocationInfo ) {
// Location lastCarLocation = mLastCarLocation;
CloudLocationInfo lastInfo = null;
// 如果数组内容不为空,就用数组最后一个值
if (cloudLocationInfo != null && !cloudLocationInfo.isEmpty()) {
lastInfo = cloudLocationInfo.get(cloudLocationInfo.size() - 1);
if ( cloudLocationInfo != null && !cloudLocationInfo.isEmpty() ) {
lastInfo = cloudLocationInfo.get( cloudLocationInfo.size() - 1 );
mLastInfo = lastInfo;
}
if ( lastInfo == null ) {
lastInfo = LocationParseUtil.locationToCloudLocation(mLastCarLocation);
lastInfo = mLastInfo;
}
LocationResult locationResult = null;
if ( lastInfo != null ) {
// 定位点预测纠偏
lastInfo = SimpleLocationCorrectStrategy.getInstance().correct(lastInfo);
lastInfo = SimpleLocationCorrectStrategy.getInstance().correct( lastInfo );
locationResult = new LocationResult();
if (lastInfo != null) {
if ( lastInfo != null ) {
// List<Double> coor = new ArrayList<>( );
// double pos[] = CoordinateUtils.transformFromWGSToGCJ( lastInfo.getLat(), lastInfo.getLon() );
// coor.add( pos[1]);
// coor.add(pos[0] );
// coors.add( coor );
// if ( coors.size()>50 ) {
// Logger.d( "Print-coor", GsonUtil.jsonFromObject( coors ) );
// coors.clear();
// }
// moveMarker( lastInfo.getLat(), lastInfo.getLon() );
locationResult.lastCoordinate = lastInfo;
locationResult.mortonCode = MortonCode.wrapEncodeMorton( lastInfo.getLon(), lastInfo.getLat() );
}
locationResult.coordinates = new ArrayList<>();
locationResult.sn = com.mogo.commons.network.Utils.getSn();
if(cloudLocationInfo == null){
locationResult.coordinates.addAll(new ArrayList<>());
}else {
locationResult.coordinates.addAll(cloudLocationInfo);
if ( cloudLocationInfo == null ) {
locationResult.coordinates.addAll( new ArrayList<>() );
} else {
locationResult.coordinates.addAll( cloudLocationInfo );
}
}
List< ADASRecognizedResult > recognizedResults = MarkerServiceHandler.getADASController().getLastADASRecognizedResult();
@@ -556,6 +573,33 @@ public class MogoServices implements IMogoMapListener,
} );
}
private IMogoMarker marker = null;
private void moveMarker( double lat, double lon ) {
List< Double > coor = new ArrayList<>();
double pos[] = CoordinateSystemTransformationUtil.transformWgsToGcj( lat, lon );
coor.add( pos[1] );
coor.add( pos[0] );
coors.add( coor );
if ( coors.size() > 50 ) {
Logger.d( "Print-coor", GsonUtil.jsonFromObject( coors ) );
coors.clear();
}
if ( marker == null ) {
marker = MogoApisHandler.getInstance().getApis()
.getMapServiceApi().getMarkerManager( mContext )
.addMarker( TAG, new MogoMarkerOptions()
.latitude( lat )
.longitude( lon )
.gps( true )
.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.bg_map_marker_blue ) ) )
;
}
if ( marker != null ) {
marker.setPosition( lat, lon );
}
}
private void initWorkThread() {
mThreadHandler = new Handler( WorkThreadHandler.getInstance().getLooper() ) {
@Override
@@ -898,7 +942,9 @@ public class MogoServices implements IMogoMapListener,
Message msg = Message.obtain();
msg.what = ServiceConst.MSG_REQUEST_DATA;
msg.obj = new RefreshObject( callback, radius, latLng, amount );
mThreadHandler.sendMessage( msg );
if ( mThreadHandler != null ) {
mThreadHandler.sendMessage( msg );
}
}
private void notifySeekHelpingStatusChanged( boolean seekHelpingStatus ) {

View File

@@ -40,7 +40,7 @@ public class MogoRTKLocation {
}
private MogoRTKLocation() {
mHandler = new Handler(WorkThreadHandler.getInstance().getLooper()) {
mHandler = new Handler(WorkThreadHandler.newInstance( TAG ).getLooper() ) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
@@ -63,8 +63,7 @@ public class MogoRTKLocation {
rtkLocationListener.onLocationChanged(list);
}
if (cacheList != null && cacheList.size() > 0) {
cacheList = null;
cacheList = new ArrayList<>();
cacheList.clear();
}
}
@@ -90,7 +89,7 @@ public class MogoRTKLocation {
} else {
Logger.d(TAG, "RTK LocationManager Provider GPS_PROVIDER unable");
}
// 注册修改上报间隔的广播, 临时使用后面可直接干掉发送广播的地方在EntranceFragment
IntentFilter filter = new IntentFilter("com.mogo.launcher.action.FIX_UPLOAT_DELAY");
AbsMogoApplication.getApp().registerReceiver(fixUploadDelayReceiver, filter);

View File

@@ -1,5 +1,7 @@
package com.mogo.service.impl.adas;
import android.text.TextUtils;
import com.mogo.commons.utils.MortonCode;
import com.mogo.service.adas.entity.ADASRecognizedListResult;
import com.mogo.service.adas.entity.ADASRecognizedResult;
@@ -89,6 +91,9 @@ class AdasObjectUtils {
}
List< RectInfo.RectBean > models = rectInfo.getModels();
for ( RectInfo.RectBean model : models ) {
if ( model == null || TextUtils.isEmpty( model.getUuid() ) ) {
continue;
}
ADASRecognizedListResult recognizedListResult = null;
if ( !result.containsKey( model.getUuid() ) ) {
recognizedListResult = new ADASRecognizedListResult();