diff --git a/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/shell/platform/android/io/flutter/view/AccessibilityBridge.java index 812170155ec..7d4e5060aa1 100644 --- a/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -266,25 +266,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { // This is guarded at instantiation time. @TargetApi(19) @RequiresApi(19) - private final AccessibilityManager.TouchExplorationStateChangeListener touchExplorationStateChangeListener = new AccessibilityManager.TouchExplorationStateChangeListener() { - @Override - public void onTouchExplorationStateChanged(boolean isTouchExplorationEnabled) { - if (isTouchExplorationEnabled) { - accessibilityFeatureFlags |= AccessibilityFeature.ACCESSIBLE_NAVIGATION.value; - } else { - onTouchExplorationExit(); - accessibilityFeatureFlags &= ~AccessibilityFeature.ACCESSIBLE_NAVIGATION.value; - } - sendLatestAccessibilityFlagsToFlutter(); - - if (onAccessibilityChangeListener != null) { - onAccessibilityChangeListener.onAccessibilityChanged( - accessibilityManager.isEnabled(), - isTouchExplorationEnabled - ); - } - } - }; + private final AccessibilityManager.TouchExplorationStateChangeListener touchExplorationStateChangeListener; // Listener that is notified when the global TRANSITION_ANIMATION_SCALE. When this scale goes // to zero, we instruct Flutter to disable animations. @@ -336,8 +318,29 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { // Tell Flutter whether touch exploration is initially active or not. Then register a listener // to be notified of changes in the future. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + touchExplorationStateChangeListener = new AccessibilityManager.TouchExplorationStateChangeListener() { + @Override + public void onTouchExplorationStateChanged(boolean isTouchExplorationEnabled) { + if (isTouchExplorationEnabled) { + accessibilityFeatureFlags |= AccessibilityFeature.ACCESSIBLE_NAVIGATION.value; + } else { + onTouchExplorationExit(); + accessibilityFeatureFlags &= ~AccessibilityFeature.ACCESSIBLE_NAVIGATION.value; + } + sendLatestAccessibilityFlagsToFlutter(); + + if (onAccessibilityChangeListener != null) { + onAccessibilityChangeListener.onAccessibilityChanged( + accessibilityManager.isEnabled(), + isTouchExplorationEnabled + ); + } + } + }; touchExplorationStateChangeListener.onTouchExplorationStateChanged(accessibilityManager.isTouchExplorationEnabled()); this.accessibilityManager.addTouchExplorationStateChangeListener(touchExplorationStateChangeListener); + } else { + touchExplorationStateChangeListener = null; } // Tell Flutter whether animations should initially be enabled or disabled. Then register a