opt
This commit is contained in:
@@ -5,14 +5,12 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -29,13 +27,11 @@ import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.map.navi.MogoCongestionInfo;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy;
|
||||
import com.mogo.module.common.map.Scene;
|
||||
import com.mogo.module.service.carinfo.CarStateInfo;
|
||||
import com.mogo.module.service.intent.IntentHandlerFactory;
|
||||
import com.mogo.module.service.marker.MapMarkerManager;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
@@ -59,10 +55,8 @@ import com.mogo.service.module.MogoAction;
|
||||
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -363,7 +357,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
if ( msg.obj instanceof RefreshObject ) {
|
||||
RefreshObject ro = ( ( RefreshObject ) msg.obj );
|
||||
mRefreshModel.refreshData( ro.mLonLat, ro.mRadius, ro.mAmount, ro.mCallback );
|
||||
MapMarkerManager.getInstance().getOnlineCarData( ro.mLonLat );
|
||||
MapMarkerManager.getInstance().getOnlineCarDataByAutoRefreshStrategy( ro.mLonLat );
|
||||
|
||||
Logger.i( TAG, "刷新半径 = %s, 点 = %s, zoomLevel = %s, amount = %s", ro.mRadius, ro.mLonLat, mLastZoomLevel, ro.mAmount );
|
||||
}
|
||||
@@ -724,6 +718,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
delay = mRefreshRemainingTime;
|
||||
}
|
||||
mHandler.sendEmptyMessageDelayed( ServiceConst.MSG_TYPE_REFRESH_DECREASE, delay );
|
||||
MapMarkerManager.getInstance().stopAutoRefresh();
|
||||
Logger.i( TAG, "下次刷新时间:%ss后", mRefreshRemainingTime );
|
||||
}
|
||||
|
||||
|
||||
@@ -74,9 +74,8 @@ class OnlineCarSearchIntentHandler implements IntentHandler {
|
||||
isSameCity = true;
|
||||
case ServiceConst.COMMAND_ZHIDAO_NEARBY_CAR_ONLINE:
|
||||
case ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND_ONLINE:
|
||||
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
|
||||
MarkerServiceHandler.getMapUIController().moveToCenter( target );
|
||||
MapMarkerManager.getInstance().getOnlineCarData(
|
||||
Logger.d( TAG, "搜索附近的好友/在线车辆" );
|
||||
doDataRequest(
|
||||
target,
|
||||
isFocus,
|
||||
isSameCity,
|
||||
@@ -111,9 +110,7 @@ class OnlineCarSearchIntentHandler implements IntentHandler {
|
||||
}
|
||||
|
||||
if ( TextUtils.equals( "附近", keyword ) ) {
|
||||
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
|
||||
MarkerServiceHandler.getMapUIController().moveToCenter( target );
|
||||
MapMarkerManager.getInstance().getOnlineCarData(
|
||||
doDataRequest(
|
||||
target,
|
||||
false,
|
||||
false,
|
||||
@@ -130,9 +127,7 @@ class OnlineCarSearchIntentHandler implements IntentHandler {
|
||||
Logger.e( TAG, "geo 检索位置错误" );
|
||||
return;
|
||||
}
|
||||
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
|
||||
MarkerServiceHandler.getMapUIController().moveToCenter( geocodeResult.getAddresses().get( 0 ).getLatlng() );
|
||||
MapMarkerManager.getInstance().getOnlineCarData(
|
||||
doDataRequest(
|
||||
target,
|
||||
false,
|
||||
false,
|
||||
@@ -164,4 +159,20 @@ class OnlineCarSearchIntentHandler implements IntentHandler {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void doDataRequest( MogoLatLng target,
|
||||
boolean onlyFocus,
|
||||
boolean onlySameCity,
|
||||
int limit,
|
||||
int radius ) {
|
||||
MarkerServiceHandler.getApis().getRefreshStrategyControllerApi().restartAutoRefreshAtTime( 30_000 );
|
||||
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
|
||||
MarkerServiceHandler.getMapUIController().moveToCenter( target );
|
||||
MapMarkerManager.getInstance().getOnlineCarDataByVoiceControl(
|
||||
target,
|
||||
onlyFocus,
|
||||
onlySameCity,
|
||||
limit,
|
||||
radius );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.mogo.module.service.marker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
@@ -16,12 +17,12 @@ import com.mogo.module.common.entity.MarkerExploreWay;
|
||||
import com.mogo.module.common.entity.MarkerLocation;
|
||||
import com.mogo.module.common.entity.MarkerNoveltyInfo;
|
||||
import com.mogo.module.common.entity.MarkerOnlineCar;
|
||||
import com.mogo.module.common.entity.MarkerPoiTypeEnum;
|
||||
import com.mogo.module.common.entity.MarkerResponse;
|
||||
import com.mogo.module.common.entity.MarkerShareMusic;
|
||||
import com.mogo.module.common.entity.MarkerShowEntity;
|
||||
import com.mogo.module.common.utils.CarSeries;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.R;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.module.service.Utils;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
@@ -29,6 +30,7 @@ import com.mogo.module.service.network.RefreshModel;
|
||||
import com.mogo.module.service.utils.ViewUtils;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.module.IMogoBizActionDoneListener;
|
||||
import com.mogo.utils.ResourcesHelper;
|
||||
import com.mogo.utils.ThreadPoolService;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -67,6 +69,8 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
// 平滑移动事件间隔(单位:秒)
|
||||
private static final int SMOOTH_DURATION = 15;
|
||||
|
||||
private Rect mMarkerDisplayBounds;
|
||||
|
||||
private MapMarkerManager() {
|
||||
}
|
||||
|
||||
@@ -272,16 +276,26 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
*
|
||||
* @param onlineCarList
|
||||
*/
|
||||
private void drawOnlineCarMarkers( List< MarkerOnlineCar > onlineCarList, int maxAmount ) {
|
||||
private void drawOnlineCarMarkers( List< MarkerOnlineCar > onlineCarList,
|
||||
int maxAmount,
|
||||
boolean clearOld,
|
||||
boolean showBounds,
|
||||
Rect bound,
|
||||
MogoLatLng centerPoint ) {
|
||||
// 将数据同步给在线车辆,避免每次 perform 的时候去拉取,造成消耗
|
||||
if ( onlineCarList == null || onlineCarList.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( clearOld ) {
|
||||
MarkerServiceHandler.getMarkerManager().removeMarkers( ModuleNames.CARD_TYPE_USER_DATA );
|
||||
}
|
||||
|
||||
int size = getAppropriateSize( maxAmount, onlineCarList );
|
||||
|
||||
Map< String, IMogoMarker > existCarMap = purgeMarkerData( onlineCarList, ModuleNames.CARD_TYPE_USER_DATA );
|
||||
|
||||
List< MogoLatLng > carPoints = new ArrayList<>();
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
MarkerOnlineCar markerOnlineCar = onlineCarList.get( i );
|
||||
MarkerLocation markerLocation = markerOnlineCar.getLocation();
|
||||
@@ -295,6 +309,10 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
markerShowEntity.setIconUrl( markerOnlineCar.getUserInfo().getUserHead() );
|
||||
}
|
||||
|
||||
if ( i <= 5 ) {
|
||||
carPoints.add( new MogoLatLng( markerLocation.getLat(), markerLocation.getLon() ) );
|
||||
}
|
||||
|
||||
String sn = getCarSnFromEntity( markerOnlineCar );
|
||||
IMogoMarker mogoMarker = existCarMap.get( sn );
|
||||
if ( mogoMarker == null ) {
|
||||
@@ -302,6 +320,11 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
}
|
||||
startSmooth( mogoMarker, markerOnlineCar, markerLocation );
|
||||
}
|
||||
|
||||
if ( showBounds && bound != null ) {
|
||||
// 将前6个点显示在固定范围内
|
||||
MarkerServiceHandler.getMapUIController().showBounds( TAG, centerPoint, carPoints, bound, false );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -662,34 +685,58 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
mCarLatLng = new MogoLatLng( lat, lon );
|
||||
}
|
||||
|
||||
public void getOnlineCarData( MogoLatLng latlng ) {
|
||||
getOnlineCarData( latlng, false, false, 50, 2_000 );
|
||||
}
|
||||
|
||||
public void getOnlineCarData( MogoLatLng latLng,
|
||||
boolean onlyFocus,
|
||||
boolean onlySameCity,
|
||||
int limit,
|
||||
int radius ) {
|
||||
public void getOnlineCarDataByAutoRefreshStrategy( MogoLatLng latlng ) {
|
||||
UiThreadHandler.removeCallbacks( runnable );
|
||||
UiThreadHandler.postDelayed( runnable, SMOOTH_DURATION * 1000 );
|
||||
getOnlineCarList( latLng, onlyFocus, onlySameCity, limit, radius );
|
||||
getOnlineCarDataImpl( latlng, false, false, 50, 2_000, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param latLng
|
||||
* @param onlyFocus
|
||||
* @param onlySameCity
|
||||
* @param limit
|
||||
* @param radius
|
||||
*/
|
||||
public void getOnlineCarDataByVoiceControl( MogoLatLng latLng,
|
||||
boolean onlyFocus,
|
||||
boolean onlySameCity,
|
||||
int limit,
|
||||
int radius ) {
|
||||
UiThreadHandler.removeCallbacks( runnable );
|
||||
UiThreadHandler.postDelayed( runnable, SMOOTH_DURATION * 1000 );
|
||||
getOnlineCarDataImpl( latLng, onlyFocus, onlySameCity, limit, radius, true );
|
||||
}
|
||||
|
||||
private Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getOnlineCarList( mCarLatLng, false, false, 2_000, 50 );
|
||||
getOnlineCarDataImpl( mCarLatLng, false, false, 50, 2_000, false );
|
||||
UiThreadHandler.postDelayed( this, SMOOTH_DURATION * 1000 );
|
||||
}
|
||||
};
|
||||
|
||||
private void getOnlineCarList(
|
||||
public void stopAutoRefresh(){
|
||||
UiThreadHandler.removeCallbacks( runnable );
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索在线车辆
|
||||
*
|
||||
* @param latLng 搜索中心点
|
||||
* @param onlyFocus 是否关注
|
||||
* @param onlySameCity 是否是相同城市
|
||||
* @param limit 条数限制
|
||||
* @param radius 搜索半径
|
||||
* @param fitBounds 是否显示在可视范围内
|
||||
*/
|
||||
private void getOnlineCarDataImpl(
|
||||
MogoLatLng latLng,
|
||||
boolean onlyFocus,
|
||||
boolean onlySameCity,
|
||||
int limit,
|
||||
int radius ) {
|
||||
int radius,
|
||||
boolean fitBounds ) {
|
||||
|
||||
if ( latLng == null ) {
|
||||
return;
|
||||
@@ -716,8 +763,17 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
int size = onlineCarList == null ? 0 : onlineCarList.size();
|
||||
trackData( size );
|
||||
|
||||
if ( mMarkerDisplayBounds == null ) {
|
||||
mMarkerDisplayBounds = new Rect(
|
||||
ResourcesHelper.getDimensionPixelSize( AbsMogoApplication.getApp(), R.dimen.module_service_marker_bounds_leftMargin ),
|
||||
ResourcesHelper.getDimensionPixelSize( AbsMogoApplication.getApp(), R.dimen.module_service_marker_bounds_topMargin ),
|
||||
ResourcesHelper.getDimensionPixelSize( AbsMogoApplication.getApp(), R.dimen.module_service_marker_bounds_rightMargin ),
|
||||
ResourcesHelper.getDimensionPixelSize( AbsMogoApplication.getApp(), R.dimen.module_service_marker_bounds_bottomMargin )
|
||||
);
|
||||
}
|
||||
|
||||
runOnTargetThread( () -> {
|
||||
drawOnlineCarMarkers( onlineCarList, Integer.MAX_VALUE );
|
||||
drawOnlineCarMarkers( onlineCarList, Integer.MAX_VALUE, fitBounds, fitBounds, mMarkerDisplayBounds, latLng );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user