mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
allow changing the volume by finger dragging on the right side of the video
This commit is contained in:
parent
dc42dd566f
commit
af84b8e9e3
2 changed files with 14 additions and 1 deletions
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.database.Cursor
|
||||
import android.media.AudioManager
|
||||
import android.net.Uri
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
@ -21,6 +22,7 @@ import java.io.File
|
|||
import java.util.*
|
||||
|
||||
val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
val Context.audioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
||||
fun Context.getRealPathFromURI(uri: Uri): String? {
|
||||
var cursor: Cursor? = null
|
||||
|
|
|
@ -18,6 +18,7 @@ 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.audioManager
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.extensions.getNavBarHeight
|
||||
import com.simplemobiletools.gallery.extensions.hasNavBar
|
||||
|
@ -26,6 +27,7 @@ import com.simplemobiletools.gallery.models.Medium
|
|||
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
|
||||
|
||||
|
@ -48,6 +50,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
|||
private var mTouchDownX = 0f
|
||||
private var mTouchDownY = 0f
|
||||
private var mTouchDownTime = 0L
|
||||
private var mTouchDownVolume = 0
|
||||
|
||||
lateinit var mView: View
|
||||
lateinit var medium: Medium
|
||||
|
@ -128,6 +131,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
|||
mTouchDownX = event.x
|
||||
mTouchDownY = event.y
|
||||
mTouchDownTime = System.currentTimeMillis()
|
||||
mTouchDownVolume = getCurrentVolume()
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val diffX = mTouchDownX - event.x
|
||||
|
@ -147,8 +151,15 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
|||
}
|
||||
}
|
||||
|
||||
private fun volumePercentChanged(percent: Int) {
|
||||
private fun getCurrentVolume() = context.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||
|
||||
private fun volumePercentChanged(percent: Int) {
|
||||
val stream = AudioManager.STREAM_MUSIC
|
||||
val maxVolume = context.audioManager.getStreamMaxVolume(stream)
|
||||
val percentPerPoint = Math.ceil(100 / maxVolume.toDouble()).toInt()
|
||||
val addPoints = percent / percentPerPoint
|
||||
val newVolume = Math.min(maxVolume, Math.max(0, mTouchDownVolume + addPoints))
|
||||
context.audioManager.setStreamVolume(stream, newVolume, 0)
|
||||
}
|
||||
|
||||
private fun initTimeHolder() {
|
||||
|
|
Loading…
Reference in a new issue