[自定义小地图]
This commit is contained in:
yangyakun
2024-03-13 17:23:15 +08:00
parent 4b850e35af
commit 86a8509237
20 changed files with 962 additions and 94 deletions

View File

@@ -126,14 +126,14 @@ class MusicPlayingView : ConstraintLayout, MusicPlayingViewModel.IMusicPlayingVi
sb_musuc_progess.progress=0.toInt()
}
Glide.with(context)
.load(musicData.coverHeadImageUrl)
.apply(RequestOptions().placeholder(R.drawable.charter_p_music_bg_relax_head))
.into(iv_music_cover)
Glide.with(context)
.load(musicData.coverBottomImageUrl)
.apply(RequestOptions().placeholder(R.drawable.charter_p_music_bg_relax_bottom))
.into(iv_music_cover_bg)
// Glide.with(context)
// .load(musicData.coverHeadImageUrl)
// .apply(RequestOptions().placeholder(R.drawable.charter_p_music_bg_relax_head))
// .into(iv_music_cover)
// Glide.with(context)
// .load(musicData.coverBottomImageUrl)
// .apply(RequestOptions().placeholder(R.drawable.charter_p_music_bg_relax_bottom))
// .into(iv_music_cover_bg)
}
private fun startAnimal(){
@@ -142,8 +142,8 @@ class MusicPlayingView : ConstraintLayout, MusicPlayingViewModel.IMusicPlayingVi
animator = null
}
animator = ObjectAnimator.ofFloat(iv_music_cover, "rotation", 0f, 360f)
iv_music_cover.pivotX = (iv_music_cover.getWidth() / 2).toFloat()
iv_music_cover.pivotY = iv_music_cover.height*174.5f/390f
iv_music_cover.pivotX = (iv_music_cover.width / 2).toFloat()
iv_music_cover.pivotY = (iv_music_cover.height / 2).toFloat()
animator?.duration = 4000
animator?.repeatCount = -1
animator?.repeatMode = ValueAnimator.RESTART

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

View File

@@ -4,14 +4,14 @@
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dp"/>
<solid android:color="@color/charter_p_488ED0" />
<solid android:color="@color/charter_p_1A488ED0" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dp"/>
<solid android:color="@color/charter_p_488ED0" />
<solid android:color="@color/charter_p_1A488ED0" />
</shape>
</clip>
</item>

View File

@@ -13,27 +13,29 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="@drawable/charter_p_music_bg_relax_bottom"
android:layout_width="@dimen/dp_358"
android:layout_height="@dimen/dp_440"/>
<ImageView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="@dimen/dp_45"
android:src="@drawable/charter_p_music_bg_middle"
android:layout_width="@dimen/dp_187"
android:layout_height="@dimen/dp_187"/>
android:layout_width="@dimen/dp_197"
android:layout_height="@dimen/dp_242"/>
<ImageView
android:id="@+id/iv_music_cover"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="@dimen/dp_45"
android:layout_marginTop="@dimen/dp_54"
android:src="@drawable/charter_p_music_bg_relax_head"
android:layout_width="@dimen/dp_187"
android:layout_height="@dimen/dp_187"/>
android:layout_width="@dimen/dp_140_4"
android:layout_height="@dimen/dp_140_4"/>
<ImageView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="@dimen/dp_43"
android:src="@drawable/charter_p_music_bg_middle"
android:layout_width="@dimen/dp_190"
android:layout_height="@dimen/dp_190"/>
<TextView
@@ -41,7 +43,7 @@
app:layout_constraintTop_toBottomOf="@+id/iv_music_cover"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="@dimen/dp_m_17"
android:layout_marginTop="@dimen/dp_30"
android:textSize="@dimen/dp_21"
tools:text="Current"
android:textColor="@color/charter_p_303C52"
@@ -81,7 +83,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_author"
android:layout_marginTop="@dimen/dp_28"
android:progressDrawable="@drawable/taxt_p_music_seekbar_style"
android:progressDrawable="@drawable/charter_p_music_seekbar_style"
android:paddingTop="3dp"
android:paddingBottom="@dimen/dp_3"
android:layout_width="@dimen/dp_270"

View File

@@ -60,6 +60,8 @@
<color name="charter_p_425877">#425877</color>
<color name="charter_p_576887">#576887</color>
<color name="charter_p_488ED0">#488ED0</color>
<color name="charter_p_1A488ED0">#1A488ED0</color>
<color name="charter_p_598CFF">#598CFF</color>
<color name="charter_p_4D6A83A5">#4D6A83A5</color>
<color name="charter_p_6A83A5">#6A83A5</color>

View File

