提交 f4fe2b61 编写于 作者: J Jason Simmons 提交者: GitHub

Do not use TouchExplorationStateChangeListener if that API is unavailable (#3148)

上级 e73c8a7f
......@@ -71,8 +71,7 @@ import org.domokit.editing.KeyboardViewState;
*/
@JNINamespace("shell")
public class FlutterView extends SurfaceView
implements AccessibilityManager.AccessibilityStateChangeListener,
AccessibilityManager.TouchExplorationStateChangeListener {
implements AccessibilityManager.AccessibilityStateChangeListener {
private static final String TAG = "FlutterView";
private static final String ACTION_DISCOVER = "io.flutter.view.DISCOVER";
......@@ -654,6 +653,7 @@ public class FlutterView extends SurfaceView
private boolean mAccessibilityEnabled = false;
private boolean mTouchExplorationEnabled = false;
private TouchExplorationListener mTouchExplorationListener;
protected void dispatchSemanticsAction(int id, int action) {
nativeDispatchSemanticsAction(mNativePlatformView, id, action);
......@@ -668,14 +668,19 @@ public class FlutterView extends SurfaceView
ensureAccessibilityEnabled();
resetWillNotDraw();
mAccessibilityManager.addAccessibilityStateChangeListener(this);
mAccessibilityManager.addTouchExplorationStateChangeListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (mTouchExplorationListener == null)
mTouchExplorationListener = new TouchExplorationListener();
mAccessibilityManager.addTouchExplorationStateChangeListener(mTouchExplorationListener);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mAccessibilityManager.removeAccessibilityStateChangeListener(this);
mAccessibilityManager.removeTouchExplorationStateChangeListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
mAccessibilityManager.removeTouchExplorationStateChangeListener(mTouchExplorationListener);
}
private void resetWillNotDraw() {
......@@ -696,18 +701,21 @@ public class FlutterView extends SurfaceView
resetWillNotDraw();
}
@Override
public void onTouchExplorationStateChanged(boolean enabled) {
if (enabled) {
mTouchExplorationEnabled = true;
ensureAccessibilityEnabled();
} else {
mTouchExplorationEnabled = false;
if (mAccessibilityNodeProvider != null) {
mAccessibilityNodeProvider.handleTouchExplorationExit();
class TouchExplorationListener
implements AccessibilityManager.TouchExplorationStateChangeListener {
@Override
public void onTouchExplorationStateChanged(boolean enabled) {
if (enabled) {
mTouchExplorationEnabled = true;
ensureAccessibilityEnabled();
} else {
mTouchExplorationEnabled = false;
if (mAccessibilityNodeProvider != null) {
mAccessibilityNodeProvider.handleTouchExplorationExit();
}
}
resetWillNotDraw();
}
resetWillNotDraw();
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册