I have an app that overrides the onTouchEvent(MotionEvent ev)
of the MainActivity
to determine Two-Finger-Swipe
and Pich-Open
/Pinch-Close
.
Everything works fine until I add the DrawerLayout
to the app (like it's described in Creating a Navigation Drawer). Problem: the DrawerLayout
prevents the call of onTouchEvent()
in the MainActivity.
I started to write a CustomDrawerLayout
, and try to override the DrawerLayout
methods onInterceptTouch()
and onTouchEvent()
.
The only way (I found) to transmit the TouchEvent
to the MainActivity:
// onTouchEvent of CustomDrawerLayout
@Override
public boolean onTouchEvent(MotionEvent ev){
// super.onTouchEvent(ev); // prevent transmission of TouchEvent
return false;
}
The problem here is that the Drawer doesn't open correctly. The Drawer stucks like described in this post: DrawerLayout getting stuck on swipe.
Is it possible to transmit the TouchEvent
to MainActivity to handle the MultiTouchDetection? Or do I have to handle this in CustomDrawerLayout
?
UPDATE 1
First I have to say that the Drawer only stucks, if I swipe from the left edge. By clicking on the DrawerIcon in the ActionBar
the Drawer works fine.
Transmission of TouchEvent
works with following code. But only if the Drawer is opend! Otherwise Activity.onTouchEvent
isn't called!
// onTouchEvent of CustomDrawerLayout
@Override
public boolean onTouchEvent(MotionEvent ev){
// super.onTouchEvent(ev); // still prevents transmission of TouchEvent
activity.onTouchEvent(ev);
return true;
}
By opening the Drawer with a swipe from the edge (-> Drawer stucks) i get a really strange behaviour :
- just DrawerIcon can close "stucked Drawer" (-> I wouldn't expect something different because I override the
CustomDrawerLayout.onTouchEvent
) - if I close the stucked Drawer by DrawersIcon the
CustomDrawerLayout.onTouchEvent
is still called
Thats strange! Why Activity.onTouchEvent()
isn't called? And how can I prevent the stucked Drawer?
UPDATE 2
Now i override the CustomDrawerLayout.onInterceptTouch()
:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
return true;
}
This has the effect that the Drawer can't be opened by a swipe from the edge -> only the DrawersIcon can open and close the Drawer. But now the TouchEvent
is always transmitted to the Activity (-> that works like expected).
But what I really want is to have the possibilty to open the Drawer by a swipe from the edge AND to have my MultiGestureDetector. Is this possible?