diff --git a/app/build.gradle b/app/build.gradle index 11fb01ca5c..afb298b173 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,9 +60,11 @@ dependencies { api rootProject.ext.dependencies.mogocommons implementation rootProject.ext.dependencies.moduledemo implementation rootProject.ext.dependencies.moduledemo2 + implementation rootProject.ext.dependencies.modulecommon } else { implementation project(':modules:mogo-module-main') implementation project(':foudations:mogo-commons') + implementation project(':modules:mogo-module-common') implementation project(':demo:demo-module-map') implementation project(':demo:demo-module-map2') } diff --git a/app/src/main/java/com/mogo/launcher/MogoApplication.java b/app/src/main/java/com/mogo/launcher/MogoApplication.java index 906b5259e6..2754e27346 100644 --- a/app/src/main/java/com/mogo/launcher/MogoApplication.java +++ b/app/src/main/java/com/mogo/launcher/MogoApplication.java @@ -1,11 +1,13 @@ package com.mogo.launcher; -import android.app.Application; import android.content.Context; import androidx.multidex.MultiDex; import com.mogo.commons.AbsMogoApplication; +import com.mogo.demo.module.map.DemoConstants; +import com.mogo.demo.module.map2.Demo2Constants; +import com.mogo.module.common.MogoModulePaths; /** * @author congtaowang @@ -24,5 +26,7 @@ public class MogoApplication extends AbsMogoApplication { protected void attachBaseContext( Context base ) { super.attachBaseContext( base ); MultiDex.install( base ); + MogoModulePaths.addModule( DemoConstants.TAG ); + MogoModulePaths.addModule( Demo2Constants.TAG ); } } diff --git a/config.gradle b/config.gradle index 62dedc2903..8b16b0683b 100644 --- a/config.gradle +++ b/config.gradle @@ -65,7 +65,7 @@ ext { // modules moduledemo : "com.mogo.module:module-demo:${DEMO_MODULE_MAP_VERSION}", - moduledemo2 : "com.mogo.module:module-demo:${DEMO_MODULE_MAP2_VERSION}", + moduledemo2 : "com.mogo.module:module-demo2:${DEMO_MODULE_MAP2_VERSION}", mogocommons : "com.mogo.commons:mogo-commons:${MOGO_COMMONS_VERSION}", mogoutils : "com.mogo.commons:mogo-utils:${MOGO_UTILS_VERSION}", mapamap : "com.mogo.map:map-amap:${MAP_AMAP_VERSION}", diff --git a/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoCardViewFragment.java b/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoCardViewFragment.java index 25c2a73663..9f9da9fd52 100644 --- a/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoCardViewFragment.java +++ b/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoCardViewFragment.java @@ -12,31 +12,21 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.alibaba.android.arouter.launcher.ARouter; import com.mogo.commons.mvp.IView; import com.mogo.commons.mvp.MvpFragment; import com.mogo.commons.mvp.Presenter; import com.mogo.map.MogoLatLng; import com.mogo.map.listener.IMogoMapListener; import com.mogo.map.location.IMogoLocationListener; -import com.mogo.map.location.IMogoLocationClient; import com.mogo.map.location.MogoLocation; import com.mogo.map.marker.IMogoMarker; import com.mogo.map.marker.IMogoMarkerClickListener; -import com.mogo.map.marker.IMogoMarkerManager; import com.mogo.map.marker.MogoMarkerOptions; import com.mogo.map.model.MogoPoi; -import com.mogo.map.navi.IMogoNavi; import com.mogo.map.search.geo.MogoPoiItem; -import com.mogo.map.search.poisearch.IMogoPoiSearch; import com.mogo.map.search.poisearch.IMogoPoiSearchListener; import com.mogo.map.search.poisearch.MogoPoiResult; -import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery; import com.mogo.map.uicontroller.EnumMapUI; -import com.mogo.map.uicontroller.IMogoMapUIController; -import com.mogo.service.MogoServicePaths; -import com.mogo.service.imageloader.IMogoImageloader; -import com.mogo.service.map.IMogoMapService; import com.mogo.service.module.IMogoModuleLifecycle; import com.mogo.utils.TipToast; import com.mogo.utils.logger.Logger; @@ -65,6 +55,8 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > private Button mAddMarker; private Button mAddMarkers; + private static IMogoMarker mLastClickedMarker; + private Bitmap mMarkerIcon; private Bitmap mClickedMarkerIcon; private TextView mLocInfo; @@ -72,19 +64,10 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > private Button m2D3D; private CheckBox mNaviMode; - private IMogoMarker mLastClickedMarker; - - private IMogoMapService mMapService; - private IMogoPoiSearch mPoiSearch; - private IMogoLocationClient mLocationClient; - private IMogoMarkerManager mMarkerManager; - private IMogoNavi mNavi; - private IMogoMapUIController mMapUIController; - private DemoInfoWindowAdapter mDemoInfoWindowAdapter; private MogoLocation mLocation; - private IMogoImageloader mImageloader; + private int position = -1; @Override protected int getLayoutId() { @@ -94,18 +77,12 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override protected void initViews() { + position = getArguments().getInt( "position" ); + mNaviMode = findViewById( R.id.demo_module_id_navi_mode ); - mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( getContext() ); - mImageloader = ( IMogoImageloader ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_IMAGE_LOADER ).navigation( getContext() ); - mPoiSearch = mMapService.getPoiSearch( getContext(), new MogoPoiSearchQuery() ); - mPoiSearch.setPoiSearchListener( this ); - mLocationClient = mMapService.getLocationClient( getContext() ); - mLocation = mLocationClient.getLastKnowLocation(); - mMarkerManager = mMapService.getMarkerManager( getContext() ); - mNavi = mMapService.getNavi( getContext() ); - mMapUIController = mMapService.getMapUIController(); - + ServiceHandler.getPoiSearch().setPoiSearchListener( this ); + mLocation = ServiceHandler.getLocationClient().getLastKnowLocation(); m2D3D = findViewById( R.id.demo_module_id_2d3d ); mLocInfo = findViewById( R.id.demo_module_id_loc_info ); @@ -114,12 +91,12 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > new View.OnClickListener() { @Override public void onClick( View v ) { - mLocationClient.start( 4_000L ); + ServiceHandler.getLocationClient().start( 4_000L ); } } ); - mDemoInfoWindowAdapter = new DemoInfoWindowAdapter( getContext(), mNavi, mImageloader ); + mDemoInfoWindowAdapter = new DemoInfoWindowAdapter( getContext(), ServiceHandler.getNavi(), ServiceHandler.getImageloader() ); mMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_search_poi_location ); mClickedMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_search_choice_point ); @@ -132,7 +109,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > .latitude( 39.974525d ) .owner( DemoConstants.TAG ) .longitude( 116.41733d ); - IMogoMarker marker = mMarkerManager.addMarker( DemoConstants.TAG, options ); + IMogoMarker marker = ServiceHandler.getMarkerManager().addMarker( DemoConstants.TAG, options ); marker.setInfoWindowAdapter( mDemoInfoWindowAdapter ); marker.setOnMarkerClickListener( DemoCardViewFragment.this ); } @@ -155,7 +132,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > } optionsList.add( options ); } - List< IMogoMarker > iMogoMarkers = mMarkerManager.addMarkers( DemoConstants.TAG, optionsList, true ); + List< IMogoMarker > iMogoMarkers = ServiceHandler.getMarkerManager().addMarkers( DemoConstants.TAG, optionsList, true ); for ( IMogoMarker iMogoMarker : iMogoMarkers ) { iMogoMarker.setInfoWindowAdapter( mDemoInfoWindowAdapter ); iMogoMarker.setOnMarkerClickListener( DemoCardViewFragment.this ); @@ -166,7 +143,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > findViewById( R.id.demo_module_id_clear ).setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { - mMarkerManager.removeMarkers( DemoConstants.TAG ); + ServiceHandler.getMarkerManager().removeMarkers( DemoConstants.TAG ); } } ); @@ -176,7 +153,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onClick( View v ) { - mMapUIController.changeMapMode( ui = ui.next() ); + ServiceHandler.getMapUIController().changeMapMode( ui = ui.next() ); m2D3D.setText( ui.toString() ); } } ); @@ -184,21 +161,21 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > findViewById( R.id.demo_module_id_current ).setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { - mMapUIController.moveToCenter( new MogoLatLng( mLocation.getLatitude(), mLocation.getLongitude() ) ); + ServiceHandler.getMapUIController().moveToCenter( new MogoLatLng( mLocation.getLatitude(), mLocation.getLongitude() ) ); } } ); findViewById( R.id.demo_module_id_start_navi ).setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { - mNavi.startNavi( !mNaviMode.isChecked() ); + ServiceHandler.getNavi().startNavi( !mNaviMode.isChecked() ); } } ); findViewById( R.id.demo_module_id_stop_navi ).setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { - mNavi.stopNavi(); + ServiceHandler.getNavi().stopNavi(); } } ); @@ -208,7 +185,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onClick( View v ) { - mMapUIController.setTrafficEnabled( enable = !enable ); + ServiceHandler.getMapUIController().setTrafficEnabled( enable = !enable ); } } ); @@ -216,7 +193,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onClick( View v ) { - mMapUIController.changeZoom( true ); + ServiceHandler.getMapUIController().changeZoom( true ); } } ); @@ -224,7 +201,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onClick( View v ) { - mMapUIController.changeZoom( false ); + ServiceHandler.getMapUIController().changeZoom( false ); } } ); @@ -232,7 +209,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onClick( View v ) { - mMapUIController.changeMapMode( EnumMapUI.Type_Light ); + ServiceHandler.getMapUIController().changeMapMode( EnumMapUI.Type_Light ); } } ); @@ -240,7 +217,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onClick( View v ) { - mMapUIController.changeMapMode( EnumMapUI.Type_Night ); + ServiceHandler.getMapUIController().changeMapMode( EnumMapUI.Type_Night ); } } ); @@ -248,7 +225,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onClick( View v ) { - mMapUIController.displayOverview(); + ServiceHandler.getMapUIController().displayOverview(); } } ); @@ -256,11 +233,11 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onClick( View v ) { - mMapUIController.recoverLockMode(); + ServiceHandler.getMapUIController().recoverLockMode(); } } ); - mLocationClient.addLocationListener( new IMogoLocationListener() { + ServiceHandler.getLocationClient().addLocationListener( new IMogoLocationListener() { @Override public void onLocationChanged( MogoLocation location ) { mLocation = location; @@ -320,7 +297,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > if ( poi != null ) { TipToast.shortTip( poi.getName() ); } - mPoiSearch.searchPOIIdAsyn( poi.getPoiId() ); + ServiceHandler.getPoiSearch().searchPOIIdAsyn( poi.getPoiId() ); } @Override @@ -338,7 +315,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > if ( mPoiMarker != null ) { mPoiMarker.destroy(); } - mPoiMarker = mMarkerManager.addMarker( DemoConstants.TAG, new MogoMarkerOptions() + mPoiMarker = ServiceHandler.getMarkerManager().addMarker( DemoConstants.TAG, new MogoMarkerOptions() .longitude( item.getPoint().lng ) .latitude( item.getPoint().lat ) .icon( mMarkerIcon ) ); @@ -379,19 +356,9 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > @Override public void onDestroyView() { - Logger.w( TAG, "onDestroyView" ); + Logger.w( TAG, "onDestroyView position=" + position ); super.onDestroyView(); getViewLifecycleOwner().getLifecycle().removeObserver( mPresenter ); - mLocationClient.removeLocationListener( this ); - if ( mLastClickedMarker != null ) { - mLastClickedMarker.destroy(); - mLastClickedMarker = null; - } - if ( mPoiSearch != null ) { - mPoiSearch.destroy(); - } - mMapService = null; - mPoiSearch = null; - mLocationClient = null; + ServiceHandler.getLocationClient().removeLocationListener( this ); } } diff --git a/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoCardViewProvider.java b/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoCardViewProvider.java index bc5287e8dc..12f06d2fea 100644 --- a/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoCardViewProvider.java +++ b/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoCardViewProvider.java @@ -31,7 +31,7 @@ import com.mogo.utils.logger.Logger; *
* 描述 */ -@Route( path = MogoModulePaths.PATH_MODULE_DEMO ) +@Route( path = DemoConstants.TAG ) public class DemoCardViewProvider implements IMogoModuleProvider { private static final String TAG = "DemoCardViewProvider"; @@ -48,7 +48,7 @@ public class DemoCardViewProvider implements IMogoModuleProvider { @Override public void init( Context context ) { - + ServiceHandler.init( context ); } @Override diff --git a/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoConstants.java b/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoConstants.java index ab82c11c7f..3178029fde 100644 --- a/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoConstants.java +++ b/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/DemoConstants.java @@ -10,5 +10,5 @@ import com.mogo.module.common.MogoModulePaths; */ public class DemoConstants { - public static final String TAG = MogoModulePaths.PATH_MODULE_DEMO; + public static final String TAG = "/demo/ui"; } diff --git a/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/ServiceHandler.java b/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/ServiceHandler.java new file mode 100644 index 0000000000..3eff1914fb --- /dev/null +++ b/demo/demo-module-map/src/main/java/com/mogo/demo/module/map/ServiceHandler.java @@ -0,0 +1,73 @@ +package com.mogo.demo.module.map; + +import android.content.Context; + +import com.alibaba.android.arouter.launcher.ARouter; +import com.mogo.map.location.IMogoLocationClient; +import com.mogo.map.marker.IMogoMarker; +import com.mogo.map.marker.IMogoMarkerManager; +import com.mogo.map.navi.IMogoNavi; +import com.mogo.map.search.poisearch.IMogoPoiSearch; +import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery; +import com.mogo.map.uicontroller.IMogoMapUIController; +import com.mogo.service.MogoServicePaths; +import com.mogo.service.imageloader.IMogoImageloader; +import com.mogo.service.map.IMogoMapService; + +/** + * @author congtaowang + * @since 2019-12-30 + *
+ * 持有服务接口实例 + */ +public class ServiceHandler { + + private static IMogoMapService mMapService; + + private static IMogoPoiSearch mPoiSearch; + private static IMogoLocationClient mLocationClient; + private static IMogoMarkerManager mMarkerManager; + private static IMogoNavi mNavi; + private static IMogoMapUIController mMapUIController; + + private static IMogoImageloader mImageloader; + + public static void init( Context context ) { + mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( context ); + mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( context ); + mImageloader = ( IMogoImageloader ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_IMAGE_LOADER ).navigation( context ); + mPoiSearch = mMapService.getPoiSearch( context, new MogoPoiSearchQuery() ); + mLocationClient = mMapService.getLocationClient( context ); + mMarkerManager = mMapService.getMarkerManager( context ); + mNavi = mMapService.getNavi( context ); + mMapUIController = mMapService.getMapUIController(); + } + + public static IMogoMapService getMapService() { + return mMapService; + } + + public static IMogoPoiSearch getPoiSearch() { + return mPoiSearch; + } + + public static IMogoLocationClient getLocationClient() { + return mLocationClient; + } + + public static IMogoMarkerManager getMarkerManager() { + return mMarkerManager; + } + + public static IMogoNavi getNavi() { + return mNavi; + } + + public static IMogoMapUIController getMapUIController() { + return mMapUIController; + } + + public static IMogoImageloader getImageloader() { + return mImageloader; + } +} diff --git a/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2CardViewFragment.java b/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2CardViewFragment.java index 4abc859bde..86c45f2a78 100644 --- a/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2CardViewFragment.java +++ b/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2CardViewFragment.java @@ -12,31 +12,21 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.alibaba.android.arouter.launcher.ARouter; import com.mogo.commons.mvp.IView; import com.mogo.commons.mvp.MvpFragment; import com.mogo.commons.mvp.Presenter; import com.mogo.map.MogoLatLng; import com.mogo.map.listener.IMogoMapListener; -import com.mogo.map.location.IMogoLocationClient; import com.mogo.map.location.IMogoLocationListener; import com.mogo.map.location.MogoLocation; import com.mogo.map.marker.IMogoMarker; import com.mogo.map.marker.IMogoMarkerClickListener; -import com.mogo.map.marker.IMogoMarkerManager; import com.mogo.map.marker.MogoMarkerOptions; import com.mogo.map.model.MogoPoi; -import com.mogo.map.navi.IMogoNavi; import com.mogo.map.search.geo.MogoPoiItem; -import com.mogo.map.search.poisearch.IMogoPoiSearch; import com.mogo.map.search.poisearch.IMogoPoiSearchListener; import com.mogo.map.search.poisearch.MogoPoiResult; -import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery; import com.mogo.map.uicontroller.EnumMapUI; -import com.mogo.map.uicontroller.IMogoMapUIController; -import com.mogo.service.MogoServicePaths; -import com.mogo.service.imageloader.IMogoImageloader; -import com.mogo.service.map.IMogoMapService; import com.mogo.service.module.IMogoModuleLifecycle; import com.mogo.utils.TipToast; import com.mogo.utils.logger.Logger; @@ -51,7 +41,6 @@ import java.util.Random; *
* 描述:demo测试各种接口 */ - public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView > > implements IView, IMogoMarkerClickListener, @@ -74,17 +63,10 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView private IMogoMarker mLastClickedMarker; - private IMogoMapService mMapService; - private IMogoPoiSearch mPoiSearch; - private IMogoLocationClient mLocationClient; - private IMogoMarkerManager mMarkerManager; - private IMogoNavi mNavi; - private IMogoMapUIController mMapUIController; - private Demo2InfoWindowAdapter mDemoInfoWindowAdapter; private MogoLocation mLocation; - private IMogoImageloader mImageloader; + private int position = -1; @Override protected int getLayoutId() { @@ -94,17 +76,12 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override protected void initViews() { + position = getArguments().getInt( "position" ); + mNaviMode = findViewById( R.id.demo_module_id_navi_mode ); - mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( getContext() ); - mImageloader = ( IMogoImageloader ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_IMAGE_LOADER ).navigation( getContext() ); - mPoiSearch = mMapService.getPoiSearch( getContext(), new MogoPoiSearchQuery() ); - mPoiSearch.setPoiSearchListener( this ); - mLocationClient = mMapService.getLocationClient( getContext() ); - mLocation = mLocationClient.getLastKnowLocation(); - mMarkerManager = mMapService.getMarkerManager( getContext() ); - mNavi = mMapService.getNavi( getContext() ); - mMapUIController = mMapService.getMapUIController(); + Service2Handler.getPoiSearch().setPoiSearchListener( this ); + mLocation = Service2Handler.getLocationClient().getLastKnowLocation(); m2D3D = findViewById( R.id.demo_module_id_2d3d ); @@ -114,12 +91,12 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView new View.OnClickListener() { @Override public void onClick( View v ) { - mLocationClient.start( 4_000L ); + Service2Handler.getLocationClient().start( 4_000L ); } } ); - mDemoInfoWindowAdapter = new Demo2InfoWindowAdapter( getContext(), mNavi, mImageloader ); + mDemoInfoWindowAdapter = new Demo2InfoWindowAdapter( getContext(), Service2Handler.getNavi(), Service2Handler.getImageloader() ); mMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_search_poi_location ); mClickedMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_search_choice_point ); @@ -132,7 +109,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView .latitude( 39.974525d ) .owner( Demo2Constants.TAG ) .longitude( 116.41733d ); - IMogoMarker marker = mMarkerManager.addMarker( Demo2Constants.TAG, options ); + IMogoMarker marker = Service2Handler.getMarkerManager().addMarker( Demo2Constants.TAG, options ); marker.setInfoWindowAdapter( mDemoInfoWindowAdapter ); marker.setOnMarkerClickListener( Demo2CardViewFragment.this ); } @@ -155,7 +132,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView } optionsList.add( options ); } - List< IMogoMarker > iMogoMarkers = mMarkerManager.addMarkers( Demo2Constants.TAG, optionsList, true ); + List< IMogoMarker > iMogoMarkers = Service2Handler.getMarkerManager().addMarkers( Demo2Constants.TAG, optionsList, true ); for ( IMogoMarker iMogoMarker : iMogoMarkers ) { iMogoMarker.setInfoWindowAdapter( mDemoInfoWindowAdapter ); iMogoMarker.setOnMarkerClickListener( Demo2CardViewFragment.this ); @@ -166,7 +143,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView findViewById( R.id.demo_module_id_clear ).setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { - mMarkerManager.removeMarkers( Demo2Constants.TAG ); + Service2Handler.getMarkerManager().removeMarkers( Demo2Constants.TAG ); } } ); @@ -176,7 +153,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onClick( View v ) { - mMapUIController.changeMapMode( ui = ui.next() ); + Service2Handler.getMapUIController().changeMapMode( ui = ui.next() ); m2D3D.setText( ui.toString() ); } } ); @@ -184,21 +161,21 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView findViewById( R.id.demo_module_id_current ).setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { - mMapUIController.moveToCenter( new MogoLatLng( mLocation.getLatitude(), mLocation.getLongitude() ) ); + Service2Handler.getMapUIController().moveToCenter( new MogoLatLng( mLocation.getLatitude(), mLocation.getLongitude() ) ); } } ); findViewById( R.id.demo_module_id_start_navi ).setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { - mNavi.startNavi( !mNaviMode.isChecked() ); + Service2Handler.getNavi().startNavi( !mNaviMode.isChecked() ); } } ); findViewById( R.id.demo_module_id_stop_navi ).setOnClickListener( new View.OnClickListener() { @Override public void onClick( View v ) { - mNavi.stopNavi(); + Service2Handler.getNavi().stopNavi(); } } ); @@ -208,7 +185,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onClick( View v ) { - mMapUIController.setTrafficEnabled( enable = !enable ); + Service2Handler.getMapUIController().setTrafficEnabled( enable = !enable ); } } ); @@ -216,7 +193,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onClick( View v ) { - mMapUIController.changeZoom( true ); + Service2Handler.getMapUIController().changeZoom( true ); } } ); @@ -224,7 +201,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onClick( View v ) { - mMapUIController.changeZoom( false ); + Service2Handler.getMapUIController().changeZoom( false ); } } ); @@ -232,7 +209,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onClick( View v ) { - mMapUIController.changeMapMode( EnumMapUI.Type_Light ); + Service2Handler.getMapUIController().changeMapMode( EnumMapUI.Type_Light ); } } ); @@ -240,7 +217,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onClick( View v ) { - mMapUIController.changeMapMode( EnumMapUI.Type_Night ); + Service2Handler.getMapUIController().changeMapMode( EnumMapUI.Type_Night ); } } ); @@ -248,7 +225,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onClick( View v ) { - mMapUIController.displayOverview(); + Service2Handler.getMapUIController().displayOverview(); } } ); @@ -256,11 +233,11 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onClick( View v ) { - mMapUIController.recoverLockMode(); + Service2Handler.getMapUIController().recoverLockMode(); } } ); - mLocationClient.addLocationListener( new IMogoLocationListener() { + Service2Handler.getLocationClient().addLocationListener( new IMogoLocationListener() { @Override public void onLocationChanged( MogoLocation location ) { mLocation = location; @@ -320,7 +297,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView if ( poi != null ) { TipToast.shortTip( poi.getName() ); } - mPoiSearch.searchPOIIdAsyn( poi.getPoiId() ); + Service2Handler.getPoiSearch().searchPOIIdAsyn( poi.getPoiId() ); } @Override @@ -338,7 +315,7 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView if ( mPoiMarker != null ) { mPoiMarker.destroy(); } - mPoiMarker = mMarkerManager.addMarker( Demo2Constants.TAG, new MogoMarkerOptions() + mPoiMarker = Service2Handler.getMarkerManager().addMarker( Demo2Constants.TAG, new MogoMarkerOptions() .longitude( item.getPoint().lng ) .latitude( item.getPoint().lat ) .icon( mMarkerIcon ) ); @@ -379,19 +356,13 @@ public class Demo2CardViewFragment extends MvpFragment< IView, Presenter< IView @Override public void onDestroyView() { - Logger.w( TAG, "onDestroyView" ); + Logger.w( TAG, "onDestroyView position=" + position ); super.onDestroyView(); getViewLifecycleOwner().getLifecycle().removeObserver( mPresenter ); - mLocationClient.removeLocationListener( this ); + Service2Handler.getLocationClient().removeLocationListener( this ); if ( mLastClickedMarker != null ) { mLastClickedMarker.destroy(); mLastClickedMarker = null; } - if ( mPoiSearch != null ) { - mPoiSearch.destroy(); - } - mMapService = null; - mPoiSearch = null; - mLocationClient = null; } } diff --git a/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2CardViewProvider.java b/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2CardViewProvider.java index d479c116dd..720db4e029 100644 --- a/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2CardViewProvider.java +++ b/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2CardViewProvider.java @@ -10,7 +10,6 @@ import com.alibaba.android.arouter.facade.annotation.Route; import com.mogo.map.listener.IMogoMapListener; import com.mogo.map.location.IMogoLocationListener; import com.mogo.map.navi.IMogoNaviListener; -import com.mogo.module.common.MogoModulePaths; import com.mogo.service.module.IMogoModuleLifecycle; import com.mogo.service.module.IMogoModuleProvider; import com.mogo.utils.logger.Logger; @@ -21,7 +20,7 @@ import com.mogo.utils.logger.Logger; *
* 描述 */ -@Route( path = MogoModulePaths.PATH_MODULE_DEMO2 ) +@Route( path = Demo2Constants.TAG ) public class Demo2CardViewProvider implements IMogoModuleProvider { private static final String TAG = "Demo2CardViewProvider"; @@ -38,7 +37,7 @@ public class Demo2CardViewProvider implements IMogoModuleProvider { @Override public void init( Context context ) { - + Service2Handler.init( context ); } @Override diff --git a/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2Constants.java b/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2Constants.java index 1c61c1f7be..27bf85a7eb 100644 --- a/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2Constants.java +++ b/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Demo2Constants.java @@ -1,7 +1,5 @@ package com.mogo.demo.module.map2; -import com.mogo.module.common.MogoModulePaths; - /** * @author congtaowang * @since 2019-12-24 @@ -10,5 +8,5 @@ import com.mogo.module.common.MogoModulePaths; */ public class Demo2Constants { - public static final String TAG = MogoModulePaths.PATH_MODULE_DEMO2; + public static final String TAG = "/demo2/ui"; } diff --git a/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Service2Handler.java b/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Service2Handler.java new file mode 100644 index 0000000000..3394c048dc --- /dev/null +++ b/demo/demo-module-map2/src/main/java/com/mogo/demo/module/map2/Service2Handler.java @@ -0,0 +1,72 @@ +package com.mogo.demo.module.map2; + +import android.content.Context; + +import com.alibaba.android.arouter.launcher.ARouter; +import com.mogo.map.location.IMogoLocationClient; +import com.mogo.map.marker.IMogoMarkerManager; +import com.mogo.map.navi.IMogoNavi; +import com.mogo.map.search.poisearch.IMogoPoiSearch; +import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery; +import com.mogo.map.uicontroller.IMogoMapUIController; +import com.mogo.service.MogoServicePaths; +import com.mogo.service.imageloader.IMogoImageloader; +import com.mogo.service.map.IMogoMapService; + +/** + * @author congtaowang + * @since 2019-12-30 + *
+ * 持有服务接口实例 + */ +public class Service2Handler { + + private static IMogoMapService mMapService; + + private static IMogoPoiSearch mPoiSearch; + private static IMogoLocationClient mLocationClient; + private static IMogoMarkerManager mMarkerManager; + private static IMogoNavi mNavi; + private static IMogoMapUIController mMapUIController; + + private static IMogoImageloader mImageloader; + + public static void init( Context context ) { + mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( context ); + mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( context ); + mImageloader = ( IMogoImageloader ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_IMAGE_LOADER ).navigation( context ); + mPoiSearch = mMapService.getPoiSearch( context, new MogoPoiSearchQuery() ); + mLocationClient = mMapService.getLocationClient( context ); + mMarkerManager = mMapService.getMarkerManager( context ); + mNavi = mMapService.getNavi( context ); + mMapUIController = mMapService.getMapUIController(); + } + + public static IMogoMapService getMapService() { + return mMapService; + } + + public static IMogoPoiSearch getPoiSearch() { + return mPoiSearch; + } + + public static IMogoLocationClient getLocationClient() { + return mLocationClient; + } + + public static IMogoMarkerManager getMarkerManager() { + return mMarkerManager; + } + + public static IMogoNavi getNavi() { + return mNavi; + } + + public static IMogoMapUIController getMapUIController() { + return mMapUIController; + } + + public static IMogoImageloader getImageloader() { + return mImageloader; + } +} diff --git a/foudations/mogo-commons/src/main/java/com/mogo/commons/mvp/MvpFragment.java b/foudations/mogo-commons/src/main/java/com/mogo/commons/mvp/MvpFragment.java index 833bca9510..4d89489dd6 100644 --- a/foudations/mogo-commons/src/main/java/com/mogo/commons/mvp/MvpFragment.java +++ b/foudations/mogo-commons/src/main/java/com/mogo/commons/mvp/MvpFragment.java @@ -20,7 +20,7 @@ public abstract class MvpFragment< V extends IView, P extends Presenter< V > > e private Context mContext; protected P mPresenter; - private View mRootView; + protected View mRootView; @Override public void onAttach( Context context ) { diff --git a/javadoc.sh b/javadoc.sh new file mode 100755 index 0000000000..b2b349fe7d --- /dev/null +++ b/javadoc.sh @@ -0,0 +1,4 @@ +#!/bin/sh + + + diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/location/ALocationClient.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/location/ALocationClient.java index 207e23302f..8dc2020411 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/location/ALocationClient.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/location/ALocationClient.java @@ -36,7 +36,7 @@ public class ALocationClient implements IMogoLocationClient { mClient = new AMapLocationClient( context ); mClient.setLocationListener( mListener ); mLastLocation = ObjectUtils.fromAMap( mClient.getLastKnownLocation() ); - if ( mLastLocation != null ) { + if ( mLastLocation == null ) { mLastLocation = new MogoLocation(); } } diff --git a/libraries/mogo-map-api/src/main/java/com/mogo/map/MogoMap.java b/libraries/mogo-map-api/src/main/java/com/mogo/map/MogoMap.java index 7571480782..b2c5986293 100644 --- a/libraries/mogo-map-api/src/main/java/com/mogo/map/MogoMap.java +++ b/libraries/mogo-map-api/src/main/java/com/mogo/map/MogoMap.java @@ -2,6 +2,8 @@ package com.mogo.map; import android.content.Context; +import com.mogo.utils.logger.Logger; + /** * @author congtaowang * @since 2019-12-20 @@ -9,6 +11,8 @@ import android.content.Context; * 描述 */ public class MogoMap { + + private static final String TAG = "MogoMap"; private IMogoMap mMap; private Context mContext; @@ -30,6 +34,7 @@ public class MogoMap { } public void init( Context context, IMogoMap map ) { + Logger.d( TAG, "init mogomap" ); this.mContext = context; this.mMap = map; } diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/MogoModulePaths.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/MogoModulePaths.java index 628fb738df..c00f766ae8 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/MogoModulePaths.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/MogoModulePaths.java @@ -1,7 +1,13 @@ package com.mogo.module.common; +import android.text.TextUtils; + import androidx.annotation.Keep; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + /** * @author congtaowang * @since 2019-12-23 @@ -10,26 +16,27 @@ import androidx.annotation.Keep; */ public class MogoModulePaths { + private static List< String > mModulesPath = new ArrayList<>(); + /** * 地图模块 fragment 路径 */ public static final String PATH_MODULE_MAP = "/map/ui"; - /** - * 测试模块 - */ - public static final String PATH_MODULE_DEMO = "/demo/ui"; - - /** - * 测试模块 - */ - public static final String PATH_MODULE_DEMO2 = "/demo2/ui"; - /** * app列表模块实例化路径 */ @Keep public static final String PATH_MODULE_APPS = "/appslist/ui"; + public static void addModule( String path ) { + if ( TextUtils.isEmpty( path.replace( " ", "" ) ) ) { + throw new IllegalArgumentException( "module path can't be empty or null or blank" ); + } + mModulesPath.add( path ); + } + public static List< String > getModulesPath() { + return mModulesPath; + } } diff --git a/modules/mogo-module-main/build.gradle b/modules/mogo-module-main/build.gradle index 3cb6e49dc2..24af006a09 100644 --- a/modules/mogo-module-main/build.gradle +++ b/modules/mogo-module-main/build.gradle @@ -42,7 +42,6 @@ dependencies { implementation rootProject.ext.dependencies.modulemap implementation rootProject.ext.dependencies.mogoserviceapi implementation rootProject.ext.dependencies.mogoservice - implementation rootProject.ext.dependencies.moduledemo implementation rootProject.ext.dependencies.moduleapps } else { implementation project(":foudations:mogo-utils") @@ -51,7 +50,6 @@ dependencies { implementation project(':modules:mogo-module-map') implementation project(':services:mogo-service-api') implementation project(':services:mogo-service') - implementation project(':demo:demo-module-map') implementation project(':modules:mogo-module-apps') } } 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 b988262687..f03c2e4a12 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 @@ -1,6 +1,7 @@ package com.mogo.module.main; import android.os.Bundle; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -11,6 +12,8 @@ import com.mogo.commons.mvp.MvpActivity; import com.mogo.map.location.IMogoLocationClient; import com.mogo.map.location.IMogoLocationListener; import com.mogo.map.location.MogoLocation; +import com.mogo.map.marker.IMogoMarker; +import com.mogo.map.marker.IMogoMarkerClickListener; import com.mogo.module.main.cards.CardModulesAdapter; import com.mogo.module.main.cards.MogoModulesHandler; import com.mogo.module.main.cards.MogoModulesManager; @@ -19,6 +22,7 @@ import com.mogo.module.main.cards.VerticalStackTransformer; import com.mogo.service.MogoServicePaths; import com.mogo.service.map.IMogoMapService; import com.mogo.service.module.IMogoModuleProvider; +import com.mogo.utils.logger.Logger; import java.util.List; @@ -29,7 +33,10 @@ import java.util.List; * 描述 */ public class MainActivity extends MvpActivity< MainView, MainPresenter > implements MainView, - IMogoLocationListener { + IMogoLocationListener, + IMogoMarkerClickListener { + + private static final String TAG = "MainActivity"; private IMogoMapService mMogoMapService; private MogoModulesHandler mMogoModuleHandler; @@ -42,6 +49,8 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme */ private IMogoLocationClient mLocationClient; + private int mCurrentPosition = 1; + @Override protected int getLayoutId() { return R.layout.module_main_activity_main; @@ -54,14 +63,23 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme mCardsContainer.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { + private int mLastPosition = -1; + @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels ) { - + Logger.i( TAG, "position = " + position ); + if ( mLastPosition != position ) { + if ( mCardModulesAdapter != null ) { + mCardModulesAdapter.render( position ); + } + mLastPosition = position; + } } @Override public void onPageSelected( int position ) { try { + mCurrentPosition = position; mMogoModuleHandler.setEnable( mCardModulesAdapter.getProvider( position ).getModuleName() ); } catch ( Exception e ) { e.printStackTrace(); @@ -71,37 +89,66 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme @Override public void onPageScrollStateChanged( int state ) { if ( state == ViewPager.SCROLL_STATE_IDLE ) { + if ( mCurrentPosition == 0 ) { + mCurrentPosition = mCardModulesAdapter.getCount() - 3; + mCardsContainer.setCurrentItem( mCurrentPosition, false ); + } else if ( mCurrentPosition == mCardModulesAdapter.getCount() - 2 ) { + mCurrentPosition = 1; + mCardsContainer.setCurrentItem( mCurrentPosition, false ); + } } } } ); } + public int getCurrentPosition() { + return mCurrentPosition; + } + + public OrientedViewPager getCardsContainer() { + return mCardsContainer; + } + @Override protected void onCreate( @Nullable Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); + mMogoModuleHandler = new MogoModulesManager( this ); + mMogoModuleHandler.onMapLoadedCallback( new Runnable() { + @Override + public void run() { + Logger.d( TAG, "map loaded." + Thread.currentThread().getName() ); + loadModules(); + } + } ); + mMogoMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation(); if ( mMogoMapService != null ) { mMogoMapService.getHostListenerRegister().registerHostMapListener( mMogoModuleHandler ); mMogoMapService.getHostListenerRegister().registerHostNaviListener( mMogoModuleHandler ); - mMogoMapService.getHostListenerRegister().registerMarkerClickListener( mMogoModuleHandler ); + mMogoMapService.getHostListenerRegister().registerMarkerClickListener( this ); } - + // 加载地图,触发地图加载完毕回调,在初始化其他卡片模块,保证卡片模块可以正确获取地图相关服务。 mMogoModuleHandler.loadMap( R.id.module_main_id_map_fragment_container ); - mMogoModuleHandler.loadAppsList( R.id.module_main_id_fragment_container ); mLocationClient = mMogoMapService.getSingletonLocationClient( getApplicationContext() ); mLocationClient.addLocationListener( this ); mLocationClient.start(); + mMogoModuleHandler.loadAppsList( R.id.module_main_id_fragment_container ); + } + + private void loadModules() { + List< IMogoModuleProvider > providers = mMogoModuleHandler.loadCards(); mCardModulesAdapter = new CardModulesAdapter( this, providers ); - mCardsContainer.setOffscreenPageLimit( providers.size() ); + mCardsContainer.setOffscreenPageLimit( providers.size() + 2 ); mCardsContainer.setPageTransformer( true, new VerticalStackTransformer( this ) ); mCardsContainer.setAdapter( mCardModulesAdapter ); - mCardsContainer.setCurrentItem( 0 ); + mCardsContainer.setCurrentItem( mCurrentPosition ); } + @NonNull @Override protected MainPresenter createPresenter() { @@ -115,6 +162,13 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme } } + @Override + public boolean onMarkerClicked( IMogoMarker marker ) { +// int mappedCardPosition = mCardModulesAdapter.getNextCardPosition( marker.getOwner(), mCurrentPosition ); +// mCardsContainer.setCurrentItem( mappedCardPosition, true ); + return false; + } + @Override protected void onDestroy() { super.onDestroy(); diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardModulesAdapter.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardModulesAdapter.java index e8c590a1d8..b572ee1ca1 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardModulesAdapter.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/CardModulesAdapter.java @@ -1,13 +1,18 @@ package com.mogo.module.main.cards; +import android.os.Bundle; +import android.text.TextUtils; import android.util.Log; +import android.view.View; +import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentStatePagerAdapter; +import com.mogo.module.main.MainActivity; import com.mogo.service.module.IMogoModuleProvider; +import com.mogo.utils.logger.Logger; import java.util.ArrayList; import java.util.List; @@ -22,26 +27,43 @@ public class CardModulesAdapter extends FragmentStatePagerAdapter { private static final String TAG = "CardModulesAdapter"; - private final FragmentActivity mActivity; + private final MainActivity mActivity; private List< IMogoModuleProvider > mProviders; + private PlaceholderFragmentProvider mLastPH; + private PlaceholderFragmentProvider mFirstPH; + private PlaceholderFragmentProvider mPH; + + + public CardModulesAdapter( @NonNull MainActivity fragmentActivity, List< IMogoModuleProvider > providers ) { + super( fragmentActivity.getSupportFragmentManager() ); + mActivity = fragmentActivity; + this.mProviders = new ArrayList<>( providers ); + this.mProviders.add( 0, mLastPH = new PlaceholderFragmentProvider() ); + this.mProviders.add( mFirstPH = new PlaceholderFragmentProvider() ); + this.mProviders.add( mPH = new PlaceholderFragmentProvider() ); + } + @NonNull @Override public Fragment getItem( int position ) { int factPosition = getFactPosition( position ); - Log.i( TAG, "factPosition=" + factPosition ); - return mProviders.get( factPosition ).createFragment( mActivity, null ); + Bundle bundle = new Bundle(); + bundle.putInt( "position", factPosition ); + Logger.d( TAG, "here" ); + final Fragment f = mProviders.get( factPosition ).createFragment( mActivity, bundle ); + if ( position == 0 ) { + mLastPH.setCopyTarget( f ); + } else if ( position == getCount() - 2 ) { + mFirstPH.setCopyTarget( f ); + } + return f; } @Override public int getCount() { - return Integer.MAX_VALUE; - } - - public CardModulesAdapter( @NonNull FragmentActivity fragmentActivity, List< IMogoModuleProvider > providers ) { - super( fragmentActivity.getSupportFragmentManager() ); - mActivity = fragmentActivity; - this.mProviders = providers; + return mProviders.size(); +// return Integer.MAX_VALUE; } public IMogoModuleProvider getProvider( int position ) { @@ -57,4 +79,50 @@ public class CardModulesAdapter extends FragmentStatePagerAdapter { return POSITION_NONE; } + /** + * marker、卡片、语音等通过 launcher 切换到其他卡片。 + * + * @param providerTag 卡片类型 + * @param currentPosition 当前卡片位置 + * @return 需要跳转到的卡片实际位置 + */ + public int getNextCardPosition( String providerTag, int currentPosition ) { + int position = 0; + int currentFactPosition = getFactPosition( currentPosition ); + for ( IMogoModuleProvider provider : mProviders ) { + if ( TextUtils.equals( providerTag, provider.getModuleName() ) ) { + break; + } + position++; + } + int offset = 0; + if ( currentFactPosition > position ) { + // 下一个卡片在当前卡片前面 + offset = position - mProviders.size(); + } else if ( currentFactPosition < position ) { + // 下一个卡片在当前卡片后面 + offset = mProviders.size() - position; + } + return currentPosition + offset; + } + + @Override + public void destroyItem( @NonNull ViewGroup container, int position, @NonNull Object object ) { +// super.destroyItem( container, position, object ); +// Logger.d( TAG, "destroy " + object ); + } + + + @Override + public void finishUpdate( @NonNull ViewGroup container ) { + super.finishUpdate( container ); + } + + public void render( int position ) { + if ( position == 1 ) { + mLastPH.renderTargetUI(); + } else if ( position == getCount() - 2 ) { + mFirstPH.renderTargetUI(); + } + } } diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesHandler.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesHandler.java index 5315def15d..a36e9b2dc3 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesHandler.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/MogoModulesHandler.java @@ -10,6 +10,8 @@ import com.mogo.service.module.IMogoModuleProvider; import java.util.Collection; import java.util.List; +import javax.security.auth.callback.Callback; + /** * @author congtaowang * @since 2019-12-24 @@ -17,7 +19,10 @@ import java.util.List; * 卡片管理 */ public interface MogoModulesHandler extends IMogoMapListener, - IMogoNaviListener, IMogoLocationListener, IMogoMarkerClickListener { + IMogoNaviListener, + IMogoLocationListener { + + void onMapLoadedCallback( Runnable callback ); /** * 加载卡片 @@ -61,5 +66,8 @@ public interface MogoModulesHandler extends IMogoMapListener, */ void setEnable( String module ); + /** + * 销毁 + */ void destroy(); } 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 56aaec6a78..a576dfa58b 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 @@ -11,7 +11,6 @@ import com.mogo.map.MogoLatLng; import com.mogo.map.listener.IMogoMapListener; import com.mogo.map.location.IMogoLocationListener; import com.mogo.map.location.MogoLocation; -import com.mogo.map.marker.IMogoMarker; import com.mogo.map.model.MogoPoi; import com.mogo.map.navi.IMogoNaviListener; import com.mogo.map.navi.MogoNaviInfo; @@ -47,6 +46,7 @@ public class MogoModulesManager implements MogoModulesHandler, private IMogoModuleProvider mMapProvider; private IMogoModuleProvider mAppsListProvider; private String mEnableModuleName = null; + private Runnable mMapLoadedCallback; public MogoModulesManager( MainActivity activity ) { if ( activity == null ) { @@ -63,13 +63,23 @@ public class MogoModulesManager implements MogoModulesHandler, return mActivity.getApplicationContext(); } + @Override + public void onMapLoadedCallback( Runnable callback ) { + mMapLoadedCallback = callback; + } + @Override public List< IMogoModuleProvider > loadCards() { - IMogoModuleProvider demo = load( MogoModulePaths.PATH_MODULE_DEMO ); - IMogoModuleProvider demo2 = load( MogoModulePaths.PATH_MODULE_DEMO2 ); - mCardProviders.put( demo.getModuleName(), demo ); - mCardProviders.put( demo2.getModuleName(), demo2 ); - return new ArrayList<>( mCardProviders.values() ); + final List< String > modulePaths = MogoModulePaths.getModulesPath(); + final ArrayList< IMogoModuleProvider > providers = new ArrayList<>(); + if ( modulePaths != null && !modulePaths.isEmpty() ) { + for ( String modulePath : modulePaths ) { + IMogoModuleProvider provider = load( modulePath ); + providers.add( provider ); + mCardProviders.put( provider.getModuleName(), provider ); + } + } + return providers; } @Override @@ -140,6 +150,12 @@ public class MogoModulesManager implements MogoModulesHandler, @Override public void onMapLoaded() { + + if ( mMapLoadedCallback != null ) { + mMapLoadedCallback.run(); + mMapLoadedCallback = null; + } + if ( mEnableModuleName != null ) { IMogoModuleProvider provider = getModuleProvider( mEnableModuleName ); if ( provider != null && provider.getMapListener() != null ) { @@ -260,12 +276,6 @@ public class MogoModulesManager implements MogoModulesHandler, } } - @Override - public boolean onMarkerClicked( IMogoMarker marker ) { - marker.setAlpha( 0.5f ); - return false; - } - @Override public void destroy() { diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/PlaceholderFragment.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/PlaceholderFragment.java new file mode 100644 index 0000000000..6b2c2b566c --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/PlaceholderFragment.java @@ -0,0 +1,26 @@ +package com.mogo.module.main.cards; + +import android.os.Bundle; + +import androidx.annotation.Nullable; + +import com.mogo.module.main.R; + +/** + * @author congtaowang + * @since 2019-12-31 + *
+ * 描述 + */ +public class PlaceholderFragment extends UnDestroyedViewFragment { + + @Override + protected int getLayoutId() { + return R.layout.module_main_fragement_placeholder; + } + + @Override + public void onCreate( @Nullable Bundle savedInstanceState ) { + super.onCreate( savedInstanceState ); + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/PlaceholderFragmentProvider.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/PlaceholderFragmentProvider.java new file mode 100644 index 0000000000..11b4dcdfd3 --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/PlaceholderFragmentProvider.java @@ -0,0 +1,100 @@ +package com.mogo.module.main.cards; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.mogo.commons.mvp.IView; +import com.mogo.commons.mvp.MvpFragment; +import com.mogo.commons.mvp.Presenter; +import com.mogo.map.listener.IMogoMapListener; +import com.mogo.map.location.IMogoLocationListener; +import com.mogo.map.navi.IMogoNaviListener; +import com.mogo.module.main.R; +import com.mogo.service.module.IMogoModuleLifecycle; +import com.mogo.service.module.IMogoModuleProvider; + +/** + * @author congtaowang + * @since 2019-12-31 + *
+ * 描述 + */ +public class PlaceholderFragmentProvider implements IMogoModuleProvider { + + private Fragment mCopyTarget; + private PlaceholderFragment mUi; + + public void setCopyTarget( Fragment mUICopyTarget ) { + this.mCopyTarget = mUICopyTarget; + } + + public void renderTargetUI() { + if ( mCopyTarget == null ) { + return; + } + final View target = mCopyTarget.getView(); + if ( target == null ) { + return; + } + target.setDrawingCacheEnabled( true ); + Bitmap result = target.getDrawingCache(); + result = target.getDrawingCache() != null ? result.copy( Bitmap.Config.ARGB_8888, false ) : null; + if ( mUi.getView() != null ) { + mUi.getView().setBackgroundDrawable( new BitmapDrawable( result ) ); + } + } + + @Override + public Fragment createFragment( Context context, Bundle data ) { + mUi = new PlaceholderFragment(); + return mUi; + } + + @Override + public View createView( Context context ) { + return null; + } + + @NonNull + @Override + public String getModuleName() { + return "placeholder"; + } + + @Override + public IMogoModuleLifecycle getCardLifecycle() { + return null; + } + + @Override + public IMogoMapListener getMapListener() { + return null; + } + + @Override + public int getType() { + return TYPE_FRAGMENT; + } + + @Override + public IMogoNaviListener getNaviListener() { + return null; + } + + @Override + public IMogoLocationListener getLocationListener() { + return null; + } + + @Override + public void init( Context context ) { + + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/UnDestroyedViewFragment.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/UnDestroyedViewFragment.java new file mode 100644 index 0000000000..29eb86e890 --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/UnDestroyedViewFragment.java @@ -0,0 +1,44 @@ +package com.mogo.module.main.cards; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.mogo.commons.mvp.IView; +import com.mogo.commons.mvp.MvpFragment; +import com.mogo.commons.mvp.Presenter; +import com.mogo.module.main.R; + +/** + * @author congtaowang + * @since 2019-12-31 + *
+ * 描述
+ */
+public abstract class UnDestroyedViewFragment extends MvpFragment< IView, Presenter< IView > > implements IView {
+
+ @Nullable
+ @Override
+ public View onCreateView( @NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState ) {
+ if ( mRootView == null ) {
+ return super.onCreateView( inflater, container, savedInstanceState );
+ }
+ return mRootView;
+ }
+
+ @Override
+ protected void initViews() {
+
+ }
+
+ @NonNull
+ @Override
+ protected Presenter< IView > createPresenter() {
+ return new Presenter< IView >( this ) {
+ };
+ }
+}
diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/VerticalStackTransformer.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/VerticalStackTransformer.java
index 8c894d3a25..9184d7b65b 100644
--- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/VerticalStackTransformer.java
+++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/cards/VerticalStackTransformer.java
@@ -26,12 +26,10 @@ public class VerticalStackTransformer extends VerticalBaseTransformer {
protected void onTransform( View page, float position ) {
if ( position <= 0.0f ) {
page.setAlpha( 1.0f );
- Log.e( "onTransform", "position <= 0.0f ==>" + position );
page.setTranslationY( 0f );
//控制停止滑动切换的时候,只有最上面的一张卡片可以点击
page.setClickable( true );
} else if ( position <= 3.0f ) {
- Log.e( "onTransform", "position <= 3.0f ==>" + position );
float scale = ( float ) ( page.getWidth() - WindowUtils.dip2px( context, spaceBetweenFirAndSecWith * position ) ) / ( float ) ( page.getWidth() );
//控制下面卡片的可见度
page.setAlpha( 1.0f );
diff --git a/modules/mogo-module-main/src/main/res/layout/module_main_fragement_placeholder.xml b/modules/mogo-module-main/src/main/res/layout/module_main_fragement_placeholder.xml
new file mode 100644
index 0000000000..621b82b4f0
--- /dev/null
+++ b/modules/mogo-module-main/src/main/res/layout/module_main_fragement_placeholder.xml
@@ -0,0 +1,8 @@
+
+