androidx.core.os.BuildCompat Java Examples
The following examples show how to use
androidx.core.os.BuildCompat.
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: ComposeText.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) { if (BuildCompat.isAtLeastNMR1() && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) { try { inputContentInfo.requestPermission(); } catch (Exception e) { Log.w(TAG, e); return false; } } if (inputContentInfo.getDescription().getMimeTypeCount() > 0) { mediaListener.onMediaSelected(inputContentInfo.getContentUri(), inputContentInfo.getDescription().getMimeType(0)); return true; } return false; }
Example #2
Source File: ThemeHelper.java From android-DarkTheme with Apache License 2.0 | 6 votes |
public static void applyTheme(@NonNull String themePref) { switch (themePref) { case LIGHT_MODE: { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); break; } case DARK_MODE: { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); break; } default: { if (BuildCompat.isAtLeastQ()) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY); } break; } } }
Example #3
Source File: ComposeText.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) { if (BuildCompat.isAtLeastNMR1() && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) { try { inputContentInfo.requestPermission(); } catch (Exception e) { Log.w(TAG, e); return false; } } if (inputContentInfo.getDescription().getMimeTypeCount() > 0) { mediaListener.onMediaSelected(inputContentInfo.getContentUri(), inputContentInfo.getDescription().getMimeType(0)); return true; } return false; }
Example #4
Source File: SkyTubeApp.java From SkyTube with GNU General Public License v3.0 | 6 votes |
@TargetApi(26) private void initChannels(Context context) { if(BuildCompat.isAtLeastR()) { return; } NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String channelId = NEW_VIDEOS_NOTIFICATION_CHANNEL; CharSequence channelName = context.getString(R.string.notification_channel_feed_title); int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(ColorUtils.compositeColors(0xFFFF0000, 0xFFFF0000)); notificationChannel.enableVibration(false); notificationManager.createNotificationChannel(notificationChannel); }
Example #5
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 #6
Source File: VideoExampleWithExoPlayerActivity.java From tv-samples with Apache License 2.0 | 4 votes |
public static boolean supportsPictureInPicture(Context context) { return BuildCompat.isAtLeastN() && context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_PICTURE_IN_PICTURE); }
Example #7
Source File: VideoExampleActivity.java From tv-samples with Apache License 2.0 | 4 votes |
public static boolean supportsPictureInPicture(Context context) { return BuildCompat.isAtLeastN() && context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_PICTURE_IN_PICTURE); }
Example #8
Source File: BuildVersionUtils.java From talkback with Apache License 2.0 | 4 votes |
public static boolean isAtLeastQ() { return BuildCompat.isAtLeastQ() || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; }
Example #9
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); }
Example #10
Source File: AccessibilityButtonMonitor.java From talkback with Apache License 2.0 | 4 votes |
@Override protected void handleMessage(Message msg, AccessibilityButtonMonitor parent) { if (parent == null) { return; } switch (msg.what) { case MSG_BUTTON_CLICKED: parent.mCallback.onAccessibilityButtonClicked(); break; case MSG_CONFIRM_BUTTON_NOT_SUPPORTED: parent.mButtonState = NOT_SUPPORTED; // Make sure that we only notify once. if (!mHasNotifiedSupportability) { LogUtils.d(TAG, "Notify that a11y button is not supported."); mHasNotifiedSupportability = true; parent.mCallback.onConfirmSupportability(false); } break; case MSG_CONFIRM_BUTTON_SUPPORTED: parent.mButtonState = SUPPORTED; // Make sure that we only notify once. if (!mHasNotifiedSupportability) { LogUtils.d(TAG, "Notify that a11y button is supported."); parent.mCallback.onConfirmSupportability(true); mHasNotifiedSupportability = true; } break; case MSG_CONFIRM_BUTTON_SUPPORTABILITY_DELAYED: boolean isAvailable; if (BuildCompat.isAtLeastOMR1()) { isAvailable = AccessibilityManager.isAccessibilityButtonSupported(); } else { isAvailable = AccessibilityServiceCompatUtils.isAccessibilityButtonAvailableCompat( parent.mService.getAccessibilityButtonController()); } parent.mButtonState = isAvailable ? SUPPORTED : NOT_SUPPORTED; if (!mHasNotifiedSupportability) { LogUtils.d( TAG, "Delayed. Notify that a11y button is %s.", (isAvailable ? "supported" : "not supported")); parent.mCallback.onConfirmSupportability(isAvailable); mHasNotifiedSupportability = true; } break; default: break; } }