android.view.DisplayCutout Java Examples
The following examples show how to use
android.view.DisplayCutout.
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: FloatingViewManager.java From dingo with GNU General Public License v3.0 | 6 votes |
/** * Find the safe area of DisplayCutout. * * @param activity {@link Activity} (Portrait and `windowLayoutInDisplayCutoutMode` != never) * @return Safe cutout insets. */ public static Rect findCutoutSafeArea(@NonNull Activity activity) { final Rect safeInsetRect = new Rect(); // TODO:Rewrite with android-x // TODO:Consider alternatives if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { return safeInsetRect; } // Fix: getDisplayCutout() on a null object reference (issue #110) final WindowInsets windowInsets = activity.getWindow().getDecorView().getRootWindowInsets(); if (windowInsets == null) { return safeInsetRect; } // set safeInsetRect final DisplayCutout displayCutout = windowInsets.getDisplayCutout(); if (displayCutout != null) { safeInsetRect.set(displayCutout.getSafeInsetLeft(), displayCutout.getSafeInsetTop(), displayCutout.getSafeInsetRight(), displayCutout.getSafeInsetBottom()); } return safeInsetRect; }
Example #2
Source File: TaskSnapshotSurface.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout, boolean alwaysConsumeNavBar, int displayId, DisplayCutout.ParcelableWrapper displayCutout) { if (mergedConfiguration != null && mOuter != null && mOuter.mOrientationOnCreation != mergedConfiguration.getMergedConfiguration().orientation) { // The orientation of the screen is changing. We better remove the snapshot ASAP as // we are going to wait on the new window in any case to unfreeze the screen, and // the starting window is not needed anymore. sHandler.post(mOuter::remove); } if (reportDraw) { sHandler.obtainMessage(MSG_REPORT_DRAW, mOuter).sendToTarget(); } }
Example #3
Source File: FloatingViewManager.java From FloatingView with Apache License 2.0 | 6 votes |
/** * Find the safe area of DisplayCutout. * * @param activity {@link Activity} (Portrait and `windowLayoutInDisplayCutoutMode` != never) * @return Safe cutout insets. */ public static Rect findCutoutSafeArea(@NonNull Activity activity) { final Rect safeInsetRect = new Rect(); // TODO:Rewrite with android-x // TODO:Consider alternatives if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { return safeInsetRect; } // Fix: getDisplayCutout() on a null object reference (issue #110) final WindowInsets windowInsets = activity.getWindow().getDecorView().getRootWindowInsets(); if (windowInsets == null) { return safeInsetRect; } // set safeInsetRect final DisplayCutout displayCutout = windowInsets.getDisplayCutout(); if (displayCutout != null) { safeInsetRect.set(displayCutout.getSafeInsetLeft(), displayCutout.getSafeInsetTop(), displayCutout.getSafeInsetRight(), displayCutout.getSafeInsetBottom()); } return safeInsetRect; }
Example #4
Source File: Session.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs, int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame, DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration, Surface outSurface) { if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag); int res = mService.relayoutWindow(this, window, seq, attrs, requestedWidth, requestedHeight, viewFlags, flags, frameNumber, outFrame, outOverscanInsets, outContentInsets, outVisibleInsets, outStableInsets, outsets, outBackdropFrame, cutout, mergedConfiguration, outSurface); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); return res; }
Example #5
Source File: CutoutUtil.java From DKVideoPlayer with Apache License 2.0 | 6 votes |
/** * 是否为允许全屏界面显示内容到刘海区域的刘海屏机型(与AndroidManifest中配置对应) */ public static boolean allowDisplayToCutout(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { // 9.0系统全屏界面默认会保留黑边,不允许显示内容到刘海区域 Window window = activity.getWindow(); WindowInsets windowInsets = window.getDecorView().getRootWindowInsets(); if (windowInsets == null) { return false; } DisplayCutout displayCutout = windowInsets.getDisplayCutout(); if (displayCutout == null) { return false; } List<Rect> boundingRects = displayCutout.getBoundingRects(); return boundingRects.size() > 0; } else { return hasCutoutHuawei(activity) || hasCutoutOPPO(activity) || hasCutoutVIVO(activity) || hasCutoutXIAOMI(activity); } }
Example #6
Source File: DisplayContent.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation, int uiMode, int dw, int dh) { final DisplayCutout displayCutout = calculateDisplayCutoutForRotation( rotation).getDisplayCutout(); final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode, displayId, displayCutout); if (width < displayInfo.smallestNominalAppWidth) { displayInfo.smallestNominalAppWidth = width; } if (width > displayInfo.largestNominalAppWidth) { displayInfo.largestNominalAppWidth = width; } final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode, displayId, displayCutout); if (height < displayInfo.smallestNominalAppHeight) { displayInfo.smallestNominalAppHeight = height; } if (height > displayInfo.largestNominalAppHeight) { displayInfo.largestNominalAppHeight = height; } }
Example #7
Source File: NotchUtils.java From ImmersionBar with Apache License 2.0 | 5 votes |
private static DisplayCutout getDisplayCutout(View view) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (view != null) { WindowInsets windowInsets = view.getRootWindowInsets(); if (windowInsets != null) { return windowInsets.getDisplayCutout(); } } } return null; }
Example #8
Source File: StreamFragment.java From Twire with GNU General Public License v3.0 | 5 votes |
@RequiresApi(Build.VERSION_CODES.P) private DisplayCutout getDisplayCutout() { Activity activity = getActivity(); if (activity != null) { WindowInsets windowInsets = activity.getWindow().getDecorView().getRootWindowInsets(); if (windowInsets != null) { return windowInsets.getDisplayCutout(); } } return null; }
Example #9
Source File: AppUtils.java From AndroidNavigation with MIT License | 5 votes |
@TargetApi(28) private static boolean attachHasOfficialNotch(View view) { WindowInsets windowInsets = view.getRootWindowInsets(); if (windowInsets != null) { DisplayCutout displayCutout = windowInsets.getDisplayCutout(); return displayCutout != null; } else { throw new IllegalStateException("activity has not yet attach to window, you must call `isCutout` after `Activity#onAttachedToWindow` is called."); } }
Example #10
Source File: PStatusBarUtil.java From YImagePicker with Apache License 2.0 | 5 votes |
/** * 是否有刘海屏 */ public static boolean hasNotchInScreen(Activity activity) { // android P 以上有标准 API 来判断是否有刘海屏 if (Build.VERSION.SDK_INT >= 28) { try { DisplayCutout displayCutout = activity.getWindow().getDecorView().getRootWindowInsets().getDisplayCutout(); if (displayCutout != null) { // 说明有刘海屏 return true; } } catch (Exception e) { return false; } } else { // 通过其他方式判断是否有刘海屏 目前官方提供有开发文档的就 小米,vivo,华为(荣耀),oppo String manufacturer = Build.MANUFACTURER; if (manufacturer == null || manufacturer.length() == 0) { return false; } else if (manufacturer.equalsIgnoreCase("HUAWEI")) { return hasNotchHw(activity); } else if (manufacturer.equalsIgnoreCase("xiaomi")) { return hasNotchXiaoMi(activity); } else if (manufacturer.equalsIgnoreCase("oppo")) { return hasNotchOPPO(activity); } else if (manufacturer.equalsIgnoreCase("vivo")) { return hasNotchVIVO(activity); } else { return false; } } return false; }
Example #11
Source File: PStatusBarUtil.java From YImagePicker with Apache License 2.0 | 5 votes |
/** * 是否有刘海屏 */ public static boolean hasNotchInScreen(Activity activity) { // android P 以上有标准 API 来判断是否有刘海屏 if (Build.VERSION.SDK_INT >= 28) { try { DisplayCutout displayCutout = activity.getWindow().getDecorView().getRootWindowInsets().getDisplayCutout(); if (displayCutout != null) { // 说明有刘海屏 return true; } } catch (Exception e) { return false; } } else { // 通过其他方式判断是否有刘海屏 目前官方提供有开发文档的就 小米,vivo,华为(荣耀),oppo String manufacturer = Build.MANUFACTURER; if (manufacturer == null || manufacturer.length() == 0) { return false; } else if (manufacturer.equalsIgnoreCase("HUAWEI")) { return hasNotchHw(activity); } else if (manufacturer.equalsIgnoreCase("xiaomi")) { return hasNotchXiaoMi(activity); } else if (manufacturer.equalsIgnoreCase("oppo")) { return hasNotchOPPO(activity); } else if (manufacturer.equalsIgnoreCase("vivo")) { return hasNotchVIVO(activity); } else { return false; } } return false; }
Example #12
Source File: DeviceUtil.java From CrazyDaily with Apache License 2.0 | 5 votes |
/** * 判断全面屏 * * @param activity Activity * @return boolean */ public static boolean isFullScreenDisplay(@NonNull Activity activity) { if (isSupportP()) { // 谷歌官方提供 Window window = activity.getWindow(); if (window != null) { WindowInsets windowInsets = window.getDecorView().getRootWindowInsets(); if (windowInsets != null) { DisplayCutout displayCutout = windowInsets.getDisplayCutout(); if (displayCutout != null) { List<Rect> rects = displayCutout.getBoundingRects(); // 一般为刘海屏即为全面屏 if (rects != null && rects.size() > 0) { return true; } } } } } WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); if (wm != null) { Display defaultDisplay = wm.getDefaultDisplay(); if (defaultDisplay != null) { DisplayMetrics dm = new DisplayMetrics(); defaultDisplay.getRealMetrics(dm); float heightPixels = dm.heightPixels; float widthPixels = dm.widthPixels; // 通过分比率比例去判断 return heightPixels / widthPixels >= 1.96f; } } return false; }
Example #13
Source File: NotchUtil.java From UIWidget with Apache License 2.0 | 5 votes |
/** * @param view * @return false indicates the failure to get the result */ @TargetApi(28) private static boolean attachHasOfficialNotch(View view) { WindowInsets windowInsets = view.getRootWindowInsets(); if (windowInsets != null) { DisplayCutout displayCutout = windowInsets.getDisplayCutout(); sHasNotch = displayCutout != null; return true; } else { // view not attached, do nothing return false; } }
Example #14
Source File: NotchUtil.java From UIWidget with Apache License 2.0 | 5 votes |
@TargetApi(28) private static void getOfficialSafeInsetRect(View view, Rect out) { if (view == null) { return; } WindowInsets rootWindowInsets = view.getRootWindowInsets(); if (rootWindowInsets == null) { return; } DisplayCutout displayCutout = rootWindowInsets.getDisplayCutout(); if (displayCutout != null) { out.set(displayCutout.getSafeInsetLeft(), displayCutout.getSafeInsetTop(), displayCutout.getSafeInsetRight(), displayCutout.getSafeInsetBottom()); } }
Example #15
Source File: SkinNotchUtils.java From Android-skin-support with MIT License | 5 votes |
/** * * @param view * @return false indicates the failure to get the result */ @TargetApi(28) private static boolean attachHasOfficialNotch(View view){ WindowInsets windowInsets = view.getRootWindowInsets(); if(windowInsets != null){ DisplayCutout displayCutout = windowInsets.getDisplayCutout(); sHasNotch = displayCutout != null; return true; }else{ // view not attached, do nothing return false; } }
Example #16
Source File: SkinNotchUtils.java From Android-skin-support with MIT License | 5 votes |
@TargetApi(28) private static void getOfficialSafeInsetRect(View view, Rect out) { if(view == null){ return; } WindowInsets rootWindowInsets = view.getRootWindowInsets(); if(rootWindowInsets == null){ return; } DisplayCutout displayCutout = rootWindowInsets.getDisplayCutout(); if(displayCutout != null){ out.set(displayCutout.getSafeInsetLeft(), displayCutout.getSafeInsetTop(), displayCutout.getSafeInsetRight(), displayCutout.getSafeInsetBottom()); } }
Example #17
Source File: NotchUtils.java From ImmersionBar with Apache License 2.0 | 5 votes |
/** * 获得DisplayCutout * Gets display cutout. * * @param activity the activity * @return the display cutout */ private static DisplayCutout getDisplayCutout(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (activity != null) { Window window = activity.getWindow(); if (window != null) { WindowInsets windowInsets = window.getDecorView().getRootWindowInsets(); if (windowInsets != null) { return windowInsets.getDisplayCutout(); } } } } return null; }
Example #18
Source File: WallpaperService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, MergedConfiguration mergedConfiguration, Rect backDropRect, boolean forceLayout, boolean alwaysConsumeNavBar, int displayId, DisplayCutout.ParcelableWrapper displayCutout) { Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED, reportDraw ? 1 : 0, outsets); mCaller.sendMessage(msg); }
Example #19
Source File: NotchUtils.java From ImmersionBar with Apache License 2.0 | 5 votes |
/** * 获得刘海屏高度 * Notch height int. * * @param activity the activity * @return the int */ public static int getNotchHeight(Activity activity) { int notchHeight = 0; int statusBarHeight = ImmersionBar.getStatusBarHeight(activity); DisplayCutout displayCutout = getDisplayCutout(activity); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && displayCutout != null) { if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { notchHeight = displayCutout.getSafeInsetTop(); } else { if (displayCutout.getSafeInsetLeft() == 0) { notchHeight = displayCutout.getSafeInsetRight(); } else { notchHeight = displayCutout.getSafeInsetLeft(); } } } else { if (hasNotchAtXiaoMi(activity)) { notchHeight = getXiaoMiNotchHeight(activity); } if (hasNotchAtHuaWei(activity)) { notchHeight = getHuaWeiNotchSize(activity)[1]; } if (hasNotchAtVIVO(activity)) { notchHeight = dp2px(activity, 32); if (notchHeight < statusBarHeight) { notchHeight = statusBarHeight; } } if (hasNotchAtOPPO(activity)) { notchHeight = 80; if (notchHeight < statusBarHeight) { notchHeight = statusBarHeight; } } } return notchHeight; }
Example #20
Source File: NotchUtils.java From MNImageBrowser with GNU General Public License v3.0 | 5 votes |
/** * 获得DisplayCutout * Gets display cutout. * * @param activity the activity * @return the display cutout */ private static DisplayCutout getDisplayCutout(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (activity != null) { Window window = activity.getWindow(); if (window != null) { WindowInsets windowInsets = window.getDecorView().getRootWindowInsets(); if (windowInsets != null) { return windowInsets.getDisplayCutout(); } } } } return null; }
Example #21
Source File: NotchUtils.java From MNImageBrowser with GNU General Public License v3.0 | 5 votes |
private static DisplayCutout getDisplayCutout(View view) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (view != null) { WindowInsets windowInsets = view.getRootWindowInsets(); if (windowInsets != null) { return windowInsets.getDisplayCutout(); } } } return null; }
Example #22
Source File: NotchUtils.java From MNImageBrowser with GNU General Public License v3.0 | 5 votes |
/** * 获得刘海屏高度 * Notch height int. * * @param activity the activity * @return the int */ public static int getNotchHeight(Activity activity) { int notchHeight = 0; int statusBarHeight = ImmersionBar.getStatusBarHeight(activity); DisplayCutout displayCutout = getDisplayCutout(activity); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && displayCutout != null) { if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { notchHeight = displayCutout.getSafeInsetTop(); } else { if (displayCutout.getSafeInsetLeft() == 0) { notchHeight = displayCutout.getSafeInsetRight(); } else { notchHeight = displayCutout.getSafeInsetLeft(); } } } else { if (hasNotchAtXiaoMi(activity)) { notchHeight = getXiaoMiNotchHeight(activity); } if (hasNotchAtHuaWei(activity)) { notchHeight = getHuaWeiNotchSize(activity)[1]; } if (hasNotchAtVIVO(activity)) { notchHeight = dp2px(activity, 32); if (notchHeight < statusBarHeight) { notchHeight = statusBarHeight; } } if (hasNotchAtOPPO(activity)) { notchHeight = 80; if (notchHeight < statusBarHeight) { notchHeight = statusBarHeight; } } } return notchHeight; }
Example #23
Source File: OverlayController.java From talkback with Apache License 2.0 | 5 votes |
/** * A menu button is drawn at the top of the screen if a menu is not currently visible. This button * offers the user the possibility of clearing the focus or choosing global actions (i.e Home, * Back, Notifications, etc). This menu button should be displayed if the user is using group * selection or point scanning. */ public void drawMenuButtonIfMenuNotVisible() { if (!isMenuVisible()) { Button menuButton = (Button) globalMenuButtonOverlay.findViewById(R.id.global_menu_button); if (!menuButton.hasOnClickListeners()) { menuButton.setOnClickListener(view -> drawGlobalMenu()); } // Adjust the global menu button after it's drawn to ensure it's not obscured by a notch. Only // do so if the button is not already visible to avoid re-drawing the button every time // the screen changes or every time the highlight moves. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && !globalMenuButtonOverlay.isVisible()) { // When switching from having a cutout to having no cutout (e.g. turning a notched phone // sideways to landscape mode), we change the gravity to CENTER_HORIZONTAL in // #adjustGlobalMenuButtonPosition. globalMenuButtonOverlay .getRootView() .post( () -> { WindowInsets windowInsets = this.globalMenuButtonOverlay.getRootView().getRootWindowInsets(); // Because of how View.getLayoutOnScreen renders in Q, we need to first check // that there is an inset before adjusting the gravity. Otherwise, the highlight // can be incorrect on screens without a display cutout. if (windowInsets == null) { return; } DisplayCutout displayCutout = windowInsets.getDisplayCutout(); if (displayCutout == null) { adjustGlobalMenuButtonPosition(displayCutout, new ArrayList<>()); } else { adjustGlobalMenuButtonForDisplayCutouts(); } }); } showGlobalMenu(); } }
Example #24
Source File: OverlayController.java From talkback with Apache License 2.0 | 5 votes |
private void adjustGlobalMenuButtonForDisplayCutouts() { // Having the gravity at CENTER_HORIZONTAL rather than START causes the display cutout's // bounding rects to be incorrect (the left coordinate is 0 even though the left of the cutout // is to the left of the center; it should be negative with CENTER_HORIZONTAL gravity). With // Gravity#START, the left coordinate is a positive number that accurately represents the // cutout's x position. We change the gravity back to START here so when this runnable is // executed in the next frame, it will calculate the bounding rects of the cutout correctly, // based on Gravity#START. LayoutParams params = globalMenuButtonOverlay.getParams(); params.gravity = Gravity.TOP | Gravity.START; globalMenuButtonOverlay.setParams(params); // Hide the global menu button overlay before further adjusting the position to avoid a visual // lag when showing the menu button (i.e. moving the menu button and highlight to the correct // position immediately after showing them in the incorrect position). globalMenuButtonOverlay.hide(); globalMenuButtonOverlay .getRootView() .post( () -> { // We need to get the root window insets again to ensure that the correct gravity is // used when calculating the cutouts. WindowInsets windowInsets = this.globalMenuButtonOverlay.getRootView().getRootWindowInsets(); if (windowInsets != null) { DisplayCutout displayCutout = windowInsets.getDisplayCutout(); List<Rect> boundingRects = (displayCutout == null) ? new ArrayList<>() : displayCutout.getBoundingRects(); adjustGlobalMenuButtonPosition(displayCutout, boundingRects); } }); showGlobalMenu(); }
Example #25
Source File: GalleryHeader.java From EhViewer with Apache License 2.0 | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.P) public void setDisplayCutout(@Nullable DisplayCutout displayCutout) { if (!ObjectUtils.equal(this.displayCutout, displayCutout)) { this.displayCutout = displayCutout; requestLayout(); } }
Example #26
Source File: DrawerLayoutContainer.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public DrawerLayoutContainer(Context context) { super(context); adjustPanLayoutHelper = new AdjustPanLayoutHelper(this); minDrawerMargin = (int) (MIN_DRAWER_MARGIN * AndroidUtilities.density + 0.5f); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); setFocusableInTouchMode(true); if (Build.VERSION.SDK_INT >= 21) { setFitsSystemWindows(true); setOnApplyWindowInsetsListener((v, insets) -> { final DrawerLayoutContainer drawerLayout = (DrawerLayoutContainer) v; if (AndroidUtilities.statusBarHeight != insets.getSystemWindowInsetTop()) { drawerLayout.requestLayout(); } AndroidUtilities.statusBarHeight = insets.getSystemWindowInsetTop(); lastInsets = insets; drawerLayout.setWillNotDraw(insets.getSystemWindowInsetTop() <= 0 && getBackground() == null); if (Build.VERSION.SDK_INT >= 28) { DisplayCutout cutout = insets.getDisplayCutout(); hasCutout = cutout != null && cutout.getBoundingRects().size() != 0; } invalidate(); return insets.consumeSystemWindowInsets(); }); setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } shadowLeft = getResources().getDrawable(R.drawable.menu_shadow); }
Example #27
Source File: DrawerLayoutContainer.java From Telegram with GNU General Public License v2.0 | 5 votes |
public DrawerLayoutContainer(Context context) { super(context); adjustPanLayoutHelper = new AdjustPanLayoutHelper(this); minDrawerMargin = (int) (MIN_DRAWER_MARGIN * AndroidUtilities.density + 0.5f); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); setFocusableInTouchMode(true); if (Build.VERSION.SDK_INT >= 21) { setFitsSystemWindows(true); setOnApplyWindowInsetsListener((v, insets) -> { final DrawerLayoutContainer drawerLayout = (DrawerLayoutContainer) v; if (AndroidUtilities.statusBarHeight != insets.getSystemWindowInsetTop()) { drawerLayout.requestLayout(); } AndroidUtilities.statusBarHeight = insets.getSystemWindowInsetTop(); lastInsets = insets; drawerLayout.setWillNotDraw(insets.getSystemWindowInsetTop() <= 0 && getBackground() == null); if (Build.VERSION.SDK_INT >= 28) { DisplayCutout cutout = insets.getDisplayCutout(); hasCutout = cutout != null && cutout.getBoundingRects().size() != 0; } invalidate(); return insets.consumeSystemWindowInsets(); }); setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } shadowLeft = getResources().getDrawable(R.drawable.menu_shadow); }
Example #28
Source File: DockedStackDividerController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
int getSmallestWidthDpForBounds(Rect bounds) { final DisplayInfo di = mDisplayContent.getDisplayInfo(); final int baseDisplayWidth = mDisplayContent.mBaseDisplayWidth; final int baseDisplayHeight = mDisplayContent.mBaseDisplayHeight; int minWidth = Integer.MAX_VALUE; // Go through all screen orientations and find the orientation in which the task has the // smallest width. for (int rotation = 0; rotation < 4; rotation++) { mTmpRect.set(bounds); mDisplayContent.rotateBounds(di.rotation, rotation, mTmpRect); final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); mTmpRect2.set(0, 0, rotated ? baseDisplayHeight : baseDisplayWidth, rotated ? baseDisplayWidth : baseDisplayHeight); final int orientation = mTmpRect2.width() <= mTmpRect2.height() ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; final int dockSide = getDockSide(mTmpRect, mTmpRect2, orientation); final int position = DockedDividerUtils.calculatePositionForBounds(mTmpRect, dockSide, getContentWidth()); final DisplayCutout displayCutout = mDisplayContent.calculateDisplayCutoutForRotation( rotation).getDisplayCutout(); // Since we only care about feasible states, snap to the closest snap target, like it // would happen when actually rotating the screen. final int snappedPosition = mSnapAlgorithmForRotation[rotation] .calculateNonDismissingSnapTarget(position).position; DockedDividerUtils.calculateBoundsForPosition(snappedPosition, dockSide, mTmpRect, mTmpRect2.width(), mTmpRect2.height(), getContentWidth()); mService.mPolicy.getStableInsetsLw(rotation, mTmpRect2.width(), mTmpRect2.height(), displayCutout, mTmpRect3); mService.intersectDisplayInsetBounds(mTmpRect2, mTmpRect3, mTmpRect); minWidth = Math.min(mTmpRect.width(), minWidth); } return (int) (minWidth / mDisplayContent.getDisplayMetrics().density); }
Example #29
Source File: Session.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public int add(IWindow window, int seq, WindowManager.LayoutParams attrs, int viewVisibility, Rect outContentInsets, Rect outStableInsets, InputChannel outInputChannel) { return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY, new Rect() /* outFrame */, outContentInsets, outStableInsets, null /* outOutsets */, new DisplayCutout.ParcelableWrapper() /* cutout */, outInputChannel); }
Example #30
Source File: Session.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs, int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets, Rect outStableInsets, Rect outOutsets, DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel) { // 调用 WMS.addWindow() return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame, outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel); }