opt
This commit is contained in:
@@ -10,6 +10,7 @@ import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.MvpActivity;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
@@ -18,7 +19,6 @@ import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.extensions.ExtensionsModuleConst;
|
||||
import com.mogo.module.main.cards.CardModulesAdapter;
|
||||
import com.mogo.module.main.cards.MogoModulesHandler;
|
||||
import com.mogo.module.main.cards.MogoModulesManager;
|
||||
@@ -31,7 +31,6 @@ import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.analytics.IMogoAnalytics;
|
||||
import com.mogo.service.cardmanager.IMogoCardManager;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.impl.fragmentmanager.FragmentStack;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -66,7 +65,8 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
private View mApps;
|
||||
private View mEntrance;
|
||||
private FrameLayout mFloatingLayout;
|
||||
private View mShadowFrame;
|
||||
private View mLeftShadowFrame;
|
||||
private View mTopShadowFrame;
|
||||
|
||||
/**
|
||||
* 主模块管控定位,可以向各个模块发送统一定位信息
|
||||
@@ -104,7 +104,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
|
||||
mCurrentPosition = position;
|
||||
provider = mCardModulesAdapter.getProvider( mCurrentPosition );
|
||||
mMogoModuleHandler.setEnable( provider.getModuleName() );
|
||||
mMogoModuleHandler.setModuleEnable( provider.getModuleName() );
|
||||
if ( !isClickMarker ) {
|
||||
mMogoCardManager.invoke( position, mMogoModuleHandler.getCurrentModuleName() );
|
||||
}
|
||||
@@ -163,9 +163,9 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoFragmentManager.init( this, R.id.module_main_id_search_fragment );
|
||||
mMogoFragmentManager.registerMainFragmentStackTransactionListener( ( size ) -> {
|
||||
if ( size == 0 ) {
|
||||
show();
|
||||
showLayout();
|
||||
} else if ( size == 1 ) {
|
||||
hide();
|
||||
hideLayout();
|
||||
}
|
||||
} );
|
||||
mHeader = findViewById( R.id.module_main_id_header_fragment_container );
|
||||
@@ -173,38 +173,37 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mApps = findViewById( R.id.module_main_id_apps_fragment_container );
|
||||
mEntrance = findViewById( R.id.module_main_id_entrance_fragment_container );
|
||||
mFloatingLayout = findViewById( R.id.module_main_id_floating_view );
|
||||
mShadowFrame = findViewById( R.id.module_main_id_map_shadow_frame );
|
||||
mLeftShadowFrame = findViewById( R.id.module_main_id_map_left_shadow_frame );
|
||||
mTopShadowFrame = findViewById( R.id.module_main_id_map_top_shadow_frame );
|
||||
|
||||
WindowViewHandler.init( mFloatingLayout );
|
||||
}
|
||||
|
||||
private void hide() {
|
||||
// 隐藏布局
|
||||
private void hideLayout() {
|
||||
mHeader.setVisibility( View.GONE );
|
||||
mCards.setVisibility( View.GONE );
|
||||
mApps.setVisibility( View.GONE );
|
||||
mEntrance.setVisibility( View.GONE );
|
||||
mFloatingLayout.setVisibility( View.GONE );
|
||||
mShadowFrame.setVisibility( View.GONE );
|
||||
mLeftShadowFrame.setVisibility( View.GONE );
|
||||
}
|
||||
|
||||
private void show() {
|
||||
// 显示布局
|
||||
private void showLayout() {
|
||||
mHeader.setVisibility( View.VISIBLE );
|
||||
mCards.setVisibility( View.VISIBLE );
|
||||
mApps.setVisibility( View.VISIBLE );
|
||||
mEntrance.setVisibility( View.VISIBLE );
|
||||
mFloatingLayout.setVisibility( View.VISIBLE );
|
||||
mShadowFrame.setVisibility( View.VISIBLE );
|
||||
mLeftShadowFrame.setVisibility( View.VISIBLE );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate( @Nullable Bundle savedInstanceState ) {
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
MogoModulePaths.addModule( new MogoModule( MogoModulePaths.PATH_MODULE_APPS, MogoModulePaths.PATH_MODULE_APPS ) );
|
||||
MogoModulePaths.addModule( new MogoModule( MogoModulePaths.PATH_MODULE_MAP, MogoModulePaths.PATH_MODULE_MAP ) );
|
||||
MogoModulePaths.addModule( new MogoModule( ServiceConst.PATH_REFRESH_STRATEGY, ServiceConst.PATH_REFRESH_STRATEGY ) );
|
||||
MogoModulePaths.addModule( new MogoModule( ExtensionsModuleConst.PATH_EXTENSION, ExtensionsModuleConst.TYPE ) );
|
||||
MogoModulePaths.addModule( new MogoModule( ExtensionsModuleConst.PATH_ENTRANCE, ExtensionsModuleConst.TYPE_ENTRANCE ) );
|
||||
|
||||
mMogoModuleHandler = new MogoModulesManager( this );
|
||||
mMogoMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
|
||||
@@ -214,30 +213,43 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoMapService.getHostListenerRegister().registerMarkerClickListener( this );
|
||||
}
|
||||
|
||||
mMogoMapUIController = mMogoMapService.getMapUIController();
|
||||
|
||||
mMogoModuleHandler.loadModules();
|
||||
mMogoModuleHandler.onMapLoadedCallback( () -> {
|
||||
mMogoModuleHandler.setMapLoadedCallback( () -> {
|
||||
Logger.d( TAG, "map loaded." + Thread.currentThread().getName() );
|
||||
loadModules();
|
||||
mShadowFrame.setVisibility( View.VISIBLE );
|
||||
mMogoMapUIController.setPointToCenter( 0.66145, 0.590688 );
|
||||
} );
|
||||
// 加载地图,触发地图加载完毕回调,在初始化其他卡片模块,保证卡片模块可以正确获取地图相关服务。
|
||||
mMogoModuleHandler.loadMap( R.id.module_main_id_map_fragment_container );
|
||||
mMogoModuleHandler.loadAppsList( R.id.module_main_id_apps_fragment_container );
|
||||
mMogoModuleHandler.loadExtensions( R.id.module_main_id_header_fragment_container );
|
||||
mMogoModuleHandler.loadEntrances( R.id.module_main_id_entrance_fragment_container );
|
||||
// 加载地图,触发地图加载完毕回调,在初始化其他卡片模块,保证卡片模块可以正确获取地图相关服务。
|
||||
mMogoModuleHandler.loadModules();
|
||||
loadContainerModules();
|
||||
loadCardModules();
|
||||
|
||||
mLocationClient = mMogoMapService.getSingletonLocationClient( getApplicationContext() );
|
||||
mLocationClient.addLocationListener( this );
|
||||
mLocationClient.start();
|
||||
// 显示左边遮罩
|
||||
mLeftShadowFrame.setVisibility( View.VISIBLE );
|
||||
mTopShadowFrame.setVisibility( View.VISIBLE );
|
||||
|
||||
// 右移地图中心点
|
||||
mMogoMapUIController = mMogoMapService.getMapUIController();
|
||||
mMogoMapUIController.setPointToCenter( 0.66145, 0.590688 );
|
||||
|
||||
// 开启定位
|
||||
startLocation();
|
||||
} );
|
||||
mMogoModuleHandler.loadMapModule( R.id.module_main_id_map_fragment_container );
|
||||
|
||||
mMogoCardManager = ( IMogoCardManager ) ARouter.getInstance().build( MogoServicePaths.PATH_CARD_MANAGER ).navigation( this );
|
||||
mAnalytics = ( IMogoAnalytics ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_ANALYTICS ).navigation( this );
|
||||
}
|
||||
|
||||
private void loadModules() {
|
||||
private void startLocation() {
|
||||
mLocationClient = mMogoMapService.getSingletonLocationClient( getApplicationContext() );
|
||||
mLocationClient.addLocationListener( this );
|
||||
mLocationClient.start();
|
||||
}
|
||||
|
||||
private void loadContainerModules() {
|
||||
mMogoModuleHandler.loadAppsListModule( R.id.module_main_id_apps_fragment_container );
|
||||
mMogoModuleHandler.loadExtensionsModule( R.id.module_main_id_header_fragment_container );
|
||||
mMogoModuleHandler.loadEntrancesModule( R.id.module_main_id_entrance_fragment_container );
|
||||
}
|
||||
|
||||
private void loadCardModules() {
|
||||
|
||||
List< IMogoModuleProvider > providers = mMogoModuleHandler.loadCardsModule();
|
||||
mCardModulesAdapter = new CardModulesAdapter( this, providers );
|
||||
@@ -268,7 +280,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
isClickMarker = true;
|
||||
switch2( marker.getOwner() );
|
||||
if ( mMogoModuleHandler != null ) {
|
||||
mMogoModuleHandler.onMarkerReceive( marker );
|
||||
mMogoModuleHandler.onMarkerClicked( marker );
|
||||
}
|
||||
isClickMarker = false;
|
||||
return false;
|
||||
@@ -291,10 +303,12 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if ( FragmentStack.getInstance().isEmpty() ) {
|
||||
if ( mMogoFragmentManager.getStackSize() == 0 ) {
|
||||
return;
|
||||
}
|
||||
FragmentStack.getInstance().pop();
|
||||
if ( mMogoFragmentManager != null ) {
|
||||
mMogoFragmentManager.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -305,10 +319,15 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mLocationClient.destroy();
|
||||
}
|
||||
mLocationClient = null;
|
||||
mMogoMapService = null;
|
||||
if ( mMogoModuleHandler != null ) {
|
||||
mMogoModuleHandler.destroy();
|
||||
mMogoModuleHandler = null;
|
||||
}
|
||||
mMogoModuleHandler = null;
|
||||
mMogoMapService = null;
|
||||
mMogoMapUIController = null;
|
||||
mMogoCardManager = null;
|
||||
mMogoFragmentManager = null;
|
||||
|
||||
AIAssist.getInstance( this ).release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,19 @@ import javax.security.auth.callback.Callback;
|
||||
*/
|
||||
public interface MogoModulesHandler extends IMogoMapListener,
|
||||
IMogoNaviListener,
|
||||
IMogoLocationListener {
|
||||
IMogoLocationListener,
|
||||
IMogoMarkerClickListener {
|
||||
|
||||
void onMapLoadedCallback( Runnable callback );
|
||||
/**
|
||||
* 地图加载完成回调
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
void setMapLoadedCallback( Runnable callback );
|
||||
|
||||
/**
|
||||
* 加载模块
|
||||
*/
|
||||
void loadModules();
|
||||
|
||||
/**
|
||||
@@ -39,49 +48,41 @@ public interface MogoModulesHandler extends IMogoMapListener,
|
||||
*
|
||||
* @param containerId 容器id
|
||||
*/
|
||||
void loadMap( int containerId );
|
||||
void loadMapModule( int containerId );
|
||||
|
||||
/**
|
||||
* 加载所有应用
|
||||
*
|
||||
* @param containerId 容器id
|
||||
*/
|
||||
void loadAppsList( int containerId );
|
||||
void loadAppsListModule( int containerId );
|
||||
|
||||
/**
|
||||
* 加载头部信息
|
||||
*
|
||||
* @param containerId
|
||||
*/
|
||||
void loadExtensions( int containerId );
|
||||
void loadExtensionsModule( int containerId );
|
||||
|
||||
/**
|
||||
* 加载快捷操作
|
||||
*
|
||||
* @param containerId
|
||||
*/
|
||||
void loadEntrances( int containerId );
|
||||
void loadEntrancesModule( int containerId );
|
||||
|
||||
/**
|
||||
* 设置某一个module可用
|
||||
*
|
||||
* @param module
|
||||
*/
|
||||
void setEnable( String module );
|
||||
void setModuleEnable( String module );
|
||||
|
||||
/**
|
||||
* 销毁
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
|
||||
/**
|
||||
* 卡片接收到Marker传入数据
|
||||
*
|
||||
* @param marker marker
|
||||
*/
|
||||
void onMarkerReceive( IMogoMarker marker );
|
||||
|
||||
/**
|
||||
* 当前卡片名称
|
||||
*
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -23,6 +24,7 @@ import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.extensions.ExtensionsModuleConst;
|
||||
import com.mogo.module.main.MainActivity;
|
||||
import com.mogo.module.main.registercenter.MogoRegisterCenterHandler;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
@@ -36,7 +38,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -90,7 +91,7 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapLoadedCallback( Runnable callback ) {
|
||||
public void setMapLoadedCallback( Runnable callback ) {
|
||||
mMapLoadedCallback = callback;
|
||||
}
|
||||
|
||||
@@ -111,35 +112,27 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMap( int containerId ) {
|
||||
loadModuleByType( ModuleType.TYPE_MAP, containerId );
|
||||
public void loadMapModule( int containerId ) {
|
||||
IMogoModuleProvider provider = ( IMogoModuleProvider ) ARouter.getInstance().build( MogoModulePaths.PATH_MODULE_MAP ).navigation( getContext() );
|
||||
addFragment( provider, containerId );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAppsList( int containerId ) {
|
||||
loadModuleByType( ModuleType.TYPE_APP_LIST, containerId );
|
||||
public void loadAppsListModule( int containerId ) {
|
||||
IMogoModuleProvider provider = ( IMogoModuleProvider ) ARouter.getInstance().build( MogoModulePaths.PATH_MODULE_APPS ).navigation( getContext() );
|
||||
addFragment( provider, containerId );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadExtensions( int containerId ) {
|
||||
loadModuleByType( ModuleType.TYPE_EXTENSION, containerId );
|
||||
public void loadExtensionsModule( int containerId ) {
|
||||
IMogoModuleProvider provider = ( IMogoModuleProvider ) ARouter.getInstance().build( ExtensionsModuleConst.PATH_EXTENSION ).navigation( getContext() );
|
||||
addFragment( provider, containerId );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadEntrances( int containerId ) {
|
||||
loadModuleByType( ModuleType.TYPE_ENTRANCE, containerId );
|
||||
}
|
||||
|
||||
private void loadModuleByType( int type, int containerId ) {
|
||||
if ( mModuleProviders.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
for ( IMogoModuleProvider value : mModuleProviders.values() ) {
|
||||
if ( value.getType() == type ) {
|
||||
addFragment( value, containerId );
|
||||
return;
|
||||
}
|
||||
}
|
||||
public void loadEntrancesModule( int containerId ) {
|
||||
IMogoModuleProvider provider = ( IMogoModuleProvider ) ARouter.getInstance().build( ExtensionsModuleConst.PATH_ENTRANCE ).navigation( getContext() );
|
||||
addFragment( provider, containerId );
|
||||
}
|
||||
|
||||
private IMogoModuleProvider load( String path ) {
|
||||
@@ -162,8 +155,9 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnable( String module ) {
|
||||
public void setModuleEnable( String module ) {
|
||||
|
||||
// 仅操作上一个模块和当前模块
|
||||
Iterator< IMogoModuleProvider > iterator = mModuleProviders.values().iterator();
|
||||
int counter = 0;
|
||||
while ( iterator.hasNext() ) {
|
||||
@@ -178,7 +172,9 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
final IMogoModuleLifecycle lifecycle = MogoRegisterCenterHandler.getInstance().getLifecycleListener( mEnableModuleName );
|
||||
if ( lifecycle != null ) {
|
||||
try {
|
||||
final long start = System.currentTimeMillis();
|
||||
lifecycle.onDisable();
|
||||
Logger.i(TAG, "set %s module disable event cost " + (System.currentTimeMillis() - start) + "ms", mEnableModuleName);
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
@@ -190,7 +186,9 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
final IMogoModuleLifecycle lifecycle = MogoRegisterCenterHandler.getInstance().getLifecycleListener( module );
|
||||
if ( lifecycle != null ) {
|
||||
try {
|
||||
final long start = System.currentTimeMillis();
|
||||
lifecycle.onPerform();
|
||||
Logger.i(TAG, "set %s module perform event cost " + (System.currentTimeMillis() - start) + "ms", module);
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
@@ -212,20 +210,6 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
mMapLoadedCallback.run();
|
||||
mMapLoadedCallback = null;
|
||||
}
|
||||
Iterator< IMogoMapListener > iterator = MogoRegisterCenterHandler.getInstance().getMapListeners();
|
||||
if ( iterator == null ) {
|
||||
return;
|
||||
}
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoMapListener listener = iterator.next();
|
||||
if ( listener != null ) {
|
||||
try {
|
||||
listener.onMapLoaded();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -426,7 +410,6 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCalculateSuccess() {
|
||||
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
|
||||
@@ -473,7 +456,7 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
IMogoNaviListener listener = iterator.next();
|
||||
if ( listener != null ) {
|
||||
try {
|
||||
listener.onUpdateTraffic(traffic);
|
||||
listener.onUpdateTraffic( traffic );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
@@ -541,15 +524,16 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkerReceive( IMogoMarker marker ) {
|
||||
public boolean onMarkerClicked( IMogoMarker marker ) {
|
||||
IMogoMarkerClickListener listener = MogoRegisterCenterHandler.getInstance().getMarkerListener( marker.getOwner() );
|
||||
if ( listener != null ) {
|
||||
try {
|
||||
listener.onMarkerClicked( marker );
|
||||
return listener.onMarkerClicked( marker );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,8 +10,8 @@ import com.mogo.utils.WindowUtils;
|
||||
public class VerticalStackTransformer extends VerticalBaseTransformer {
|
||||
|
||||
private Context context;
|
||||
private int spaceBetweenFirAndSecWith = 5 * 2;//第一张卡片和第二张卡片宽度差 dp单位
|
||||
private int spaceBetweenFirAndSecHeight = 5;//第一张卡片和第二张卡片高度差 dp单位
|
||||
private int spaceBetweenFirAndSecWith;//第一张卡片和第二张卡片宽度差
|
||||
private int spaceBetweenFirAndSecHeight;//第一张卡片和第二张卡片高度差
|
||||
|
||||
public VerticalStackTransformer( Context context ) {
|
||||
this.context = context;
|
||||
|
||||
Reference in New Issue
Block a user