Merge branch 'dev' into dev_custom_map
This commit is contained in:
@@ -33,6 +33,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.intent.IntentHandlerFactory;
|
||||
import com.mogo.module.service.launchercard.LauncherCardRefresher;
|
||||
import com.mogo.module.service.marker.MapMarkerManager;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
import com.mogo.module.service.network.RefreshModel;
|
||||
@@ -303,6 +304,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
restartAutoRefreshAtTime( 2_000L );
|
||||
}
|
||||
mIsMainPageFirstResume = false;
|
||||
LauncherCardRefresher.getInstance( mContext ).stop();
|
||||
} else {
|
||||
unregisterInternalUnWakeupWords();
|
||||
stopAutoRefreshStrategy();
|
||||
@@ -384,6 +386,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
mIntentManager.registerIntentListener( ServiceConst.COMMAND_BACK, this );
|
||||
mIntentManager.registerIntentListener( MogoReceiver.ACTION_AUTO_NAVI_RECEIVER, this );
|
||||
mIntentManager.registerIntentListener( MogoReceiver.ACTION_AUTO_NAVI_SEND, this );
|
||||
mIntentManager.registerIntentListener( MogoReceiver.ACTION_MOGO, this );
|
||||
|
||||
mADASController = MarkerServiceHandler.getADASController();
|
||||
mLauncher = MarkerServiceHandler.getLauncher();
|
||||
@@ -397,7 +400,6 @@ public class MogoServices implements IMogoMapListener,
|
||||
if ( DebugConfig.isLaunchLocationService() ) {
|
||||
initLocationServiceProcess( context );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initLocationServiceProcess( Context context ) {
|
||||
@@ -478,6 +480,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
filter.addAction( Intent.ACTION_CLOSE_SYSTEM_DIALOGS );
|
||||
filter.addAction( MogoReceiver.ACTION_AUTO_NAVI_RECEIVER );
|
||||
filter.addAction( MogoReceiver.ACTION_AUTO_NAVI_SEND );
|
||||
filter.addAction( MogoReceiver.ACTION_MOGO );
|
||||
try {
|
||||
context.getApplicationContext().registerReceiver( mAIAssistReceiver, filter );
|
||||
Logger.i( TAG, "register voice receiver." );
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.Intent;
|
||||
import com.mogo.module.common.utils.CarSeries;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.module.service.launchercard.LauncherCardRefresher;
|
||||
import com.mogo.module.service.receiver.AccStatusReceiver;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -69,6 +70,11 @@ class AccStatusIntentHandler implements IntentHandler {
|
||||
}
|
||||
Logger.d( TAG, "acc status: %s", state );
|
||||
MarkerServiceHandler.getMogoStatusManager().setAccStatus( ServiceConst.TYPE, accOn );
|
||||
if ( state == ACC_ON ) {
|
||||
LauncherCardRefresher.getInstance( context ).start();
|
||||
} else if ( state == ACC_OFF ) {
|
||||
LauncherCardRefresher.getInstance( context ).stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public class IntentHandlerFactory {
|
||||
mHandlers.put( MogoReceiver.ACTIION_ADAS, ADASStatusIntentHandler.getInstance() );
|
||||
mHandlers.put( MogoReceiver.ACTION_VOICE_READY, new AIAssistIntentHandler() );
|
||||
mHandlers.put( ServiceConst.COMMAND_BACK, WholeVoiceCommandIntentHandler.getInstance() );
|
||||
mHandlers.put( MogoReceiver.ACTION_MOGO, new MogoControllerIntentHandler() );
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mogo.utils.logger.LogLevel;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.NetConfig;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/8/17
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class MogoControllerIntentHandler implements IntentHandler {
|
||||
|
||||
public static final String KEY_OPER = "oper";
|
||||
public static final int TYPE_OPER_OPEN_LOG = 1;
|
||||
public static final int TYPE_OPER_CLOSE_LOG = 2;
|
||||
|
||||
@Override
|
||||
public void handle( Context context, Intent intent ) {
|
||||
int oper = intent.getIntExtra( KEY_OPER, 0 );
|
||||
switch ( oper ) {
|
||||
case TYPE_OPER_OPEN_LOG:
|
||||
Logger.init( LogLevel.DEBUG );
|
||||
NetConfig.instance().setLoggable( true );
|
||||
break;
|
||||
case TYPE_OPER_CLOSE_LOG:
|
||||
Logger.init( LogLevel.OFF );
|
||||
NetConfig.instance().setLoggable( false );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.mogo.module.service.launchercard;
|
||||
|
||||
public class LauncherCardRefreshStrategy {
|
||||
|
||||
private long interval; // 间隔时间
|
||||
private static LauncherCardRefreshType type = LauncherCardRefreshType.OnlineCar;
|
||||
|
||||
private LauncherCardRefreshStrategy next;
|
||||
|
||||
private int msgType;// 触发的消息类型
|
||||
|
||||
public LauncherCardRefreshStrategy( long interval, LauncherCardRefreshStrategy next, int msgType ) {
|
||||
this.interval = interval;
|
||||
this.next = next;
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public int getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public long getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
public LauncherCardRefreshType getType() {
|
||||
if ( type == LauncherCardRefreshType.ExploreWay ) {
|
||||
type = LauncherCardRefreshType.OnlineCar;
|
||||
} else {
|
||||
type = LauncherCardRefreshType.ExploreWay;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return type.limit;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return type.desc;
|
||||
}
|
||||
|
||||
public int getRadius() {
|
||||
return 2_000;
|
||||
}
|
||||
|
||||
public LauncherCardRefreshStrategy getNext() {
|
||||
if ( next == null ) {
|
||||
return this;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
package com.mogo.module.service.launchercard;
|
||||
|
||||
public enum LauncherCardRefreshType {
|
||||
ExploreWay( 50, "道路事件" ),
|
||||
OnlineCar( 20, "车友" );
|
||||
|
||||
public int limit;
|
||||
public String desc;
|
||||
|
||||
LauncherCardRefreshType( int limit, String desc ) {
|
||||
this.limit = limit;
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
package com.mogo.module.service.launchercard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.commons.voice.VoicePreemptType;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.module.common.entity.MarkerResponse;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.R;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
import com.mogo.module.service.network.RefreshModel;
|
||||
import com.mogo.utils.AppUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.storage.SharedPrefsMgr;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/8/17
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class LauncherCardRefresher {
|
||||
|
||||
private static final String TAG = "LauncherCardRefresher";
|
||||
|
||||
public static final String KEY_LauncherCardTipCounter = "LauncherCardTipCounter";
|
||||
public static final String KEY_LauncherCardTipLastTipTime = "LauncherCardTipLastTipTime";
|
||||
|
||||
|
||||
private static volatile LauncherCardRefresher sInstance;
|
||||
|
||||
public static final int MSG_REFRESH = 2020;
|
||||
public static final int MSG_TTS_TIP = 2021;
|
||||
public static final long ONE_MINUTE = 15 * 1000L;
|
||||
public static final long ONE_DAY = 24 * 60 * ONE_MINUTE;
|
||||
|
||||
private LauncherCardRefresher( Context context ) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public static LauncherCardRefresher getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( LauncherCardRefresher.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new LauncherCardRefresher( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
// 阻止反序列化,必须实现 Serializable 接口
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private Handler mHandler = new Handler( Looper.getMainLooper() ) {
|
||||
@Override
|
||||
public void handleMessage( Message msg ) {
|
||||
super.handleMessage( msg );
|
||||
if ( mRefreshStop ) {
|
||||
return;
|
||||
}
|
||||
switch ( msg.what ) {
|
||||
case MSG_REFRESH:
|
||||
try {
|
||||
handleRefreshMsg();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error when refresh launcher card." );
|
||||
}
|
||||
break;
|
||||
case MSG_TTS_TIP:
|
||||
playTTS();
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final Context mContext;
|
||||
private boolean mRefreshStop = true;
|
||||
private boolean mStart = false;
|
||||
private RefreshModel mRefreshModel;
|
||||
private LauncherCardRefreshStrategy mRefreshStrategy = new LauncherCardRefreshStrategy(
|
||||
2 * ONE_MINUTE,
|
||||
new LauncherCardRefreshStrategy(
|
||||
3 * ONE_MINUTE,
|
||||
new LauncherCardRefreshStrategy(
|
||||
20 * ONE_MINUTE,
|
||||
null,
|
||||
MSG_REFRESH ),
|
||||
MSG_REFRESH ),
|
||||
MSG_TTS_TIP
|
||||
);
|
||||
|
||||
public void start() {
|
||||
if ( DebugConfig.isLauncher() || DebugConfig.getCarMachineType() == DebugConfig.CAR_MACHINE_TYPE_BYD ) {
|
||||
return;
|
||||
}
|
||||
if ( mStart ) {
|
||||
return;
|
||||
}
|
||||
|
||||
int counter = SharedPrefsMgr.getInstance( mContext ).getInt( KEY_LauncherCardTipCounter, 0 );
|
||||
if ( counter >= 5 ) {
|
||||
long lastTipTime = SharedPrefsMgr.getInstance( mContext ).getLong( KEY_LauncherCardTipLastTipTime, 0L );
|
||||
if ( System.currentTimeMillis() - lastTipTime < 10 * ONE_DAY ) {
|
||||
stop();
|
||||
return;
|
||||
} else {
|
||||
SharedPrefsMgr.getInstance( mContext ).putInt( KEY_LauncherCardTipCounter, 0 );
|
||||
counter = 0;
|
||||
SharedPrefsMgr.getInstance( mContext ).putLong( KEY_LauncherCardTipLastTipTime, 0L );
|
||||
}
|
||||
}
|
||||
mHandler.sendEmptyMessageDelayed( mRefreshStrategy.getMsgType(), mRefreshStrategy.getInterval() );
|
||||
Logger.d( TAG, "start" );
|
||||
mRefreshStop = false;
|
||||
mStart = true;
|
||||
|
||||
SharedPrefsMgr.getInstance( mContext ).putInt( KEY_LauncherCardTipCounter, ++counter );
|
||||
SharedPrefsMgr.getInstance( mContext ).putLong( KEY_LauncherCardTipLastTipTime, System.currentTimeMillis() );
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
mRefreshStop = true;
|
||||
mStart = false;
|
||||
mHandler.removeMessages( MSG_REFRESH );
|
||||
mHandler.removeMessages( MSG_TTS_TIP );
|
||||
Logger.d( TAG, "stop" );
|
||||
}
|
||||
|
||||
private void restart() {
|
||||
if ( !mStart ) {
|
||||
return;
|
||||
}
|
||||
mRefreshStop = false;
|
||||
mHandler.removeMessages( MSG_REFRESH );
|
||||
mHandler.removeMessages( MSG_TTS_TIP );
|
||||
mHandler.sendEmptyMessageDelayed( mRefreshStrategy.getMsgType(), mRefreshStrategy.getInterval() );
|
||||
}
|
||||
|
||||
private void handleRefreshMsg() {
|
||||
if ( mRefreshModel == null ) {
|
||||
mRefreshModel = new RefreshModel( mContext );
|
||||
}
|
||||
MogoLocation location = MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation();
|
||||
if ( location == null ) {
|
||||
restart();
|
||||
return;
|
||||
}
|
||||
MogoLatLng latLng = new MogoLatLng( location.getLatitude(), location.getLongitude() );
|
||||
if ( mRefreshStrategy.getType() == LauncherCardRefreshType.ExploreWay ) {
|
||||
handleRefreshExplorerWayData( latLng );
|
||||
} else {
|
||||
handleRefreshOnlineCarData( latLng );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRefreshExplorerWayData( MogoLatLng latLng ) {
|
||||
mRefreshModel.refreshDataSync( latLng,
|
||||
mRefreshStrategy.getRadius(),
|
||||
mRefreshStrategy.getLimit(),
|
||||
new RefreshCallback< MarkerResponse >() {
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse response ) {
|
||||
notifyLauncherCard( LauncherCardRefreshType.ExploreWay, response );
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private void handleRefreshOnlineCarData( MogoLatLng latLng ) {
|
||||
mRefreshModel.queryOnLineCarWithRoute( latLng,
|
||||
false,
|
||||
true,
|
||||
mRefreshStrategy.getRadius(),
|
||||
mRefreshStrategy.getLimit(),
|
||||
new RefreshCallback< MarkerResponse >() {
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse response ) {
|
||||
notifyLauncherCard( LauncherCardRefreshType.OnlineCar, response );
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
private boolean notifyLauncherCard( LauncherCardRefreshType type, MarkerResponse response ) {
|
||||
if ( response == null || response.getResult() == null ) {
|
||||
return false;
|
||||
}
|
||||
String tts = mContext.getString( R.string.module_service_launcher_card_tips );
|
||||
String info = mContext.getString( R.string.module_service_launcher_card_info );
|
||||
if ( type == LauncherCardRefreshType.ExploreWay ) {
|
||||
if ( response.getResult().getExploreWay() == null || response.getResult().getExploreWay().isEmpty() ) {
|
||||
return false;
|
||||
}
|
||||
int size = response.getResult().getExploreWay().size();
|
||||
speakTTS( tts = String.format( tts, size, mRefreshStrategy.getDesc() ) );
|
||||
notifyLauncherCard( String.format( info, size, mRefreshStrategy.getDesc() ), size, tts );
|
||||
} else {
|
||||
if ( response.getResult().getOnlineCar() == null || response.getResult().getOnlineCar().isEmpty() ) {
|
||||
return false;
|
||||
}
|
||||
int size = response.getResult().getOnlineCar().size();
|
||||
speakTTS( tts = String.format( tts, size, mRefreshStrategy.getDesc() ) );
|
||||
notifyLauncherCard( String.format( info, size, mRefreshStrategy.getDesc() ), size , tts);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void speakTTS( String msg ) {
|
||||
if ( AppUtils.isAppForeground( mContext ) ) {
|
||||
return;
|
||||
}
|
||||
Logger.d( TAG, msg );
|
||||
AIAssist.getInstance( mContext ).speakTTSVoice( msg );
|
||||
}
|
||||
|
||||
private void notifyLauncherCard( String info, int amount, String tts ) {
|
||||
Intent intent = new Intent( "com.mogo.launcher.v2x" );
|
||||
intent.putExtra( "v2x_warning_type", "20000" );
|
||||
intent.putExtra( "v2x_warining_timeout", 20 * 1000 );
|
||||
intent.putExtra( "v2x_warning_tts", tts );
|
||||
intent.putExtra( "v2x_warning_eventCount", amount );
|
||||
intent.putExtra( "v2x_warning_info", info );
|
||||
mContext.sendBroadcast( intent );
|
||||
Logger.d( TAG, "发送广播到桌面卡片." );
|
||||
}
|
||||
|
||||
private void playTTS() {
|
||||
try {
|
||||
AIAssist.getInstance( mContext ).speakTTSVoice( mContext.getString( R.string.module_service_open_app_tip ) );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,10 @@ public interface RefreshApiService {
|
||||
@POST( "/yycp-launcherSnapshot/launcherSnapshot/querySnapshotAsync" )
|
||||
Observable< BaseData > refreshData( @FieldMap Map< String, Object > parameters );
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST( "/yycp-launcherSnapshot/launcherSnapshot/querySnapshotSync" )
|
||||
Observable< MarkerResponse > refreshDataSync( @FieldMap Map< String, Object > parameters );
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST( "/yycp-launcherSnapshot/user/queryOnLineCarWithRoute" )
|
||||
Observable<MarkerResponse> queryOnLineCarWithRoute(@FieldMap Map< String, Object > parameters );
|
||||
|
||||
@@ -105,6 +105,51 @@ public class RefreshModel {
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshDataSync( MogoLatLng latLng, int radius, int limit, final RefreshCallback callback ) {
|
||||
if ( mRefreshApiService != null ) {
|
||||
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
|
||||
final RefreshBody refreshBody = new RefreshBody();
|
||||
refreshBody.limit = limit;
|
||||
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
|
||||
refreshBody.radius = radius;
|
||||
refreshBody.dataType.add( ServiceConst.CARD_TYPE_ROAD_CONDITION );
|
||||
|
||||
String data = GsonUtil.jsonFromObject( refreshBody );
|
||||
query.put( "data", data );
|
||||
Logger.d( TAG, data );
|
||||
|
||||
|
||||
mRefreshApiService.refreshDataSync( query )
|
||||
.subscribeOn( Schedulers.io() )
|
||||
.observeOn( AndroidSchedulers.mainThread() )
|
||||
.subscribe( new SubscribeImpl< MarkerResponse >( RequestOptions.create( mContext ) ) {
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse o ) {
|
||||
super.onSuccess( o );
|
||||
if ( callback != null ) {
|
||||
callback.onSuccess( o );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError( Throwable e ) {
|
||||
super.onError( e );
|
||||
if ( callback != null ) {
|
||||
callback.onFail();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError( String message, int code ) {
|
||||
super.onError( message, code );
|
||||
if ( callback != null ) {
|
||||
callback.onFail();
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询车辆 及路线
|
||||
*
|
||||
|
||||
@@ -58,6 +58,8 @@ public class MogoReceiver extends BroadcastReceiver {
|
||||
// 接受高德发过来的广播
|
||||
public static final String ACTION_AUTO_NAVI_SEND = "AUTONAVI_STANDARD_BROADCAST_SEND";
|
||||
|
||||
public static final String ACTION_MOGO = "com.mogo.ACTION";
|
||||
|
||||
private IMogoIntentManager mMogoIntentManager;
|
||||
|
||||
public MogoReceiver(Context context) {
|
||||
|
||||
Reference in New Issue
Block a user