[Fix]修复小地图加载失败问题

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2021-11-15 20:02:20 +08:00
parent 8d29be3ba6
commit 26d92ba5d2
15 changed files with 273 additions and 383 deletions

1
.idea/misc.xml generated
View File

@@ -24,6 +24,7 @@
<entry key="core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_traffic_light_vr.xml" value="0.18996305418719212" />
<entry key="core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_vip_identification.xml" value="0.45" />
<entry key="core/function-impl/mogo-core-function-map/src/main/res/layout/function_map_fragment_hd_map.xml" value="0.29322916666666665" />
<entry key="core/function-impl/mogo-core-function-smp/src/main/res/layout/module_small_map_fragment.xml" value="0.44166666666666665" />
<entry key="core/mogo-core-network/src/main/res/layout/item_v2x_crossroad_live_video.xml" value="0.1984375" />
<entry key="foudations/mogo-commons/src/main/res/layout/module_commons_layout_toast.xml" value="0.3117283950617284" />
<entry key="modules/mogo-module-authorize/src/main/res/layout/module_authorize_fragment.xml" value="0.273046875" />

View File

@@ -17,10 +17,9 @@ import com.mogo.commons.constants.SharedPrefsConstants;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.Utils;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.config.HmiBuildConfig;
import com.mogo.eagle.core.data.constants.MogoServicePaths;
import com.mogo.map.MapApiPath;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.map.MapApiPath;
import com.mogo.module.carchatting.card.CallChatConstant;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.MogoModule;
@@ -239,7 +238,6 @@ public class MogoApplication extends AbsMogoApplication {
}
/**
* TODO 这里定位数据有问题
* 上传自车位置信息到云端
*/
private void uploadLocPerFiveSecond() {
@@ -317,10 +315,7 @@ public class MogoApplication extends AbsMogoApplication {
MogoModulePaths.addModuleFunctionServer(new MogoModule(MogoServicePaths.PATH_V2X_OBU_MOGO, "IMoGoObuProvider"));
// 超视距,路测、行车记录仪监控
MogoModulePaths.addModuleFunctionServer(new MogoModule(MogoServicePaths.PATH_AI_MONITORING, "IMoGoMonitoringProvider"));
// 小地图模块
MogoModulePaths.addModuleFunction(new MogoModule(MogoServicePaths.PATH_SMALL_MAP, "IMogoSmallMapProvider"));
// HMI模块 loadWaringModule
// MogoModulePaths.addModuleFunction(new MogoModule(MogoServicePaths.PATH_HMI, "IMoGoWaringProvider"));
// V2X 模块
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_V2X_MODULE, "V2XProvider"));
@@ -345,7 +340,7 @@ public class MogoApplication extends AbsMogoApplication {
startService(intent);
}
Log.i("timer", "cost " + (System.currentTimeMillis() - start) + "ms");
Log.i(TAG, "App launch timer cost " + (System.currentTimeMillis() - start) + "ms");
}
@Override

View File

