From b4199874cf0d693a8a4f8c51379ee579a7215bcd Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Thu, 9 Feb 2023 15:48:48 +0800 Subject: [PATCH] =?UTF-8?q?[M2]=20M2=20=E5=B9=BF=E5=91=8A=E6=A8=A1?= =?UTF-8?q?=E5=9D=97opt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../och/bus/passenger/constant/URLConst.kt | 16 +-- .../bus/passenger/model/PM2DrivingModel.kt | 7 +- .../passenger/ui/video/PM2VideoFragment.kt | 68 ++++++++++-- .../ui/widget/video/AdvancePagerAdapter.kt | 100 +++++++++++++++++- .../ui/widget/video/AdvanceVideoView.kt | 83 +++++++++++++++ .../ui/widget/video/ImageAndVideoRotation.kt | 8 +- .../passenger/ui/widget/video/RotationItem.kt | 4 +- .../res/layout/p_m2_driving_info_fragment.xml | 2 +- .../src/m2/res/layout/p_m2_hpmap_fragment.xml | 34 +++--- .../src/m2/res/layout/p_m2_video_fragment.xml | 11 +- 10 files changed, 273 insertions(+), 60 deletions(-) create mode 100644 OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceVideoView.kt diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/constant/URLConst.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/constant/URLConst.kt index a6a50f6c37..5e4200edc5 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/constant/URLConst.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/constant/URLConst.kt @@ -14,29 +14,15 @@ class URLConst { private const val Shettle_BASE_URL_OCH_QA = "https://och-driver-qa.zhidaozhixing.com" private const val Shettle_BASE_URL_OCH_RELEASE = "https://och-driver.zhidaozhixing.com" - private const val BASE_URL_OCH_DEV = "http://tech-dev.zhidaohulian.com" - private const val BASE_URL_OCH_QA = "https://tech-qa.zhidaohulian.com" - private const val BASE_URL_OCH_RELEASE = "https://tech.zhidaohulian.com" - @JvmStatic fun getBaseUrl(): String { - return if(AppIdentityModeUtils.isShuttle(FunctionBuildConfig.appIdentityMode)){ - when (DebugConfig.getNetMode()) { + return when (DebugConfig.getNetMode()) { DebugConfig.NET_MODE_DEV, DebugConfig.NET_MODE_DEMO -> Shettle_BASE_URL_OCH_DEV DebugConfig.NET_MODE_QA -> Shettle_BASE_URL_OCH_QA DebugConfig.NET_MODE_RELEASE -> Shettle_BASE_URL_OCH_RELEASE else -> Shettle_BASE_URL_OCH_RELEASE } - }else{ - when (DebugConfig.getNetMode()) { - DebugConfig.NET_MODE_DEV, DebugConfig.NET_MODE_DEMO -> BASE_URL_OCH_DEV - DebugConfig.NET_MODE_QA -> BASE_URL_OCH_QA - DebugConfig.NET_MODE_RELEASE -> BASE_URL_OCH_RELEASE - else -> BASE_URL_OCH_RELEASE - } - } - } } } \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/model/PM2DrivingModel.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/model/PM2DrivingModel.kt index 6ed8a78a8a..0e47a35b16 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/model/PM2DrivingModel.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/model/PM2DrivingModel.kt @@ -8,7 +8,7 @@ import com.mogo.eagle.core.data.map.MogoLocation import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager -import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ20ListenerManager +import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr @@ -74,7 +74,8 @@ class PM2DrivingModel private constructor() { CallerAutoPilotStatusListenerManager.addListener(TAG, mAutoPilotStatusListener) // 定位监听 - CallerChassisLocationGCJ20ListenerManager.addListener(TAG, mMapLocationListener) + CallerChassisLocationGCJ02ListenerManager.addListener(TAG, mMapLocationListener) + CallerChassisLocationGCJ02ListenerManager.setListenerHz(TAG,5)//设置5hz, 1s返回一次 } public fun releaseListener(){ @@ -82,7 +83,7 @@ class PM2DrivingModel private constructor() { CallerAutoPilotStatusListenerManager.removeListener(TAG) // 定位监听 - CallerChassisLocationGCJ20ListenerManager.removeListener(TAG) + CallerChassisLocationGCJ02ListenerManager.removeListener(TAG) } fun setDrivingInfoCallback(drivingInfoCallback : DrivingInfoCallback?){ diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/video/PM2VideoFragment.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/video/PM2VideoFragment.kt index 5dc013080d..587e839869 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/video/PM2VideoFragment.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/video/PM2VideoFragment.kt @@ -3,6 +3,8 @@ package com.mogo.och.bus.passenger.ui.video import com.mogo.commons.mvp.MvpFragment import com.mogo.och.bus.passenger.R import com.mogo.och.bus.passenger.presenter.PM2VideoPresenter +import com.mogo.och.bus.passenger.ui.widget.video.RotationItem +import kotlinx.android.synthetic.m2.p_m2_video_fragment.* /** * @author: wangmingjun @@ -10,21 +12,13 @@ import com.mogo.och.bus.passenger.presenter.PM2VideoPresenter */ class PM2VideoFragment : MvpFragment() { - /** - * 改变自动驾驶状态 - * - * @param status 2 - running 1 - enable 2 - disable - */ + + private var arrayListOf = mutableListOf() + override fun getLayoutId(): Int { return R.layout.p_m2_video_fragment } - override fun getTagName(): String { - return TAG - } - - override fun initViews() { - } override fun createPresenter(): PM2VideoPresenter { return PM2VideoPresenter(this) @@ -33,4 +27,56 @@ class PM2VideoFragment : companion object { private val TAG = PM2VideoFragment::class.java.simpleName } + + override fun getTagName(): String { + return TAG + } + + override fun initViews() { + initResourceData() + image_video_rotation_view.setData(arrayListOf) + } + + override fun onPause() { + super.onPause() + image_video_rotation_view.setPause() + } + + override fun onResume() { + super.onResume() + image_video_rotation_view.setResume() + } + + private fun initResourceData() { + TODO("要替换成接驳私有化的链接") + arrayListOf.clear() + arrayListOf.add( + RotationItem( + "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656558672856/小宝宝.mp4", + 0, + "小宝宝" + ) + ) + arrayListOf.add( + RotationItem( + "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559367261/2.png", + 0, + "小猫" + ) + ) + arrayListOf.add( + RotationItem( + "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656558730074/星空.mp4", + 1, + "星空" + ) + ) + arrayListOf.add( + RotationItem( + "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559384635/3.png", + 0, + "星空" + ) + ) + } } \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvancePagerAdapter.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvancePagerAdapter.kt index 496460d091..8e36998e78 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvancePagerAdapter.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvancePagerAdapter.kt @@ -1,23 +1,81 @@ package com.mogo.och.bus.passenger.ui.widget.video +import android.content.Context import android.view.View +import android.view.ViewGroup import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager /** * @author: wangmingjun * @date: 2023/2/6 */ -class AdvancePagerAdapter: PagerAdapter() { +class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter(), + ViewPager.OnPageChangeListener { + + private val mContext: Context = context + private val mViewPager: ViewPager = viewPager + + private var dataList = mutableListOf() + private var viewList = mutableListOf() + + private var thread: Thread? = null + + private var lastPosition = -1 + + private var current = 0 + private val time = 5000 + private val pause = false + + fun setData(list: MutableList){ + if (list.isEmpty()) return + dataList.addAll(list) + + viewList.clear() + + list.forEach { + addView(it) + } + + mViewPager.addOnPageChangeListener(this) + + notifyDataSetChanged() + + } + override fun getCount(): Int { - TODO("Not yet implemented") + return dataList.size } override fun isViewFromObject(view: View, `object`: Any): Boolean { - TODO("Not yet implemented") + return view === `object` } - public fun setData(list: MutableList){ + override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) { + container.removeView(viewList[position]) + } + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view: View = viewList[position] + container.addView(view) + return view + + } + + override fun getItemPosition(`object`: Any): Int { + return POSITION_NONE + } + + private fun addView(item: RotationItem) { + if (item.type.equals("1")) { // 表示视频 + var videoView = AdvanceVideoView(mContext) + videoView.setVideoImagePath(item.path) + viewList.add(videoView) + } else { // 表示图片 + var imageView = AdvanceImageView(mContext) + imageView.setImagePath(item.path) + viewList.add(imageView) + } } public fun setPause(){ @@ -27,4 +85,38 @@ class AdvancePagerAdapter: PagerAdapter() { public fun setResume(){ } + + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { + TODO("Not yet implemented") + } + + override fun onPageSelected(position: Int) { + TODO("Not yet implemented") + } + + override fun onPageScrollStateChanged(state: Int) { + // 由于viewpager的预加载机制onPageSelected这里面加载videoview 放的跟玩一样 等操作完成后再播放videoview就香了 很丝滑 +// if (state == 0) { +// if (viewList.size > 1) { //多于1,才会循环跳转 +// if (lastPosition != -1 && lastPosition != mViewPager.currentItem +// && viewList[lastPosition] is AdvanceVideoView) { +// var videoView: AdvanceVideoView = (AdvanceVideoView)viewList[lastPosition] +// videoView.setPause() +// } +// if (mViewPager.getCurrentItem() < 1) { //首位之前,跳转到末尾(N) +// var position = dataList.size //注意这里是mList,而不是mViews +// mViewPager.setCurrentItem(position, false) +// } else if (mViewPager.currentItem > dataList.size) { //末位之后,跳转到首位(1) +// mViewPager.setCurrentItem(1, false) //false:不显示跳转过程的动画 +// } +// current = 0;//换页重新计算时间 +// if (viewList.get(mViewPager.currentItem) instanceof AdvanceVideoView) { +// ((AdvanceVideoView) list.get(mViewPager.getCurrentItem())).setVideo(mediaPlayer -> { +// mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, true); +// }) +// } +// lastPosition = mViewPager.currentItem +// } +// } + } } \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceVideoView.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceVideoView.kt new file mode 100644 index 0000000000..cd5f2d86cc --- /dev/null +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceVideoView.kt @@ -0,0 +1,83 @@ +package com.mogo.och.bus.passenger.ui.widget.video + +import android.content.Context +import android.graphics.Color +import android.media.MediaPlayer +import android.util.AttributeSet +import android.widget.ImageView +import android.widget.RelativeLayout +import android.widget.VideoView +import com.bumptech.glide.Glide +import com.mogo.eagle.core.utilcode.util.UiThreadHandler + +/** + * @author: wangmingjun + * @date: 2023/2/8 + */ +class AdvanceVideoView @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null +) : RelativeLayout(context, attrs) { + + private var videoRelativeLayout: RelativeLayout? = null + private var videoPlayer: VideoView? = null + + private var startImage: ImageView? = null + private var path: String? = null + + init { + initView() + } + + private fun initView() { + videoRelativeLayout = RelativeLayout(context) + addView(videoRelativeLayout, LayoutParams(-1,-1)) + startImage = ImageView(context) + startImage?.scaleType = ImageView.ScaleType.FIT_XY + addView(startImage, LayoutParams(-1,-1)) + } + + fun setVideoImagePath(path: String){ + this.path = path + startImage?.let { Glide.with(context).load(path).into(it) } + } + + fun setVideo(onCompletionListener : MediaPlayer.OnCompletionListener) { + if (videoPlayer != null) { + videoRelativeLayout?.removeView(videoPlayer) + videoPlayer = null + } + videoPlayer = VideoView(context) + videoPlayer?.setVideoPath(path) + videoPlayer?.setBackgroundColor(Color.TRANSPARENT) + + var layoutParams= LayoutParams(-1,-1) + //设置videoview占满父view播放 + layoutParams.addRule(ALIGN_PARENT_LEFT) + layoutParams.addRule(ALIGN_PARENT_RIGHT) + layoutParams.addRule(ALIGN_PARENT_TOP) + layoutParams.addRule(ALIGN_PARENT_BOTTOM) + videoRelativeLayout?.addView(videoPlayer, layoutParams); + videoPlayer?.setOnCompletionListener(onCompletionListener); + videoPlayer?.start() + + videoPlayer?.setOnPreparedListener { + UiThreadHandler.postDelayed({ + startImage?.visibility = GONE + }, 400) //防止黑屏闪烁 + } + } + + fun setPause() { + if (videoPlayer != null) { + videoPlayer?.pause() + startImage?.visibility = VISIBLE + } + } + + fun setRestart() { + if (videoPlayer != null) { + videoPlayer?.start() + startImage?.visibility = GONE + } + } +} \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/ImageAndVideoRotation.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/ImageAndVideoRotation.kt index b323b4795d..31c2e308a1 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/ImageAndVideoRotation.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/ImageAndVideoRotation.kt @@ -23,20 +23,20 @@ class ImageAndVideoRotation @JvmOverloads constructor( private fun initView() { viewPager = ViewPager(context) - pagerAdapter = AdvancePagerAdapter() + pagerAdapter = AdvancePagerAdapter(context, viewPager!!) viewPager?.adapter = pagerAdapter addView(viewPager, LayoutParams(-1,-1)) } - public fun setData(list: MutableList){ + fun setData(list: MutableList){ pagerAdapter?.setData(list) } - public fun setPause(){ + fun setPause(){ pagerAdapter?.setPause() } - public fun setResume(){ + fun setResume(){ pagerAdapter?.setResume() } } \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/RotationItem.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/RotationItem.kt index 14479133a8..80b733636f 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/RotationItem.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/RotationItem.kt @@ -3,5 +3,7 @@ package com.mogo.och.bus.passenger.ui.widget.video /** * @author: wangmingjun * @date: 2023/2/6 + * type:0 图片 + * type:1 视频 */ -data class RotationItem(var path: String, var type: String) \ No newline at end of file +data class RotationItem(var path: String, var type: Int, var title: String) \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_driving_info_fragment.xml b/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_driving_info_fragment.xml index 8f1e26ea45..12bd19f1e0 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_driving_info_fragment.xml +++ b/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_driving_info_fragment.xml @@ -134,7 +134,7 @@ - - - + + + + + + - - - - - + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintLeft_toLeftOf="parent" /> - - - + \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_video_fragment.xml b/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_video_fragment.xml index 9cbde67745..72a3a97a20 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_video_fragment.xml +++ b/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_video_fragment.xml @@ -6,12 +6,9 @@ - + \ No newline at end of file