@@ -36,7 +36,7 @@
android:layout_marginEnd="@dimen/dp_12"
android:layout_marginStart="@dimen/dp_93"
android:textColor="@color/taxi_p_004DC4"
android:textSize="@dimen/dp_35"
android:textSize="@dimen/dp_38"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_top"
app:layout_constraintBottom_toBottomOf="@+id/gl_horizontal_center"
@@ -44,19 +44,44 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_endstation"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLength="25"
android:maxLines="1"
android:layout_marginStart="@dimen/dp_7"
android:textColor="@color/taxi_p_293449"
android:textSize="@dimen/dp_35"
android:textSize="@dimen/dp_38"
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_top"
app:layout_constraintBottom_toBottomOf="@+id/gl_horizontal_center"
app:layout_constraintEnd_toStartOf="@+id/actv_arrived_time_unit"
app:layout_constraintStart_toEndOf="@+id/actv_endstation_title"
android:text="--" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_arrived_time_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/taxi_p_004DC4"
android:textSize="@dimen/dp_38"
android:layout_marginEnd="@dimen/dp_8"
app:layout_constraintEnd_toStartOf="@+id/actv_arrived_time"
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_top"
app:layout_constraintBottom_toBottomOf="@+id/gl_horizontal_center"
android:text="到达" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_arrived_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:textColor="@color/taxi_p_203555"
android:textSize="@dimen/dp_38"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="@dimen/dp_97"
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_top"
app:layout_constraintBottom_toBottomOf="@+id/gl_horizontal_center"
tools:text="15:05" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_distance"
@@ -95,7 +120,7 @@
android:textSize="@dimen/dp_61"
android:fontFamily="@font/din"
android:textColor="@color/taxi_p_081831"
app:layout_constraintEnd_toStartOf="@+id/actv_arrived_time"
app:layout_constraintEnd_toStartOf="@+id/ll_simplemap_contain"
app:layout_constraintStart_toEndOf="@+id/actv_distance"
app:layout_constraintTop_toTopOf="@+id/actv_distance"
android:text="--" />
@@ -111,30 +136,60 @@
app:layout_constraintStart_toStartOf="@+id/actv_surplus_time"
app:layout_constraintEnd_toEndOf="@+id/actv_surplus_time" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_arrived_time"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll_simplemap_contain"
android:layout_width="0dp"
android:gravity="center"
android:layout_height="wrap_content"
android:textSize="@dimen/dp_61"
android:textColor="@color/taxi_p_081831"
android:layout_marginEnd="@dimen/dp_58"
android:text="--"
android:fontFamily="@font/din"
app:layout_constraintBottom_toTopOf="@+id/progress_distance"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/actv_surplus_time"
app:layout_constraintTop_toTopOf="@+id/actv_distance" />
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_center">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_arrived_time_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/taxi_p_112B57"
android:textSize="@dimen/dp_33"
android:text="到达"
app:layout_constraintTop_toBottomOf="@+id/actv_arrived_time"
app:layout_constraintStart_toStartOf="@+id/actv_arrived_time"
app:layout_constraintEnd_toEndOf="@+id/actv_arrived_time" />
<com.mogo.och.taxi.passenger.ui.simplemap.SimpleMapView
android:id="@+id/simpleMap"
android:layout_width="@dimen/dp_180"
android:layout_height="@dimen/dp_180"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- <com.mogo.och.taxi.passenger.ui.simplemap.SimpleMapView-->
<!-- android:id="@+id/simpleMap"-->
<!-- app:layout_constraintTop_toTopOf="@+id/gl_horizontal_center"-->
<!-- app:layout_constraintBottom_toTopOf="@+id/progress_distance"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- android:layout_marginEnd="@dimen/dp_58"-->
<!-- android:layout_width="@dimen/dp_180"-->
<!-- android:layout_height="@dimen/dp_180"/>-->
<!-- <androidx.appcompat.widget.AppCompatTextView-->
<!-- android:id="@+id/actv_arrived_time"-->
<!-- android:layout_width="0dp"-->
<!-- android:gravity="center"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:textSize="@dimen/dp_61"-->
<!-- android:textColor="@color/taxi_p_081831"-->
<!-- android:layout_marginEnd="@dimen/dp_58"-->
<!-- android:text="&#45;&#45;"-->
<!-- android:fontFamily="@font/din"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toEndOf="@+id/actv_surplus_time"-->
<!-- app:layout_constraintTop_toTopOf="@+id/actv_distance" />-->
<!-- <androidx.appcompat.widget.AppCompatTextView-->
<!-- android:id="@+id/actv_arrived_time_unit"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:textColor="@color/taxi_p_112B57"-->
<!-- android:textSize="@dimen/dp_33"-->
<!-- android:text="到达"-->
<!-- app:layout_constraintTop_toBottomOf="@+id/actv_arrived_time"-->
<!-- app:layout_constraintStart_toStartOf="@+id/actv_arrived_time"-->
<!-- app:layout_constraintEnd_toEndOf="@+id/actv_arrived_time" />-->
<ProgressBar
android:id="@+id/progress_distance"

View File

@@ -143,7 +143,7 @@ class MusicPlayingView : ConstraintLayout, MusicPlayingViewModel.IMusicPlayingVi
}
animator = ObjectAnimator.ofFloat(iv_music_cover, "rotation", 0f, 360f)
iv_music_cover.pivotX = (iv_music_cover.getWidth() / 2).toFloat()
iv_music_cover.pivotY = 174.5f
iv_music_cover.pivotY = (iv_music_cover.height / 2).toFloat()
animator?.duration = 4000
animator?.repeatCount = -1
animator?.repeatMode = ValueAnimator.RESTART

View File

