增加自车位置加强提示动画及接口

This commit is contained in:
tongchenfei
2020-11-18 19:35:19 +08:00
parent 3146f2a5b0
commit 8b5bc93455
10 changed files with 145 additions and 45 deletions

View File

@@ -9,7 +9,9 @@ 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;
@@ -85,7 +87,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
AMapNaviViewListener,
AMapMessageListener,
AMap.OnCameraChangeListener,
AMap.OnMyLocationChangeListener {
AMap.OnMyLocationChangeListener,
Handler.Callback{
private static final String TAG = "AMapNaviViewWrapper";
@@ -568,6 +571,14 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
}
private boolean isInEmphasizeAnim = false;
@Override
public void emphasizeMyLocation() {
isInEmphasizeAnim = true;
setCarCursorOption(null);
}
@Override
public void showMyLocation( View view ) {
if ( NaviClient.getInstance( getContext() ).isNaviing() ) {
@@ -936,9 +947,11 @@ public class AMapNaviViewWrapper implements IMogoMapView,
"MY_LOCATION_CONFIG", "");
if (myLocationConfigCache == null || !myLocationConfigCache.equals(myLocationConfig)) {
// 内存缓存的地址为空,或者内存缓存的地址和sp保存的config不一致那得重新获取bitmap
myLocationConfigCache = myLocationConfig;
loadMyLocationIcon(myLocationConfig);
} else if (isInEmphasizeAnim) {
DEFAULT_OPTION.setCarCursorBmp(inflateMyLocation(myLocationBitmap));
}
}
@Override
@@ -1043,6 +1056,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
@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);
}
@@ -1063,11 +1078,50 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
}
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;
}
}

View File

