This commit is contained in:
lixiaopeng
2021-04-26 11:02:02 +08:00
parent 707fa23eef
commit 253cfa4ecd

View File

@@ -26,7 +26,7 @@ public
*
* 描述
*/
@Route( path = "/service/base/info" )
@Route(path = "/service/base/info")
class MogoMainService extends Service implements IMogoLocationListener {
private static final String TAG = "MogoMainService";
@@ -39,10 +39,10 @@ class MogoMainService extends Service implements IMogoLocationListener {
@Override
public void onCreate() {
Logger.d( TAG, "基本服务启动" );
Logger.d(TAG, "基本服务启动");
mServiceApis = MogoApisHandler.getInstance().getApis();
initAndStartLocation();
UiThreadHandler.postDelayed( () -> {
UiThreadHandler.postDelayed(() -> {
loadBaseModules();
startTanluService();
initADAS();
@@ -56,53 +56,61 @@ class MogoMainService extends Service implements IMogoLocationListener {
@Nullable
@Override
public IBinder onBind( Intent intent ) {
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand( Intent intent, int flags, int startId ) {
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
private void initAndStartLocation() {
Logger.d( TAG, "开始定位" );
mLocationClient = mServiceApis.getMapServiceApi().getSingletonLocationClient( AbsMogoApplication.getApp() );
mLocationClient.addLocationListener( this );
mLocationClient.start( 2_000L );
Logger.d(TAG, "开始定位");
if (mServiceApis != null) {
mLocationClient = mServiceApis.getMapServiceApi().getSingletonLocationClient(AbsMogoApplication.getApp());
mLocationClient.addLocationListener(this);
mLocationClient.start(2_000L);
}
}
private void initGpsSimulatorListener() {
mServiceApis.getMapServiceApi().getNavi( this ).registerCarLocationChangedListener( EventDispatchCenter.getInstance() );
if (mServiceApis != null) {
mServiceApis.getMapServiceApi().getNavi(this).registerCarLocationChangedListener(EventDispatchCenter.getInstance());
}
}
private void loadBaseModules() {
Logger.d( TAG, "加载基本模块" );
Logger.d(TAG, "加载基本模块");
MogoModulesManager.getInstance().loadBaseModule();
}
private void startTanluService() {
UiThreadHandler.postDelayed( () -> {
Logger.d( TAG, "startTanluService ---------- " );
mServiceApis.getTanluApi().startTanluService();
UiThreadHandler.postDelayed(() -> {
Logger.d(TAG, "startTanluService ---------- ");
if (mServiceApis != null) {
mServiceApis.getTanluApi().startTanluService();
}
}, 2_000L
);
}
private void initADAS() {
mServiceApis.getAdasControllerApi().init( AbsMogoApplication.getApp() );
if (mServiceApis != null) {
mServiceApis.getAdasControllerApi().init(AbsMogoApplication.getApp());
}
}
@Override
public void onLocationChanged( MogoLocation location ) {
EventDispatchCenter.getInstance().onLocationChanged( location );
public void onLocationChanged(MogoLocation location) {
EventDispatchCenter.getInstance().onLocationChanged(location);
}
@Override
public void onDestroy() {
super.onDestroy();
if ( mLocationClient != null ) {
mLocationClient.removeLocationListener( this );
if (mLocationClient != null) {
mLocationClient.removeLocationListener(this);
mLocationClient.stop();
mLocationClient.destroy();
mLocationClient = null;