גזירים במסך

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

השיטות הבאות מתארות איך אנחנו מטפלים בגזירים בשורת הסטטוס בכל המקרים (כלומר: מרכז למעלה, למעלה לא במרכז, למטה, ושני גזירים בכל הסיבובים).

הדרישות

כדי לוודא שאפליקציות לא ייפגעו ממנה בעקבות חיתוך, צריך לוודא ש:

  • שורת הסטטוס נמשכת לפחות לגובה של המגרעת בפריסה לאורך
  • אזור המגרעת צריך להיות בפורמט letterbox במצב של מסך מלא ובמצב לרוחב

במכשיר יכול להיות מגרעת אחת לכל היותר בכל קצה קצר (למעלה ולמטה).

מידע נוסף זמין במאמר בנושא CDD.

הטמעה

כדי להטמיע את המגרעת במסך במכשיר, צריך להגדיר את ההגדרות הבאות עבור ממשק המשתמש של המערכת.

ערך תיאור
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

ערך בוליאני שקובע אם לשרטט את נתיב המגרעת (מוגדר שלמעלה) בתוכנה. אפשר להשתמש בו כדי לחקות גזיר או כדי למלא מגרעת פיזית להשגת החלקה.

אם True, יש למלא את 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.