opt
This commit is contained in:
@@ -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')
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}",
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.mogo.utils.logger.Logger;
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
@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
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* <p>
|
||||
* 持有服务接口实例
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
* <p>
|
||||
* 描述: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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
@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
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* <p>
|
||||
* 持有服务接口实例
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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 ) {
|
||||
|
||||
4
javadoc.sh
Executable file
4
javadoc.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.mogo.map;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-20
|
||||
@@ -10,6 +12,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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
|
||||
@@ -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
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
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 ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
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 ) {
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#f00">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -68,7 +68,7 @@ public interface IMogoMapService extends IProvider {
|
||||
*/
|
||||
IMogoPoiSearch getPoiSearch( Context context, MogoPoiSearchQuery query );
|
||||
|
||||
/**
|
||||
/**f
|
||||
* 获取导航操作实例
|
||||
*
|
||||
* @param context
|
||||
|
||||
@@ -10,5 +10,6 @@
|
||||
./gradlew :modules:mogo-module-common:clean :modules:mogo-module-common:uploadArchives
|
||||
./gradlew :modules:mogo-module-map:clean :modules:mogo-module-map:uploadArchives
|
||||
./gradlew :demo:demo-module-map:clean :demo:demo-module-map:uploadArchives
|
||||
./gradlew :demo:demo-module-map2:clean :demo:demo-module-map2:uploadArchives
|
||||
./gradlew :modules:mogo-module-apps:clean :modules:mogo-module-apps:uploadArchives
|
||||
./gradlew :modules:mogo-module-main:clean :modules:mogo-module-main:uploadArchives
|
||||
Reference in New Issue
Block a user