डिसप्ले कटआउट

Android 9 में, डिवाइसों पर अलग-अलग तरह के डिसप्ले कटआउट लागू करने की सुविधा जोड़ी गई है. डिस्प्ले कटआउट की मदद से, आपको इमर्सिव और एज-टू-एज अनुभव मिलता है. साथ ही, डिवाइसों के सामने मौजूद अहम सेंसर के लिए जगह भी मिलती है.

सबसे ऊपर बीच में डिसप्ले कटआउट

पहली इमेज. सबसे ऊपर बीच में डिसप्ले कटआउट

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);
    }

इन तरीकों में बताया गया है कि सभी मामलों में स्टेटस बार में कटआउट कैसे हैंडल किए जाते हैं. जैसे, टॉप सेंटर, टॉप अनसेंटर्ड, बॉटम, और सभी रोटेशन में डुअल-कटआउट.

ज़रूरी शर्तें

यह पक्का करने के लिए कि कटआउट की वजह से ऐप्लिकेशन पर बुरा असर न पड़े, आपको यह पक्का करना होगा कि:

  • स्टेटस बार, पोर्ट्रेट मोड में कटआउट की ऊंचाई तक फैला हो
  • कटआउट वाला हिस्सा, फ़ुलस्क्रीन और लैंडस्केप मोड में लेटरबॉक्स किया जाना चाहिए

आपके डिवाइस में, हर छोटे किनारे (ऊपर और नीचे) पर ज़्यादा से ज़्यादा एक कटआउट हो सकता है.

ज़्यादा जानकारी के लिए, सीडीडी देखें.

लागू करना

अपने डिवाइस पर डिसप्ले कटआउट लागू करने के लिए, आपको सिस्टम यूज़र इंटरफ़ेस (यूआई) के लिए यहां दी गई वैल्यू कॉन्फ़िगर करनी होंगी.

वैल्यू ब्यौरा
quick_qs_offset_height

इससे क्विक सेटिंग पैनल के लिए टॉप मार्जिन तय किया जाता है. घड़ी और बैटरी की जानकारी, पैनल के ऊपर दिखती है.

वैल्यू-लैंड में इसे status_bar_height_landscape पर सेट करें. साथ ही, पोर्ट्रेट मोड में इसे 48 डीपी के डिफ़ॉल्ट साइज़ या कटआउट की ऊंचाई पर सेट करें. इनमें से जो भी ज़्यादा हो उसे सेट करें. अगर चाहें, तो इसे कटआउट से ज़्यादा लंबा किया जा सकता है.

quick_qs_total_height

सूचना शेड के बड़ा होने पर, क्विक सेटिंग पैनल (क्विक सेटिंग पैनल छोटा होने पर) की कुल ऊंचाई. इसमें घड़ी वाले पैनल के ऊपर की जगह भी शामिल है.

क्विक सेटिंग के लेआउट की वजह से, क्विक-क्विक सेटिंग पैनल की कुल ऊंचाई (ऑफ़सेट शामिल है) को स्टैटिक तौर पर पता होना चाहिए. इसलिए, इस वैल्यू को उसी डेल्टा quick_qs_offset_height से अडजस्ट किया जाना चाहिए. लैंडस्केप मोड में, इसकी डिफ़ॉल्ट वैल्यू 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>

Validation

डिसप्ले कटआउट को लागू करने की पुष्टि करने के लिए, tests/framework/base/windowmanager/src/android/server/wm पर सीटीएस टेस्ट चलाएं.