Windowmanager Not Allowing To Pass Touch
Solution 1:
You can't do that on the same view I'm afraid, because the touch event either enters to your view, or it does not. Whether you're using intercept, returning false etc... They all depend on whether the event actually reaches your view, and even then, returning false wouldn't pass the event to the below screen, because they are different processes. In your case, the event wouldn't reach your window, and that would mean you can't handle the event at all.
I'm not entirely sure what the parent does, I believe you're trying to move the circle view here after touching it, with a drag operation or some sort. So, I'll give an example approach on how you can do it.
Adding the view in left and right corner can be specified in the layout params you are creating. For instance, top-left would look like this:
params.x = 0;paramx.y = 0;
Top-right would look like this:
WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Point size = new Point();
// Get the screen dimensions here
manager.getDefaultDisplay().getSize(point);
int screenWidth = point.x;
// Assuming your view has a 40 dp width and height,// calculate its pixel variantint circleWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DP, 40, getResources().getDisplayMetrics());
// Target the top-right corner of the screen.params.x = screenWidth - circleWidth;
// Y coordinate would be 0.params.y = 0;
And view parameters would look like this:
// Assuming your view has a 40 dp width and height,// calculate its pixel variantint circleSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DP, 40, getResources().getDisplayMetrics());
WindowManager.LayoutParams params = new WindowManager.LayoutParams(circleSize /* width */,
circleSize /* height */,
0/* x */,
0/* y */,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY /* windowType */,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH /* outsideTouch */,
PixelFormat.TRANSLUCENT /* format */);
After that, moving the view would actually require to change your layout params and updating the view layout. In your onTouchEvent
you can do something like this:
// Assuming you know the new x and y values of the view, you can// update the layout params of the view like this:
((WindowManager.LayoutParams) getLayoutParams()).x = targetX;
((WindowManager.LayoutParams) getLayoutParams()).y = targetY;
// To update the view, you need to either call requestLayout() or// do it from window manager directly.// If the first way doesn't work, 2nd will work.// First way:
requestLayout();
// Second way:// This will get the same window manager the service has.WindowManagermanager= (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
// Update the view layout afterwards.
manager.updateViewLayout(this, getLayoutParams());
That way, you can move the view with the touch event.
Couple things to note:
- If you can capture the
onTouchEvent
you know that you've touched the circle, so you don't need to perform coordinate checks by using the raw values (I'm referring toisPointInside()
function). Returning true from all of them will help you receive all the events, but that's not necessary. You probably know how the lifecycle works anyway. - Each circle must be added to the window manager as root with
WindowManager.addView()
so that the touches do not interfere each other, and touching a point where circle is not in will pass the event to the below screen.
This would be a start for your requirement, and I think you can fit this with your needs.
Post a Comment for "Windowmanager Not Allowing To Pass Touch"