From efb107b063ffae88674ace5cdb4ef06eeb001cf2 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Fri, 9 Jun 2017 23:13:49 +0200 Subject: [PATCH] Fix context menues inside SlidingView for Android 7.x --- src/ch/blinkenlights/android/vanilla/SlidingView.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/SlidingView.java b/src/ch/blinkenlights/android/vanilla/SlidingView.java index ef3e9279..5f2c91a6 100644 --- a/src/ch/blinkenlights/android/vanilla/SlidingView.java +++ b/src/ch/blinkenlights/android/vanilla/SlidingView.java @@ -289,11 +289,14 @@ public class SlidingView extends FrameLayout @Override public boolean onTouch(View v, MotionEvent event){ - // Fix up the event offset as we are moving the view itself. - // This is required to get flings correctly detected - event.setLocation(event.getRawX(), event.getRawY()); + // The GestureDetector needs a motion event where the raw coordinates + // equal the 'relative' ones to calculate flings correctly. + // We are therefore creating a faked motion event because we'd like to + // use the real one for everything else. + MotionEvent fakeEvent = MotionEvent.obtain(event); + fakeEvent.setLocation(event.getRawX(), event.getRawY()); + mDetector.onTouchEvent(fakeEvent); - mDetector.onTouchEvent(event); float y = event.getRawY(); float dy = y - mPreviousY; // diff Y float vy = getTranslationY(); // view Y