opt
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
package com.mogo.module.map;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.navi.MogoNaviConfig;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public
|
||||
@@ -18,21 +16,19 @@ public
|
||||
*
|
||||
* 接收高德地图车机版广播
|
||||
*/
|
||||
class AutoNaviBroadcastReceiver extends BroadcastReceiver {
|
||||
class AutoNaviBroadcastIntentHandler implements IMogoIntentListener {
|
||||
|
||||
public static final String TAG = "AutoNaviBroadcastReceiver";
|
||||
|
||||
public static final String AUTONAVI_STANDARD_BROADCAST_RECV = "AUTONAVI_STANDARD_BROADCAST_RECV";
|
||||
|
||||
public void register() {
|
||||
IntentFilter inputFilter = new IntentFilter();
|
||||
inputFilter.addAction( AUTONAVI_STANDARD_BROADCAST_RECV );
|
||||
AbsMogoApplication.getApp().registerReceiver( this, inputFilter );
|
||||
public void register( IMogoIntentManager manager ) {
|
||||
manager.registerIntentListener( AUTONAVI_STANDARD_BROADCAST_RECV, this );
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
public void unregister(IMogoIntentManager manager ) {
|
||||
mCallback = null;
|
||||
AbsMogoApplication.getApp().unregisterReceiver( this );
|
||||
manager.unregisterIntentListener( AUTONAVI_STANDARD_BROADCAST_RECV, this );
|
||||
}
|
||||
|
||||
private OnMapControlCallback mCallback;
|
||||
@@ -42,7 +38,7 @@ class AutoNaviBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive( Context context, Intent intent ) {
|
||||
public void onIntentReceived( String intentStr, Intent intent ) {
|
||||
String action = intent.getAction();
|
||||
|
||||
int keyType = intent.getIntExtra( "KEY_TYPE", 0 );
|
||||
@@ -122,6 +118,5 @@ class AutoNaviBroadcastReceiver extends BroadcastReceiver {
|
||||
.avoidSpeed( prefer == 3 );
|
||||
mCallback.onReCalculatePath( config );
|
||||
}
|
||||
mCallback.onEnd( intent );
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.module.IMogoSearchManager;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.service.strategy.IMogoRefreshStrategyController;
|
||||
import com.mogo.utils.AppUtils;
|
||||
import com.mogo.utils.ResourcesHelper;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -73,23 +74,11 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
mView.getUIController().recoverLockMode();
|
||||
}
|
||||
};
|
||||
private AutoNaviBroadcastReceiver mAutoNaviReceiver;
|
||||
private AutoNaviBroadcastIntentHandler mAutoNaviReceiver;
|
||||
private MapControlCommandHandler mCustomVoiceCommandHandler;
|
||||
|
||||
public MapPresenter( MapView view ) {
|
||||
super( view );
|
||||
initBroadcast();
|
||||
mCustomVoiceCommandHandler = new MapControlCommandHandler();
|
||||
mCustomVoiceCommandHandler.setCallback( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* opera type为0:0 实时路况开;1实时路况关 type为1:0 放大地图; 1缩小地图 type为2:0切换2d车上; 1切换2d北上;2切换3d车上支持
|
||||
*/
|
||||
private void initBroadcast() {
|
||||
mAutoNaviReceiver = new AutoNaviBroadcastReceiver();
|
||||
mAutoNaviReceiver.setCallback( this );
|
||||
mAutoNaviReceiver.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,11 +147,10 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
if ( CustomNaviInterrupter.getInstance().interrupt() ) {
|
||||
// 导航过程中语音指令退出导航,会出现 activity 不走 onResume 的情况
|
||||
UiThreadHandler.postDelayed( () -> {
|
||||
if ( isForeground( getContext() ) && !hasOthersActivity() && !mStatusManager.isMainPageOnResume() ) {
|
||||
if ( AppUtils.isAppForeground( getContext() ) && !hasOthersActivity() && !mStatusManager.isMainPageOnResume() ) {
|
||||
mLauncher.backToLauncher( getContext() );
|
||||
}
|
||||
}, 500L );
|
||||
onEnd( intent );
|
||||
return;
|
||||
}
|
||||
mMogoMapService.getNavi( getContext() ).stopNavi();
|
||||
@@ -176,26 +164,6 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
mMogoMapService.getNavi( getContext() ).reCalculateRoute( config );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnd( Intent intent ) {
|
||||
mMogoIntentManager.invoke( AutoNaviBroadcastReceiver.AUTONAVI_STANDARD_BROADCAST_RECV, intent );
|
||||
}
|
||||
|
||||
private boolean isForeground( Context context ) {
|
||||
if ( context != null ) {
|
||||
ActivityManager activityManager = ( ActivityManager ) context.getSystemService( Context.ACTIVITY_SERVICE );
|
||||
List< ActivityManager.RunningAppProcessInfo > processes = activityManager.getRunningAppProcesses();
|
||||
for ( ActivityManager.RunningAppProcessInfo processInfo : processes ) {
|
||||
if ( processInfo.processName.equals( context.getPackageName() ) ) {
|
||||
if ( processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasOthersActivity() {
|
||||
ActivityManager am = ( ActivityManager ) getContext().getSystemService( Context.ACTIVITY_SERVICE );
|
||||
List< ActivityManager.RunningTaskInfo > list = am.getRunningTasks( 1 );
|
||||
@@ -298,6 +266,16 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
for ( String cmd : VoiceConstants.sUnUnRegisterCmds ) {
|
||||
mMogoIntentManager.registerIntentListener( cmd, this );
|
||||
}
|
||||
|
||||
initBroadcast();
|
||||
mCustomVoiceCommandHandler = new MapControlCommandHandler();
|
||||
mCustomVoiceCommandHandler.setCallback( this );
|
||||
}
|
||||
|
||||
private void initBroadcast() {
|
||||
mAutoNaviReceiver = new AutoNaviBroadcastIntentHandler();
|
||||
mAutoNaviReceiver.setCallback( this );
|
||||
mAutoNaviReceiver.register( mMogoIntentManager );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,7 +287,6 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
@Override
|
||||
public void onPause( @NonNull LifecycleOwner owner ) {
|
||||
super.onPause( owner );
|
||||
|
||||
unregisterVoiceCmd();
|
||||
}
|
||||
|
||||
@@ -317,7 +294,7 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
public void onDestroy( @NonNull LifecycleOwner owner ) {
|
||||
super.onDestroy( owner );
|
||||
if ( mAutoNaviReceiver != null ) {
|
||||
mAutoNaviReceiver.unregister();
|
||||
mAutoNaviReceiver.unregister( mMogoIntentManager );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,6 @@ public interface OnMapControlCallback {
|
||||
// 重新规划路线
|
||||
void onReCalculatePath( MogoNaviConfig config );
|
||||
|
||||
// 结束
|
||||
void onEnd( Intent intent );
|
||||
|
||||
// 查看全程
|
||||
void onDisplayOverview();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user