fix side volume/brightness gesture control at the video player

This commit is contained in:
tibbi 2019-01-03 19:52:16 +01:00
parent af3cfc46bf
commit 2dfbf32f1c

View File

@ -10,8 +10,8 @@ import android.view.MotionEvent
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.RelativeLayout import android.widget.RelativeLayout
import android.widget.TextView import android.widget.TextView
import com.simplemobiletools.commons.extensions.onGlobalLayout
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.activities.ViewPagerActivity
import com.simplemobiletools.gallery.pro.extensions.audioManager import com.simplemobiletools.gallery.pro.extensions.audioManager
import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION
import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD
@ -25,6 +25,7 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co
private var mTouchDownValue = -1 private var mTouchDownValue = -1
private var mTempBrightness = 0 private var mTempBrightness = 0
private var mLastTouchY = 0f private var mLastTouchY = 0f
private var mViewHeight = 0
private var mIsBrightnessScroll = false private var mIsBrightnessScroll = false
private var mPassTouches = false private var mPassTouches = false
private var dragThreshold = DRAG_THRESHOLD * context.resources.displayMetrics.density private var dragThreshold = DRAG_THRESHOLD * context.resources.displayMetrics.density
@ -44,6 +45,9 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co
mParentView = parentView mParentView = parentView
mIsBrightnessScroll = isBrightness mIsBrightnessScroll = isBrightness
mSlideInfoText = activity.getString(if (isBrightness) R.string.brightness else R.string.volume) mSlideInfoText = activity.getString(if (isBrightness) R.string.brightness else R.string.volume)
onGlobalLayout {
mViewHeight = height
}
} }
override fun dispatchTouchEvent(ev: MotionEvent): Boolean { override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
@ -80,7 +84,7 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co
val diffY = mTouchDownY - event.y val diffY = mTouchDownY - event.y
if (Math.abs(diffY) > dragThreshold && Math.abs(diffY) > Math.abs(diffX)) { if (Math.abs(diffY) > dragThreshold && Math.abs(diffY) > Math.abs(diffX)) {
var percent = ((diffY / ViewPagerActivity.screenHeight) * 100).toInt() * 3 var percent = ((diffY / mViewHeight) * 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)) { if ((percent == 100 && event.y > mLastTouchY) || (percent == -100 && event.y < mLastTouchY)) {