@@ -426,6 +426,11 @@ public class AMapViewWrapper implements IMogoMapView,
}
}
@Override
public void emphasizeMyLocation() {
// 空实现
}
@Override
public void showMyLocation( View view ) {
if ( NaviClient.getInstance( getContext() ).isNaviing() ) {

View File

@@ -99,6 +99,13 @@ public class AMapUIController implements IMogoMapUIController {
}
}
@Override
public void emphasizeMyLocation() {
if ( mClient != null ) {
mClient.emphasizeMyLocation();
}
}
@Override
public void showMyLocation( View view ) {
if ( mClient != null ) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@@ -1,9 +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_size"
android:layout_height="@dimen/module_map_amap_my_location_size" />
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>

View File

@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="module_map_amap_my_location_size">370px</dimen>
<dimen name="module_map_amap_my_location_bg_size">370px</dimen>
<dimen name="module_map_amap_my_location_icon_width">78px</dimen>
<dimen name="module_map_amap_my_location_icon_height">120px</dimen>
</resources>

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="path_width">60px</dimen>
<dimen name="module_map_amap_my_location_size">146px</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_bg_size">146px</dimen>
</resources>

View File

@@ -71,6 +71,11 @@ public interface IMogoMapUIController {
*/
void showMyLocation( View view );
/**
* 强调自车位置,加个动画突显一下自车位置
*/
void emphasizeMyLocation();
/**
* 以外部定位的方式改变当前位置
*

View File

@@ -92,6 +92,13 @@ public class MogoMapUIController implements IMogoMapUIController {
}
}
@Override
public void emphasizeMyLocation() {
if ( mDelegate != null ) {
mDelegate.emphasizeMyLocation();
}
}
@Override
public void showMyLocation( View view ) {
if ( mDelegate != null ) {

View File

@@ -832,50 +832,62 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
private void debugTopView() {
findViewById(R.id.btnDebugCtrlNaviView).setOnClickListener(view -> {
if (!toggle) {
TopViewAnimHelper.getInstance().showNaviView();
} else {
TopViewAnimHelper.getInstance().hideNaviView();
}
toggle = !toggle;
SharedPrefsMgr.getInstance(getContext()).putString("MY_LOCATION_CONFIG", "https" +
"://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1605705236512" +
"&di=50620661ded7035fb84899a408f9f27e&imgtype=0&src=http%3A%2F%2Fb-ssl" +
".duitang.com%2Fuploads%2Fitem%2F201409%2F11%2F20140911211243_3rT4u.jpeg");
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().setCarCursorOption(null);
// if (!toggle) {
// TopViewAnimHelper.getInstance().showNaviView();
// } else {
// TopViewAnimHelper.getInstance().hideNaviView();
// }
// toggle = !toggle;
});
findViewById(R.id.btnDebugCtrlSubView).setOnClickListener(view -> {
View v = LayoutInflater.from(getContext()).inflate(R.layout.demo_top, null);
TextView tv = v.findViewById(R.id.tvIndex);
tv.setText("sub view height: " + currentHeight + ": " + v);
mApis.getTopViewManager().addSubView(v, new IMogoTopViewStatusListener() {
@Override
public void onViewAdded(View view) {
Logger.d(TAG, "onSubViewAdded: " + view);
}
@Override
public void onViewRemoved(View view) {
Logger.d(TAG, "onSubViewRemoved: " + view);
}
@Override
public void beforeViewAddAnim(View view) {
Logger.d(TAG, "beforeSubViewAddAnim: " + view);
}
@Override
public void beforeViewRemoveAnim(View view) {
Logger.d(TAG, "beforeSubViewRemoveAnim: " + view);
}
});
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().emphasizeMyLocation();
// View v = LayoutInflater.from(getContext()).inflate(R.layout.demo_top, null);
// TextView tv = v.findViewById(R.id.tvIndex);
// tv.setText("sub view height: " + currentHeight + ": " + v);
// mApis.getTopViewManager().addSubView(v, new IMogoTopViewStatusListener() {
// @Override
// public void onViewAdded(View view) {
// Logger.d(TAG, "onSubViewAdded: " + view);
// }
//
// @Override
// public void onViewRemoved(View view) {
// Logger.d(TAG, "onSubViewRemoved: " + view);
// }
//
// @Override
// public void beforeViewAddAnim(View view) {
// Logger.d(TAG, "beforeSubViewAddAnim: " + view);
// }
//
// @Override
// public void beforeViewRemoveAnim(View view) {
// Logger.d(TAG, "beforeSubViewRemoveAnim: " + view);
// }
// });
});
findViewById(R.id.btnDebugCtrlTopView).setOnClickListener(view -> {
View v = LayoutInflater.from(getContext()).inflate(R.layout.demo_top, null);
TextView tv = v.findViewById(R.id.tvIndex);
Random random = new Random();
currentHeight = heights[random.nextInt(3)];
tv.setText(" height: " + currentHeight + ": " + v);
ViewGroup.LayoutParams params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, currentHeight);
mApis.getEntranceButtonController().addLeftFeatureView(v);
SharedPrefsMgr.getInstance(getContext()).putString("MY_LOCATION_CONFIG", "https" +
"://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1605705508574" +
"&di=339d3259ad21f5f48c8abcd1bafff324&imgtype=0&src=http%3A%2F%2Fc-ssl" +
".duitang.com%2Fuploads%2Fitem%2F202004%2F23%2F20200423111550_4AJLr.thumb" +
".1000_0.jpeg");
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().emphasizeMyLocation();
// View v = LayoutInflater.from(getContext()).inflate(R.layout.demo_top, null);
// TextView tv = v.findViewById(R.id.tvIndex);
// Random random = new Random();
// currentHeight = heights[random.nextInt(3)];
// tv.setText(" height: " + currentHeight + ": " + v);
// ViewGroup.LayoutParams params =
// new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, currentHeight);
// mApis.getEntranceButtonController().addLeftFeatureView(v);
// mApis.getTopViewManager().addView(v, params, new IMogoTopViewStatusListener() {
// @Override