@@ -5,8 +5,10 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.commons.voice.AIAssist
import com.mogo.eagle.core.utilcode.kotlin.onClick
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.och.common.module.voice.VoiceNotice
import com.mogo.och.taxi.passenger.common.R
import kotlinx.android.synthetic.main.taxi_p_rightbar.view.ck_music
import kotlinx.android.synthetic.main.taxi_p_rightbar.view.ck_setting
@@ -63,6 +65,10 @@ class RightBarView : ConstraintLayout {
}
iv_center_location.onClick {
this.rightBarCallback?.setGo2CenterClick()
VoiceNotice.showNotice(
"想和我对话的时候可以直接戳我,也可以对我说\\'你好小智\\'",
AIAssist.LEVEL2
)
}
}

View File

@@ -0,0 +1,5 @@
package com.mogo.och.taxi.passenger.ui.simplemap
import android.graphics.Paint
data class LineData(val startPoint:NearPointView, val endPoint: NearPointView, val distance:Float, var paint: Paint)

View File

@@ -0,0 +1,10 @@
package com.mogo.och.taxi.passenger.ui.simplemap
import com.mogo.eagle.core.data.map.MogoLocation
/**
* index 点的坐标
* location 点的经纬度
* distance 点距离车的位置
*/
data class NearPoint(val index:Int, val location: MogoLocation, val distance:Float)

View File

@@ -0,0 +1,5 @@
package com.mogo.och.taxi.passenger.ui.simplemap
import android.graphics.Paint
data class NearPointView(val x:Float, val y: Float, val distance:Float)

View File

