Adding windows A, B, and C in Android, touching window C does not trigger touch outside events for windows A and B

34 views Asked by At

Application A has launched 6 windows, while application B has launched one window. The window in application B handles touch events. However, the 6 windows in application A do not receive touch outside events, causing difficulty in closing the 6 windows.

private fun initControlCenterBar(screenCount: Int) {
        repeat(screenCount) {
            val keyIndex = when (it) {
                0 -> ScreenIndex.LEFT
                1 -> ScreenIndex.MIDDLE
                2 -> ScreenIndex.RIGHT
                else -> ScreenIndex.LEFT
            }
            val centerControlLeftView =
                SuspendCenterLeftControlView(this@LauncherActivity, keyIndex = keyIndex)
            val centerControlRightView =
                SuspendCenterRightControlView(this@LauncherActivity, keyIndex = keyIndex)
            // left window
            centerControlLeftView.params.x = ScreenWidth * it
            centerControlLeftView.params.y = CONTROL_LOCATION_Y
            // right window
            centerControlRightView.params.gravity = Gravity.RIGHT or Gravity.TOP
            centerControlRightView.params.x = ScreenWidth * (screenCount - 1 - it)
            centerControlRightView.params.y = CONTROL_LOCATION_Y
            //add viewBinding
            mMainControlBindingList.apply {
                add(SuspendCenterControlLeftViewBinding.bind(centerControlLeftView.suspendView))
                add(SuspendCenterControlRightViewBinding.bind(centerControlRightView.suspendView))
            }
            //add window
            SuspendWindowManager.apply {
                addSuspendView(centerControlLeftView)
                addSuspendView(centerControlRightView)
            }
        }
        // mutual exclusion
        mMainControlBindingList.forEach {
            it.root.setOnTouchListener { _, event ->
                if (event.actionMasked == MotionEvent.ACTION_OUTSIDE) {
                    Log.d("test", "===>Outside Touch")
                }
                true
            }
        }
    }

window params config:

private fun initLayoutParams() {
        params = WindowManager.LayoutParams()
        params.width = WindowManager.LayoutParams.WRAP_CONTENT
        params.height = WindowManager.LayoutParams.WRAP_CONTENT
        params.flags =
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
        params.format = PixelFormat.TRANSLUCENT
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
            params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
        } else {
            params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
        }

        params.x = setStartX()
        params.y = setStartY()
        params.gravity = Gravity.LEFT or Gravity.TOP
        params.width = setWidth()
        params.height = setHeight()
    }

My launcher application opens multiple floating windows, all of which have an expanded state. I expect that when the user clicks on other empty areas, the expanded floating windows can be closed. This scenario works fine with touches on the activity, but once another window triggers touch events, my multiple floating windows fail to correctly receive outside events. I hope they can function as intended.

0

There are 0 answers