优化代码

This commit is contained in:
董宏宇
2020-02-21 23:54:21 +08:00
parent 30edccf509
commit f72ce1e69c
3 changed files with 68 additions and 69 deletions

View File

@@ -15,8 +15,6 @@ public class MarkerShowEntity {
// false - 没选中true - 选中
private boolean isChecked;
// false - 非高亮true - 高亮
private boolean isHighlighted;
// icon 地址,例如:头像,唱片图片,探路缩略,可能为空展示默认图
private String iconUrl;
// 要展示的文本
@@ -36,14 +34,6 @@ public class MarkerShowEntity {
isChecked = checked;
}
public boolean isHighlighted() {
return isHighlighted;
}
public void setHighlighted(boolean highlighted) {
isHighlighted = highlighted;
}
public String getIconUrl() {
return iconUrl;
}
@@ -108,7 +98,6 @@ public class MarkerShowEntity {
public String toString() {
return "MarkerShowEntity{" +
"isChecked=" + isChecked +
", isHighlighted=" + isHighlighted +
", iconUrl='" + iconUrl + '\'' +
", textContent='" + textContent + '\'' +
", markerType='" + markerType + '\'' +

View File

@@ -1,15 +1,11 @@
package com.mogo.module.service.marker;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.BounceInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.TextView;
import com.amap.api.maps.model.animation.Animation;
import com.amap.api.maps.model.animation.ScaleAnimation;
@@ -33,6 +29,7 @@ import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.service.Utils;
import com.mogo.module.service.datamanager.MogoDataHandler;
import com.mogo.module.service.utils.ViewUtils;
import com.mogo.service.cardmanager.IMogoCardChangedListener;
import com.mogo.service.connection.IMogoOnMessageListener;
import com.mogo.utils.logger.Logger;
@@ -126,26 +123,11 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
return false;
}
// 将上次选中 Marker 设置为未选中状态
MarkerShowEntity lastMarkerShowEntity = (MarkerShowEntity) lastMarker.getObject();
Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker lastMarkerShowEntity" + lastMarkerShowEntity);
if (lastMarkerShowEntity != null) {
lastMarkerShowEntity.setChecked(false);
lastMarkerShowEntity.setHighlighted(false);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, lastMarkerShowEntity, lastMarker.getMogoMarkerOptions());
lastMarker.setIcon(fromView(markerView.getView()));
}
closeMarker(lastMarker);
}
// 将当前的Marker设置为选中
MarkerShowEntity markerShowEntity = (MarkerShowEntity) marker.getObject();
Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker markerShowEntity" + markerShowEntity);
if (markerShowEntity != null) {
markerShowEntity.setChecked(true);
markerShowEntity.setHighlighted(true);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, marker.getMogoMarkerOptions());
marker.setIcon(fromView(markerView.getView()));
}
openMarker(marker);
lastMarker = marker;
// 数据统计代码
@@ -197,31 +179,6 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
}
private Bitmap fromView(View view) {
view.setDrawingCacheEnabled(true);
processChildView(view);
view.destroyDrawingCache();
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap bitmap = null;
return (bitmap = view.getDrawingCache()) != null ? bitmap.copy(Bitmap.Config.ARGB_8888, false) : null;
}
private void processChildView(View view) {
if (!(view instanceof ViewGroup)) {
if (view instanceof TextView) {
((TextView) view).setHorizontallyScrolling(false);
}
} else {
for (int var1 = 0; var1 < ((ViewGroup) view).getChildCount(); ++var1) {
processChildView(((ViewGroup) view).getChildAt(var1));
}
}
}
// 对指定类型高亮处理
public synchronized static void highlightedMarker(final String typeTag) {
highlightedMarker(typeTag, false);
@@ -331,22 +288,38 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
// 将上次选中 Marker 设置为未选中状态
if (marker != null) {
Logger.i(TAG, "closeMarkerSelect 将出Marker详情关闭" + marker);
// 将上次选中 Marker 设置为未选中状态
MarkerShowEntity lastMarkerShowEntity = (MarkerShowEntity) marker.getObject();
lastMarkerShowEntity.setChecked(false);
lastMarkerShowEntity.setHighlighted(false);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, lastMarkerShowEntity, marker.getMogoMarkerOptions());
marker.setIcon(fromView(markerView.getView()));
closeMarker(marker);
lastMarker = null;
}
}
/**
* 绘制Marker
*/
// 展开气泡
private void openMarker(IMogoMarker mogoMarker) {
if (mogoMarker != null) {
Object object = mogoMarker.getObject();
if (object != null) {
MarkerShowEntity markerShowEntity = (MarkerShowEntity) object;
markerShowEntity.setChecked(true);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, mogoMarker.getMogoMarkerOptions());
mogoMarker.setIcon(ViewUtils.fromView(markerView.getView()));
}
}
}
// 折叠气泡
private void closeMarker(IMogoMarker mogoMarker) {
if (mogoMarker != null) {
Object object = mogoMarker.getObject();
if (object != null) {
MarkerShowEntity markerShowEntity = (MarkerShowEntity) object;
markerShowEntity.setChecked(false);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, mogoMarker.getMogoMarkerOptions());
mogoMarker.setIcon(ViewUtils.fromView(markerView.getView()));
}
}
}
// 绘制Marker
public synchronized void drawMapMarker(MarkerResponse response) {
lastMarker = null;

View File

@@ -0,0 +1,37 @@
package com.mogo.module.service.utils;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020-02-2123:51
* desc :
* version: 1.0
*/
public class ViewUtils {
public static Bitmap fromView(View view) {
view.setDrawingCacheEnabled(true);
processChildView(view);
view.destroyDrawingCache();
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap bitmap = null;
return (bitmap = view.getDrawingCache()) != null ? bitmap.copy(Bitmap.Config.ARGB_8888, false) : null;
}
public static void processChildView(View view) {
if (!(view instanceof ViewGroup)) {
if (view instanceof TextView) {
((TextView) view).setHorizontallyScrolling(false);
}
} else {
for (int var1 = 0; var1 < ((ViewGroup) view).getChildCount(); ++var1) {
processChildView(((ViewGroup) view).getChildAt(var1));
}
}
}
}