@@ -0,0 +1,685 @@
package com.mogo.och.taxi.passenger.ui.simplemap
import android.animation.ArgbEvaluator
import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.LinearGradient
import android.graphics.Matrix
import android.graphics.Paint
import android.graphics.Path
import android.graphics.Shader
import android.util.AttributeSet
import android.util.Log
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil
import com.mogo.och.taxi.passenger.common.R
import kotlin.math.cos
import kotlin.math.sin
class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback {
private val TAG = "EvaluateView"
constructor(context: Context) : super(context)
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet)
constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super(context, attributeSet, defStyleAttr)
constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attributeSet, defStyleAttr, defStyleRes)
//定义、并创建画笔
var p = Paint().apply {
strokeWidth = 4f
isAntiAlias = true
color = Color.RED
}
var pLine = Paint().apply {
strokeWidth = 10f
isAntiAlias = true
style = Paint.Style.STROKE
color = Color.BLUE
}
var bmBlockWidth = 0
var bmBlockHeight = 0
var widthView = 0
var heighView = 0
var proportion = 0f
var preLineData = mutableListOf<LineData>()
var nextLineData = mutableListOf<LineData>()
val bmBlock = BitmapFactory.decodeResource(resources, R.drawable.taxi_navi_arrow_icon).also {
bmBlockWidth = it.width
bmBlockHeight = it.height
}
val matrixArrow = Matrix()
var evaluator = ArgbEvaluator()
private var viewModel: SimpleMapViewModel?=null
override fun onAttachedToWindow() {
super.onAttachedToWindow()
viewModel = findViewTreeViewModelStoreOwner()?.let {
ViewModelProvider(it).get(SimpleMapViewModel::class.java)
}
viewModel?.setViewCallback(this)
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
widthView = width
heighView = height
proportion = widthView / 500f
matrixArrow.setTranslate(
(width / 2 - bmBlockWidth / 2).toFloat(),
(height / 2 - bmBlockHeight / 2).toFloat()
)
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
var startPointNextUse:NearPointView? = null
var secondPointNextUse:NearPointView? = null
nextLineData.forEachIndexed { index, lineData ->
val startPoint = lineData.startPoint
val endPoint = lineData.endPoint
if(index==0) {
val line4Point = getLine4Point(startPoint, endPoint, true)
Log.d(
"DrawLineView_startPoint",
"${startPoint.x}------${startPoint.y}--${startPoint.distance}--------${endPoint.x}------${endPoint.y}----${endPoint.distance}"
)
val path = Path()
val D = line4Point[0]
val F = line4Point[1]
val I = line4Point[2]
val G = line4Point[3]
path.moveTo(D.x,D.y)
path.lineTo(F.x,F.y)
path.lineTo(I.x,I.y)
path.lineTo(G.x,G.y)
startPointNextUse = I
secondPointNextUse = G
path.close()
canvas.drawPath(path,lineData.paint)
}else{
val line4Point = getLine4Point(startPoint, endPoint, false)
val path = Path()
path.moveTo(startPointNextUse!!.x,startPointNextUse!!.y)
path.lineTo(secondPointNextUse!!.x,secondPointNextUse!!.y)
val tempStart = line4Point[0]
val tempEnd = line4Point[1]
path.lineTo(tempStart.x,tempStart.y)
path.lineTo(tempEnd.x,tempEnd.y)
startPointNextUse = tempEnd
secondPointNextUse = tempStart
canvas.drawPath(path,lineData.paint)
}
}
preLineData.forEachIndexed { index, lineData ->
val startPoint = lineData.startPoint
val endPoint = lineData.endPoint
if(index==0) {
val line4Point = getLine4Point(startPoint, endPoint, true)
val path = Path()
val D = line4Point[0]
val F = line4Point[1]
val I = line4Point[2]
val G = line4Point[3]
path.moveTo(D.x,D.y)
path.lineTo(F.x,F.y)
path.lineTo(I.x,I.y)
path.lineTo(G.x,G.y)
startPointNextUse = I
secondPointNextUse = G
path.close()
canvas.drawPath(path,lineData.paint)
}else{
val line4Point = getLine4Point(startPoint, endPoint, false)
val path = Path()
path.moveTo(startPointNextUse!!.x,startPointNextUse!!.y)
path.lineTo(secondPointNextUse!!.x,secondPointNextUse!!.y)
val tempStart = line4Point[0]
val tempEnd = line4Point[1]
path.lineTo(tempStart.x,tempStart.y)
path.lineTo(tempEnd.x,tempEnd.y)
startPointNextUse = tempEnd
secondPointNextUse = tempStart
canvas.drawPath(path,lineData.paint)
}
}
canvas.drawBitmap(bmBlock, matrixArrow, p)
}
fun getLine4Point(A: NearPointView, B: NearPointView, isFirst: Boolean):List<NearPointView> {
val reuslt = mutableListOf<NearPointView>()
// 120 80 120 80 (80,80) (120,120)
if (B.y > A.y && B.x > A.x) {
val AD = 5f
val BG = 5f
val BC = B.x-A.x
val AB = B.distance
val AC = B.y-A.y
val DE=AD*BC/AB
val GH=BG*BC/AB
val AE=AD*AC/AB
val BH=BG*AC/AB
val gx = B.x-BH
val gy = B.y+GH
val Ix = B.x+BH
val Iy = B.y-GH
// D点坐吧
val dx = A.x-AE
val dy = A.y+DE
val fx = A.x+AE
val fy = A.y-DE
if(isFirst){
reuslt.add(NearPointView(dx,dy,0f))
reuslt.add(NearPointView(fx,fy,0f))
reuslt.add(NearPointView(Ix,Iy,0f))
reuslt.add(NearPointView(gx,gy,0f))
}else{
reuslt.add(NearPointView(gx,gy,0f))
reuslt.add(NearPointView(Ix,Iy,0f))
}
}
// 120 80 80 120 (120,80) (80,120)
if (B.y > A.y && B.x < A.x) {
val AD = 5f
val BC = A.x-B.x
val AB = B.distance
val BG = 5f
val AC = B.y-A.y
val DE=AD*BC/AB
val GH=BG*BC/AB
val AE=AD*AC/AB
val BH=BG*AC/AB
val gx = B.x+BH
val gy = B.y+GH
val Ix = B.x-BH
val Iy = B.y-GH
// D点坐吧
val dx = A.x-AE
val dy = A.y-DE
val fx = A.x+AE
val fy = A.y+DE
if(isFirst){
reuslt.add(NearPointView(dx,dy,0f))
reuslt.add(NearPointView(fx,fy,0f))
reuslt.add(NearPointView(gx,gy,0f))
reuslt.add(NearPointView(Ix,Iy,0f))
}else{
reuslt.add(NearPointView(Ix,Iy,0f))
reuslt.add(NearPointView(gx,gy,0f))
}
}
// 80 120 80 120 (120,120) (80,80)
if (B.y < A.y && B.x < A.x) {
val AD = 5f
val BC = A.y-B.y
val AB = B.distance
val AC = A.x-B.x
val AE=AD*BC/AB
val DE=AD*AC/AB
// D点坐吧
val dx = A.x-AE
val dy = A.y+DE
val fx = A.x+AE
val fy = A.y-DE
val BG = 5f
val GH= BG*BC/AB
val BH= BG*AC/AB
val gx = B.x-GH
val gy = B.y+BH
val Ix = B.x+GH
val Iy = B.y-BH
if(isFirst){
reuslt.add(NearPointView(fx,fy,0f))
reuslt.add(NearPointView(dx,dy,0f))
reuslt.add(NearPointView(gx,gy,0f))
reuslt.add(NearPointView(Ix,Iy,0f))
}else{
reuslt.add(NearPointView(Ix,Iy,0f))
reuslt.add(NearPointView(gx,gy,0f))
}
}
// 80 120 120 80 (80,120) (120,80)
if (B.y < A.y && B.x > A.x) {
val AD = 5f
val AC = B.x-A.x
val AB = B.distance
val BG = 5f
val BC = A.y-B.y
val DE=AD*AC/AB
val GH=BG*AC/AB
val AE=AD*BC/AB
val BH=BG*BC/AB
// D点坐吧
val dx = A.x-AE
val dy = A.y-DE
val fx = A.x+AE
val fy = A.y+DE
val gx = B.x+BH
val gy = B.y+GH
val Ix = B.x-BH
val Iy = B.y-GH
if(isFirst){
reuslt.add(NearPointView(fx,fy,0f))
reuslt.add(NearPointView(dx,dy,0f))
reuslt.add(NearPointView(Ix,Iy,0f))
reuslt.add(NearPointView(gx,gy,0f))
}else{
reuslt.add(NearPointView(gx,gy,0f))
reuslt.add(NearPointView(Ix,Iy,0f))
}
}
return reuslt
}
/**
* 获取两条线的夹角
* @param centerX
* @param centerY
* @param xInView
* @param yInView
* @return
*/
fun getRotationBetweenLines(
prePoint: NearPointView,
current: NearPointView,
nextPoint: NearPointView,
): Pair<Double, Boolean>? {
val degreesAB = Math.toDegrees(
Math.atan2(
(prePoint.y - current.y).toDouble(),
(prePoint.x - current.x).toDouble()
)
)
val degreesBC = Math.toDegrees(
Math.atan2(
(current.y - nextPoint.y).toDouble(),
(current.x - nextPoint.x).toDouble()
)
)
// 120 80 120 80 (80,80) (120,120)
if (current.y > prePoint.y && current.x > prePoint.x) {
if (degreesAB > degreesBC) {
return Pair(degreesAB - 90, true)
} else {
return Pair(degreesAB + 90, false)
}
}
// 120 80 80 120 (120,80) (80,120)
if (current.y > prePoint.y && current.x < prePoint.x) {
if (degreesAB > degreesBC) {
return Pair(270-degreesAB, false)
} else {
return Pair(degreesAB-90, false)
}
}
// 80 120 80 120 (120,120) (80,80)
if (current.y < prePoint.y && current.x < prePoint.x) {
if(degreesBC>0&&degreesBC<degreesAB+180){
return Pair(270-degreesAB, true)
}else if(degreesBC>degreesAB+180&&degreesBC<180){
return Pair(degreesAB + 90, false)
}else if(degreesBC>-180&&degreesBC<degreesAB){
return Pair(degreesAB + 90, false)
}else if(degreesBC<0&&degreesBC>degreesAB){
return Pair(270-degreesAB, true)
}
}
// 80 120 120 80 (80,120) (120,80)
if (current.y < prePoint.y && current.x > prePoint.x) {
if (degreesAB > degreesBC) {
return Pair(degreesAB + 90, false)
} else {
return Pair(degreesAB - 90, true)
}
}
return null
}
@Synchronized
override fun setData(carLocation: MogoLocation, nextList: MutableList<NearPoint>, preList: MutableList<NearPoint>) {
var nextPointMaxLength = 0f
var prePointMaxLength = 0f
val nextPointList = mutableListOf<NearPointView>()
nextLineData.clear()
nextList.forEachIndexed { index, currentPoint ->
val headingAngle = CoordinateCalculateRouteUtil.getHeadingAngle(
carLocation.longitude,
carLocation.latitude,
currentPoint.location.longitude,
currentPoint.location.latitude
)
val distancePx = currentPoint.distance * proportion
var x = 0f
var y = 0f
if (headingAngle == 0.0) {
x = (widthView / 2).toFloat()
y = (heighView / 2) - distancePx
} else if (headingAngle > 0 && headingAngle < 90) {
val xDistance = distancePx * sin(Math.toRadians(headingAngle))
val yDistance = distancePx * cos(Math.toRadians(headingAngle))
x = ((widthView / 2) + xDistance).toFloat()
y = ((heighView / 2) - yDistance).toFloat()
} else if (headingAngle == 90.0) {
x = widthView / 2 + distancePx
y = (heighView / 2).toFloat()
} else if (headingAngle > 90 && headingAngle < 180) {
val xDistance = distancePx * sin(Math.toRadians(180 - headingAngle))
val yDistance = distancePx * cos(Math.toRadians(180 - headingAngle))
x = (widthView / 2 + xDistance).toFloat()
y = (heighView / 2 + yDistance).toFloat()
} else if (headingAngle == 180.0) {
x = (widthView / 2).toFloat()
y = (heighView / 2) + distancePx
} else if (headingAngle > 180 && headingAngle < 270) {
val xDistance = distancePx * sin(Math.toRadians(headingAngle - 180))
val yDistance = distancePx * cos(Math.toRadians(headingAngle - 180))
x = (widthView / 2 - xDistance).toFloat()
y = (heighView / 2 + yDistance).toFloat()
} else if (headingAngle == 270.0) {
x = (widthView / 2) - distancePx
y = (heighView / 2).toFloat()
} else if (headingAngle > 270 && headingAngle < 360) {
val xDistance = distancePx * sin(Math.toRadians(360 - headingAngle))
val yDistance = distancePx * cos(Math.toRadians(360 - headingAngle))
x = (widthView / 2 - xDistance).toFloat()
y = (heighView / 2 - yDistance).toFloat()
} else if (headingAngle == 360.0) {
x = (widthView / 2).toFloat()
y = (heighView / 2) - distancePx
}
if (index == 0) {
val distancePx = CoordinateUtils.calculateLineDistance(
carLocation.longitude,
carLocation.latitude,
currentPoint.location.longitude,
currentPoint.location.latitude
) * proportion
nextPointList.add(NearPointView(x, y, distancePx))
nextPointMaxLength += distancePx
} else {
val prePoint = nextList[index - 1]
val distancePx = CoordinateUtils.calculateLineDistance(
prePoint.location.longitude,
prePoint.location.latitude,
currentPoint.location.longitude,
currentPoint.location.latitude
) * proportion
nextPointList.add(NearPointView(x, y, distancePx))
nextPointMaxLength += distancePx
}
}
val prePointList = mutableListOf<NearPointView>()
preLineData.clear()
preList.forEachIndexed { index, currentPoint ->
val headingAngle = CoordinateCalculateRouteUtil.getHeadingAngle(
carLocation.longitude,
carLocation.latitude,
currentPoint.location.longitude,
currentPoint.location.latitude
)
val distancePx = currentPoint.distance * proportion
var x = 0f
var y = 0f
if (headingAngle == 0.0) {
x = (widthView / 2).toFloat()
y = (heighView / 2) - distancePx
} else if (headingAngle > 0 && headingAngle < 90) {
val xDistance = distancePx * sin(Math.toRadians(headingAngle))
val yDistance = distancePx * cos(Math.toRadians(headingAngle))
x = (widthView / 2 + xDistance).toFloat()
y = (heighView / 2 - yDistance).toFloat()
} else if (headingAngle == 90.0) {
x = widthView / 2 + distancePx
y = (heighView / 2).toFloat()
} else if (headingAngle > 90 && headingAngle < 180) {
val xDistance = distancePx * sin(Math.toRadians(180 - headingAngle))
val yDistance = distancePx * cos(Math.toRadians(180 - headingAngle))
x = (widthView / 2 + xDistance).toFloat()
y = (heighView / 2 + yDistance).toFloat()
} else if (headingAngle == 180.0) {
x = (widthView / 2).toFloat()
y = (heighView / 2) + distancePx
} else if (headingAngle > 180 && headingAngle < 270) {
val xDistance = distancePx * sin(Math.toRadians(headingAngle - 180))
val yDistance = distancePx * cos(Math.toRadians(headingAngle - 180))
x = (widthView / 2 - xDistance).toFloat()
y = (heighView / 2 + yDistance).toFloat()
} else if (headingAngle == 270.0) {
x = (widthView / 2) - distancePx
y = (heighView / 2).toFloat()
} else if (headingAngle > 270 && headingAngle < 360) {
val xDistance = distancePx * sin(Math.toRadians(360 - headingAngle))
val yDistance = distancePx * cos(Math.toRadians(360 - headingAngle))
x = ((widthView / 2) - xDistance).toFloat()
y = ((heighView / 2) - yDistance).toFloat()
} else if (headingAngle == 360.0) {
x = (widthView / 2).toFloat()
y = (heighView / 2) - distancePx
}
if (index == 0) {
prePointList.add(NearPointView(x, y, distancePx))
prePointMaxLength += distancePx
} else {
val prePoint = preList[index - 1]
val distancePx = CoordinateUtils.calculateLineDistance(
prePoint.location.longitude,
prePoint.location.latitude,
currentPoint.location.longitude,
currentPoint.location.latitude
) * proportion
prePointList.add(NearPointView(x, y, distancePx))
prePointMaxLength += distancePx
}
}
var hasDraw = 0f
var lastColor = Color.parseColor("#2ED3FF")
nextPointList.forEachIndexed { index, triple ->
val paint = Paint()
paint.apply {
strokeWidth = 20f
isAntiAlias = true
}
val colorPencent = if (index == nextPointList.size - 1) {
1f
} else {
(triple.distance + hasDraw) / nextPointMaxLength
}
val evaluateColor = evaluator.evaluate(
colorPencent,
Color.parseColor("#2ED3FF"),
Color.parseColor("#002ED3FF")
) as Int
if (index == 0) {
paint.shader = LinearGradient(
widthView / 2f,
heighView / 2f,
triple.x,
triple.y,
lastColor,
evaluateColor,
Shader.TileMode.CLAMP
)
nextLineData.add(
LineData(
NearPointView(widthView / 2f, heighView / 2f, 0f),
triple, triple.distance, paint
)
)
} else {
val prePoint = nextPointList[index - 1]
paint.shader = LinearGradient(
prePoint.x,
prePoint.y,
triple.x,
triple.y,
lastColor,
evaluateColor,
Shader.TileMode.CLAMP
)
nextLineData.add(LineData(prePoint, triple, triple.distance, paint))
}
hasDraw += triple.distance
Log.d(
"DrawLineViewdrawNext",
"颜色百分比:${colorPencent}-颜色:${colorPencent}---长度${nextPointMaxLength}-----${hasDraw}"
)
if (hasDraw > nextPointMaxLength) {
hasDraw = nextPointMaxLength
}
lastColor = evaluateColor
}
Log.d("DrawLineViewdrawPre", "---------------------------")
hasDraw = 0f
lastColor = Color.parseColor("#2ED3FF")
prePointList.forEachIndexed { index, triple ->
val paint = Paint()
paint.apply {
strokeWidth = 20f
isAntiAlias = true
color = Color.RED
}
val colorPencent = if (index == prePointList.size - 1) {
1f
} else {
(triple.distance + hasDraw) / prePointMaxLength
}
val evaluateColor = evaluator.evaluate(
colorPencent,
Color.parseColor("#FF2ED3FF"),
Color.parseColor("#002ED3FF")
) as Int
if (index == 0) {
paint.shader = LinearGradient(
widthView / 2f,
heighView / 2f,
triple.x,
triple.y,
lastColor,
evaluateColor,
Shader.TileMode.CLAMP
)
preLineData.add(
LineData(
NearPointView(widthView / 2f, heighView / 2f, 0f),
triple, triple.distance, paint
)
)
} else {
val prePoint = prePointList[index - 1]
paint.shader = LinearGradient(
prePoint.x,
prePoint.y,
triple.x,
triple.y,
lastColor,
evaluateColor,
Shader.TileMode.CLAMP
)
preLineData.add(LineData(prePoint, triple, triple.distance, paint))
}
hasDraw += triple.distance
Log.d(
"DrawLineViewdrawPre",
"颜色百分比:${colorPencent}-颜色:${colorPencent}---长度${prePointMaxLength}-----${hasDraw}"
)
if (hasDraw > prePointMaxLength) {
hasDraw = prePointMaxLength
}
lastColor = evaluateColor
}
Log.d("DrawLineViewdrawPre", "---------------------------")
ThreadUtils.runOnUiThread {
matrixArrow.setTranslate(
(width / 2 - bmBlockWidth / 2).toFloat(),
(height / 2 - bmBlockHeight / 2).toFloat()
)
carLocation.heading.let {
matrixArrow.preRotate(it.toFloat(), bmBlockWidth / 2f, bmBlockHeight / 2f)
}
invalidate()
}
}
}

