[8.0.0]
[fea] [咨询列表]
This commit is contained in:
@@ -48,15 +48,18 @@ class RootViewConstrainLayout : ConstraintLayout {
|
||||
event?.let {
|
||||
if (it.action==MotionEvent.ACTION_DOWN) {
|
||||
val needInterceptLight = needIntercept(it, light_setting)//
|
||||
val needInterceptLightCheckBox = needIntercept(it, cb_setting_light)//
|
||||
|
||||
if(needInterceptLight){
|
||||
if(needInterceptLight&&needInterceptLightCheckBox){
|
||||
if(cb_setting_light?.isChecked==true){
|
||||
cb_setting_light?.isChecked = false
|
||||
}
|
||||
}
|
||||
|
||||
val needInterceptVoice = needIntercept(it, voice_setting)//
|
||||
if(needInterceptVoice){
|
||||
val pressCbSettingVoice = needIntercept(it, cb_setting_voice)//
|
||||
|
||||
if(needInterceptVoice&&pressCbSettingVoice){
|
||||
if(cb_setting_voice?.isChecked==true){
|
||||
cb_setting_voice?.isChecked = false
|
||||
}
|
||||
@@ -68,6 +71,9 @@ class RootViewConstrainLayout : ConstraintLayout {
|
||||
return super.onInterceptTouchEvent(event)
|
||||
}
|
||||
|
||||
/**
|
||||
* event 事件 落在了view 外部
|
||||
*/
|
||||
private fun needIntercept(event: MotionEvent,view: View?):Boolean {
|
||||
view?.apply {
|
||||
val location = IntArray(2)
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.mogo.och.unmanned.passenger.ui.video
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
@@ -12,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.eagle.core.function.main.MainMoGoApplication
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.mogo.och.common.module.wigets.WrapContentLinearLayoutManager
|
||||
import com.mogo.och.common.module.wigets.media.IMediaDataSourceListener
|
||||
import com.mogo.och.common.module.wigets.media.MediaDataSourceManager
|
||||
import com.mogo.och.common.module.wigets.media.MediaFileCacheManager
|
||||
@@ -20,16 +19,9 @@ import com.mogo.och.common.module.wigets.media.MediaPlayLogger
|
||||
import com.mogo.och.unmanned.passenger.bean.TaxiPassengerVideoPlay
|
||||
import com.mogo.och.unmanned.taxi.passenger.R
|
||||
import com.mogo.och.unmanned.passenger.ui.video.layoutmanage.CarouselLayoutManager
|
||||
import com.mogo.och.unmanned.passenger.ui.video.layoutmanage.CarouselZoomPostLayoutListener
|
||||
import com.mogo.och.unmanned.passenger.ui.video.layoutmanage.CenterScrollListener
|
||||
import com.mogo.och.unmanned.passenger.widget.ConsultVideoPlayer
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.IndicatorView
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorOrientation
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorStyle
|
||||
import com.shuyu.gsyvideoplayer.GSYVideoManager
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoView
|
||||
import kotlin.math.floor
|
||||
import kotlinx.android.synthetic.main.taxt_u_p_mogo_video_layout.view.infoVideoPlaylist
|
||||
|
||||
/**
|
||||
* @author ChenFufeng
|
||||
@@ -39,7 +31,7 @@ internal class InfoVideoView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : FrameLayout(
|
||||
) : ConstraintLayout(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
@@ -49,33 +41,31 @@ internal class InfoVideoView @JvmOverloads constructor(
|
||||
private const val TAG = "VideoView"
|
||||
}
|
||||
|
||||
private val mediaList = mutableListOf<TaxiPassengerVideoPlay>()
|
||||
//新的数据,在view不展示的时候完成新数据更新
|
||||
private val mNewMediaList = mutableListOf<TaxiPassengerVideoPlay>()
|
||||
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.taxt_u_p_mogo_video_layout, this, true)
|
||||
initView()
|
||||
}
|
||||
|
||||
private var rvVideoPlaylist: RecyclerView? = null
|
||||
private lateinit var indicatorView: IndicatorView
|
||||
private lateinit var clContain: ConstraintLayout
|
||||
private val mediaList = mutableListOf<TaxiPassengerVideoPlay>()
|
||||
//新的数据,在view不展示的时候完成新数据更新
|
||||
private val mNewMediaList = mutableListOf<TaxiPassengerVideoPlay>()
|
||||
|
||||
fun exitFullScreenMode(resetVideoPlayer: Boolean) {
|
||||
val carouselLayoutManager = rvVideoPlaylist?.layoutManager as CarouselLayoutManager
|
||||
val (_: Int, player) = getPlayer(carouselLayoutManager)
|
||||
player?.let {
|
||||
it.exitFullScreenMode()
|
||||
it.onVideoPause()
|
||||
if (resetVideoPlayer) {
|
||||
it.onVideoReset()
|
||||
}
|
||||
}
|
||||
val carouselLayoutManager = infoVideoPlaylist.layoutManager as CarouselLayoutManager
|
||||
// val (_: Int, player) = getPlayer(carouselLayoutManager)
|
||||
// player?.let {
|
||||
// it.exitFullScreenMode()
|
||||
// it.onVideoPause()
|
||||
// if (resetVideoPlayer) {
|
||||
// it.onVideoReset()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
initData()
|
||||
MediaFileCacheManager.createFileCacheDir(MainMoGoApplication.getApp().applicationContext)
|
||||
MediaDataSourceManager.init(TAG, object : IMediaDataSourceListener {
|
||||
override fun onMediaDataSourceChanged(list: List<MediaItem>) {
|
||||
@@ -110,138 +100,16 @@ internal class InfoVideoView @JvmOverloads constructor(
|
||||
private fun updateMediaListDataAndView(newList: MutableList<TaxiPassengerVideoPlay>) {
|
||||
mediaList.clear()
|
||||
mediaList.addAll(newList)
|
||||
mediaList.addAll(newList)
|
||||
UiThreadHandler.post {
|
||||
initData()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onVisibilityChanged(changedView: View, visibility: Int) {
|
||||
super.onVisibilityChanged(changedView, visibility)
|
||||
if (changedView != this) {
|
||||
return
|
||||
}
|
||||
val carouselLayoutManager = rvVideoPlaylist?.layoutManager as CarouselLayoutManager
|
||||
val (_: Int, player) = getPlayer(carouselLayoutManager)
|
||||
when (visibility) {
|
||||
View.VISIBLE -> {
|
||||
player?.let {
|
||||
if (!player.isIfCurrentIsFullscreen) {
|
||||
when (player.currentState) {
|
||||
GSYVideoView.CURRENT_STATE_PAUSE -> {
|
||||
//player.onVideoResume(false)
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
player?.let {
|
||||
if (!player.isIfCurrentIsFullscreen) {
|
||||
player.onVideoPause()
|
||||
}
|
||||
}
|
||||
try {
|
||||
// 在播放完成的时机更新整体数据
|
||||
if (mNewMediaList.isNotEmpty()) {
|
||||
updateMediaListDataAndView(mNewMediaList)
|
||||
mNewMediaList.clear()
|
||||
MediaPlayLogger.printInfoLog("onVisibilityChanged, 宣传视频数据已更新")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
initView()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
rvVideoPlaylist = findViewById(R.id.infoVideoPlaylist)
|
||||
indicatorView = findViewById(R.id.infoIndicatorView)
|
||||
clContain = findViewById(R.id.infoContainer)
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
val carouselLayoutManager =
|
||||
CarouselLayoutManager(
|
||||
CarouselLayoutManager.HORIZONTAL,
|
||||
true
|
||||
)
|
||||
carouselLayoutManager.setPostLayoutListener(CarouselZoomPostLayoutListener())
|
||||
carouselLayoutManager.maxVisibleItems = 1
|
||||
indicatorView.notifyDataChanged(mediaList.size)
|
||||
indicatorView.setSlideMode(IndicatorSlideMode.SCALE)
|
||||
indicatorView.setOrientation(IndicatorOrientation.INDICATOR_HORIZONTAL)
|
||||
indicatorView.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
|
||||
indicatorView.setSliderColor(
|
||||
Color.parseColor("#80FFFFFF"), Color.parseColor("#3FACFD"),
|
||||
Color.parseColor("#3FACFD")
|
||||
)
|
||||
indicatorView.setSliderWidth(9f, 54f)
|
||||
indicatorView.setSliderHeight(9f)
|
||||
indicatorView.setSliderGap(36f)
|
||||
rvVideoPlaylist?.addOnScrollListener(object : CenterScrollListener() {
|
||||
var prePlayerPosition = 0
|
||||
override fun pageSelect(recyclerView: RecyclerView?, newState: Int) {
|
||||
//播放视频
|
||||
val (centerItemPosition: Int, player) = getPlayer(carouselLayoutManager)
|
||||
indicatorView.onPageSelected(centerItemPosition)
|
||||
if (player is ConsultVideoPlayer) {
|
||||
if (prePlayerPosition != centerItemPosition) {
|
||||
if (player.currentState == GSYVideoView.CURRENT_STATE_PAUSE) {
|
||||
player.onVideoReset()
|
||||
}
|
||||
val playerHolder =
|
||||
carouselLayoutManager.findViewByPosition(prePlayerPosition)
|
||||
val prePlayer =
|
||||
playerHolder?.findViewById<ConsultVideoPlayer>(R.id.video_item_player)
|
||||
prePlayer?.onVideoReset()
|
||||
} else {
|
||||
player.onVideoResume(false)
|
||||
}
|
||||
}
|
||||
prePlayerPosition = centerItemPosition
|
||||
MediaPlayLogger.printInfoLog("pageSelect, currentPosition=$prePlayerPosition")
|
||||
}
|
||||
|
||||
override fun pageStop() {
|
||||
val (_: Int, player) = getPlayer(carouselLayoutManager)
|
||||
if (player is ConsultVideoPlayer) {
|
||||
player.onVideoPause()
|
||||
}
|
||||
}
|
||||
})
|
||||
carouselLayoutManager.addOnDargAutoDiffListener { adapterPosition, currentPosition ->
|
||||
val fl = adapterPosition - floor(adapterPosition)
|
||||
var currentIndex = currentPosition
|
||||
if (fl > 0.5) {
|
||||
if (currentPosition == 0) {
|
||||
currentIndex = rvVideoPlaylist?.adapter!!.itemCount - 1
|
||||
} else {
|
||||
currentIndex -= 1
|
||||
}
|
||||
}
|
||||
indicatorView.onPageScrolled(currentIndex, fl, 0)
|
||||
}
|
||||
val recyclerVideoAdapter =
|
||||
RecyclerVideoAdapter(
|
||||
context,
|
||||
mediaList,
|
||||
rvVideoPlaylist
|
||||
)
|
||||
recyclerVideoAdapter.setOnThumbImageClilckListener {
|
||||
val (_: Int, player) = getPlayer(carouselLayoutManager)
|
||||
if (player is ConsultVideoPlayer) {
|
||||
player.onVideoReset()
|
||||
player.thumbImageViewLayout.visibility = View.VISIBLE
|
||||
}
|
||||
rvVideoPlaylist?.smoothScrollToPosition(it)
|
||||
}
|
||||
rvVideoPlaylist?.layoutManager = carouselLayoutManager
|
||||
rvVideoPlaylist?.setHasFixedSize(true)
|
||||
rvVideoPlaylist?.adapter = recyclerVideoAdapter
|
||||
infoVideoPlaylist.layoutManager = WrapContentLinearLayoutManager(context,RecyclerView.VERTICAL,false)
|
||||
infoVideoPlaylist.addItemDecoration(SpacesItemDecoration(40, 140))
|
||||
infoVideoPlaylist.adapter = RecyclerVideoAdapterNew(context, mediaList)
|
||||
}
|
||||
|
||||
private fun getPlayer(carouselLayoutManager: CarouselLayoutManager): Pair<Int, ConsultVideoPlayer?> {
|
||||
@@ -251,17 +119,6 @@ internal class InfoVideoView @JvmOverloads constructor(
|
||||
return Pair(centerItemPosition, player)
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasWindowFocus)
|
||||
val carouselLayoutManager = rvVideoPlaylist?.layoutManager as CarouselLayoutManager
|
||||
val (_: Int, player) = getPlayer(carouselLayoutManager)
|
||||
player?.let {
|
||||
if (it.isInPlayingState && !it.isIfCurrentIsFullscreen && !hasWindowFocus) {
|
||||
player.onVideoPause()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
MediaDataSourceManager.unInit(TAG)
|
||||
GSYVideoManager.releaseAllVideos()
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.mogo.och.unmanned.passenger.ui.video
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.mogo.och.common.module.wigets.media.MediaItem
|
||||
import com.mogo.och.unmanned.passenger.bean.TaxiPassengerVideoPlay
|
||||
import com.mogo.och.unmanned.taxi.passenger.R
|
||||
import com.mogo.skin.utils.SkinResources
|
||||
import me.jessyan.autosize.AutoSizeCompat
|
||||
|
||||
class RecyclerVideoAdapterNew(
|
||||
private val context: Context,
|
||||
private val itemDataList: MutableList<TaxiPassengerVideoPlay>
|
||||
) : RecyclerView.Adapter<RecyclerVideoAdapterNew.SwitchLineViewHolder>() {
|
||||
private var onThumbImageClilckListener: OnThumbImageClilckListener? = null
|
||||
|
||||
|
||||
val placeholderDrawable = SkinResources.getInstance().getDrawable(R.drawable.road_video_bg)
|
||||
|
||||
fun setOnThumbImageClilckListener(onThumbImageClilckListener: OnThumbImageClilckListener?) {
|
||||
this.onThumbImageClilckListener = onThumbImageClilckListener
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SwitchLineViewHolder {
|
||||
val v = LayoutInflater.from(context).inflate(R.layout.taxt_u_p_list_video_item, parent, false)
|
||||
return SwitchLineViewHolder(v)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SwitchLineViewHolder, position: Int) {
|
||||
|
||||
AutoSizeCompat.autoConvertDensityOfGlobal(holder.itemView.resources)
|
||||
|
||||
val taxiPassengerVideoPlay = itemDataList[position]
|
||||
val isVideo = taxiPassengerVideoPlay.type == MediaItem.MEDIA_TYPE_VIDEO
|
||||
|
||||
holder.adName.setText(taxiPassengerVideoPlay.title)
|
||||
|
||||
val imageUrl = if (isVideo) {
|
||||
taxiPassengerVideoPlay.imageUrl
|
||||
} else {
|
||||
taxiPassengerVideoPlay.url
|
||||
}
|
||||
|
||||
Glide.with(context)
|
||||
.load(imageUrl)
|
||||
.apply(RequestOptions().placeholder(placeholderDrawable).centerCrop())
|
||||
.into(holder.adHeader);
|
||||
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return itemDataList.size
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
class SwitchLineViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val adHeader: AppCompatImageView = itemView.findViewById(R.id.video_item_image)//线路名称
|
||||
val adName: AppCompatTextView = itemView.findViewById(R.id.actv_video_head)//线路名称
|
||||
val isPlaying: AppCompatImageView = itemView.findViewById(R.id.aciv_playing_bar) //终点
|
||||
}
|
||||
|
||||
|
||||
interface OnThumbImageClilckListener {
|
||||
fun onDxChanged(targetPosition: Int)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "RecyclerVideoAdapter"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.mogo.och.unmanned.passenger.ui.video
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.CheckBox
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.widget.media.video.TextureVideoViewOutlineProvider
|
||||
import com.mogo.och.unmanned.taxi.passenger.R
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
|
||||
class RoundedViewConstrainLayout : ConstraintLayout {
|
||||
|
||||
private val TAG = "LockView"
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet)
|
||||
|
||||
constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attributeSet,
|
||||
defStyleAttr
|
||||
)
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
this.outlineProvider = TextureVideoViewOutlineProvider(AutoSizeUtils.dp2px(context,36f).toFloat())
|
||||
this.clipToOutline = true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.mogo.och.unmanned.passenger.ui.video;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* 这是LinearLayoutManager设置Item间距的的一个辅助类
|
||||
*
|
||||
* @author donghongyu
|
||||
*/
|
||||
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
|
||||
private final int space;
|
||||
private final int top;
|
||||
|
||||
public SpacesItemDecoration(int space,int top) {
|
||||
this.space = space;
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view,
|
||||
RecyclerView parent, RecyclerView.State state) {
|
||||
int pos = parent.getChildAdapterPosition(view);
|
||||
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams)view.getLayoutParams();
|
||||
if(pos == 0){
|
||||
layoutParams.setMargins(0,top,0,space);
|
||||
}else {
|
||||
layoutParams.setMargins(0,0,0,space);
|
||||
}
|
||||
|
||||
view.setLayoutParams(layoutParams);
|
||||
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.util.AttributeSet
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.annotation.AIndicatorOrientation
|
||||
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.base.BaseIndicatorView
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.drawer.DrawerProxy
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorOrientation
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.AttrsController
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
class IndicatorView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : BaseIndicatorView(context, attrs, defStyleAttr) {
|
||||
|
||||
private var mDrawerProxy: DrawerProxy
|
||||
|
||||
init {
|
||||
AttrsController.initAttrs(context, attrs, mIndicatorOptions)
|
||||
mDrawerProxy = DrawerProxy(mIndicatorOptions)
|
||||
}
|
||||
|
||||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||
super.onLayout(changed, left, top, right, bottom)
|
||||
mDrawerProxy.onLayout(changed, left, top, right, bottom)
|
||||
}
|
||||
|
||||
override fun onMeasure(
|
||||
widthMeasureSpec: Int,
|
||||
heightMeasureSpec: Int
|
||||
) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
val measureResult = mDrawerProxy.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
setMeasuredDimension(measureResult.measureWidth, measureResult.measureHeight)
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
rotateCanvas(canvas)
|
||||
mDrawerProxy.onDraw(canvas)
|
||||
}
|
||||
|
||||
override fun setIndicatorOptions(options: IndicatorOptions) {
|
||||
super.setIndicatorOptions(options)
|
||||
mDrawerProxy.setIndicatorOptions(options)
|
||||
}
|
||||
|
||||
override fun notifyDataChanged(itemCount:Int) {
|
||||
mDrawerProxy = DrawerProxy(mIndicatorOptions)
|
||||
super.notifyDataChanged(itemCount)
|
||||
}
|
||||
|
||||
private fun rotateCanvas(canvas: Canvas) {
|
||||
if (mIndicatorOptions.orientation == IndicatorOrientation.INDICATOR_VERTICAL) {
|
||||
canvas.rotate(90f, width / 2f, width / 2f)
|
||||
} else if (mIndicatorOptions.orientation == IndicatorOrientation.INDICATOR_RTL) {
|
||||
canvas.rotate(180f, width / 2f, height / 2f)
|
||||
}
|
||||
}
|
||||
|
||||
fun setOrientation(@AIndicatorOrientation orientation: Int) {
|
||||
mIndicatorOptions.orientation = orientation
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.annotation
|
||||
|
||||
import androidx.annotation.IntDef
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorOrientation
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangpan
|
||||
* @date 2021/1/21
|
||||
*/
|
||||
@IntDef(
|
||||
IndicatorOrientation.INDICATOR_HORIZONTAL, IndicatorOrientation.INDICATOR_VERTICAL,
|
||||
IndicatorOrientation.INDICATOR_RTL
|
||||
)
|
||||
@kotlin.annotation.Retention(AnnotationRetention.SOURCE)
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
|
||||
annotation class AIndicatorOrientation()
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.annotation
|
||||
|
||||
import androidx.annotation.IntDef
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode.Companion.NORMAL
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode.Companion.SMOOTH
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode.Companion.WORM
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode.Companion.COLOR
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode.Companion.SCALE
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhangpan on 2019-10-18.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
@IntDef(NORMAL, SMOOTH, WORM, COLOR, SCALE)
|
||||
@kotlin.annotation.Retention(AnnotationRetention.SOURCE)
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
|
||||
annotation class AIndicatorSlideMode
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.annotation
|
||||
|
||||
import androidx.annotation.IntDef
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorStyle
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhangpan on 2019-10-18.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
@IntDef(IndicatorStyle.CIRCLE, IndicatorStyle.DASH, IndicatorStyle.ROUND_RECT)
|
||||
@kotlin.annotation.Retention(AnnotationRetention.SOURCE)
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
|
||||
annotation class AIndicatorStyle
|
||||
@@ -1,203 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.base
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.annotation.AIndicatorSlideMode
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.annotation.AIndicatorStyle
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhangpan on 2019-09-04.
|
||||
* Description:IndicatorView基类,处理了页面滑动。
|
||||
* </pre>
|
||||
*/
|
||||
@Suppress("UNUSED")
|
||||
open class BaseIndicatorView constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet?,
|
||||
defStyleAttr: Int
|
||||
) : View(context, attrs, defStyleAttr), IIndicator {
|
||||
|
||||
var mIndicatorOptions: IndicatorOptions
|
||||
|
||||
private var recyclerView: RecyclerView? = null
|
||||
|
||||
init {
|
||||
mIndicatorOptions = IndicatorOptions()
|
||||
}
|
||||
|
||||
fun setPageSize(pageSize: Int): BaseIndicatorView {
|
||||
mIndicatorOptions.pageSize = pageSize
|
||||
return this
|
||||
}
|
||||
|
||||
// 页面选定
|
||||
fun onPageSelected(position: Int) {
|
||||
if (getSlideMode() == IndicatorSlideMode.NORMAL) {
|
||||
setCurrentPosition(position)
|
||||
setSlideProgress(0f)
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
// 滚动距离
|
||||
fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||
if (getSlideMode() != IndicatorSlideMode.NORMAL && getPageSize() > 1) {
|
||||
scrollSlider(position, positionOffset)
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
private fun scrollSlider(position: Int, positionOffset: Float) {
|
||||
if (mIndicatorOptions.slideMode == IndicatorSlideMode.SCALE
|
||||
|| mIndicatorOptions.slideMode == IndicatorSlideMode.COLOR) {
|
||||
setCurrentPosition(position)
|
||||
setSlideProgress(positionOffset)
|
||||
} else {
|
||||
if (position % getPageSize() == getPageSize() - 1) { // 最后一个页面与第一个页面
|
||||
if (positionOffset < 0.5) {
|
||||
setCurrentPosition(position)
|
||||
setSlideProgress(0f)
|
||||
} else {
|
||||
setCurrentPosition(0)
|
||||
setSlideProgress(0f)
|
||||
}
|
||||
} else { // 中间页面
|
||||
setCurrentPosition(position)
|
||||
setSlideProgress(positionOffset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun notifyDataChanged(itemCount: Int) {
|
||||
setPageSize(itemCount)
|
||||
requestLayout()
|
||||
invalidate()
|
||||
}
|
||||
|
||||
private fun setupViewPager() {
|
||||
|
||||
}
|
||||
|
||||
fun getNormalSlideWidth(): Float {
|
||||
return mIndicatorOptions.normalSliderWidth
|
||||
}
|
||||
|
||||
fun setNormalSlideWidth(normalSliderWidth: Float) {
|
||||
mIndicatorOptions.normalSliderWidth = normalSliderWidth
|
||||
}
|
||||
|
||||
fun getCheckedSlideWidth(): Float {
|
||||
return mIndicatorOptions.checkedSliderWidth
|
||||
}
|
||||
|
||||
fun setCheckedSlideWidth(checkedSliderWidth: Float) {
|
||||
mIndicatorOptions.checkedSliderWidth = checkedSliderWidth
|
||||
}
|
||||
|
||||
val checkedSliderWidth: Float
|
||||
get() = mIndicatorOptions.checkedSliderWidth
|
||||
|
||||
fun setCurrentPosition(currentPosition: Int) {
|
||||
mIndicatorOptions.currentPosition = currentPosition
|
||||
}
|
||||
|
||||
fun getCurrentPosition(): Int {
|
||||
return mIndicatorOptions.currentPosition
|
||||
}
|
||||
|
||||
fun getIndicatorGap(indicatorGap: Float) {
|
||||
mIndicatorOptions.sliderGap = indicatorGap
|
||||
}
|
||||
|
||||
fun setIndicatorGap(indicatorGap: Float) {
|
||||
mIndicatorOptions.sliderGap = indicatorGap
|
||||
}
|
||||
|
||||
fun setCheckedColor(@ColorInt normalColor: Int) {
|
||||
mIndicatorOptions.checkedSliderColor = normalColor
|
||||
}
|
||||
|
||||
fun getCheckedColor(): Int {
|
||||
return mIndicatorOptions.checkedSliderColor
|
||||
}
|
||||
|
||||
fun setNormalColor(@ColorInt normalColor: Int) {
|
||||
mIndicatorOptions.normalSliderColor = normalColor
|
||||
}
|
||||
|
||||
fun getSlideProgress(): Float {
|
||||
return mIndicatorOptions.slideProgress
|
||||
}
|
||||
|
||||
fun setSlideProgress(slideProgress: Float) {
|
||||
mIndicatorOptions.slideProgress = slideProgress
|
||||
}
|
||||
|
||||
fun getPageSize(): Int {
|
||||
return mIndicatorOptions.pageSize
|
||||
}
|
||||
|
||||
fun setSliderColor(
|
||||
@ColorInt normalColor: Int,
|
||||
@ColorInt selectedColor: Int,
|
||||
@ColorInt selectedEndColor: Int
|
||||
): BaseIndicatorView {
|
||||
mIndicatorOptions.setSliderColor(normalColor, selectedColor,selectedEndColor)
|
||||
return this
|
||||
}
|
||||
|
||||
fun setSliderWidth(sliderWidth: Float): BaseIndicatorView {
|
||||
mIndicatorOptions.setSliderWidth(sliderWidth)
|
||||
return this
|
||||
}
|
||||
|
||||
fun setSliderWidth(
|
||||
normalSliderWidth: Float,
|
||||
selectedSliderWidth: Float
|
||||
): BaseIndicatorView {
|
||||
mIndicatorOptions.setSliderWidth(normalSliderWidth, selectedSliderWidth)
|
||||
return this
|
||||
}
|
||||
|
||||
fun setSliderGap(sliderGap: Float): BaseIndicatorView {
|
||||
mIndicatorOptions.sliderGap = sliderGap
|
||||
return this
|
||||
}
|
||||
|
||||
fun getSlideMode(): Int {
|
||||
return mIndicatorOptions.slideMode
|
||||
}
|
||||
|
||||
fun setSlideMode(@AIndicatorSlideMode slideMode: Int): BaseIndicatorView {
|
||||
mIndicatorOptions.slideMode = slideMode
|
||||
return this
|
||||
}
|
||||
|
||||
fun setIndicatorStyle(@AIndicatorStyle indicatorStyle: Int): BaseIndicatorView {
|
||||
mIndicatorOptions.indicatorStyle = indicatorStyle
|
||||
return this
|
||||
}
|
||||
|
||||
fun setSliderHeight(sliderHeight: Float): BaseIndicatorView {
|
||||
mIndicatorOptions.sliderHeight = sliderHeight
|
||||
return this
|
||||
}
|
||||
|
||||
fun showIndicatorWhenOneItem(showIndicatorWhenOneItem: Boolean) {
|
||||
mIndicatorOptions.showIndicatorOneItem = showIndicatorWhenOneItem
|
||||
}
|
||||
|
||||
fun onPageScrollStateChanged(state: Int) {
|
||||
}
|
||||
|
||||
override fun setIndicatorOptions(options: IndicatorOptions) {
|
||||
mIndicatorOptions = options
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.base
|
||||
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhangpan on 2019-09-02.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
interface IIndicator {
|
||||
|
||||
fun notifyDataChanged(itemCount:Int)
|
||||
|
||||
fun setIndicatorOptions(options: IndicatorOptions)
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.drawer
|
||||
|
||||
import android.animation.ArgbEvaluator
|
||||
import android.graphics.Paint
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorOrientation
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2019/11/23.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
abstract class BaseDrawer internal constructor(internal var mIndicatorOptions: IndicatorOptions) :
|
||||
IDrawer {
|
||||
|
||||
private val mMeasureResult: MeasureResult
|
||||
internal var maxWidth: Float = 0.toFloat()
|
||||
internal var minWidth: Float = 0.toFloat()
|
||||
internal var mPaint: Paint = Paint()
|
||||
internal var argbEvaluator: ArgbEvaluator? = null
|
||||
|
||||
companion object {
|
||||
const val INDICATOR_PADDING_ADDITION = 6
|
||||
const val INDICATOR_PADDING = 3
|
||||
}
|
||||
|
||||
protected val isWidthEquals: Boolean
|
||||
get() = mIndicatorOptions.normalSliderWidth == mIndicatorOptions.checkedSliderWidth
|
||||
|
||||
init {
|
||||
mPaint.isAntiAlias = true
|
||||
mMeasureResult = MeasureResult()
|
||||
if (mIndicatorOptions.slideMode == IndicatorSlideMode.SCALE
|
||||
|| mIndicatorOptions.slideMode == IndicatorSlideMode.COLOR
|
||||
) {
|
||||
argbEvaluator = ArgbEvaluator()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMeasure(
|
||||
widthMeasureSpec: Int,
|
||||
heightMeasureSpec: Int
|
||||
): MeasureResult {
|
||||
maxWidth =
|
||||
mIndicatorOptions.normalSliderWidth.coerceAtLeast(mIndicatorOptions.checkedSliderWidth)
|
||||
minWidth =
|
||||
mIndicatorOptions.normalSliderWidth.coerceAtMost(mIndicatorOptions.checkedSliderWidth)
|
||||
if (mIndicatorOptions.orientation == IndicatorOrientation.INDICATOR_VERTICAL) {
|
||||
mMeasureResult.setMeasureResult(measureHeight(), measureWidth())
|
||||
} else {
|
||||
mMeasureResult.setMeasureResult(measureWidth(), measureHeight())
|
||||
}
|
||||
return mMeasureResult
|
||||
}
|
||||
|
||||
protected open fun measureHeight(): Int {
|
||||
return mIndicatorOptions.sliderHeight.toInt() + INDICATOR_PADDING
|
||||
}
|
||||
|
||||
private fun measureWidth(): Int {
|
||||
val pageSize = mIndicatorOptions.pageSize
|
||||
val indicatorGap = mIndicatorOptions.sliderGap
|
||||
return ((pageSize - 1) * indicatorGap + maxWidth + (pageSize - 1) * minWidth).toInt() + INDICATOR_PADDING_ADDITION
|
||||
}
|
||||
|
||||
override fun onLayout(
|
||||
changed: Boolean,
|
||||
left: Int,
|
||||
top: Int,
|
||||
right: Int,
|
||||
bottom: Int
|
||||
) {
|
||||
}
|
||||
|
||||
inner class MeasureResult {
|
||||
|
||||
var measureWidth: Int = 0
|
||||
internal set
|
||||
|
||||
var measureHeight: Int = 0
|
||||
internal set
|
||||
|
||||
internal fun setMeasureResult(
|
||||
measureWidth: Int,
|
||||
measureHeight: Int
|
||||
) {
|
||||
this.measureWidth = measureWidth
|
||||
this.measureHeight = measureHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.drawer
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.RectF
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.utils.IndicatorUtils
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2019/11/23.
|
||||
* Description: Circle Indicator drawer.
|
||||
</pre> *
|
||||
*/
|
||||
class CircleDrawer internal constructor(indicatorOptions: IndicatorOptions) : BaseDrawer(
|
||||
indicatorOptions
|
||||
) {
|
||||
|
||||
private val rectF = RectF()
|
||||
|
||||
override fun measureHeight(): Int {
|
||||
return maxWidth.toInt() + INDICATOR_PADDING_ADDITION
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val pageSize = mIndicatorOptions.pageSize
|
||||
if (pageSize > 1 || mIndicatorOptions.showIndicatorOneItem && pageSize == 1) {
|
||||
drawNormal(canvas)
|
||||
drawSlider(canvas)
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawNormal(canvas: Canvas) {
|
||||
val normalIndicatorWidth = mIndicatorOptions.normalSliderWidth
|
||||
mPaint.color = mIndicatorOptions.normalSliderColor
|
||||
for (i in 0 until mIndicatorOptions.pageSize) {
|
||||
val coordinateX = IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, i)
|
||||
val coordinateY = IndicatorUtils.getCoordinateY(maxWidth)
|
||||
drawCircle(canvas, coordinateX, coordinateY, normalIndicatorWidth / 2)
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawSlider(canvas: Canvas) {
|
||||
mPaint.color = mIndicatorOptions.checkedSliderColor
|
||||
when (mIndicatorOptions.slideMode) {
|
||||
IndicatorSlideMode.NORMAL, IndicatorSlideMode.SMOOTH -> drawCircleSlider(canvas)
|
||||
IndicatorSlideMode.WORM -> drawWormSlider(canvas)
|
||||
IndicatorSlideMode.SCALE -> drawScaleSlider(canvas)
|
||||
IndicatorSlideMode.COLOR -> drawColor(canvas)
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawColor(canvas: Canvas) {
|
||||
val currentPosition = mIndicatorOptions.currentPosition
|
||||
val slideProgress = mIndicatorOptions.slideProgress
|
||||
val coordinateX = IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
|
||||
val coordinateY = IndicatorUtils.getCoordinateY(maxWidth)
|
||||
var evaluate = argbEvaluator?.evaluate(
|
||||
slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = (evaluate as Int)
|
||||
drawCircle(canvas, coordinateX, coordinateY, mIndicatorOptions.normalSliderWidth / 2)
|
||||
|
||||
// 绘制可循环的ViewPager指示器渐变
|
||||
evaluate = argbEvaluator?.evaluate(
|
||||
1 - slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = evaluate as Int
|
||||
val nextCoordinateX = if (currentPosition == mIndicatorOptions.pageSize - 1) {
|
||||
IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, 0)
|
||||
} else {
|
||||
coordinateX + mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
|
||||
}
|
||||
drawCircle(canvas, nextCoordinateX, coordinateY, mIndicatorOptions.checkedSliderWidth / 2)
|
||||
}
|
||||
|
||||
private fun drawScaleSlider(canvas: Canvas) {
|
||||
val currentPosition = mIndicatorOptions.currentPosition
|
||||
val slideProgress = mIndicatorOptions.slideProgress
|
||||
val coordinateX = IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
|
||||
val coordinateY = IndicatorUtils.getCoordinateY(maxWidth)
|
||||
if (slideProgress < 1) {
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = (evaluate as Int)
|
||||
val radius =
|
||||
mIndicatorOptions.checkedSliderWidth / 2 - (mIndicatorOptions.checkedSliderWidth / 2 - mIndicatorOptions.normalSliderWidth / 2) * slideProgress
|
||||
drawCircle(canvas, coordinateX, coordinateY, radius)
|
||||
}
|
||||
|
||||
if (currentPosition == mIndicatorOptions.pageSize - 1) {
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
slideProgress, mIndicatorOptions.normalSliderColor, mIndicatorOptions.checkedSliderColor
|
||||
)
|
||||
mPaint.color = evaluate as Int
|
||||
val nextCoordinateX = maxWidth / 2
|
||||
val nextRadius = minWidth / 2 + (maxWidth / 2 - minWidth / 2) * (slideProgress)
|
||||
drawCircle(canvas, nextCoordinateX, coordinateY, nextRadius)
|
||||
} else {
|
||||
if (slideProgress > 0) {
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
slideProgress, mIndicatorOptions.normalSliderColor, mIndicatorOptions.checkedSliderColor
|
||||
)
|
||||
mPaint.color = evaluate as Int
|
||||
val nextCoordinateX =
|
||||
coordinateX + mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
|
||||
val nextRadius =
|
||||
mIndicatorOptions.normalSliderWidth / 2 + (mIndicatorOptions.checkedSliderWidth / 2 - mIndicatorOptions.normalSliderWidth / 2) * slideProgress
|
||||
drawCircle(canvas, nextCoordinateX, coordinateY, nextRadius)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawCircleSlider(canvas: Canvas) {
|
||||
val currentPosition = mIndicatorOptions.currentPosition
|
||||
val startCoordinateX =
|
||||
IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
|
||||
val endCoordinateX = IndicatorUtils.getCoordinateX(
|
||||
mIndicatorOptions, maxWidth, (currentPosition + 1) % mIndicatorOptions.pageSize
|
||||
)
|
||||
val coordinateX =
|
||||
startCoordinateX + (endCoordinateX - startCoordinateX) * mIndicatorOptions.slideProgress
|
||||
val coordinateY = IndicatorUtils.getCoordinateY(maxWidth)
|
||||
val radius = mIndicatorOptions.checkedSliderWidth / 2
|
||||
drawCircle(canvas, coordinateX, coordinateY, radius)
|
||||
}
|
||||
|
||||
private fun drawWormSlider(canvas: Canvas) {
|
||||
val sliderHeight = mIndicatorOptions.normalSliderWidth
|
||||
val slideProgress = mIndicatorOptions.slideProgress
|
||||
val currentPosition = mIndicatorOptions.currentPosition
|
||||
val distance = mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
|
||||
val startCoordinateX =
|
||||
IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
|
||||
val left = startCoordinateX + (distance * (slideProgress - 0.5f) * 2.0f).coerceAtLeast(
|
||||
0f
|
||||
) - mIndicatorOptions.normalSliderWidth / 2 + INDICATOR_PADDING
|
||||
val right = startCoordinateX + (distance * slideProgress * 2f).coerceAtMost(
|
||||
distance
|
||||
) + mIndicatorOptions.normalSliderWidth / 2 + INDICATOR_PADDING
|
||||
rectF.set(left, INDICATOR_PADDING.toFloat(), right, sliderHeight + INDICATOR_PADDING)
|
||||
canvas.drawRoundRect(rectF, sliderHeight, sliderHeight, mPaint)
|
||||
}
|
||||
|
||||
private fun drawCircle(
|
||||
canvas: Canvas,
|
||||
coordinateX: Float,
|
||||
coordinateY: Float,
|
||||
radius: Float
|
||||
) {
|
||||
canvas.drawCircle(
|
||||
coordinateX + INDICATOR_PADDING, coordinateY + INDICATOR_PADDING, radius, mPaint
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.drawer
|
||||
|
||||
import android.graphics.Canvas
|
||||
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2019/11/23.
|
||||
* Description: Dash Indicator Drawer.
|
||||
</pre> *
|
||||
*/
|
||||
class DashDrawer internal constructor(indicatorOptions: IndicatorOptions) : RectDrawer(
|
||||
indicatorOptions
|
||||
) {
|
||||
|
||||
override fun drawDash(canvas: Canvas) {
|
||||
canvas.drawRect(mRectF, mPaint)
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.drawer
|
||||
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorStyle
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2019/11/24.
|
||||
* Description: Indicator Drawer Factory.
|
||||
</pre> *
|
||||
*/
|
||||
internal object DrawerFactory {
|
||||
fun createDrawer(indicatorOptions: IndicatorOptions): IDrawer {
|
||||
return when (indicatorOptions.indicatorStyle) {
|
||||
IndicatorStyle.DASH -> DashDrawer(indicatorOptions)
|
||||
IndicatorStyle.ROUND_RECT -> RoundRectDrawer(indicatorOptions)
|
||||
else -> CircleDrawer(indicatorOptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.drawer
|
||||
|
||||
import android.graphics.Canvas
|
||||
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2019/11/23.
|
||||
* Description: Indicator Drawer Proxy.
|
||||
</pre> *
|
||||
*/
|
||||
class DrawerProxy(indicatorOptions: IndicatorOptions) : IDrawer {
|
||||
|
||||
private lateinit var mIDrawer: IDrawer
|
||||
|
||||
init {
|
||||
init(indicatorOptions)
|
||||
}
|
||||
|
||||
private fun init(indicatorOptions: IndicatorOptions) {
|
||||
mIDrawer = DrawerFactory.createDrawer(indicatorOptions)
|
||||
}
|
||||
|
||||
override fun onLayout(
|
||||
changed: Boolean,
|
||||
left: Int,
|
||||
top: Int,
|
||||
right: Int,
|
||||
bottom: Int
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onMeasure(
|
||||
widthMeasureSpec: Int,
|
||||
heightMeasureSpec: Int
|
||||
): BaseDrawer.MeasureResult {
|
||||
return mIDrawer.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
mIDrawer.onDraw(canvas)
|
||||
}
|
||||
|
||||
fun setIndicatorOptions(indicatorOptions: IndicatorOptions) {
|
||||
init(indicatorOptions)
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.drawer
|
||||
|
||||
import android.graphics.Canvas
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2019/11/23.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
interface IDrawer {
|
||||
|
||||
fun onLayout(
|
||||
changed: Boolean,
|
||||
left: Int,
|
||||
top: Int,
|
||||
right: Int,
|
||||
bottom: Int
|
||||
)
|
||||
|
||||
fun onMeasure(
|
||||
widthMeasureSpec: Int,
|
||||
heightMeasureSpec: Int
|
||||
): BaseDrawer.MeasureResult
|
||||
|
||||
fun onDraw(canvas: Canvas)
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.drawer
|
||||
|
||||
import android.graphics.*
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.utils.IndicatorUtils
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2020/1/17.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
open class RectDrawer internal constructor(indicatorOptions: IndicatorOptions) : BaseDrawer(
|
||||
indicatorOptions
|
||||
) {
|
||||
internal var mRectF: RectF = RectF()
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val pageSize = mIndicatorOptions.pageSize
|
||||
if (pageSize > 1 || mIndicatorOptions.showIndicatorOneItem && pageSize == 1) {
|
||||
if (isWidthEquals && mIndicatorOptions.slideMode != IndicatorSlideMode.NORMAL) {
|
||||
drawUncheckedSlider(canvas, pageSize)
|
||||
drawCheckedSlider(canvas)
|
||||
} else { // 单独处理normalWidth与checkedWidth不一致的情况
|
||||
if (mIndicatorOptions.slideMode == IndicatorSlideMode.SCALE) {
|
||||
for (i in 0 until pageSize) {
|
||||
drawScaleSlider(canvas, i)
|
||||
}
|
||||
} else {
|
||||
drawInequalitySlider(canvas, pageSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawScaleSlider(
|
||||
canvas: Canvas,
|
||||
i: Int
|
||||
) {
|
||||
val checkedColor = mIndicatorOptions.checkedSliderColor
|
||||
val indicatorGap = mIndicatorOptions.sliderGap
|
||||
val sliderHeight = mIndicatorOptions.sliderHeight
|
||||
val currentPosition = mIndicatorOptions.currentPosition
|
||||
val normalWidth = mIndicatorOptions.normalSliderWidth
|
||||
val checkedWidth = mIndicatorOptions.checkedSliderWidth
|
||||
when {
|
||||
i < currentPosition -> {
|
||||
mPaint.color = mIndicatorOptions.normalSliderColor
|
||||
val left: Float = if (currentPosition == mIndicatorOptions.pageSize - 1) {
|
||||
(i * normalWidth + i * indicatorGap) + (checkedWidth - normalWidth) * mIndicatorOptions.slideProgress
|
||||
} else {
|
||||
(i * normalWidth + i * indicatorGap)
|
||||
}
|
||||
mRectF.set(left, 0f, left + normalWidth, sliderHeight)
|
||||
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
|
||||
}
|
||||
i == currentPosition -> {
|
||||
mPaint.color = checkedColor
|
||||
val slideProgress = mIndicatorOptions.slideProgress
|
||||
if (currentPosition == mIndicatorOptions.pageSize - 1) {
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
slideProgress, checkedColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = (evaluate as Int)
|
||||
val right =
|
||||
(mIndicatorOptions.pageSize - 1) * (normalWidth + mIndicatorOptions.sliderGap) + checkedWidth
|
||||
val left = right - checkedWidth + (checkedWidth - normalWidth) * (slideProgress)
|
||||
mRectF.set(left, 0f, right, sliderHeight)
|
||||
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
|
||||
} else {
|
||||
if (slideProgress < 1) {
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
slideProgress, checkedColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = (evaluate as Int)
|
||||
val left = i * normalWidth + i * indicatorGap
|
||||
val right = left + normalWidth + (checkedWidth - normalWidth) * (1 - slideProgress)
|
||||
mRectF.set(left, 0f, right, sliderHeight)
|
||||
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
|
||||
}
|
||||
}
|
||||
|
||||
if (currentPosition == mIndicatorOptions.pageSize - 1) {
|
||||
if (slideProgress > 0) {
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
1 - slideProgress, checkedColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = evaluate as Int
|
||||
val left = 0f
|
||||
val right = left + normalWidth + (checkedWidth - normalWidth) * slideProgress
|
||||
|
||||
mRectF.set(left, 0f, right, sliderHeight)
|
||||
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
|
||||
}
|
||||
} else {
|
||||
if (slideProgress > 0) {
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
1 - slideProgress, checkedColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = evaluate as Int
|
||||
val right =
|
||||
i * normalWidth + i * indicatorGap + normalWidth + (indicatorGap + checkedWidth)
|
||||
val left = right - (normalWidth) - (checkedWidth - normalWidth) * (slideProgress)
|
||||
mRectF.set(left, 0f, right, sliderHeight)
|
||||
drawRoundRect(canvas, sliderHeight, sliderHeight,mRectF.width()>checkedWidth/2)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
if ((currentPosition + 1 != i || mIndicatorOptions.slideProgress == 0f)) { // 避免多余绘制
|
||||
mPaint.color = mIndicatorOptions.normalSliderColor
|
||||
val left = i * minWidth + i * indicatorGap + (checkedWidth - minWidth)
|
||||
mRectF.set(left, 0f, left + minWidth, sliderHeight)
|
||||
drawRoundRect(canvas, sliderHeight, sliderHeight,false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawUncheckedSlider(
|
||||
canvas: Canvas,
|
||||
pageSize: Int
|
||||
) {
|
||||
for (i in 0 until pageSize) {
|
||||
mPaint.color = mIndicatorOptions.normalSliderColor
|
||||
val left = i * maxWidth + i * +mIndicatorOptions.sliderGap + (maxWidth - minWidth)
|
||||
mRectF.set(left, 0f, left + minWidth, mIndicatorOptions.sliderHeight)
|
||||
drawRoundRect(canvas, mIndicatorOptions.sliderHeight, mIndicatorOptions.sliderHeight,false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawInequalitySlider(
|
||||
canvas: Canvas,
|
||||
pageSize: Int
|
||||
) {
|
||||
var left = 0f
|
||||
for (i in 0 until pageSize) {
|
||||
val sliderWidth = (if (i == mIndicatorOptions.currentPosition) maxWidth else minWidth)
|
||||
mPaint.color =
|
||||
if (i == mIndicatorOptions.currentPosition) mIndicatorOptions.checkedSliderColor else mIndicatorOptions.normalSliderColor
|
||||
mRectF.set(left, 0f, left + sliderWidth, mIndicatorOptions.sliderHeight)
|
||||
drawRoundRect(canvas, mIndicatorOptions.sliderHeight, mIndicatorOptions.sliderHeight,false)
|
||||
left += sliderWidth + mIndicatorOptions.sliderGap
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawCheckedSlider(canvas: Canvas) {
|
||||
mPaint.color = mIndicatorOptions.checkedSliderColor
|
||||
when (mIndicatorOptions.slideMode) {
|
||||
IndicatorSlideMode.SMOOTH -> drawSmoothSlider(canvas)
|
||||
IndicatorSlideMode.WORM -> drawWormSlider(canvas)
|
||||
IndicatorSlideMode.COLOR -> drawColorSlider(canvas)
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawColorSlider(canvas: Canvas) {
|
||||
val currentPosition = mIndicatorOptions.currentPosition
|
||||
val slideProgress = mIndicatorOptions.slideProgress
|
||||
val left = currentPosition * minWidth + currentPosition * mIndicatorOptions.sliderGap
|
||||
if (slideProgress < 0.99) {
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = (evaluate as Int)
|
||||
mRectF.set(left, 0f, left + minWidth, mIndicatorOptions.sliderHeight)
|
||||
drawRoundRect(canvas, mIndicatorOptions.sliderHeight, mIndicatorOptions.sliderHeight,false)
|
||||
}
|
||||
|
||||
var nextSliderLeft = left + mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
|
||||
if (currentPosition == mIndicatorOptions.pageSize - 1) {
|
||||
nextSliderLeft = 0f
|
||||
}
|
||||
val evaluate = argbEvaluator?.evaluate(
|
||||
1 - slideProgress, mIndicatorOptions.checkedSliderColor, mIndicatorOptions.normalSliderColor
|
||||
)
|
||||
mPaint.color = evaluate as Int
|
||||
mRectF.set(nextSliderLeft, 0f, nextSliderLeft + minWidth, mIndicatorOptions.sliderHeight)
|
||||
drawRoundRect(canvas, mIndicatorOptions.sliderHeight, mIndicatorOptions.sliderHeight,false)
|
||||
}
|
||||
|
||||
private fun drawWormSlider(canvas: Canvas) {
|
||||
val sliderHeight = mIndicatorOptions.sliderHeight
|
||||
val slideProgress = mIndicatorOptions.slideProgress
|
||||
val currentPosition = mIndicatorOptions.currentPosition
|
||||
val distance = mIndicatorOptions.sliderGap + mIndicatorOptions.normalSliderWidth
|
||||
val startCoordinateX =
|
||||
IndicatorUtils.getCoordinateX(mIndicatorOptions, maxWidth, currentPosition)
|
||||
val left = startCoordinateX + (distance * (slideProgress - 0.5f) * 2.0f).coerceAtLeast(
|
||||
0f
|
||||
) - mIndicatorOptions.normalSliderWidth / 2
|
||||
val right = startCoordinateX + (distance * slideProgress * 2f).coerceAtMost(
|
||||
distance
|
||||
) + mIndicatorOptions.normalSliderWidth / 2
|
||||
mRectF.set(left, 0f, right, sliderHeight)
|
||||
drawRoundRect(canvas, sliderHeight, sliderHeight,false)
|
||||
}
|
||||
|
||||
private fun drawSmoothSlider(canvas: Canvas) {
|
||||
val currentPosition = mIndicatorOptions.currentPosition
|
||||
val indicatorGap = mIndicatorOptions.sliderGap
|
||||
val sliderHeight = mIndicatorOptions.sliderHeight
|
||||
val left =
|
||||
currentPosition * maxWidth + currentPosition * +indicatorGap + (maxWidth + indicatorGap) * mIndicatorOptions.slideProgress
|
||||
mRectF.set(left, 0f, left + maxWidth, sliderHeight)
|
||||
drawRoundRect(canvas, sliderHeight, sliderHeight,false)
|
||||
}
|
||||
|
||||
protected open fun drawRoundRect(
|
||||
canvas: Canvas,
|
||||
rx: Float,
|
||||
ry: Float,
|
||||
isWidth:Boolean
|
||||
) {
|
||||
drawDash(canvas)
|
||||
}
|
||||
|
||||
protected open fun drawDash(canvas: Canvas) {}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.drawer
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.LinearGradient
|
||||
import android.graphics.Shader
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2019/11/26.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
class RoundRectDrawer internal constructor(val indicatorOptions: IndicatorOptions) : RectDrawer(
|
||||
indicatorOptions
|
||||
) {
|
||||
|
||||
override fun drawRoundRect(canvas: Canvas, rx: Float, ry: Float, isWidth: Boolean) {
|
||||
if(isWidth) {
|
||||
val linearGradient =
|
||||
LinearGradient(
|
||||
mRectF.left,
|
||||
(mRectF.bottom - mRectF.top) / 2,
|
||||
mRectF.right,
|
||||
(mRectF.bottom - mRectF.top) / 2,
|
||||
indicatorOptions.checkedSliderColor,
|
||||
indicatorOptions.checkedEndSliderColor,
|
||||
Shader.TileMode.CLAMP
|
||||
)
|
||||
mPaint.shader = linearGradient
|
||||
}else{
|
||||
mPaint.color = indicatorOptions.normalSliderColor
|
||||
mPaint.shader = null
|
||||
}
|
||||
canvas.drawRoundRect(mRectF, rx, ry, mPaint)
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.enums
|
||||
|
||||
import android.widget.LinearLayout
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangpan
|
||||
* @date 2021/1/21
|
||||
*/
|
||||
class IndicatorOrientation {
|
||||
companion object {
|
||||
const val INDICATOR_HORIZONTAL = LinearLayout.HORIZONTAL
|
||||
const val INDICATOR_VERTICAL = LinearLayout.VERTICAL
|
||||
const val INDICATOR_RTL = 3
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.enums
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhangpan on 2019-10-18.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
interface IndicatorSlideMode {
|
||||
companion object {
|
||||
const val NORMAL = 0
|
||||
const val SMOOTH = 2
|
||||
const val WORM = 3
|
||||
const val SCALE = 4
|
||||
const val COLOR = 5
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.enums
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhangpan on 2019-10-18.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
interface IndicatorStyle {
|
||||
companion object {
|
||||
const val CIRCLE = 0
|
||||
const val DASH = 1 shl 1
|
||||
const val ROUND_RECT = 1 shl 2
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.option;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.utils.IndicatorUtils;
|
||||
import com.mogo.och.unmanned.taxi.passenger.R;
|
||||
|
||||
public class AttrsController {
|
||||
|
||||
public static void initAttrs(@NonNull Context context, @Nullable AttributeSet attrs,
|
||||
IndicatorOptions indicatorOptions) {
|
||||
if (attrs != null) {
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IndicatorView);
|
||||
int indicatorSlideMode = typedArray.getInt(R.styleable.IndicatorView_vpi_slide_mode, 0);
|
||||
int indicatorStyle = typedArray.getInt(R.styleable.IndicatorView_vpi_style, 0);
|
||||
int checkedColor = typedArray.getColor(R.styleable.IndicatorView_vpi_slider_checked_color,
|
||||
Color.parseColor("#6C6D72"));
|
||||
int normalColor = typedArray.getColor(R.styleable.IndicatorView_vpi_slider_normal_color,
|
||||
Color.parseColor("#8C18171C"));
|
||||
int orientation = typedArray.getInt(R.styleable.IndicatorView_vpi_orientation, 0);
|
||||
float radius = typedArray.getDimension(R.styleable.IndicatorView_vpi_slider_radius,
|
||||
IndicatorUtils.dp2px(8));
|
||||
indicatorOptions.setCheckedColor(checkedColor);
|
||||
indicatorOptions.setNormalSliderColor(normalColor);
|
||||
indicatorOptions.setOrientation(orientation);
|
||||
indicatorOptions.setIndicatorStyle(indicatorStyle);
|
||||
indicatorOptions.setSlideMode(indicatorSlideMode);
|
||||
indicatorOptions.setSliderWidth(radius * 2, radius * 2);
|
||||
typedArray.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.option
|
||||
|
||||
import android.graphics.Color
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.annotation.AIndicatorOrientation
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.annotation.AIndicatorSlideMode
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.annotation.AIndicatorStyle
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorOrientation
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.enums.IndicatorSlideMode
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.utils.IndicatorUtils
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhpan on 2019/11/20.
|
||||
* Description:Indicator的配置参数
|
||||
</pre> *
|
||||
*/
|
||||
class IndicatorOptions {
|
||||
|
||||
@AIndicatorOrientation
|
||||
var orientation = IndicatorOrientation.INDICATOR_HORIZONTAL
|
||||
|
||||
@AIndicatorStyle
|
||||
var indicatorStyle: Int = 0
|
||||
|
||||
/**
|
||||
* Indicator滑动模式,目前仅支持两种
|
||||
*
|
||||
* @see IndicatorSlideMode.NORMAL
|
||||
*
|
||||
* @see IndicatorSlideMode.SMOOTH
|
||||
*/
|
||||
@AIndicatorSlideMode
|
||||
var slideMode: Int = 0
|
||||
|
||||
/**
|
||||
* 页面size
|
||||
*/
|
||||
var pageSize: Int = 0
|
||||
|
||||
/**
|
||||
* 未选中时Indicator颜色
|
||||
*/
|
||||
var normalSliderColor: Int = 0
|
||||
|
||||
/**
|
||||
* 选中时Indicator颜色
|
||||
*/
|
||||
var checkedSliderColor: Int = 0
|
||||
/**
|
||||
* 选中时IndicatorEnd颜色
|
||||
*/
|
||||
var checkedEndSliderColor: Int = 0
|
||||
|
||||
/**
|
||||
* Indicator间距
|
||||
*/
|
||||
var sliderGap: Float = 0f
|
||||
|
||||
var sliderHeight: Float = 0f
|
||||
get() = if (field > 0) field else normalSliderWidth / 2
|
||||
|
||||
var normalSliderWidth: Float = 0f
|
||||
|
||||
var checkedSliderWidth: Float = 0f
|
||||
|
||||
/**
|
||||
* 指示器当前位置
|
||||
*/
|
||||
var currentPosition: Int = 0
|
||||
|
||||
/**
|
||||
* 从一个点滑动到另一个点的进度
|
||||
*/
|
||||
var slideProgress: Float = 0f
|
||||
|
||||
var showIndicatorOneItem: Boolean = false
|
||||
|
||||
init {
|
||||
normalSliderWidth = IndicatorUtils.dp2px(8f)
|
||||
.toFloat()
|
||||
checkedSliderWidth = normalSliderWidth
|
||||
sliderGap = normalSliderWidth
|
||||
normalSliderColor = Color.parseColor("#8C18171C")
|
||||
checkedSliderColor = Color.parseColor("#8C6C6D72")
|
||||
slideMode = IndicatorSlideMode.NORMAL
|
||||
}
|
||||
|
||||
fun setCheckedColor(checkedColor: Int) {
|
||||
this.checkedSliderColor = checkedColor
|
||||
}
|
||||
|
||||
fun setSliderWidth(
|
||||
normalIndicatorWidth: Float,
|
||||
checkedIndicatorWidth: Float
|
||||
) {
|
||||
this.normalSliderWidth = normalIndicatorWidth
|
||||
this.checkedSliderWidth = checkedIndicatorWidth
|
||||
}
|
||||
|
||||
fun setSliderWidth(sliderWidth: Float) {
|
||||
setSliderWidth(sliderWidth, sliderWidth)
|
||||
}
|
||||
|
||||
fun setSliderColor(
|
||||
normalColor: Int,
|
||||
checkedColor: Int,
|
||||
selectedEndColor: Int
|
||||
) {
|
||||
this.normalSliderColor = normalColor
|
||||
this.checkedSliderColor = checkedColor
|
||||
this.checkedEndSliderColor = selectedEndColor
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.mogo.och.unmanned.passenger.widget.indicator.utils
|
||||
|
||||
import android.content.res.Resources
|
||||
import com.mogo.och.unmanned.passenger.widget.indicator.option.IndicatorOptions
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by zhangpan on 2020-01-20.
|
||||
* Description:
|
||||
</pre> *
|
||||
*/
|
||||
object IndicatorUtils {
|
||||
|
||||
@JvmStatic
|
||||
fun dp2px(dpValue: Float): Int {
|
||||
return (0.5f + dpValue * Resources.getSystem().displayMetrics.density).toInt()
|
||||
}
|
||||
|
||||
fun getCoordinateX(
|
||||
indicatorOptions: IndicatorOptions,
|
||||
maxDiameter: Float,
|
||||
index: Int
|
||||
): Float {
|
||||
val normalIndicatorWidth = indicatorOptions.normalSliderWidth
|
||||
return maxDiameter / 2 + (normalIndicatorWidth + indicatorOptions.sliderGap) * index
|
||||
}
|
||||
|
||||
fun getCoordinateY(maxDiameter: Float): Float {
|
||||
return maxDiameter / 2
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 872 B After Width: | Height: | Size: 840 B |
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mogo.och.unmanned.passenger.ui.video.RoundedViewConstrainLayout 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_marginTop="@dimen/dp_20"
|
||||
android:layout_marginBottom="@dimen/dp_20"
|
||||
android:layout_width="@dimen/dp_410"
|
||||
android:layout_height="@dimen/dp_230">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/video_item_image"
|
||||
android:layout_gravity="center"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/v_bottom_bg"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:background="@color/taxi_cp_66000000"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_60"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/actv_video_head"
|
||||
app:layout_constraintTop_toTopOf="@+id/v_bottom_bg"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/v_bottom_bg"
|
||||
app:layout_constraintEnd_toStartOf="@+id/aciv_playing_bar"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="@dimen/dp_18"
|
||||
android:layout_marginEnd="@dimen/dp_10"
|
||||
android:textSize="@dimen/dp_29"
|
||||
android:textColor="@color/white"
|
||||
android:singleLine="true"
|
||||
android:text="蘑菇车联湖南衡阳蘑菇车联湖南衡阳智…"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/aciv_playing_bar"
|
||||
android:layout_marginStart="@dimen/dp_25"
|
||||
android:src="@drawable/taxi_p_music_list_playing"
|
||||
app:layout_constraintTop_toTopOf="@+id/v_bottom_bg"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/v_bottom_bg"
|
||||
app:layout_constraintEnd_toEndOf="@+id/v_bottom_bg"
|
||||
app:layout_constraintStart_toEndOf="@+id/actv_video_head"
|
||||
android:visibility="gone"
|
||||
android:layout_marginEnd="@dimen/dp_18"
|
||||
android:layout_width="@dimen/dp_35"
|
||||
android:layout_height="@dimen/dp_29"/>
|
||||
|
||||
</com.mogo.och.unmanned.passenger.ui.video.RoundedViewConstrainLayout>
|
||||
|
||||
@@ -10,28 +10,12 @@
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/infoVideoPlaylist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1231dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="194dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_width="@dimen/dp_410"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="@dimen/dp_90"
|
||||
android:layout_marginTop="@dimen/dp_121"
|
||||
android:layout_marginBottom="@dimen/dp_160"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.mogo.och.unmanned.passenger.widget.indicator.IndicatorView
|
||||
android:id="@+id/infoIndicatorView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginBottom="@dimen/dp_231"
|
||||
app:vpi_orientation="horizontal"
|
||||
app:vpi_slide_mode="scale"
|
||||
app:vpi_slider_checked_color="@color/taxi_p_traffic_light_red_color_up"
|
||||
app:vpi_slider_normal_color="@color/taxi_p_check_keyboard_input_field"
|
||||
app:vpi_slider_radius="@dimen/dp_20"
|
||||
app:vpi_style="round_rect" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -92,6 +92,7 @@
|
||||
|
||||
<color name="taxi_cp_A3C9EA">#A3C9EA</color>
|
||||
<color name="taxi_cp_394047">#394047</color>
|
||||
<color name="taxi_cp_66000000">#66000000</color>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -117,11 +117,11 @@ public class MogoApplication extends MainMoGoApplication {
|
||||
countlyConfig.crashes.enableRecordAllThreadsWithCrash();
|
||||
|
||||
// 初始化Countly SDK配置
|
||||
Countly.sharedInstance().init(countlyConfig);
|
||||
// java崩溃报告
|
||||
Countly.sharedInstance().crashes();
|
||||
// C++ 崩溃报告
|
||||
CountlyNative.initNative(this);
|
||||
// Countly.sharedInstance().init(countlyConfig);
|
||||
// // java崩溃报告
|
||||
// Countly.sharedInstance().crashes();
|
||||
// // C++ 崩溃报告
|
||||
// CountlyNative.initNative(this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user