[6.5.0][道路事件] 绿波通行UI开发
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
package com.mogo.eagle.core.function.hmi.ui.greenwave
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Looper
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.eagle.core.data.map.MogoLocation
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.utilcode.kotlin.scope
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.eagle.core.utilcode.rv.divider.CommonDividerItemDecoration
|
||||
import com.mogo.eagle.core.utilcode.util.SizeUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import kotlinx.coroutines.Runnable
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.abs
|
||||
import kotlinx.android.synthetic.main.view_green_wave_passenger_layout.view.speed as passenger_speed
|
||||
import kotlinx.android.synthetic.main.view_green_wave_driver_layout.view.speed as driver_speed
|
||||
import kotlinx.android.synthetic.main.view_green_wave_passenger_layout.view.wave_rv as passenger_wave_rv
|
||||
import kotlinx.android.synthetic.main.view_green_wave_driver_layout.view.wave_rv as driver_wave_rv
|
||||
import kotlinx.android.synthetic.main.view_green_wave_passenger_layout.view.recommend_speed as passenger_recommend_speed
|
||||
import kotlinx.android.synthetic.main.view_green_wave_driver_layout.view.recommend_speed as driver_recommend_speed
|
||||
import kotlinx.android.synthetic.main.view_green_wave_passenger_layout.view.recommend_cross as passenger_recommend_cross
|
||||
import kotlinx.android.synthetic.main.view_green_wave_driver_layout.view.recommend_cross as driver_recommend_cross
|
||||
|
||||
class GreenWaveView: LinearLayout, IMoGoChassisLocationGCJ02Listener, RecyclerView.OnItemTouchListener, Runnable {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "GreenWaveView"
|
||||
}
|
||||
|
||||
private var lastSpeed: Int = Int.MIN_VALUE
|
||||
|
||||
constructor(context: Context) : this(context, null)
|
||||
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
||||
LayoutInflater.from(context).inflate(if (isDriver) R.layout.view_green_wave_driver_layout else R.layout.view_green_wave_passenger_layout, this)
|
||||
background = if (isDriver) ContextCompat.getDrawable(context, R.drawable.bg_green_wave_driver) else ContextCompat.getDrawable(context, R.drawable.bg_green_wave_passenger)
|
||||
}
|
||||
|
||||
private val isDriver by lazy {
|
||||
AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)
|
||||
}
|
||||
|
||||
private class WaveHolder(item: ImageView): RecyclerView.ViewHolder(item)
|
||||
|
||||
private class WaveAdapter: RecyclerView.Adapter<WaveHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WaveHolder {
|
||||
val item = ImageView(parent.context)
|
||||
item.layoutParams = RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||
return WaveHolder(item)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return 5000
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: WaveHolder, position: Int) {
|
||||
val item = holder.itemView as? ImageView ?: return
|
||||
val reminder = position % 3
|
||||
when(reminder) {
|
||||
0 -> {
|
||||
item.background = ContextCompat.getDrawable(item.context, R.drawable.icon_green_wave_alpha_low)
|
||||
}
|
||||
1 -> {
|
||||
item.background = ContextCompat.getDrawable(item.context, R.drawable.icon_green_wave_alpha_mid)
|
||||
}
|
||||
else -> {
|
||||
item.background = ContextCompat.getDrawable(item.context, R.drawable.icon_green_wave_alpha_high)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 5, this)
|
||||
val rv: RecyclerView? = if (isDriver) driver_wave_rv else passenger_wave_rv
|
||||
rv?.addItemDecoration(CommonDividerItemDecoration.Builder()
|
||||
.spanCountTBCare(false)
|
||||
.horizontalInnerSpace(SizeUtils.dp2px(10f))
|
||||
.build())
|
||||
rv?.addOnItemTouchListener(this)
|
||||
rv?.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, true)
|
||||
rv?.adapter = WaveAdapter()
|
||||
startAutoScroll()
|
||||
}
|
||||
|
||||
private fun startAutoScroll() {
|
||||
removeCallbacks(this)
|
||||
post(this)
|
||||
}
|
||||
|
||||
private fun stopAutoScroll() {
|
||||
removeCallbacks(this)
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
val rv: RecyclerView? = if (isDriver) driver_wave_rv else passenger_wave_rv
|
||||
rv?.scrollBy(-3, 0)
|
||||
postDelayed(this, 20)
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) { }
|
||||
|
||||
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) { }
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
CallerChassisLocationGCJ02ListenerManager.removeListener(TAG)
|
||||
val rv: RecyclerView? = if (isDriver) driver_wave_rv else passenger_wave_rv
|
||||
rv?.removeOnItemTouchListener(this)
|
||||
stopAutoScroll()
|
||||
}
|
||||
|
||||
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
|
||||
var isChanged = false
|
||||
val speed = (abs(mogoLocation?.gnssSpeed ?: 0f) * 3.6f).toInt()
|
||||
if (lastSpeed != speed) {
|
||||
isChanged = true
|
||||
lastSpeed = speed
|
||||
}
|
||||
if (isChanged) {
|
||||
UiThreadHandler.post {
|
||||
if (isDriver) {
|
||||
driver_speed?.text = speed.toString()
|
||||
} else {
|
||||
passenger_speed?.text = speed.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(minSpeed: Int, maxSpeed: Int, cross: Int) {
|
||||
scope.launch {
|
||||
if (isDriver) {
|
||||
driver_recommend_speed?.text = "建议车速${minSpeed}-${maxSpeed}km/h"
|
||||
driver_recommend_cross?.text = "可丝滑通过${cross}个路口"
|
||||
} else {
|
||||
passenger_recommend_speed?.text = "建议车速${minSpeed}-${maxSpeed}km/h"
|
||||
passenger_recommend_cross?.text = "可丝滑通过${cross}个路口"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="@dimen/dp_16" />
|
||||
<solid android:color="#43D1A6" />
|
||||
</shape>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="@dimen/dp_16" />
|
||||
<gradient
|
||||
android:startColor="#68E0BB"
|
||||
android:endColor="#b072ECC3"/>
|
||||
</shape>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<size android:width="@dimen/dp_90" android:height="@dimen/dp_90" />
|
||||
<solid android:color="#FFFFFF" />
|
||||
</shape>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<size android:width="@dimen/dp_90" android:height="@dimen/dp_90" />
|
||||
<gradient
|
||||
android:startColor="#BADDFFF3"
|
||||
android:endColor="#FFFFFF"
|
||||
android:angle="-45"/>
|
||||
</shape>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:background="@drawable/bg_green_wave_driver"
|
||||
tools:layout_height="wrap_content"
|
||||
tools:layout_width="wrap_content"
|
||||
tools:parentTag="android.widget.LinearLayout">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="@dimen/dp_90"
|
||||
android:layout_height="@dimen/dp_90"
|
||||
android:layout_marginStart="@dimen/dp_20"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
android:layout_marginBottom="@dimen/dp_20"
|
||||
android:background="@drawable/bg_white_circle_driver"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/speed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="-5dp"
|
||||
android:textColor="#43D1AB"
|
||||
android:textSize="@dimen/sp_34"
|
||||
tools:text="56" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="km/h"
|
||||
android:textColor="#43D1A6"
|
||||
android:textSize="@dimen/sp_14" />
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/wave_rv"
|
||||
android:layout_width="@dimen/dp_400"
|
||||
android:layout_height="@dimen/dp_129"
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="@dimen/dp_30"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recommend_speed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/dp_4"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="@dimen/dp_30"
|
||||
tools:text="建议车速45-60km/h" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recommend_cross"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#b0ffffff"
|
||||
android:textSize="@dimen/dp_20"
|
||||
tools:text="可丝滑通过2个路口" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</merge>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:parentTag="android.widget.LinearLayout"
|
||||
tools:layout_width="wrap_content"
|
||||
tools:layout_height="wrap_content"
|
||||
tools:gravity="center_vertical"
|
||||
tools:background="@drawable/bg_green_wave_passenger">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="@dimen/dp_108"
|
||||
android:layout_height="@dimen/dp_108"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/bg_white_circle_passenger"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:layout_marginStart="@dimen/dp_34"
|
||||
android:layout_marginTop="@dimen/dp_24"
|
||||
android:layout_marginBottom="@dimen/dp_24"
|
||||
android:gravity="center">
|
||||
<TextView
|
||||
android:id="@+id/speed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/dp_49"
|
||||
android:textColor="#0F664B"
|
||||
android:layout_marginBottom="-5dp"
|
||||
tools:text="56"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/dp_18"
|
||||
android:textColor="#0F664B"
|
||||
android:text="km/h" />
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/wave_rv"
|
||||
android:layout_width="@dimen/dp_400"
|
||||
android:layout_height="@dimen/dp_155"
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_29"
|
||||
android:layout_centerVertical="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recommend_speed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/dp_33"
|
||||
android:textColor="#004A35"
|
||||
android:layout_marginBottom="@dimen/dp_4"
|
||||
tools:text="建议车速45-60km/h" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recommend_cross"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/dp_22"
|
||||
android:textColor="#004A35"
|
||||
tools:text="可丝滑通过2个路口" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
</merge>
|
||||
Reference in New Issue
Block a user