opt
This commit is contained in:
@@ -82,6 +82,10 @@ public class MarkerServiceHandler {
|
||||
mMapMarkerManager.init( context );
|
||||
}
|
||||
|
||||
public static IMogoServiceApis getApis(){
|
||||
return mApis;
|
||||
}
|
||||
|
||||
public static IMogoMapService getMapService() {
|
||||
return mMapService;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.location.LocationManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Trace;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
@@ -30,7 +29,6 @@ import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.map.navi.MogoCongestionInfo;
|
||||
import com.mogo.map.navi.MogoNaviInfo;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.map.uicontroller.CarCursorOption;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
@@ -38,6 +36,7 @@ import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy;
|
||||
import com.mogo.module.common.map.Scene;
|
||||
import com.mogo.module.service.carinfo.CarStateInfo;
|
||||
import com.mogo.module.service.intent.IntentHandlerFactory;
|
||||
import com.mogo.module.service.marker.MapMarkerManager;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
import com.mogo.module.service.network.RefreshModel;
|
||||
@@ -60,14 +59,11 @@ import com.mogo.service.module.MogoAction;
|
||||
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
import com.mogo.utils.AppUtils;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
@@ -796,24 +792,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
mActionManager.invoke( MapMarkerManager.getInstance().getCurrentModuleName(), MogoAction.Prev );
|
||||
}
|
||||
} else if ( ServiceConst.COMMAND_SWITCH_CARD.equals( command ) ) {
|
||||
String data = intent.getStringExtra( "data" );
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject( data );
|
||||
String card = jsonObject.getString( "card" );
|
||||
if ( TextUtils.equals( "多媒体卡片", card )
|
||||
|| TextUtils.equals( "媒体中心卡片", card )
|
||||
|| TextUtils.equals( "音乐卡片", card ) ) {
|
||||
switchCard2( ServiceConst.CARD_TYPE_SHARE_MUSIC );
|
||||
} else if ( TextUtils.equals( "探路卡片", card ) ) {
|
||||
switchCard2( ServiceConst.CARD_TYPE_ROAD_CONDITION );
|
||||
} else if ( TextUtils.equals( "在线车辆卡片", card ) ) {
|
||||
switchCard2( ServiceConst.CARD_TYPE_USER_DATA );
|
||||
} else if ( TextUtils.equals( "新鲜事卡片", card ) ) {
|
||||
switchCard2( ServiceConst.CARD_TYPE_NOVELTY );
|
||||
}
|
||||
} catch ( JSONException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
|
||||
} else if ( MogoReceiver.ACTION_ADAS_STATUS.equals( command ) ) {
|
||||
String msg = intent.getStringExtra( "adasMsg" );
|
||||
if ( TextUtils.isEmpty( msg ) ) {
|
||||
@@ -825,82 +804,14 @@ public class MogoServices implements IMogoMapListener,
|
||||
// changeMyLocation( stateInfo.getValues() );
|
||||
}
|
||||
} else if ( ServiceConst.COMMAND_OPERATION.equals( command ) ) {
|
||||
try {
|
||||
JSONObject object = new JSONObject( intent.getStringExtra( "data" ) );
|
||||
String app = object.optString( "object" );
|
||||
String operation = object.optString( "operation" );
|
||||
if ( TextUtils.equals( app, "车聊聊" ) ) {
|
||||
if ( TextUtils.equals( "打开", operation ) ) {
|
||||
switchCard2( ServiceConst.CARD_TYPE_CARS_CHATTING );
|
||||
}
|
||||
} else {
|
||||
if ( TextUtils.equals( app, "探路" ) ) {
|
||||
if ( TextUtils.equals( "打开", operation ) ) {
|
||||
switchCard2( ServiceConst.CARD_TYPE_ROAD_CONDITION );
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( JSONException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
|
||||
} else if ( MogoReceiver.ACTION_VOICE_READY.equals( command ) ) {
|
||||
AIAssist.getInstance( mContext ).flush();
|
||||
mStatusManager.setAIAssistReady( TAG, true );
|
||||
} else if ( ServiceConst.COMMAND_MY_LOCATION.equals( command ) ) {
|
||||
if ( mStatusManager.isSearchUIShow() ) {
|
||||
return;
|
||||
}
|
||||
if ( mStatusManager.isMainPageOnResume() ) {
|
||||
mUiController.recoverLockMode();
|
||||
} else {
|
||||
mLauncher.backToLauncher( mContext );
|
||||
UiThreadHandler.postDelayed( () -> {
|
||||
mUiController.recoverLockMode();
|
||||
}, 2_000L );
|
||||
}
|
||||
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
|
||||
} else if ( MogoReceiver.ACTION_MOCK.equals( command ) ) {
|
||||
|
||||
if ( !DebugConfig.isDebug() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int oper = intent.getIntExtra( "oper", -1 );
|
||||
switch ( oper ) {
|
||||
case 1:
|
||||
mUiController.showMyLocation( true );
|
||||
break;
|
||||
case 2:
|
||||
boolean status = intent.getBooleanExtra( "status", false );
|
||||
mStatusManager.setSeekHelping( TAG, status );
|
||||
break;
|
||||
case 3:
|
||||
String msg = intent.getStringExtra( "msg" );
|
||||
if ( !TextUtils.isEmpty( msg ) ) {
|
||||
TipToast.shortTip( msg );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换卡片
|
||||
*/
|
||||
private void switchCard2( String card ) {
|
||||
if ( AppUtils.isApplicationBroughtToBackground( mContext ) ) {
|
||||
mLauncher.backToLauncher( mContext );
|
||||
UiThreadHandler.postDelayed( () -> {
|
||||
if ( mStatusManager.isADASShow() ) {
|
||||
mADASController.closeADAS();
|
||||
}
|
||||
mCardManager.switch2( card, true );
|
||||
}, 2000L );
|
||||
} else {
|
||||
mFragmentManager.clearAll();
|
||||
if ( mStatusManager.isADASShow() ) {
|
||||
mADASController.closeADAS();
|
||||
}
|
||||
mCardManager.switch2( card, true );
|
||||
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-17
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class AppOperationIntentHandler implements IntentHandler {
|
||||
|
||||
@Override
|
||||
public void handle( Context context, Intent intent ) {
|
||||
try {
|
||||
JSONObject object = new JSONObject( intent.getStringExtra( "data" ) );
|
||||
String app = object.optString( "object" );
|
||||
String operation = object.optString( "operation" );
|
||||
if ( TextUtils.equals( app, "车聊聊" ) ) {
|
||||
if ( TextUtils.equals( "打开", operation ) ) {
|
||||
SwitchCardIntentHandler.switchCard2( context, ServiceConst.CARD_TYPE_CARS_CHATTING );
|
||||
}
|
||||
} else {
|
||||
if ( TextUtils.equals( app, "探路" ) ) {
|
||||
if ( TextUtils.equals( "打开", operation ) ) {
|
||||
SwitchCardIntentHandler.switchCard2( context, ServiceConst.CARD_TYPE_ROAD_CONDITION );
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( JSONException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-17
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class EmptyIntentHandler implements IntentHandler {
|
||||
|
||||
private static final String TAG = "EmptyIntentHandler";
|
||||
|
||||
@Override
|
||||
public void handle( Context context, Intent intent ) {
|
||||
Logger.w( TAG, "空实现." );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-17
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public interface IntentHandler {
|
||||
|
||||
void handle( Context context, Intent intent );
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.module.service.receiver.MogoReceiver;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-17
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class IntentHandlerFactory {
|
||||
|
||||
private IntentHandlerFactory() {
|
||||
// private constructor
|
||||
mHandlers.put( MogoReceiver.ACTION_MOCK, new MockIntentHandler() );
|
||||
mHandlers.put( ServiceConst.COMMAND_SWITCH_CARD, new SwitchCardIntentHandler() );
|
||||
mHandlers.put( ServiceConst.COMMAND_OPERATION, new AppOperationIntentHandler() );
|
||||
mHandlers.put( ServiceConst.COMMAND_MY_LOCATION, new MyLocationHandler() );
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
private static final IntentHandlerFactory INSTANCE = new IntentHandlerFactory();
|
||||
}
|
||||
|
||||
public static IntentHandlerFactory getInstance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
// 阻止反序列化,必须实现 Serializable 接口
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private Map< String, IntentHandler > mHandlers = new HashMap<>();
|
||||
|
||||
private IntentHandler DEFAULT = new EmptyIntentHandler();
|
||||
|
||||
private IntentHandler getIntentHandler( String intent ) {
|
||||
if ( mHandlers.containsKey( intent ) && mHandlers.get( intent ) != null ) {
|
||||
return mHandlers.get( intent );
|
||||
}
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
public void handle( Context context, String intent, Intent obj ) {
|
||||
IntentHandler handler = getIntentHandler( intent );
|
||||
if ( handler != null ) {
|
||||
handler.handle( context, obj );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.service.entrance.ButtonIndex;
|
||||
import com.mogo.utils.TipToast;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-17
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MockIntentHandler implements IntentHandler {
|
||||
|
||||
private static final String TAG = "MockIntentHandler";
|
||||
|
||||
@Override
|
||||
public void handle( Context context, Intent intent ) {
|
||||
if ( !DebugConfig.isDebug() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int oper = intent.getIntExtra( "oper", -1 );
|
||||
switch ( oper ) {
|
||||
case 1:
|
||||
MarkerServiceHandler.getMapUIController().showMyLocation( true );
|
||||
break;
|
||||
case 2:
|
||||
boolean status = intent.getBooleanExtra( "status", false );
|
||||
MarkerServiceHandler.getMogoStatusManager().setSeekHelping( TAG, status );
|
||||
break;
|
||||
case 3:
|
||||
String msg = intent.getStringExtra( "msg" );
|
||||
if ( !TextUtils.isEmpty( msg ) ) {
|
||||
TipToast.shortTip( msg );
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
TextView button1 = MarkerServiceHandler.getApis().getEntranceButtonController().getButton( ButtonIndex.BUTTON1 );
|
||||
if ( button1 != null ) {
|
||||
button1.setVisibility( View.VISIBLE );
|
||||
button1.setBackgroundColor( Color.RED );
|
||||
button1.setOnClickListener( view -> {
|
||||
TipToast.shortTip( "测试" );
|
||||
} );
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
TextView button2 = MarkerServiceHandler.getApis().getEntranceButtonController().getButton( ButtonIndex.BUTTON1 );
|
||||
if ( button2 != null ) {
|
||||
button2.setOnClickListener( null );
|
||||
button2.setVisibility( View.GONE );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-17
|
||||
* <p>
|
||||
* 语音指令:定位我的位置等处理
|
||||
*/
|
||||
public class MyLocationHandler implements IntentHandler {
|
||||
|
||||
@Override
|
||||
public void handle( Context context, Intent intent ) {
|
||||
if ( MarkerServiceHandler.getMogoStatusManager().isSearchUIShow() ) {
|
||||
return;
|
||||
}
|
||||
if ( MarkerServiceHandler.getMogoStatusManager().isMainPageOnResume() ) {
|
||||
MarkerServiceHandler.getMapUIController().recoverLockMode();
|
||||
} else {
|
||||
MarkerServiceHandler.getLauncher().backToLauncher( context );
|
||||
UiThreadHandler.postDelayed( () -> {
|
||||
MarkerServiceHandler.getMapUIController().recoverLockMode();
|
||||
}, 2_000L );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.utils.AppUtils;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-17
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class SwitchCardIntentHandler implements IntentHandler {
|
||||
|
||||
@Override
|
||||
public void handle( Context context, Intent intent ) {
|
||||
String data = intent.getStringExtra( "data" );
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject( data );
|
||||
String card = jsonObject.getString( "card" );
|
||||
if ( TextUtils.equals( "多媒体卡片", card )
|
||||
|| TextUtils.equals( "媒体中心卡片", card )
|
||||
|| TextUtils.equals( "音乐卡片", card ) ) {
|
||||
switchCard2( context, ServiceConst.CARD_TYPE_SHARE_MUSIC );
|
||||
} else if ( TextUtils.equals( "探路卡片", card ) ) {
|
||||
switchCard2( context, ServiceConst.CARD_TYPE_ROAD_CONDITION );
|
||||
} else if ( TextUtils.equals( "在线车辆卡片", card ) ) {
|
||||
switchCard2( context, ServiceConst.CARD_TYPE_USER_DATA );
|
||||
} else if ( TextUtils.equals( "新鲜事卡片", card ) ) {
|
||||
switchCard2( context, ServiceConst.CARD_TYPE_NOVELTY );
|
||||
}
|
||||
} catch ( JSONException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换卡片
|
||||
*/
|
||||
public static void switchCard2( Context context, String card ) {
|
||||
if ( AppUtils.isApplicationBroughtToBackground( context ) ) {
|
||||
MarkerServiceHandler.getLauncher().backToLauncher( context );
|
||||
UiThreadHandler.postDelayed( () -> {
|
||||
if ( MarkerServiceHandler.getMogoStatusManager().isADASShow() ) {
|
||||
MarkerServiceHandler.getADASController().closeADAS();
|
||||
}
|
||||
MarkerServiceHandler.getMogoCardManager().switch2( card, true );
|
||||
}, 2000L );
|
||||
} else {
|
||||
MarkerServiceHandler.getFragmentManager().clearAll();
|
||||
if ( MarkerServiceHandler.getMogoStatusManager().isADASShow() ) {
|
||||
MarkerServiceHandler.getADASController().closeADAS();
|
||||
}
|
||||
MarkerServiceHandler.getMogoCardManager().switch2( card, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user