add a volume slider at the video fragments right side

This commit is contained in:
tibbi 2017-08-06 16:44:00 +02:00
parent 1074043c93
commit 15c20ab758
3 changed files with 47 additions and 0 deletions

View file

@ -17,6 +17,7 @@ import com.simplemobiletools.commons.extensions.getFormattedDuration
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.ViewPagerActivity
import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.getNavBarHeight
import com.simplemobiletools.gallery.extensions.hasNavBar
@ -26,6 +27,7 @@ import kotlinx.android.synthetic.main.pager_video_item.view.*
import java.io.IOException
class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSeekBarChangeListener {
private val CLICK_MAX_DURATION = 150
private var mMediaPlayer: MediaPlayer? = null
private var mSurfaceView: SurfaceView? = null
@ -43,6 +45,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
private var mCurrTime = 0
private var mDuration = 0
private var mTouchDownX = 0f
private var mTouchDownY = 0f
private var mTouchDownTime = 0L
lateinit var mView: View
lateinit var medium: Medium
@ -82,6 +88,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
mSurfaceHolder!!.addCallback(this)
mSurfaceView!!.setOnClickListener({ toggleFullscreen() })
mView.video_holder.setOnClickListener { toggleFullscreen() }
mView.video_volume_controller.setOnTouchListener { v, event ->
handleVolumeTouched(event)
true
}
initTimeHolder()
}
@ -112,6 +122,35 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
listener?.fragmentClicked()
}
private fun handleVolumeTouched(event: MotionEvent) {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
mTouchDownX = event.x
mTouchDownY = event.y
mTouchDownTime = System.currentTimeMillis()
}
MotionEvent.ACTION_MOVE -> {
val diffX = mTouchDownX - event.x
val diffY = mTouchDownY - event.y
if (Math.abs(diffY) > Math.abs(diffX)) {
var percent = ((diffY / ViewPagerActivity.screenHeight) * 100).toInt() * 2
percent = Math.min(100, Math.max(-100, percent))
volumePercentChanged(percent)
}
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
mView.video_holder.performClick()
}
}
}
}
private fun volumePercentChanged(percent: Int) {
}
private fun initTimeHolder() {
mTimeHolder = mView.video_time_holder
val res = resources

View file

@ -12,6 +12,13 @@
android:layout_centerInParent="true"
android:background="@android:color/transparent"/>
<RelativeLayout
android:id="@+id/video_volume_controller"
android:layout_width="@dimen/video_side_slider_width"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
<ImageView
android:id="@+id/video_play_outline"
android:layout_width="@dimen/play_outline_size_big"

View file

@ -8,4 +8,5 @@
<dimen name="play_outline_size_big">150dp</dimen>
<dimen name="timer_padding">24dp</dimen>
<dimen name="tmb_shadow_height">50dp</dimen>
<dimen name="video_side_slider_width">150dp</dimen>
</resources>