rely on GestureFrameLayout at zooming videos on separate screen too
This commit is contained in:
parent
59dd51f06a
commit
9077a9d6b2
|
@ -5,7 +5,6 @@ import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Matrix
|
|
||||||
import android.graphics.Point
|
import android.graphics.Point
|
||||||
import android.graphics.SurfaceTexture
|
import android.graphics.SurfaceTexture
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
|
@ -43,27 +42,18 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
private var mScreenWidth = 0
|
private var mScreenWidth = 0
|
||||||
private var mCurrTime = 0
|
private var mCurrTime = 0
|
||||||
private var mDuration = 0
|
private var mDuration = 0
|
||||||
private var mSaveScale = 1f
|
|
||||||
private var mRight = 0f
|
|
||||||
private var mBottom = 0f
|
|
||||||
private var mLastTouchX = 0f
|
|
||||||
private var mLastTouchY = 0f
|
|
||||||
private var mDragThreshold = 0f
|
private var mDragThreshold = 0f
|
||||||
private var mTouchDownX = 0f
|
private var mTouchDownX = 0f
|
||||||
private var mTouchDownY = 0f
|
private var mTouchDownY = 0f
|
||||||
private var mTouchDownTime = 0L
|
private var mTouchDownTime = 0L
|
||||||
private var mProgressAtDown = 0L
|
private var mProgressAtDown = 0L
|
||||||
private var mCloseDownThreshold = 100f
|
private var mCloseDownThreshold = 100f
|
||||||
private var mCurrZoomMode = ZOOM_MODE_NONE
|
|
||||||
|
|
||||||
private var mUri: Uri? = null
|
private var mUri: Uri? = null
|
||||||
private var mExoPlayer: SimpleExoPlayer? = null
|
private var mExoPlayer: SimpleExoPlayer? = null
|
||||||
private var mVideoSize = Point(0, 0)
|
private var mVideoSize = Point(0, 0)
|
||||||
private var mTimerHandler = Handler()
|
private var mTimerHandler = Handler()
|
||||||
private var mPlayWhenReadyHandler = Handler()
|
private var mPlayWhenReadyHandler = Handler()
|
||||||
private var mScaleDetector: ScaleGestureDetector? = null
|
|
||||||
private var mMatrices = FloatArray(9)
|
|
||||||
private val mMatrix = Matrix()
|
|
||||||
|
|
||||||
private var mIgnoreCloseDown = false
|
private var mIgnoreCloseDown = false
|
||||||
|
|
||||||
|
@ -168,6 +158,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
video_curr_time.setOnClickListener { skip(false) }
|
video_curr_time.setOnClickListener { skip(false) }
|
||||||
video_duration.setOnClickListener { skip(true) }
|
video_duration.setOnClickListener { skip(true) }
|
||||||
video_toggle_play_pause.setOnClickListener { togglePlayPause() }
|
video_toggle_play_pause.setOnClickListener { togglePlayPause() }
|
||||||
|
video_surface_frame.setOnClickListener { toggleFullscreen() }
|
||||||
|
|
||||||
video_next_file.beVisibleIf(intent.getBooleanExtra(SHOW_NEXT_ITEM, false))
|
video_next_file.beVisibleIf(intent.getBooleanExtra(SHOW_NEXT_ITEM, false))
|
||||||
video_next_file.setOnClickListener { handleNextFile() }
|
video_next_file.setOnClickListener { handleNextFile() }
|
||||||
|
@ -175,14 +166,9 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
video_prev_file.beVisibleIf(intent.getBooleanExtra(SHOW_PREV_ITEM, false))
|
video_prev_file.beVisibleIf(intent.getBooleanExtra(SHOW_PREV_ITEM, false))
|
||||||
video_prev_file.setOnClickListener { handlePrevFile() }
|
video_prev_file.setOnClickListener { handlePrevFile() }
|
||||||
|
|
||||||
video_player_holder.setOnTouchListener { view, event ->
|
video_surface_frame.setOnTouchListener { view, event ->
|
||||||
handleEvent(event)
|
handleEvent(event)
|
||||||
true
|
false
|
||||||
}
|
|
||||||
|
|
||||||
video_surface.setOnTouchListener { view, event ->
|
|
||||||
handleEventWithZooming(event)
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initExoPlayer()
|
initExoPlayer()
|
||||||
|
@ -208,7 +194,6 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
}
|
}
|
||||||
|
|
||||||
mDragThreshold = DRAG_THRESHOLD * resources.displayMetrics.density
|
mDragThreshold = DRAG_THRESHOLD * resources.displayMetrics.density
|
||||||
mScaleDetector = ScaleGestureDetector(applicationContext, ScaleListener())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initExoPlayer() {
|
private fun initExoPlayer() {
|
||||||
|
@ -510,7 +495,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
val diffX = event.x - mTouchDownX
|
val diffX = event.x - mTouchDownX
|
||||||
val diffY = event.y - mTouchDownY
|
val diffY = event.y - mTouchDownY
|
||||||
|
|
||||||
if (mIsDragged || (Math.abs(diffX) > mDragThreshold && Math.abs(diffX) > Math.abs(diffY))) {
|
if (mIsDragged || (Math.abs(diffX) > mDragThreshold && Math.abs(diffX) > Math.abs(diffY)) && video_surface_frame.controller.state.zoom == 1f) {
|
||||||
if (!mIsDragged) {
|
if (!mIsDragged) {
|
||||||
arrayOf(video_curr_time, video_seekbar, video_duration).forEach {
|
arrayOf(video_curr_time, video_seekbar, video_duration).forEach {
|
||||||
it.animate().alpha(1f).start()
|
it.animate().alpha(1f).start()
|
||||||
|
@ -549,10 +534,6 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
if (!mIsPlaying) {
|
if (!mIsPlaying) {
|
||||||
togglePlayPause()
|
togglePlayPause()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
|
||||||
toggleFullscreen()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mIsDragged = false
|
mIsDragged = false
|
||||||
}
|
}
|
||||||
|
@ -627,150 +608,4 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {}
|
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {}
|
||||||
|
|
||||||
private fun handleEventWithZooming(event: MotionEvent) {
|
|
||||||
mScaleDetector?.onTouchEvent(event)
|
|
||||||
|
|
||||||
mMatrix.getValues(mMatrices)
|
|
||||||
val x = mMatrices[Matrix.MTRANS_X]
|
|
||||||
val y = mMatrices[Matrix.MTRANS_Y]
|
|
||||||
|
|
||||||
when (event.actionMasked) {
|
|
||||||
MotionEvent.ACTION_DOWN -> {
|
|
||||||
mTouchDownTime = System.currentTimeMillis()
|
|
||||||
mCurrZoomMode = ZOOM_MODE_DRAG
|
|
||||||
mLastTouchX = event.x
|
|
||||||
mLastTouchY = event.y
|
|
||||||
|
|
||||||
mTouchDownX = event.x
|
|
||||||
mTouchDownY = event.y
|
|
||||||
mProgressAtDown = mExoPlayer!!.currentPosition
|
|
||||||
}
|
|
||||||
MotionEvent.ACTION_UP -> {
|
|
||||||
mCurrZoomMode = ZOOM_MODE_NONE
|
|
||||||
val diffX = mTouchDownX - event.x
|
|
||||||
val diffY = mTouchDownY - event.y
|
|
||||||
|
|
||||||
val downGestureDuration = System.currentTimeMillis() - mTouchDownTime
|
|
||||||
if (!mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION && mSaveScale == 1f) {
|
|
||||||
supportFinishAfterTransition()
|
|
||||||
}
|
|
||||||
mIgnoreCloseDown = false
|
|
||||||
|
|
||||||
if (mIsDragged) {
|
|
||||||
if (mIsFullscreen) {
|
|
||||||
arrayOf(video_curr_time, video_seekbar, video_duration).forEach {
|
|
||||||
it.animate().alpha(0f).start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mIsPlaying) {
|
|
||||||
togglePlayPause()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
|
||||||
toggleFullscreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mIsDragged = false
|
|
||||||
}
|
|
||||||
MotionEvent.ACTION_POINTER_DOWN -> {
|
|
||||||
mLastTouchX = event.x
|
|
||||||
mLastTouchY = event.y
|
|
||||||
mCurrZoomMode = ZOOM_MODE_ZOOM
|
|
||||||
mIgnoreCloseDown = true
|
|
||||||
}
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
|
||||||
val diffX = event.x - mTouchDownX
|
|
||||||
val diffY = event.y - mTouchDownY
|
|
||||||
if (mSaveScale == 1f && (mIsDragged || (Math.abs(diffX) > mDragThreshold && Math.abs(diffX) > Math.abs(diffY)))) {
|
|
||||||
if (!mIsDragged) {
|
|
||||||
arrayOf(video_curr_time, video_seekbar, video_duration).forEach {
|
|
||||||
it.animate().alpha(1f).start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mIgnoreCloseDown = true
|
|
||||||
mIsDragged = true
|
|
||||||
var percent = ((diffX / mScreenWidth) * 100).toInt()
|
|
||||||
percent = Math.min(100, Math.max(-100, percent))
|
|
||||||
|
|
||||||
val skipLength = (mDuration * 1000f) * (percent / 100f)
|
|
||||||
var newProgress = mProgressAtDown + skipLength
|
|
||||||
newProgress = Math.max(Math.min(mExoPlayer!!.duration.toFloat(), newProgress), 0f)
|
|
||||||
val newSeconds = (newProgress / 1000).toInt()
|
|
||||||
setPosition(newSeconds)
|
|
||||||
resetPlayWhenReady()
|
|
||||||
} else if (mCurrZoomMode == ZOOM_MODE_ZOOM || mCurrZoomMode == ZOOM_MODE_DRAG && mSaveScale > MIN_VIDEO_ZOOM_SCALE) {
|
|
||||||
var deltaX = event.x - mLastTouchX
|
|
||||||
var deltaY = event.y - mLastTouchY
|
|
||||||
if (y + deltaY > 0) {
|
|
||||||
deltaY = -y
|
|
||||||
} else if (y + deltaY < -mBottom) {
|
|
||||||
deltaY = -(y + mBottom)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x + deltaX > 0) {
|
|
||||||
deltaX = -x
|
|
||||||
} else if (x + deltaX < -mRight) {
|
|
||||||
deltaX = -(x + mRight)
|
|
||||||
}
|
|
||||||
|
|
||||||
mMatrix.postTranslate(deltaX, deltaY)
|
|
||||||
mLastTouchX = event.x
|
|
||||||
mLastTouchY = event.y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MotionEvent.ACTION_POINTER_UP -> {
|
|
||||||
mCurrZoomMode = ZOOM_MODE_NONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
video_surface.setTransform(mMatrix)
|
|
||||||
video_surface.invalidate()
|
|
||||||
}
|
|
||||||
|
|
||||||
// taken from https://github.com/Manuiq/ZoomableTextureView
|
|
||||||
private inner class ScaleListener : ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
|
||||||
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
|
||||||
mCurrZoomMode = ZOOM_MODE_ZOOM
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onScale(detector: ScaleGestureDetector): Boolean {
|
|
||||||
val width = video_surface.width
|
|
||||||
val height = video_surface.height
|
|
||||||
if (width <= 0 || height <= 0) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var scaleFactor = detector.scaleFactor
|
|
||||||
val origScale = mSaveScale
|
|
||||||
mSaveScale *= scaleFactor
|
|
||||||
|
|
||||||
if (mSaveScale > MAX_VIDEO_ZOOM_SCALE) {
|
|
||||||
mSaveScale = MAX_VIDEO_ZOOM_SCALE
|
|
||||||
scaleFactor = MAX_VIDEO_ZOOM_SCALE / origScale
|
|
||||||
} else if (mSaveScale < MIN_VIDEO_ZOOM_SCALE) {
|
|
||||||
mSaveScale = MIN_VIDEO_ZOOM_SCALE
|
|
||||||
scaleFactor = MIN_VIDEO_ZOOM_SCALE / origScale
|
|
||||||
}
|
|
||||||
|
|
||||||
mRight = width * mSaveScale - width
|
|
||||||
mBottom = height * mSaveScale - height
|
|
||||||
mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY)
|
|
||||||
if (scaleFactor < 1) {
|
|
||||||
mMatrix.getValues(mMatrices)
|
|
||||||
val y = mMatrices[Matrix.MTRANS_Y]
|
|
||||||
if (scaleFactor < 1) {
|
|
||||||
if (y < -mBottom) {
|
|
||||||
mMatrix.postTranslate(0f, -(y + mBottom))
|
|
||||||
} else if (y > 0) {
|
|
||||||
mMatrix.postTranslate(0f, -y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,11 +115,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
video_surface.setOnTouchListener { view, event ->
|
|
||||||
handleEvent(event)
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
video_surface_frame.setOnTouchListener { view, event ->
|
video_surface_frame.setOnTouchListener { view, event ->
|
||||||
handleEvent(event)
|
handleEvent(event)
|
||||||
false
|
false
|
||||||
|
|
|
@ -12,11 +12,18 @@
|
||||||
android:layout_height="@dimen/default_status_action_height"
|
android:layout_height="@dimen/default_status_action_height"
|
||||||
android:background="@drawable/gradient_background_flipped"/>
|
android:background="@drawable/gradient_background_flipped"/>
|
||||||
|
|
||||||
<TextureView
|
<com.alexvasilkov.gestures.GestureFrameLayout
|
||||||
android:id="@+id/video_surface"
|
android:id="@+id/video_surface_frame"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent">
|
||||||
android:layout_centerInParent="true"/>
|
|
||||||
|
<TextureView
|
||||||
|
android:id="@+id/video_surface"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true"/>
|
||||||
|
|
||||||
|
</com.alexvasilkov.gestures.GestureFrameLayout>
|
||||||
|
|
||||||
<com.simplemobiletools.gallery.pro.views.MediaSideScroll
|
<com.simplemobiletools.gallery.pro.views.MediaSideScroll
|
||||||
android:id="@+id/video_volume_controller"
|
android:id="@+id/video_volume_controller"
|
||||||
|
|
Loading…
Reference in New Issue