แสดงพิลึก

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

ช่องเจาะจอแสดงผลตรงกลางด้านบน

รูปที่ 1 ช่องเจาะของจอแสดงผลส่วนกลางด้านบน

Android 9 รองรับการตัดประเภทต่อไปนี้:

  • ตรงกลางด้านบน: ช่องเจาะตรงกลางขอบด้านบน
  • ด้านบนไม่ตรงกลาง: ช่องเจาะอาจอยู่ที่มุมหรือหลุดจากกึ่งกลางเล็กน้อย
  • ด้านล่าง: คัตเอาท์ที่ด้านล่าง
  • คู่: ช่องเจาะหนึ่งอันที่ด้านบนและอีกอันที่ด้านล่าง

ตัวอย่างและที่มา

รหัสตัวจัดการหน้าต่างต่อไปนี้ที่ 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);
    }

วิธีการเหล่านี้สรุปวิธีจัดการคัตเอาต์ในแถบสถานะในทุกกรณี (เช่น ตรงกลางบน ด้านบนไม่ตรงกลาง ด้านล่าง และคัตเอาต์คู่ในการหมุนทั้งหมด)

ความต้องการ

เพื่อให้แน่ใจว่าแอปจะไม่ได้รับผลกระทบเชิงลบจากการตัดออก คุณต้องตรวจสอบให้แน่ใจว่า:

  • แถบสถานะจะขยายไปจนถึงความสูงของช่องเจาะในโหมดแนวตั้งเป็นอย่างน้อย
  • พื้นที่ตัดออกจะต้องอยู่ในแถบดำแถบดำในโหมดเต็มหน้าจอและแนวนอน

อุปกรณ์ของคุณสามารถมีช่องเจาะได้สูงสุด 1 ช่องที่ขอบด้านสั้นแต่ละด้าน (ด้านบนและด้านล่าง)

สำหรับข้อมูลเพิ่มเติม โปรดดูที่ CDD

การนำไปปฏิบัติ

หากต้องการใช้การตัดการแสดงผลบนอุปกรณ์ของคุณ คุณต้องกำหนดค่าต่อไปนี้สำหรับ System UI

ค่า คำอธิบาย
quick_qs_offset_height

กำหนดระยะขอบด้านบนสำหรับแผงการตั้งค่าด่วน นาฬิกาและแบตเตอรี่จะแสดงในพื้นที่ด้านบนแผง

ใน value-land ให้ตั้งค่าเป็น status_bar_height_landscape และในแนวตั้งให้ตั้งค่าเริ่มต้นที่ 48dp หรือความสูงของจุดตัด แล้วแต่จำนวนใดจะใหญ่กว่า สามารถเลือกที่จะสูงกว่าคัตเอาต์ได้หากต้องการ

quick_qs_total_height

ความสูงรวมของแผงการตั้งค่าด่วนด่วน (แผงการตั้งค่าด่วนยุบ) เมื่อขยายแถบการแจ้งเตือน รวมถึงพื้นที่เหนือแผงที่มีนาฬิกา

เนื่องจากวิธีการวางการตั้งค่าด่วน ความสูงรวมของพาเนลการตั้งค่าด่วนด่วน (รวมถึงออฟเซ็ต) จะต้องทราบแบบคงที่ ดังนั้นค่านี้จึงต้องปรับด้วยเดลต้า quick_qs_offset_height เดียวกัน Values-land มีค่าเริ่มต้นเป็น 152dp ในขณะที่ค่าเริ่มต้นของแนวตั้งคือ 176dp

status_bar_height_portrait

ความสูงเริ่มต้นของแถบสถานะจากมุมมองของกรอบงาน

ในอุปกรณ์ส่วนใหญ่ ค่าเริ่มต้นนี้จะอยู่ที่ 24dp เมื่อมีการตัดออก ให้ตั้งค่านี้เป็นความสูงของการตัดออก สามารถเลือกที่จะสูงกว่าคัตเอาต์ได้หากต้องการ

status_bar_height_landscape

ความสูงของแถบสถานะในแนวนอน รองรับการตัดขอบด้านสั้นของอุปกรณ์เท่านั้น ดังนั้น นี่จะเป็นความสูงของแถบสถานะที่ไม่มีการเปลี่ยนแปลงเสมอ

ในอุปกรณ์ที่ไม่มีคัตเอาต์ ค่านี้จะเทียบเท่ากับ status_bar_height_portrait เมื่อมีจุดตัด ให้เก็บค่านี้ไว้ที่ความสูงของแถบสถานะเริ่มต้น

config_mainBuiltInDisplayCutout

เส้นทางที่กำหนดรูปร่างของช่องเจาะ นี่คือสตริงที่แยกวิเคราะห์ได้โดย android.util.PathParser และเป็นวิธีกำหนดขนาดและรูปร่างของคัตเอาต์ให้กับระบบ

สามารถระบุ @dp บนพาธเพื่อจำลองรูปร่างที่มีเป้าหมายไปที่อุปกรณ์ต่างๆ เนื่องจากการตัดออกจริงมีขนาดพิกเซลที่แน่นอน อย่าใช้ตัวระบุ @dp เมื่อกำหนดเส้นทางสำหรับรอยบากของฮาร์ดแวร์

config_fillMainBuiltinDisplayCutout

ค่าบูลีนที่กำหนดว่าจะวาดเส้นทางคัตเอาท์ (กำหนดไว้ด้านบน) ในซอฟต์แวร์หรือไม่ สามารถใช้เพื่อจำลองคัตเอาต์ หรือเติมคัตเอาต์จริงเพื่อลดรอยหยักได้

หากเป็นจริง config_mainBuiltInDisplayCutout จะถูกเติมด้วยสีดำ

ดูไฟล์ 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