I have the following hierarchy: Activity
-> PopupWindow
-> CustomView
My the PopupWindow
itself is a square, but transparent, so you can see the Activity sitting in the background. The CustomView
is a circle embedded inside the PopupWindow.
What I have achieved so far is
PopupWindow
and the touch event gets dispatched to the Activity.The missing part is now, to dispatch any touch event that happens inside the PopupWindow
but outside the CustomView
(circle) to the Activity.
I already know how to sense when the touch is outside of my circle. I just have problems delegating it to the Activity.
In my CustomView
I have the following in onTouch
if (radiusTouch > maxRadius) {
return false;
}
In my PopupWindow
I already setup the following, but it gets never called:
popup.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i(TAG, "PopupWindow :: onTouch()");
return false;
}
});
Anything else I have to do to delegate the touch event all the way to the Activity?
Android supports multiple pointers, e.g. fingers which are interacting with the screen. The base class for touch support is the MotionEvent class which is passed to Views via the onTouchEvent() method. you override the onTouchEvent() method.
 Gestures are scripted “solutions” that take advantage of these touch events.  So instead of tracking two touch points to determine if they're moving away or closer to one another in order to manipulate the size of a photo, you can just use GESTURE_ZOOM.
To make sure that each view correctly receives the touch events intended for it, override the onInterceptTouchEvent() method.
The touch event is passed in as a MotionEvent , which contains the x,y coordinates, time, type of event, and other information. The touch event is sent to the Window's superDispatchTouchEvent() . Window is an abstract class. The actual implementation is PhoneWindow .
Consider the FLAG_NOT_TOUCH_MODAL:
/** Window flag: Even when this window is focusable (its
* {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events
* outside of the window to be sent to the windows behind it. Otherwise
* it will consume all pointer events itself, regardless of whether they
* are inside of the window. */
public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020;
You can use this code to upate the window flags after the popup window was shown.
FrameLayout popupContainer = (FrameLayout)contentView.getParent();
WindowManager.LayoutParams p = (WindowManager.LayoutParams)popupContainer.getLayoutParams();
p.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
WindowManager windowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
windowManager.updateViewLayout(popupContainer, p);
Try setting these on your PopupWindow instance:
window.setBackgroundDrawable(new BitmapDrawable());
window.setOutsideTouchable(true);
and
window.setTouchable(true);
This is just a suggestion... I haven't tested it. Let me know if it works.
[Note: This is for the onTouch() to get called on touch events..]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With