اندروید ۹ از پیادهسازی انواع مختلف بریدگی نمایشگر در دستگاهها پشتیبانی میکند. بریدگیهای نمایشگر به شما امکان میدهند تا تجربههای فراگیر و لبه به لبه ایجاد کنید و در عین حال فضای کافی برای حسگرهای مهم در جلوی دستگاهها فراهم باشد.

شکل ۱. برش نمایشگر در مرکز بالا
اندروید ۹ از انواع برشهای زیر پشتیبانی میکند:
- مرکز بالا: برش در مرکز لبه بالا
- بالا غیرمتمرکز: برش ممکن است در گوشه یا کمی خارج از مرکز باشد
- پایین: برش در پایین
- دوتایی: یک برش در بالا و یکی در پایین
مثالها و منابع
کد مدیر پنجره زیر در PhoneWindowManager.java نشان میدهد که چگونه فریمهای نمایش در ناحیه امن قرار میگیرند، زمانی که LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS تنظیم نشده باشد.
// Ensure that windows with a DEFAULT or NEVER display cutout mode are laid out in
// the cutout safe zone.
if (cutoutMode != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
final Rect displayCutoutSafeExceptMaybeBars = mTmpDisplayCutoutSafeExceptMaybeBarsRect;
displayCutoutSafeExceptMaybeBars.set(displayFrames.mDisplayCutoutSafe);
if (layoutInScreen && layoutInsetDecor && !requestedFullscreen
&& cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT) {
// At the top we have the status bar, so apps that are
// LAYOUT_IN_SCREEN | LAYOUT_INSET_DECOR but not FULLSCREEN
// already expect that there's an inset there and we don't need to exclude
// the window from that area.
displayCutoutSafeExceptMaybeBars.top = Integer.MIN_VALUE;
}
if (layoutInScreen && layoutInsetDecor && !requestedHideNavigation
&& cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT) {
// Same for the navigation bar.
switch (mNavigationBarPosition) {
case NAV_BAR_BOTTOM:
displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE;
break;
case NAV_BAR_RIGHT:
displayCutoutSafeExceptMaybeBars.right = Integer.MAX_VALUE;
break;
case NAV_BAR_LEFT:
displayCutoutSafeExceptMaybeBars.left = Integer.MIN_VALUE;
break;
}
}
if (type == TYPE_INPUT_METHOD && mNavigationBarPosition == NAV_BAR_BOTTOM) {
// The IME can always extend under the bottom cutout if the navbar is there.
displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE;
}
// Windows that are attached to a parent and laid out in said parent already avoid
// the cutout according to that parent and don't need to be further constrained.
// Floating IN_SCREEN windows get what they ask for and lay out in the full screen.
// They will later be cropped or shifted using the displayFrame in WindowState,
// which prevents overlap with the DisplayCutout.
if (!attachedInParent && !floatingInScreenWindow) {
mTmpRect.set(pf);
pf.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
parentFrameWasClippedByDisplayCutout |= !mTmpRect.equals(pf);
}
// Make sure that NO_LIMITS windows clipped to the display don't extend under the
// cutout.
df.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
}
SystemUI در ناحیه برش رندر میشود و باید مشخص کند که کجا میتواند رسم کند. PhoneStatusBarView.java نمونهای از یک نما را ارائه میدهد که تعیین میکند برش نمایشگر کجا باشد، چقدر بزرگ باشد و آیا نوار ناوبری از ناحیه برش عبور میکند یا خیر.
با override کردن onApplyWindowInsets() ، یک نما میتواند محل برش را تعیین کرده و طرحبندی خود را بر اساس آن بهروزرسانی کند.
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (updateOrientationAndCutout(mLastOrientation)) {
updateLayoutForCutout();
requestLayout();
}
return super.onApplyWindowInsets(insets);
}
این روشها نحوهی مدیریت بریدگیها در نوار وضعیت را در تمام موارد (یعنی بریدگیهای بالا-مرکز، بالا-غیرمرکز، پایین و دو-بریدگی در تمام چرخشها) مشخص میکنند.
الزامات
برای اطمینان از اینکه برنامهها تحت تأثیر منفی بریدگیها قرار نمیگیرند، باید مطمئن شوید که:
- نوار وضعیت در حالت عمودی حداقل تا ارتفاع بریدگی صفحه نمایش امتداد مییابد
- ناحیه برش باید در حالتهای تمامصفحه و افقی با حروف بزرگ مشخص شود
دستگاه شما میتواند تا یک بریدگی در هر لبه کوتاه (بالا و پایین) داشته باشد.
برای اطلاعات بیشتر، به CDD مراجعه کنید.
پیادهسازی
برای پیادهسازی بریدگیهای نمایشگر در دستگاه خود، باید مقادیر زیر را برای رابط کاربری سیستم پیکربندی کنید.
| ارزش | توضیحات |
|---|---|
quick_qs_offset_height | حاشیه بالایی پنل تنظیمات سریع را تعیین میکند. ساعت و باتری در فضای بالای پنل نمایش داده میشوند. در values-land، روی |
quick_qs_total_height | ارتفاع کل پنل تنظیمات سریع (پنل تنظیمات سریع جمعشده) هنگام باز شدن نوار اعلانها، شامل فضای بالای پنل حاوی ساعت. به دلیل نحوه چیدمان تنظیمات سریع، ارتفاع کل پنل تنظیمات سریع (شامل آفست) باید به صورت استاتیک مشخص باشد، بنابراین این مقدار باید با همان دلتای |
status_bar_height_portrait | ارتفاع پیشفرض نوار وضعیت از دید چارچوب. در بیشتر دستگاهها، این مقدار به صورت پیشفرض روی ۲۴dp تنظیم شده است. وقتی یک بریدگی وجود دارد، این مقدار را برابر با ارتفاع بریدگی تنظیم کنید. در صورت تمایل، میتوان به صورت اختیاری بلندتر از بریدگی باشد. |
status_bar_height_landscape | ارتفاع نوار وضعیت در حالت افقی. بریدگیها فقط در لبههای کوتاه دستگاه پشتیبانی میشوند، بنابراین این ارتفاع نوار وضعیت همیشه بدون تغییر خواهد بود. در دستگاهی که بریدگی ندارد، این معادل |
config_mainBuiltInDisplayCutout | مسیری که شکل بریدگی را تعریف میکند. این یک رشته است که توسط میتوان |
config_fillMainBuiltinDisplayCutout | یک مقدار بولی که تعیین میکند آیا مسیر برش (تعریف شده در بالا) در نرمافزار رسم شود یا خیر. میتواند برای شبیهسازی یک برش یا پر کردن یک برش فیزیکی برای دستیابی به صافی لبهها استفاده شود. اگر درست باشد، |
برای تعاریف پیشفرض، به این فایلهای dimens مراجعه کنید:
نمونهای از پوشش برای یک برش شبیهسازی شده:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- The bounding path of the cutout region of the main built-in display.
Must either be empty if there is no cutout region, or a string that is parsable by
{@link android.util.PathParser}.
The path is assumed to be specified in display coordinates with pixel units and in
the display's native orientation, with the origin of the coordinate system at the
center top of the display.
To facilitate writing device-independent emulation overlays, the marker `@dp` can be
appended after the path string to interpret coordinates in dp instead of px units.
Note that a physical cutout should be configured in pixels for the best results.
-->
<string translatable="false" name="config_mainBuiltInDisplayCutout">
M 0,0
L -48, 0
L -44.3940446283, 36.0595537175
C -43.5582133885, 44.4178661152 -39.6, 48.0 -31.2, 48.0
L 31.2, 48.0
C 39.6, 48.0 43.5582133885, 44.4178661152 44.3940446283, 36.0595537175
L 48, 0
Z
@dp
</string>
<!-- Whether the display cutout region of the main built-in display should be forced to
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
-->
<bool name="config_fillMainBuiltInDisplayCutout">true</bool>
<!-- Height of the status bar -->
<dimen name="status_bar_height_portrait">48dp</dimen>
<dimen name="status_bar_height_landscape">28dp</dimen>
<!-- Height of area above QQS where battery/time go (equal to status bar height if > 48dp) -->
<dimen name="quick_qs_offset_height">48dp</dimen>
<!-- Total height of QQS (quick_qs_offset_height + 128) -->
<dimen name="quick_qs_total_height">176dp</dimen>
</resources>
اعتبارسنجی
برای اعتبارسنجی پیادهسازی بریدگیهای نمایشگر، تستهای CTS را در tests/framework/base/windowmanager/src/android/server/wm اجرا کنید.