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/MarkerLocation.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MarkerLocation.java index 466becae24..38715c15aa 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MarkerLocation.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MarkerLocation.java @@ -8,7 +8,7 @@ import java.io.Serializable; public class MarkerLocation implements Serializable { private String address; - private Double angle; + private float angle; private Double lat; private Double lon; @@ -20,11 +20,11 @@ public class MarkerLocation implements Serializable { this.address = address; } - public Double getAngle() { + public float getAngle() { return angle; } - public void setAngle(Double angle) { + public void setAngle(float angle) { this.angle = angle; } 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 086d4e7fc4..1572906b37 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 @@ -1,5 +1,7 @@ package com.mogo.module.common.entity; +import java.util.Objects; + /** * author : donghongyu * e-mail : 1358506549@qq.com @@ -73,6 +75,19 @@ public class MarkerShowEntity { this.markerLocation = markerLocation; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MarkerShowEntity that = (MarkerShowEntity) o; + return bindObj.equals(that.bindObj); + } + + @Override + public int hashCode() { + return Objects.hash(bindObj); + } + @Override public String toString() { return "MarkerShowEntity{" + 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 f160f2debc..f26baef41e 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 @@ -19,7 +19,6 @@ 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.service.marker.MapMarkerAdapter; -import com.mogo.module.service.marker.MapMarkerView; import com.mogo.service.MogoServicePaths; import com.mogo.service.connection.IMogoOnMessageListener; import com.mogo.service.connection.IMogoSocketManager; @@ -29,7 +28,6 @@ import com.mogo.service.statusmanager.IMogoStatusManager; import com.mogo.utils.logger.Logger; import java.util.List; -import java.util.Random; /** * author : donghongyu @@ -122,19 +120,31 @@ public class MarkerServiceHandler { @Override public boolean onMarkerClicked(IMogoMarker marker) { - Logger.e(TAG, "点击了大而全中的Marker"); + Logger.e(TAG, "onMarkerClicked 点击了大而全中的Marker:" + marker); if (lastMarker != null) { - // 设置未选中状态 - MarkerShowEntity markerShowEntity = (MarkerShowEntity) marker.getObject(); - markerShowEntity.setChecked(false); - drawMapMarker(markerShowEntity); + // 判断点击的是否是同一个 + if (marker.equals(lastMarker)) { + Logger.w(TAG, "onMarkerClicked 与上一次点击的Marker一样,不做处理:" + marker); + return false; + } + + // 将上次选中 Marker 设置为未选中状态 + MarkerShowEntity lastMarkerShowEntity = (MarkerShowEntity) lastMarker.getObject(); + + Logger.e(TAG, "onMarkerClicked 点击了大而全中的Marker lastMarkerShowEntity:" + lastMarkerShowEntity); + + lastMarkerShowEntity.setChecked(false); + drawMapMarker(lastMarkerShowEntity); lastMarker.destroy(); } - // 绘制选中的状态 + // 将当前的Marker设置为选中 MarkerShowEntity markerShowEntity = (MarkerShowEntity) marker.getObject(); + Logger.e(TAG, "onMarkerClicked 点击了大而全中的Marker markerShowEntity:" + markerShowEntity); + markerShowEntity.setChecked(true); + lastMarker = drawMapMarker(markerShowEntity); marker.destroy(); @@ -245,19 +255,19 @@ public class MarkerServiceHandler { //TODO 这里是用来测试的 public static void drawMapMarker() { - Logger.e(TAG, "=====绘制Marker===="); - - MapMarkerView mapMarkerView = new MapMarkerView(mContext); - - MogoMarkerOptions options = new MogoMarkerOptions() - .icon(mapMarkerView) - .owner("CARD_TYPE_USER_DATA") - .latitude(39.574525d + new Random().nextDouble()) - .longitude(116.21733d + new Random().nextDouble()); - IMogoMarker marker = getMarkerManager().addMarker("CARD_TYPE_USER_DATA", options); - marker.setOnMarkerClickListener(mogoMarkerClickListener); - marker.setObject("我是Marker上面绑定的数据"); - - getMapUIController().changeZoom(8); +// Logger.e(TAG, "=====绘制Marker===="); +// +// MapMarkerView mapMarkerView = new MapMarkerView(mContext); +// +// MogoMarkerOptions options = new MogoMarkerOptions() +// .icon(mapMarkerView) +// .owner("CARD_TYPE_USER_DATA") +// .latitude(39.574525d + new Random().nextDouble()) +// .longitude(116.21733d + new Random().nextDouble()); +// IMogoMarker marker = getMarkerManager().addMarker("CARD_TYPE_USER_DATA", options); +// marker.setOnMarkerClickListener(mogoMarkerClickListener); +// marker.setObject("我是Marker上面绑定的数据"); +// +// getMapUIController().changeZoom(8); } } 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 de17e62502..8c2fe8d16b 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 @@ -23,13 +23,9 @@ public class MapMarkerAdapter { */ public static View getMarkerView(Context context, MarkerShowEntity markerShowEntity) { if (markerShowEntity.isChecked()) { - MapMarkerInfoView mapMarkerInfoView = new MapMarkerInfoView(context); - mapMarkerInfoView.updateView(markerShowEntity); - return mapMarkerInfoView; + return new MapMarkerInfoView(context, markerShowEntity); } else { - MapMarkerView mapMarkerView = new MapMarkerView(context); - mapMarkerView.updateView(markerShowEntity); - return mapMarkerView; + return new MapMarkerView(context, markerShowEntity); } } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerBaseView.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerBaseView.java new file mode 100644 index 0000000000..04127ff0f4 --- /dev/null +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerBaseView.java @@ -0,0 +1,83 @@ +package com.mogo.module.service.marker; + +import android.content.Context; +import android.graphics.Bitmap; +import android.text.TextUtils; +import android.util.AttributeSet; +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.service.imageloader.IMogoImageLoaderListener; +import com.mogo.service.imageloader.MogoImageView; +import com.mogo.utils.WindowUtils; +import com.mogo.utils.logger.Logger; + +/** + * author : donghongyu + * e-mail : 1358506549@qq.com + * date : 2020-01-1310:55 + * desc : 地图上抽离的Marker的共性 + * version: 1.0 + */ +public abstract class MapMarkerBaseView extends ConstraintLayout { + private String TAG = "MapMarkerBaseView"; + + protected Context mContext; + + protected MogoImageView ivUserHead; + protected ImageView ivIconForeground; + protected ImageView ivCar; + + public MapMarkerBaseView(Context context) { + super(context); + mContext = context; + initView(context); + } + + public MapMarkerBaseView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + mContext = context; + initView(context); + } + + public MapMarkerBaseView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + mContext = context; + initView(context); + } + + protected abstract void initView(Context context); + + public abstract void updateView(MarkerShowEntity markerShowEntity); + + protected void loadImageWithMarker(MarkerShowEntity markerShowEntity) { + if (!TextUtils.isEmpty(markerShowEntity.getIconUrl())) { + 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) { + + } + }); + } + } +} 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 7b8a2daae4..ab29d5ce6d 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,24 +1,17 @@ package com.mogo.module.service.marker; import android.content.Context; -import android.graphics.Bitmap; +import android.text.TextUtils; 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 @@ -27,35 +20,33 @@ import com.mogo.utils.logger.Logger; * desc : 地图Marker图标带文本信息 * version: 1.0 */ -public class MapMarkerInfoView extends ConstraintLayout { +public class MapMarkerInfoView extends MapMarkerBaseView { private String TAG = "MapMarkerInfoView"; - private Context mContext; - - private MogoImageView ivUserHead; - private ImageView ivIconForeground; private TextView tvMarkerContent; public MapMarkerInfoView(Context context) { super(context); - initView(context); } public MapMarkerInfoView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); - initView(context); } public MapMarkerInfoView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - initView(context); } - private void initView(Context context) { - mContext = context; + public MapMarkerInfoView(Context context, MarkerShowEntity markerShowEntity) { + super(context); + updateView(markerShowEntity); + } + + protected void initView(Context context) { LayoutInflater.from(context).inflate(R.layout.view_map_marker_info, this); ivUserHead = findViewById(R.id.ivUserHead); ivIconForeground = findViewById(R.id.ivIconForeground); + ivCar = findViewById(R.id.ivCar); tvMarkerContent = findViewById(R.id.tvMarkerContent); } @@ -75,27 +66,13 @@ public class MapMarkerInfoView extends ConstraintLayout { 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() { - } + ivCar.setRotation(markerShowEntity.getMarkerLocation().getAngle()); + if (!TextUtils.isEmpty(markerShowEntity.getTextContent())) { + tvMarkerContent.setText(markerShowEntity.getTextContent()); + } + loadImageWithMarker(markerShowEntity); - @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 da4c33cdcb..39230dae48 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,23 +1,15 @@ 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 @@ -26,35 +18,33 @@ import com.mogo.utils.logger.Logger; * desc : 地图Marker图标 * version: 1.0 */ -public class MapMarkerView extends ConstraintLayout { +public class MapMarkerView extends MapMarkerBaseView { private String TAG = "MapMarkerView"; - private Context mContext; - - private MogoImageView ivUserHead; - private ImageView ivIconForeground; - public MapMarkerView(Context context) { super(context); - initView(context); } public MapMarkerView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); - initView(context); } public MapMarkerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - initView(context); } + public MapMarkerView(Context context, MarkerShowEntity markerShowEntity) { + super(context); + updateView(markerShowEntity); + } + + protected void initView(Context context) { + setBackground(null); - 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); + ivCar = findViewById(R.id.ivCar); } public void updateView(MarkerShowEntity markerShowEntity) { @@ -73,28 +63,14 @@ public class MapMarkerView extends ConstraintLayout { 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() { + ivCar.setRotation(markerShowEntity.getMarkerLocation().getAngle()); - } + loadImageWithMarker(markerShowEntity); - @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/drawable-xhdpi/icon_map_marker_listen.png b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_listen.png index a2b097eb26..f846dcefc3 100644 Binary files a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_listen.png and b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_listen.png differ diff --git a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_misic.png b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_misic.png index eac62954aa..b0dc73d75a 100644 Binary files a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_misic.png and b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_misic.png differ diff --git a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_news.png b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_news.png index a832ba97e2..26edaa7f7a 100644 Binary files a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_news.png and b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_news.png differ diff --git a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_refuel.png b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_refuel.png new file mode 100644 index 0000000000..bac7ee2e40 Binary files /dev/null and b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_refuel.png differ diff --git a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_block_off.png b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_block_off.png new file mode 100644 index 0000000000..8c6b30842b Binary files /dev/null and b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_block_off.png differ diff --git a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_block_up.png b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_block_up.png new file mode 100644 index 0000000000..cbe3fe5b66 Binary files /dev/null and b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_block_up.png differ diff --git a/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_check.png b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_check.png new file mode 100644 index 0000000000..1a86fe5896 Binary files /dev/null and b/modules/mogo-module-service/src/main/res/drawable-xhdpi/icon_map_marker_road_check.png differ diff --git a/modules/mogo-module-service/src/main/res/drawable/bg_map_marker_orange_info.xml b/modules/mogo-module-service/src/main/res/drawable/bg_map_marker_orange_info.xml new file mode 100644 index 0000000000..2ba73d956c --- /dev/null +++ b/modules/mogo-module-service/src/main/res/drawable/bg_map_marker_orange_info.xml @@ -0,0 +1,15 @@ + + + + + + + + \ 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 45ce46a8a8..eabc960031 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 @@ -11,7 +11,6 @@ android:id="@+id/ivCar" android:layout_width="@dimen/dp_34" android:layout_height="@dimen/dp_64" - android:rotation="270" android:src="@drawable/icon_map_marker_car_blue" android:translationY="-5dp" app:layout_constraintEnd_toEndOf="@+id/ivBg" 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 c61305a92b..a2d3e6ad2a 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 @@ -12,7 +12,6 @@ android:id="@+id/ivCar" android:layout_width="@dimen/dp_34" android:layout_height="@dimen/dp_64" - android:rotation="270" android:src="@drawable/icon_map_marker_car_blue" android:translationY="-5dp" app:layout_constraintEnd_toEndOf="@+id/ivReverseTriangle" @@ -23,7 +22,7 @@ android:id="@+id/llMarkerContent" android:layout_width="wrap_content" android:layout_height="@dimen/dp_74" - android:background="@drawable/bg_map_marker_blue_info" + android:background="@drawable/bg_map_marker_green_info" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" > @@ -44,13 +43,13 @@ 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" + android:visibility="gone" app:layout_constraintStart_toStartOf="@+id/ivUserHead" - app:layout_constraintTop_toTopOf="@+id/ivUserHead" /> + app:layout_constraintTop_toTopOf="@+id/ivUserHead" + tools:visibility="visible" /> + app:layout_constraintTop_toTopOf="@+id/ivUserHead" + tools:text="诗一样的女子" /> @@ -72,7 +71,7 @@ android:id="@+id/ivReverseTriangle" android:layout_width="10dp" android:layout_height="10dp" - android:src="@drawable/bg_shape_reverse_triangle_blue" + android:src="@drawable/bg_shape_reverse_triangle_green" app:layout_constraintEnd_toEndOf="@+id/llMarkerContent" app:layout_constraintStart_toStartOf="@+id/llMarkerContent" app:layout_constraintTop_toBottomOf="@+id/llMarkerContent" />