bugfix: UI-253
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.mogo.module.service.marker;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-02-15
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public interface IMarkerView {
|
||||
|
||||
View getView();
|
||||
|
||||
void setMarker( IMogoMarker marker );
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class MapMarkerAdapter {
|
||||
* @param markerShowEntity 要填充的数据
|
||||
* @return MarkerView
|
||||
*/
|
||||
public static View getMarkerView(Context context, MarkerShowEntity markerShowEntity, MogoMarkerOptions options) {
|
||||
public static IMarkerView getMarkerView(Context context, MarkerShowEntity markerShowEntity, MogoMarkerOptions options) {
|
||||
if (markerShowEntity.isChecked()) {
|
||||
return new MapMarkerInfoView(context, markerShowEntity, options);
|
||||
} else {
|
||||
|
||||
@@ -4,12 +4,17 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.module.common.entity.MarkerShowEntity;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
@@ -26,7 +31,7 @@ import com.mogo.utils.logger.Logger;
|
||||
* desc : 地图上抽离的Marker的共性
|
||||
* version: 1.0
|
||||
*/
|
||||
public abstract class MapMarkerBaseView extends LinearLayout {
|
||||
public abstract class MapMarkerBaseView extends LinearLayout implements IMarkerView {
|
||||
private String TAG = "MapMarkerBaseView";
|
||||
|
||||
protected Context mContext;
|
||||
@@ -34,6 +39,7 @@ public abstract class MapMarkerBaseView extends LinearLayout {
|
||||
protected MogoImageView ivUserHead;
|
||||
protected ImageView ivIcon;
|
||||
protected ImageView ivCar;
|
||||
protected IMogoMarker mMarker;
|
||||
|
||||
public MapMarkerBaseView(Context context) {
|
||||
super(context);
|
||||
@@ -53,7 +59,12 @@ public abstract class MapMarkerBaseView extends LinearLayout {
|
||||
initView(context);
|
||||
}
|
||||
|
||||
protected abstract void initView(Context context);
|
||||
@Override
|
||||
public void setMarker( IMogoMarker marker ) {
|
||||
this.mMarker = marker;
|
||||
}
|
||||
|
||||
protected abstract void initView( Context context);
|
||||
|
||||
public abstract void updateView(MarkerShowEntity markerShowEntity);
|
||||
|
||||
@@ -74,13 +85,15 @@ public abstract class MapMarkerBaseView extends LinearLayout {
|
||||
@Override
|
||||
public void onCompleted(Bitmap bitmap) {
|
||||
Logger.d(TAG, "loadImageWithMarker loaded.");
|
||||
mOptions.notifyObservers();
|
||||
// 使用view渲染地图marker,刷新纹理的时候,需要重新用view生成纹理,然后在设置
|
||||
if ( mMarker != null ) {
|
||||
mMarker.setIcon( fromView( MapMarkerBaseView.this ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
Logger.e(TAG, "loadImageWithMarker onFailure.");
|
||||
mOptions.notifyObservers();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -89,4 +102,35 @@ public abstract class MapMarkerBaseView extends LinearLayout {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Bitmap fromView( View view ) {
|
||||
FrameLayout frameLayout = new FrameLayout( view.getContext() );
|
||||
frameLayout.addView( view );
|
||||
frameLayout.setDrawingCacheEnabled( true );
|
||||
processChildView( frameLayout );
|
||||
frameLayout.destroyDrawingCache();
|
||||
frameLayout.measure( View.MeasureSpec.makeMeasureSpec( 0, View.MeasureSpec.UNSPECIFIED ), View.MeasureSpec.makeMeasureSpec( 0, View.MeasureSpec.UNSPECIFIED ) );
|
||||
frameLayout.layout( 0, 0, frameLayout.getMeasuredWidth(), frameLayout.getMeasuredHeight() );
|
||||
Bitmap bitmap = null;
|
||||
return ( bitmap = frameLayout.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 ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,10 +471,11 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
|
||||
.object(markerShowEntity)
|
||||
.latitude(markerShowEntity.getMarkerLocation().getLat())
|
||||
.longitude(markerShowEntity.getMarkerLocation().getLon());
|
||||
View markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, options);
|
||||
options.icon(markerView);
|
||||
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, options);
|
||||
options.icon(markerView.getView());
|
||||
|
||||
IMogoMarker marker = MarkerServiceHandler.getMarkerManager().addMarker(markerShowEntity.getMarkerType(), options);
|
||||
markerView.setMarker( marker );
|
||||
marker.setOnMarkerClickListener(this);
|
||||
return marker;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user