Gesture manager not responding when changing brightness with WindowManager.LayoutParams

40 Views Asked by At

I am registering the visibility of the system bars with the following code

private var isVisibility=false

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        binding = FragmentSlideBinding.inflate(layoutInflater)
        
        binding.root.setOnApplyWindowInsetsListener{ view, windowInsets ->
            isVisibility = windowInsets.isVisible(Type.navigationBars())|| windowInsets.isVisible(Type.statusBars())
            playerModel.updateVisibility(visibility = isVisibility)
            if (isVisibility && !isOnDestroyView){
                controlsHideAutomatic()
            }
            view.onApplyWindowInsets(windowInsets)
      
        return binding.root
}

I have these functions to show and hide

    private fun showSystemUi() {        windowInsetsController?.show(Type.systemBars())
    }
    private fun hideSystemUi() {       windowInsetsController?.hide(Type.systemBars())
    }

This class handles gestures

private inner class GesturePlayerManager:GestureDetector.SimpleOnGestureListener(){

        override fun onSingleTapConfirmed(e: MotionEvent): Boolean {

            if(isVisibility)hideSystemUi() else showSystemUi()

            Log.e("click_movie","clicked")

            return true

        }

        override fun onScroll(
            e1: MotionEvent,
            e2: MotionEvent,
            distanceX: Float,
            distanceY: Float

    ): Boolean {

    ....

    var newValue:Float

   changeBrightness(newValue)

     return true

    }


In Onscroll I call the function to change the brightness, and the onSingleTapConfirmed no longer receives the call on the user's next Click. a single tap on the screen and the system bars are displayed without calling (onSingleTapConfirmed) leaving other controls out of sync

private fun changeBrightness(newBrightness: Float){

val attributes = activity!!.window.attributes
        attributes.screenBrightness = value
        activity!!.window.attributes = newBrightness

}

Only this method has worked for me without altering the handling of GestureManager

private fun changeBrightness(brightness:Int) {
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness)
}

but I would like to be able to implement it in the correct way this method

private fun changeBrightness(newBrightness: Float){

val attributes = activity!!.window.attributes
        attributes.screenBrightness = value
        activity!!.window.attributes = newBrightness

}


0

There are 0 best solutions below