This commit is contained in:
wangcongtao
2020-04-27 11:33:33 +08:00
parent 4c3a637397
commit 9bda2d80df
2 changed files with 176 additions and 0 deletions

View File

@@ -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
* <p>
* 描述
*/
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 );
}
}
}