完成了根据不同的marker类型的数据加载
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.mogo.module.service;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
@@ -16,7 +17,8 @@ import com.mogo.module.common.entity.MarkerLocation;
|
||||
import com.mogo.module.common.entity.MarkerOnlineCar;
|
||||
import com.mogo.module.common.entity.MarkerResponse;
|
||||
import com.mogo.module.common.entity.MarkerShareMusic;
|
||||
import com.mogo.module.service.marker.MapMarkerInfoView;
|
||||
import com.mogo.module.common.entity.MarkerShowEntity;
|
||||
import com.mogo.module.service.marker.MapMarkerAdapter;
|
||||
import com.mogo.module.service.marker.MapMarkerView;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
@@ -122,36 +124,19 @@ public class MarkerServiceHandler {
|
||||
public boolean onMarkerClicked(IMogoMarker marker) {
|
||||
Logger.e(TAG, "点击了大而全中的Marker");
|
||||
if (lastMarker != null) {
|
||||
// 重置为默认状态
|
||||
MapMarkerView mapMarkerView = new MapMarkerView(mContext);
|
||||
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.icon(mapMarkerView)
|
||||
.owner(lastMarker.getOwner())
|
||||
.latitude(lastMarker.getPosition().getLat())
|
||||
.longitude(lastMarker.getPosition().getLng());
|
||||
|
||||
IMogoMarker newMarker = getMarkerManager().addMarker(lastMarker.getOwner(), options);
|
||||
newMarker.setOnMarkerClickListener(mogoMarkerClickListener);
|
||||
newMarker.setObject(lastMarker.getObject());
|
||||
// 设置未选中状态
|
||||
MarkerShowEntity markerShowEntity = (MarkerShowEntity) marker.getObject();
|
||||
markerShowEntity.setChecked(false);
|
||||
drawMapMarker(markerShowEntity);
|
||||
|
||||
lastMarker.destroy();
|
||||
}
|
||||
|
||||
|
||||
// 绘制选中的状态
|
||||
MapMarkerInfoView mapMarkerInfoView = new MapMarkerInfoView(mContext);
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.icon(mapMarkerInfoView)
|
||||
.owner(marker.getOwner())
|
||||
.latitude(marker.getPosition().getLat())
|
||||
.longitude(marker.getPosition().getLng());
|
||||
MarkerShowEntity markerShowEntity = (MarkerShowEntity) marker.getObject();
|
||||
markerShowEntity.setChecked(true);
|
||||
lastMarker = drawMapMarker(markerShowEntity);
|
||||
|
||||
IMogoMarker newMarker = getMarkerManager().addMarker(marker.getOwner(), options);
|
||||
newMarker.setOnMarkerClickListener(mogoMarkerClickListener);
|
||||
newMarker.setObject(marker.getObject());
|
||||
|
||||
lastMarker = newMarker;
|
||||
marker.destroy();
|
||||
return false;
|
||||
}
|
||||
@@ -176,40 +161,60 @@ public class MarkerServiceHandler {
|
||||
if (carChat != null) {
|
||||
for (MarkerCarChat markerCarChat : carChat) {
|
||||
MarkerLocation markerLocation = markerCarChat.getLocation();
|
||||
drawMapMarker(
|
||||
markerCarChat.getType(),
|
||||
markerCarChat,
|
||||
markerLocation);
|
||||
|
||||
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
|
||||
markerShowEntity.setBindObj(markerCarChat);
|
||||
markerShowEntity.setMarkerLocation(markerLocation);
|
||||
markerShowEntity.setMarkerType(markerCarChat.getType());
|
||||
markerShowEntity.setTextContent(markerCarChat.getUserInfo().getUserName());
|
||||
markerShowEntity.setIconUrl(markerCarChat.getUserInfo().getUserHead());
|
||||
|
||||
drawMapMarker(markerShowEntity);
|
||||
}
|
||||
}
|
||||
|
||||
if (onlineCar != null) {
|
||||
for (MarkerOnlineCar markerOnlineCar : onlineCar) {
|
||||
MarkerLocation markerLocation = markerOnlineCar.getLocation();
|
||||
drawMapMarker(
|
||||
markerOnlineCar.getType(),
|
||||
markerOnlineCar,
|
||||
markerLocation);
|
||||
|
||||
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
|
||||
markerShowEntity.setBindObj(markerOnlineCar);
|
||||
markerShowEntity.setMarkerLocation(markerLocation);
|
||||
markerShowEntity.setMarkerType(markerOnlineCar.getType());
|
||||
markerShowEntity.setTextContent(markerOnlineCar.getUserInfo().getUserName());
|
||||
markerShowEntity.setIconUrl(markerOnlineCar.getUserInfo().getUserHead());
|
||||
|
||||
drawMapMarker(markerShowEntity);
|
||||
}
|
||||
}
|
||||
|
||||
if (exploreWay != null) {
|
||||
for (MarkerExploreWay markerExploreWay : exploreWay) {
|
||||
MarkerLocation markerLocation = markerExploreWay.getLocation();
|
||||
drawMapMarker(
|
||||
markerExploreWay.getType(),
|
||||
markerExploreWay,
|
||||
markerLocation);
|
||||
|
||||
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
|
||||
markerShowEntity.setBindObj(markerExploreWay);
|
||||
markerShowEntity.setMarkerLocation(markerLocation);
|
||||
markerShowEntity.setMarkerType(markerExploreWay.getType());
|
||||
markerShowEntity.setTextContent(markerExploreWay.getUserInfo().getUserName());
|
||||
markerShowEntity.setIconUrl(markerExploreWay.getUserInfo().getUserHead());
|
||||
|
||||
drawMapMarker(markerShowEntity);
|
||||
}
|
||||
}
|
||||
|
||||
if (shareMusic != null) {
|
||||
for (MarkerShareMusic markerShareMusic : shareMusic) {
|
||||
MarkerLocation markerLocation = markerShareMusic.getLocation();
|
||||
drawMapMarker(
|
||||
markerShareMusic.getType(),
|
||||
markerShareMusic,
|
||||
markerLocation);
|
||||
|
||||
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
|
||||
markerShowEntity.setBindObj(markerShareMusic);
|
||||
markerShowEntity.setMarkerLocation(markerLocation);
|
||||
markerShowEntity.setMarkerType(markerShareMusic.getType());
|
||||
markerShowEntity.setTextContent(markerShareMusic.getMediaName());
|
||||
markerShowEntity.setIconUrl(markerShareMusic.getMediaImg());
|
||||
|
||||
drawMapMarker(markerShowEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,27 +224,22 @@ public class MarkerServiceHandler {
|
||||
|
||||
/**
|
||||
* 绘制Marker
|
||||
*
|
||||
* @param markerTag Marker类型
|
||||
* http://gitlab.zhidaoauto.com/ecos/yycp-service/CarLauncher-Docs/blob/master/%E5%8D%A1%E7%89%87%E7%B1%BB%E5%9E%8B%E5%AE%9A%E4%B9%89.md
|
||||
* @param bindObject 绑定的对应的数据
|
||||
* @param markerLocation 要绘制Marker的位置信息
|
||||
*/
|
||||
public static void drawMapMarker(String markerTag,
|
||||
Object bindObject,
|
||||
MarkerLocation markerLocation) {
|
||||
Logger.e(TAG, "绘制Marker====markerTag:" + markerTag);
|
||||
MapMarkerView mapMarkerView = new MapMarkerView(mContext);
|
||||
public static IMogoMarker drawMapMarker(MarkerShowEntity markerShowEntity) {
|
||||
Logger.e(TAG, "绘制Marker====markerTag:" + markerShowEntity);
|
||||
View markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity);
|
||||
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.owner(markerTag)
|
||||
.latitude(markerLocation.getLat())
|
||||
.longitude(markerLocation.getLon());
|
||||
options.icon(mapMarkerView);
|
||||
.owner(markerShowEntity.getMarkerType())
|
||||
.latitude(markerShowEntity.getMarkerLocation().getLat())
|
||||
.longitude(markerShowEntity.getMarkerLocation().getLon());
|
||||
options.icon(markerView);
|
||||
|
||||
IMogoMarker marker = getMarkerManager().addMarker(markerTag, options);
|
||||
IMogoMarker marker = getMarkerManager().addMarker(markerShowEntity.getMarkerType(), options);
|
||||
marker.setOnMarkerClickListener(mogoMarkerClickListener);
|
||||
marker.setObject(bindObject);
|
||||
marker.setObject(markerShowEntity);
|
||||
|
||||
return marker;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,11 +22,14 @@ public class MapMarkerAdapter {
|
||||
* @return MarkerView
|
||||
*/
|
||||
public static View getMarkerView(Context context, MarkerShowEntity markerShowEntity) {
|
||||
|
||||
if (markerShowEntity.isChecked()) {
|
||||
return new MapMarkerView(context);
|
||||
MapMarkerInfoView mapMarkerInfoView = new MapMarkerInfoView(context);
|
||||
mapMarkerInfoView.updateView(markerShowEntity);
|
||||
return mapMarkerInfoView;
|
||||
} else {
|
||||
return new MapMarkerInfoView(context);
|
||||
MapMarkerView mapMarkerView = new MapMarkerView(context);
|
||||
mapMarkerView.updateView(markerShowEntity);
|
||||
return mapMarkerView;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
package com.mogo.module.service.marker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.mogo.module.common.entity.MarkerShowEntity;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.R;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.service.imageloader.IMogoImageLoaderListener;
|
||||
import com.mogo.service.imageloader.MogoImageView;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* author : donghongyu
|
||||
@@ -17,8 +28,14 @@ import com.mogo.module.service.R;
|
||||
* version: 1.0
|
||||
*/
|
||||
public class MapMarkerInfoView extends ConstraintLayout {
|
||||
private String TAG = "MapMarkerInfoView";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private MogoImageView ivUserHead;
|
||||
private ImageView ivIconForeground;
|
||||
private TextView tvMarkerContent;
|
||||
|
||||
public MapMarkerInfoView(Context context) {
|
||||
super(context);
|
||||
initView(context);
|
||||
@@ -34,10 +51,54 @@ public class MapMarkerInfoView extends ConstraintLayout {
|
||||
initView(context);
|
||||
}
|
||||
|
||||
|
||||
private void initView(Context context) {
|
||||
mContext = context;
|
||||
LayoutInflater.from(context).inflate(R.layout.view_map_marker_info, this);
|
||||
ivUserHead = findViewById(R.id.ivUserHead);
|
||||
ivIconForeground = findViewById(R.id.ivIconForeground);
|
||||
tvMarkerContent = findViewById(R.id.tvMarkerContent);
|
||||
}
|
||||
|
||||
public void updateView(MarkerShowEntity markerShowEntity) {
|
||||
try {
|
||||
switch (markerShowEntity.getMarkerType()) {
|
||||
case ServiceConst
|
||||
.CARD_TYPE_CARS_CHATTING:
|
||||
case ServiceConst
|
||||
.CARD_TYPE_USER_DATA:
|
||||
ivIconForeground.setVisibility(View.GONE);
|
||||
break;
|
||||
case ServiceConst
|
||||
.CARD_TYPE_ROAD_CONDITION:
|
||||
case ServiceConst
|
||||
.CARD_TYPE_SHARE_MUSIC:
|
||||
ivIconForeground.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
tvMarkerContent.setText(markerShowEntity.getTextContent());
|
||||
MarkerServiceHandler
|
||||
.getImageloader()
|
||||
.displayImage(markerShowEntity.getIconUrl(), ivUserHead, WindowUtils.dip2px(mContext, 50), WindowUtils.dip2px(mContext, 50),
|
||||
new IMogoImageLoaderListener() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(Bitmap bitmap) {
|
||||
// 刷新图标
|
||||
Logger.d(TAG, "loaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
package com.mogo.module.service.marker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.mogo.module.common.entity.MarkerShowEntity;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.R;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
import com.mogo.service.imageloader.IMogoImageLoaderListener;
|
||||
import com.mogo.service.imageloader.MogoImageView;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* author : donghongyu
|
||||
@@ -17,8 +27,13 @@ import com.mogo.module.service.R;
|
||||
* version: 1.0
|
||||
*/
|
||||
public class MapMarkerView extends ConstraintLayout {
|
||||
private String TAG = "MapMarkerView";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private MogoImageView ivUserHead;
|
||||
private ImageView ivIconForeground;
|
||||
|
||||
public MapMarkerView(Context context) {
|
||||
super(context);
|
||||
initView(context);
|
||||
@@ -38,6 +53,48 @@ public class MapMarkerView extends ConstraintLayout {
|
||||
private void initView(Context context) {
|
||||
mContext = context;
|
||||
LayoutInflater.from(context).inflate(R.layout.view_map_marker, this);
|
||||
ivUserHead = findViewById(R.id.ivUserHead);
|
||||
ivIconForeground = findViewById(R.id.ivIconForeground);
|
||||
}
|
||||
|
||||
public void updateView(MarkerShowEntity markerShowEntity) {
|
||||
try {
|
||||
switch (markerShowEntity.getMarkerType()) {
|
||||
case ServiceConst
|
||||
.CARD_TYPE_CARS_CHATTING:
|
||||
case ServiceConst
|
||||
.CARD_TYPE_USER_DATA:
|
||||
ivIconForeground.setVisibility(View.GONE);
|
||||
break;
|
||||
case ServiceConst
|
||||
.CARD_TYPE_ROAD_CONDITION:
|
||||
case ServiceConst
|
||||
.CARD_TYPE_SHARE_MUSIC:
|
||||
ivIconForeground.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
MarkerServiceHandler
|
||||
.getImageloader()
|
||||
.displayImage(markerShowEntity.getIconUrl(), ivUserHead, WindowUtils.dip2px(mContext, 50), WindowUtils.dip2px(mContext, 50),
|
||||
new IMogoImageLoaderListener() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(Bitmap bitmap) {
|
||||
// 刷新图标
|
||||
Logger.d(TAG, "loaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user