diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/UserDataMarkerInfoWindowAdapter.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/UserDataMarkerInfoWindowAdapter.java new file mode 100644 index 0000000000..47ebe41223 --- /dev/null +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/UserDataMarkerInfoWindowAdapter.java @@ -0,0 +1,108 @@ +package com.mogo.module.service.marker; + +import android.content.Context; +import android.graphics.Bitmap; +import android.os.Looper; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import com.mogo.map.marker.IMogoInfoWindowAdapter; +import com.mogo.map.marker.IMogoMarker; +import com.mogo.module.common.entity.MarkerShowEntity; +import com.mogo.module.service.MarkerServiceHandler; +import com.mogo.module.service.R; +import com.mogo.service.imageloader.IMogoImageLoaderListener; +import com.mogo.service.imageloader.MogoImageView; +import com.mogo.utils.UiThreadHandler; +import com.mogo.utils.WindowUtils; +import com.mogo.utils.logger.Logger; + +/** + * @author congtaowang + * @since 2020-04-27 + *

+ * 描述 + */ +public class UserDataMarkerInfoWindowAdapter implements IMogoInfoWindowAdapter { + + private static final String TAG = "UserDataMarkerInfoWindowAdapter"; + + private static volatile UserDataMarkerInfoWindowAdapter sInstance; + private final Context mContext; + + private View mInfoWindowView = null; + + private MogoImageView mUserHeader; + private TextView mContent; + + private UserDataMarkerInfoWindowAdapter( Context context ) { + this.mContext = context; + } + + public static UserDataMarkerInfoWindowAdapter getInstance( Context context ) { + if ( sInstance == null ) { + synchronized ( UserDataMarkerInfoWindowAdapter.class ) { + if ( sInstance == null ) { + sInstance = new UserDataMarkerInfoWindowAdapter( context ); + } + } + } + return sInstance; + } + + public synchronized void release() { + sInstance = null; + } + + @Override + public View getInfoWindow( IMogoMarker marker ) { + return inflateView( marker ); + } + + private View inflateView( IMogoMarker marker ) { + if ( marker == null ) { + return null; + } + + if ( mInfoWindowView == null ) { + mInfoWindowView = LayoutInflater.from( mContext ).inflate( R.layout.view_map_data_user_info_window, null ); + mUserHeader = mInfoWindowView.findViewById( R.id.module_service_id_user_header ); + mContent = mInfoWindowView.findViewById( R.id.module_service_id_content ); + } + + try { + MarkerShowEntity markerShowEntity = ( MarkerShowEntity ) marker.getObject(); + mContent.setText( markerShowEntity.getTextContent() ); + loadImageWithMarker( markerShowEntity ); + } catch ( Exception e ) { + Logger.e( TAG, e, "error." ); + } + + return mInfoWindowView; + } + + protected void loadImageWithMarker( final MarkerShowEntity markerShowEntity ) { + + if ( Looper.myLooper() != Looper.getMainLooper() ) { + UiThreadHandler.post( () -> { + runOnUiThread( markerShowEntity ); + } ); + } else { + runOnUiThread( markerShowEntity ); + } + } + + private void runOnUiThread( final MarkerShowEntity markerShowEntity ) { + if ( !TextUtils.isEmpty( markerShowEntity.getIconUrl() ) ) { + MarkerServiceHandler.getImageloader().displayImage( markerShowEntity.getIconUrl(), + mUserHeader, + WindowUtils.dip2px( mContext, 50 ), WindowUtils.dip2px( mContext, 50 ), + null ); + + } else { + mUserHeader.setBackgroundResource( R.drawable.icon_default_user_head ); + } + } +} diff --git a/modules/mogo-module-service/src/main/res/layout/view_map_data_user_info_window.xml b/modules/mogo-module-service/src/main/res/layout/view_map_data_user_info_window.xml new file mode 100644 index 0000000000..85dc31340e --- /dev/null +++ b/modules/mogo-module-service/src/main/res/layout/view_map_data_user_info_window.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + \ No newline at end of file