Add direction view fellow drive direction

This commit is contained in:
董宏宇
2021-07-07 13:34:37 +08:00
parent b554edf38e
commit 2dc42ee007
4 changed files with 49 additions and 3 deletions

View File

@@ -6,7 +6,8 @@ import android.location.Location;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
@@ -26,6 +27,7 @@ import com.mogo.map.MogoLatLng;
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.view.RoundLayout;
import com.mogo.module.small.map.animation.DirectionRotateAnimation;
import com.mogo.module.small.map.utils.MapAssetStyleUtils;
import com.mogo.module.small.map.view.ISmallMapDirectionView;
import com.mogo.utils.logger.Logger;
@@ -46,6 +48,10 @@ public class SmallMapDirectionView
public static final String MODULE_NAME = "SmallMap";
private RoundLayout rlSmallMapBorder;
private ImageView mIvMapBorder;
private DirectionRotateAnimation mRotateAnimation;
private int lastAngle = 0;
private AMapNaviView mAMapNaviView;
private AMap mAMap;
private AMapNavi mAMapNavi;
@@ -69,11 +75,15 @@ public class SmallMapDirectionView
}
private void initView(Context context) {
mRotateAnimation = new DirectionRotateAnimation(context, null);
LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
mAMapNaviView = AbsMogoApplication.getMapNaviView();
rlSmallMapBorder = findViewById(R.id.rlSmallMapBorder);
rlSmallMapBorder.addView(mAMapNaviView);
mIvMapBorder = findViewById(R.id.ivMapBorder);
initAMapView();
@@ -122,7 +132,7 @@ public class SmallMapDirectionView
public void onCameraChange(CameraPosition cameraPosition) {
if (cameraPosition != null) {
//Log.w("onCameraChange", "cameraPosition=" + cameraPosition.bearing);
//changeAngle((int) cameraPosition.bearing);
changeAngle((int) cameraPosition.bearing);
}
}
@@ -257,4 +267,32 @@ public class SmallMapDirectionView
public void clearPolyline() {
}
/**
* 修改角度
*
* @param angle 角度 0 - 359度旋转,相对于自身中心位置
*/
public void changeAngle(int angle) {
int tempAngle = 360 - angle;
// if (tempAngle <= 180) {
// tempAngle = tempAngle;
// } else {
// tempAngle = -(360 - tempAngle);
// }
mRotateAnimation.setFromDegrees(lastAngle);
mRotateAnimation.setToDegrees(tempAngle);
//设置线性插值,可以解决旋转一圈后卡顿问题
mRotateAnimation.setInterpolator(new LinearInterpolator());
//设置旋转一圈时间
mRotateAnimation.setDuration(300);
//控件动画结束时是否保持动画最后的状态
mRotateAnimation.setFillAfter(true);
mIvMapBorder.startAnimation(mRotateAnimation);
// 刷新最后一次角度
lastAngle = tempAngle;
}
}

View File

@@ -10,7 +10,6 @@
android:layout_width="@dimen/module_small_map_view_border_width"
android:layout_height="@dimen/module_small_map_view_border_width"
android:layout_centerInParent="true"
android:layout_margin="@dimen/module_small_map_padding"
android:background="@drawable/module_small_map_view_border" />
<com.mogo.module.common.view.RoundLayout
@@ -31,4 +30,11 @@
android:layout_height="match_parent" />-->
</com.mogo.module.common.view.RoundLayout>
<ImageView
android:id="@+id/ivMapBorder"
android:layout_width="@dimen/module_small_map_border_view_width"
android:layout_height="@dimen/module_small_map_border_view_width"
android:layout_centerInParent="true"
android:src="@drawable/module_small_map_view_border_north" />
</merge>

View File

@@ -2,6 +2,7 @@
<resources>
<dimen name="module_small_map_padding">40px</dimen>
<dimen name="module_small_map_view_border_width">400px</dimen>
<dimen name="module_small_map_border_view_width">550px</dimen>
<dimen name="module_small_map_view_width">360px</dimen>
</resources>

View File

@@ -2,6 +2,7 @@
<resources>
<dimen name="module_small_map_padding">30px</dimen>
<dimen name="module_small_map_view_border_width">288px</dimen>
<dimen name="module_small_map_border_view_width">450px</dimen>
<dimen name="module_small_map_view_width">260px</dimen>
</resources>