//package com.dlc.exam.ui.widget
//
//import android.content.Context
//import android.media.AudioManager
//import android.provider.Settings
//import android.provider.Settings.SettingNotFoundException
//import android.util.AttributeSet
//import android.util.Log
//import android.widget.SeekBar
//import cn.jzvd.JZUtils
//import cn.jzvd.JzvdStd
//import kotlin.math.abs
//
///**
// * info
// *
// * @author ReiChin_
// */
//class ExamJzvdStd @JvmOverloads constructor(
//    context: Context,
//    attrs: AttributeSet? = null,
//) : JzvdStd(context, attrs) {
//
//    /**
//     * 设置是否可以拖拽进度条
//     */
//    fun setDraggable(enabled: Boolean) {
//        val seekBar = findViewById<SeekBar>(cn.jzvd.R.id.bottom_seek_progress)
//        seekBar.isEnabled = enabled
//    }
//
////    override fun onTouch(v: View?, event: MotionEvent?): Boolean {
////        if (v?.id == cn.jzvd.R.id.surface_container) {
////            val seekBar = findViewById<SeekBar>(cn.jzvd.R.id.bottom_seek_progress)
////            return if (seekBar.isEnabled) super.onTouch(v, event) else false
////        }
////        return super.onTouch(v, event)
////    }
//
//    override fun touchActionMove(x: Float, y: Float) {
//        Log.i(TAG, "onTouch surfaceContainer actionMove [" + this.hashCode() + "] ")
//        val deltaX = x - mDownX
//        var deltaY = y - mDownY
//        val absDeltaX = abs(deltaX)
//        val absDeltaY = abs(deltaY)
//        if (screen == SCREEN_FULLSCREEN) {
//            //拖动的是NavigationBar和状态栏
//            if (mDownX > JZUtils.getScreenWidth(context) || mDownY < JZUtils.getStatusBarHeight(
//                    context
//                )
//            ) {
//                return
//            }
//            if (!mChangePosition && !mChangeVolume && !mChangeBrightness) {
//                if (absDeltaX > THRESHOLD || absDeltaY > THRESHOLD) {
//                    cancelProgressTimer()
//                    if (absDeltaX >= THRESHOLD) {
//                        // 全屏模式下的CURRENT_STATE_ERROR状态下,不响应进度拖动事件.
//                        // 否则会因为mediaplayer的状态非法导致App Crash
//                        val seekBar = findViewById<SeekBar>(cn.jzvd.R.id.bottom_seek_progress)
//                        if (state != STATE_ERROR && seekBar.isEnabled) {
//                            mChangePosition = true
//                            mGestureDownPosition = currentPositionWhenPlaying
//                        }
//                    } else {
//                        //如果y轴滑动距离超过设置的处理范围，那么进行滑动事件处理
//                        if (mDownX < mScreenHeight * 0.5f) { //左侧改变亮度
//                            mChangeBrightness = true
//                            val lp = JZUtils.getWindow(context).attributes
//                            if (lp.screenBrightness < 0) {
//                                try {
//                                    mGestureDownBrightness = Settings.System.getInt(
//                                        context.contentResolver, Settings.System.SCREEN_BRIGHTNESS
//                                    ).toFloat()
//                                    Log.i(
//                                        TAG,
//                                        "current system brightness: $mGestureDownBrightness"
//                                    )
//                                } catch (e: SettingNotFoundException) {
//                                    e.printStackTrace()
//                                }
//                            } else {
//                                mGestureDownBrightness = lp.screenBrightness * 255
//                                Log.i(
//                                    TAG,
//                                    "current activity brightness: $mGestureDownBrightness"
//                                )
//                            }
//                        } else { //右侧改变声音
//                            mChangeVolume = true
//                            mGestureDownVolume =
//                                mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
//                        }
//                    }
//                }
//            }
//        }
//        if (mChangePosition) {
//            val totalTimeDuration = duration
//            if (PROGRESS_DRAG_RATE <= 0) {
//                Log.d(TAG, "error PROGRESS_DRAG_RATE value")
//                PROGRESS_DRAG_RATE = 1f
//            }
//            mSeekTimePosition =
//                (mGestureDownPosition + deltaX * totalTimeDuration / (mScreenWidth * PROGRESS_DRAG_RATE)).toLong()
//            if (mSeekTimePosition > totalTimeDuration) mSeekTimePosition = totalTimeDuration
//            val seekTime = JZUtils.stringForTime(mSeekTimePosition)
//            val totalTime = JZUtils.stringForTime(totalTimeDuration)
//            showProgressDialog(deltaX, seekTime, mSeekTimePosition, totalTime, totalTimeDuration)
//        }
//        if (mChangeVolume) {
//            deltaY = -deltaY
//            val max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
//            val deltaV = (max * deltaY * 3 / mScreenHeight).toInt()
//            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mGestureDownVolume + deltaV, 0)
//            //dialog中显示百分比
//            val volumePercent =
//                (mGestureDownVolume * 100 / max + deltaY * 3 * 100 / mScreenHeight).toInt()
//            showVolumeDialog(-deltaY, volumePercent)
//        }
//        if (mChangeBrightness) {
//            deltaY = -deltaY
//            val deltaV = (255 * deltaY * 3 / mScreenHeight).toInt()
//            val params = JZUtils.getWindow(context).attributes
//            if ((mGestureDownBrightness + deltaV) / 255 >= 1) { //这和声音有区别，必须自己过滤一下负值
//                params.screenBrightness = 1f
//            } else if ((mGestureDownBrightness + deltaV) / 255 <= 0) {
//                params.screenBrightness = 0.01f
//            } else {
//                params.screenBrightness = (mGestureDownBrightness + deltaV) / 255
//            }
//            JZUtils.getWindow(context).attributes = params
//            //dialog中显示百分比
//            val brightnessPercent =
//                (mGestureDownBrightness * 100 / 255 + deltaY * 3 * 100 / mScreenHeight).toInt()
//            showBrightnessDialog(brightnessPercent)
//            //                        mDownY = y;
//        }
//    }
//
//}