@@ -22,7 +22,6 @@ import androidx.annotation.Nullable;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.eagle.core.function.api.base.IMoGoFunctionProvider;
import com.mogo.eagle.core.function.api.map.smp.IMogoSmallMapProvider;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.main.MainActivity;
@@ -124,7 +123,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
super.loadOthersModules();
Logger.d(TAG, "loadOthersModules");
loadOCHModule();
loadSmpModule();
}
/**
@@ -139,15 +137,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
}
}
/**
* 加载小地图模块
*/
private void loadSmpModule() {
IMogoSmallMapProvider smp = ARouter.getInstance().navigation(IMogoSmallMapProvider.class);
if (smp != null) {
smp.init(this, R.id.module_main_id_smp_fragment);
}
}
@Override
protected void onDestroy() {

View File

@@ -30,10 +30,12 @@ import com.amap.api.maps.model.Polyline;
import com.amap.api.maps.model.PolylineOptions;
import com.mogo.cloud.commons.utils.CoordinateUtils;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.api.map.listener.IMoGoMapLocationListener;
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager;
import com.mogo.eagle.core.function.smp.utils.MapAssetStyleUtils;
import com.mogo.eagle.core.function.smp.view.ISmallMapDirectionView;
import com.mogo.eagle.core.widget.RoundLayout;
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.utils.DrivingDirectionUtils;
import com.mogo.utils.logger.Logger;
@@ -49,10 +51,10 @@ import java.util.List;
*/
public class SmallMapDirectionView
extends RelativeLayout
implements IMogoCarLocationChangedListener2, ISmallMapDirectionView {
implements IMoGoMapLocationListener, ISmallMapDirectionView {
//小地图名称
public static final String MODULE_NAME = "SmallMap";
public static final String TAG = "SmallMapDirectionView";
private RoundLayout rlSmallMapBorder;
private TextureMapView mAMapNaviView;
@@ -67,6 +69,7 @@ public class SmallMapDirectionView
private Polyline mPolyline;
private CameraUpdate mCameraUpdate;
private Context mContext;
public SmallMapDirectionView(Context context) {
this(context, null);
}
@@ -85,18 +88,18 @@ public class SmallMapDirectionView
}
private void initView(Context context) {
Logger.d(TAG, "initView");
mContext = context;
View smpView = LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
View smpView = LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
mAMapNaviView = (TextureMapView)smpView.findViewById(R.id.aMapNaviView);
mAMapNaviView = (TextureMapView) smpView.findViewById(R.id.aMapNaviView);
// rlSmallMapBorder = findViewById(R.id.rlSmallMapBorder);
// rlSmallMapBorder.addView(mAMapNaviView);
initAMapView();
// 注册定位监听
SmpServiceManager.getMogoRegisterCenter()
.registerCarLocationChangedListener(MODULE_NAME, this);
CallerMapLocationListenerManager.INSTANCE.addListener(TAG, this);
setOnLongClickListener(view -> {
MogoApisHandler.getInstance().getApis()
@@ -117,9 +120,7 @@ public class SmallMapDirectionView
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
// 注册定位监听
SmpServiceManager.getMogoRegisterCenter()
.unregisterCarLocationChangedListener(MODULE_NAME, this);
CallerMapLocationListenerManager.INSTANCE.removeListener(TAG);
}
private void initAMapView() {
@@ -166,7 +167,7 @@ public class SmallMapDirectionView
mAMap.setOnMapLoadedListener(new AMap.OnMapLoadedListener() {
@Override
public void onMapLoaded() {
mAMapNaviView.getMap().setPointToCenter(mAMapNaviView.getWidth()/2, mAMapNaviView.getHeight()/2);
mAMapNaviView.getMap().setPointToCenter(mAMapNaviView.getWidth() / 2, mAMapNaviView.getHeight() / 2);
}
});
}
@@ -177,10 +178,11 @@ public class SmallMapDirectionView
return true;
}
@Override
public void onCarLocationChanged2(Location latLng) {
//Logger.d(MODULE_NAME, "onCarLocationChanged2 latLng:" + latLng);
LatLng currentLatLng = new LatLng(latLng.getLatitude(), latLng.getLongitude());
public void onLocationChanged(@Nullable MogoLocation location) {
Logger.d(TAG, "onCarLocationChanged2 latLng:" + location);
LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude());
//更新车辆位置
if (mCarMarker != null) {
// mCarMarker.setRotateAngle(360 - latLng.getBearing());
@@ -209,8 +211,8 @@ public class SmallMapDirectionView
endLatLng.latitude, endLatLng.longitude,
currentLatLng.latitude, currentLatLng.longitude
);
Log.d(MODULE_NAME, "calculateDistance=" + calculateDistance);
Log.d(TAG, "calculateDistance=" + calculateDistance);
if (calculateDistance <= 20) {
clearPolyline();
} else {
@@ -220,13 +222,13 @@ public class SmallMapDirectionView
//设置希望展示的地图缩放级别
mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, zoomLevel));
}
CameraPosition cameraPosition = new CameraPosition.Builder().target(mCarMarker.getPosition()).bearing(latLng.getBearing()).tilt(0).zoom(zoomLevel).build();
CameraPosition cameraPosition = new CameraPosition.Builder().target(mCarMarker.getPosition()).bearing(location.getBearing()).tilt(0).zoom(zoomLevel).build();
mAMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
private void removeLoction(Location latLng) {
for (LatLng l: mCoordinatesLatLng){
if (!isPointOnCarFront(latLng,l)){
for (LatLng l : mCoordinatesLatLng) {
if (!isPointOnCarFront(latLng, l)) {
mCoordinatesLatLng.remove(l);
}
}
@@ -250,10 +252,6 @@ public class SmallMapDirectionView
}
}
@Override
public void onCarLocationChanged(MogoLatLng latLng) {
Logger.d(MODULE_NAME, "onCarLocationChanged latLng:" + latLng);
}
@Override
public void drawablePolyline() {
@@ -297,22 +295,23 @@ public class SmallMapDirectionView
}
public LatLng CoordinateConverterFrom84(Context mContext, MogoLatLng mogoLatLng){
public LatLng CoordinateConverterFrom84(Context mContext, MogoLatLng mogoLatLng) {
CoordinateConverter mCoordinateConverter = new CoordinateConverter(mContext);
mCoordinateConverter.from(CoordinateConverter.CoordType.GPS);
mCoordinateConverter.coord(new LatLng(mogoLatLng.lat,mogoLatLng.lon));
LatLng latLng = mCoordinateConverter.convert();
mCoordinateConverter.coord(new LatLng(mogoLatLng.lat, mogoLatLng.lon));
LatLng latLng = mCoordinateConverter.convert();
return latLng;
}
public List<LatLng> CoordinateConverterFrom84ForList(Context mContext, List<MogoLatLng> mogoLatLngList){
List<LatLng> list = new ArrayList<>();
for (MogoLatLng m:mogoLatLngList) {
LatLng mogoLatLng = CoordinateConverterFrom84(mContext,m);
public List<LatLng> CoordinateConverterFrom84ForList(Context mContext, List<MogoLatLng> mogoLatLngList) {
List<LatLng> list = new ArrayList<>();
for (MogoLatLng m : mogoLatLngList) {
LatLng mogoLatLng = CoordinateConverterFrom84(mContext, m);
list.add(mogoLatLng);
}
return list;
}
@Override
public void clearPolyline() {
// mCoordinatesLatLng.clear();
@@ -327,7 +326,7 @@ public class SmallMapDirectionView
}
}
public void resetPolyine(){
public void resetPolyine() {
mCoordinatesLatLng.clear();
if (mPolyline != null) {
mPolyline.remove();
@@ -341,32 +340,33 @@ public class SmallMapDirectionView
}
public void onCreateView(Bundle savedInstanceState) {
if(mAMapNaviView != null){
if (mAMapNaviView != null) {
mAMapNaviView.onCreate(savedInstanceState);
}
}
public void onResume() {
if(mAMapNaviView != null){
if (mAMapNaviView != null) {
mAMapNaviView.onResume();
}
}
public void onPause() {
if(mAMapNaviView != null){
if (mAMapNaviView != null) {
mAMapNaviView.onPause();
}
}
public void onDestroy() {
if(mAMapNaviView != null){
if (mAMapNaviView != null) {
mAMapNaviView.onDestroy();
}
}
public void convert(List<MogoLatLng> coordinates) {
mCoordinatesLatLng.clear();
List<LatLng> latLngs = CoordinateConverterFrom84ForList(mContext,coordinates);
List<LatLng> latLngs = CoordinateConverterFrom84ForList(mContext, coordinates);
mCoordinatesLatLng.addAll(latLngs);
}
}

View File

@@ -2,24 +2,29 @@ package com.mogo.eagle.core.function.smp;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.commons.mvp.BaseFragment;
import com.mogo.eagle.core.data.autopilot.ADASTrajectoryInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotRouteInfo;
import com.mogo.eagle.core.data.constants.MoGoFragmentPaths;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningListener;
import com.mogo.eagle.core.function.api.map.smp.IMogoSmallMapProvider;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager;
import java.util.ArrayList;
import java.util.List;
/**
* @author donghongyu
* @date 2021/5/19 10:50 上午
*/
public class SmallMapFragment extends Fragment {
protected View mRootView;
@Route(path = MoGoFragmentPaths.PATH_FRAGMENT_SMP)
public class SmallMapFragment extends BaseFragment implements IMogoSmallMapProvider, IMoGoAutopilotPlanningListener {
private final String TAG = "SmallMapFragment";
protected SmallMapDirectionView mSmallMapDirectionView;
@Override
@@ -27,22 +32,40 @@ public class SmallMapFragment extends Fragment {
super.onAttach(context);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (mRootView == null) {
mRootView = inflater.inflate(R.layout.module_small_map_fragment, container, false);
mSmallMapDirectionView = mRootView.findViewById(R.id.smallMapDirectionView);
mSmallMapDirectionView.onCreateView(savedInstanceState);
} else {
ViewGroup viewGroup = (ViewGroup) mRootView.getParent();
if (viewGroup != null) {
viewGroup.removeView(mRootView);
}
}
return mRootView;
protected int getLayoutId() {
return R.layout.module_small_map_fragment;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
SmpServiceManager.init(getContext());
}
@Override
protected void initViews(Bundle savedInstanceState) {
super.initViews(savedInstanceState);
mSmallMapDirectionView = mRootView.findViewById(R.id.smallMapDirectionView);
mSmallMapDirectionView.onCreateView(savedInstanceState);
CallerAutopilotPlanningListenerManager.INSTANCE.addListener(TAG, this);
}
@Override
public void showPanel() {
mSmallMapDirectionView.setVisibility(View.VISIBLE);
}
@Override
public void hidePanel() {
mSmallMapDirectionView.setVisibility(View.GONE);
}
@Override
public void drawablePolyline(List<MogoLatLng> coordinates) {
if (mSmallMapDirectionView != null) {
mSmallMapDirectionView.convert(coordinates);
@@ -50,6 +73,7 @@ public class SmallMapFragment extends Fragment {
}
}
@Override
public void clearPolyline() {
if (mSmallMapDirectionView != null) {
mSmallMapDirectionView.clearPolyline();
@@ -73,6 +97,29 @@ public class SmallMapFragment extends Fragment {
public void onDestroy() {
super.onDestroy();
mSmallMapDirectionView.onDestroy();
CallerAutopilotPlanningListenerManager.INSTANCE.removeListener(TAG);
}
@Override
public void onAutopilotTrajectory(ArrayList<ADASTrajectoryInfo> trajectoryInfos) {
}
@Override
public void onAutopilotRotting(AutopilotRouteInfo routeList) {
if (routeList.getModels() == null || routeList.getModels().size() == 0) {
return;
}
List<MogoLatLng> latLngList = new ArrayList<>();
for (AutopilotRouteInfo.RouteModels routeModel : routeList.getModels()) {
latLngList.add(new MogoLatLng(routeModel.getLat(), routeModel.getLon()));
}
Log.e(TAG, "routeResult:" + latLngList.size());
if (latLngList.size() > 0) {
drawablePolyline(latLngList);
} else {
clearPolyline();
}
}
}

View File

@@ -1,176 +0,0 @@
package com.mogo.eagle.core.function.smp;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.eagle.core.data.autopilot.ADASTrajectoryInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotRouteInfo;
import com.mogo.eagle.core.data.constants.MogoServicePaths;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningListener;
import com.mogo.eagle.core.function.api.map.smp.IMogoSmallMapProvider;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.StatusDescriptor;
import java.util.ArrayList;
import java.util.List;
/**
* @author donghongyu
* @date 12/10/20 1:34 PM
*/
@Route(path = MogoServicePaths.PATH_SMALL_MAP)
public class SmallMapProvider implements IMogoSmallMapProvider, IMogoStatusChangedListener, IMoGoAutopilotPlanningListener {
private final String TAG = "SmallMapProvider";
private Context mContext;
private int mContainerId;
private FragmentActivity mActivity;
private SmallMapFragment mSmallMapFragment;
@Override
public void init(FragmentActivity activity, int containerId) {
Log.d(TAG, "小地图模块初始化……init(FragmentActivity activity, int containerId)");
mActivity = activity;
mContainerId = containerId;
SmpServiceManager.init(mActivity);
CallerAutopilotPlanningListenerManager.INSTANCE.addListener(TAG, this);
}
@Override
public void init(Context context) {
Log.d(TAG, "小地图模块初始化……init(Context context)");
mContext = context;
MogoApisHandler.getInstance()
.getApis()
.getStatusManagerApi()
.registerStatusChangedListener(
MogoServicePaths.PATH_SMALL_MAP,
StatusDescriptor.VR_MODE,
this);
MogoApisHandler.getInstance()
.getApis()
.getStatusManagerApi()
.registerStatusChangedListener(
MogoServicePaths.PATH_SMALL_MAP,
StatusDescriptor.MAIN_PAGE_RESUME,
this);
// MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasAutopilotRouteCallBack(this);
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
showPanel();
} else {
hidePanel();
}
}
@Override
public void showPanel() {
Log.d(TAG, "小地图模块触发展示……");
try {
if (mSmallMapFragment == null) {
Log.d(TAG, "准备add fragment======");
mSmallMapFragment = new SmallMapFragment();
mActivity.getSupportFragmentManager().beginTransaction().add(mContainerId, mSmallMapFragment).commitAllowingStateLoss();
return;
}
Log.d(TAG, "准备show fragment");
mActivity.getSupportFragmentManager().beginTransaction().show(mSmallMapFragment).commitAllowingStateLoss();
} catch (Exception e) {
Log.d(TAG, "add fragment 失败 ======" + e.getMessage());
e.printStackTrace();
}
}
@Override
public void hidePanel() {
Log.d(TAG, "小地图模块触发隐藏……");
try {
if (mSmallMapFragment != null) {
Log.d(TAG, "准备hide fragment");
mActivity.getSupportFragmentManager().beginTransaction().hide(mSmallMapFragment).commitAllowingStateLoss();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void drawablePolyline(List<MogoLatLng> coordinates) {
if (mSmallMapFragment != null) {
mSmallMapFragment.drawablePolyline(coordinates);
}
}
@Override
public void clearPolyline() {
if (mSmallMapFragment != null) {
mSmallMapFragment.clearPolyline();
}
}
@Override
public void onStatusChanged(StatusDescriptor descriptor, boolean isTrue) {
Log.d(TAG, "onStatusChanged……descriptor=" + descriptor + "isTrue=" + isTrue);
if (descriptor == StatusDescriptor.VR_MODE) {
if (isTrue) {
showPanel();
} else {
hidePanel();
}
}
}
@Nullable
@Override
public Fragment createCoverage(@Nullable FragmentActivity activity, @Nullable Integer containerId) {
return null;
}
@NonNull
@Override
public String getFunctionName() {
return TAG;
}
@Override
public void onDestroy() {
CallerAutopilotPlanningListenerManager.INSTANCE.removeListener(TAG);
}
@Override
public void onAutopilotTrajectory(ArrayList<ADASTrajectoryInfo> trajectoryInfos) {
}
@Override
public void onAutopilotRotting(AutopilotRouteInfo routeList) {
if (routeList.getModels() == null || routeList.getModels().size() == 0) {
return;
}
List<MogoLatLng> latLngList = new ArrayList<>();
for (AutopilotRouteInfo.RouteModels routeModel : routeList.getModels()) {
latLngList.add(new MogoLatLng(routeModel.getLat(), routeModel.getLon()));
}
Log.e(TAG, "routeResult:" + latLngList.size());
if (latLngList.size() > 0) {
drawablePolyline(latLngList);
} else {
clearPolyline();
}
}
}

View File

@@ -9,17 +9,24 @@ import androidx.annotation.Keep;
public class MoGoFragmentPaths {
/**
* 高精地图Fragment
* 高精地图 Fragment
*/
@Keep
@Deprecated
public static final String PATH_FRAGMENT_MAP = "/hd_map_ui/";
/**
* HMI 业务相关的
* HMI Fragment
*/
@Keep
@Deprecated
public static final String PATH_FRAGMENT_HMI = "/hmi_ui/";
/**
* 小地图 Fragment
*/
@Keep
@Deprecated
public static final String PATH_FRAGMENT_SMP = "/smp_ui/";
}

View File

@@ -1,11 +1,6 @@
package com.mogo.eagle.core.function.api.map.smp;
import androidx.annotation.IdRes;
import androidx.fragment.app.FragmentActivity;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.api.base.IMoGoFunctionProvider;
import java.util.List;
@@ -13,15 +8,7 @@ import java.util.List;
* @author donghongyu
* @date 12/10/20 1:36 PM
*/
public interface IMogoSmallMapProvider extends IMoGoFunctionProvider {
/**
* 初始化网约车容器
*
* @param activity activity
* @param containerId 容器ID
*/
void init(FragmentActivity activity, @IdRes int containerId);
public interface IMogoSmallMapProvider {
/**
* 显示面板

View File

@@ -18,14 +18,22 @@ object CallerMapStyleListenerManager : CallerBase() {
private var mMapStyleMode = 0
// 存储所有注册了监听的对象invokeXXXX进行遍历回调将信息同步
private val mMapStyleChangeListeners: ConcurrentHashMap<String, IMoGoMapStyleChangeListener> = ConcurrentHashMap()
private val mMapStyleChangeListeners: ConcurrentHashMap<String, IMoGoMapStyleChangeListener> =
ConcurrentHashMap()
/**
* 返回当前的地图皮肤
*/
fun getMapStyleMode(): Int {
return mMapStyleMode
}
/**
* 添加 地图样式改变 监听
* @param tag 标记,用来注销监听使用
* @param listener 监听回调
*/
fun addMapStyleChangeListener(
fun addListener(
@Nullable tag: String,
@Nullable listener: IMoGoMapStyleChangeListener
) {
@@ -37,7 +45,7 @@ object CallerMapStyleListenerManager : CallerBase() {
* 删除 地图样式改变 监听
* @param tag 标记,用来注销监听使用
*/
fun removeMapStyleChangeListener(@Nullable tag: String) {
fun removeListener(@Nullable tag: String) {
mMapStyleChangeListeners.remove(tag)
}
@@ -45,7 +53,7 @@ object CallerMapStyleListenerManager : CallerBase() {
* 删除 地图样式改变 监听
* @param listener 要删除的监听对象
*/
fun removeMapStyleChangeListener(@Nullable listener: IMoGoMapStyleChangeListener) {
fun removeListener(@Nullable listener: IMoGoMapStyleChangeListener) {
mMapStyleChangeListeners.forEach {
if (it.value == listener) {
mMapStyleChangeListeners.remove(it.key)
@@ -56,15 +64,15 @@ object CallerMapStyleListenerManager : CallerBase() {
/**
* 触发 地图样式改变 监听
*/
fun invokeMapStyleChangeListener() {
invokeMapStyleChangeListener(mMapStyleMode)
fun invokeMapStyleChange() {
invokeMapStyleChange(mMapStyleMode)
}
/**
* 触发 地图样式改变 监听
* @param mapStyleMode 选中状态
*/
fun invokeMapStyleChangeListener(mapStyleMode: Int) {
fun invokeMapStyleChange(mapStyleMode: Int) {
LogUtils.dTag(TAG, "mapStyleMode:$mapStyleMode")
mMapStyleMode = mapStyleMode
mMapStyleChangeListeners.forEach {

View File

@@ -1,33 +1,34 @@
package com.mogo.eagle.core.function.call.map;
package com.mogo.eagle.core.function.call.map
import com.mogo.eagle.core.data.constants.MogoServicePaths;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.api.map.smp.IMogoSmallMapProvider;
import com.mogo.eagle.core.function.call.base.CallerBase;
import java.util.List;
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.eagle.core.data.constants.MoGoFragmentPaths
import com.mogo.eagle.core.data.map.MogoLatLng
import com.mogo.eagle.core.function.api.map.smp.IMogoSmallMapProvider
import com.mogo.eagle.core.function.call.base.CallerBase
/**
* @author xiaoyuzhou
* @date 2021/9/17 6:15 下午
* 小地图调用者管理这里对外及其他模块提供小地图功能的调用用啥写啥不要过度设计不允许直接将Provider暴露出去
*/
public class CallerSmpManager extends CallerBase {
private static IMogoSmallMapProvider getMogoSmallMapProvider() {
return getApiInstance(IMogoSmallMapProvider.class, MogoServicePaths.PATH_SMALL_MAP);
}
object CallerSmpManager : CallerBase() {
private val mogoSmallMapProvider: IMogoSmallMapProvider
get() = ARouter.getInstance().build(MoGoFragmentPaths.PATH_FRAGMENT_SMP)
.navigation() as IMogoSmallMapProvider
/**
* 绘制路径线
*/
public static void drawablePolyline(List<MogoLatLng> coordinates) {
getMogoSmallMapProvider().drawablePolyline(coordinates);
@JvmStatic
fun drawablePolyline(coordinates: List<MogoLatLng?>?) {
mogoSmallMapProvider.drawablePolyline(coordinates)
}
/**
* 清除路径线
*/
public static void clearPolyline() {
getMogoSmallMapProvider().clearPolyline();
@JvmStatic
fun clearPolyline() {
mogoSmallMapProvider.clearPolyline()
}
}
}

View File

@@ -0,0 +1,105 @@
package com.mogo.commons.mvp;
import android.content.Context;
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 androidx.fragment.app.Fragment;
/**
* 基础Fragment
*/
public abstract class BaseFragment extends Fragment {
private Context mContext;
protected View mRootView;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mContext = context;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (mRootView == null) {
mRootView = inflater.inflate(getLayoutId(), container, false);
} else {
ViewGroup viewGroup = (ViewGroup) mRootView.getParent();
if (viewGroup != null) {
viewGroup.removeView(mRootView);
}
}
return mRootView;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initViews();
initViews(savedInstanceState);
}
/**
* 布局资源
*
* @return
*/
protected abstract int getLayoutId();
/**
* 获取绑定的TAG标记
*
* @return 返回唯一TAG标记
*/
public abstract String getTagName();
/**
* 初始化控件必须在初始化完成之后才可以实例化presenter避免
* presenter 生命周期错乱
*/
protected abstract void initViews();
protected void initViews(Bundle savedInstanceState) {
}
@Nullable
protected <T extends View> T findViewById(int id) {
if (mRootView == null) {
mRootView = getView();
}
if (mRootView != null) {
return (T) mRootView.findViewById(id);
}
return null;
}
@Nullable
@Override
public Context getContext() {
if (mContext == null) {
mContext = super.getContext();
}
return mContext;
}
@Override
public void onDestroyView() {
super.onDestroyView();
mRootView = null;
mContext = null;
}
}

View File

@@ -1,16 +1,9 @@
package com.mogo.commons.mvp;
import android.content.Context;
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 androidx.fragment.app.Fragment;
import com.mogo.utils.logger.Logger;
/**
* @author congtaowang
@@ -18,68 +11,17 @@ import com.mogo.utils.logger.Logger;
* <p>
* mvp fragment
*/
public abstract class MvpFragment<V extends IView, P extends Presenter<V>> extends Fragment implements IView {
public abstract class MvpFragment<V extends IView, P extends Presenter<V>> extends BaseFragment implements IView {
private Context mContext;
protected P mPresenter;
protected View mRootView;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mContext = context;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (mRootView == null) {
mRootView = inflater.inflate(getLayoutId(), container, false);
} else {
ViewGroup viewGroup = (ViewGroup) mRootView.getParent();
if (viewGroup != null) {
viewGroup.removeView(mRootView);
}
}
return mRootView;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
/**
* 布局资源
*
* @return
*/
protected abstract int getLayoutId();
/**
* 获取绑定的TAG标记
* @return 返回唯一TAG标记
*/
public abstract String getTagName();
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initViews();
initViews(savedInstanceState);
mPresenter = createPresenter();
getViewLifecycleOwner().getLifecycle().addObserver(mPresenter);
}
/**
* 初始化控件必须在初始化完成之后才可以实例化presenter避免
* presenter 生命周期错乱
*/
protected abstract void initViews();
protected void initViews(Bundle savedInstanceState) {
}
/**
* 创建 presenter 实例
*
@@ -92,26 +34,6 @@ public abstract class MvpFragment<V extends IView, P extends Presenter<V>> exten
return mPresenter;
}
@Nullable
protected <T extends View> T findViewById(int id) {
if (mRootView == null) {
mRootView = getView();
}
if (mRootView != null) {
return (T) mRootView.findViewById(id);
}
return null;
}
@Nullable
@Override
public Context getContext() {
if (mContext == null) {
mContext = super.getContext();
}
return mContext;
}
@Override
public void onDestroyView() {
super.onDestroyView();
@@ -119,7 +41,5 @@ public abstract class MvpFragment<V extends IView, P extends Presenter<V>> exten
getViewLifecycleOwner().getLifecycle().removeObserver(mPresenter);
}
mPresenter = null;
mRootView = null;
mContext = null;
}
}

View File

@@ -26,6 +26,7 @@ import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.call.map.CallerLocationUpdaterManager;
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapStyleListenerManager;
import com.mogo.eagle.core.utilcode.mogo.toast.TipToast;
import com.mogo.map.IMogoMap;
import com.mogo.map.IMogoMapView;
@@ -963,18 +964,18 @@ public class AMapViewWrapper implements IMogoMapView,
}
@Override
public void onChangeMapStyle(int i) {
public void onChangeMapStyle(int styleId) {
EnumMapUI last = mCurrentUI;
Logger.d(TAG, "currentMapStyle = %s", i);
Logger.d(TAG, "currentMapStyle = %s", styleId);
if (i == MapAutoApi.MAP_STYLE_DAY
|| i == MapAutoApi.MAP_STYLE_DAY_NAV) {
if (styleId == MapAutoApi.MAP_STYLE_DAY
|| styleId == MapAutoApi.MAP_STYLE_DAY_NAV) {
mCurrentUI = EnumMapUI.Type_Light;
} else if (i == MapAutoApi.MAP_STYLE_NIGHT
|| i == MapAutoApi.MAP_STYLE_NIGHT_NAV) {
} else if (styleId == MapAutoApi.MAP_STYLE_NIGHT
|| styleId == MapAutoApi.MAP_STYLE_NIGHT_NAV) {
mCurrentUI = EnumMapUI.Type_Night;
} else if (i == MapAutoApi.MAP_STYLE_VR) {
} else if (styleId == MapAutoApi.MAP_STYLE_VR) {
mCurrentUI = EnumMapUI.Type_VR;
// 进入vr模式的时候自动切换到车头朝上
change2CarUp();
@@ -998,6 +999,7 @@ public class AMapViewWrapper implements IMogoMapView,
try {
Logger.d(TAG, "currentUI = %s", mCurrentUI);
MogoMapListenerHandler.getInstance().onMapModeChanged(mCurrentUI);
CallerMapStyleListenerManager.INSTANCE.invokeMapStyleChange(styleId);
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -20,6 +20,7 @@ import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.context.ContextHolderUtil;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.mvp.BaseFragment;
import com.mogo.commons.mvp.MvpActivity;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.eagle.core.data.constants.MoGoFragmentPaths;
@@ -202,7 +203,7 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
loadOthersModules();
}
}, 1000);
Log.i("timer", "cost " + (System.currentTimeMillis() - start) + "ms");
Log.i(TAG, "App launch timer cost " + (System.currentTimeMillis() - start) + "ms");
});
loadFunctionFragment();
loadFunctionMapView();
@@ -266,7 +267,6 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
}
protected void loadContainerModules() {
//MogoModulesManager.getInstance().loadWaringModule(R.id.module_main_id_waring_fragment);
MogoModulesManager.getInstance().loadEntrancesModule(R.id.module_main_id_entrance_fragment_container);
MogoModulesManager.getInstance().loadEventPanelModule(R.id.module_main_id_event_panel_fragment_container);
}
@@ -280,9 +280,13 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
@Override
public void loadFunctionFragment() {
// 加载 HMI 框架
MvpFragment fragmentHdMap = (MvpFragment) ARouter.getInstance().build(MoGoFragmentPaths.PATH_FRAGMENT_HMI).navigation();
// 加载 HMI 图层
BaseFragment fragmentHdMap = (BaseFragment) ARouter.getInstance().build(MoGoFragmentPaths.PATH_FRAGMENT_HMI).navigation();
addFragment(fragmentHdMap, fragmentHdMap.getTagName(), R.id.module_main_id_waring_fragment);
// 加载 小地图 图层
BaseFragment fragmentSmpMap = (BaseFragment) ARouter.getInstance().build(MoGoFragmentPaths.PATH_FRAGMENT_SMP).navigation();
addFragment(fragmentSmpMap, fragmentSmpMap.getTagName(), R.id.module_main_id_smp_fragment);
}
/**