[M2] 1、图/视频轮播opt 2、m2竖屏
This commit is contained in:
@@ -20,7 +20,7 @@ import com.mogo.och.bus.passenger.ui.PM2BaseFragment
|
||||
* Created on 2022/3/29
|
||||
*/
|
||||
@Route(path = BusPassengerConst.PATH)
|
||||
class MogoOCHBusPassenger : IMogoOCH, IMogoStatusChangedListener {
|
||||
class MogoOCHBusPassenger : IMogoOCH {
|
||||
private var mActivity: FragmentActivity? = null
|
||||
private var mContainerId = 0
|
||||
private var mPM2Fragment: PM2BaseFragment? = null
|
||||
@@ -28,6 +28,7 @@ class MogoOCHBusPassenger : IMogoOCH, IMogoStatusChangedListener {
|
||||
override fun createCoverage(activity: FragmentActivity?, containerId: Int?): Fragment? {
|
||||
mActivity = activity
|
||||
mContainerId = containerId!!
|
||||
showFragment()
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -40,18 +41,6 @@ class MogoOCHBusPassenger : IMogoOCH, IMogoStatusChangedListener {
|
||||
}
|
||||
|
||||
override fun init(context: Context) {
|
||||
MogoStatusManager.getInstance()
|
||||
.registerStatusChangedListener("OchBus", StatusDescriptor.VR_MODE, this)
|
||||
}
|
||||
|
||||
override fun onStatusChanged(descriptor: StatusDescriptor, isTrue: Boolean) {
|
||||
if (descriptor == StatusDescriptor.VR_MODE) {
|
||||
if (isTrue) {
|
||||
showFragment()
|
||||
} else {
|
||||
hideFragment()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,12 +48,12 @@ class PM2VideoFragment :
|
||||
}
|
||||
|
||||
private fun initResourceData() {
|
||||
TODO("要替换成接驳私有化的链接")
|
||||
arrayListOf.clear()
|
||||
arrayListOf.add(
|
||||
RotationItem(
|
||||
"https://img.zhidaohulian.com/fileServer/online_car_hailing/1656558672856/小宝宝.mp4",
|
||||
0,
|
||||
"https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559345882/1.png",
|
||||
"小宝宝"
|
||||
)
|
||||
)
|
||||
@@ -61,6 +61,7 @@ class PM2VideoFragment :
|
||||
RotationItem(
|
||||
"https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559367261/2.png",
|
||||
0,
|
||||
"",
|
||||
"小猫"
|
||||
)
|
||||
)
|
||||
@@ -68,6 +69,7 @@ class PM2VideoFragment :
|
||||
RotationItem(
|
||||
"https://img.zhidaohulian.com/fileServer/online_car_hailing/1656558730074/星空.mp4",
|
||||
1,
|
||||
"https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559406169/4.png",
|
||||
"星空"
|
||||
)
|
||||
)
|
||||
@@ -75,7 +77,8 @@ class PM2VideoFragment :
|
||||
RotationItem(
|
||||
"https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559384635/3.png",
|
||||
0,
|
||||
"星空"
|
||||
"",
|
||||
"大海"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.bumptech.glide.Glide
|
||||
class AdvanceImageView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null
|
||||
) : RelativeLayout(context, attrs) {
|
||||
|
||||
private var imageView: ImageView? = null
|
||||
|
||||
init {
|
||||
@@ -22,10 +23,10 @@ class AdvanceImageView @JvmOverloads constructor(
|
||||
private fun initView() {
|
||||
imageView = ImageView(context)
|
||||
imageView?.scaleType = ImageView.ScaleType.FIT_XY
|
||||
addView(imageView, LayoutParams(-1,-1))
|
||||
addView(imageView, LayoutParams(-1, -1))
|
||||
}
|
||||
|
||||
public fun setImagePath(path: String){
|
||||
fun setImagePath(path: String){
|
||||
imageView?.let { Glide.with(context).load(path).into(it) }
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,12 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter(
|
||||
private var dataList = mutableListOf<RotationItem>()
|
||||
private var viewList = mutableListOf<View>()
|
||||
|
||||
private var thread: Thread? = null
|
||||
|
||||
private var lastPosition = -1
|
||||
|
||||
private var current = 0
|
||||
private val time = 5000
|
||||
private val pause = false
|
||||
private var thread: Thread? = null
|
||||
|
||||
fun setData(list: MutableList<RotationItem>){
|
||||
if (list.isEmpty()) return
|
||||
@@ -41,6 +40,16 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter(
|
||||
|
||||
notifyDataSetChanged()
|
||||
|
||||
mViewPager.currentItem = 0
|
||||
|
||||
if (list.size > 0) {
|
||||
if (list[0].type == 1) {//有人反应第一个是视频不播放这边优化了一下
|
||||
var video = list[mViewPager.currentItem] as AdvanceVideoView
|
||||
video.setVideo {
|
||||
mViewPager.setCurrentItem(mViewPager.currentItem + 1, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
@@ -67,9 +76,10 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter(
|
||||
}
|
||||
|
||||
private fun addView(item: RotationItem) {
|
||||
if (item.type.equals("1")) { // 表示视频
|
||||
if (item.type === 1) { // 表示视频
|
||||
var videoView = AdvanceVideoView(mContext)
|
||||
videoView.setVideoImagePath(item.path)
|
||||
videoView.setCacheImageView(item.cacheImgPath)
|
||||
videoView.setVideoPath(item.path)
|
||||
viewList.add(videoView)
|
||||
} else { // 表示图片
|
||||
var imageView = AdvanceImageView(mContext)
|
||||
@@ -78,45 +88,72 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
public fun setPause(){
|
||||
fun setPause(){
|
||||
|
||||
}
|
||||
|
||||
public fun setResume(){
|
||||
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
|
||||
// }
|
||||
// }
|
||||
if (state == 0) { //静止,什么都没做
|
||||
if (viewList.size > 1) { //多于1,才会循环跳转
|
||||
if (lastPosition != -1 && lastPosition != mViewPager.currentItem
|
||||
&& viewList[lastPosition] is AdvanceVideoView) {
|
||||
var videoView: AdvanceVideoView = viewList[lastPosition] as AdvanceVideoView
|
||||
videoView.setPause()
|
||||
}
|
||||
if (mViewPager.currentItem < 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[mViewPager.currentItem] is AdvanceVideoView) {
|
||||
|
||||
(viewList[mViewPager.currentItem] as AdvanceVideoView).setVideo {
|
||||
mViewPager.setCurrentItem(mViewPager.currentItem + 1, true)
|
||||
}
|
||||
|
||||
}else if (viewList[mViewPager.currentItem] is AdvanceImageView){
|
||||
startTimer()
|
||||
}
|
||||
lastPosition = mViewPager.currentItem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startTimer() {
|
||||
if (null != thread && !thread?.isInterrupted!!) {
|
||||
thread?.interrupt()
|
||||
thread = null
|
||||
}
|
||||
thread = Thread{
|
||||
while (null != thread && !thread?.isInterrupted!!) {
|
||||
try {
|
||||
Thread.sleep(1000)
|
||||
if (!pause && viewList[mViewPager.currentItem] !is AdvanceVideoView)
|
||||
current += 1000
|
||||
if (current >= time) {
|
||||
mViewPager.post {
|
||||
mViewPager.setCurrentItem(mViewPager.currentItem + 1, true)
|
||||
}
|
||||
current = 0
|
||||
}
|
||||
} catch (e: InterruptedException) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
thread?.start()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.mogo.och.bus.passenger.ui.widget.video
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.media.MediaPlayer
|
||||
import android.util.AttributeSet
|
||||
import android.widget.ImageView
|
||||
@@ -9,6 +11,7 @@ import android.widget.RelativeLayout
|
||||
import android.widget.VideoView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import java.lang.RuntimeException
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
@@ -19,9 +22,8 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
) : RelativeLayout(context, attrs) {
|
||||
|
||||
private var videoRelativeLayout: RelativeLayout? = null
|
||||
private var videoPlayer: VideoView? = null
|
||||
|
||||
private var startImage: ImageView? = null
|
||||
private var cacheImage: ImageView? = null
|
||||
private var videoView: VideoView? = null
|
||||
private var path: String? = null
|
||||
|
||||
init {
|
||||
@@ -30,54 +32,93 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
|
||||
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))
|
||||
addView(videoRelativeLayout, LayoutParams(-1, -1))
|
||||
cacheImage = ImageView(context)
|
||||
cacheImage?.scaleType = ImageView.ScaleType.FIT_XY
|
||||
addView(cacheImage, LayoutParams(-1, -1))
|
||||
}
|
||||
|
||||
fun setVideoImagePath(path: String){
|
||||
fun setVideoPath(path: String){
|
||||
this.path = path
|
||||
startImage?.let { Glide.with(context).load(path).into(it) }
|
||||
}
|
||||
|
||||
|
||||
fun setCacheImageView(imgPath: String){
|
||||
cacheImage?.visibility = VISIBLE
|
||||
cacheImage?.let { Glide.with(context).load(imgPath).into(it) }
|
||||
}
|
||||
|
||||
fun setVideo(onCompletionListener : MediaPlayer.OnCompletionListener) {
|
||||
if (videoPlayer != null) {
|
||||
videoRelativeLayout?.removeView(videoPlayer)
|
||||
videoPlayer = null
|
||||
if (videoView != null){
|
||||
videoRelativeLayout?.removeView(videoView)
|
||||
videoView = null
|
||||
}
|
||||
videoPlayer = VideoView(context)
|
||||
videoPlayer?.setVideoPath(path)
|
||||
videoPlayer?.setBackgroundColor(Color.TRANSPARENT)
|
||||
|
||||
var layoutParams= LayoutParams(-1,-1)
|
||||
//视频播放控件
|
||||
videoView = VideoView(context)
|
||||
videoView?.setVideoPath(path)
|
||||
videoView?.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()
|
||||
videoRelativeLayout?.addView(videoView, layoutParams)
|
||||
videoView?.setOnCompletionListener(onCompletionListener)
|
||||
videoView?.start()
|
||||
|
||||
videoPlayer?.setOnPreparedListener {
|
||||
videoView?.setOnPreparedListener {
|
||||
UiThreadHandler.postDelayed({
|
||||
startImage?.visibility = GONE
|
||||
}, 400) //防止黑屏闪烁
|
||||
cacheImage?.visibility = GONE
|
||||
},500)
|
||||
}
|
||||
|
||||
videoView?.setOnCompletionListener(onCompletionListener)
|
||||
}
|
||||
|
||||
fun setPause() {
|
||||
if (videoPlayer != null) {
|
||||
videoPlayer?.pause()
|
||||
startImage?.visibility = VISIBLE
|
||||
if (videoView != null) {
|
||||
videoView?.pause()
|
||||
}
|
||||
}
|
||||
|
||||
fun setRestart() {
|
||||
if (videoPlayer != null) {
|
||||
videoPlayer?.start()
|
||||
startImage?.visibility = GONE
|
||||
if (videoView != null) {
|
||||
videoView?.start()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载首帧,作为视频缓存显示的图片
|
||||
*/
|
||||
private fun loadCacheImage(){
|
||||
Thread {
|
||||
var retriever = MediaMetadataRetriever()
|
||||
var bitmap: Bitmap? = null
|
||||
try {
|
||||
if (path?.contains("http") == true){
|
||||
retriever.setDataSource(path, HashMap<String,String>())
|
||||
}else{
|
||||
retriever.setDataSource(path)
|
||||
}
|
||||
bitmap = retriever.frameAtTime
|
||||
}catch (ex: Exception){
|
||||
ex.printStackTrace()
|
||||
}finally {
|
||||
try {
|
||||
retriever.release()
|
||||
}catch (e: RuntimeException){
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
if (bitmap != null) {
|
||||
UiThreadHandler.post {
|
||||
// setCacheImageView(bitmap)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@ package com.mogo.och.bus.passenger.ui.widget.video
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.viewpager.widget.PagerAdapter
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2023/2/6
|
||||
@@ -25,7 +23,8 @@ class ImageAndVideoRotation @JvmOverloads constructor(
|
||||
viewPager = ViewPager(context)
|
||||
pagerAdapter = AdvancePagerAdapter(context, viewPager!!)
|
||||
viewPager?.adapter = pagerAdapter
|
||||
addView(viewPager, LayoutParams(-1,-1))
|
||||
|
||||
addView(viewPager, LayoutParams(-1, -1))
|
||||
}
|
||||
|
||||
fun setData(list: MutableList<RotationItem>){
|
||||
|
||||
@@ -6,4 +6,7 @@ package com.mogo.och.bus.passenger.ui.widget.video
|
||||
* type:0 图片
|
||||
* type:1 视频
|
||||
*/
|
||||
data class RotationItem(var path: String, var type: Int, var title: String)
|
||||
data class RotationItem(var path: String,
|
||||
var type: Int,
|
||||
var cacheImgPath: String,
|
||||
var title: String)
|
||||
@@ -8,7 +8,7 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/driving_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_height="@dimen/dp_853"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"/>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/hd_map_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_height="@dimen/dp_853"
|
||||
app:layout_constraintTop_toBottomOf="@+id/driving_fragment"
|
||||
app:layout_constraintLeft_toLeftOf="parent"/>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/video_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_height="@dimen/dp_853"
|
||||
app:layout_constraintTop_toBottomOf="@+id/hd_map_fragment"
|
||||
app:layout_constraintLeft_toLeftOf="parent"/>
|
||||
|
||||
|
||||
@@ -13,19 +13,19 @@
|
||||
|
||||
<!-- 消息盒子气泡-->
|
||||
|
||||
<com.mogo.eagle.core.function.hmi.ui.msgbox.PassengerMsgBoxBubbleView
|
||||
android:id="@+id/box_bubble_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent" />
|
||||
<!-- <com.mogo.eagle.core.function.hmi.ui.msgbox.PassengerMsgBoxBubbleView-->
|
||||
<!-- android:id="@+id/box_bubble_view"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintLeft_toLeftOf="parent" />-->
|
||||
|
||||
<!--pnc行为决策-->
|
||||
<com.mogo.eagle.core.function.hmi.ui.vehicle.PncActionsView
|
||||
android:id="@+id/pnc_actions_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent" />
|
||||
<!-- <com.mogo.eagle.core.function.hmi.ui.vehicle.PncActionsView-->
|
||||
<!-- android:id="@+id/pnc_actions_view"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
|
||||
<!-- app:layout_constraintRight_toRightOf="parent" />-->
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -18,7 +18,12 @@ project.android.productFlavors {
|
||||
// 车机类型,主要用于区分自研车机还是别人家的车机,自研车机类型为0
|
||||
buildConfigField 'int', 'CAR_MACHINE_TYPE', '2'
|
||||
//高德地图鉴权信息
|
||||
manifestPlaceholders = [AMAP_API_VALUE: rootProject.ext.android.fLauncherAmapApiValue, CHANNEL_VALUE: "fOchBusPassenger",ACTIVITY_ROOT:true]
|
||||
manifestPlaceholders = [
|
||||
AMAP_API_VALUE: rootProject.ext.android.fLauncherAmapApiValue,
|
||||
CHANNEL_VALUE: "fOchBusPassenger",
|
||||
ACTIVITY_ROOT:true,
|
||||
SCREEN_ORIENTATION: "portrait"
|
||||
]
|
||||
|
||||
// 是否需要实时上报坐标
|
||||
buildConfigField 'boolean', 'IS_NEED_UPLOAD_COORDINATES_IN_TIME', 'true'
|
||||
|
||||
Reference in New Issue
Block a user