send a more advanced click event with coordinates at clicking side slider

This commit is contained in:
tibbi 2018-02-09 19:14:48 +01:00
parent db8a88cbfe
commit 0616117f36
4 changed files with 21 additions and 8 deletions

View file

@ -0,0 +1,13 @@
package com.simplemobiletools.gallery.extensions
import android.os.SystemClock
import android.view.MotionEvent
import android.view.View
fun View.sendFakeClick(x: Float, y: Float) {
val uptime = SystemClock.uptimeMillis()
val event = MotionEvent.obtain(uptime, uptime, MotionEvent.ACTION_DOWN, x, y, 0)
dispatchTouchEvent(event)
event.action = MotionEvent.ACTION_UP
dispatchTouchEvent(event)
}

View file

@ -62,12 +62,12 @@ class PhotoFragment : ViewPagerFragment() {
instant_prev_item.parentView = container instant_prev_item.parentView = container
instant_next_item.parentView = container instant_next_item.parentView = container
photo_brightness_controller.initialize(activity!!, slide_info, true, container) { photo_brightness_controller.initialize(activity!!, slide_info, true, container) { x, y ->
view.apply { view.apply {
if (subsampling_view.isVisible()) { if (subsampling_view.isVisible()) {
subsampling_view.performClick() subsampling_view.sendFakeClick(x, y)
} else { } else {
gif_view.performClick() gif_view.sendFakeClick(x, y)
} }
} }
} }

View file

@ -85,12 +85,12 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
mView!!.apply { mView!!.apply {
brightnessSideScroll = video_brightness_controller brightnessSideScroll = video_brightness_controller
brightnessSideScroll.initialize(activity!!, slide_info, true, container) { brightnessSideScroll.initialize(activity!!, slide_info, true, container) { x, y ->
video_holder.performClick() video_holder.performClick()
} }
volumeSideScroll = video_volume_controller volumeSideScroll = video_volume_controller
volumeSideScroll.initialize(activity!!, slide_info, false, container) { volumeSideScroll.initialize(activity!!, slide_info, false, container) { x, y ->
video_holder.performClick() video_holder.performClick()
} }
} }

View file

@ -33,9 +33,9 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co
private lateinit var activity: Activity private lateinit var activity: Activity
private lateinit var slideInfoView: TextView private lateinit var slideInfoView: TextView
private lateinit var callback: () -> Unit private lateinit var callback: (Float, Float) -> Unit
fun initialize(activity: Activity, slideInfoView: TextView, isBrightness: Boolean, parentView: ViewGroup?, callback: () -> Unit) { fun initialize(activity: Activity, slideInfoView: TextView, isBrightness: Boolean, parentView: ViewGroup?, callback: (x: Float, y: Float) -> Unit) {
this.activity = activity this.activity = activity
this.slideInfoView = slideInfoView this.slideInfoView = slideInfoView
this.callback = callback this.callback = callback
@ -101,7 +101,7 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co
} }
MotionEvent.ACTION_UP -> { MotionEvent.ACTION_UP -> {
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
callback() callback(event.rawX, event.rawY)
} }
if (mIsBrightnessScroll) { if (mIsBrightnessScroll) {