View File

@@ -0,0 +1,82 @@
package com.mogo.och.taxi.passenger.ui.simplemap
import androidx.lifecycle.ViewModel
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
import com.mogo.och.common.module.manager.distancemamager.ITrajectoryListener
import com.mogo.och.common.module.manager.distancemamager.TrajectoryAndDistanceManager
class SimpleMapViewModel : ViewModel(), ITrajectoryListener {
private val TAG = SimpleMapViewModel::class.java.simpleName
private val orderShowEvaluate = "SHOWEVALUATE"
private var simpleMapCallback: SimpleMapCallback?=null
init {
TrajectoryAndDistanceManager.addTrajectoryListener(TAG,this)
}
fun setViewCallback(viewCallback: SimpleMapCallback) {
this.simpleMapCallback = viewCallback
}
override fun onCleared() {
super.onCleared()
this.simpleMapCallback = null
}
interface SimpleMapCallback {
fun setData(
carLocation: MogoLocation,
nextList: MutableList<NearPoint>,
preList: MutableList<NearPoint>
)
}
override fun trajectoryCallback(
routeArrivied: MutableList<MogoLocation>,
routeArriving: MutableList<MogoLocation>,
location: MogoLocation
) {
val nextList = mutableListOf<NearPoint>()
val preList = mutableListOf<NearPoint>()
looper@ for(index in routeArrivied.size-1 downTo 0){
val tempMogLocation = routeArrivied[index]
val distance = CoordinateUtils.calculateLineDistance(
location.longitude,
location.latitude,
tempMogLocation.longitude,
tempMogLocation.latitude
)
if (distance >= 250) {
nextList.add(NearPoint(index,tempMogLocation,distance))
break@looper
} else {
nextList.add(NearPoint(index,tempMogLocation,distance))
}
}
looper@ for(index in 0 until routeArriving.size){
val tempMogLocation = routeArriving[index]
val distance = CoordinateUtils.calculateLineDistance(
location.longitude,
location.latitude,
tempMogLocation.longitude,
tempMogLocation.latitude
)
if (distance >= 250) {
preList.add(NearPoint(index,tempMogLocation,distance))
break@looper
} else {
preList.add(NearPoint(index,tempMogLocation,distance))
}
}
CallerLogger.d(TAG,"nextList:${nextList.size}---preList:${preList.size}")
this.simpleMapCallback?.setData(location,nextList,preList)
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 138 KiB

View File

@@ -4,14 +4,14 @@
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dp"/>
<solid android:color="@color/taxi_cp_488ED0" />
<solid android:color="@color/taxi_cp_1A488ED0" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dp"/>
<solid android:color="@color/taxi_cp_488ED0" />
<solid android:color="@color/taxi_cp_1A488ED0" />
</shape>
</clip>
</item>

View File

@@ -28,42 +28,35 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="@dimen/dp_127"
android:layout_marginTop="@dimen/dp_146"
android:src="@drawable/taxt_p_music_bg_relax_head"
android:layout_width="@dimen/dp_390"
android:layout_height="@dimen/dp_390"/>
android:layout_width="@dimen/dp_310"
android:layout_height="@dimen/dp_310"/>
<TextView
android:id="@+id/tv_music_name"
app:layout_constraintTop_toBottomOf="@+id/iv_music_cover"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="@dimen/dp_m_17"
android:layout_marginTop="@dimen/dp_61"
android:textSize="@dimen/dp_38"
tools:text="Current"
android:textColor="@color/taxi_cp_303C52"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_author"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_tag"
app:layout_constraintTop_toBottomOf="@+id/tv_music_name"
android:textSize="@dimen/dp_32"
android:textColor="@color/taxi_cp_576887"
tools:text="Kokia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_tag"
app:layout_constraintStart_toEndOf="@+id/tv_author"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textSize="@dimen/dp_16"
app:layout_constraintBaseline_toBaselineOf="@+id/tv_author"
app:layout_constraintTop_toBottomOf="@+id/tv_music_name"
android:layout_marginTop="8dp"
android:textSize="@dimen/dp_24"
android:textColor="@color/taxi_cp_576887"
tools:text="轻柔"
android:background="@drawable/taxi_p_music_list_tag_bg"
android:paddingStart="9dp"
android:paddingEnd="@dimen/dp_9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
@@ -76,7 +69,7 @@
android:thumb="@null"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_author"
app:layout_constraintTop_toBottomOf="@+id/tv_tag"
android:layout_marginTop="@dimen/dp_31"
android:progressDrawable="@drawable/taxt_p_music_seekbar_style"
android:paddingTop="3dp"

View File

@@ -7,6 +7,7 @@
<color name="taxi_cp_576887">#576887</color>
<color name="taxi_cp_4DFFFFFF">#4DFFFFFF</color>
<color name="taxi_cp_488ED0">#44488ED0</color>
<color name="taxi_cp_1A488ED0">#1A488ED0</color>
<color name="taxi_cp_598CFF">#598CFF</color>
<color name="taxi_cp_2CBFFC">#2CBFFC</color>
<color name="taxi_cp_1060ff">#1060ff</color>

View File

@@ -36,7 +36,7 @@
android:layout_marginEnd="@dimen/dp_12"
android:layout_marginStart="@dimen/dp_93"
android:textColor="@color/taxi_p_004DC4"
android:textSize="@dimen/dp_35"
android:textSize="@dimen/dp_38"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_top"
app:layout_constraintBottom_toBottomOf="@+id/gl_horizontal_center"
@@ -44,19 +44,44 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_endstation"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLength="25"
android:maxLines="1"
android:layout_marginStart="@dimen/dp_7"
android:textColor="@color/taxi_p_293449"
android:textSize="@dimen/dp_35"
android:textSize="@dimen/dp_38"
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_top"
app:layout_constraintBottom_toBottomOf="@+id/gl_horizontal_center"
app:layout_constraintEnd_toStartOf="@+id/actv_arrived_time_unit"
app:layout_constraintStart_toEndOf="@+id/actv_endstation_title"
android:text="--" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_arrived_time_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/taxi_p_004DC4"
android:textSize="@dimen/dp_38"
android:layout_marginEnd="@dimen/dp_8"
app:layout_constraintEnd_toStartOf="@+id/actv_arrived_time"
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_top"
app:layout_constraintBottom_toBottomOf="@+id/gl_horizontal_center"
android:text="到达" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_arrived_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:textColor="@color/taxi_p_203555"
android:textSize="@dimen/dp_38"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="@dimen/dp_97"
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_top"
app:layout_constraintBottom_toBottomOf="@+id/gl_horizontal_center"
tools:text="15:05" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_distance"
@@ -95,7 +120,7 @@
android:textSize="@dimen/dp_61"
android:fontFamily="@font/taxt_u_p_din"
android:textColor="@color/taxi_p_081831"
app:layout_constraintEnd_toStartOf="@+id/actv_arrived_time"
app:layout_constraintEnd_toStartOf="@+id/ll_simplemap_contain"
app:layout_constraintStart_toEndOf="@+id/actv_distance"
app:layout_constraintTop_toTopOf="@+id/actv_distance"
android:text="--" />
@@ -111,30 +136,26 @@
app:layout_constraintStart_toStartOf="@+id/actv_surplus_time"
app:layout_constraintEnd_toEndOf="@+id/actv_surplus_time" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_arrived_time"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll_simplemap_contain"
android:layout_width="0dp"
android:gravity="center"
android:layout_height="wrap_content"
android:textSize="@dimen/dp_61"
android:textColor="@color/taxi_p_081831"
android:layout_marginEnd="@dimen/dp_58"
android:text="--"
android:fontFamily="@font/taxt_u_p_din"
app:layout_constraintBottom_toTopOf="@+id/progress_distance"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/actv_surplus_time"
app:layout_constraintTop_toTopOf="@+id/actv_distance" />
app:layout_constraintTop_toTopOf="@+id/gl_horizontal_center">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actv_arrived_time_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/taxi_p_112B57"
android:textSize="@dimen/dp_33"
android:text="到达"
app:layout_constraintTop_toBottomOf="@+id/actv_arrived_time"
app:layout_constraintStart_toStartOf="@+id/actv_arrived_time"
app:layout_constraintEnd_toEndOf="@+id/actv_arrived_time" />
<com.mogo.och.taxi.passenger.ui.simplemap.SimpleMapView
android:id="@+id/simpleMap"
android:layout_width="@dimen/dp_180"
android:layout_height="@dimen/dp_180"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ProgressBar
android:id="@+id/progress_distance"

View File

@@ -168,6 +168,7 @@
<dimen name="dp_138">138dp</dimen>
<dimen name="dp_139">139dp</dimen>
<dimen name="dp_140">140dp</dimen>
<dimen name="dp_140_4">140.4dp</dimen>
<dimen name="dp_141">141dp</dimen>
<dimen name="dp_141_5">141.5dp</dimen>
<dimen name="dp_142">142dp</dimen>