From 98c9a5a089e6c4f47913ccf1aec8ec7dc74c9a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Fri, 10 Jan 2020 21:39:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E7=9A=84marker=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- .../common/entity/MarkerShowEntity.java | 23 ++++ .../module/service/MarkerServiceHandler.java | 114 +++++++++--------- .../service/marker/MapMarkerAdapter.java | 9 +- .../service/marker/MapMarkerInfoView.java | 63 +++++++++- .../module/service/marker/MapMarkerView.java | 57 +++++++++ .../src/main/res/layout/view_map_marker.xml | 6 +- .../main/res/layout/view_map_marker_info.xml | 2 + 8 files changed, 212 insertions(+), 64 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 8a8f75bfe2..703e5d4b89 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ - + diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MarkerShowEntity.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MarkerShowEntity.java index 72ebf7823e..086d4e7fc4 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MarkerShowEntity.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MarkerShowEntity.java @@ -21,6 +21,9 @@ public class MarkerShowEntity { // 绑定 MarkerView 的数据 private Object bindObj; + //Marker 经纬度位置信息 + private MarkerLocation markerLocation; + public boolean isChecked() { return isChecked; } @@ -61,4 +64,24 @@ public class MarkerShowEntity { public void setBindObj(Object bindObj) { this.bindObj = bindObj; } + + public MarkerLocation getMarkerLocation() { + return markerLocation; + } + + public void setMarkerLocation(MarkerLocation markerLocation) { + this.markerLocation = markerLocation; + } + + @Override + public String toString() { + return "MarkerShowEntity{" + + "isChecked=" + isChecked + + ", iconUrl='" + iconUrl + '\'' + + ", textContent='" + textContent + '\'' + + ", markerType='" + markerType + '\'' + + ", bindObj=" + bindObj + + ", markerLocation=" + markerLocation + + '}'; + } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MarkerServiceHandler.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MarkerServiceHandler.java index 9bd21058cb..f160f2debc 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MarkerServiceHandler.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MarkerServiceHandler.java @@ -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; } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerAdapter.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerAdapter.java index fefd8712c0..de17e62502 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerAdapter.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerAdapter.java @@ -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; } } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerInfoView.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerInfoView.java index 49ae295243..7b8a2daae4 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerInfoView.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerInfoView.java @@ -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(); + } } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerView.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerView.java index 129284a85b..da4c33cdcb 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerView.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerView.java @@ -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(); + } + } } \ No newline at end of file diff --git a/modules/mogo-module-service/src/main/res/layout/view_map_marker.xml b/modules/mogo-module-service/src/main/res/layout/view_map_marker.xml index 78cc7c93b1..45ce46a8a8 100644 --- a/modules/mogo-module-service/src/main/res/layout/view_map_marker.xml +++ b/modules/mogo-module-service/src/main/res/layout/view_map_marker.xml @@ -29,7 +29,7 @@ app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + tools:visibility="visible" /> \ No newline at end of file diff --git a/modules/mogo-module-service/src/main/res/layout/view_map_marker_info.xml b/modules/mogo-module-service/src/main/res/layout/view_map_marker_info.xml index 2f940f1122..c61305a92b 100644 --- a/modules/mogo-module-service/src/main/res/layout/view_map_marker_info.xml +++ b/modules/mogo-module-service/src/main/res/layout/view_map_marker_info.xml @@ -44,6 +44,8 @@ android:id="@+id/ivIconForeground" android:layout_width="@dimen/dp_56" android:layout_height="@dimen/dp_56" + android:visibility="gone" + tools:visibility="visible" android:layout_gravity="center" android:layout_marginTop="@dimen/dp_6" android:src="@drawable/icon_map_marker_music_play"