Android 9 เพิ่มการรองรับการใช้คัตเอาท์ดิสเพลย์ประเภทต่างๆ ในอุปกรณ์ คัตเอาท์ดิสเพลย์ช่วยให้คุณสร้างประสบการณ์การใช้งานที่เต็มอิ่มตั้งแต่ขอบจรดขอบ โดยยังคงมีพื้นที่สำหรับเซ็นเซอร์ที่สำคัญที่ด้านหน้าของอุปกรณ์

รูปที่ 1 หน้าจอรอยบากตรงกลางด้านบน
Android 9 รองรับคัตเอาท์ประเภทต่อไปนี้
- ตรงกลางด้านบน: คัตเอาท์ตรงกลางขอบด้านบน
- ด้านบนไม่ตรงกลาง: คัตเอาท์อาจอยู่ที่มุมหรือเบี่ยงจากตรงกลางเล็กน้อย
- ด้านล่าง: คัตเอาท์ที่ด้านล่าง
- คู่: คัตเอาท์ 1 รายการที่ด้านบนและอีก 1 รายการที่ด้านล่าง
ตัวอย่างและแหล่งที่มา
โค้ด Window Manager ต่อไปนี้ที่
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 มีตัวอย่างมุมมองที่กำหนดตำแหน่ง ขนาด และการแทรกคัตเอาท์ดิสเพลย์จากแถบการนำทางหลีกเลี่ยงพื้นที่คัตเอาท์หรือไม่
การลบล้าง onApplyWindowInsets() จะช่วยให้มุมมองกำหนดตำแหน่งของคัตเอาท์และอัปเดตเลย์เอาต์ตามนั้นได้
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (updateOrientationAndCutout(mLastOrientation)) {
updateLayoutForCutout();
requestLayout();
}
return super.onApplyWindowInsets(insets);
}
เมธอดเหล่านี้สรุปวิธีจัดการคัตเอาท์ในแถบสถานะในทุกกรณี (เช่น ตรงกลางด้านบน ด้านบนไม่ตรงกลาง ด้านล่าง และคัตเอาท์คู่ในการหมุนทั้งหมด)
ข้อกำหนด
คุณต้องตรวจสอบสิ่งต่อไปนี้เพื่อให้แน่ใจว่าคัตเอาท์จะไม่ส่งผลเสียต่อแอป
- แถบสถานะขยายไปถึงความสูงของคัตเอาท์อย่างน้อยในโหมดแนวตั้ง
- พื้นที่คัตเอาท์ต้องเป็น Letterbox ในโหมดเต็มหน้าจอและโหมดแนวนอน
อุปกรณ์ของคุณมีคัตเอาท์ได้สูงสุด 1 รายการที่ขอบสั้นแต่ละด้าน (ด้านบนและด้านล่าง)
ดูข้อมูลเพิ่มเติมได้ที่ CDD
การใช้งาน
หากต้องการใช้คัตเอาท์ดิสเพลย์ในอุปกรณ์ คุณต้องกำหนดค่าต่อไปนี้สำหรับ UI ของระบบ
| ค่า | คำอธิบาย |
|---|---|
quick_qs_offset_height
|
กำหนดระยะขอบด้านบนสำหรับแผงการตั้งค่าด่วน ระบบจะแสดงนาฬิกาและแบตเตอรี่ในพื้นที่เหนือแผง ใน values-land ให้ตั้งค่าเป็น |
quick_qs_total_height
|
ความสูงทั้งหมดของแผงการตั้งค่าด่วน (แผงการตั้งค่าด่วนที่ยุบอยู่) เมื่อขยายหน้าต่างแจ้งเตือน รวมถึงพื้นที่เหนือแผงที่มีนาฬิกา
เนื่องจากเลย์เอาต์ของการตั้งค่าด่วน ความสูงทั้งหมดของแผงการตั้งค่าด่วน (รวมถึงออฟเซ็ต) ต้องทราบแบบคงที่ ดังนั้นคุณต้องปรับค่านี้ด้วยเดลต้า |
status_bar_height_portrait
|
ความสูงเริ่มต้นของแถบสถานะจากมุมมองของเฟรมเวิร์ก ในอุปกรณ์ส่วนใหญ่ ค่าเริ่มต้นจะเป็น 24dp เมื่อมีคัตเอาท์ ให้ตั้งค่านี้เป็นความสูงของคัตเอาท์ อาจสูงกว่าคัตเอาท์ได้หากต้องการ |
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