From 34b2a38758f268c41a8d4b1f02c9e6a06f6d8aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20St=C3=A4hli?= Date: Mon, 16 Dec 2024 16:39:55 +0100 Subject: [PATCH] Move to better location --- .../pillarbox/demo/shared/ui/TalkBack.kt | 24 ++++++++++++ .../demo/shared/ui/TalkBackEnabled.kt | 37 ------------------- 2 files changed, 24 insertions(+), 37 deletions(-) delete mode 100644 pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/TalkBackEnabled.kt diff --git a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/TalkBack.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/TalkBack.kt index 6e48ee580..6bcae4c21 100644 --- a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/TalkBack.kt +++ b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/TalkBack.kt @@ -36,3 +36,27 @@ fun rememberIsTouchExplorationEnabled(): Boolean { return isTouchExplorationEnabled } + +/** + * A composable function that returns a boolean indicating whether TalkBack is currently enabled. + * + * This function uses a [DisposableEffect] to register an [AccessibilityManager.AccessibilityStateChangeListener] + * that updates the state of the composable when the accessibility state changes. + * + * @return `true` if TalkBack is enabled, `false` otherwise. + */ +@Composable +fun rememberIsTalkBackEnabled(): Boolean { + val accessibilityManager = LocalContext.current.getSystemService() ?: return false + val (isTalkBackEnabled, setTalkBackEnabled) = remember { + mutableStateOf(accessibilityManager.isEnabled) + } + DisposableEffect(Unit) { + val l = AccessibilityManager.AccessibilityStateChangeListener(setTalkBackEnabled) + accessibilityManager.addAccessibilityStateChangeListener(l) + onDispose { + accessibilityManager.removeAccessibilityStateChangeListener(l) + } + } + return isTalkBackEnabled +} diff --git a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/TalkBackEnabled.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/TalkBackEnabled.kt deleted file mode 100644 index f660849b8..000000000 --- a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/TalkBackEnabled.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) SRG SSR. All rights reserved. - * License information is available from the LICENSE file. - */ -package ch.srgssr.pillarbox.demo.shared.ui - -import android.view.accessibility.AccessibilityManager -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.ui.platform.LocalContext -import androidx.core.content.getSystemService - -/** - * A composable function that returns a boolean indicating whether TalkBack is currently enabled. - * - * This function uses a [DisposableEffect] to register an [AccessibilityManager.AccessibilityStateChangeListener] - * that updates the state of the composable when the accessibility state changes. - * - * @return `true` if TalkBack is enabled, `false` otherwise. - */ -@Composable -fun rememberIsTalkBackEnabled(): Boolean { - val accessibilityManager = LocalContext.current.getSystemService() ?: return false - val (isTalkBackEnabled, setTalkBackEnabled) = remember { - mutableStateOf(accessibilityManager.isEnabled) - } - DisposableEffect(Unit) { - val l = AccessibilityManager.AccessibilityStateChangeListener(setTalkBackEnabled) - accessibilityManager.addAccessibilityStateChangeListener(l) - onDispose { - accessibilityManager.removeAccessibilityStateChangeListener(l) - } - } - return isTalkBackEnabled -}