1. 与adas联调自车图标配置;

2. 修改自车动画实现位置;
This commit is contained in:
tongchenfei
2020-11-19 18:11:23 +08:00
parent b13e1fa28b
commit 92bc1bbebe
12 changed files with 217 additions and 157 deletions

View File

@@ -1,27 +1,17 @@
package com.mogo.map.impl.amap;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.os.Trace;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapUtils;
@@ -35,15 +25,13 @@ import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.maps.model.Poi;
import com.amap.api.maps.model.Polyline;
import com.amap.api.maps.model.animation.Animation;
import com.amap.api.maps.model.animation.ScaleAnimation;
import com.amap.api.maps.model.animation.TranslateAnimation;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.enums.AMapNaviViewShowMode;
import com.amap.api.navi.model.NaviInfo;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.mogo.map.IMogoMap;
import com.mogo.map.IMogoMapView;
import com.mogo.map.MogoLatLng;
@@ -62,11 +50,8 @@ import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.map.uicontroller.MapCameraPosition;
import com.mogo.map.uicontroller.MapControlResult;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.WindowUtils;
import com.mogo.utils.glide.GlideApp;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.storage.SharedPrefsMgr;
import java.util.List;
@@ -87,8 +72,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
AMapNaviViewListener,
AMapMessageListener,
AMap.OnCameraChangeListener,
AMap.OnMyLocationChangeListener,
Handler.Callback{
AMap.OnMyLocationChangeListener{
private static final String TAG = "AMapNaviViewWrapper";
@@ -137,7 +121,6 @@ public class AMapNaviViewWrapper implements IMogoMapView,
// 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
// options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
// 设置自车的图片对象
checkDefaultOption();
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), DEFAULT_OPTION.getNaviCursorRes() ) );
// 设置指南针图标否在导航界面显示默认显示。true显示false隐藏。
options.setCompassEnabled( false );
@@ -565,18 +548,38 @@ public class AMapNaviViewWrapper implements IMogoMapView,
mMapView.getMap().setMyLocationStyle( style );
if ( visible ) {
// 强制刷新一遍车标
setCarCursorOption(null);
setCarCursorOption(mCarCursorOption);
// style.myLocationIcon( BitmapDescriptorFactory.fromResource( mCarCursorOption.getCarCursorRes() ) );
}
}
}
private boolean isInEmphasizeAnim = false;
@Override
public void emphasizeMyLocation() {
isInEmphasizeAnim = true;
setCarCursorOption(null);
if (mMyLocationMarker == null) {
initMyLocationMarker();
}
ScaleAnimation animation = new ScaleAnimation(1f, 1.2f, 1f, 1.2f);
animation.setDuration(250);
mMyLocationMarker.setAnimation(animation);
// mMyLocationMarker.setAnimationListener(new Animation.AnimationListener() {
// @Override
// public void onAnimationStart() {
//
// }
//
// @Override
// public void onAnimationEnd() {
// mMyLocationMarker.setAnimationListener(null);
// ScaleAnimation animation = new ScaleAnimation(1.5f, 1f, 1.5f, 1f);
// animation.setDuration(250);
// mMyLocationMarker.setAnimation(animation);
// mMyLocationMarker.startAnimation();
// }
// });
mMyLocationMarker.startAnimation();
}
@Override
@@ -939,42 +942,25 @@ public class AMapNaviViewWrapper implements IMogoMapView,
return mIsCarLocked;
}
private String myLocationConfigCache = null;
private boolean isUseDefaultOption = false;
private void checkDefaultOption(){
String myLocationConfig = SharedPrefsMgr.getInstance(getContext()).getString(
"MY_LOCATION_CONFIG", "");
if (myLocationConfigCache == null || !myLocationConfigCache.equals(myLocationConfig)) {
// 内存缓存的地址为空,或者内存缓存的地址和sp保存的config不一致那得重新获取bitmap
loadMyLocationIcon(myLocationConfig);
} else if (isInEmphasizeAnim) {
DEFAULT_OPTION.setCarCursorBmp(inflateMyLocation(myLocationBitmap));
}
}
@Override
public void setCarCursorOption( CarCursorOption option ) {
if (!isVisible) {
// 当前自车图标没有显示,所以先不走下面的流程
return;
}
if ( mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION ) {
mCarCursorOption.destroy();
}
checkDefaultOption();
if ( option != null ) {
try {
isUseDefaultOption = false;
mCarCursorOption = option.clone();
} catch ( Exception e ) {
isUseDefaultOption = true;
// if ( mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION) {
// mCarCursorOption.destroy();
// }
if(option != mCarCursorOption) {
if (option != null) {
try {
mCarCursorOption = option.clone();
} catch (Exception e) {
mCarCursorOption = DEFAULT_OPTION;
}
} else {
mCarCursorOption = DEFAULT_OPTION;
}
} else {
isUseDefaultOption = true;
mCarCursorOption = DEFAULT_OPTION;
}
if ( !checkAMapView() ) {
return;
@@ -1032,96 +1018,4 @@ public class AMapNaviViewWrapper implements IMogoMapView,
mMapView.getMap().moveCamera( CameraUpdateFactory.changeBearing( bearing ) );
}
}
protected void loadMyLocationIcon(String url) {
if ( Looper.myLooper() != Looper.getMainLooper() ) {
UiThreadHandler.post( ()-> loadMyLocationIconInUiThread(url));
} else {
loadMyLocationIconInUiThread(url);
}
}
private void loadMyLocationIconInUiThread(String url) {
if (!url.isEmpty()) {
RequestOptions options = new RequestOptions()
.placeholder( DEFAULT_OPTION.getCarCursorRes() )
.error( DEFAULT_OPTION.getCarCursorRes() )
.dontAnimate();
GlideApp.with( getContext() )
.asBitmap()
.load( url )
.apply( options )
.into( new SimpleTarget< Bitmap >() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition< ? super Bitmap > transition ) {
if (isUseDefaultOption) {
myLocationConfigCache = url;
myLocationBitmap = resource;
DEFAULT_OPTION.setCarCursorBmp(inflateMyLocation(resource));
setCarCursorOption(null);
}
}
@Override
public void onLoadStarted( @Nullable Drawable placeholder ) {
}
@Override
public void onLoadCleared( @Nullable Drawable placeholder ) {
}
@Override
public void onLoadFailed( @Nullable Drawable errorDrawable ) {
}
} );
}
}
private float emphasizeAnimOffset = 1f;
private Bitmap inflateMyLocation(Bitmap res) {
if (res == null) {
throw new IllegalArgumentException("inflate myLocation bitmap can not be null!");
}
View root =
LayoutInflater.from(getContext()).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);
if (isInEmphasizeAnim) {
iv.setScaleX(emphasizeAnimOffset);
iv.setScaleY(emphasizeAnimOffset);
handler.sendEmptyMessageDelayed(MSG_CONTINUE_EMPHASIZE_ANIM, EMPHASIZE_ANIM_DELAY);
}
return BitmapDescriptorFactory.fromView(root).getBitmap();
}
/**
* 目前仅用于强调动画
*/
private Handler handler = new Handler(this);
private static final int MSG_CONTINUE_EMPHASIZE_ANIM = 1001;
private static final long EMPHASIZE_ANIM_DELAY = 80;
private int emphasizeAnimProgress = 0;
private Bitmap myLocationBitmap;
@Override
public boolean handleMessage(Message msg) {
if (msg.what == MSG_CONTINUE_EMPHASIZE_ANIM) {
if (emphasizeAnimProgress < 5) {
emphasizeAnimOffset += 0.1;
emphasizeAnimProgress++;
}else if(emphasizeAnimProgress<10){
emphasizeAnimOffset -= 0.1;
emphasizeAnimProgress++;
} else if (emphasizeAnimProgress == 10) {
isInEmphasizeAnim = false;
emphasizeAnimProgress = 0;
emphasizeAnimOffset = 1;
}
setCarCursorOption(null);
return true;
}
return false;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="path_width">60px</dimen>
<dimen name="module_map_amap_my_location_icon_width">78px</dimen>
<dimen name="module_map_amap_my_location_icon_height">120px</dimen>
<dimen name="module_map_amap_my_location_icon_width">44px</dimen>
<dimen name="module_map_amap_my_location_icon_height">66px</dimen>
<dimen name="module_map_amap_my_location_bg_size">146px</dimen>
</resources>