कटआउट प्रदर्शित करें

एंड्रॉइड 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);
    }

ये विधियाँ बताती हैं कि सभी मामलों में स्टेटस बार में कटआउट को कैसे नियंत्रित किया जाता है (यानी शीर्ष केंद्र, शीर्ष अकेंद्रित, निचला और सभी घुमावों में दोहरे कटआउट)।

आवश्यकताएं

यह सुनिश्चित करने के लिए कि ऐप कटआउट से नकारात्मक रूप से प्रभावित न हों, आपको यह सुनिश्चित करना होगा कि:

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

आपके डिवाइस में प्रत्येक छोटे किनारे (ऊपर और नीचे) पर अधिकतम एक कटआउट हो सकता है।

अधिक जानकारी के लिए सीडीडी देखें।

कार्यान्वयन

अपने डिवाइस पर डिस्प्ले कटआउट लागू करने के लिए, आपको सिस्टम यूआई के लिए निम्नलिखित मानों को कॉन्फ़िगर करना होगा।

कीमत विवरण
quick_qs_offset_height

त्वरित सेटिंग्स पैनल के लिए शीर्ष मार्जिन को परिभाषित करता है। घड़ी और बैटरी पैनल के ऊपर की जगह में प्रदर्शित होती हैं।

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

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>

मान्यकरण

डिस्प्ले कटआउट के अपने कार्यान्वयन को मान्य करने के लिए, test/framework/base/windowmanager/src/android/server/wm पर CTS परीक्षण चलाएँ।