[fea]
[视角切换]
This commit is contained in:
yangyakun
2024-07-02 19:01:47 +08:00
parent 2e55e31402
commit af2db07838
23 changed files with 653 additions and 84 deletions

View File

@@ -25,7 +25,7 @@ class OrderStatusView : AppCompatImageView, OrderStatusViewModel.IVisualCallback
)
private fun initView() {
setImageResource(R.drawable.common_visual_medium)
setImageResource(R.drawable.common_status_unorder)
}
override fun onAttachedToWindow() {

View File

@@ -0,0 +1,220 @@
package com.mogo.och.common.module.wigets.map.switchvisual
import android.animation.ObjectAnimator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.LinearGradient
import android.graphics.Paint
import android.graphics.Shader
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.MotionEvent
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.mogo.och.common.module.R
import kotlin.properties.Delegates
class SeekBarView : ConstraintLayout, VisualViewModel.IVisualCallback {
//定义、并创建画笔
var p = Paint().apply {
strokeWidth = 1f
style = Paint.Style.STROKE
isAntiAlias = true
shader = LinearGradient(
0f, 0f, 600f, 600f, intArrayOf(Color.RED, Color.BLUE, Color.BLACK),
null, Shader.TileMode.CLAMP
)
}
constructor(context: Context) : super(context)
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet)
constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super(
context,
attributeSet,
defStyleAttr
)
private var viewModel: VisualViewModel? = null
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
val split = (height - draggableButton.height) / 3f
canvas.drawLine(0f,split,width.toFloat(),split,p)
canvas.drawLine(0f,split*2,width.toFloat(),split*2,p)
canvas.drawLine(0f,(height - draggableButton.height).toFloat(),width.toFloat(),split*3,p)
val translationY = draggableButton.translationY
canvas.drawLine(0f,translationY,width.toFloat(),translationY,p)
}
private var initialX = 0f
private var initialY = 0f
private val tempSet = ConstraintSet()
/**
* 为该组件的触碰事件重写事件处理方法
*/
override fun onTouchEvent(event: MotionEvent?): Boolean {
if(value==VisualViewModel.Visualangle.UnChange){
return true
}
when (event?.action) {
MotionEvent.ACTION_DOWN -> {
initialX = event.rawX;
initialY = event.rawY;
}
MotionEvent.ACTION_MOVE -> {
if(draggableButton.translationY<-draggableButton.height){
tempSet.clone(this)
tempSet.setTranslationY(R.id.iv_setting_only_value,-draggableButton.height.toFloat())
tempSet.applyTo(this)
return true
}else if (draggableButton.translationY>(height)){
tempSet.clone(this)
tempSet.setTranslationY(R.id.iv_setting_only_value,(height).toFloat())
tempSet.applyTo(this)
return true
}
val dx = event.rawX - initialX;
val dy = event.rawY - initialY;
initialX = event.rawX;
initialY = event.rawY;
tempSet.clone(this)
tempSet.setTranslationY(R.id.iv_setting_only_value,draggableButton.translationY+dy)
tempSet.applyTo(this)
}
MotionEvent.ACTION_UP -> {
if(draggableButton.translationY<0){
translationByValue(VisualViewModel.Visualangle.Middle)
}else if (draggableButton.translationY>(height-draggableButton.height)){
translationByValue(VisualViewModel.Visualangle.Long)
}else{
val marginTop = draggableButton.translationY
val split = (height - draggableButton.height) / 2
// if(marginTop>0&&marginTop<split){
// translationByValue(Visualangle.Middle)
// }else if(marginTop>split&&marginTop<split*2){
// translationByValue(Visualangle.Crossroads)
// }else if(marginTop*2>split&&marginTop<(height - draggableButton.height)){
// translationByValue(Visualangle.Long)
// }
if(marginTop>0&&marginTop<split){
translationByValue(VisualViewModel.Visualangle.Middle)
}else if(marginTop>split&&marginTop<(height - draggableButton.height)){
translationByValue(VisualViewModel.Visualangle.Long)
}
}
}
else -> {}
}
return true
}
private var value: VisualViewModel.Visualangle by Delegates.observable(VisualViewModel.Visualangle.None) { _, oldValue, newValue ->
if (oldValue != newValue) {
viewModel?.changeVisualView(newValue)
}
}
fun translationByValue(visualangle: VisualViewModel.Visualangle){
value = visualangle
when (visualangle) {
VisualViewModel.Visualangle.Middle -> {
ObjectAnimator.ofFloat(draggableButton, "translationY", draggableButton.translationY, 0f).apply {
duration = 100
}.start()
}
VisualViewModel.Visualangle.Long -> {
ObjectAnimator.ofFloat(
draggableButton,
"translationY",
draggableButton.translationY,
(height - draggableButton.height).toFloat()
).apply {
duration = 100
}.start()
}
VisualViewModel.Visualangle.UnChange -> {
ObjectAnimator.ofFloat(
draggableButton,
"translationY",
draggableButton.translationY,
(height - draggableButton.height) / 2f
).apply {
duration = 100
}.start()
alpha = 0.5f
}
}
}
private lateinit var draggableButton:ImageView
private fun initView() {
LayoutInflater.from(context).inflate(R.layout.taxi_p_seekbar_visualangle, this, true)
draggableButton = findViewById(R.id.iv_setting_only_value)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
viewModel = findViewTreeViewModelStoreOwner()?.let {
ViewModelProvider(it).get(VisualViewModel::class.java)
}
viewModel?.setDistanceCallback(this)
}
init {
try {
initView()
} catch (e: Exception) {
e.printStackTrace()
}
}
override fun setMiddleAngle() {
UiThreadHandler.post({
translationByValue(VisualViewModel.Visualangle.Middle)
}, UiThreadHandler.MODE.QUEUE)
}
override fun setLongAngle() {
UiThreadHandler.post({
translationByValue(VisualViewModel.Visualangle.Long)
}, UiThreadHandler.MODE.QUEUE)
}
override fun setUnableChange() {
UiThreadHandler.post({
translationByValue(VisualViewModel.Visualangle.UnChange)
}, UiThreadHandler.MODE.QUEUE)
}
override fun setSkyboxAngle() {
UiThreadHandler.post({
translationByValue(VisualViewModel.Visualangle.Middle)
}, UiThreadHandler.MODE.QUEUE)
}
}

