下面列出了android.view.accessibility.AccessibilityManager#addTouchExplorationStateChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Sets the current touch explore state change listener and removes the previous one if necessary
* @param listener Null value unregisters the current listener, non-null unregisters previous one and registers new one
* If the current listener is the same as the previous one, no operation is performed.
*/
protected void setTouchExploreChangeListener(@Nullable AccessibilityManager.TouchExplorationStateChangeListener listener) {
// if current touchExplorerStateChangeListener is identical to previous one, no operation is necessary
if (listener != touchExplorationStateChangeListener) {
AccessibilityManager am = getAccessibilityManager();
if (am != null) {
/* touch explorer state listeners are additive (i.e. adding one doesn't remove the previous one), so we need to be careful
* and only register one at a time. so, if the one we currently have is valid (non-null), unregister it.
* If the new one is valid (non-null) register it.
*/
if (touchExplorationStateChangeListener != null) {
am.removeTouchExplorationStateChangeListener((AccessibilityManager.TouchExplorationStateChangeListener) touchExplorationStateChangeListener);
}
if (listener != null) {
am.addTouchExplorationStateChangeListener(listener);
}
touchExplorationStateChangeListener = listener;
}
}
}
public void load() {
am = (AccessibilityManager) getContext().getSystemService(ACCESSIBILITY_SERVICE);
am.addTouchExplorationStateChangeListener(new AccessibilityManager.TouchExplorationStateChangeListener() {
@Override
public void onTouchExplorationStateChanged(boolean b) {
JSObject ret = new JSObject();
ret.put("value", b);
notifyListeners(EVENT_SCREEN_READER_STATE_CHANGE, ret);
}
});
}
@SuppressLint("NewApi")
@Override
public void postInflationStartup() {
super.postInflationStartup();
mSnackbarManager = new SnackbarManager(this);
mDataUseSnackbarController = new DataUseSnackbarController(this, getSnackbarManager());
mAssistStatusHandler = createAssistStatusHandler();
if (mAssistStatusHandler != null) {
if (mTabModelSelector != null) {
mAssistStatusHandler.setTabModelSelector(mTabModelSelector);
}
mAssistStatusHandler.updateAssistState();
}
// If a user had ALLOW_LOW_END_DEVICE_UI explicitly set to false then we manually override
// SysUtils.isLowEndDevice() with a switch so that they continue to see the normal UI. This
// is only the case for grandfathered-in svelte users. We no longer do so for newer users.
if (!ChromePreferenceManager.getInstance(this).getAllowLowEndDeviceUi()) {
CommandLine.getInstance().appendSwitch(
BaseSwitches.DISABLE_LOW_END_DEVICE_MODE);
}
AccessibilityManager manager = (AccessibilityManager)
getBaseContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
manager.addAccessibilityStateChangeListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mTouchExplorationStateChangeListener = new TouchExplorationStateChangeListener() {
@Override
public void onTouchExplorationStateChanged(boolean enabled) {
checkAccessibility();
}
};
manager.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
}
// Make the activity listen to policy change events
getChromeApplication().addPolicyChangeListener(this);
// Set up the animation placeholder to be the SurfaceView. This disables the
// SurfaceView's 'hole' clipping during animations that are notified to the window.
mWindowAndroid.setAnimationPlaceholderView(mCompositorViewHolder.getSurfaceView());
// Inform the WindowAndroid of the keyboard accessory view.
mWindowAndroid.setKeyboardAccessoryView((ViewGroup) findViewById(R.id.keyboard_accessory));
initializeToolbar();
}
@SuppressLint("NewApi")
@Override
public void postInflationStartup() {
super.postInflationStartup();
mSnackbarManager = new SnackbarManager(this);
mDataUseSnackbarController = new DataUseSnackbarController(this, getSnackbarManager());
mAssistStatusHandler = createAssistStatusHandler();
if (mAssistStatusHandler != null) {
if (mTabModelSelector != null) {
mAssistStatusHandler.setTabModelSelector(mTabModelSelector);
}
mAssistStatusHandler.updateAssistState();
}
// If a user had ALLOW_LOW_END_DEVICE_UI explicitly set to false then we manually override
// SysUtils.isLowEndDevice() with a switch so that they continue to see the normal UI. This
// is only the case for grandfathered-in svelte users. We no longer do so for newer users.
if (!ChromePreferenceManager.getInstance(this).getAllowLowEndDeviceUi()) {
CommandLine.getInstance().appendSwitch(
BaseSwitches.DISABLE_LOW_END_DEVICE_MODE);
}
AccessibilityManager manager = (AccessibilityManager)
getBaseContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
manager.addAccessibilityStateChangeListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mTouchExplorationStateChangeListener = new TouchExplorationStateChangeListener() {
@Override
public void onTouchExplorationStateChanged(boolean enabled) {
checkAccessibility();
}
};
manager.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
}
// Make the activity listen to policy change events
CombinedPolicyProvider.get().addPolicyChangeListener(this);
// Set up the animation placeholder to be the SurfaceView. This disables the
// SurfaceView's 'hole' clipping during animations that are notified to the window.
mWindowAndroid.setAnimationPlaceholderView(mCompositorViewHolder.getSurfaceView());
// Inform the WindowAndroid of the keyboard accessory view.
mWindowAndroid.setKeyboardAccessoryView((ViewGroup) findViewById(R.id.keyboard_accessory));
initializeToolbar();
initializeTabModels();
if (!isFinishing() && getFullscreenManager() != null) {
getFullscreenManager().initialize(
(ControlContainer) findViewById(R.id.control_container),
getTabModelSelector(),
getControlContainerHeightResource());
}
}
@SuppressLint("NewApi")
@Override
public void postInflationStartup() {
super.postInflationStartup();
mSnackbarManager = new SnackbarManager(this, null);
mDataUseSnackbarController = new DataUseSnackbarController(this, getSnackbarManager());
mAssistStatusHandler = createAssistStatusHandler();
if (mAssistStatusHandler != null) {
if (mTabModelSelector != null) {
mAssistStatusHandler.setTabModelSelector(mTabModelSelector);
}
mAssistStatusHandler.updateAssistState();
}
// If a user had ALLOW_LOW_END_DEVICE_UI explicitly set to false then we manually override
// SysUtils.isLowEndDevice() with a switch so that they continue to see the normal UI. This
// is only the case for grandfathered-in svelte users. We no longer do so for newer users.
if (!ChromePreferenceManager.getInstance().getAllowLowEndDeviceUi()) {
CommandLine.getInstance().appendSwitch(
BaseSwitches.DISABLE_LOW_END_DEVICE_MODE);
}
AccessibilityManager manager = (AccessibilityManager)
getBaseContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
manager.addAccessibilityStateChangeListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mTouchExplorationStateChangeListener = new TouchExplorationStateChangeListener() {
@Override
public void onTouchExplorationStateChanged(boolean enabled) {
checkAccessibility();
}
};
manager.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
}
// Make the activity listen to policy change events
CombinedPolicyProvider.get().addPolicyChangeListener(this);
mDidAddPolicyChangeListener = true;
// Set up the animation placeholder to be the SurfaceView. This disables the
// SurfaceView's 'hole' clipping during animations that are notified to the window.
getWindowAndroid().setAnimationPlaceholderView(mCompositorViewHolder.getCompositorView());
// Inform the WindowAndroid of the keyboard accessory view.
getWindowAndroid().setKeyboardAccessoryView(
(ViewGroup) findViewById(R.id.keyboard_accessory));
initializeToolbar();
initializeTabModels();
if (!isFinishing() && getFullscreenManager() != null) {
getFullscreenManager().initialize(
(ControlContainer) findViewById(R.id.control_container),
getTabModelSelector(),
getControlContainerHeightResource());
}
if (mBottomSheet != null) {
mBottomSheet.setTabModelSelector(mTabModelSelector);
mBottomSheet.setFullscreenManager(mFullscreenManager);
mFadingBackgroundView = (FadingBackgroundView) findViewById(R.id.fading_focus_target);
mBottomSheet.addObserver(new EmptyBottomSheetObserver() {
@Override
public void onTransitionPeekToHalf(float transitionFraction) {
mFadingBackgroundView.setViewAlpha(transitionFraction);
}
});
mFadingBackgroundView.addObserver(mBottomSheet);
mBottomSheetContentController =
(BottomSheetContentController) ((ViewStub) findViewById(R.id.bottom_nav_stub))
.inflate();
int controlContainerHeight =
((ControlContainer) findViewById(R.id.control_container)).getView().getHeight();
mBottomSheetContentController.init(
mBottomSheet, controlContainerHeight, mTabModelSelector, this);
}
((BottomContainer) findViewById(R.id.bottom_container)).initialize(mFullscreenManager);
}