Java Code Examples for androidx.core.os.BuildCompat#isAtLeastO()
The following examples show how to use
androidx.core.os.BuildCompat#isAtLeastO() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessibilityButtonMonitor.java From talkback with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.O) public void shutdown() { if (!BuildCompat.isAtLeastO()) { return; } // Unregister callback from AccessibilityButtonController. mService .getAccessibilityButtonController() .unregisterAccessibilityButtonCallback(mAccessibilityButtonCallback); }
Example 2
Source File: AccessibilityButtonMonitor.java From talkback with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.O) public void initAccessibilityButton(@NonNull AccessibilityButtonMonitorCallback callback) { mCallback = callback; if (!BuildCompat.isAtLeastO()) { LogUtils.d(TAG, "Accessibility button is not supported for pre-O devices."); // A11y button is not supported on pre-O devices. mHandler.confirmAccessibilityButtonSupportability(false); return; } // Ensure the flag is added to AccessibilityServiceInfo. AccessibilityServiceInfo info = mService.getServiceInfo(); info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON; mService.setServiceInfo(info); @NonNull AccessibilityButtonController accessibilityButtonController = mService.getAccessibilityButtonController(); if (AccessibilityServiceCompatUtils.isAccessibilityButtonAvailableCompat( accessibilityButtonController)) { LogUtils.d(TAG, "Accessibility button is available on initialization."); // If a11y button is available at the very beginning when the monitor is initialized, we can // confirm that the a11y button is supported on the device. mHandler.confirmAccessibilityButtonSupportability(true); } else { LogUtils.d(TAG, "Accessibility button is not available on initialization."); // If a11y button is not available when monitor is initialized, there could be two reasons: // 1. The device has physical nav bar button and the virtual nav bar is not supported on the // device, which is permanent unavailability. // 2. Race condition during framework initialization, it returns false when we call // AccessibilityButtonController.isAccessibilityButtonAvailable(), but soon the // AccessibilityButtonCallback.onAvailabilityChanged will be called to update availability. // // In both cases, it's acceptable to post delay to notify unavailability. If we get notified // that the availability changes before time out, we can cancel this delayed message and // update the availability with another message. mHandler.postDelayedConfirmAccessibilityButtonSupportability(TIMEOUT); } // Register callback to AccessibilityButtonController. mAccessibilityButtonCallback = new AccessibilityButtonController.AccessibilityButtonCallback() { @Override public void onClicked(AccessibilityButtonController controller) { LogUtils.d(TAG, "Accessibility button clicked."); handleControllerCallbackButtonClicked(); } @Override public void onAvailabilityChanged( AccessibilityButtonController controller, boolean available) { LogUtils.d(TAG, "Accessibility button availability changed. isAvailable=%s", available); handleControllerCallbackAvailabilityChanged(available); } }; accessibilityButtonController.registerAccessibilityButtonCallback(mAccessibilityButtonCallback); }