How to pass clicks through 2 overlapping rectangles in Android Studio Overlay - Stack Overflow

I have an overlay service. On the overlay, I want to have multiple draggable buttons, and lines connect

I have an overlay service. On the overlay, I want to have multiple draggable buttons, and lines connecting these buttons.

This is a minimal setup: I added a button and a layout which holds all the lines to the window manager .

        WindowManager.LayoutParams layerParam = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
                PixelFormat.TRANSLUCENT);
        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        View lineLayer = new View(context); 
        // assume we add a few lines on this layer
        wm.addView(lineLayer, layerParam);


        WindowManager.LayoutParams circleParam = new WindowManager.LayoutParams(
                200,
                200,
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT
        );
        circleParam.gravity = Gravity.TOP | Gravity.START;
        circleParam.x = 400;
        circleParam.y = 600;

        View circleView = new View(context);
        circleView.setBackgroundResource(R.drawable.ic_cursor_24);
        circleView.setOnTouchListener((view, event) -> {
            Log.w("LOG_TAG", "circle clicked");
            circleParam.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
            wm.updateViewLayout(view, circleParam);
            return true;
        });
        wm.addView(circleView, circleParam);

With this implementation, when I click on the button, the button would print a message and disable itself, and when I click on other regions, my clicks will be passed through to the underlying app.

However, after I disabled the button, my future clicks will not pass through the disabled button to the underlaying app. Instead, when 2 or more overlapping overlay views have FLAG_NOT_TOUCHABLE flag set, the clicks will just get blocked.

My question is how can I pass clicks through the disabled buttons?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745059687a4608888.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信