improve the volume slider ux

This commit is contained in:
tibbi 2017-08-06 22:35:19 +02:00
parent 8aaf1df568
commit c857c17f50
2 changed files with 11 additions and 2 deletions

View file

@ -273,7 +273,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
} }
override fun onConfigurationChanged(newConfig: Configuration?) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
loadImage() loadImage()
} }

View file

@ -51,6 +51,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
private var mTouchDownY = 0f private var mTouchDownY = 0f
private var mTouchDownTime = 0L private var mTouchDownTime = 0L
private var mTouchDownVolume = 0 private var mTouchDownVolume = 0
private var mLastTouchY = 0f
private var mSlideInfoText = "" private var mSlideInfoText = ""
private var mSlideInfoFadeHandler = Handler() private var mSlideInfoFadeHandler = Handler()
@ -118,7 +119,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
} }
} }
override fun onConfigurationChanged(newConfig: Configuration?) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
setVideoSize() setVideoSize()
initTimeHolder() initTimeHolder()
@ -133,6 +134,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
mTouchDownX = event.x mTouchDownX = event.x
mTouchDownY = event.y mTouchDownY = event.y
mLastTouchY = event.y
mTouchDownTime = System.currentTimeMillis() mTouchDownTime = System.currentTimeMillis()
mTouchDownVolume = getCurrentVolume() mTouchDownVolume = getCurrentVolume()
mSlideInfoText = "${getString(R.string.volume)}:\n" mSlideInfoText = "${getString(R.string.volume)}:\n"
@ -144,8 +146,15 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
if (Math.abs(diffY) > Math.abs(diffX)) { if (Math.abs(diffY) > Math.abs(diffX)) {
var percent = ((diffY / ViewPagerActivity.screenHeight) * 100).toInt() * 3 var percent = ((diffY / ViewPagerActivity.screenHeight) * 100).toInt() * 3
percent = Math.min(100, Math.max(-100, percent)) percent = Math.min(100, Math.max(-100, percent))
if ((percent == 100 && event.y > mLastTouchY) || (percent == -100 && event.y < mLastTouchY)) {
mTouchDownY = event.y
mTouchDownVolume = getCurrentVolume()
}
volumePercentChanged(percent) volumePercentChanged(percent)
} }
mLastTouchY = event.y
} }
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {