From 4a1f50e76fa7086649b8608f59c7b74e9b3d941e Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Fri, 27 Mar 2020 10:51:42 +0800 Subject: [PATCH 1/6] opt --- .../main/cards/CardIntroduceConfig.java | 23 +++++++++ .../main/cards/CardIntroduceConfigs.java | 47 +++++++++++++++++++ .../module/main/cards/MogoModulesManager.java | 23 ++++++--- .../service/marker/MapMarkerManager.java | 1 + .../service/impl/adas/MogoADASController.java | 4 ++ 5 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfig.java create mode 100644 modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfigs.java diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfig.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfig.java new file mode 100644 index 0000000000..ef3b24ed50 --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfig.java @@ -0,0 +1,23 @@ +package com.mogo.module.main.cards; + +/** + * @author congtaowang + * @since 2020-03-27 + *

+ * 卡片播报配置 + */ +public class CardIntroduceConfig { + + public String cardType; + public String broadcastWords; + public int broadcastAmount; + + public CardIntroduceConfig( String cardType, String broadcastWords, int broadcastAmount ) { + this.cardType = cardType; + this.broadcastWords = broadcastWords; + this.broadcastAmount = broadcastAmount; + } + + public CardIntroduceConfig() { + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfigs.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfigs.java new file mode 100644 index 0000000000..1d2434e2ec --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfigs.java @@ -0,0 +1,47 @@ +package com.mogo.module.main.cards; + +import com.mogo.module.common.ModuleNames; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author congtaowang + * @since 2020-03-27 + *

+ * 卡片播报配置 + */ +public class CardIntroduceConfigs { + + public static Map< String, CardIntroduceConfig > sConfigs = new HashMap<>(); + + static { + sConfigs.put( ModuleNames.CARD_TYPE_BUSINESS_OPERATION, new CardIntroduceConfig( ModuleNames.CARD_TYPE_BUSINESS_OPERATION, "随时查看路况,可以对我说某某地点堵不堵", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_SHARE_MUSIC, new CardIntroduceConfig( ModuleNames.CARD_TYPE_SHARE_MUSIC, "", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_CARS_CHATTING, new CardIntroduceConfig( ModuleNames.CARD_TYPE_CARS_CHATTING, "", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_ROAD_CONDITION, new CardIntroduceConfig( ModuleNames.CARD_TYPE_ROAD_CONDITION, "", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_USER_DATA, new CardIntroduceConfig( ModuleNames.CARD_TYPE_USER_DATA, "", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_NOVELTY, new CardIntroduceConfig( ModuleNames.CARD_TYPE_NOVELTY, "", 0 ) ); + } + + public static CardIntroduceConfig getConfig( String type ) { + return sConfigs.get( type ); + } + + public static void init( List< CardIntroduceConfig > configs ) { + if ( configs == null ) { + return; + } + for ( CardIntroduceConfig config : configs ) { + if ( config == null ) { + return; + } + sConfigs.put( config.cardType, config ); + } + } + + public static void increase( String type ) { + + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesManager.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesManager.java index 961aafd349..f4be4c7567 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesManager.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesManager.java @@ -31,6 +31,7 @@ import com.mogo.module.main.MainActivity; import com.mogo.module.main.assist.MapBroadCastHelper; import com.mogo.module.main.registercenter.MogoRegisterCenterHandler; import com.mogo.module.service.receiver.MogoReceiver; +import com.mogo.service.IMogoServiceApis; import com.mogo.service.MogoServicePaths; import com.mogo.service.analytics.IMogoAnalytics; import com.mogo.service.intent.IMogoIntentListener; @@ -38,7 +39,9 @@ import com.mogo.service.intent.IMogoIntentManager; import com.mogo.service.module.IMogoModuleLifecycle; import com.mogo.service.module.IMogoModuleProvider; import com.mogo.service.module.ModuleType; +import com.mogo.utils.CommonUtils; import com.mogo.utils.ResourcesHelper; +import com.mogo.utils.WorkThreadHandler; import com.mogo.utils.logger.Logger; import com.mogo.utils.network.utils.GsonUtil; import com.mogo.utils.storage.SharedPrefsMgr; @@ -66,6 +69,9 @@ public class MogoModulesManager implements MogoModulesHandler, private static final String TAG = "MogoModulesManager"; + public static final String KEY_VOICE_BROADCAST_CONFIG = "voice_broadcast_"; + private String mBroadcastConfigKey; + private MainActivity mActivity; private Map< MogoModule, IMogoModuleProvider > mModuleProviders = new HashMap<>(); @@ -86,15 +92,18 @@ public class MogoModulesManager implements MogoModulesHandler, throw new NullPointerException( "activity can't be null." ); } this.mActivity = activity; - mTrackManager = ( IMogoAnalytics ) ARouter.getInstance() - .build( MogoServicePaths.PATH_UTILS_ANALYTICS ) - .navigation(); - - mMogoIntentManager = ( IMogoIntentManager ) ARouter.getInstance() - .build( MogoServicePaths.PATH_INTENT_MANAGER ) - .navigation(); + IMogoServiceApis apis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation(); + mTrackManager = apis.getAnalyticsApi(); + mMogoIntentManager = apis.getIntentManagerApi(); registerReceiver(); + + WorkThreadHandler.getInstance().post( () -> { + mBroadcastConfigKey = KEY_VOICE_BROADCAST_CONFIG + CommonUtils.getVersionCode( mActivity ); + String configsStr = SharedPrefsMgr.getInstance( mActivity ).getString( mBroadcastConfigKey ); + List< CardIntroduceConfig > configs = GsonUtil.arrayFromJson( configsStr, CardIntroduceConfig.class ); + CardIntroduceConfigs.init( configs ); + } ); } private Context getContext() { diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java index 6dd1001e38..2828c1b12c 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java @@ -344,6 +344,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener, } // 解析不同的Marker类型,然后对应的进行绘制 + Logger.d( TAG, "draw marker" ); mLastDataResult = response.getResult(); UiThreadHandler.post( () -> { diff --git a/services/mogo-service/src/main/java/com/mogo/service/impl/adas/MogoADASController.java b/services/mogo-service/src/main/java/com/mogo/service/impl/adas/MogoADASController.java index 9969338db9..f2d6092c5e 100644 --- a/services/mogo-service/src/main/java/com/mogo/service/impl/adas/MogoADASController.java +++ b/services/mogo-service/src/main/java/com/mogo/service/impl/adas/MogoADASController.java @@ -47,6 +47,8 @@ public class MogoADASController implements IMogoADASController { return; } + Logger.d( TAG, "open adas" ); + Intent intent = new Intent( ACTION ); intent.putExtra( PARAM_COMMAND, VAL_COMMAND ); JSONObject object = new JSONObject(); @@ -67,6 +69,8 @@ public class MogoADASController implements IMogoADASController { return; } + Logger.d( TAG, "close adas" ); + Intent intent = new Intent( ACTION ); intent.putExtra( PARAM_COMMAND, VAL_COMMAND ); JSONObject object = new JSONObject(); From df18131405ef15e63297037da4a65a67d6ca1fe7 Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Fri, 27 Mar 2020 13:52:24 +0800 Subject: [PATCH 2/6] opt --- .../com/mogo/module/main/MainActivity.java | 6 +- .../main/cards/CardIntroduceConfigs.java | 82 ++- .../module/main/cards/MogoModulesManager.java | 12 +- .../com/mogo/module/service/MogoServices.java | 618 +++++++++--------- 4 files changed, 381 insertions(+), 337 deletions(-) diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/MainActivity.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/MainActivity.java index dde1f24783..a3c1ea3cde 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/MainActivity.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/MainActivity.java @@ -25,6 +25,8 @@ import com.mogo.map.uicontroller.IMogoMapUIController; import com.mogo.module.common.MogoModule; import com.mogo.module.common.MogoModulePaths; import com.mogo.module.main.assist.MapBroadCastHelper; +import com.mogo.module.main.cards.CardIntroduceConfig; +import com.mogo.module.main.cards.CardIntroduceConfigs; import com.mogo.module.main.cards.CardModulesAdapter; import com.mogo.module.main.cards.HorizentalStackTransformer; import com.mogo.module.main.cards.MogoModulesHandler; @@ -198,7 +200,8 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme mCardCoverUpBottomLayout = findViewById( R.id.module_main_id_card_cover_up_bottom ); // 避免事件穿透导致地图被滑动 - mLeftShadowFrame.setOnClickListener( view -> {} ); + mLeftShadowFrame.setOnClickListener( view -> { + } ); WindowViewHandler.init( mFloatingLayout ); } @@ -378,6 +381,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme MapBroadCastHelper.getInstance( this ).mapBackground(); super.onPause(); mMogoStatusManager.setMainPageResumeStatus( TAG, false ); + CardIntroduceConfigs.flush( getApplicationContext() ); } @Override diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfigs.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfigs.java index 1d2434e2ec..3c928968d1 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfigs.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardIntroduceConfigs.java @@ -1,7 +1,17 @@ package com.mogo.module.main.cards; -import com.mogo.module.common.ModuleNames; +import android.content.Context; +import com.mogo.commons.voice.AIAssist; +import com.mogo.commons.voice.VoicePreemptType; +import com.mogo.module.common.ModuleNames; +import com.mogo.utils.CommonUtils; +import com.mogo.utils.WorkThreadHandler; +import com.mogo.utils.logger.Logger; +import com.mogo.utils.network.utils.GsonUtil; +import com.mogo.utils.storage.SharedPrefsMgr; + +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,34 +24,66 @@ import java.util.Map; */ public class CardIntroduceConfigs { + private static final String TAG = "CardIntroduceConfigs"; + + public static final String KEY_VOICE_BROADCAST_CONFIG = "voice_broadcast_"; + public static String sBroadcastConfigKey; + public static Map< String, CardIntroduceConfig > sConfigs = new HashMap<>(); static { - sConfigs.put( ModuleNames.CARD_TYPE_BUSINESS_OPERATION, new CardIntroduceConfig( ModuleNames.CARD_TYPE_BUSINESS_OPERATION, "随时查看路况,可以对我说某某地点堵不堵", 0 ) ); - sConfigs.put( ModuleNames.CARD_TYPE_SHARE_MUSIC, new CardIntroduceConfig( ModuleNames.CARD_TYPE_SHARE_MUSIC, "", 0 ) ); - sConfigs.put( ModuleNames.CARD_TYPE_CARS_CHATTING, new CardIntroduceConfig( ModuleNames.CARD_TYPE_CARS_CHATTING, "", 0 ) ); - sConfigs.put( ModuleNames.CARD_TYPE_ROAD_CONDITION, new CardIntroduceConfig( ModuleNames.CARD_TYPE_ROAD_CONDITION, "", 0 ) ); - sConfigs.put( ModuleNames.CARD_TYPE_USER_DATA, new CardIntroduceConfig( ModuleNames.CARD_TYPE_USER_DATA, "", 0 ) ); - sConfigs.put( ModuleNames.CARD_TYPE_NOVELTY, new CardIntroduceConfig( ModuleNames.CARD_TYPE_NOVELTY, "", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_BUSINESS_OPERATION, new CardIntroduceConfig( ModuleNames.CARD_TYPE_BUSINESS_OPERATION, "", 3 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_SHARE_MUSIC, new CardIntroduceConfig( ModuleNames.CARD_TYPE_SHARE_MUSIC, "音乐新闻听书,海量资源随你选", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_CARS_CHATTING, new CardIntroduceConfig( ModuleNames.CARD_TYPE_CARS_CHATTING, "开车无聊,就用车聊聊", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_ROAD_CONDITION, new CardIntroduceConfig( ModuleNames.CARD_TYPE_ROAD_CONDITION, "随时查看路况,可以对我说某某地点堵不堵", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_USER_DATA, new CardIntroduceConfig( ModuleNames.CARD_TYPE_USER_DATA, "在线车辆,邀你在地图上发现万千有趣的车友", 0 ) ); + sConfigs.put( ModuleNames.CARD_TYPE_NOVELTY, new CardIntroduceConfig( ModuleNames.CARD_TYPE_NOVELTY, "新鲜事,邀你给同城车友分享沿途封路、拥堵消息", 0 ) ); } - public static CardIntroduceConfig getConfig( String type ) { - return sConfigs.get( type ); - } + public static void init( Context context ) { - public static void init( List< CardIntroduceConfig > configs ) { - if ( configs == null ) { - return; - } - for ( CardIntroduceConfig config : configs ) { - if ( config == null ) { + WorkThreadHandler.getInstance().post( () -> { + sBroadcastConfigKey = KEY_VOICE_BROADCAST_CONFIG + CommonUtils.getVersionCode( context ); + String configsStr = SharedPrefsMgr.getInstance( context ).getString( sBroadcastConfigKey ); + List< CardIntroduceConfig > configs = GsonUtil.arrayFromJson( configsStr, CardIntroduceConfig.class ); + if ( configs == null ) { return; } - sConfigs.put( config.cardType, config ); - } + for ( CardIntroduceConfig config : configs ) { + if ( config == null ) { + return; + } + sConfigs.put( config.cardType, config ); + } + } ); } - public static void increase( String type ) { - + public static void broadcast( Context context, String type ) { + if ( sConfigs.get( type ) == null ) { + Logger.d( TAG, "un support %s", type ); + return; + } + if ( sConfigs.get( type ).broadcastAmount >= 3 ) { + Logger.d( TAG, "do not broadcast %s cast amount = %s", type, type ); + return; + } + + CardIntroduceConfig config = sConfigs.get( type ); + config.broadcastAmount++; + + Logger.d( TAG, "speak card introduce: %s", config.broadcastWords ); + AIAssist.getInstance( context ).speakTTSVoice( config.broadcastWords, VoicePreemptType.PREEMPT_TYPE_IMMEADIATELY, null ); + } + + public static void flush( Context context ) { + if ( sBroadcastConfigKey == null || sConfigs.isEmpty() ) { + return; + } + WorkThreadHandler.getInstance().post( () -> { + synchronized ( sConfigs ) { + ArrayList configs = new ArrayList( sConfigs.entrySet() ); + SharedPrefsMgr.getInstance( context ).putString( sBroadcastConfigKey, GsonUtil.jsonFromObject( configs ) ); + } + } ); } } diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesManager.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesManager.java index f4be4c7567..fb8370c364 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesManager.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesManager.java @@ -69,7 +69,7 @@ public class MogoModulesManager implements MogoModulesHandler, private static final String TAG = "MogoModulesManager"; - public static final String KEY_VOICE_BROADCAST_CONFIG = "voice_broadcast_"; + private String mBroadcastConfigKey; private MainActivity mActivity; @@ -97,13 +97,7 @@ public class MogoModulesManager implements MogoModulesHandler, mMogoIntentManager = apis.getIntentManagerApi(); registerReceiver(); - - WorkThreadHandler.getInstance().post( () -> { - mBroadcastConfigKey = KEY_VOICE_BROADCAST_CONFIG + CommonUtils.getVersionCode( mActivity ); - String configsStr = SharedPrefsMgr.getInstance( mActivity ).getString( mBroadcastConfigKey ); - List< CardIntroduceConfig > configs = GsonUtil.arrayFromJson( configsStr, CardIntroduceConfig.class ); - CardIntroduceConfigs.init( configs ); - } ); + CardIntroduceConfigs.init( getContext() ); } private Context getContext() { @@ -288,6 +282,8 @@ public class MogoModulesManager implements MogoModulesHandler, mSortedCards.add( 0, mEnableModuleName ); SharedPrefsMgr.getInstance( getContext() ).putString( KEY_SORTED_CARD_MODULES, GsonUtil.jsonFromObject( mSortedCards ) ); Log.i( TAG, "enable & disable card cost " + ( System.currentTimeMillis() - start1 ) + "ms" ); + + CardIntroduceConfigs.broadcast( mActivity, mEnableModuleName ); } @Override diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java index bf2913cbab..9fb7bd3426 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java @@ -81,13 +81,13 @@ import java.util.List; * 4. 用户交互语音导致地图视图移动,缩放,不触发刷新 */ public class MogoServices implements IMogoMapListener, - IMogoLocationListener, - IMogoNaviListener, - IMogoStatusChangedListener, - IMogoIntentListener, - IMogoAimlessModeListener, - IMogoVoiceCmdCallBack, - FragmentStackTransactionListener { + IMogoLocationListener, + IMogoNaviListener, + IMogoStatusChangedListener, + IMogoIntentListener, + IMogoAimlessModeListener, + IMogoVoiceCmdCallBack, + FragmentStackTransactionListener { private boolean mInternalUnWakeupRegisterStatus = false; @@ -165,30 +165,30 @@ public class MogoServices implements IMogoMapListener, */ private boolean mLoopRequest = false; - private Handler mHandler = new Handler(Looper.getMainLooper()) { + private Handler mHandler = new Handler( Looper.getMainLooper() ) { @Override - public void handleMessage(@NonNull Message msg) { - super.handleMessage(msg); - switch (msg.what) { + public void handleMessage( @NonNull Message msg ) { + super.handleMessage( msg ); + switch ( msg.what ) { case ServiceConst.MSG_TYPE_REFRESH_DECREASE: - if (mStatusManager.isSearchUIShow() || mStatusManager.isADASShow()) { + if ( mStatusManager.isSearchUIShow() || mStatusManager.isADASShow() ) { stopAutoRefreshStrategy(); return; } mRefreshRemainingTime -= ServiceConst.DECREASE_INTERVAL; - if (mRefreshRemainingTime <= 0) { - Logger.d(TAG, "move to center and refresh data."); + if ( mRefreshRemainingTime <= 0 ) { + Logger.d( TAG, "move to center and refresh data." ); invokeAutoRefresh(); } else { - mHandler.sendEmptyMessageDelayed(msg.what, ServiceConst.DECREASE_INTERVAL); + mHandler.sendEmptyMessageDelayed( msg.what, ServiceConst.DECREASE_INTERVAL ); } break; case ServiceConst.MSG_LOOP_REQUEST: - if (mStatusManager.isSearchUIShow() || mStatusManager.isADASShow()) { + if ( mStatusManager.isSearchUIShow() || mStatusManager.isADASShow() ) { return; } - if (mLoopRequest) { - Logger.d(TAG, "补偿刷新触发"); + if ( mLoopRequest ) { + Logger.d( TAG, "补偿刷新触发" ); invokeAutoRefresh(); } break; @@ -199,13 +199,13 @@ public class MogoServices implements IMogoMapListener, * 自动刷新:锁车、缩放比例:16、半径 2KM */ private void invokeAutoRefresh() { - mStatusManager.setUserInteractionStatus(ServiceConst.TYPE, true, false); - mUiController.changeZoom(ServiceConst.DEFAULT_LOCK_CAR_ZOOM_LEVEL); - mUiController.setLockZoom(ServiceConst.DEFAULT_LOCK_CAR_ZOOM_LEVEL); - mStatusManager.setUserInteractionStatus(TAG, true, false); + mStatusManager.setUserInteractionStatus( ServiceConst.TYPE, true, false ); + mUiController.changeZoom( ServiceConst.DEFAULT_LOCK_CAR_ZOOM_LEVEL ); + mUiController.setLockZoom( ServiceConst.DEFAULT_LOCK_CAR_ZOOM_LEVEL ); + mStatusManager.setUserInteractionStatus( TAG, true, false ); mUiController.recoverLockMode(); - notifyRefreshData(mLastAutoRefreshLocation, - ServiceConst.DEFAULT_AUTO_REFRESH_DATA_RADIUS, mAutoRefreshCallback); + notifyRefreshData( mLastAutoRefreshLocation, + ServiceConst.DEFAULT_AUTO_REFRESH_DATA_RADIUS, mAutoRefreshCallback ); } }; private Context mContext; @@ -228,7 +228,7 @@ public class MogoServices implements IMogoMapListener, public void onSuccess() { mLoopRequest = false; // 用户手动操作地图刷新成功后,设置状态为 true,引发延时策略 - mStatusManager.setUserInteractionStatus(ServiceConst.TYPE, true, true); + mStatusManager.setUserInteractionStatus( ServiceConst.TYPE, true, true ); } @Override @@ -244,29 +244,29 @@ public class MogoServices implements IMogoMapListener, @Override public void onSuccess() { mLoopRequest = false; - Logger.d(TAG, "request Success."); + Logger.d( TAG, "request Success." ); invokeAutoRefreshStrategy(); } @Override public void onFail() { - if (mLoopRequest) { - Logger.d(TAG, "onFail and loop"); - mHandler.sendEmptyMessageDelayed(ServiceConst.MSG_LOOP_REQUEST, - ServiceConst.LOOP_INTERVAL); + if ( mLoopRequest ) { + Logger.d( TAG, "onFail and loop" ); + mHandler.sendEmptyMessageDelayed( ServiceConst.MSG_LOOP_REQUEST, + ServiceConst.LOOP_INTERVAL ); } else { invokeAutoRefreshStrategy(); } } private void invokeAutoRefreshStrategy() { - if (mStatusManager.isSearchUIShow()) { + if ( mStatusManager.isSearchUIShow() ) { return; } mRefreshRemainingTime = mAutoRefreshStrategy.getInterval(); - mHandler.removeMessages(ServiceConst.MSG_TYPE_REFRESH_DECREASE); - mHandler.sendEmptyMessageDelayed(ServiceConst.MSG_TYPE_REFRESH_DECREASE, - ServiceConst.DECREASE_INTERVAL); + mHandler.removeMessages( ServiceConst.MSG_TYPE_REFRESH_DECREASE ); + mHandler.sendEmptyMessageDelayed( ServiceConst.MSG_TYPE_REFRESH_DECREASE, + ServiceConst.DECREASE_INTERVAL ); } }; @@ -274,120 +274,120 @@ public class MogoServices implements IMogoMapListener, private Handler mThreadHandler; - public void init(Context context) { + public void init( Context context ) { mContext = context; - MarkerServiceHandler.init(mContext); - mRefreshModel = new RefreshModel(context); + MarkerServiceHandler.init( mContext ); + mRefreshModel = new RefreshModel( context ); mMogoMapService = MarkerServiceHandler.getMapService(); mUiController = mMogoMapService.getMapUIController(); - mNavi = mMogoMapService.getNavi(context); + mNavi = mMogoMapService.getNavi( context ); mStatusManager = MarkerServiceHandler.getMogoStatusManager(); - mStatusManager.registerStatusChangedListener(ServiceConst.TYPE, - StatusDescriptor.USER_INTERACTED, this); - mStatusManager.registerStatusChangedListener(ServiceConst.TYPE, StatusDescriptor.SEARCH_UI, - this); - mStatusManager.registerStatusChangedListener(ServiceConst.TYPE, StatusDescriptor.ADAS_UI, - this); - mStatusManager.registerStatusChangedListener(ServiceConst.TYPE, - StatusDescriptor.MAIN_PAGE_RESUME, this); + mStatusManager.registerStatusChangedListener( ServiceConst.TYPE, + StatusDescriptor.USER_INTERACTED, this ); + mStatusManager.registerStatusChangedListener( ServiceConst.TYPE, StatusDescriptor.SEARCH_UI, + this ); + mStatusManager.registerStatusChangedListener( ServiceConst.TYPE, StatusDescriptor.ADAS_UI, + this ); + mStatusManager.registerStatusChangedListener( ServiceConst.TYPE, + StatusDescriptor.MAIN_PAGE_RESUME, this ); - registerMogoReceiver(context); + registerMogoReceiver( context ); registerInternalUnWakeupWords(); mRegisterCenter = MarkerServiceHandler.getRegisterCenter(); - mRegisterCenter.registerMogoLocationListener(ServiceConst.TYPE, this); - mRegisterCenter.registerMogoNaviListener(ServiceConst.TYPE, this); - mRegisterCenter.registerMogoMapListener(ServiceConst.TYPE, this); - mRegisterCenter.registerMogoAimlessModeListener(ServiceConst.TYPE, this); + mRegisterCenter.registerMogoLocationListener( ServiceConst.TYPE, this ); + mRegisterCenter.registerMogoNaviListener( ServiceConst.TYPE, this ); + mRegisterCenter.registerMogoMapListener( ServiceConst.TYPE, this ); + mRegisterCenter.registerMogoAimlessModeListener( ServiceConst.TYPE, this ); mActionManager = MarkerServiceHandler.getActionManager(); mIntentManager = MarkerServiceHandler.getIntentManager(); - mIntentManager.registerIntentListener(MogoReceiver.ACTIION_ADAS, this); - mIntentManager.registerIntentListener(Intent.ACTION_POWER_CONNECTED, this); - mIntentManager.registerIntentListener(Intent.ACTION_POWER_DISCONNECTED, this); - mIntentManager.registerIntentListener(MogoReceiver.ACTION_NWD_ACC, this); - mIntentManager.registerIntentListener(MogoReceiver.ACTION_VOICE_UI, this); - mIntentManager.registerIntentListener(ServiceConst.COMMAND_NEXT, this); - mIntentManager.registerIntentListener(ServiceConst.COMMAND_PREVIOUS, this); - mIntentManager.registerIntentListener(ServiceConst.COMMAND_SWITCH_CARD, this); - mIntentManager.registerIntentListener(ServiceConst.COMMAND_MY_LOCATION, this); - mIntentManager.registerIntentListener(MogoReceiver.ACTION_ADAS_STATUS, this); - mIntentManager.registerIntentListener(ServiceConst.COMMAND_OPERATION, this); - mIntentManager.registerIntentListener(MogoReceiver.ACTION_VOICE_READY, this); - mIntentManager.registerIntentListener(MogoReceiver.ACTION_MOCK, this); + mIntentManager.registerIntentListener( MogoReceiver.ACTIION_ADAS, this ); + mIntentManager.registerIntentListener( Intent.ACTION_POWER_CONNECTED, this ); + mIntentManager.registerIntentListener( Intent.ACTION_POWER_DISCONNECTED, this ); + mIntentManager.registerIntentListener( MogoReceiver.ACTION_NWD_ACC, this ); + mIntentManager.registerIntentListener( MogoReceiver.ACTION_VOICE_UI, this ); + mIntentManager.registerIntentListener( ServiceConst.COMMAND_NEXT, this ); + mIntentManager.registerIntentListener( ServiceConst.COMMAND_PREVIOUS, this ); + mIntentManager.registerIntentListener( ServiceConst.COMMAND_SWITCH_CARD, this ); + mIntentManager.registerIntentListener( ServiceConst.COMMAND_MY_LOCATION, this ); + mIntentManager.registerIntentListener( MogoReceiver.ACTION_ADAS_STATUS, this ); + mIntentManager.registerIntentListener( ServiceConst.COMMAND_OPERATION, this ); + mIntentManager.registerIntentListener( MogoReceiver.ACTION_VOICE_READY, this ); + mIntentManager.registerIntentListener( MogoReceiver.ACTION_MOCK, this ); mADASController = MarkerServiceHandler.getADASController(); mLauncher = MarkerServiceHandler.getLauncher(); mFragmentManager = MarkerServiceHandler.getFragmentManager(); mCardManager = MarkerServiceHandler.getMogoCardManager(); - mFragmentManager.addMainFragmentStackTransactionListener(this); + mFragmentManager.addMainFragmentStackTransactionListener( this ); initWorkThread(); } private void initWorkThread() { - mHandlerThread = new HandlerThread("mogo-handler-thread"); + mHandlerThread = new HandlerThread( "mogo-handler-thread" ); mHandlerThread.start(); - mThreadHandler = new Handler(mHandlerThread.getLooper()) { + mThreadHandler = new Handler( mHandlerThread.getLooper() ) { @Override - public void handleMessage(Message msg) { - super.handleMessage(msg); - if (msg.what == ServiceConst.MSG_MAP_CHANGED) { - if (msg.obj instanceof RefreshObject) { - RefreshObject ro = ((RefreshObject) msg.obj); - if (invokeRefreshWhenTranslationByUser(ro.mLonLat)) { - notifyRefreshData(ro.mLonLat, ro.mRadius, ro.mCallback); + public void handleMessage( Message msg ) { + super.handleMessage( msg ); + if ( msg.what == ServiceConst.MSG_MAP_CHANGED ) { + if ( msg.obj instanceof RefreshObject ) { + RefreshObject ro = ( ( RefreshObject ) msg.obj ); + if ( invokeRefreshWhenTranslationByUser( ro.mLonLat ) ) { + notifyRefreshData( ro.mLonLat, ro.mRadius, ro.mCallback ); mLastCustomRefreshCenterLocation = ro.mLonLat; } } - } else if (msg.what == ServiceConst.MSG_REQUEST_DATA) { - if (msg.obj instanceof RefreshObject) { - RefreshObject ro = ((RefreshObject) msg.obj); - mRefreshModel.refreshData(ro.mLonLat, ro.mRadius, ro.mAmount, ro.mCallback); - Logger.i(TAG, "刷新半径 = %s, 点 = %s, zoomLevel = %s, amount = %s", ro.mRadius, - ro.mLonLat, mLastZoomLevel, ro.mAmount); + } else if ( msg.what == ServiceConst.MSG_REQUEST_DATA ) { + if ( msg.obj instanceof RefreshObject ) { + RefreshObject ro = ( ( RefreshObject ) msg.obj ); + mRefreshModel.refreshData( ro.mLonLat, ro.mRadius, ro.mAmount, ro.mCallback ); + Logger.i( TAG, "刷新半径 = %s, 点 = %s, zoomLevel = %s, amount = %s", ro.mRadius, + ro.mLonLat, mLastZoomLevel, ro.mAmount ); } } } }; } - private void registerMogoReceiver(Context context) { - if (context == null) { + private void registerMogoReceiver( Context context ) { + if ( context == null ) { return; } - List modules = MogoModulePaths.getModules(); - if (modules.isEmpty() || modules == null) { + List< MogoModule > modules = MogoModulePaths.getModules(); + if ( modules.isEmpty() || modules == null ) { return; } - mAIAssistReceiver = new MogoReceiver(context); + mAIAssistReceiver = new MogoReceiver( context ); IntentFilter filter = new IntentFilter(); - if (modules != null && !modules.isEmpty()) { - for (MogoModule module : modules) { - if (TextUtils.isEmpty(module.getBroadcastAction())) { + if ( modules != null && !modules.isEmpty() ) { + for ( MogoModule module : modules ) { + if ( TextUtils.isEmpty( module.getBroadcastAction() ) ) { continue; } - filter.addAction(module.getBroadcastAction()); + filter.addAction( module.getBroadcastAction() ); } } - filter.addAction(MogoReceiver.VOICE_ACTION); - filter.addAction(MogoReceiver.ACTIION_ADAS); - filter.addAction(MogoReceiver.ACTION_NWD_ACC); + filter.addAction( MogoReceiver.VOICE_ACTION ); + filter.addAction( MogoReceiver.ACTIION_ADAS ); + filter.addAction( MogoReceiver.ACTION_NWD_ACC ); // acc On - filter.addAction(Intent.ACTION_POWER_CONNECTED); - filter.addAction(Intent.ACTION_POWER_DISCONNECTED); + filter.addAction( Intent.ACTION_POWER_CONNECTED ); + filter.addAction( Intent.ACTION_POWER_DISCONNECTED ); // 小智语音 - filter.addAction(MogoReceiver.ACTION_VOICE_UI); - filter.addAction(MogoReceiver.ACTION_ADAS_STATUS); - filter.addAction(MogoReceiver.ACTION_VOICE_READY); - filter.addAction(MogoReceiver.ACTION_MOCK); + filter.addAction( MogoReceiver.ACTION_VOICE_UI ); + filter.addAction( MogoReceiver.ACTION_ADAS_STATUS ); + filter.addAction( MogoReceiver.ACTION_VOICE_READY ); + filter.addAction( MogoReceiver.ACTION_MOCK ); try { - context.getApplicationContext().registerReceiver(mAIAssistReceiver, filter); - Logger.i(TAG, "register voice receiver."); - } catch (Exception e) { - Logger.e(TAG, e, "error. "); + context.getApplicationContext().registerReceiver( mAIAssistReceiver, filter ); + Logger.i( TAG, "register voice receiver." ); + } catch ( Exception e ) { + Logger.e( TAG, e, "error. " ); } } @@ -397,16 +397,16 @@ public class MogoServices implements IMogoMapListener, } private void initMapStatus() { - if (mIsMapStatusOk) { + if ( mIsMapStatusOk ) { return; } try { float width = getMapCameraFactWidth(); float height = getMapCameraFactHeight(); mIsVertical = width < height; - Logger.i(TAG, "map status is vertical : " + mIsVertical); + Logger.i( TAG, "map status is vertical : " + mIsVertical ); mIsMapStatusOk = true; - } catch (Exception e) { + } catch ( Exception e ) { e.printStackTrace(); } } @@ -416,9 +416,9 @@ public class MogoServices implements IMogoMapListener, */ private float getMapCameraFactWidth() { try { - return Utils.calculateLineDistance(mCameraNorthEastPosition, - new MogoLatLng(mCameraNorthEastPosition.lat, mCameraSouthWestPosition.lng)); - } catch (Exception e) { + return Utils.calculateLineDistance( mCameraNorthEastPosition, + new MogoLatLng( mCameraNorthEastPosition.lat, mCameraSouthWestPosition.lng ) ); + } catch ( Exception e ) { return ServiceConst.DEFAULT_AUTO_REFRESH_DATA_RADIUS; } } @@ -428,57 +428,57 @@ public class MogoServices implements IMogoMapListener, */ private float getMapCameraFactHeight() { try { - return Utils.calculateLineDistance(mCameraSouthWestPosition, - new MogoLatLng(mCameraNorthEastPosition.lat, mCameraSouthWestPosition.lng)); - } catch (Exception e) { + return Utils.calculateLineDistance( mCameraSouthWestPosition, + new MogoLatLng( mCameraNorthEastPosition.lat, mCameraSouthWestPosition.lng ) ); + } catch ( Exception e ) { return ServiceConst.DEFAULT_AUTO_REFRESH_DATA_RADIUS; } } @Override - public void onTouch(MotionEvent motionEvent) { - switch (motionEvent.getActionMasked()) { + public void onTouch( MotionEvent motionEvent ) { + switch ( motionEvent.getActionMasked() ) { case MotionEvent.ACTION_DOWN: - if (mLastZoomLevel == 0) { + if ( mLastZoomLevel == 0 ) { mLastZoomLevel = mUiController.getZoomLevel(); - Logger.i(TAG, "初始化缩放级别 为:%f", mLastZoomLevel); + Logger.i( TAG, "初始化缩放级别 为:%f", mLastZoomLevel ); } break; case MotionEvent.ACTION_UP: - restartAutoRefreshAtTime(ServiceConst.DEFAULT_AUTO_REFRESH_WHEN_INTERRUPT); + restartAutoRefreshAtTime( ServiceConst.DEFAULT_AUTO_REFRESH_WHEN_INTERRUPT ); break; } } private void stopAutoRefreshStrategy() { - Logger.d(TAG, "stop auto refresh strategy"); - mHandler.removeMessages(ServiceConst.MSG_TYPE_REFRESH_DECREASE); + Logger.d( TAG, "stop auto refresh strategy" ); + mHandler.removeMessages( ServiceConst.MSG_TYPE_REFRESH_DECREASE ); } @Override - public void onPOIClick(MogoPoi poi) { + public void onPOIClick( MogoPoi poi ) { } @Override - public void onMapClick(MogoLatLng latLng) { + public void onMapClick( MogoLatLng latLng ) { } @Override - public void onLockMap(boolean isLock) { + public void onLockMap( boolean isLock ) { } @Override - public void onMapModeChanged(EnumMapUI ui) { + public void onMapModeChanged( EnumMapUI ui ) { } @Override - public void onMapChanged(MogoLatLng latLng, float zoom, float tilt, float bearing) { + public void onMapChanged( MogoLatLng latLng, float zoom, float tilt, float bearing ) { - if (mIsCameraInited) { + if ( mIsCameraInited ) { mLastZoomLevel = zoom; mLastCustomRefreshCenterLocation = latLng; mIsCameraInited = false; @@ -488,117 +488,117 @@ public class MogoServices implements IMogoMapListener, // 部分非用户操作导致地图视图变化:绘线、圈点等不触发用户刷新 // 消费状态 - if (mStatusManager.isUserInteracted()) { + if ( mStatusManager.isUserInteracted() ) { mLastCustomRefreshCenterLocation = latLng; mLastZoomLevel = zoom; return; } // v2x // adas 状态下不做任何操作 - if (mStatusManager.isADASShow()) { + if ( mStatusManager.isADASShow() ) { mLastCustomRefreshCenterLocation = latLng; mLastZoomLevel = zoom; return; } // 手动刷新触发 - if (mLastZoomLevel - zoom > mCustomRefreshStrategy.getZoomOutLevel()) { + if ( mLastZoomLevel - zoom > mCustomRefreshStrategy.getZoomOutLevel() ) { // 缩放级别缩小 - notifyRefreshData(latLng, getQueryRadius(), mCustomRefreshCallback); + notifyRefreshData( latLng, getQueryRadius(), mCustomRefreshCallback ); mLastCustomRefreshCenterLocation = latLng; mLastZoomLevel = zoom; - } else if (mLastZoomLevel - zoom < 0) { + } else if ( mLastZoomLevel - zoom < 0 ) { mLastZoomLevel = zoom; - } else if (mLastZoomLevel == zoom) { + } else if ( mLastZoomLevel == zoom ) { // 手动平移 Message msg = Message.obtain(); msg.what = ServiceConst.MSG_MAP_CHANGED; - msg.obj = new RefreshObject(mCustomRefreshCallback, getQueryRadius(), latLng, 0); - mThreadHandler.sendMessage(msg); + msg.obj = new RefreshObject( mCustomRefreshCallback, getQueryRadius(), latLng, 0 ); + mThreadHandler.sendMessage( msg ); } } private int getQueryRadius() { mCameraSouthWestPosition = mUiController.getCameraSouthWestPosition(); mCameraNorthEastPosition = mUiController.getCameraNorthEastPosition(); - if (mIsVertical) { - return ((int) (getMapCameraFactWidth() / 2)); + if ( mIsVertical ) { + return ( ( int ) ( getMapCameraFactWidth() / 2 ) ); } - return ((int) (getMapCameraFactHeight() / 2)); + return ( ( int ) ( getMapCameraFactHeight() / 2 ) ); } /** * 平移地图刷新策略 */ - private boolean invokeRefreshWhenTranslationByUser(MogoLatLng latLng) { + private boolean invokeRefreshWhenTranslationByUser( MogoLatLng latLng ) { try { - Trace.beginSection("timer.invokeRefreshWhenTranslationByUser"); + Trace.beginSection( "timer.invokeRefreshWhenTranslationByUser" ); float factor = 0.0f; - if (mIsVertical) { + if ( mIsVertical ) { factor = getMapCameraFactWidth(); } else { factor = getMapCameraFactHeight(); } - if (factor == 0.0f) { + if ( factor == 0.0f ) { return false; } - float distance = Utils.calculateLineDistance(latLng, mLastCustomRefreshCenterLocation); + float distance = Utils.calculateLineDistance( latLng, mLastCustomRefreshCenterLocation ); Trace.endSection(); return distance > factor; - } catch (Exception e) { - Logger.e(TAG, e, "warming. "); + } catch ( Exception e ) { + Logger.e( TAG, e, "warming. " ); return false; } } @Override - public void onLocationChanged(MogoLocation location) { + public void onLocationChanged( MogoLocation location ) { - if (mStatusManager.isADASShow()) { + if ( mStatusManager.isADASShow() ) { return; } - if (mStatusManager.isSearchUIShow()) { + if ( mStatusManager.isSearchUIShow() ) { return; } - if (location == null) { + if ( location == null ) { return; } // 自动刷新触发 - final MogoLatLng point = new MogoLatLng(location.getLatitude(), location.getLongitude()); - if (mLastAutoRefreshLocation == null) { + final MogoLatLng point = new MogoLatLng( location.getLatitude(), location.getLongitude() ); + if ( mLastAutoRefreshLocation == null ) { mLastAutoRefreshLocation = point; mLoopRequest = true; - notifyRefreshData(mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback); + notifyRefreshData( mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback ); return; } - float distance = Utils.calculateLineDistance(mLastAutoRefreshLocation, point); - if (distance > mAutoRefreshStrategy.getDistance()) { - mStatusManager.setUserInteractionStatus(ServiceConst.TYPE, true, false); + float distance = Utils.calculateLineDistance( mLastAutoRefreshLocation, point ); + if ( distance > mAutoRefreshStrategy.getDistance() ) { + mStatusManager.setUserInteractionStatus( ServiceConst.TYPE, true, false ); mUiController.recoverLockMode(); - mStatusManager.setUserInteractionStatus(TAG, true, false); - mUiController.changeZoom(ServiceConst.DEFAULT_ZOOM_LEVEL); + mStatusManager.setUserInteractionStatus( TAG, true, false ); + mUiController.changeZoom( ServiceConst.DEFAULT_ZOOM_LEVEL ); mLastAutoRefreshLocation = point; - notifyRefreshData(mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback); + notifyRefreshData( mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback ); } } /** * 刷新数据 */ - private void notifyRefreshData(MogoLatLng latLng, int radius, RefreshCallback callback) { - if (mStatusManager.isSearchUIShow()) { + private void notifyRefreshData( MogoLatLng latLng, int radius, RefreshCallback callback ) { + if ( mStatusManager.isSearchUIShow() ) { return; } - Logger.d(TAG, mAutoRefreshCallback == callback ? "触发自动刷新" : "触发手动刷新"); + Logger.d( TAG, mAutoRefreshCallback == callback ? "触发自动刷新" : "触发手动刷新" ); int amount = mLastZoomLevel >= 10 ? 5 : 10; Message msg = Message.obtain(); msg.what = ServiceConst.MSG_REQUEST_DATA; - msg.obj = new RefreshObject(callback, radius, latLng, amount); - mThreadHandler.sendMessage(msg); + msg.obj = new RefreshObject( callback, radius, latLng, amount ); + mThreadHandler.sendMessage( msg ); } @Override @@ -612,7 +612,7 @@ public class MogoServices implements IMogoMapListener, } @Override - public void onNaviInfoUpdate(MogoNaviInfo naviinfo) { + public void onNaviInfoUpdate( MogoNaviInfo naviinfo ) { } @Override @@ -624,38 +624,38 @@ public class MogoServices implements IMogoMapListener, } @Override - public void onStatusChanged(StatusDescriptor descriptor, boolean isTrue) { + public void onStatusChanged( StatusDescriptor descriptor, boolean isTrue ) { //Logger.d( TAG, "状态发生改变---descriptor---" + descriptor + "----isTrue---" + isTrue ); - switch (descriptor) { + switch ( descriptor ) { case USER_INTERACTED: - if (isTrue) { - restartAutoRefreshAtTime(ServiceConst.DEFAULT_AUTO_REFRESH_WHEN_INTERRUPT); + if ( isTrue ) { + restartAutoRefreshAtTime( ServiceConst.DEFAULT_AUTO_REFRESH_WHEN_INTERRUPT ); } break; case SEARCH_UI: - if (isTrue) { + if ( isTrue ) { // 搜索时,不在自动刷新打点策略 stopAutoRefreshStrategy(); } else { // 搜索后,打开打点策略 - if (mAutoRefreshCallback != null) { + if ( mAutoRefreshCallback != null ) { mAutoRefreshCallback.onSuccess(); } } break; case ADAS_UI: try { - if (isTrue) { + if ( isTrue ) { onAdasOn(); } else { onAdasClosed(); } - } catch (Exception e) { + } catch ( Exception e ) { e.printStackTrace(); } break; case MAIN_PAGE_RESUME: - if (isTrue) { + if ( isTrue ) { registerInternalUnWakeupWords(); } else { unregisterInternalUnWakeupWords(); @@ -674,31 +674,31 @@ public class MogoServices implements IMogoMapListener, private void onAdasClosed() { refreshStrategy(); // ADAS关闭后,打开打点策略 - if (mAutoRefreshCallback != null) { + if ( mAutoRefreshCallback != null ) { mAutoRefreshCallback.onSuccess(); } } - public void restartAutoRefreshAtTime(int time) { - if (time < 0) { - Logger.w(TAG, "ignore refresh request case time < 0"); + public void restartAutoRefreshAtTime( int time ) { + if ( time < 0 ) { + Logger.w( TAG, "ignore refresh request case time < 0" ); return; } stopAutoRefreshStrategy(); mRefreshRemainingTime = time; long delay = ServiceConst.DECREASE_INTERVAL; - if (mRefreshRemainingTime < ServiceConst.DECREASE_INTERVAL) { + if ( mRefreshRemainingTime < ServiceConst.DECREASE_INTERVAL ) { delay = mRefreshRemainingTime; } - mHandler.sendEmptyMessageDelayed(ServiceConst.MSG_TYPE_REFRESH_DECREASE, delay); - Logger.i(TAG, "下次刷新时间:%ss后", mRefreshRemainingTime); + mHandler.sendEmptyMessageDelayed( ServiceConst.MSG_TYPE_REFRESH_DECREASE, delay ); + Logger.i( TAG, "下次刷新时间:%ss后", mRefreshRemainingTime ); } public void refreshStrategy() { - Logger.d(TAG, "move to center and refresh data."); - mStatusManager.setUserInteractionStatus(ServiceConst.TYPE, true, false); + Logger.d( TAG, "move to center and refresh data." ); + mStatusManager.setUserInteractionStatus( ServiceConst.TYPE, true, false ); mUiController.recoverLockMode();// 锁车代替移到中心点 - notifyRefreshData(mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback); + notifyRefreshData( mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback ); } @Override @@ -712,36 +712,36 @@ public class MogoServices implements IMogoMapListener, } @Override - public void onUpdateTraffic(MogoTraffic traffic) { + public void onUpdateTraffic( MogoTraffic traffic ) { } @Override - public void onUpdateTraffic2(MogoTraffic traffic) { + public void onUpdateTraffic2( MogoTraffic traffic ) { - if (traffic != null) { + if ( traffic != null ) { - if (traffic.getSpeedLimit() <= 0) { + if ( traffic.getSpeedLimit() <= 0 ) { return; } - Logger.i(TAG, "speed = %d, desc = %s", traffic.getSpeedLimit(), traffic.getDesc()); + Logger.i( TAG, "speed = %d, desc = %s", traffic.getSpeedLimit(), traffic.getDesc() ); // 发送当前限速到 adas - Intent intent = new Intent("com.mogo.launcher.adas"); - intent.putExtra("adas_speed_limit", traffic.getSpeedLimit()); - mContext.sendBroadcast(intent); + Intent intent = new Intent( "com.mogo.launcher.adas" ); + intent.putExtra( "adas_speed_limit", traffic.getSpeedLimit() ); + mContext.sendBroadcast( intent ); } } @Override - public void onUpdateCongestion(MogoCongestionInfo info) { + public void onUpdateCongestion( MogoCongestionInfo info ) { } @Override - public void onIntentReceived(String command, Intent intent) { - if (MogoReceiver.ACTIION_ADAS.equals(command)) { - if (intent == null) { + public void onIntentReceived( String command, Intent intent ) { + if ( MogoReceiver.ACTIION_ADAS.equals( command ) ) { + if ( intent == null ) { return; } int status = intent.getIntExtra( MogoReceiver.PARAM_ADAS_STATUS, 0 ); @@ -760,70 +760,72 @@ public class MogoServices implements IMogoMapListener, } else if ( TextUtils.equals( val, MogoReceiver.VALUE_SHOW ) ) { mStatusManager.setVoiceUIShow( TAG, true ); } - } else if (ServiceConst.COMMAND_NEXT.equals(command)) { - if (mStatusManager.isMainPageOnResume()) { - mActionManager.invoke(MapMarkerManager.getInstance().getCurrentModuleName(), - MogoAction.Next); + } else if ( ServiceConst.COMMAND_NEXT.equals( command ) ) { + if ( mStatusManager.isMainPageOnResume() ) { + mActionManager.invoke( MapMarkerManager.getInstance().getCurrentModuleName(), + MogoAction.Next ); } - } else if (ServiceConst.COMMAND_PREVIOUS.equals(command)) { - if (mStatusManager.isMainPageOnResume()) { - mActionManager.invoke(MapMarkerManager.getInstance().getCurrentModuleName(), - MogoAction.Prev); + } else if ( ServiceConst.COMMAND_PREVIOUS.equals( command ) ) { + if ( mStatusManager.isMainPageOnResume() ) { + mActionManager.invoke( MapMarkerManager.getInstance().getCurrentModuleName(), + MogoAction.Prev ); } - } else if (ServiceConst.COMMAND_SWITCH_CARD.equals(command)) { - String data = intent.getStringExtra("data"); + } 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)) { - 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); + 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) { + } catch ( JSONException e ) { e.printStackTrace(); } - } else if (MogoReceiver.ACTION_ADAS_STATUS.equals(command)) { - String msg = intent.getStringExtra("adasMsg"); - if (TextUtils.isEmpty(msg)) { + } else if ( MogoReceiver.ACTION_ADAS_STATUS.equals( command ) ) { + String msg = intent.getStringExtra( "adasMsg" ); + if ( TextUtils.isEmpty( msg ) ) { return; } - CarStateInfo stateInfo = GsonUtil.objectFromJson(msg, CarStateInfo.class); - if (stateInfo != null) { - changeCarHeadstockDirection(stateInfo.getValues().getHeading()); + CarStateInfo stateInfo = GsonUtil.objectFromJson( msg, CarStateInfo.class ); + if ( stateInfo != null ) { + changeCarHeadstockDirection( stateInfo.getValues().getHeading() ); // changeMyLocation( stateInfo.getValues() ); } - } else if (ServiceConst.COMMAND_OPERATION.equals(command)) { + } 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); + 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 ); } } - } catch (JSONException e) { + } catch ( JSONException e ) { e.printStackTrace(); } - } else if (MogoReceiver.ACTION_VOICE_READY.equals(command)) { - AIAssist.getInstance(mContext).flush(); - } else if (ServiceConst.COMMAND_MY_LOCATION.equals(command)) { - if (mStatusManager.isSearchUIShow()) { + } else if ( MogoReceiver.ACTION_VOICE_READY.equals( command ) ) { + AIAssist.getInstance( mContext ).flush(); + } else if ( ServiceConst.COMMAND_MY_LOCATION.equals( command ) ) { + if ( mStatusManager.isSearchUIShow() ) { return; } - if (mStatusManager.isMainPageOnResume()) { + if ( mStatusManager.isMainPageOnResume() ) { mUiController.recoverLockMode(); } - } else if (MogoReceiver.ACTION_MOCK.equals(command)) { - final int oper = intent.getIntExtra("oper", -1); - switch (oper) { + } else if ( MogoReceiver.ACTION_MOCK.equals( command ) ) { + final int oper = intent.getIntExtra( "oper", -1 ); + switch ( oper ) { case 1: - mUiController.showMyLocation(true); + mUiController.showMyLocation( true ); break; } } @@ -832,154 +834,154 @@ public class MogoServices implements IMogoMapListener, /** * 切换卡片 */ - private void switchCard2(String card) { - if (isApplicationBroughtToBackground(mContext)) { - mLauncher.backToLauncher(mContext); - UiThreadHandler.postDelayed(() -> { - if (mStatusManager.isADASShow()) { + private void switchCard2( String card ) { + if ( isApplicationBroughtToBackground( mContext ) ) { + mLauncher.backToLauncher( mContext ); + UiThreadHandler.postDelayed( () -> { + if ( mStatusManager.isADASShow() ) { mADASController.closeADAS(); } - mCardManager.switch2(card, true); - }, 2000L); + mCardManager.switch2( card, true ); + }, 2000L ); } else { mFragmentManager.clearAll(); - if (mStatusManager.isADASShow()) { + if ( mStatusManager.isADASShow() ) { mADASController.closeADAS(); } - mCardManager.switch2(card, true); + mCardManager.switch2( card, true ); } } - private boolean isApplicationBroughtToBackground(final Context context) { - ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - List tasks = am.getRunningTasks(1); - if (!tasks.isEmpty()) { - ComponentName topActivity = tasks.get(0).topActivity; - if (!topActivity.getPackageName().equals(context.getPackageName())) { + private boolean isApplicationBroughtToBackground( final Context context ) { + ActivityManager am = ( ActivityManager ) context.getSystemService( Context.ACTIVITY_SERVICE ); + List< ActivityManager.RunningTaskInfo > tasks = am.getRunningTasks( 1 ); + if ( !tasks.isEmpty() ) { + ComponentName topActivity = tasks.get( 0 ).topActivity; + if ( !topActivity.getPackageName().equals( context.getPackageName() ) ) { return true; } } return false; } - private void changeCarHeadstockDirection(final double degree) { - if (mNavi.isNaviing()) { + private void changeCarHeadstockDirection( final double degree ) { + if ( mNavi.isNaviing() ) { return; } - if (mStatusManager.isSearchUIShow()) { + if ( mStatusManager.isSearchUIShow() ) { return; } - if (!mStatusManager.isMainPageOnResume()) { + if ( !mStatusManager.isMainPageOnResume() ) { return; } - if (mUiController.getCurrentUiMode() != EnumMapUI.NorthUP_2D) { + if ( mUiController.getCurrentUiMode() != EnumMapUI.NorthUP_2D ) { return; } - UiThreadHandler.post(() -> { + UiThreadHandler.post( () -> { - mUiController.showMyLocation(inflateCursorView(degree)); - }); + mUiController.showMyLocation( inflateCursorView( degree ) ); + } ); } - private View inflateCursorView(double degree) { - View view = View.inflate(mContext, R.layout.map_amap_cursor, null); - view.setRotation((float) degree); + private View inflateCursorView( double degree ) { + View view = View.inflate( mContext, R.layout.map_amap_cursor, null ); + view.setRotation( ( float ) degree ); return view; } - private void changeMyLocation(CarStateInfo.ValuesBean valuesBean) { - if (valuesBean == null) { + private void changeMyLocation( CarStateInfo.ValuesBean valuesBean ) { + if ( valuesBean == null ) { return; } - Location location = new Location(LocationManager.GPS_PROVIDER); - location.setAltitude(valuesBean.getAlt()); - location.setLatitude(valuesBean.getLat()); - location.setLongitude(valuesBean.getLon()); + Location location = new Location( LocationManager.GPS_PROVIDER ); + location.setAltitude( valuesBean.getAlt() ); + location.setLatitude( valuesBean.getLat() ); + location.setLongitude( valuesBean.getLon() ); } /** * 注册桌面免唤醒指令 */ private void registerInternalUnWakeupWords() { - if (mInternalUnWakeupRegisterStatus) { + if ( mInternalUnWakeupRegisterStatus ) { return; } mInternalUnWakeupRegisterStatus = true; - AIAssist.getInstance(mContext) - .registerUnWakeupCommand(ServiceConst.CMD_UN_WAKE_PREV, - ServiceConst.CMD_UN_WAKE_PREV_UN_WAKE_WORDS, this); - AIAssist.getInstance(mContext) - .registerUnWakeupCommand(ServiceConst.CMD_UN_WAKE_NEXT, - ServiceConst.CMD_UN_WAKE_NEXT_UN_WAKE_WORDS, this); - AIAssist.getInstance(mContext) - .registerUnWakeupCommand(ServiceConst.CMD_UN_WAKEUP_MY_LOCATION, - ServiceConst.CMD_UN_WAKEUP_WORDS_MY_LOCATION, this); + AIAssist.getInstance( mContext ) + .registerUnWakeupCommand( ServiceConst.CMD_UN_WAKE_PREV, + ServiceConst.CMD_UN_WAKE_PREV_UN_WAKE_WORDS, this ); + AIAssist.getInstance( mContext ) + .registerUnWakeupCommand( ServiceConst.CMD_UN_WAKE_NEXT, + ServiceConst.CMD_UN_WAKE_NEXT_UN_WAKE_WORDS, this ); + AIAssist.getInstance( mContext ) + .registerUnWakeupCommand( ServiceConst.CMD_UN_WAKEUP_MY_LOCATION, + ServiceConst.CMD_UN_WAKEUP_WORDS_MY_LOCATION, this ); } /** * 注销桌面免唤醒指令 */ private void unregisterInternalUnWakeupWords() { - if (!mInternalUnWakeupRegisterStatus) { + if ( !mInternalUnWakeupRegisterStatus ) { return; } mInternalUnWakeupRegisterStatus = false; - AIAssist.getInstance(mContext) - .unregisterUnWakeupCommand(ServiceConst.CMD_UN_WAKE_PREV, this); - AIAssist.getInstance(mContext) - .unregisterUnWakeupCommand(ServiceConst.CMD_UN_WAKE_NEXT, this); - AIAssist.getInstance(mContext) - .unregisterUnWakeupCommand(ServiceConst.CMD_UN_WAKEUP_MY_LOCATION, this); + AIAssist.getInstance( mContext ) + .unregisterUnWakeupCommand( ServiceConst.CMD_UN_WAKE_PREV, this ); + AIAssist.getInstance( mContext ) + .unregisterUnWakeupCommand( ServiceConst.CMD_UN_WAKE_NEXT, this ); + AIAssist.getInstance( mContext ) + .unregisterUnWakeupCommand( ServiceConst.CMD_UN_WAKEUP_MY_LOCATION, this ); } @Override - public void onCmdSelected(String cmd) { - if (TextUtils.equals(ServiceConst.CMD_UN_WAKE_PREV, cmd)) { - mActionManager.invoke(MapMarkerManager.getInstance().getCurrentModuleName(), - MogoAction.Prev); - } else if (TextUtils.equals(ServiceConst.CMD_UN_WAKE_NEXT, cmd)) { - mActionManager.invoke(MapMarkerManager.getInstance().getCurrentModuleName(), - MogoAction.Next); - } else if (TextUtils.equals(ServiceConst.CMD_UN_WAKEUP_MY_LOCATION, cmd)) { - if (mStatusManager.isMainPageOnResume()) { + public void onCmdSelected( String cmd ) { + if ( TextUtils.equals( ServiceConst.CMD_UN_WAKE_PREV, cmd ) ) { + mActionManager.invoke( MapMarkerManager.getInstance().getCurrentModuleName(), + MogoAction.Prev ); + } else if ( TextUtils.equals( ServiceConst.CMD_UN_WAKE_NEXT, cmd ) ) { + mActionManager.invoke( MapMarkerManager.getInstance().getCurrentModuleName(), + MogoAction.Next ); + } else if ( TextUtils.equals( ServiceConst.CMD_UN_WAKEUP_MY_LOCATION, cmd ) ) { + if ( mStatusManager.isMainPageOnResume() ) { mUiController.recoverLockMode(); } - } else if (TextUtils.equals(ServiceConst.CMD_BACK, cmd)) { + } else if ( TextUtils.equals( ServiceConst.CMD_BACK, cmd ) ) { mFragmentManager.clearAll(); } } @Override - public void onCmdAction(String speakText) { + public void onCmdAction( String speakText ) { } @Override - public void onCmdCancel(String speakText) { + public void onCmdCancel( String speakText ) { } @Override - public void onSpeakEnd(String speakText) { + public void onSpeakEnd( String speakText ) { } @Override - public void onSpeakSelectTimeOut(String speakText) { + public void onSpeakSelectTimeOut( String speakText ) { } @Override - public void onTransaction(int size) { - if (size == 0) { - mUiController.setPointToCenter(0.66145, 0.661094); - mUiController.showMyLocation(!mNavi.isNaviing()); - AIAssist.getInstance(mContext).unregisterUnWakeupCommand(ServiceConst.CMD_BACK); + public void onTransaction( int size ) { + if ( size == 0 ) { + mUiController.setPointToCenter( 0.66145, 0.661094 ); + mUiController.showMyLocation( !mNavi.isNaviing() ); + AIAssist.getInstance( mContext ).unregisterUnWakeupCommand( ServiceConst.CMD_BACK ); } else { - mUiController.showMyLocation(false); - AIAssist.getInstance(mContext) - .registerUnWakeupCommand(ServiceConst.CMD_BACK, ServiceConst.CMD_BACK_WORDS, this); - mUiController.setPointToCenter(0.5, 0.5); + mUiController.showMyLocation( false ); + AIAssist.getInstance( mContext ) + .registerUnWakeupCommand( ServiceConst.CMD_BACK, ServiceConst.CMD_BACK_WORDS, this ); + mUiController.setPointToCenter( 0.5, 0.5 ); } } } From 10a77cf8bb0483cf329ed1d80e8e85d8ca70c45a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Mar 2020 15:54:21 +0800 Subject: [PATCH 3/6] finish the authorize logic --- app/src/nwd/AndroidManifest.xml | 8 +- build.gradle | 2 + config.gradle | 1 + .../aspectj/VoiceForbiddenTrackPoint.kt | 4 + .../biz/IMogoAuthorizeController.kt | 15 ++- .../invoke/IMogoAuthorizeContentListener.kt | 4 +- .../launcher/IAuthorizeMainInvoke.kt | 9 +- .../launcher/IMogoAuthorizeMainManager.kt | 12 ++- .../launcher/MogoAuthorizeMainController.kt | 14 ++- .../launcher/MogoMainAuthorize.kt | 14 ++- .../module/MogoModuleAuthorize.kt | 1 + .../authorize/fragment/AuthorizeContract.kt | 3 +- .../authorize/fragment/AuthorizeFragment.kt | 29 +++++- .../authorize/fragment/AuthorizePresenter.kt | 63 ++++++------- .../module/authorize/model/BaseResponse.kt | 2 +- .../authorize/model/IMogoAuthorizeModel.kt | 5 +- .../bean/{UserAgreement.kt => Agreement.kt} | 8 +- .../mogo/module/authorize/net/AuthorizeApi.kt | 9 +- .../mogo/module/authorize/net/CoroutineDSL.kt | 5 +- .../module/authorize/util/AnalyticsUtil.kt | 24 +++++ .../authorize/voice/IVoiceBusinessListener.kt | 8 ++ .../authorize/voice/IVoiceCommandListener.kt | 35 +++++++ .../authorize/voice/IVoiceIntentListener.kt | 18 ++++ .../module/authorize/voice/VoiceManager.kt | 40 ++++++++ .../mogo/module/authorize/voice/VoiceUtil.kt | 93 +++++++++++++++++++ .../res/layout/module_authorize_fragment.xml | 34 +++---- .../src/main/res/values/strings.xml | 1 + .../agreement/ExampleInstrumentedTest.kt | 22 ----- .../com/mogo/module/guide/GuideBizManager.kt | 16 +++- .../module/guide/fragment/GuideFragment.kt | 17 ++-- .../guide/guide/GuideAppListFragment.kt | 4 + .../module/guide/guide/GuideCardFragment.kt | 10 +- .../guide/guide/GuideEntryMainFragment.kt | 7 +- .../guide/guide/GuideLocationFragment.kt | 4 + .../guide/guide/GuideNavigationFragment.kt | 4 + .../guide/guide/GuideOnLineCarFragment.kt | 4 + .../module/guide/guide/GuideStartFragment.kt | 4 +- .../mogo/module/guide/util/AnalyticsUtil.kt | 24 +++++ .../module/guide/util/SharedPreferenceUtil.kt | 4 + 39 files changed, 451 insertions(+), 130 deletions(-) create mode 100644 modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/aspectj/VoiceForbiddenTrackPoint.kt rename modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/bean/{UserAgreement.kt => Agreement.kt} (73%) create mode 100644 modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/util/AnalyticsUtil.kt create mode 100644 modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceBusinessListener.kt create mode 100644 modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceCommandListener.kt create mode 100644 modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceIntentListener.kt create mode 100644 modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/VoiceManager.kt create mode 100644 modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/VoiceUtil.kt create mode 100644 modules/mogo-module-guide/src/main/java/com/mogo/module/guide/util/AnalyticsUtil.kt diff --git a/app/src/nwd/AndroidManifest.xml b/app/src/nwd/AndroidManifest.xml index 0e42bd5132..c11d678710 100644 --- a/app/src/nwd/AndroidManifest.xml +++ b/app/src/nwd/AndroidManifest.xml @@ -1,12 +1,10 @@ - + package="com.mogo.launcher" + android:sharedUserId="android.uid.system"> - - + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5388f39431..3ded6f7f50 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. apply from: "config.gradle" apply from: "javadoc.gradle" + buildscript { ext.kotlin_version = '1.3.41' @@ -23,6 +24,7 @@ buildscript { classpath 'com.android.tools.build:gradle:3.5.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.alibaba:arouter-register:1.0.2" + classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/config.gradle b/config.gradle index 58336a0e3e..42749665e5 100644 --- a/config.gradle +++ b/config.gradle @@ -133,5 +133,6 @@ ext { coroutinescore : "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1", coroutinesandroid : "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1", + aspectj : "org.aspectj:aspectjrt:1.8.9", ] } \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/aspectj/VoiceForbiddenTrackPoint.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/aspectj/VoiceForbiddenTrackPoint.kt new file mode 100644 index 0000000000..4517f18e9c --- /dev/null +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/aspectj/VoiceForbiddenTrackPoint.kt @@ -0,0 +1,4 @@ +package com.mogo.module.authorize.aspectj + +class VoiceForbiddenTrackPoint { +} \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/biz/IMogoAuthorizeController.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/biz/IMogoAuthorizeController.kt index 4e8142a38d..3f0c24f96b 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/biz/IMogoAuthorizeController.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/biz/IMogoAuthorizeController.kt @@ -3,14 +3,14 @@ package com.mogo.module.authorize.authprovider.biz import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeContentListener import com.mogo.module.authorize.model.BaseResponse import com.mogo.module.authorize.model.IMogoAuthorizeModel -import com.mogo.module.authorize.model.bean.UserAgreement +import com.mogo.module.authorize.model.bean.AgreementData import com.mogo.module.authorize.net.request import com.mogo.utils.logger.Logger open class IMogoAuthorizeController { companion object { - const val TAG = "IMogoAuthorizeController" + const val TAG = "AuthorizeController" } private val authorizeModel: IMogoAuthorizeModel by lazy { IMogoAuthorizeModel() } @@ -24,15 +24,14 @@ open class IMogoAuthorizeController { }) } try { - request> { + request> { loader { - authorizeModel.invokeAuthorizeContent(1) + authorizeModel.invokeAuthorizeContent(agreementType) } onSuccess { - Logger.d(TAG, "invokeAuthorizeContent onSuccess data: ${it.result}") getAuthorizeContentListener(tag, { listener -> - if (it.result != null) { - listener.requestContentSuccess(it.result) + if (it.result != null && it.result.agreement.agreementContent != null) { + listener.requestContentSuccess(it.result.agreement) } else { listener.requestContentFailed("request authorize content success ,but result data is :${it.result}") } @@ -49,7 +48,7 @@ open class IMogoAuthorizeController { }) } } - }catch (e:Exception){ + } catch (e: Exception) { e.printStackTrace() } } diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/invoke/IMogoAuthorizeContentListener.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/invoke/IMogoAuthorizeContentListener.kt index 75b0200ee3..06a999aa3e 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/invoke/IMogoAuthorizeContentListener.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/invoke/IMogoAuthorizeContentListener.kt @@ -1,13 +1,13 @@ package com.mogo.module.authorize.authprovider.invoke -import com.mogo.module.authorize.model.bean.UserAgreement +import com.mogo.module.authorize.model.bean.Agreement /** * 获取授权信息回调 */ interface IMogoAuthorizeContentListener { - fun requestContentSuccess(userAgreement: UserAgreement) + fun requestContentSuccess(userAgreement: Agreement) fun requestContentFailed(errorMsg: String) } \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/IAuthorizeMainInvoke.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/IAuthorizeMainInvoke.kt index 4fa6005c28..af945e03c7 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/IAuthorizeMainInvoke.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/IAuthorizeMainInvoke.kt @@ -9,11 +9,16 @@ interface IAuthorizeMainInvoke : IMogoAuthorizeInvoke { * 同意授权 * tag:透传模块ID */ - fun agreeAuthorize(tag: String, agrId: Long) + fun agreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) /** * 不同意授权 * tag:透传模块ID */ - fun disAgreeAuthorize(tag: String, agrId: Long) + fun disAgreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) + + /** + * 是否已经注册回调 + */ + fun hasRegister(tag: String): Boolean } \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/IMogoAuthorizeMainManager.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/IMogoAuthorizeMainManager.kt index 2519d6cbed..810997e582 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/IMogoAuthorizeMainManager.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/IMogoAuthorizeMainManager.kt @@ -9,6 +9,10 @@ import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListen @Route(path = AuthorizeConstant.PROVIDER_LAUNCHER) class IMogoAuthorizeMainManager : IMogoAuthorizeMainProvider { + override fun hasRegister(tag: String): Boolean { + return mogoAuthShow.hasRegister(tag) + } + override fun needAuthorize(): Boolean { return mogoAuthShow.needAuthorize() } @@ -17,12 +21,12 @@ class IMogoAuthorizeMainManager : IMogoAuthorizeMainProvider { mogoAuthShow.invokeAuthorizeContent(tag) } - override fun agreeAuthorize(tag: String, agrId: Long) { - mogoAuthShow.agreeAuthorize(tag, agrId) + override fun agreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) { + mogoAuthShow.agreeAuthorize(tag, agrId, onSuccess, onError) } - override fun disAgreeAuthorize(tag: String, agrId: Long) { - mogoAuthShow.disAgreeAuthorize(tag, agrId) + override fun disAgreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) { + mogoAuthShow.disAgreeAuthorize(tag, agrId, onSuccess, onError) } override fun registerAuthorizeListener(tag: String, listener: IMogoAcquireAuthorizeListener) { diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/MogoAuthorizeMainController.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/MogoAuthorizeMainController.kt index fba421396c..976f98d086 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/MogoAuthorizeMainController.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/MogoAuthorizeMainController.kt @@ -13,25 +13,31 @@ object MogoAuthorizeMainController : IMogoAuthorizeController() { private val authorizeShowModel: MogoAuthorizeMainModel by lazy { MogoAuthorizeMainModel() } @Synchronized - fun agreeAuthorize(tag: String, agrId: Long) { + fun agreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) { val acquireAuthListener = MogoAuthorizeRegisterHandler.getAuthorizeListener(tag) updateAuthorize(agrId, AGREEMENT_EFFECT, { if (acquireAuthListener != null) { + onSuccess.invoke() acquireAuthListener.authorizeSuccess() } else { Logger.d(TAG, "agreeAuthorize --- can not find listener by this tag :$tag ") } }, { - authorizeFailed(tag, it ?: "agreeAuthorize failed,please check network") + val errorMsg = it ?: "agreeAuthorize failed,please check network" + onError.invoke(errorMsg) + authorizeFailed(tag, errorMsg) }) } @Synchronized - fun disAgreeAuthorize(tag: String, agrId: Long) { + fun disAgreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) { updateAuthorize(agrId, AGREEMENT_NOT_EFFECT, { + onSuccess.invoke() authorizeFailed(tag, "UserDisAgree authorize") }, { - authorizeFailed(tag, it ?: "disAgreeAuthorize failed,please check network") + val errorMsg = it ?: "disAgreeAuthorize failed,please check network" + onError.invoke(errorMsg) + authorizeFailed(tag, errorMsg) }) } diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/MogoMainAuthorize.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/MogoMainAuthorize.kt index 33fdb9e8dc..63e4424f65 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/MogoMainAuthorize.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/launcher/MogoMainAuthorize.kt @@ -26,12 +26,18 @@ class MogoMainAuthorize private constructor() : MogoAuthorizeManagerImpl(), IMog @Volatile private var showAuthorizeView: Boolean = false - override fun agreeAuthorize(tag: String, agrId: Long) { - MogoAuthorizeMainController.agreeAuthorize(tag, agrId) + override fun hasRegister(tag: String): Boolean { + if (tag.isNullOrBlank()) return false + val listener = MogoAuthorizeRegisterHandler.getAuthorizeContentListener(tag) + return listener != null } - override fun disAgreeAuthorize(tag: String, agrId: Long) { - MogoAuthorizeMainController.disAgreeAuthorize(tag, agrId) + override fun agreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) { + MogoAuthorizeMainController.agreeAuthorize(tag, agrId, onSuccess, onError) + } + + override fun disAgreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) { + MogoAuthorizeMainController.disAgreeAuthorize(tag, agrId, onSuccess, onError) } fun invokeAuthorizeForShow() { diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/module/MogoModuleAuthorize.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/module/MogoModuleAuthorize.kt index 1f6faddb97..e7fb2c8327 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/module/MogoModuleAuthorize.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/authprovider/module/MogoModuleAuthorize.kt @@ -19,6 +19,7 @@ class MogoModuleAuthorize private constructor() : MogoAuthorizeManagerImpl(), IM override fun invokeAuthorization(tag: String) { mogoAuthShow.showAuthorizeView(tag, { //todo SP存储状态 + }, { errorMsg -> val listener = MogoAuthorizeRegisterHandler.getAuthorizeListener(tag) listener?.authorizeFailed(errorMsg) diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizeContract.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizeContract.kt index 193f7e9146..91c4683926 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizeContract.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizeContract.kt @@ -13,10 +13,11 @@ class AuthorizeContract { } interface Biz { - fun invokeAuthorize(invokeTag: String) + fun invokeAuthorizationContent(invokeTag: String) fun agreeAuthorize(tag: String, agreementId: Long) fun disAgreeAuthorize(tag: String, agreementId: Long) + } } \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizeFragment.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizeFragment.kt index 4be93d917b..7d2dcb8258 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizeFragment.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizeFragment.kt @@ -4,10 +4,16 @@ import android.text.Html import android.view.View import com.mogo.commons.mvp.MvpFragment import com.mogo.module.authorize.R +import com.mogo.module.authorize.util.AnalyticsUtil +import com.mogo.module.authorize.util.AnalyticsUtil.INVOKE_TRACK_AUTHORIZE_CLICK +import com.mogo.module.authorize.util.AnalyticsUtil.INVOKE_TRACK_AUTHORIZE_SHOW +import com.mogo.module.authorize.voice.IVoiceCommandListener +import com.mogo.module.authorize.voice.IVoiceIntentListener +import com.mogo.module.authorize.voice.VoiceUtil import com.mogo.utils.logger.Logger import kotlinx.android.synthetic.main.module_authorize_fragment.* -class AuthorizeFragment(private val invokeTag: String) : MvpFragment(), AuthorizeContract.View, View.OnClickListener { +class AuthorizeFragment(private val invokeTag: String) : MvpFragment(), AuthorizeContract.View, View.OnClickListener, IVoiceCommandListener, IVoiceIntentListener { companion object { const val TAG = "AuthorizeFragment" @@ -20,11 +26,13 @@ class AuthorizeFragment(private val invokeTag: String) : MvpFragment { + AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 1, "operation_result" to 1)) mPresenter.agreeAuthorize(invokeTag, agreementId) } R.id.btnAuthorizeDisAgree -> { + AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 1, "operation_result" to 2)) mPresenter.disAgreeAuthorize(invokeTag, agreementId) } R.id.clLoadingErrorContainer, R.id.btnAuthorizeLoadingError -> { - mPresenter.invokeAuthorize(invokeTag) + mPresenter.invokeAuthorizationContent(invokeTag) } } } + override fun onVoiceCmdAgree() { + AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 2, "operation_result" to 1)) + mPresenter.agreeAuthorize(invokeTag, agreementId) + } + + override fun onVoiceCmdDisAgree() { + AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 2, "operation_result" to 2)) + mPresenter.disAgreeAuthorize(invokeTag, agreementId) + } + + override fun onDestroy() { + super.onDestroy() + VoiceUtil.unregisterAll(context!!, this) + } } \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizePresenter.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizePresenter.kt index 96d96c6f08..010df3f4e8 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizePresenter.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/fragment/AuthorizePresenter.kt @@ -4,12 +4,10 @@ import androidx.lifecycle.LifecycleOwner import com.mogo.commons.mvp.Presenter import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeContentListener import com.mogo.module.authorize.authprovider.launcher.MogoMainAuthorize.Companion.mogoAuthShow -import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListener -import com.mogo.module.authorize.model.bean.UserAgreement -import com.mogo.module.authorize.model.proxy.AuthorizeProxy +import com.mogo.module.authorize.model.bean.Agreement import com.mogo.utils.logger.Logger -class AuthorizePresenter : Presenter, AuthorizeContract.Biz, IMogoAuthorizeContentListener, IMogoAcquireAuthorizeListener { +class AuthorizePresenter : Presenter, AuthorizeContract.Biz, IMogoAuthorizeContentListener { companion object { const val TAG = "AuthorizePresenter" @@ -24,51 +22,54 @@ class AuthorizePresenter : Presenter, AuthorizeContract. override fun onCreate(owner: LifecycleOwner) { super.onCreate(owner) Logger.d(TAG, "onCreate invokeTag:$invokeTag") - invokeAuthorize(invokeTag!!) + invokeAuthorizationContent(invokeTag!!) } - override fun invokeAuthorize(invokeTag: String) { + override fun invokeAuthorizationContent(invokeTag: String) { mView.readyToAuthorize() this.invokeTag = invokeTag - mogoAuthShow.registerInvokeAuthorizeContentListener(invokeTag, this) - mogoAuthShow.registerAuthorizeListener(invokeTag, this) + if (!mogoAuthShow.hasRegister(invokeTag)) { + mogoAuthShow.registerInvokeAuthorizeContentListener(invokeTag, this) + } mogoAuthShow.invokeAuthorizeContent(invokeTag) } - override fun requestContentSuccess(userAgreement: UserAgreement) { - val id = userAgreement.agreementEntity.id - val content = userAgreement.agreementContent[0] - val title = userAgreement.agreementEntity.title - val bottomContent = userAgreement.agreementEntity.agreementButtonFirst - val lastContent = userAgreement.agreementEntity.agreementButtonSecond - mView.showAuthorizationAgreementContent(id, content, title, bottomContent, lastContent) + override fun requestContentSuccess(userAgreement: Agreement) { + Logger.d(TAG, "requestContentSuccess userAgreement:$userAgreement") + if (userAgreement?.agreementContent != null && userAgreement?.agreementContent.isNotEmpty()) { + val id = userAgreement.tUserAgreementEntity.id + val content = userAgreement.agreementContent[0] + val title = userAgreement.tUserAgreementEntity.title + val bottomContent = userAgreement.tUserAgreementEntity.agreementButtonFirst + val lastContent = userAgreement.tUserAgreementEntity.agreementButtonSecond + mView.showAuthorizationAgreementContent(id, content, title, bottomContent, lastContent) + } else { + mView.showAuthorizationError() + } } override fun requestContentFailed(errorMsg: String) { Logger.d(TAG, "requestContentFailed errorMsg:$errorMsg") +// mView.showAuthorizationAgreementContent(0, "123", "123456", "34234", "3543535") mView.showAuthorizationError() } override fun agreeAuthorize(tag: String, agreementId: Long) { - mogoAuthShow.agreeAuthorize(tag, agreementId) + mogoAuthShow.agreeAuthorize(tag, agreementId, { + Logger.d(TAG, "agreeAuthorize success") + closeAuthorizeView() + }, { s: String -> + Logger.d(TAG, "agreeAuthorize failed") + closeAuthorizeView() + }) } override fun disAgreeAuthorize(tag: String, agreementId: Long) { - mogoAuthShow.disAgreeAuthorize(tag, agreementId) - } - - override fun authorizeSuccess() { - mogoAuthShow.authorizeSuccess(invokeTag!!) - closeAuthorizeView() - } - - override fun authorizeFailed(errorMsg: String) { - mogoAuthShow.authorizeFailed(invokeTag!!, errorMsg) - closeAuthorizeView() - } - - override fun forbiddenVoiceWhenAuthorize(cmd: String) { - //do nothing + mogoAuthShow.disAgreeAuthorize(tag, agreementId, { + closeAuthorizeView() + }, { s: String -> + closeAuthorizeView() + }) } private fun closeAuthorizeView() { diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/BaseResponse.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/BaseResponse.kt index d5790a7d87..963747434a 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/BaseResponse.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/BaseResponse.kt @@ -1,6 +1,6 @@ package com.mogo.module.authorize.model -class BaseResponse(val code: Int, val msg: String, val result: T) { +class BaseResponse(val code: Int, val msg: String, val detailMsg: String, val result: T) { } diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/IMogoAuthorizeModel.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/IMogoAuthorizeModel.kt index 92b5fe261d..5747d89775 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/IMogoAuthorizeModel.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/IMogoAuthorizeModel.kt @@ -3,7 +3,8 @@ package com.mogo.module.authorize.model import com.google.gson.Gson import com.mogo.commons.network.Utils.getSn import com.mogo.module.authorize.model.bean.RequestUserAgreement -import com.mogo.module.authorize.model.bean.UserAgreement +import com.mogo.module.authorize.model.bean.Agreement +import com.mogo.module.authorize.model.bean.AgreementData open class IMogoAuthorizeModel : BaseRepository() { @@ -11,7 +12,7 @@ open class IMogoAuthorizeModel : BaseRepository() { const val TAG = "IMogoAuthorizeModel" } - suspend fun invokeAuthorizeContent(agreementType: Int): BaseResponse { + suspend fun invokeAuthorizeContent(agreementType: Int): BaseResponse { val requestUserAgreement = Gson().toJson(RequestUserAgreement(agreementType)) val map = mapOf("sn" to getSn(), "data" to requestUserAgreement) return apiCall { getNetWorkApi().getAuthorizeContent(map) } diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/bean/UserAgreement.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/bean/Agreement.kt similarity index 73% rename from modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/bean/UserAgreement.kt rename to modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/bean/Agreement.kt index 9e11630fc2..d530e2741f 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/bean/UserAgreement.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/model/bean/Agreement.kt @@ -3,9 +3,11 @@ package com.mogo.module.authorize.model.bean const val AGREEMENT_EFFECT = 1 //用户协议生效 const val AGREEMENT_NOT_EFFECT = 2 //用户协议不生效 -class RequestUserAgreement(val agreementType:Int) +class RequestUserAgreement(val agreementType: Int) -data class UserAgreement(var agreementEntity: TUserAgreementEntity, var agreementContent: List) +data class AgreementData(val agreement: Agreement) + +data class Agreement(var tUserAgreementEntity: TUserAgreementEntity, var agreementContent: List) data class TUserAgreementEntity( val id: Long, //协议ID @@ -18,4 +20,4 @@ data class TUserAgreementEntity( val agreementUserType: String, //协议适用用户 val agreementStatus: Int, //协议状态 1:生效 2:未生效 val createTime: String, //协议创建时间 - val updateTime: String) //协议更新时间 \ No newline at end of file + val updateTime: String) //协议更新时间 diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/net/AuthorizeApi.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/net/AuthorizeApi.kt index c2b25d961a..ea6538d5f5 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/net/AuthorizeApi.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/net/AuthorizeApi.kt @@ -1,7 +1,8 @@ package com.mogo.module.authorize.net import com.mogo.module.authorize.model.BaseResponse -import com.mogo.module.authorize.model.bean.UserAgreement +import com.mogo.module.authorize.model.bean.Agreement +import com.mogo.module.authorize.model.bean.AgreementData import retrofit2.http.FieldMap import retrofit2.http.FormUrlEncoded import retrofit2.http.POST @@ -10,12 +11,12 @@ interface AuthorizeApi { //获取授权内容· @FormUrlEncoded - @POST("yycp-channelManager/user/agreement/findUserAgreement") - suspend fun getAuthorizeContent(@FieldMap authorizeContent: Map): BaseResponse + @POST("yycp-channelManager/agreement/findUserAgreement") + suspend fun getAuthorizeContent(@FieldMap authorizeContent: Map): BaseResponse //更新授权状态 @FormUrlEncoded - @POST("yycp-channelManager/user/agreement/updateStatus") + @POST("yycp-channelManager/agreement/updateStatus") suspend fun updateAuthorize(@FieldMap updateStatus: Map): BaseResponse } \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/net/CoroutineDSL.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/net/CoroutineDSL.kt index c415974178..f9d611409a 100644 --- a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/net/CoroutineDSL.kt +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/net/CoroutineDSL.kt @@ -5,7 +5,6 @@ import com.mogo.module.authorize.exception.ApiException.Companion.NULL_REQUEST_D import com.mogo.module.authorize.exception.CommonException.Companion.NETWORK_EXCEPTION import com.mogo.module.authorize.exception.CommonException.Companion.NULL_EXCEPTION import com.mogo.module.authorize.model.BaseResponse -import com.mogo.utils.logger.Logger import kotlinx.coroutines.* import java.net.SocketTimeoutException import java.net.UnknownHostException @@ -63,7 +62,7 @@ class Request { } } catch (e: Exception) { e.printStackTrace() - if(e == null){ + if (e == null) { onError?.invoke(NULL_EXCEPTION) return@launch } @@ -71,7 +70,7 @@ class Request { is UnknownHostException -> onError?.invoke(NETWORK_EXCEPTION) is TimeoutException -> onError?.invoke(NETWORK_EXCEPTION) is SocketTimeoutException -> onError?.invoke(NETWORK_EXCEPTION) - else -> onError?.invoke(java.lang.Exception(e.message?:"")) + else -> onError?.invoke(java.lang.Exception(e.message ?: "")) } } finally { onComplete?.invoke() diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/util/AnalyticsUtil.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/util/AnalyticsUtil.kt new file mode 100644 index 0000000000..bb08c3350f --- /dev/null +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/util/AnalyticsUtil.kt @@ -0,0 +1,24 @@ +package com.mogo.module.authorize.util + +import com.alibaba.android.arouter.launcher.ARouter +import com.mogo.service.IMogoServiceApis +import com.mogo.service.MogoServicePaths +import com.mogo.service.analytics.IMogoAnalytics + +object AnalyticsUtil { + + const val INVOKE_TRACK_AUTHORIZE_SHOW = "Launcher_Privacy_protocol_Show" + const val INVOKE_TRACK_AUTHORIZE_CLICK = "Launcher_Privacy_protocol_click" + + private var trackRouter: IMogoAnalytics? = null + + fun track(eventType: String, data: MutableMap? = hashMapOf()) { + if (trackRouter == null) { + val arouter = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation() + if (arouter is IMogoServiceApis) { + trackRouter = arouter.analyticsApi + } + } + trackRouter!!.track(eventType, data) + } +} \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceBusinessListener.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceBusinessListener.kt new file mode 100644 index 0000000000..b9792d1126 --- /dev/null +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceBusinessListener.kt @@ -0,0 +1,8 @@ +package com.mogo.module.authorize.voice + +interface IVoiceBusinessListener { + + fun onVoiceCmdAgree() + + fun onVoiceCmdDisAgree() +} \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceCommandListener.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceCommandListener.kt new file mode 100644 index 0000000000..bf50a36ae6 --- /dev/null +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceCommandListener.kt @@ -0,0 +1,35 @@ +package com.mogo.module.authorize.voice + +import com.mogo.commons.voice.IMogoVoiceCmdCallBack +import com.mogo.utils.logger.Logger + +private const val IVoiceCommandTAG = "IVoiceCommandTAG" + +interface IVoiceCommandListener : IMogoVoiceCmdCallBack, IVoiceBusinessListener { + + override fun onCmdSelected(cmd: String?) { + Logger.i( + IVoiceCommandTAG, "onCmdSelected cmd:${cmd ?: "cmd is null"}" + ) + cmd?.let { + VoiceManager.handleOnCmdSelected(cmd, this) + } + } + + override fun onCmdAction(speakText: String?) { + + } + + override fun onCmdCancel(speakText: String?) { + + } + + override fun onSpeakSelectTimeOut(speakText: String?) { + + } + + override fun onSpeakEnd(speakText: String?) { + Logger.i(IVoiceCommandTAG, "onSpeakEnd --- speakText : $speakText") + } + +} \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceIntentListener.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceIntentListener.kt new file mode 100644 index 0000000000..f4b3d233d6 --- /dev/null +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/IVoiceIntentListener.kt @@ -0,0 +1,18 @@ +package com.mogo.module.authorize.voice + +import android.content.Intent +import com.mogo.service.intent.IMogoIntentListener +import com.mogo.utils.logger.Logger + +private const val IVoiceIntentTAG = "IVoiceIntentListener" + +interface IVoiceIntentListener : IMogoIntentListener, IVoiceBusinessListener { + + override fun onIntentReceived(cmd: String?, intent: Intent?) { + Logger.i(IVoiceIntentTAG, "cmd -> $cmd") + if (intent != null && cmd != null) { + VoiceManager.handleOnIntentCmd(cmd, intent, this) + } + } + +} \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/VoiceManager.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/VoiceManager.kt new file mode 100644 index 0000000000..d29e9d6a82 --- /dev/null +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/VoiceManager.kt @@ -0,0 +1,40 @@ +package com.mogo.module.authorize.voice + +import android.content.Intent +import com.mogo.module.authorize.voice.VoiceUtil.VOICE_REGISTER_AUTHORIZE_AGREE +import com.mogo.module.authorize.voice.VoiceUtil.VOICE_REGISTER_AUTHORIZE_DISAGREE +import com.mogo.utils.logger.Logger + +object VoiceManager { + + private const val TAG = "VoiceManager" + + fun handleOnCmdSelected(cmd: String, listener: IVoiceCommandListener) { + Logger.i(TAG, "handleOnCmdSelected: cmd ---> $cmd") + when (cmd) { + VOICE_REGISTER_AUTHORIZE_AGREE -> { + Logger.i(TAG, "语音免唤醒 同意") + listener.onVoiceCmdAgree() + } + VOICE_REGISTER_AUTHORIZE_DISAGREE -> { + Logger.i(TAG, "语音免唤醒 不同意") + listener.onVoiceCmdDisAgree() + } + } + } + + fun handleOnIntentCmd(cmd: String, intent: Intent, listener: IVoiceIntentListener) { + Logger.i(TAG, "handleOnIntentCmd: cmd -> $cmd") + when (cmd) { + VOICE_REGISTER_AUTHORIZE_AGREE -> { + Logger.i(TAG, "语音唤醒 同意") + listener.onVoiceCmdAgree() + } + VOICE_REGISTER_AUTHORIZE_DISAGREE -> { + Logger.i(TAG, "语音免唤醒 不同意") + listener.onVoiceCmdDisAgree() + } + } + } + +} \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/VoiceUtil.kt b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/VoiceUtil.kt new file mode 100644 index 0000000000..b393c41670 --- /dev/null +++ b/modules/mogo-module-authorize/src/main/java/com/mogo/module/authorize/voice/VoiceUtil.kt @@ -0,0 +1,93 @@ +package com.mogo.module.authorize.voice + +import android.content.Context +import com.alibaba.android.arouter.launcher.ARouter +import com.mogo.commons.voice.AIAssist +import com.mogo.service.IMogoServiceApis +import com.mogo.service.MogoServicePaths +import com.mogo.service.intent.IMogoIntentManager +import com.mogo.utils.logger.Logger + +object VoiceUtil { + + private const val TAG = "VoiceUtil" + private var intentRegister: IMogoIntentManager? = null + + init { + Logger.i(TAG, "init") + val register = + ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation() + if (register is IMogoServiceApis) { + intentRegister = register.intentManagerApi + } + } + + //WakeUp Command (Intent) + const val VOICE_INTENT_AGREE = "system.application.operation" //同意 + const val VOICE_INTENT_DISAGREE = "system.application.operation" //不同意 + + //unWakeUp Command + const val VOICE_REGISTER_AUTHORIZE_AGREE = "CMD_AUTHORIZATION_AGREE" + private val agreeArray: Array = arrayOf("同意", "调整", "好的") + const val VOICE_REGISTER_AUTHORIZE_DISAGREE = "CMD_AUTHORIZATION_DISAGREE" + private val disAgreeArray: Array = arrayOf("不同意", "不调整") + + private var hasRegister = false + + fun speak(content: String, context: Context, listener: IVoiceCommandListener) { + AIAssist.getInstance(context).speakTTSVoice(content, listener) + } + + fun registerAll( + context: Context, + voiceCommand: IVoiceCommandListener, + intentCommand: IVoiceIntentListener + ) { + if (!hasRegister) { + hasRegister = true + registerAgree(context, voiceCommand, intentCommand) + registerDisAgree(context, voiceCommand, intentCommand) + } + } + + private fun registerAgree( + context: Context, + voiceCommand: IVoiceCommandListener, + intentCommand: IVoiceIntentListener + ) { + Logger.i(TAG, "registerAgree") + AIAssist.getInstance(context) + .registerUnWakeupCommand( + VOICE_REGISTER_AUTHORIZE_AGREE, + agreeArray, voiceCommand + ) +// intentRegister?.registerIntentListener(VOICE_INTENT_AGREE, intentCommand) + } + + private fun registerDisAgree( + context: Context, + voiceCommand: IVoiceCommandListener, + intentCommand: IVoiceIntentListener + ) { + Logger.i(TAG, "registerDisAgree") + AIAssist.getInstance(context) + .registerUnWakeupCommand( + VOICE_REGISTER_AUTHORIZE_DISAGREE, + disAgreeArray, voiceCommand + ) +// intentRegister?.registerIntentListener(VOICE_INTENT_DISAGREE, intentCommand) + } + + fun unregisterAll(context: Context, listener: IVoiceIntentListener) { + Logger.i(TAG, "unregister All") + AIAssist.getInstance(context).unregisterUnWakeupCommand(VOICE_REGISTER_AUTHORIZE_AGREE) + AIAssist.getInstance(context).unregisterUnWakeupCommand(VOICE_REGISTER_AUTHORIZE_DISAGREE) + hasRegister = false + + Logger.i(TAG, "unregister IntentVoiceCommand --- intentRegister:$intentRegister") + intentRegister?.let { + it.unregisterIntentListener(VOICE_INTENT_AGREE, listener) + it.unregisterIntentListener(VOICE_INTENT_DISAGREE, listener) + } + } +} \ No newline at end of file diff --git a/modules/mogo-module-authorize/src/main/res/layout/module_authorize_fragment.xml b/modules/mogo-module-authorize/src/main/res/layout/module_authorize_fragment.xml index 7e09e1a855..df1463e347 100644 --- a/modules/mogo-module-authorize/src/main/res/layout/module_authorize_fragment.xml +++ b/modules/mogo-module-authorize/src/main/res/layout/module_authorize_fragment.xml @@ -50,11 +50,25 @@ android:layout_marginRight="@dimen/dp_330" android:layout_marginBottom="@dimen/dp_90" android:background="@drawable/module_authorize_selector_dark_corner" + android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - android:visibility="gone" app:layout_constraintTop_toTopOf="parent"> +