Repository: skyline-emu/skyline
File: app/src/main/java/emu/skyline/input/onscreen/OnScreenEditActivity.kt (Kotlin)

Code before:
    private val actions : List<Pair<Int, () -> Unit>> = listOf(
            Pair(R.drawable.ic_restore, { binding.onScreenControllerView.resetControls() }),
            Pair(R.drawable.ic_toggle, toggleAction),
            Pair(R.drawable.ic_edit, editAction),
            Pair(R.drawable.ic_zoom_out, { binding.onScreenControllerView.decreaseScale() }),
            Pair(R.drawable.ic_zoom_in, { binding.onScreenControllerView.increaseScale() }),
            Pair(R.drawable.ic_opacity_minus) { binding.onScreenControllerView.decreaseOpacity() },
            Pair(R.drawable.ic_opacity_plus) { binding.onScreenControllerView.increaseOpacity() },
            Pair(R.drawable.ic_close, closeAction)
    )

    private val fabMapping = mutableMapOf<Int, FloatingActionButton>()

    override fun onCreate(savedInstanceState : Bundle?) {
        super.onCreate(savedInstanceState)
        window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
        setContentView(binding.root)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            // Android might not allow child views to overlap the system bars
            // Override this behavior and force content to extend into the cutout area
            window.setDecorFitsSystemWindows(false)

            window.insetsController?.let {
                it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
                it.hide(WindowInsets.Type.systemBars())
            }
        }

        binding.onScreenControllerView.recenterSticks = appSettings.onScreenControlRecenterSticks

        actions.forEach { pair ->
            binding.fabParent.addView(LayoutInflater.from(this).inflate(R.layout.on_screen_edit_mini_fab, binding.fabParent, false).apply {
                (this as FloatingActionButton).setImageDrawable(ContextCompat.getDrawable(context, pair.first))
                setOnClickListener { pair.second.invoke() }
                fabMapping[pair.first] = this
            })
        }
    }

    override fun onResume() {
        super.onResume()

        fullScreen()
    }

    private fun fullScreen() {
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
            @Suppress("DEPRECATION")
            window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    or View.SYSTEM_UI_FLAG_LAYOUT_STABLE

Review comment (suggestion):
You definitely don't want to do this to have both color pickers in the same dialog window. I'm not sure about the library you're using, but you should be able to easily create a new XML layout with both color sections in there, then hook up the code to load up that XML. If you can't do that, you'll need to draw them in code, but there's no need to show both, then dismiss one, then merge them manually like you are doing here.

Code after:
            }.setNegativeButton(R.string.cancel, null)
            .setOnDismissListener { fullScreen() }
            .show()
    }

    private val paletteAction : () -> Unit = {
        DoubleColorPicker(this@OnScreenEditActivity).apply {
            setTitle(this@OnScreenEditActivity.getString(R.string.osc_background_color))
            setDefaultColorButton(binding.onScreenControllerView.getBackGroundColor())
            setRoundColorButton(true)
            setColors(*SwitchColors.colors.toIntArray())
            setDefaultDoubleColorButton(binding.onScreenControllerView.getTextColor())
            setSecondTitle(this@OnScreenEditActivity.getString(R.string.osc_text_color))
            setOnChooseDoubleColorListener(object : OnChooseDoubleColorListener {
                override fun onChooseColor(position : Int, color : Int, position2 : Int, color2 : Int) {
                    binding.onScreenControllerView.setBackGroundColor(SwitchColors.colors[position])
                    binding.onScreenControllerView.setTextColor(SwitchColors.colors[position2])
                }

                override fun onCancel() {}
            })
            show()
        }


    }

    private val actions : List<Pair<Int, () -> Unit>> = listOf(
        Pair(R.drawable.ic_palette, paletteAction),
        Pair(R.drawable.ic_restore) { binding.onScreenControllerView.resetControls() },
        Pair(R.drawable.ic_toggle, toggleAction),
        Pair(R.drawable.ic_edit, editAction),
        Pair(R.drawable.ic_zoom_out) { binding.onScreenControllerView.decreaseScale() },
        Pair(R.drawable.ic_zoom_in) { binding.onScreenControllerView.increaseScale() },
        Pair(R.drawable.ic_opacity_minus) { binding.onScreenControllerView.decreaseOpacity() },
        Pair(R.drawable.ic_opacity_plus) { binding.onScreenControllerView.increaseOpacity() },
        Pair(R.drawable.ic_close, closeAction)
    )

    private val fabMapping = mutableMapOf<Int, FloatingActionButton>()

    override fun onCreate(savedInstanceState : Bundle?) {
        super.onCreate(savedInstanceState)
        window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
        setContentView(binding.root)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            // Android might not allow child views to overlap the system bars
            // Override this behavior and force content to extend into the cutout area
            window.setDecorFitsSystemWindows(false)