Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Guard initialization of touch exploration listener #8103

Merged
merged 3 commits into from
Mar 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,25 +266,7 @@ public void onAccessibilityStateChanged(boolean accessibilityEnabled) {
// 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.
Expand Down Expand Up @@ -336,8 +318,29 @@ public void onChange(boolean selfChange, Uri uri) {
// 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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I think we should avoid in-line anonymous definitions beyond anything more compicated than a click handler. If we can't define this up above where it was then we should define it as a static inner class. I will make this change next week.

@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
Expand Down