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 );
}
}
}

View File

@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="vertical"
android:paddingStart="@dimen/dp_5"
android:paddingEnd="@dimen/dp_5"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/module_service_id_marker_content"
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_90"
android:background="@drawable/bg_map_marker_blue_info"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.mogo.service.imageloader.MogoImageView
android:id="@+id/module_service_id_user_header"
android:layout_width="@dimen/dp_76"
android:layout_height="@dimen/dp_76"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:miv_failureHolder="@drawable/icon_default_user_head"
app:miv_overlayImageId="@drawable/icon_default_user_head"
app:miv_placeHolder="@drawable/icon_default_user_head"
app:miv_shape="circle" />
<TextView
android:id="@+id/module_service_id_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="@dimen/sp_32"
app:layout_constraintBottom_toBottomOf="@+id/module_service_id_user_header"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/module_service_id_user_header"
app:layout_constraintTop_toTopOf="@+id/module_service_id_user_header"
tools:text="诗一样的女子" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="-10dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="@+id/module_service_id_marker_content"
app:layout_constraintStart_toStartOf="@+id/module_service_id_marker_content"
app:layout_constraintTop_toBottomOf="@+id/module_service_id_marker_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/bg_shape_reverse_triangle_blue" />
</LinearLayout>
</LinearLayout>