1. 与adas联调自车图标配置;
2. 修改自车动画实现位置;
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package com.mogo.module.common.map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.mogo.map.uicontroller.CarCursorOption;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.glide.GlideApp;
|
||||
|
||||
/**
|
||||
* 自车图标工具类
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class MyLocationUtil {
|
||||
|
||||
private static boolean isLoadingIcon = false;
|
||||
private static boolean needEmphasizeMyLocation = false;
|
||||
|
||||
public static void emphasizeMyLocation(){
|
||||
if (!isLoadingIcon) {
|
||||
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().emphasizeMyLocation();
|
||||
}else{
|
||||
needEmphasizeMyLocation = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static final CarCursorOption DEFAULT_OPTION = new CarCursorOption.Builder()
|
||||
.build();
|
||||
|
||||
public static void setMyLocationIconUrl(Context context, String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||
UiThreadHandler.post(() -> loadMyLocationIconInUiThread(context, url));
|
||||
} else {
|
||||
loadMyLocationIconInUiThread(context, url);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadMyLocationIconInUiThread(Context context, String url) {
|
||||
if (!url.isEmpty()) {
|
||||
isLoadingIcon = true;
|
||||
RequestOptions options = new RequestOptions()
|
||||
.placeholder(DEFAULT_OPTION.getCarCursorRes())
|
||||
.error(DEFAULT_OPTION.getCarCursorRes())
|
||||
.dontAnimate();
|
||||
GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(options)
|
||||
.into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource,
|
||||
@Nullable Transition<? super Bitmap> transition) {
|
||||
DEFAULT_OPTION.setCarCursorBmp(inflateMyLocation(context, resource));
|
||||
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().setCarCursorOption(DEFAULT_OPTION);
|
||||
if (needEmphasizeMyLocation) {
|
||||
needEmphasizeMyLocation = false;
|
||||
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().emphasizeMyLocation();
|
||||
}
|
||||
isLoadingIcon = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadStarted(@Nullable Drawable placeholder) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap inflateMyLocation(Context context, Bitmap res) {
|
||||
if (res == null) {
|
||||
throw new IllegalArgumentException("inflate myLocation bitmap can not be null!");
|
||||
}
|
||||
View root =
|
||||
LayoutInflater.from(context).inflate(R.layout.module_map_amap_my_location, null, false);
|
||||
ImageView iv =
|
||||
root.findViewById(R.id.module_map_amap_my_location_iv);
|
||||
iv.setImageBitmap(res);
|
||||
return BitmapDescriptorFactory.fromView(root).getBitmap();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:id="@+id/module_map_amap_my_location_bg_iv"
|
||||
android:layout_width="@dimen/module_map_amap_my_location_bg_size"
|
||||
android:layout_height="@dimen/module_map_amap_my_location_bg_size"
|
||||
android:src="@drawable/map_api_ic_current_location2"/>
|
||||
<ImageView
|
||||
android:id="@+id/module_map_amap_my_location_iv"
|
||||
android:layout_width="@dimen/module_map_amap_my_location_icon_width"
|
||||
android:layout_height="@dimen/module_map_amap_my_location_icon_height"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/module_map_amap_my_location_icon"/>
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user