[6.7.0][Feat]小地图和全览地图动态切换
This commit is contained in:
@@ -7,13 +7,8 @@ import android.animation.ObjectAnimator
|
||||
import android.animation.PropertyValuesHolder
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.constraintlayout.widget.ConstraintSet
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.function.hmi.util.ConstraintUtil
|
||||
import kotlinx.android.synthetic.main.view_map_container.view.exchangeLayout
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
|
||||
/**
|
||||
* 可自定义绘制顺序的ConstraintLayout
|
||||
@@ -184,7 +179,7 @@ class ExchangeChildLayout @JvmOverloads constructor(
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
super.onAnimationEnd(animation)
|
||||
// updateLayoutParams()
|
||||
swapLayoutParamsWithoutAnim()
|
||||
// swapLayoutParamsWithoutAnim()
|
||||
invalidate()
|
||||
isPlayingAnim = false
|
||||
}
|
||||
@@ -192,7 +187,7 @@ class ExchangeChildLayout @JvmOverloads constructor(
|
||||
override fun onAnimationCancel(animation: Animator) {
|
||||
super.onAnimationCancel(animation)
|
||||
// updateLayoutParams()
|
||||
swapLayoutParamsWithoutAnim()
|
||||
// swapLayoutParamsWithoutAnim()
|
||||
invalidate()
|
||||
isPlayingAnim = false
|
||||
}
|
||||
@@ -220,112 +215,61 @@ class ExchangeChildLayout @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateLayoutParams() {
|
||||
// if (childCount > 2) return
|
||||
// children.forEachIndexed { index, view ->
|
||||
// if (index == 0) {
|
||||
// changeRule(view, true)
|
||||
// } else {
|
||||
// changeRule(view, false)
|
||||
// }
|
||||
private fun swapLayoutParamsWithoutAnim() {
|
||||
// if (constraintUtil == null) {
|
||||
// constraintUtil = ConstraintUtil(exchangeLayout)
|
||||
// }
|
||||
// if (isSwapped) {
|
||||
// val begin = constraintUtil!!.begin()
|
||||
// // 清除约束关系
|
||||
// begin.clear(R.id.mapBizView, R.id.overMapView)
|
||||
// // 设置新的约束关系
|
||||
// begin.Left_toLeftOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
// begin.Top_toTopOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
// begin.Right_toRightOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
// begin.Bottom_toBottomOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
//
|
||||
// begin.Left_toLeftOf(R.id.mapBizView, ConstraintSet.UNSET)
|
||||
// begin.Top_toTopOf(R.id.mapBizView, ConstraintSet.UNSET)
|
||||
// begin.Right_toRightOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
// begin.Bottom_toBottomOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
// begin.setWidth(R.id.mapBizView, AutoSizeUtils.dp2px(context, 270f))
|
||||
// begin.setHeight(R.id.mapBizView, AutoSizeUtils.dp2px(context, 270f))
|
||||
// begin.setMargin(
|
||||
// R.id.mapBizView,
|
||||
// 0,
|
||||
// 0,
|
||||
// AutoSizeUtils.dp2px(context, 60f),
|
||||
// AutoSizeUtils.dp2px(context, 60f)
|
||||
// )
|
||||
// // 应用新的属性集
|
||||
// begin.commit()
|
||||
// } else {
|
||||
//// constraintUtil?.reSet()
|
||||
// val begin = constraintUtil!!.begin()
|
||||
// // 清除约束关系
|
||||
// begin.clear(R.id.mapBizView, R.id.overMapView)
|
||||
// // 设置新的约束关系
|
||||
// begin.Left_toLeftOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
// begin.Top_toTopOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
// begin.Right_toRightOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
// begin.Bottom_toBottomOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
//
|
||||
// begin.Left_toLeftOf(R.id.overMapView, ConstraintSet.UNSET)
|
||||
// begin.Top_toTopOf(R.id.overMapView, ConstraintSet.UNSET)
|
||||
// begin.Right_toRightOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
// begin.Bottom_toBottomOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
// begin.setWidth(R.id.overMapView, AutoSizeUtils.dp2px(context, 270f))
|
||||
// begin.setHeight(R.id.overMapView, AutoSizeUtils.dp2px(context, 270f))
|
||||
// begin.setMargin(
|
||||
// R.id.overMapView,
|
||||
// 0,
|
||||
// 0,
|
||||
// AutoSizeUtils.dp2px(context, 60f),
|
||||
// AutoSizeUtils.dp2px(context, 60f)
|
||||
// )
|
||||
// // 应用新的属性集
|
||||
// begin.commit()
|
||||
// }
|
||||
}
|
||||
|
||||
private fun changeRule(
|
||||
view: View, isBottom: Boolean,
|
||||
) {
|
||||
val layoutParams = view.layoutParams as LayoutParams
|
||||
if (isBottom) {
|
||||
if (isSwapped) {
|
||||
layoutParams.startToStart = LayoutParams.UNSET
|
||||
layoutParams.topToTop = LayoutParams.UNSET
|
||||
layoutParams.endToEnd = LayoutParams.PARENT_ID
|
||||
layoutParams.bottomToBottom = LayoutParams.PARENT_ID
|
||||
layoutParams.width = minWidth
|
||||
layoutParams.height = minHeight
|
||||
} else {
|
||||
layoutParams.startToStart = LayoutParams.PARENT_ID
|
||||
layoutParams.topToTop = LayoutParams.PARENT_ID
|
||||
layoutParams.endToEnd = LayoutParams.UNSET
|
||||
layoutParams.bottomToBottom = LayoutParams.UNSET
|
||||
layoutParams.width = maxWidth
|
||||
layoutParams.height = maxHeight
|
||||
}
|
||||
} else {
|
||||
if (isSwapped) {
|
||||
layoutParams.startToStart = LayoutParams.PARENT_ID
|
||||
layoutParams.topToTop = LayoutParams.PARENT_ID
|
||||
layoutParams.endToEnd = LayoutParams.UNSET
|
||||
layoutParams.bottomToBottom = LayoutParams.UNSET
|
||||
layoutParams.width = maxWidth
|
||||
layoutParams.height = maxHeight
|
||||
} else {
|
||||
layoutParams.startToStart = LayoutParams.UNSET
|
||||
layoutParams.topToTop = LayoutParams.UNSET
|
||||
layoutParams.endToEnd = LayoutParams.PARENT_ID
|
||||
layoutParams.bottomToBottom = LayoutParams.PARENT_ID
|
||||
layoutParams.width = minWidth
|
||||
layoutParams.height = minHeight
|
||||
}
|
||||
}
|
||||
view.layoutParams = layoutParams
|
||||
}
|
||||
|
||||
private fun swapLayoutParamsWithoutAnim() {
|
||||
if (constraintUtil == null) {
|
||||
constraintUtil = ConstraintUtil(exchangeLayout)
|
||||
}
|
||||
if (isSwapped) {
|
||||
val begin = constraintUtil!!.begin()
|
||||
// 清除约束关系
|
||||
begin.clear(R.id.mapBizView, R.id.overMapView)
|
||||
// 设置新的约束关系
|
||||
begin.Left_toLeftOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
begin.Top_toTopOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
begin.Right_toRightOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
begin.Bottom_toBottomOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
|
||||
begin.Left_toLeftOf(R.id.mapBizView, ConstraintSet.UNSET)
|
||||
begin.Top_toTopOf(R.id.mapBizView, ConstraintSet.UNSET)
|
||||
begin.Right_toRightOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
begin.Bottom_toBottomOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
begin.setWidth(R.id.mapBizView, AutoSizeUtils.dp2px(context, 270f))
|
||||
begin.setHeight(R.id.mapBizView, AutoSizeUtils.dp2px(context, 270f))
|
||||
begin.setMargin(
|
||||
R.id.mapBizView,
|
||||
0,
|
||||
0,
|
||||
AutoSizeUtils.dp2px(context, 60f),
|
||||
AutoSizeUtils.dp2px(context, 60f)
|
||||
)
|
||||
// 应用新的属性集
|
||||
begin.commit()
|
||||
} else {
|
||||
// constraintUtil?.reSet()
|
||||
val begin = constraintUtil!!.begin()
|
||||
// 清除约束关系
|
||||
begin.clear(R.id.mapBizView, R.id.overMapView)
|
||||
// 设置新的约束关系
|
||||
begin.Left_toLeftOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
begin.Top_toTopOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
begin.Right_toRightOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
begin.Bottom_toBottomOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
|
||||
begin.Left_toLeftOf(R.id.overMapView, ConstraintSet.UNSET)
|
||||
begin.Top_toTopOf(R.id.overMapView, ConstraintSet.UNSET)
|
||||
begin.Right_toRightOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
begin.Bottom_toBottomOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
begin.setWidth(R.id.overMapView, AutoSizeUtils.dp2px(context, 270f))
|
||||
begin.setHeight(R.id.overMapView, AutoSizeUtils.dp2px(context, 270f))
|
||||
begin.setMargin(
|
||||
R.id.overMapView,
|
||||
0,
|
||||
0,
|
||||
AutoSizeUtils.dp2px(context, 60f),
|
||||
AutoSizeUtils.dp2px(context, 60f)
|
||||
)
|
||||
// 应用新的属性集
|
||||
begin.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,20 @@ import android.transition.Transition
|
||||
import android.transition.Transition.TransitionListener
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import android.view.View
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.constraintlayout.widget.ConstraintSet
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.function.hmi.util.ConstraintUtil
|
||||
import com.mogo.eagle.core.function.view.TravelRealityView
|
||||
import com.mogo.eagle.core.utilcode.mogo.view.OnPreventFastClickListener
|
||||
import com.mogo.map.listener.IMogoMapListener
|
||||
import com.mogo.map.listener.MogoMapListenerHandler
|
||||
import kotlinx.android.synthetic.main.view_map_container.view.exchangeLayout
|
||||
import kotlinx.android.synthetic.main.view_map_container.view.mapBizView
|
||||
import kotlinx.android.synthetic.main.view_map_container.view.overMapView
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
import kotlinx.android.synthetic.main.view_map_container.view.parentLayout
|
||||
import kotlinx.android.synthetic.main.view_map_container.view.shadowView
|
||||
|
||||
class MapContainerLayout @JvmOverloads constructor(
|
||||
context: Context,
|
||||
@@ -26,7 +27,7 @@ class MapContainerLayout @JvmOverloads constructor(
|
||||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr), IMogoMapListener {
|
||||
|
||||
private var isSwapped = false
|
||||
private var isScaled = false
|
||||
private var isPlayingAnim = false
|
||||
private var constraintUtil: ConstraintUtil? = null
|
||||
|
||||
@@ -78,77 +79,58 @@ class MapContainerLayout @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
overMapView.setOnGestureListener(object : TravelRealityView.OnGestureListener {
|
||||
override fun onSingleTap(lng: Float, lat: Float) {
|
||||
if (!exchangeLayout.getSwapFlag()) {
|
||||
overMapView.setMapFlag(false)
|
||||
exchangeLayout.swapViews()
|
||||
}
|
||||
shadowView.setOnClickListener(object : OnPreventFastClickListener() {
|
||||
override fun onClickImpl(v: View?) {
|
||||
swapViewsWithAnim()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onMapClick(latLng: MogoLatLng?) {
|
||||
super.onMapClick(latLng)
|
||||
if (exchangeLayout.getSwapFlag()) {
|
||||
overMapView.setMapFlag(true)
|
||||
exchangeLayout.swapViews()
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(message = "会多次requestLayout导致高精地图卡顿")
|
||||
private fun swapViewsWithAnim() {
|
||||
if (isPlayingAnim) return
|
||||
if (constraintUtil == null) {
|
||||
constraintUtil = ConstraintUtil(exchangeLayout, 300, DecelerateInterpolator())
|
||||
constraintUtil = ConstraintUtil(parentLayout, 300, AccelerateDecelerateInterpolator())
|
||||
constraintUtil?.addTransitionListener(transitionListener)
|
||||
}
|
||||
if (!isSwapped) {
|
||||
if (!isScaled) {
|
||||
// 获取属性集并设置动画
|
||||
val begin = constraintUtil!!.beginWithAnim()
|
||||
// 清除约束关系
|
||||
begin.clear(R.id.mapBizView, R.id.overMapView)
|
||||
begin.clear(R.id.overMapView)
|
||||
// 设置新的约束关系
|
||||
begin.Left_toLeftOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
begin.Top_toTopOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
begin.Right_toRightOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
begin.Bottom_toBottomOf(R.id.overMapView, ConstraintSet.PARENT_ID)
|
||||
|
||||
begin.Left_toLeftOf(R.id.mapBizView, ConstraintSet.UNSET)
|
||||
begin.Top_toTopOf(R.id.mapBizView, ConstraintSet.UNSET)
|
||||
begin.Right_toRightOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
begin.Bottom_toBottomOf(R.id.mapBizView, ConstraintSet.PARENT_ID)
|
||||
begin.setWidth(R.id.mapBizView, AutoSizeUtils.dp2px(context, 270f))
|
||||
begin.setHeight(R.id.mapBizView, AutoSizeUtils.dp2px(context, 270f))
|
||||
begin.setMargin(
|
||||
R.id.mapBizView,
|
||||
0,
|
||||
0,
|
||||
AutoSizeUtils.dp2px(context, 60f),
|
||||
AutoSizeUtils.dp2px(context, 60f)
|
||||
)
|
||||
// 应用新的属性集
|
||||
begin.commit()
|
||||
exchangeLayout.setSwapped(true)
|
||||
isSwapped = true
|
||||
} else {
|
||||
constraintUtil?.reSetWidthAnim()
|
||||
exchangeLayout.setSwapped(false)
|
||||
isSwapped = false
|
||||
}
|
||||
}
|
||||
|
||||
private val transitionListener = object : TransitionListener {
|
||||
override fun onTransitionStart(transition: Transition?) {
|
||||
isPlayingAnim = true
|
||||
overMapView.setMapFlag(isScaled)
|
||||
}
|
||||
|
||||
override fun onTransitionEnd(transition: Transition?) {
|
||||
isPlayingAnim = false
|
||||
overMapView.swapSettings()
|
||||
updateShadowBg(isScaled)
|
||||
isScaled = !isScaled
|
||||
}
|
||||
|
||||
override fun onTransitionCancel(transition: Transition?) {
|
||||
isPlayingAnim = false
|
||||
overMapView.swapSettings()
|
||||
updateShadowBg(isScaled)
|
||||
isScaled = !isScaled
|
||||
}
|
||||
|
||||
override fun onTransitionPause(transition: Transition?) {
|
||||
@@ -159,4 +141,12 @@ class MapContainerLayout @JvmOverloads constructor(
|
||||
isPlayingAnim = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateShadowBg(isSmallMap: Boolean) {
|
||||
if (!isSmallMap) {
|
||||
shadowView.setBackgroundResource(R.drawable.gaojing_bg)
|
||||
} else {
|
||||
shadowView.background = null
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
@@ -2,47 +2,49 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/parentLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:ignore="MissingDefaultResource">
|
||||
|
||||
<com.mogo.eagle.core.function.hmi.map.ExchangeChildLayout
|
||||
android:id="@+id/exchangeLayout"
|
||||
<!--高精地图-->
|
||||
<com.mogo.eagle.core.function.view.MapBizView
|
||||
android:id="@+id/mapBizView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
<!--高精地图-->
|
||||
<com.mogo.eagle.core.function.view.MapBizView
|
||||
android:id="@+id/mapBizView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:isWeatherEnable="false"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
app:isWeatherEnable="false"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!--高德地图-->
|
||||
<com.mogo.eagle.core.function.view.TravelRealityView
|
||||
android:id="@+id/overMapView"
|
||||
android:layout_width="270dp"
|
||||
android:layout_height="270dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
app:roadRangeDrawable="@drawable/taxi_overmap_road_range"
|
||||
app:roadTrajectoryDrawable="@drawable/taxi_orvermap_road_trajectory"
|
||||
app:globalPathColor="#39BA90"
|
||||
app:carDrawable="@drawable/taxt_u_p_map_car"
|
||||
app:compassDrawable="@drawable/taxt_u_p_map_car_light"
|
||||
app:endPointDrawable="@drawable/taxi_overmap_endpoint"
|
||||
app:mapStyleExtraPath="over_view_style_extra.data"
|
||||
app:mapStylePath="over_view_style.data"
|
||||
app:resetDrawable="@null"
|
||||
app:leftPadding="70"
|
||||
app:topPadding="70"
|
||||
app:rightPadding="70"
|
||||
app:bottomPadding="160"
|
||||
/>
|
||||
</com.mogo.eagle.core.function.hmi.map.ExchangeChildLayout>
|
||||
<!--高德地图-->
|
||||
<com.mogo.eagle.core.function.view.TravelRealityView
|
||||
android:id="@+id/overMapView"
|
||||
android:layout_width="270dp"
|
||||
android:layout_height="270dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
app:bottomPadding="160"
|
||||
app:carDrawable="@drawable/taxt_u_p_map_car"
|
||||
app:compassDrawable="@drawable/taxt_u_p_map_car_light"
|
||||
app:endPointDrawable="@drawable/taxi_overmap_endpoint"
|
||||
app:globalPathColor="#39BA90"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:leftPadding="70"
|
||||
app:mapStyleExtraPath="over_view_style_extra.data"
|
||||
app:mapStylePath="over_view_style.data"
|
||||
app:resetDrawable="@null"
|
||||
app:rightPadding="70"
|
||||
app:roadRangeDrawable="@drawable/taxi_overmap_road_range"
|
||||
app:roadTrajectoryDrawable="@drawable/taxi_orvermap_road_trajectory"
|
||||
app:topPadding="70" />
|
||||
|
||||
<View
|
||||
android:id="@+id/shadowView"
|
||||
android:layout_width="270dp"
|
||||
android:layout_height="270dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user