View File

@@ -62,11 +62,21 @@ class VisualView : AppCompatImageView, VisualViewModel.IVisualCallback {
}, UiThreadHandler.MODE.QUEUE)
}
override fun setViewResource(resource: Int) {
override fun setMiddleAngle() {
UiThreadHandler.post({
setImageResource(resource)
setImageResource(R.drawable.common_visual_medium)
}, UiThreadHandler.MODE.QUEUE)
}
override fun setLongAngle() {
UiThreadHandler.post({
setImageResource(R.drawable.common_visual_long)
}, UiThreadHandler.MODE.QUEUE)
}
override fun setUnableChange() {
}
}

View File

@@ -1,14 +1,16 @@
package com.mogo.och.common.module.wigets.map.switchvisual
import androidx.lifecycle.ViewModel
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.map.listener.IMogoMapListener
import com.mogo.map.listener.MogoMapListenerHandler
import com.mogo.eagle.core.function.angle.scenes.LongSight
import com.mogo.eagle.core.function.api.map.angle.IMoGoVisualAngleChangeProvider
import com.mogo.eagle.core.function.api.map.angle.Scene
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager
import com.mogo.map.uicontroller.VisualAngleMode
import com.mogo.och.common.module.R
import com.mogo.eagle.core.function.angle.scenes.Default
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
class VisualViewModel : ViewModel(), IMogoMapListener {
class VisualViewModel : ViewModel(),
IMoGoVisualAngleChangeProvider.OnMoGoVisualAngleSceneChangeListener {
private val TAG = VisualViewModel::class.java.simpleName
@@ -20,72 +22,116 @@ class VisualViewModel : ViewModel(), IMogoMapListener {
override fun onCleared() {
super.onCleared()
MogoMapListenerHandler.mogoMapListenerHandler.unregisterHostMapListener(TAG)
CallerVisualAngleManager.removeListener(TAG)
this.viewCallback = null
}
fun setDistanceCallback(viewCallback: IVisualCallback) {
MogoMapListenerHandler.mogoMapListenerHandler.registerHostMapListener(TAG, this)
CallerVisualAngleManager.addListener(TAG, this)
this.viewCallback = viewCallback
}
override fun onMapVisualAngleChanged(visualAngleMode: VisualAngleMode?) {
CallerLogger.d(TAG,"视角切换成功${visualAngleMode}")
visualAngleMode?.let {
if (visualAngleMode.isMediumSight) {
this.viewCallback?.setViewShow(true)
this.viewCallback?.setViewResource(R.drawable.common_visual_medium)
} else if (visualAngleMode.isLongSight) {
this.viewCallback?.setViewShow(true)
this.viewCallback?.setViewResource(R.drawable.common_visual_long)
} else if (visualAngleMode.isCloseSight) {
this.viewCallback?.setViewShow(false)
} else{
this.viewCallback?.setViewShow(false)
}
}
}
override fun onSceneChanged(scene: Scene) {
if (scene.isCanSwitch) {// 可切换
when (scene.angle) {
VisualAngleMode.MODE_MEDIUM_SIGHT -> {
UiThreadHandler.post({
this.viewCallback?.setViewShow(true)
this.viewCallback?.setMiddleAngle()
}, UiThreadHandler.MODE.QUEUE)
}
override fun onMapLoaded() {
super.onMapLoaded()
CallerLogger.d(TAG,"地图加载成功 onMapLoaded")
val mapUIController = CallerMapUIServiceManager.getMapUIController()
mapUIController?.let {
val visualAngleMode = mapUIController.currentMapVisualAngle
if (visualAngleMode.isMediumSight) {
this.viewCallback?.setViewShow(true)
this.viewCallback?.setViewResource(R.drawable.common_visual_medium)
} else if (visualAngleMode.isLongSight) {
this.viewCallback?.setViewShow(true)
this.viewCallback?.setViewResource(R.drawable.common_visual_long)
} else if (visualAngleMode.isCloseSight) {
this.viewCallback?.setViewShow(false)
} else{
this.viewCallback?.setViewShow(false)
VisualAngleMode.MODE_LONG_SIGHT -> {
UiThreadHandler.post({
this.viewCallback?.setViewShow(true)
this.viewCallback?.setLongAngle()
}, UiThreadHandler.MODE.QUEUE)
}
VisualAngleMode.MAP_STYLE_VR_SKY_BOX -> {
UiThreadHandler.post({
this.viewCallback?.setViewShow(true)
this.viewCallback?.setSkyboxAngle()
}, UiThreadHandler.MODE.QUEUE)
}
else -> {
// 不可切换
UiThreadHandler.post({
this.viewCallback?.setViewShow(false)
this.viewCallback?.setUnableChange()
}, UiThreadHandler.MODE.QUEUE)
}
}
} else {// 不可切换
UiThreadHandler.post({
this.viewCallback?.setViewShow(false)
this.viewCallback?.setUnableChange()
}, UiThreadHandler.MODE.QUEUE)
}
}
fun changeVisualView() {
val mapUIController = CallerMapUIServiceManager.getMapUIController()
mapUIController?.currentMapVisualAngle?.let {
CallerLogger.d(TAG,"切换视角:${it}")
if (it.isLongSight) {
mapUIController.setLockMode(true);
mapUIController.changeMapVisualAngle(VisualAngleMode.MODE_MEDIUM_SIGHT, null);
} else if (it.isMediumSight) {
mapUIController.setLockMode(false);
mapUIController.changeMapVisualAngle(VisualAngleMode.MODE_LONG_SIGHT, null);
} else {
mapUIController.changeMapVisualAngle(VisualAngleMode.MODE_MEDIUM_SIGHT, null);
CallerVisualAngleManager.getCurrentScene().let {
val default = Default(0)
when (it.angle) {
VisualAngleMode.MODE_MEDIUM_SIGHT -> {
if(default.angle==VisualAngleMode.MODE_MEDIUM_SIGHT){
CallerVisualAngleManager.changeScene(LongSight(0))
}
}
VisualAngleMode.MODE_LONG_SIGHT -> {
CallerVisualAngleManager.changeScene(Default(0))
}
VisualAngleMode.MAP_STYLE_VR_SKY_BOX -> {
if(default.angle==VisualAngleMode.MAP_STYLE_VR_SKY_BOX){
CallerVisualAngleManager.changeScene(LongSight(0))
}
}
else -> {
}
}
}
}
fun changeVisualView(angle: Visualangle) {
when (angle) {
Visualangle.Middle -> {
CallerVisualAngleManager.changeScene(Default(0))
}
Visualangle.Long -> {
CallerVisualAngleManager.changeScene(LongSight(0))
}
Visualangle.UnChange -> {
viewCallback?.setUnableChange()
}
}
}
enum class Visualangle {
Middle, Long, UnChange,None
}
interface IVisualCallback {
fun setViewShow(boolean: Boolean)
fun setViewShow(boolean: Boolean) {}
fun setViewResource(resource: Int)
fun setMiddleAngle() {}
fun setLongAngle() {}
fun setSkyboxAngle() {}
fun setUnableChange() {}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<merge 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:layout_width="100dp"
android:layout_height="208dp"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<ImageView
android:id="@+id/iv_setting_only_bg"
android:layout_width="39dp"
android:layout_height="141dp"
android:src="@drawable/taxi_p_visual_angle_bg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iv_setting_only_value"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/taxi_p_visual_angle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</merge>